Employee Benefit Application - calcluate benefit amount

This commit is contained in:
Jamsheer 2018-05-15 12:35:34 +05:30
parent d48998bae1
commit 9cb2fc2766
2 changed files with 39 additions and 44 deletions

View File

@ -30,22 +30,7 @@ frappe.ui.form.on('Employee Benefit Application', {
frappe.ui.form.on("Employee Benefit Application Detail",{ frappe.ui.form.on("Employee Benefit Application Detail",{
amount: function(frm, cdt, cdn) { amount: function(frm, cdt, cdn) {
calculate_all(frm.doc, cdt, cdn) calculate_all(frm.doc, cdt, cdn);
var child = locals[cdt][cdn];
if(child.amount && child.earning_component){
frappe.call({
"method": "frappe.client.get",
args: {
doctype: "Salary Component",
name: child.earning_component,
},
callback: function (data) {
if(data.message){
validate_max_benefit_for_component(frm.doc, data.message)
}
}
});
}
}, },
}) })
@ -57,34 +42,12 @@ var calculate_all = function(doc, dt, dn) {
if(cint(tbl[i].amount) > 0) { if(cint(tbl[i].amount) > 0) {
total_amount += flt(tbl[i].amount); total_amount += flt(tbl[i].amount);
} }
var amount = tbl[i].amount; if(tbl[i].is_pro_rata_applicable == 1){
frappe.call({ pro_rata_dispensed_amount += flt(tbl[i].amount)
method: "frappe.client.get_value", }
args: {
doctype: "Salary Component",
fieldname: "is_pro_rata_applicable",
filters:{
name: tbl[i].earning_component
}
},
callback: function (data) {
if(data.message){
if(data.message.is_pro_rata_applicable == 1){
console.log("Any time here");
pro_rata_dispensed_amount += amount
console.log(amount);
console.log(pro_rata_dispensed_amount);
}
}
}
});
} }
doc.total_amount = total_amount; doc.total_amount = total_amount;
doc.remainig_benefits = doc.max_benefits - total_amount doc.remainig_benefits = doc.max_benefits - total_amount;
doc.pro_rata_dispensed_amount = pro_rata_dispensed_amount doc.pro_rata_dispensed_amount = pro_rata_dispensed_amount;
refresh_many(['pro_rata_dispensed_amount', 'total_amount','remainig_benefits']); refresh_many(['pro_rata_dispensed_amount', 'total_amount','remainig_benefits']);
} }
var validate_max_benefit_for_component = function(doc, salary_component) {
// TODO: Validate Max Benefit
}

View File

@ -45,6 +45,38 @@
"translatable": 0, "translatable": 0,
"unique": 0 "unique": 0
}, },
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "is_pro_rata_applicable",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Is Pro-rata Applicable",
"length": 0,
"no_copy": 0,
"options": "earning_component.is_pro_rata_applicable",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
@ -87,7 +119,7 @@
"issingle": 0, "issingle": 0,
"istable": 1, "istable": 1,
"max_attachments": 0, "max_attachments": 0,
"modified": "2018-04-13 19:32:35.064272", "modified": "2018-05-15 12:03:25.545041",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Employee Benefit Application Detail", "name": "Employee Benefit Application Detail",