Improved bill totals reconciliation IO-583

This commit is contained in:
Patrick Fic
2021-01-20 14:08:26 -08:00
parent bb51d510cd
commit 0287830e73
18 changed files with 455 additions and 13 deletions

View File

@@ -17,16 +17,33 @@ export default function JobBillsTotalComponent({ loading, bills, jobTotals }) {
const totals = jobTotals;
let billTotals = Dinero({ amount: 0 });
let billTotals = Dinero();
let billCms = Dinero();
let lbrAdjustments = Dinero();
bills.forEach((i) =>
i.billlines.forEach((il) => {
billTotals = billTotals.add(
Dinero({
amount: Math.round(
(il.actual_cost || 0) * (i.is_credit_memo ? -1 : 1) * 100
),
}).multiply(il.quantity)
);
if (!i.is_credit_memo) {
billTotals = billTotals.add(
Dinero({
amount: Math.round((il.actual_price || 0) * 100),
}).multiply(il.quantity)
);
} else {
billCms = billCms.add(
Dinero({
amount: Math.round((il.actual_price || 0) * -100),
}).multiply(il.quantity)
);
}
if (il.deductedfromlbr) {
console.log(i, "Deducting from labor.");
lbrAdjustments = lbrAdjustments.add(
Dinero({
amount: Math.round((il.actual_price || 0) * 100),
}).multiply(il.quantity)
);
}
})
);
@@ -35,10 +52,13 @@ export default function JobBillsTotalComponent({ loading, bills, jobTotals }) {
);
const discrepancy = totalPartsSublet.subtract(billTotals);
const discrepWithLbrAdj = discrepancy.add(lbrAdjustments);
const discrepWithCms = discrepWithLbrAdj.subtract(billCms);
return (
<div className="job-bills-totals-container">
<Statistic
title={t("jobs.labels.partstotal")}
title={t("jobs.labels.rosaletotal")}
value={totalPartsSublet.toFormat()}
/>
<Statistic
@@ -52,6 +72,28 @@ export default function JobBillsTotalComponent({ loading, bills, jobTotals }) {
}}
value={discrepancy.toFormat()}
/>
<Statistic
title={t("bills.labels.dedfromlbr")}
value={lbrAdjustments.toFormat()}
/>
<Statistic
title={t("bills.labels.discrepwithlbradj")}
valueStyle={{
color: discrepWithLbrAdj.getAmount === 0 ? "green" : "red",
}}
value={discrepWithLbrAdj.toFormat()}
/>
<Statistic
title={t("bills.labels.billcmtotal")}
value={billCms.toFormat()}
/>
<Statistic
title={t("bills.labels.discrepwithcms")}
valueStyle={{
color: discrepWithCms.getAmount === 0 ? "green" : "red",
}}
value={discrepWithCms.toFormat()}
/>
</div>
);
}