Refactored some Job Calculation Logic. IO-439

This commit is contained in:
Patrick Fic
2020-12-04 15:16:36 -08:00
parent db1e046130
commit 65a22922eb
9 changed files with 267 additions and 227 deletions

View File

@@ -11538,6 +11538,27 @@
</translation> </translation>
</translations> </translations>
</concept_node> </concept_node>
<concept_node>
<name>PAO</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node> <concept_node>
<name>PAR</name> <name>PAR</name>
<definition_loaded>false</definition_loaded> <definition_loaded>false</definition_loaded>
@@ -16981,6 +17002,27 @@
</translation> </translation>
</translations> </translations>
</concept_node> </concept_node>
<concept_node>
<name>labor_rates_subtotal</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node> <concept_node>
<name>laborallocations</name> <name>laborallocations</name>
<definition_loaded>false</definition_loaded> <definition_loaded>false</definition_loaded>

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
{ {
"name": "bodyshop", "name": "bodyshop",
"version": "0.1.1", "version": "0.1.0001",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@@ -4737,6 +4737,23 @@
"integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ==", "integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ==",
"optional": true "optional": true
}, },
"bindings": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
"integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
"optional": true,
"requires": {
"file-uri-to-path": "1.0.0"
},
"dependencies": {
"file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",
"optional": true
}
}
},
"block-stream": { "block-stream": {
"version": "0.0.9", "version": "0.0.9",
"resolved": "https://registry.npmjs.org/block-stream/-/block-stream-0.0.9.tgz", "resolved": "https://registry.npmjs.org/block-stream/-/block-stream-0.0.9.tgz",
@@ -20508,6 +20525,7 @@
"integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==", "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==",
"optional": true, "optional": true,
"requires": { "requires": {
"bindings": "^1.5.0",
"nan": "^2.12.1" "nan": "^2.12.1"
} }
}, },
@@ -21049,6 +21067,7 @@
"integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==", "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==",
"optional": true, "optional": true,
"requires": { "requires": {
"bindings": "^1.5.0",
"nan": "^2.12.1" "nan": "^2.12.1"
} }
}, },

View File

