How to get total of amount from table


tot
how to get total of amount from table to text box

Hi @GhadaEbrahim,

Please check it.

Thank You!

1 Like

@GhadaEbrahim as your problem,

    validate: function(frm) {
        total_sum= 0;
        $.each(frm.doc.payment_details,  function(i,  d) {
            total_sum = total_sum + flt(d.collection_amount);
        });
    } ;

hopes it will work

i tried both scripts but when i click on save its not working


Try this

frappe.ui.form.on('Old Purchase',  {
    validate: function(frm) {
        var total = 0;
        $.each(frm.doc.historical_purchase,  function(i,  d) {
            total += flt(d.collected_amount);
        });
        frm.set_value("debt_collected_amount", total);
         refresh_field("debt_collected_amount");
    } 
});

I have tried it still but its not fetching the total amount from table

Hey @GhadaEbrahim,

I think, you not proper understand.

Plesae match with field and doctype.

Supplier β†’ Parent DocType
frm.doc.payment_details β†’ Child Table field name in Parent DocType
d.collected_amount β†’ Child table field name which you want to calculate in parent field.
debt_collected_amount β†’ Parent Doctype field name.

frappe.ui.form.on('Supplier',  {
    validate: function(frm) {
        var dca = 0;
        $.each(frm.doc.payment_details,  function(i,  d) {
            dca += flt(d.collected_amount);
        });
        frm.set_value("debt_collected_amount", dca);
    } 
});

I hope this helps.
Thank You!

2 Likes

Thanks … its help me.

in same table i need to add function if type of payment = cheque and cheque is not clear don’ t calculate the amount in total amount .


Just Add if condition

frappe.ui.form.on('Old Purchase',  {
    validate: function(frm) {
        var total = 0;
        $.each(frm.doc. payment_details,  function(i,  d) {
            //set your child table field name
            if (d.payment == "cheque" && d.cheque == "clear"){
            total += flt(d.collected_amount);
        }});
        frm.set_value("debt_collected_amount", total);
         refresh_field("debt_collected_amount");
    } 
});