Calculate Custom fields

cur_frm.cscript.custom_total_2014 = function(doc) {

total_incentive = doc.january + doc.february + doc.march + doc.april + doc.may + doc.june + doc.july + doc.august + doc.september + doc.october + doc.november + doc.december;
doc.total_2014 = total_incentive;

}

Regarding the above script i need some help.

I created several custom fields and i want to make some automatically calculations through the custom fields.

The above calculations working OK but i need to have some more fields calculations.

Can you advice please.

Can you be more specific about what you want ?

-Anand

Attached screenshot.

Nevertheless, All the fields are customs. I need to do the following calculations

  1. SUM of Total T (2014)
  2. SUM of Total B (2014) then,
  3. T remaining 2014 = Yearly T - Total T (2014)

Thanks in advance!

<img src=“/uploads/default/182/35350ef6cb7e8e2f.png” width=“561” height="500

Your code looks okay!

Hi Rmehta,

with this code i can calculate only SUM of Total T (2014)

I need to calculate at the same time, so i need the SUM of Total B (2014) and subtraction for T remaining 2014

Can you advice for any solution?

Sorry I am unable to understand where you are stuck?

OK let me try to explain you better

I want to calculate the sum of the year for both columns Total T (2014) and Total B (2014) after that i want to calculate

T remaining 2014 = Yearly T - Total T (2014)

This code is ONLY the calculation of Total T (2014) and i want to do the rest calculations

Is there any help or update?

Thanks

I am still not able to understand your issue. What you are asking is simple addition which should work? What is Yearly T where does it come from?

I suggest, you can engage a freelancer to help you out if you want to get this done asap.

i have to coded like this but no output any one advie to calculate this total

cur_frm.add_fetch("budgeted_amount", "purchased_amount", "excess_amount");
frappe.ui.form.on("budgeted_amount", "purchased_amount", function(frm, doctype, name) {
    

cur_frm.cscript.custom_validate = function(doc) {

var budgeted_amount=budgeted_amount;
var purchased_amount=purchased_amount;
var excess_amount=0;


doc.excess_amount=purchased_amount-budgeted_amount;


doc.budgeted_amount=budgeted_amount;
doc.purchased_amount=purchased_amount;

}

});

Try this:

frappe.ui.form.on("Task", "budgeted_amount", function(frm) {
	calculate_excess_amount(frm);
})

frappe.ui.form.on("Task", "purchased_amount", function(frm) {
	calculate_excess_amount(frm);
})

var calculate_excess_amount = function(frm) {
	var excess_amount = flt(frm.doc.purchased_amount) - flt(frm.doc.budgeted_amount);
	frm.set_value("excess_amount", excess_amount);
}

sorry no i think not working can you this image

@Senthil_Kumar check this script, also you can see browser console for error log

frappe.ui.form.on("Task", "budgeted_amount", function(frm) {
    calculate_excess_amount(frm);
});

frappe.ui.form.on("Task", "purchased_amount", function(frm) {
    calculate_excess_amount(frm);
});

var calculate_excess_amount = function(frm) {
    var excess_amount = flt(frm.doc.purchased_amount) - flt(frm.doc.budgeted_amount);
    frm.set_value("excess_amount", excess_amount);
}
2 Likes

its working thakn you so much… :grinning: :gift:

@Senthil_Kumar try sending a real gift :smile:

1 Like