WIP America

This commit is contained in:
Patrick Fic
2023-01-26 10:58:35 -08:00
parent 66a80e439f
commit 0a60f77bfc
3 changed files with 113 additions and 109 deletions

View File

@@ -402,98 +402,98 @@ function replaceEmpty(someObj, replaceValue = null) {
} }
async function CheckTaxRates(estData, bodyshop) { async function CheckTaxRates(estData, bodyshop) {
//LKQ Check // //LKQ Check
if ( // if (
!estData.parts_tax_rates?.PAL || // !estData.parts_tax_rates?.PAL ||
estData.parts_tax_rates?.PAL?.prt_tax_rt === null || // estData.parts_tax_rates?.PAL?.prt_tax_rt === null ||
estData.parts_tax_rates?.PAL?.prt_tax_rt === 0 // estData.parts_tax_rates?.PAL?.prt_tax_rt === 0
) { // ) {
const res = await confirmDialog( // const res = await confirmDialog(
`Rome Online has detected that there is a missing tax rate for LKQ parts. Pressing OK will set the tax rate to ${bodyshop.bill_tax_rates.state_tax_rate}% and enable the rate. Pressing cancel will keep the tax rate as is.` // `Rome Online has detected that there is a missing tax rate for LKQ parts. Pressing OK will set the tax rate to ${bodyshop.bill_tax_rates.state_tax_rate}% and enable the rate. Pressing cancel will keep the tax rate as is.`
); // );
if (res) { // if (res) {
if (!estData.parts_tax_rates.PAL) { // if (!estData.parts_tax_rates.PAL) {
estData.parts_tax_rates.PAL = { // estData.parts_tax_rates.PAL = {
prt_discp: 0, // prt_discp: 0,
prt_mktyp: true, // prt_mktyp: true,
prt_mkupp: 0, // prt_mkupp: 0,
prt_type: "PAL", // prt_type: "PAL",
}; // };
} // }
estData.parts_tax_rates.PAL.prt_tax_rt = // estData.parts_tax_rates.PAL.prt_tax_rt =
bodyshop.bill_tax_rates.state_tax_rate / 100; // bodyshop.bill_tax_rates.state_tax_rate / 100;
estData.parts_tax_rates.PAL.prt_tax_in = true; // estData.parts_tax_rates.PAL.prt_tax_in = true;
} // }
} // }
//PAC Check // //PAC Check
if ( // if (
!estData.parts_tax_rates?.PAC || // !estData.parts_tax_rates?.PAC ||
estData.parts_tax_rates?.PAC?.prt_tax_rt === null || // estData.parts_tax_rates?.PAC?.prt_tax_rt === null ||
estData.parts_tax_rates?.PAC?.prt_tax_rt === 0 // estData.parts_tax_rates?.PAC?.prt_tax_rt === 0
) { // ) {
const res = await confirmDialog( // const res = await confirmDialog(
`Rome Online has detected that there is a missing tax rate for rechromed parts. Pressing OK will set the tax rate to ${bodyshop.bill_tax_rates.state_tax_rate}% and enable the rate. Pressing cancel will keep the tax rate as is.` // `Rome Online has detected that there is a missing tax rate for rechromed parts. Pressing OK will set the tax rate to ${bodyshop.bill_tax_rates.state_tax_rate}% and enable the rate. Pressing cancel will keep the tax rate as is.`
); // );
if (res) { // if (res) {
if (!estData.parts_tax_rates.PAC) { // if (!estData.parts_tax_rates.PAC) {
estData.parts_tax_rates.PAC = { // estData.parts_tax_rates.PAC = {
prt_discp: 0, // prt_discp: 0,
prt_mktyp: true, // prt_mktyp: true,
prt_mkupp: 0, // prt_mkupp: 0,
prt_type: "PAC", // prt_type: "PAC",
}; // };
} // }
estData.parts_tax_rates.PAC.prt_tax_rt = // estData.parts_tax_rates.PAC.prt_tax_rt =
bodyshop.bill_tax_rates.state_tax_rate / 100; // bodyshop.bill_tax_rates.state_tax_rate / 100;
estData.parts_tax_rates.PAC.prt_tax_in = true; // estData.parts_tax_rates.PAC.prt_tax_in = true;
} // }
} // }
//PAM Check // //PAM Check
if ( // if (
!estData.parts_tax_rates?.PAM || // !estData.parts_tax_rates?.PAM ||
estData.parts_tax_rates?.PAM?.prt_tax_rt === null || // estData.parts_tax_rates?.PAM?.prt_tax_rt === null ||
estData.parts_tax_rates?.PAM?.prt_tax_rt === 0 // estData.parts_tax_rates?.PAM?.prt_tax_rt === 0
) { // ) {
const res = await confirmDialog( // const res = await confirmDialog(
`Rome Online has detected that there is a missing tax rate for remanufactured parts. Pressing OK will set the tax rate to ${bodyshop.bill_tax_rates.state_tax_rate}% and enable the rate. Pressing cancel will keep the tax rate as is.` // `Rome Online has detected that there is a missing tax rate for remanufactured parts. Pressing OK will set the tax rate to ${bodyshop.bill_tax_rates.state_tax_rate}% and enable the rate. Pressing cancel will keep the tax rate as is.`
); // );
if (res) { // if (res) {
if (!estData.parts_tax_rates.PAM) { // if (!estData.parts_tax_rates.PAM) {
estData.parts_tax_rates.PAM = { // estData.parts_tax_rates.PAM = {
prt_discp: 0, // prt_discp: 0,
prt_mktyp: true, // prt_mktyp: true,
prt_mkupp: 0, // prt_mkupp: 0,
prt_type: "PAM", // prt_type: "PAM",
}; // };
} // }
estData.parts_tax_rates.PAM.prt_tax_rt = // estData.parts_tax_rates.PAM.prt_tax_rt =
bodyshop.bill_tax_rates.state_tax_rate / 100; // bodyshop.bill_tax_rates.state_tax_rate / 100;
estData.parts_tax_rates.PAM.prt_tax_in = true; // estData.parts_tax_rates.PAM.prt_tax_in = true;
} // }
} // }
if ( // if (
!estData.parts_tax_rates?.PAR || // !estData.parts_tax_rates?.PAR ||
estData.parts_tax_rates?.PAR?.prt_tax_rt === null || // estData.parts_tax_rates?.PAR?.prt_tax_rt === null ||
estData.parts_tax_rates?.PAR?.prt_tax_rt === 0 // estData.parts_tax_rates?.PAR?.prt_tax_rt === 0
) { // ) {
const res = await confirmDialog( // const res = await confirmDialog(
`Rome Online has detected that there is a missing tax rate for recored parts. Pressing OK will set the tax rate to ${bodyshop.bill_tax_rates.state_tax_rate}% and enable the rate. Pressing cancel will keep the tax rate as is.` // `Rome Online has detected that there is a missing tax rate for recored parts. Pressing OK will set the tax rate to ${bodyshop.bill_tax_rates.state_tax_rate}% and enable the rate. Pressing cancel will keep the tax rate as is.`
); // );
if (res) { // if (res) {
if (!estData.parts_tax_rates.PAR) { // if (!estData.parts_tax_rates.PAR) {
estData.parts_tax_rates.PAR = { // estData.parts_tax_rates.PAR = {
prt_discp: 0, // prt_discp: 0,
prt_mktyp: true, // prt_mktyp: true,
prt_mkupp: 0, // prt_mkupp: 0,
prt_type: "PAR", // prt_type: "PAR",
}; // };
} // }
estData.parts_tax_rates.PAR.prt_tax_rt = // estData.parts_tax_rates.PAR.prt_tax_rt =
bodyshop.bill_tax_rates.state_tax_rate / 100; // bodyshop.bill_tax_rates.state_tax_rate / 100;
estData.parts_tax_rates.PAR.prt_tax_in = true; // estData.parts_tax_rates.PAR.prt_tax_in = true;
} // }
} // }
//IO-1387 If a sublet line is NOT R&R, use the labor tax. If it is, use the sublet tax rate. //IO-1387 If a sublet line is NOT R&R, use the labor tax. If it is, use the sublet tax rate.
//Currently limited to SK shops only. //Currently limited to SK shops only.

View File

@@ -20,7 +20,7 @@ require("dotenv").config({
async function RunTheTest() { async function RunTheTest() {
const bodyshopids = ["6c63a820-542c-497e-8c82-0cc38fb2bbca"]; const bodyshopids = ["6c63a820-542c-497e-8c82-0cc38fb2bbca"];
const bearerToken = `Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImQwNTU5YzU5MDgzZDc3YWI2NDUxOThiNTIxZmM4ZmVmZmVlZmJkNjIiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoiUGF0cmljayBGaWMgKERFVikiLCJodHRwczovL2hhc3VyYS5pby9qd3QvY2xhaW1zIjp7IngtaGFzdXJhLWRlZmF1bHQtcm9sZSI6InVzZXIiLCJ4LWhhc3VyYS1hbGxvd2VkLXJvbGVzIjpbInVzZXIiXSwieC1oYXN1cmEtdXNlci1pZCI6ImhOSjhBRHB0REhRQkRFcXNCOFFNWVRqaURuZjEifSwiaXNzIjoiaHR0cHM6Ly9zZWN1cmV0b2tlbi5nb29nbGUuY29tL2ltZXgtZGV2IiwiYXVkIjoiaW1leC1kZXYiLCJhdXRoX3RpbWUiOjE2NzE1Njc4NzUsInVzZXJfaWQiOiJoTko4QURwdERIUUJERXFzQjhRTVlUamlEbmYxIiwic3ViIjoiaE5KOEFEcHRESFFCREVxc0I4UU1ZVGppRG5mMSIsImlhdCI6MTY3NDE2ODAxOCwiZXhwIjoxNjc0MTcxNjE4LCJlbWFpbCI6InBhdHJpY2tAaW1leC5kZXYiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImZpcmViYX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WFpbCI6InBhdHJpY2tAaW1leC5kZXYiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZW1haWwiOlsicGF0cmlja0BpbWV4LmRldiJdfSwic2lnbl9pbl9wcm92aWRlciI6InBhc3N3b3JkIn19.UGFIwVz_B8Q2m7_lmpT8U4Kq0LG3N-yiv4eRhWybme46y1OCiUpw1dJct-vjunprGTrRXdRlWsEOBEmPULYYbKektcHs60boxQxPty9YghageMcknj14ujoLE98Gz3pN6De4mAQMtqYdWaC20OWrH8wIDGkoFMN7PHhY-c2QWdt-UQH_OUW0dqY0vSSJIlC9QNI3Rjn0N6if40j2jnTF9qgIClRjoWN9OBh1s1qIou6yNchnA2v9ni1Js_kGmMJfixmkTxUau3THCxVQAdPtuwURYRn1Xa8Eo5feo0FLoFbPtylHUZyaoogE7q6ZQkHA2A3ylIxWhYUspyPzkIyf_g`;
const { jobs } = await client.request( const { jobs } = await client.request(
gql` gql`
query GET_JOBS($bodyshopids: [uuid!]!) { query GET_JOBS($bodyshopids: [uuid!]!) {

View File

@@ -1,4 +1,3 @@
const { objectLength } = require("@oozcitak/util");
const Dinero = require("dinero.js"); const Dinero = require("dinero.js");
const queries = require("../graphql-client/queries"); const queries = require("../graphql-client/queries");
const GraphQLClient = require("graphql-request").GraphQLClient; const GraphQLClient = require("graphql-request").GraphQLClient;
@@ -380,6 +379,7 @@ function CalculatePartsTotals(jobLines, parts_tax_rates) {
const ret = jl.reduce( const ret = jl.reduce(
(acc, value) => { (acc, value) => {
console.log(JSON.stringify(acc, null, 2));
switch (value.part_type) { switch (value.part_type) {
case "PAS": case "PAS":
case "PASL": case "PASL":
@@ -535,7 +535,7 @@ function CalculatePartsTotals(jobLines, parts_tax_rates) {
//Check if there's any parts in this part type. //Check if there's any parts in this part type.
if (ret.parts.list[key] !== undefined) { if (ret.parts.list[key] !== undefined) {
markup = ret.parts.list[key].total.percentage( markup = ret.parts.list[key].total.percentage(
parts_tax_rates[key].prt_mkupp parts_tax_rates[key].prt_mkupp * 100 //Seems that mark up is written as decimal not %.
); );
} }
} }
@@ -543,14 +543,15 @@ function CalculatePartsTotals(jobLines, parts_tax_rates) {
adjustments[key] = adjustment; adjustments[key] = adjustment;
}); });
Object.keys(adjustments).forEach((key) => { //Temporarily commenting this out since these totals appear to be already included in the calculation.
if (ret.parts.list[key] !== undefined) { // Object.keys(adjustments).forEach((key) => {
ret.parts.list[key].total = ret.parts.list[key].total.add( // if (ret.parts.list[key] !== undefined) {
adjustments[key] // ret.parts.list[key].total = ret.parts.list[key].total.add(
); // adjustments[key]
ret.parts.subtotal = ret.parts.subtotal.add(adjustments[key]); // );
} // ret.parts.subtotal = ret.parts.subtotal.add(adjustments[key]);
}); // }
// });
return { return {
adjustments, adjustments,
@@ -575,19 +576,12 @@ 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") {
// return (
// 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))
// );
// } 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.part_type === null && (jobLine.act_price || 0 > 0)) || (jobLine.part_type === null && (jobLine.act_price || 0 > 0)) ||
(jobLine.db_ref && jobLine.db_ref.startsWith("9360"))) && //This ref works in Canada, but DB_REFS in the US do not fill in. (jobLine.db_ref && jobLine.db_ref.startsWith("9360"))) && //This ref works in Canada, but DB_REFS in the US do not fill in.
!isPaintOrShopMat !isPaintOrShopMat
); );
//}
} }
function CalculateAdditional(job) { function CalculateAdditional(job) {
@@ -800,6 +794,16 @@ function DiscountNotAlreadyCounted(jobline, joblines) {
) )
return true; 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); const ParentLine = joblines.find((j) => j.unq_seq === jobline.line_ref);
return ParentLine && !(ParentLine.prt_dsmk_m && ParentLine.prt_dsmk_m !== 0); return ParentLine && !(ParentLine.prt_dsmk_m && ParentLine.prt_dsmk_m !== 0);