Calculate Grand Total

Hi,

Is there a way to calculate a row in a table field type?

Ex.
Table 1:
SR Item Code QTY Unit Price Total Price
1 Cellphone 2 100 200
2 Tape 3 20 60
3 Knife 1 250 250


Grand Total: 510

Your help would be much appreciated!

Check this thread:

Hi @nabinhait thank you for your suggestion! however I have tried whats on it but still grand total wont appear?

Please refer to this one.

Thanks!

I did not understand what are you trying to do? Is BOQ a child table?
Can you please elaborate with some screenshots?

@nabinhait please refer to the picture. we would like to have the sum for the buying cost of the items to show at the grand total. So we would like to know how to add a column. Hope you get us.

What are the doctype name for the Item table? Assuming it is “BOQ Item” and the fieldname is “items”. I am also assuming the fieldname of Buying Cost is “buying_cost” and for Grand Total is “grand_total”.

Considering the above, you code should look like this:

frappe.ui.form.on("BOQ Item", "buying_cost", function(frm, cdt, cdn) {
	// code for calculate total and set on parent field.
	grand_total = 0;
	$.each(frm.doc.items || [], function(i, d) {
		grand_total += flt(d.buying_cost);
	});
	frm.set_value("grand_total", grand_total);
});
1 Like

@nabinhait It works!!! We are very thankful with this!! We have learned a lot on this one. Thank you.