Improve backwards compatibility for job totals calculations.
This commit is contained in:
@@ -13,9 +13,11 @@ export default function JobTotalsTableParts({ job }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const insuranceAdjustments = useMemo(() => {
|
const insuranceAdjustments = useMemo(() => {
|
||||||
|
if (!job.job_totals) return [];
|
||||||
|
if (!job.job_totals?.parts?.adjustments) return [];
|
||||||
const adjs = [];
|
const adjs = [];
|
||||||
Object.keys(job.job_totals.parts.adjustments).forEach((key) => {
|
Object.keys(job.job_totals?.parts?.adjustments).forEach((key) => {
|
||||||
if (Dinero(job.job_totals.parts.adjustments[key]).getAmount() !== 0) {
|
if (Dinero(job.job_totals?.parts?.adjustments[key]).getAmount() !== 0) {
|
||||||
adjs.push({
|
adjs.push({
|
||||||
id: key,
|
id: key,
|
||||||
amount: Dinero(job.job_totals.parts.adjustments[key]),
|
amount: Dinero(job.job_totals.parts.adjustments[key]),
|
||||||
@@ -25,10 +27,6 @@ export default function JobTotalsTableParts({ job }) {
|
|||||||
|
|
||||||
return adjs;
|
return adjs;
|
||||||
}, [job.job_totals.parts.adjustments]);
|
}, [job.job_totals.parts.adjustments]);
|
||||||
console.log(
|
|
||||||
"🚀 ~ file: job-totals.table.parts.component.jsx:16 ~ insuranceAdjustments ~ insuranceAdjustments",
|
|
||||||
insuranceAdjustments
|
|
||||||
);
|
|
||||||
|
|
||||||
const data = useMemo(() => {
|
const data = useMemo(() => {
|
||||||
return Object.keys(job.job_totals.parts.parts.list)
|
return Object.keys(job.job_totals.parts.parts.list)
|
||||||
|
|||||||
103
job-totals-testing-util.js
Normal file
103
job-totals-testing-util.js
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
const path = require("path");
|
||||||
|
const Dinero = require("dinero.js");
|
||||||
|
const { gql } = require("graphql-request");
|
||||||
|
const queries = require("./server/graphql-client/queries");
|
||||||
|
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||||
|
const logger = require("./server/utils/logger");
|
||||||
|
const AxiosLib = require("axios").default;
|
||||||
|
const axios = AxiosLib.create();
|
||||||
|
|
||||||
|
// Dinero.defaultCurrency = "USD";
|
||||||
|
// Dinero.globalLocale = "en-CA";
|
||||||
|
Dinero.globalRoundingMode = "HALF_EVEN";
|
||||||
|
const client = require("./server/graphql-client/graphql-client").client;
|
||||||
|
require("dotenv").config({
|
||||||
|
path: path.resolve(
|
||||||
|
process.cwd(),
|
||||||
|
`.env.${process.env.NODE_ENV || "development"}`
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
async function RunTheTest() {
|
||||||
|
const bodyshopids = ["6c63a820-542c-497e-8c82-0cc38fb2bbca"];
|
||||||
|
const bearerToken = `Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImQwNTU5YzU5MDgzZDc3YWI2NDUxOThiNTIxZmM4ZmVmZmVlZmJkNjIiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoiUGF0cmljayBGaWMgKERFVikiLCJodHRwczovL2hhc3VyYS5pby9qd3QvY2xhaW1zIjp7IngtaGFzdXJhLWRlZmF1bHQtcm9sZSI6InVzZXIiLCJ4LWhhc3VyYS1hbGxvd2VkLXJvbGVzIjpbInVzZXIiXSwieC1oYXN1cmEtdXNlci1pZCI6ImhOSjhBRHB0REhRQkRFcXNCOFFNWVRqaURuZjEifSwiaXNzIjoiaHR0cHM6Ly9zZWN1cmV0b2tlbi5nb29nbGUuY29tL2ltZXgtZGV2IiwiYXVkIjoiaW1leC1kZXYiLCJhdXRoX3RpbWUiOjE2NzE1Njc4NzUsInVzZXJfaWQiOiJoTko4QURwdERIUUJERXFzQjhRTVlUamlEbmYxIiwic3ViIjoiaE5KOEFEcHRESFFCREVxc0I4UU1ZVGppRG5mMSIsImlhdCI6MTY3NDE2ODAxOCwiZXhwIjoxNjc0MTcxNjE4LCJlbWFpbCI6InBhdHJpY2tAaW1leC5kZXYiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZW1haWwiOlsicGF0cmlja0BpbWV4LmRldiJdfSwic2lnbl9pbl9wcm92aWRlciI6InBhc3N3b3JkIn19.an7UXCMA9VXoPiGAYlDqB_Kn0HREeomVPEh7fl7OHo_eLoShLdvzPo0NlXnDCuhZXD1dUZj-cCZw-pcwKoa05cDoGRTmmgGLaqh43bqqnxOupkb90aHjYzw6Nuz1Cn-PEqkqqZRDbnAbpHWp_2Iaj4zBu1mEQ8_D9rvNuOoH_73-FnQwT4uyT0-SNUlV_9ajn1RprxeaAxk5rahL89eBDi4NF3h24cbjh15pfd4pkEk6H6bI09PuXewA_2Kl8krKMjoOvCA5OA0K7echV1vC4Z2gIHTdvdYKuRUUFK9J7rR5nMGUMVMjmkEEJPTkZzZ4vzsBJyD-BDQmB6bAF2S6Mw`;
|
||||||
|
const { jobs } = await client.request(
|
||||||
|
gql`
|
||||||
|
query GET_JOBS($bodyshopids: [uuid!]!) {
|
||||||
|
jobs(
|
||||||
|
where: { shopid: { _in: $bodyshopids } }
|
||||||
|
order_by: { created_at: desc }
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
ro_number
|
||||||
|
job_totals
|
||||||
|
cieca_ttl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
{
|
||||||
|
bodyshopids,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const results = [];
|
||||||
|
|
||||||
|
for (const job of jobs) {
|
||||||
|
try {
|
||||||
|
await axios.post(
|
||||||
|
`http://localhost:4000/job/totalsssu`,
|
||||||
|
{ id: job.id },
|
||||||
|
{ headers: { Authorization: bearerToken } }
|
||||||
|
);
|
||||||
|
const { jobs_by_pk: newjob } = await client.request(
|
||||||
|
gql`
|
||||||
|
query GET_JOBS($id: uuid!) {
|
||||||
|
jobs_by_pk(id: $id) {
|
||||||
|
id
|
||||||
|
ro_number
|
||||||
|
cieca_ttl
|
||||||
|
job_totals
|
||||||
|
ownr_fn
|
||||||
|
ownr_ln
|
||||||
|
ownr_co_nm
|
||||||
|
ins_co_nm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
{
|
||||||
|
id: job.id,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = {
|
||||||
|
id: newjob.id,
|
||||||
|
owner: `${newjob.ownr_fn} ${newjob.ownr_ln} ${job.ownr_co_nm || ""}`,
|
||||||
|
ins_co: newjob.ins_co_nm,
|
||||||
|
};
|
||||||
|
|
||||||
|
const calcTotal = newjob.job_totals.totals.total_repairs.amount;
|
||||||
|
const ttlTotal = newjob.cieca_ttl.data.g_ttl_amt * 100;
|
||||||
|
result.difference = Math.abs(calcTotal - ttlTotal) / 100;
|
||||||
|
|
||||||
|
if (Math.abs(calcTotal - ttlTotal) > 5) {
|
||||||
|
//Diff is greater than 5 cents. Fail it.
|
||||||
|
result.result = "***FAIL***";
|
||||||
|
} else {
|
||||||
|
result.result = "PASS";
|
||||||
|
}
|
||||||
|
console.log(`${result.result} => RO ${job.ro_number}`);
|
||||||
|
|
||||||
|
results.push(result);
|
||||||
|
} catch (error) {
|
||||||
|
results.push({
|
||||||
|
ro_number: job.ro_number,
|
||||||
|
id: job.id,
|
||||||
|
result: "**503 FAILURE**",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.table(results);
|
||||||
|
}
|
||||||
|
|
||||||
|
RunTheTest();
|
||||||
@@ -261,8 +261,8 @@ function CalculateRatesTotals(ratesList) {
|
|||||||
//Otherwise, calculate them and add them to the default MAPA and MASH centers.
|
//Otherwise, calculate them and add them to the default MAPA and MASH centers.
|
||||||
let hasMapaLine = false;
|
let hasMapaLine = false;
|
||||||
let hasMashLine = false;
|
let hasMashLine = false;
|
||||||
let mapaOpCodes = ParseCalopCode(ratesList.materials["mapa"].cal_opcode);
|
let mapaOpCodes = ParseCalopCode(ratesList.materials["mapa"]?.cal_opcode);
|
||||||
let mashOpCodes = ParseCalopCode(ratesList.materials["mash"].cal_opcode);
|
let mashOpCodes = ParseCalopCode(ratesList.materials["mash"]?.cal_opcode);
|
||||||
|
|
||||||
jobLines.forEach((item) => {
|
jobLines.forEach((item) => {
|
||||||
//IO-1317 Use the lines on the estimate if they exist instead.
|
//IO-1317 Use the lines on the estimate if they exist instead.
|
||||||
@@ -312,7 +312,7 @@ function CalculateRatesTotals(ratesList) {
|
|||||||
ret.mapa.hours = ret.mapa.hours + item.mod_lb_hrs;
|
ret.mapa.hours = ret.mapa.hours + item.mod_lb_hrs;
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
if (mashOpCodes.includes(item.lbr_op)) {
|
if (mashOpCodes.length === 0 || mashOpCodes.includes(item.lbr_op)) {
|
||||||
// Added when processing CIECA ID 14A60015 to have materials match.
|
// Added when processing CIECA ID 14A60015 to have materials match.
|
||||||
ret.mash.hours = ret.mash.hours + item.mod_lb_hrs; //Apparently there may be an exclusion for glass hours in BC.
|
ret.mash.hours = ret.mash.hours + item.mod_lb_hrs; //Apparently there may be an exclusion for glass hours in BC.
|
||||||
}
|
}
|
||||||
@@ -370,6 +370,8 @@ function CalculateRatesTotals(ratesList) {
|
|||||||
ret.subtotal = subtotal;
|
ret.subtotal = subtotal;
|
||||||
ret.rates_subtotal = rates_subtotal;
|
ret.rates_subtotal = rates_subtotal;
|
||||||
|
|
||||||
|
ret.mapa.hasMapaLine = hasMapaLine;
|
||||||
|
ret.mash.hasMashLine = hasMashLine;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -573,18 +575,19 @@ function IsAdditionalCost(jobLine) {
|
|||||||
const isPaintOrShopMat =
|
const isPaintOrShopMat =
|
||||||
jobLine.db_ref === "936008" || jobLine.db_ref === "936007";
|
jobLine.db_ref === "936008" || jobLine.db_ref === "936007";
|
||||||
|
|
||||||
if (process.env.COUNTRY === "USA") {
|
// if (process.env.COUNTRY === "USA") {
|
||||||
return (
|
// return (
|
||||||
jobLine.lbr_op === "OP13" || //Added to resolve manual job lines coming into other totals because they have no reference.
|
// jobLine.lbr_op === "OP13" || //Added to resolve manual job lines coming into other totals because they have no reference.
|
||||||
(jobLine.part_type === null && (jobLine.act_price || 0 > 0))
|
// (jobLine.part_type === null && (jobLine.act_price || 0 > 0))
|
||||||
);
|
// );
|
||||||
} else {
|
// } else {
|
||||||
return (
|
return (
|
||||||
(jobLine.lbr_op === "OP13" || //Added to resolve manual job lines coming into other totals because they have no reference.
|
(jobLine.lbr_op === "OP13" || //Added to resolve manual job lines coming into other totals because they have no reference.
|
||||||
(jobLine.db_ref && jobLine.db_ref.startsWith("9360"))) && //This ref works in Canada, but DB_REFS in the US do not fill in.
|
(jobLine.part_type === null && (jobLine.act_price || 0 > 0)) ||
|
||||||
!isPaintOrShopMat
|
(jobLine.db_ref && jobLine.db_ref.startsWith("9360"))) && //This ref works in Canada, but DB_REFS in the US do not fill in.
|
||||||
);
|
!isPaintOrShopMat
|
||||||
}
|
);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
function CalculateAdditional(job) {
|
function CalculateAdditional(job) {
|
||||||
@@ -738,18 +741,21 @@ function CalculateTaxesTotals(job, otherTotals) {
|
|||||||
.add(
|
.add(
|
||||||
otherTotals.additional.storage.percentage((job.tax_str_rt || 0) * 100)
|
otherTotals.additional.storage.percentage((job.tax_str_rt || 0) * 100)
|
||||||
)
|
)
|
||||||
.add(additionalItemsTax)
|
.add(additionalItemsTax),
|
||||||
.add(
|
// .add(
|
||||||
process.env.COUNTRY === "USA"
|
// 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
|
// ? otherTotals.rates.mapa.total.percentage(
|
||||||
.percentage((job.tax_paint_mat_rt || 0) * 100)
|
// (job.tax_paint_mat_rt || 0) * 100
|
||||||
.add(
|
// )
|
||||||
otherTotals.rates.mash.total.percentage(
|
// : Dinero()
|
||||||
(job.tax_paint_mat_rt || 0) * 100
|
// )
|
||||||
)
|
// .add(
|
||||||
)
|
// otherTotals.rates.mash.hasMashLine === false //If parts and materials were not added as lines, we must calculate the taxes on them.
|
||||||
: Dinero()
|
// ? otherTotals.rates.mash.total.percentage(
|
||||||
),
|
// (job.tax_paint_mat_rt || 0) * 100
|
||||||
|
// )
|
||||||
|
// : Dinero()
|
||||||
|
// )
|
||||||
// .add(otherTotals.additional.pvrt),
|
// .add(otherTotals.additional.pvrt),
|
||||||
local_tax: subtotal.percentage((job.local_tax_rate || 0) * 100),
|
local_tax: subtotal.percentage((job.local_tax_rate || 0) * 100),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user