From 25b89d191b389b146c303664ae51e72152ba5949 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 26 Jan 2023 17:01:12 -0800 Subject: [PATCH] Futher calculations refinments and QBD testing. --- .../jobs-available-table.container.jsx | 4 +- .../jobs-detail-rates.parts.component.jsx | 110 +++++++++--------- job-totals-testing-util.js | 16 ++- server/job/job-totals.js | 60 +++++----- 4 files changed, 104 insertions(+), 86 deletions(-) diff --git a/client/src/components/jobs-available-table/jobs-available-table.container.jsx b/client/src/components/jobs-available-table/jobs-available-table.container.jsx index bde60ffef..dfe9f604e 100644 --- a/client/src/components/jobs-available-table/jobs-available-table.container.jsx +++ b/client/src/components/jobs-available-table/jobs-available-table.container.jsx @@ -520,7 +520,7 @@ async function ResolveCCCLineIssues(estData, bodyshop) { //TODO Ensure that this doesnt get violated //This needs to be done before cleansing unq_seq since some misc prices could move over. estData.joblines.data.forEach((line) => { - if (line.misc_amt && line.misc_amt > 0) { + if (line.misc_amt && line.misc_amt !== 0) { line.act_price = line.misc_amt; line.part_type = "PAS"; line.tax_part = line.misc_tax; @@ -546,6 +546,8 @@ async function ResolveCCCLineIssues(estData, bodyshop) { ...estData.joblines.data[nonRefLineIndex + 1], act_price: null, db_price: null, + prt_dsmk_p: 0, + prt_dsmk_m: 0, }; }); } diff --git a/client/src/components/jobs-detail-rates/jobs-detail-rates.parts.component.jsx b/client/src/components/jobs-detail-rates/jobs-detail-rates.parts.component.jsx index d75d706d4..fcd56740d 100644 --- a/client/src/components/jobs-detail-rates/jobs-detail-rates.parts.component.jsx +++ b/client/src/components/jobs-detail-rates/jobs-detail-rates.parts.component.jsx @@ -29,7 +29,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "PAA", "prt_discp"]} > - + - + - + ); }} @@ -79,7 +79,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "PAC", "prt_discp"]} > - + - + - + ); }} @@ -129,7 +129,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "PAL", "prt_discp"]} > - + - + - + ); }} @@ -179,7 +179,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "PAG", "prt_discp"]} > - + - + - + ); }} @@ -229,7 +229,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "PAM", "prt_discp"]} > - + - + - + ); }} @@ -279,7 +279,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "PAN", "prt_discp"]} > - + - + - + ); }} @@ -329,7 +329,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "PAO", "prt_discp"]} > - + - + - + ); }} @@ -379,7 +379,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "PAP", "prt_discp"]} > - + - + - + ); }} @@ -429,7 +429,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "PAR", "prt_discp"]} > - + - + - + ); }} @@ -479,7 +479,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "PAS", "prt_discp"]} > - + - + - + ); }} @@ -529,7 +529,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "PASL", "prt_discp"]} > - + - + - + ); }} @@ -579,7 +579,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "CCDR", "prt_discp"]} > - + - + - + @@ -613,7 +613,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "CCF", "prt_discp"]} > - + - + - + @@ -647,7 +647,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "CCM", "prt_discp"]} > - + - + - + @@ -681,7 +681,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "CCC", "prt_discp"]} > - + - + - + @@ -715,7 +715,7 @@ export function JobsDetailRatesParts({ label={t("jobs.fields.parts_tax_rates.prt_discp")} name={["parts_tax_rates", "CCD", "prt_discp"]} > - + - + - + - + - + - + - + - + - + - + diff --git a/job-totals-testing-util.js b/job-totals-testing-util.js index 0e1f419d0..bbf13d99f 100644 --- a/job-totals-testing-util.js +++ b/job-totals-testing-util.js @@ -20,7 +20,7 @@ require("dotenv").config({ async function RunTheTest() { const bodyshopids = ["6c63a820-542c-497e-8c82-0cc38fb2bbca"]; - const bearerToken = `Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImQwNTU5YzU5MDgzZDc3YWI2NDUxOThiNTIxZmM4ZmVmZmVlZmJkNjIiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoiUGF0cmljayBGaWMgKERFVikiLCJodHRwczovL2hhc3VyYS5pby9qd3QvY2xhaW1zIjp7IngtaGFzdXJhLWRlZmF1bHQtcm9sZSI6InVzZXIiLCJ4LWhhc3VyYS1hbGxvd2VkLXJvbGVzIjpbInVzZXIiXSwieC1oYXN1cmEtdXNlci1pZCI6ImhOSjhBRHB0REhRQkRFcXNCOFFNWVRqaURuZjEifSwiaXNzIjoiaHR0cHM6Ly9zZWN1cmV0b2tlbi5nb29nbGUuY29tL2ltZXgtZGV2IiwiYXVkIjoiaW1leC1kZXYiLCJhdXRoX3RpbWUiOjE2NzQ1OTgwMTEsInVzZXJfaWQiOiJoTko4QURwdERIUUJERXFzQjhRTVlUamlEbmYxIiwic3ViIjoiaE5KOEFEcHRESFFCREVxc0I4UU1ZVGppRG5mMSIsImlhdCI6MTY3NDY3Mz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5KOEFEcHRESFFCREVxc0I4UU1ZVGppRG5mMSIsImlhdCI6MTY3NDc3ODM3NCwiZXhwIjoxNjc0NzgxOTc0LCJlbWFpbCI6InBhdHJpY2tAaW1leC5kZXYiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZW1haWwiOlsicGF0cmlja0BpbWV4LmRldiJdfSwic2lnbl9pbl9wcm92aWRlciI6InBhc3N3b3JkIn19.d6uLsEMeaG68m5jzageh5Wlesp-nPNARwic6QKZFoJbAk20Lr2nO7DOUQcsPlFQyFeoGTEG8mugkAfPAVkI76a7SlrgxsjesncO5DPfpKXPr3dIacmzW832ZYayMNZQFoWLmjYxI7WSEXhzxwaKOKdrjFYUQVo4urMyB1IiaNeZAUhIHhE6tTcxhbfHt7YYkMlWriKCTXfu-9L6EEkSXBOH1EaDOWLJ5bqjBdFjwgywalB8nShsmSi0F1AWoaXzXxVKb2RiPzRjByq2VbRhUXzV2EJIEG9Glxr1aQ7S8x-RlRkdgQgN1OHO3P3-SbMoz-7KZEjpc7H-FB1Dj5iXLhQ`; const { jobs } = await client.request( gql` query GET_JOBS($bodyshopids: [uuid!]!) { @@ -98,6 +98,20 @@ async function RunTheTest() { } console.table(results); + const summary = results.reduce( + (acc, val) => { + if (val.result === "PASS") { + return { ...acc, pass: acc.pass + 1 }; + } else { + return { ...acc, fail: acc.fail + 1 }; + } + }, + { pass: 0, fail: 0 } + ); + console.log( + "Pass Rate: ", + ((summary.pass / (summary.fail + summary.pass)) * 100).toFixed(1) + ); } RunTheTest(); diff --git a/server/job/job-totals.js b/server/job/job-totals.js index b0b5dbb6f..7f16ff1f3 100644 --- a/server/job/job-totals.js +++ b/server/job/job-totals.js @@ -180,8 +180,6 @@ async function AutoAddAtsIfRequired({ job, client }) { }); job.joblines[atsLineIndex].act_price = atsAmount; } - - console.log(job.jobLines); } } @@ -379,7 +377,6 @@ function CalculatePartsTotals(jobLines, parts_tax_rates) { const ret = jl.reduce( (acc, value) => { - console.log(JSON.stringify(acc, null, 2)); switch (value.part_type) { case "PAS": case "PASL": @@ -524,7 +521,11 @@ function CalculatePartsTotals(jobLines, parts_tax_rates) { //Check if there's any parts in this part type. if (ret.parts.list[key] !== undefined) { disc = ret.parts.list[key].total - .percentage(parts_tax_rates[key].prt_discp) + .percentage( + Math.abs(parts_tax_rates[key].prt_discp) > 1 + ? parts_tax_rates[key].prt_discp + : parts_tax_rates[key].prt_discp * 100 + ) .multiply(-1); } } @@ -535,7 +536,9 @@ function CalculatePartsTotals(jobLines, parts_tax_rates) { //Check if there's any parts in this part type. if (ret.parts.list[key] !== undefined) { markup = ret.parts.list[key].total.percentage( - parts_tax_rates[key].prt_mkupp * 100 //Seems that mark up is written as decimal not %. + Math.abs(parts_tax_rates[key].prt_mkupp) > 1 + ? parts_tax_rates[key].prt_mkupp + : parts_tax_rates[key].prt_mkupp * 100 //Seems that mark up is written as decimal not %. ); } } @@ -736,20 +739,20 @@ function CalculateTaxesTotals(job, otherTotals) { otherTotals.additional.storage.percentage((job.tax_str_rt || 0) * 100) ) .add(additionalItemsTax), - // .add( - // otherTotals.rates.mapa.hasMapaLine === false //If parts and materials were not added as lines, we must calculate the taxes on them. - // ? otherTotals.rates.mapa.total.percentage( - // (job.tax_paint_mat_rt || 0) * 100 - // ) - // : Dinero() - // ) - // .add( - // otherTotals.rates.mash.hasMashLine === false //If parts and materials were not added as lines, we must calculate the taxes on them. - // ? otherTotals.rates.mash.total.percentage( - // (job.tax_paint_mat_rt || 0) * 100 - // ) - // : Dinero() - // ) + // .add( + // otherTotals.rates.mapa.hasMapaLine === false //If parts and materials were not added as lines, we must calculate the taxes on them. + // ? otherTotals.rates.mapa.total.percentage( + // (job.tax_paint_mat_rt || 0) * 100 + // ) + // : Dinero() + // ) + // .add( + // otherTotals.rates.mash.hasMashLine === false //If parts and materials were not added as lines, we must calculate the taxes on them. + // ? otherTotals.rates.mash.total.percentage( + // (job.tax_paint_mat_rt || 0) * 100 + // ) + // : Dinero() + // ), // .add(otherTotals.additional.pvrt), local_tax: subtotal.percentage((job.local_tax_rate || 0) * 100), }; @@ -787,6 +790,15 @@ function CalculateTaxesTotals(job, otherTotals) { exports.default = Totals; function DiscountNotAlreadyCounted(jobline, joblines) { + //CCC already factors in the discount. If the difference between the 2 is exactly the discount, it's all good. + if ( + Math.round( + (jobline.prt_dsmk_m / (jobline.act_price - jobline.prt_dsmk_m)) * 100 + ) === Math.abs(jobline.prt_dsmk_p) + ) { + return false; + } + if ( //If it's not a discount line, then it definitely hasn't been counted yet. jobline.db_ref !== "900510" && @@ -794,16 +806,6 @@ function DiscountNotAlreadyCounted(jobline, joblines) { ) return true; - if (jobline.unq_seq === '68') { - console.log("stophere"); - } - //CCC already factors in the discount. If the difference between the 2 is exactly the discount, it's all good. - if ( - Math.round(jobline.prt_dsmk_m / jobline.act_price - jobline.prt_dsmk_m) === - Math.abs(jobline.prt_dsmk_p) - ) - return false; - const ParentLine = joblines.find((j) => j.unq_seq === jobline.line_ref); return ParentLine && !(ParentLine.prt_dsmk_m && ParentLine.prt_dsmk_m !== 0);