Costing custom script

Hello,

I need a help.

I have created a costing template, and in that there are different sections.

In the sewing section there are 3 different tables in which the data should be entered(Currency)

So, I want to add the data’s entered in each table.

And finally add all the 3 tables total and display it in the Total2 field.

I have written a custom script, but the data doesn’t gets added.

Please help me.

I have attached the screenshot.

Thanks and Regards,
Sujay

Any help??

First, you should get the total of each table by adding extra field name total in each table
After that, you can go throw this code to check if this total field is changed and add its value to Total2 Field

frappe.ui.form.on("Doctype Name", "fieldnameoftotal", function (frm, cdt, cdn) {
    var total = 0;
    $.each(frm.doc.child_table_field_name || [], function (i, d) {
        total += flt(d.fieldnameoftotal);
    });
    frm.set_value("total2", total);
});

Hello,

Thanks for the response.

Doctype name refers to??

Is it the name of the child table?

I have created a extra field for the Sewing total as TTL1, Labels Total as TTL2 and Trims/accessories total as TTL3

There are many fields in the table, how shall I Include in the script?

These are the field names for Sewing:
Threads
Elastic1
Elastic2
Mobilon Tapes
Piping
Collar
Cuff
Hanger Loops
Others

These are the field names for Label:
Main Label
Care Label
Heatseal
Fit Label
Size Tab
Size Label
Slim Label
Name Label

These are the field names for Trim/Accessories:
Zippers
Black_Gripper
Ziper_Tape
Hood_and_Bar
Buttons_27L_4Hole_1pce_DTM
Buttons_16L_4Hole_8pce_Clear
Rivert
Elets
Belt
Drawcord_Twill_Tape_String
Velour_Tape
Gross_Grain_Tape
Badges
Chain_Guard
Other

Thanks & Regards,
Sujay

Yes the doctype name refers to the child table name

    frappe.ui.form.on("Doctype Name", "ttl1", function (frm, cdt, cdn) {
        var total = 0;
        $.each(frm.doc.sewing || [], function (i, d) {
            total += flt(d.ttl1);
        });
        frm.set_value("total2", total);
    });


 frappe.ui.form.on("Doctype Name", "ttl2", function (frm, cdt, cdn) {
        var total = 0;
        $.each(frm.doc.label || [], function (i, d) {
            total += flt(d.ttl2);
        });
        frm.set_value("total2", total);
    });

frappe.ui.form.on("Doctype Name", "ttl3", function (frm, cdt, cdn) {
        var total = 0;
        $.each(frm.doc.trim_accessories || [], function (i, d) {
            total += flt(d.ttl3);
        });
        frm.set_value("total2", total);
    });

Hello,

Its not working.

I had entered the values but there is no changes in the total fields “TTL1”, “TTL2”, “TTL3”, and “Total2”

Regards,
Sujay

Can you help?

Its not working.

I had entered the values but there is no changes in the total fields “TTL1”, “TTL2”, “TTL3”, and “Total2”

Regards,
Sujay

you must get the total of each table before getting all three total together
Go Throw this code to get the total of each table

frappe.ui.form.on('Sweing Doctype Name', {
    threads: function (frm, cdt, cdn) {
        var row = locals[cdt][cdn];
        if(row.threads){
            frappe.model.set_value(cdt, cdn, "ttl1", row.ttl1 + row.threads);
        }
    }
    .
    .
    .
    .    
    
});

Hello,

This is how I have edited in the custom script.

Its not working.

And when I try to enter the value it shows an message as below:

Please help as I am not familiar with scripts.

Regards,
Sujay

can anyone help

can you help, I have edited as per your instructions, but its not working.

I suppose you want to total the threads property from each row in the 3 tables. Is this your entire custom script? also you are setting the value of ttl1, ttl2, ttl3 on change of the threads property, but who is changing the threads prop? It’s visible only in the first table…

Is this duplicated in Calculations in script - #6 by lasalesi?

You can here use

cur_frm.set_value("total2", total);

instead. But make sure that your parent doctype has a field called “total2”.