Override the tax_amount in quotation

well since i have tried to override the amount original formula and server-side and client-side and it is working but i wanted to make the tax amount calculated so it as the total changing but it didnt work (the tax amount n total calculated correctly in server-side when saving the quotation though) my only problem in client-side
my client script:

function calculateAmount(frm, cdt, cdn) {
    setTimeout(function() {
        var item = locals[cdt][cdn];
        var length = item.length;
        var width = item.width;
        var quantity = item.qty;
        var rate = item.rate;

        // Calculate the item amount
        var amount = length * rate * width * quantity;

        frappe.model.set_value(cdt, cdn, 'amount', amount);

        // Calculate the total of items
        var total = 0;
        frm.doc.items.forEach(function(item) {
            total += item.amount;
        });

        // Calculate the total tax amount based on tax rates
        
        var taxTotal=0
        for (var i = 0; i < frm.doc.taxes.length; i++) {
             var tax = frm.doc.taxes[i];
            var currentTaxAmount = 0;

            if (tax.charge_type === "Actual") {
                // Distribute the tax amount proportionally to each item row
                var actual = tax.tax_amount;
                currentTaxAmount = (total * actual) / frm.doc.net_total || 0.0;
            } else if (tax.charge_type === "On Net Total") {
                currentTaxAmount = (tax.rate / 100.0) * total;
            } else if (tax.charge_type === "On Previous Row Amount") {
                currentTaxAmount = (tax.rate / 100.0) * frm.doc.taxes[i - 1].base_tax_amount;
            } else if (tax.charge_type === "On Previous Row Total") {
                currentTaxAmount = (tax.rate / 100.0) * frm.doc.taxes[cint(tax.row_id) - 1].base_total;
            } else if (tax.charge_type === "On Item Quantity") {
                currentTaxAmount = tax.rate * item.qty;
            }
            console.log(currentTaxAmount)
            taxTotal += currentTaxAmount;
        }
        frappe.model.set_value('Quotation', frm.doc.name, 'total', total);
        // Calculate total related fields
        var grandTotal = total + taxTotal;
        var baseGrandTotal = grandTotal * frm.doc.conversion_rate;
        var roundedTotal = Math.round(grandTotal);

        // Update the document fields
        frappe.model.set_value('Quotation', frm.doc.name, 'grand_total', grandTotal);
        frappe.model.set_value('Quotation', frm.doc.name, 'base_grand_total', baseGrandTotal);
        frappe.model.set_value('Quotation',frm.doc.name,'total_taxes_and_charges',taxTotal)
        frappe.model.set_value('Quotation', frm.doc.name, 'rounded_total', roundedTotal);
        console.log('total',total,"//"
        ,'grandTotal',grandTotal,'baseGrandTotal',baseGrandTotal,'taxTotal',taxTotal
        ,'rounded total',roundedTotal)
    }, 1000);
}

frappe.ui.form.on('Quotation Item', {
    length: function(frm, cdt, cdn) {
        calculateAmount(frm, cdt, cdn);
    },
    width: function(frm, cdt, cdn) {
        calculateAmount(frm, cdt, cdn);
    },
    qty: function(frm, cdt, cdn) {
        calculateAmount(frm, cdt, cdn);
    },
    rate: function(frm, cdt, cdn) {
        calculateAmount(frm, cdt, cdn);
    },
    refresh: function(frm, cdt, cdn) {
        calculateAmount(frm, cdt, cdn);
    },
});


but when i add this line so i can change the tax_amount value everything returns to original formula and it stops overriding for amount total and all

frappe.model.set_value('Sales Taxes and Charges',tax.name,'tax_amount',currentTaxAmount)

hope you can help