diff --git a/server/job/job-totals.js b/server/job/job-totals.js index c2ec10132..675ea942c 100644 --- a/server/job/job-totals.js +++ b/server/job/job-totals.js @@ -378,28 +378,41 @@ async function CalculateRatesTotals({ job, client }) { (!hasMahwLine || hasMahwLine.act_price !== stlMahw.ttl_amt) ) { //Add a hazardous waste material line in case there isn't one on the estimate. - const newMahwLine = { - line_desc: "Hazardous Waste Removal*", - part_type: "PAS", - oem_partno: null, - db_price: 0, - act_price: stlMahw.ttl_amt, - part_qty: 1, - //mod_lbr_ty: "LAB", - db_hrs: 0, - mod_lb_hrs: 0, - lbr_op: "OP11", - lbr_amt: 0, - op_code_desc: "REMOVE / REPLACE", - tax_part: stlMahw.tax_amt > 0 ? true : false, - db_ref: null, - manual_line: true, - jobid: job.id, - }; - job.joblines.push(newMahwLine); - await client.request(queries.INSERT_NEW_JOB_LINE, { - lineInput: [newMahwLine], - }); + if (hasMahwLine) { + //Update it + job.joblines.forEach((jl) => { + if (jl.id === hasMahwLine.id) { + jl.act_price = stlMahw.ttl_amt; + } + }); + await client.request(queries.UPDATE_JOB_LINE, { + lineId: hasMahwLine.id, + line: { act_price: stlMahw.ttl_amt }, + }); + } else { + const newMahwLine = { + line_desc: "Hazardous Waste Removal*", + part_type: "PAS", + oem_partno: null, + db_price: 0, + act_price: stlMahw.ttl_amt, + part_qty: 1, + //mod_lbr_ty: "LAB", + db_hrs: 0, + mod_lb_hrs: 0, + lbr_op: "OP11", + lbr_amt: 0, + op_code_desc: "REMOVE / REPLACE", + tax_part: stlMahw.tax_amt > 0 ? true : false, + db_ref: null, + manual_line: true, + jobid: job.id, + }; + job.joblines.push(newMahwLine); + await client.request(queries.INSERT_NEW_JOB_LINE, { + lineInput: [newMahwLine], + }); + } } //Materials Scrubbing as required by CCC. @@ -1061,10 +1074,10 @@ async function UpdateJobLines(joblinesToUpdate) { generateUpdateQuery(_.pick(line, ["id", "prt_dsmk_m", "prt_dsmk_p"]), index) ); const query = ` -mutation UPDATE_EST_LINES{ - ${updateQueries} -} -`; + mutation UPDATE_EST_LINES{ + ${updateQueries} + } + `; const result = await adminClient.request(query); }