IO-813 Calculation updates to include adjustments

This commit is contained in:
Patrick Fic
2021-03-31 11:02:11 -07:00
parent 3c1ecd9638
commit e85be1c173
4 changed files with 67 additions and 36 deletions

View File

@@ -46,13 +46,13 @@ export function JobsTotalsTableComponent({ jobRO, job }) {
</Card>
</Col>
<Col {...colSpan}>
<Row gutter={[0, 32]}>
<Col span={24}>
<Row gutter={[16, 16]}>
<Col sm={24} md={12}>
<Card title={t("jobs.labels.partstotal")}>
<JobTotalsTableParts job={job} />
</Card>
</Col>
<Col span={24}>
<Col sm={24} md={12}>
<Card title={t("jobs.labels.othertotal")}>
<JobTotalsTableOther job={job} />
</Card>

View File

@@ -17,9 +17,29 @@ export default function JobTotalsTableOther({ job }) {
key: t("jobs.labels.subletstotal"),
total: job.job_totals.parts.sublets.total,
},
...((job.job_totals.additional.additionalCostItems &&
job.job_totals.additional.additionalCostItems.map((i) => {
return {
key: i.key,
total: i.total,
};
})) ||
[]),
{
key: t("jobs.labels.additionaltotal"),
total: job.job_totals.additional,
key: t("jobs.fields.adjustment_bottom_line"),
total: job.job_totals.additional.adjustments,
},
{
key: t("jobs.fields.towing"),
total: job.job_totals.additional.towing,
},
{
key: t("jobs.fields.storage"),
total: job.job_totals.additional.storage,
},
{
key: t("jobs.fields.pvrt"),
total: job.job_totals.additional.pvrt,
},
];
}, [job.job_totals, t]);
@@ -67,7 +87,7 @@ export default function JobTotalsTableOther({ job }) {
<Table.Summary.Cell>
<strong>
{Dinero(job.job_totals.parts.parts.total).toFormat()}
{Dinero(job.job_totals.additional.total).toFormat()}
</strong>
</Table.Summary.Cell>
</Table.Summary.Row>

View File

@@ -199,7 +199,7 @@ const generateInvoiceQbxml = (
(i) => jobline.profitcenter_part.toLowerCase() === i.name.toLowerCase()
);
if (!!!account) {
if (!account) {
throw new Error(
`A matching account does not exist for the allocation. Center: ${center}`
);

View File

@@ -279,31 +279,41 @@ function IsAdditionalCost(jobLine) {
}
function CalculateAdditional(job) {
let ret = job.joblines
let ret = {
additionalCosts: null,
additionalCostItems: [],
adjustments: null,
towing: null,
storage: null,
pvrt: null,
total: null,
};
ret.additionalCosts = job.joblines
.filter((jl) => !jl.removed && IsAdditionalCost(jl))
.reduce((acc, val) => {
return acc.add(
Dinero({ amount: Math.round((val.act_price || 0) * 100) }).multiply(
val.part_qty || 1
)
);
const lineValue = Dinero({
amount: Math.round((val.act_price || 0) * 100),
}).multiply(val.part_qty || 1);
ret.additionalCostItems.push({ key: val.line_desc, total: lineValue });
return acc.add(lineValue);
}, Dinero());
ret = ret
.add(
Dinero({
amount: Math.round((job.towing_payable || 0) * 100),
})
)
.add(
Dinero({
amount: Math.round((job.storage_payable || 0) * 100),
})
)
.add(
Dinero({
amount: Math.round((job.ca_bc_pvrt || 0) * 100),
})
);
ret.adjustments = Dinero({
amount: Math.round((job.adjustment_bottom_line || 0) * 100),
});
ret.towing = Dinero({
amount: Math.round((job.towing_payable || 0) * 100),
});
ret.storage = Dinero({
amount: Math.round((job.storage_payable || 0) * 100),
});
ret.pvrt = Dinero({
amount: Math.round((job.ca_bc_pvrt || 0) * 100),
});
ret.total = ret.additionalCosts
.add(ret.adjustments) //IO-813 Adjustment takes care of GST & PST at labor rate.
.add(ret.towing)
.add(ret.storage)
.add(ret.pvrt);
return ret;
}
@@ -312,7 +322,7 @@ function CalculateTaxesTotals(job, otherTotals) {
const subtotal = otherTotals.parts.parts.subtotal
.add(otherTotals.parts.sublets.subtotal)
.add(otherTotals.rates.subtotal) //No longer using just rates subtotal to include mapa/mash.
.add(otherTotals.additional);
.add(otherTotals.additional.total);
// .add(Dinero({ amount: (job.towing_payable || 0) * 100 }))
// .add(Dinero({ amount: (job.storage_payable || 0) * 100 }));
@@ -371,14 +381,15 @@ function CalculateTaxesTotals(job, otherTotals) {
otherTotals.rates.subtotal.percentage((job.tax_lbr_rt || 0) * 100) // THis is currently using the lbr tax rate from PFH not PFL.
)
.add(
Dinero({
amount: Math.round((job.towing_payable || 0) * 100),
}).percentage((job.tax_tow_rt || 0) * 100)
otherTotals.additional.adjustments.percentage(
(job.tax_lbr_rt || 0) * 100
)
)
.add(
Dinero({
amount: Math.round((job.storage_payable || 0) * 100),
}).percentage((job.tax_str_rt || 0) * 100)
otherTotals.additional.towing.percentage((job.tax_tow_rt || 0) * 100)
)
.add(
otherTotals.additional.storage.percentage((job.tax_str_rt || 0) * 100)
)
.add(additionalItemsTax),
local_tax: subtotal.percentage((job.local_tax_rate || 0) * 100),