I am trying calculate Tax Amount on line items on sales invoice item doctype but its not working

Trying to calculate line Total tax by subtracting net_amount from amount on sales invoice item. Below is my client script, please assist.
frappe.ui.form.on(‘Sales Invoice’, {
refresh(frm) {
// your code here
frappe.ui.form.on(“Sales Invoice Item”, “amount”, function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, “custom_vat_amount”, d.amount-d.net_amount);
refresh_field(“custom_vat_amount”);
});

    frappe.ui.form.on("Sales Invoice Item", "net_amount", function(frm, cdt, cdn) { 
	 var d = locals[cdt][cdn]; 
	 frappe.model.set_value(cdt, cdn, "custom_vat_amount", d.amount-d.net_amount); 
	 refresh_field("custom_vat_amount");  
	  });
	  
}

})

Try this …

frappe.ui.form.on("Sales Invoice Item", {
    net_amount: function(frm,cdt,cdn) {
        var d = locals[cdt][cdn];
        frappe.model.set_value(cdt, cdn, 'custom_vat_amount', d.amount-d.net_amount);
    }
});

But why you want to calculate this… if this is for printing purpose you can make this in custom print format… This will avoid adding a extra field in child doctype…

The Tax Authority in my region demands Sales Invoice Table to display in the following format:

Sales Invoice Table Layout

VAT being the line item tax amount. I am not sure how to do it on print format without a Client Script. Your help will be greatly appreciated

Sales Invoice Table to display in the sense in while printing yes?

Yes on printing

Tried the script you gave me, its not working

There could be an issue here, if a sales line has more than one tax item. E.g. a tax template, with VAT, Catering Levy, and Service Charge.

Hello,

The d.amount is 0 for me, Do you have idea why is that?

ERPNEXT 15.