@@ -170,55 +170,12 @@ export function JobsTotalsTableComponent({ bodyshop, jobRO, job }) {
job.job_totals.rates.la4.rate job.job_totals.rates.la4.rate
})`}</td> })`}</td>
</tr> </tr>
<tr> <tr>
<td>{t("jobs.labels.rates_subtotal")}</td> <td>{t("jobs.labels.labor_rates_subtotal")}</td>
<td>{Dinero(job.job_totals.rates.subtotal).toFormat()}</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</Col>
<Col {...colSpan}>
<div className="job-totals-half">
<table>
<tbody>
{Object.keys(job.job_totals.parts.parts.list).map(
(key, idx) => (
<tr key={idx}>
<td>{t(`jobs.fields.${key.toLowerCase()}`)}</td>
<td className="currency">
{Dinero(
job.job_totals.parts.parts.list[key].total
).toFormat()}
</td>
<td></td>
</tr>
)
)}
<tr>
<td>{t("jobs.labels.partstotal")}</td>
<td className="currency"> <td className="currency">
{Dinero(job.job_totals.parts.parts.total).toFormat()} <strong>
</td> {Dinero(job.job_totals.rates.rates_subtotal).toFormat()}
<td>{`(${Dinero( </strong>
job.job_totals.parts.parts.subtotal
).toFormat()})`}</td>
</tr>
<tr>
<td>{t("jobs.labels.subletstotal")}</td>
<td className="currency">
{Dinero(job.job_totals.parts.sublets.total).toFormat()}
</td>
<td>{`(${Dinero(
job.job_totals.parts.sublets.subtotal
).toFormat()})`}</td>
</tr>
<tr>
<td>{t("jobs.labels.additionaltotal")}</td>
<td className="currency">
{Dinero(job.job_totals.additional).toFormat()}
</td> </td>
<td></td> <td></td>
</tr> </tr>
@@ -240,6 +197,60 @@ export function JobsTotalsTableComponent({ bodyshop, jobRO, job }) {
job.job_totals.rates.mash.rate job.job_totals.rates.mash.rate
})`}</td> })`}</td>
</tr> </tr>
<tr>
<td>{t("jobs.labels.rates_subtotal")}</td>
<td className="currency">
<strong>
{Dinero(job.job_totals.rates.subtotal).toFormat()}
</strong>
</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</Col>
<Col {...colSpan}>
<div className="job-totals-half">
<Typography.Title level={4}>
{t("jobs.labels.partstotal")}
</Typography.Title>
<table>
<tbody>
{Object.keys(job.job_totals.parts.parts.list).map(
(key, idx) => (
<tr key={idx}>
<td>{t(`jobs.fields.${key.toLowerCase()}`)}</td>
<td className="currency">
{Dinero(
job.job_totals.parts.parts.list[key].total
).toFormat()}
</td>
</tr>
)
)}
<tr>
<td>{t("jobs.labels.partstotal")}</td>
<td className="currency">
<strong>
{Dinero(job.job_totals.parts.parts.total).toFormat()}
</strong>
</td>
</tr>
<tr>
<td>{t("jobs.labels.subletstotal")}</td>
<td className="currency">
{Dinero(job.job_totals.parts.sublets.total).toFormat()}
</td>
</tr>
<tr>
<td>{t("jobs.labels.additionaltotal")}</td>
<td className="currency">
{Dinero(job.job_totals.additional).toFormat()}
</td>
</tr>
</tbody> </tbody>
</table> </table>
<div <div
@@ -254,6 +265,10 @@ export function JobsTotalsTableComponent({ bodyshop, jobRO, job }) {
} }
}} }}
> >
<Statistic
title={t("jobs.labels.federal_tax_amt")}
value={Dinero(job.job_totals.totals.federal_tax).toFormat()}
/>
<Statistic <Statistic
title={t("jobs.labels.state_tax_amt")} title={t("jobs.labels.state_tax_amt")}
value={Dinero(job.job_totals.totals.state_tax).toFormat()} value={Dinero(job.job_totals.totals.state_tax).toFormat()}
@@ -262,10 +277,6 @@ export function JobsTotalsTableComponent({ bodyshop, jobRO, job }) {
title={t("jobs.labels.local_tax_amt")} title={t("jobs.labels.local_tax_amt")}
value={Dinero(job.job_totals.totals.local_tax).toFormat()} value={Dinero(job.job_totals.totals.local_tax).toFormat()}
/> />
<Statistic
title={t("jobs.labels.federal_tax_amt")}
value={Dinero(job.job_totals.totals.federal_tax).toFormat()}
/>
</div> </div>
<div <div
className="job-totals-stats" className="job-totals-stats"

View File

@@ -491,6 +491,7 @@ export const GET_JOB_BY_PK = gql`
notes notes
location location
tax_part tax_part
db_ref
parts_order_lines { parts_order_lines {
id id
parts_order { parts_order {

View File

@@ -752,6 +752,7 @@
"PAL": "LKQ", "PAL": "LKQ",
"PAM": "Remanufactured", "PAM": "Remanufactured",
"PAN": "New/OEM", "PAN": "New/OEM",
"PAO": "Other",
"PAR": "Recored", "PAR": "Recored",
"PAS": "Sublet", "PAS": "Sublet",
"PASL": "Sublet" "PASL": "Sublet"
@@ -1035,6 +1036,7 @@
"inproduction": "In Production", "inproduction": "In Production",
"job": "Job Details", "job": "Job Details",
"jobcosting": "Job Costing", "jobcosting": "Job Costing",
"labor_rates_subtotal": "Labor Rates Subtotal",
"laborallocations": "Labor Allocations", "laborallocations": "Labor Allocations",
"labortotals": "Labor Totals", "labortotals": "Labor Totals",
"lines": "Estimate Lines", "lines": "Estimate Lines",
@@ -1049,7 +1051,7 @@
"partssubletstotal": "Parts & Sublets Total", "partssubletstotal": "Parts & Sublets Total",
"partstotal": "Parts Total", "partstotal": "Parts Total",
"rates": "Rates", "rates": "Rates",
"rates_subtotal": "Rates Subtotal", "rates_subtotal": "All Rates Subtotal",
"reconciliation": { "reconciliation": {
"billlinestotal": "Bill Lines Total", "billlinestotal": "Bill Lines Total",
"byassoc": "By Line Association", "byassoc": "By Line Association",

View File

@@ -752,6 +752,7 @@
"PAL": "", "PAL": "",
"PAM": "", "PAM": "",
"PAN": "", "PAN": "",
"PAO": "",
"PAR": "", "PAR": "",
"PAS": "", "PAS": "",
"PASL": "" "PASL": ""
@@ -1035,6 +1036,7 @@
"inproduction": "", "inproduction": "",
"job": "", "job": "",
"jobcosting": "", "jobcosting": "",
"labor_rates_subtotal": "",
"laborallocations": "", "laborallocations": "",
"labortotals": "", "labortotals": "",
"lines": "Líneas estimadas", "lines": "Líneas estimadas",

View File

@@ -752,6 +752,7 @@
"PAL": "", "PAL": "",
"PAM": "", "PAM": "",
"PAN": "", "PAN": "",
"PAO": "",
"PAR": "", "PAR": "",
"PAS": "", "PAS": "",
"PASL": "" "PASL": ""
@@ -1035,6 +1036,7 @@
"inproduction": "", "inproduction": "",
"job": "", "job": "",
"jobcosting": "", "jobcosting": "",
"labor_rates_subtotal": "",
"laborallocations": "", "laborallocations": "",
"labortotals": "", "labortotals": "",
"lines": "Estimer les lignes", "lines": "Estimer les lignes",

View File

@@ -13,231 +13,96 @@ exports.default = async function (req, res) {
additional: CalculateAdditional(job), additional: CalculateAdditional(job),
}; };
ret.totals = CalculateTaxesTotals(job, ret); ret.totals = CalculateTaxesTotals(job, ret);
// console.log("CalculateJob -> Final", ret);
res.status(200).json(ret); res.status(200).json(ret);
} catch (error) { } catch (error) {
console.log("error", error); console.log("error", error);
res.status(400).send(JSON.stringify(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) { function CalculateRatesTotals(ratesList, shoprates) {
const jobLines = ratesList.joblines.filter((jl) => !jl.removed); const jobLines = ratesList.joblines.filter((jl) => !jl.removed);
let ret = { let ret = {
la1: { la1: {
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LA1")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
rate: ratesList.rate_la1 || 0, rate: ratesList.rate_la1 || 0,
}, },
la2: { la2: {
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LA2")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
rate: ratesList.rate_la2 || 0, rate: ratesList.rate_la2 || 0,
}, },
la3: { la3: {
rate: ratesList.rate_la3 || 0, rate: ratesList.rate_la3 || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LA3")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
}, },
la4: { la4: {
rate: ratesList.rate_la4 || 0, rate: ratesList.rate_la4 || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LA4")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
}, },
laa: { laa: {
rate: ratesList.rate_laa || 0, rate: ratesList.rate_laa || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LAA")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
}, },
lab: { lab: {
rate: ratesList.rate_lab || 0, rate: ratesList.rate_lab || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LAB")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
}, },
lad: { lad: {
rate: ratesList.rate_lad || 0, rate: ratesList.rate_lad || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LAD")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
}, },
lae: { lae: {
rate: ratesList.rate_lae || 0, rate: ratesList.rate_lae || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LAE")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
}, },
laf: { laf: {
rate: ratesList.rate_laf || 0, rate: ratesList.rate_laf || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LAF")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
}, },
lag: { lag: {
rate: ratesList.rate_lag || 0, rate: ratesList.rate_lag || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LAG")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
}, },
lam: { lam: {
rate: ratesList.rate_lam || 0, rate: ratesList.rate_lam || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LAM")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
}, },
lar: { lar: {
rate: ratesList.rate_lar || 0, rate: ratesList.rate_lar || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LAR")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
}, },
las: { las: {
rate: ratesList.rate_las || 0, rate: ratesList.rate_las || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LAS")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
}, },
lau: { lau: {
rate: ratesList.rate_lau || 0, rate: ratesList.rate_lau || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LAU")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
}, },
mapa: { mapa: {
rate: ratesList.rate_mapa || 0, rate: ratesList.rate_mapa || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty === "LAR")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
}, },
mash: { mash: {
rate: ratesList.rate_mash || 0, rate: ratesList.rate_mash || 0,
hours: jobLines hours: 0,
.filter((item) => item.mod_lbr_ty !== "LAR")
.reduce((acc, value) => acc + value.mod_lb_hrs, 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 subtotal = Dinero({ amount: 0 });
let rates_subtotal = Dinero({ amount: 0 }); let rates_subtotal = Dinero({ amount: 0 });
for (const property in ret) { for (const property in ret) {
@@ -245,11 +110,7 @@ function CalculateRatesTotals(ratesList, shoprates) {
ret[property].hours ret[property].hours
); );
subtotal = subtotal.add(ret[property].total); subtotal = subtotal.add(ret[property].total);
if ( if (property !== "mapa" && property !== "mash")
property !== "mapa" &&
property !== "mash"
//&& property !== "rate_atp"
)
rates_subtotal = rates_subtotal.add(ret[property].total); rates_subtotal = rates_subtotal.add(ret[property].total);
} }
ret.subtotal = subtotal; ret.subtotal = subtotal;
@@ -257,7 +118,6 @@ function CalculateRatesTotals(ratesList, shoprates) {
return ret; return ret;
} }
function CalculatePartsTotals(jobLines) { function CalculatePartsTotals(jobLines) {
const ret = jobLines const ret = jobLines
.filter((jl) => !jl.removed) .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;
}