How to calculate sum of column of a child table in a parent field

HI. i am new to the script & i want to calculate sum of total packing charges column of a child table into a parent doctype field.

frappe.ui.form.on(“Sales Invoice Item”, {
qty: function(frm,cdt,cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, ‘total_packing_charges’, (d.qty * d.packing_charges));
console.log(“message”);
frm.refresh_field(‘Sales Invoice Item’);
}
});

frappe.ui.form.on(“Sales Invoice”, “refresh”, function(frm, cdt, cdn) {
//code for calculate total and set on parent field.
additional_discount_amount = 0;
$.each(frm.doc.items || [], function(i, d) {
additional_discount_amount += flt(d.total_packing_charges);
console.log(“hello”);
});
frm.set_value(“additional_discount_amount”, additional_discount_amount);
});

the above script is to calculate total packing charges of a child table.
and i want now sum of total packing charges into an additional discount amount field of parent doctype.
please help

Try :
var additional_discount_amount = 0;

Thanks Vesper_solutions
It worked.