From d48998bae13ce5c2ba7e866ba5b243fc3b27ddb1 Mon Sep 17 00:00:00 2001 From: Jamsheer Date: Mon, 14 May 2018 12:05:47 +0530 Subject: [PATCH] Employee Benefit Application - Calculate benefit amounts --- .../employee_benefit_application.js | 74 ++++++++ .../employee_benefit_application.json | 158 +++++++++++++++++- 2 files changed, 231 insertions(+), 1 deletion(-) diff --git a/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.js b/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.js index 9af2b5b23e..b5fc99e597 100644 --- a/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.js +++ b/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.js @@ -12,5 +12,79 @@ frappe.ui.form.on('Employee Benefit Application', { } } }) + }, + employee: function(frm) { + frappe.call({ + doc: frm.doc, + method: "get_max_benefits", + callback: function (data) { + if(!data.exc){ + if(data.message){ + frm.set_value("max_benefits", data.message) + } + } + } + }); } }); + +frappe.ui.form.on("Employee Benefit Application Detail",{ + amount: function(frm, 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) + } + } + }); + } + }, +}) + +var calculate_all = function(doc, dt, dn) { + var tbl = doc.employee_benefits || []; + var pro_rata_dispensed_amount = 0; + var total_amount = 0; + for(var i = 0; i < tbl.length; i++){ + if(cint(tbl[i].amount) > 0) { + total_amount += flt(tbl[i].amount); + } + var amount = tbl[i].amount; + frappe.call({ + 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.remainig_benefits = doc.max_benefits - total_amount + doc.pro_rata_dispensed_amount = pro_rata_dispensed_amount + refresh_many(['pro_rata_dispensed_amount', 'total_amount','remainig_benefits']); +} + +var validate_max_benefit_for_component = function(doc, salary_component) { + // TODO: Validate Max Benefit +} diff --git a/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.json b/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.json index 0fff4fdab2..3c1c8aaee2 100644 --- a/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.json +++ b/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.json @@ -77,6 +77,68 @@ "translatable": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "max_benefits", + "fieldtype": "Currency", + "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": "Max Benefits (Yearly)", + "length": 0, + "no_copy": 0, + "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_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "remainig_benefits", + "fieldtype": "Currency", + "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": "Remainig Benefits (Yearly)", + "length": 0, + "no_copy": 0, + "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_on_submit": 0, @@ -107,6 +169,38 @@ "translatable": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "Today", + "fieldname": "date", + "fieldtype": "Date", + "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": "Date", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, { "allow_bulk_edit": 0, "allow_on_submit": 0, @@ -139,6 +233,68 @@ "translatable": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "pro_rata_dispensed_amount", + "fieldtype": "Currency", + "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": "Pro Rata Dispensed Amount", + "length": 0, + "no_copy": 0, + "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_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "total_amount", + "fieldtype": "Currency", + "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": "Total Amount", + "length": 0, + "no_copy": 0, + "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_on_submit": 0, @@ -243,7 +399,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2018-04-14 15:35:20.748301", + "modified": "2018-05-11 16:58:31.662866", "modified_by": "Administrator", "module": "HR", "name": "Employee Benefit Application",