How to Calculate Grand Total in Custom Doctype?

Hello everyone,

I created a Custom doctype for (Bill of Quantity), Please I need your help to Calculate the grand total amount.

Hi

let calc_grand_total = function(frm){
	var grand_total = 0;
	var tbl = frm.doc.items || [];
	var tbl_lenght = tbl.length;
		for (var i = 0, len = tbl_lenght; i < len; i++) {
	                   grand_total = grand_total + tbl[i].amount                                 
		}
	frm.set_value('grand_total',grand_total)
}					

use this function in validate function

@MiM thanks, I will try it

@MiM Thanks, I will try it.

Hello,
It did not work. Please can you explain to me more, how i can use the function in validate function?.

Hi,
with the code above
write this code


frappe.ui.form.on('Bill Of Quantity', {
	 validate: function(frm) {
              calc_grand_total(frm)
	 }
});

let calc_grand_total = function(frm){
	var grand_total = 0;
	var tbl = frm.doc.items || [];
	var tbl_lenght = tbl.length;
		for (var i = 0, len = tbl_lenght; i < len; i++) {
	                   grand_total = grand_total + tbl[i].amount                                 
		}
	frm.set_value('grand_total',grand_total)
}

try this code but make sure of fields names

1 Like

Hello,

It works very well. Thank you very much i really appreciate. God bless you.

@MiM

Hello,

It works very well. Thank you very much i really appreciate. God bless you.