+
+ {t("jobs.labels.partstotal")}
+
+
+
+ {Object.keys(job.job_totals.parts.parts.list).map(
+ (key, idx) => (
+
+ | {t(`jobs.fields.${key.toLowerCase()}`)} |
+
+ {Dinero(
+ job.job_totals.parts.parts.list[key].total
+ ).toFormat()}
+ |
+
+ )
+ )}
+
+ | {t("jobs.labels.partstotal")} |
+
+
+ {Dinero(job.job_totals.parts.parts.total).toFormat()}
+
+ |
+
+
+ | {t("jobs.labels.subletstotal")} |
+
+ {Dinero(job.job_totals.parts.sublets.total).toFormat()}
+ |
+
+
+
+ | {t("jobs.labels.additionaltotal")} |
+
+ {Dinero(job.job_totals.additional).toFormat()}
+ |
+
+
-
Final", ret);
res.status(200).json(ret);
} catch (error) {
console.log("error", error);
res.status(400).send(JSON.stringify(error));
}
};
-
-function CalculateAdditional(job) {
- return job.joblines
- .filter(
- (jl) =>
- !jl.removed &&
- (jl.lbr_op === "OP2" ||
- jl.lbr_op === "OP3" ||
- jl.lbr_op === "OP4" ||
- jl.lbr_op === "OP5" ||
- jl.lbr_op === "OP6" ||
- jl.lbr_op === "OP7" ||
- jl.lbr_op === "OP8" ||
- jl.lbr_op === "OP9" ||
- jl.lbr_op === "OP10" ||
- jl.lbr_op === "OP13" ||
- jl.lbr_op === "OP13" ||
- jl.lbr_op === "OP14" ||
- jl.lbr_op === "OP15")
- )
- .reduce((acc, val) => {
- return acc.add(
- Dinero({ amount: Math.round((val.act_price || 0) * 100) })
- );
- }, Dinero());
-}
-
-function CalculateTaxesTotals(job, otherTotals) {
- //const theObj = JSON.parse(JSON.stringify(otherTotals));
- const subtotal = otherTotals.parts.parts.subtotal
- .add(otherTotals.parts.sublets.subtotal)
- .add(otherTotals.rates.rates_subtotal)
- .add(otherTotals.additional)
- .add(Dinero({ amount: (job.towing_payable || 0) * 100 }))
- .add(Dinero({ amount: (job.storage_payable || 0) * 100 }));
- //TODO Levies should be included??
-
- const statePartsTax = job.joblines
- .filter((jl) => !jl.removed)
- .reduce((acc, val) => {
- if (!!!val.tax_part || !!!val.part_type) return acc;
- // if (!!job.parts_tax_rates[val.part_type]) {
- // console.log("val.line_desc", val.line_desc);
-
- return acc.add(
- Dinero({ amount: Math.round(val.act_price * 100) })
- .multiply(val.part_qty)
- .percentage(
- (!val.part_type && val.lbr_op === "OP13"
- ? job.parts_tax_rates["PAN"].prt_tax_rt
- : job.parts_tax_rates[val.part_type] &&
- job.parts_tax_rates[val.part_type].prt_tax_rt) * 100
- )
- );
- // } else {
- // return acc;
- // }
- }, Dinero({ amount: 0 }));
-
- let ret = {
- subtotal: subtotal,
- federal_tax: subtotal.percentage((job.federal_tax_rate || 0) * 100),
- statePartsTax,
- state_tax: statePartsTax
- .add(
- otherTotals.rates.rates_subtotal.percentage((job.tax_lbr_rt || 0) * 100)
- )
- .add(
- Dinero({
- amount: Math.round((job.towing_payable || 0) * 100),
- }).percentage((job.tax_tow_rt || 0) * 100)
- )
- .add(
- Dinero({
- amount: Math.round((job.storage_payable || 0) * 100),
- }).percentage((job.tax_str_rt || 0) * 100)
- ),
- //Currently commented out for mitchell as these come over as line items usually instead.
- // .add(
- // otherTotals.rates.mapa.total.percentage(
- // (job.tax_paint_mat_rt || 0) * 100
- // )
- // )
- // .add(
- // otherTotals.rates.mash.total.percentage(
- // (job.tax_shop_mat_rt || 0) * 100
- // )
- // )
- local_tax: subtotal.percentage((job.local_tax_rate || 0) * 100),
- };
- ret.total_repairs = ret.subtotal
- .add(ret.federal_tax)
- .add(ret.state_tax)
- .add(ret.local_tax);
-
- ret.custPayable = {
- deductible: Dinero({ amount: (job.ded_amt || 0) * 100 }) || 0,
- federal_tax: job.ca_gst_registrant ? ret.federal_tax : Dinero(),
- other_customer_amount: Dinero({
- amount: (job.other_amount_payable || 0) * 100,
- }),
- dep_taxes: Dinero({ amount: job.depreciation_taxes || 0 }),
- };
-
- ret.custPayable.total = ret.custPayable.deductible
- .add(ret.custPayable.federal_tax)
- .add(ret.custPayable.other_customer_amount)
- .add(ret.custPayable.dep_taxes);
-
- ret.net_repairs = ret.total_repairs.subtract(ret.custPayable.total);
-
- return ret;
-}
-
function CalculateRatesTotals(ratesList, shoprates) {
const jobLines = ratesList.joblines.filter((jl) => !jl.removed);
let ret = {
la1: {
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LA1")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
rate: ratesList.rate_la1 || 0,
},
la2: {
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LA2")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
rate: ratesList.rate_la2 || 0,
},
la3: {
rate: ratesList.rate_la3 || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LA3")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
la4: {
rate: ratesList.rate_la4 || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LA4")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
laa: {
rate: ratesList.rate_laa || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LAA")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
lab: {
rate: ratesList.rate_lab || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LAB")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
lad: {
rate: ratesList.rate_lad || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LAD")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
lae: {
rate: ratesList.rate_lae || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LAE")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
laf: {
rate: ratesList.rate_laf || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LAF")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
lag: {
rate: ratesList.rate_lag || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LAG")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
lam: {
rate: ratesList.rate_lam || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LAM")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
lar: {
rate: ratesList.rate_lar || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LAR")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
las: {
rate: ratesList.rate_las || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LAS")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
lau: {
rate: ratesList.rate_lau || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LAU")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
-
mapa: {
rate: ratesList.rate_mapa || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty === "LAR")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
mash: {
rate: ratesList.rate_mash || 0,
- hours: jobLines
- .filter((item) => item.mod_lbr_ty !== "LAR")
- .reduce((acc, value) => acc + value.mod_lb_hrs, 0),
+ hours: 0,
},
};
+ jobLines.forEach((item) => {
+ if (item.mod_lbr_ty) {
+ //There's a labor type, assign the hours.
+ ret[item.mod_lbr_ty.toLowerCase()].hours =
+ ret[item.mod_lbr_ty.toLowerCase()].hours + item.mod_lb_hrs;
+
+ if (item.mod_lbr_ty === "LAR") {
+ ret.mapa.hours = ret.mapa.hours + item.mod_lb_hrs;
+ } else {
+ ret.mash.hours = ret.mapa.hours + item.mod_lb_hrs;
+ }
+ }
+ });
+
let subtotal = Dinero({ amount: 0 });
let rates_subtotal = Dinero({ amount: 0 });
for (const property in ret) {
@@ -245,11 +110,7 @@ function CalculateRatesTotals(ratesList, shoprates) {
ret[property].hours
);
subtotal = subtotal.add(ret[property].total);
- if (
- property !== "mapa" &&
- property !== "mash"
- //&& property !== "rate_atp"
- )
+ if (property !== "mapa" && property !== "mash")
rates_subtotal = rates_subtotal.add(ret[property].total);
}
ret.subtotal = subtotal;
@@ -257,7 +118,6 @@ function CalculateRatesTotals(ratesList, shoprates) {
return ret;
}
-
function CalculatePartsTotals(jobLines) {
const ret = jobLines
.filter((jl) => !jl.removed)
@@ -307,8 +167,6 @@ function CalculatePartsTotals(jobLines) {
),
},
};
- // default:
- // return acc;
}
},
{
@@ -335,3 +193,106 @@ function CalculatePartsTotals(jobLines) {
},
};
}
+
+function IsAdditionalCost(jobLine) {
+ //May be able to use db_ref here to help.
+ //936012 is Haz Waste Dispoal
+ //936008 is Paint/Materials
+ //936007 is Shop/Materials
+
+ return !jobLine.db_ref || jobLine.db_ref.startsWith("9360");
+}
+
+function CalculateAdditional(job) {
+ return job.joblines
+ .filter((jl) => !jl.removed && IsAdditionalCost(jl))
+ .reduce((acc, val) => {
+ return acc.add(
+ Dinero({ amount: Math.round((val.act_price || 0) * 100) })
+ );
+ }, Dinero());
+}
+
+function CalculateTaxesTotals(job, otherTotals) {
+ const subtotal = otherTotals.parts.parts.subtotal
+ .add(otherTotals.parts.sublets.subtotal)
+ .add(otherTotals.rates.rates_subtotal)
+ .add(otherTotals.additional)
+ .add(Dinero({ amount: (job.towing_payable || 0) * 100 }))
+ .add(Dinero({ amount: (job.storage_payable || 0) * 100 }));
+ //TODO Levies should be included??
+
+ //Potential issue here with Sublet Calculation. Sublets are calculated under labor in Mitchell, but it's done in IO
+ //Under the parts rates.
+
+ let statePartsTax = Dinero();
+ let additionalItemsTax = Dinero();
+
+ job.joblines
+ .filter((jl) => !jl.removed)
+ .forEach((val) => {
+ if (!!!val.tax_part || !!!val.part_type || IsAdditionalCost(val)) {
+ additionalItemsTax = additionalItemsTax.add(
+ Dinero({ amount: Math.round((val.act_price || 0) * 100) })
+ .multiply(val.part_qty || 1)
+ .percentage(
+ (job.parts_tax_rates["PAN"] &&
+ job.parts_tax_rates["PAN"].prt_tax_rt) * 100
+ )
+ );
+ } else {
+ statePartsTax = statePartsTax.add(
+ Dinero({ amount: Math.round((val.act_price || 0) * 100) })
+ .multiply(val.part_qty || 1)
+ .percentage(
+ (job.parts_tax_rates[val.part_type] &&
+ job.parts_tax_rates[val.part_type].prt_tax_rt) * 100
+ )
+ );
+ }
+ });
+
+ let ret = {
+ subtotal: subtotal,
+ federal_tax: subtotal.percentage((job.federal_tax_rate || 0) * 100),
+ statePartsTax,
+ state_tax: statePartsTax
+ .add(
+ otherTotals.rates.rates_subtotal.percentage((job.tax_lbr_rt || 0) * 100)
+ )
+ .add(
+ Dinero({
+ amount: Math.round((job.towing_payable || 0) * 100),
+ }).percentage((job.tax_tow_rt || 0) * 100)
+ )
+ .add(
+ Dinero({
+ amount: Math.round((job.storage_payable || 0) * 100),
+ }).percentage((job.tax_str_rt || 0) * 100)
+ )
+ .add(additionalItemsTax),
+ local_tax: subtotal.percentage((job.local_tax_rate || 0) * 100),
+ };
+ ret.total_repairs = ret.subtotal
+ .add(ret.federal_tax)
+ .add(ret.state_tax)
+ .add(ret.local_tax);
+
+ ret.custPayable = {
+ deductible: Dinero({ amount: (job.ded_amt || 0) * 100 }) || 0,
+ federal_tax: job.ca_gst_registrant ? ret.federal_tax : Dinero(),
+ other_customer_amount: Dinero({
+ amount: (job.other_amount_payable || 0) * 100,
+ }),
+ dep_taxes: Dinero({ amount: job.depreciation_taxes || 0 }),
+ };
+
+ ret.custPayable.total = ret.custPayable.deductible
+ .add(ret.custPayable.federal_tax)
+ .add(ret.custPayable.other_customer_amount)
+ .add(ret.custPayable.dep_taxes);
+
+ ret.net_repairs = ret.total_repairs.subtract(ret.custPayable.total);
+
+ return ret;
+}