How to make field equals the sum of 2 other values by client script

Hi there,
I have 4 fields: “direct_cost”, “sample_cost”, “second_degree” and “base_total_cost”

I want to sum (sample_cost + second_degree * base_total_cost) + base_total_cost= direct_cost
can you help me to get it, please?
Thanks a lot for help

Create custom script like this

  frappe.ui.form.on("Sales Order", {
    refresh: function(frm) {
        frm.set_value("outstanding", (frm.doc.rounded_total - frm.doc.advance_paid));
        // use the __islocal value of doc, to check if the doc is saved or not
  frm.set_df_property("outstanding", "read_only", frm.doc.__islocal ? 0 : 1);
    }
});