Hello @community,
I have a query in child table calculation. I have created following table
I want to calculate Net (%) of particular material w.r.t total net weight. (Here 5940 kg) . So, here, all net weight of particular material is 1980 kg. So Net (%) of each should be 33.33 %. But when ever i add new material entry with it’s respective weight and moisture, then it calculates it’s net (%) but did not change previously calculate net (%) of other materials. It Means, 100 % Net will be modified after entry of second material and so on.
This is My code for calculation.
frappe.ui.form.on(“Material Table Weigh Bridge”, “moisture”, function(frm, cdt, cdn){
var d = locals[cdt][cdn];
frappe.model.set_value(d.doctype, d.name, “net_weight”, d.material_weight - (d.material_weight * (d.moisture/100)));
var material = frm.doc.material;
var total = 0
var net_weight = 0
for(var j in material) {
total = total + material[j].material_weight
net_weight = net_weight + material[j].net_weight;
cur_frm.set_value(“total_weight”,total);
cur_frm.set_value(“net_weight”,net_weight);
var Moisture_Pers = ((frm.doc.total_weight - frm.doc.net_weight) * 100) / frm.doc.total_weight;
cur_frm.set_value(“moisture_weight”,Moisture_Pers);
}
frappe.model.set_value(d.doctype, d.name, “net”, (material[j].net_weight /frm.doc.net_weight) * 100);
});
/ Material table calculation, on event of material weight /
frappe.ui.form.on(“Material Table Weigh Bridge”, “material_weight”, function(frm, cdt, cdn){
var d = locals[cdt][cdn];
frappe.model.set_value(d.doctype, d.name, “net_weight”, d.material_weight - (d.material_weight * (d.moisture/100)));
var material = frm.doc.material;
var total = 0
var net_weight = 0
for(var j in material) {
total = total + material[j].material_weight
net_weight = net_weight + material[j].net_weight;
cur_frm.set_value(“total_weight”,total);
cur_frm.set_value(“net_weight”,net_weight);
var Moisture_Pers = ((frm.doc.total_weight - frm.doc.net_weight) * 100) / frm.doc.total_weight;
cur_frm.set_value(“moisture_weight”,Moisture_Pers);
}
frappe.model.set_value(d.doctype, d.name, “net”, (material[j].net_weight /frm.doc.net_weight) * 100);
});
Any Help will be appreciate.
Thanks,
Hardik Gadesha