From d5b8ea3ac56d1307f7ad332e139feb75082e5568 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 19 Aug 2021 14:24:12 -0700 Subject: [PATCH] IO-1317 --- server/job/job-totals.js | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/server/job/job-totals.js b/server/job/job-totals.js index d61ea6a82..f06071d9b 100644 --- a/server/job/job-totals.js +++ b/server/job/job-totals.js @@ -157,7 +157,28 @@ function CalculateRatesTotals(ratesList) { }, }; + //Determine if there are MAPA and MASH lines already on the estimate. + //If there are, don't do anything extra (mitchell estimate) + //Otherwise, calculate them and add them to the default MAPA and MASH centers. + let hasMapaLine = false; + let hasMashLine = false; + jobLines.forEach((item) => { + //IO-1317 Use the lines on the estimate if they exist instead. + if (item.db_ref === "936008") { + //If either of these DB REFs change, they also need to change in job-totals/job-costing calculations. + hasMapaLine = true; + ret["mapa"].total = Dinero({ + amount: Math.round((item.act_price || 0) * 100), + }); + } + if (item.db_ref === "936007") { + hasMashLine = true; + ret["mash"].total = Dinero({ + amount: Math.round((item.act_price || 0) * 100), + }); + } + if (item.mod_lbr_ty) { //There's a labor type, assign the hours. ret[item.mod_lbr_ty.toLowerCase()].hours = @@ -173,11 +194,24 @@ function CalculateRatesTotals(ratesList) { let subtotal = Dinero({ amount: 0 }); let rates_subtotal = Dinero({ amount: 0 }); + + console.log("Has mapa, mash", hasMapaLine, hasMashLine); + for (const property in ret) { - ret[property].total = Dinero({ - amount: Math.round((ret[property].rate || 0) * 100), - }).multiply(ret[property].hours); + //Skip calculating mapa and mash if we got the amounts. + if ( + !( + (property === "mapa" && hasMapaLine) || + (property === "mash" && hasMashLine) + ) + ) { + ret[property].total = Dinero({ + amount: Math.round((ret[property].rate || 0) * 100), + }).multiply(ret[property].hours); + } + subtotal = subtotal.add(ret[property].total); + if (property !== "mapa" && property !== "mash") rates_subtotal = rates_subtotal.add(ret[property].total); }