IO-793 Add additional job totals calculations to pli.

This commit is contained in:
Patrick Fic
2021-03-30 11:00:15 -07:00
parent e9d7f55899
commit 0498c8781f
7 changed files with 118 additions and 13 deletions

View File

@@ -6,7 +6,12 @@ import AlertComponent from "../alert/alert.component";
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
import "./job-bills-total.styles.scss";
export default function JobBillsTotalComponent({ loading, bills, jobTotals }) {
export default function JobBillsTotalComponent({
loading,
bills,
partsOrders,
jobTotals,
}) {
const { t } = useTranslation();
if (loading) return <LoadingSkeleton />;
@@ -20,6 +25,19 @@ export default function JobBillsTotalComponent({ loading, bills, jobTotals }) {
let billTotals = Dinero();
let billCms = Dinero();
let lbrAdjustments = Dinero();
let totalReturns = Dinero();
partsOrders.forEach((p) =>
p.parts_order_lines.forEach((pol) => {
if (p.return) {
totalReturns = totalReturns.add(
Dinero({
amount: Math.round((pol.cost || 0) * 100),
}).multiply(pol.quantity)
);
}
})
);
bills.forEach((i) =>
i.billlines.forEach((il) => {
@@ -50,11 +68,13 @@ export default function JobBillsTotalComponent({ loading, bills, jobTotals }) {
const totalPartsSublet = Dinero(totals.parts.parts.total).add(
Dinero(totals.parts.sublets.total)
);
const discrepancy = totalPartsSublet.subtract(billTotals);
const discrepWithLbrAdj = discrepancy.add(lbrAdjustments);
const discrepWithCms = discrepWithLbrAdj.subtract(billCms);
const creditsNotReceived = totalReturns.subtract(billCms);
return (
<Card title={t("jobs.labels.jobtotals")}>
<Space wrap size="large">
@@ -95,6 +115,21 @@ export default function JobBillsTotalComponent({ loading, bills, jobTotals }) {
}}
value={discrepWithCms.toFormat()}
/>
<Statistic
title={t("bills.labels.totalreturns")}
value={totalReturns.toFormat()}
/>{" "}
<Statistic
title={t("bills.labels.creditsreceived")}
value={billCms.toFormat()}
/>
<Statistic
title={t("bills.labels.creditsnotreceived")}
valueStyle={{
color: creditsNotReceived.getAmount === 0 ? "green" : "red",
}}
value={creditsNotReceived.toFormat()}
/>
</Space>
</Card>
);