# Provident Fund Calculation

Hi,
I want to calculate Provident Fund on the Basis of “Basic Salary” in the Salary Structure, but I am not able to use the proper event and method.

I appreciate if anyone can help me in this regard.

I tried this but its not working.

``````frappe.ui.form.on("Salary Structure","type", function(frm, cdt, cdn) {
var d =locals[cdt][cdn]
var item=frappe.get_doc(cdt,cdn);
if(d.type == "Basic"){
frappe.model.set_value(cdt, cdn, "provident_fund", item.amount*12/100);
cur_frm.refresh_fields();
}
});
``````

Try

frappe.ui.form.on(“Salary Structure Deduction”, …

@rmehta
That is fine, but how will I get the value of basic there?

Hi Rushabh,

I have solved the problem upto a stage see my code below:

``````var a=0;
frappe.ui.form.on("Salary Structure Deduction","d_type", function(frm, cdt, cdn) {
var d =locals[cdt][cdn]
var item=frappe.get_doc(cdt,cdn);
if(d.d_type == "Provident Fund"){
frappe.model.set_value(cdt, cdn, "d_modified_amt", a*12/100);
//cur_frm.refresh_fields();
}
});

frappe.ui.form.on("Salary Structure Earning","e_type", function(frm, cdt, cdn) {
var d =locals[cdt][cdn]
var item=frappe.get_doc(cdt,cdn);
if(d.e_type=="Basic")
{
a=d.modified_value;
}
});
``````

Now the only problem I am facing is, I need to select the Earning Type (“Basic”) from the list to get the value of “Basic” in variable, Similarly, I need to select the Deduction Type (“Provident Fund”) from the to update the value in “Provident Fund”

Is there any way to get rid of this problem?

2 Likes