Added automatic reconciliation for jobs. BOD-406
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
import React, { useMemo } from "react";
|
||||
import { Button, Space, Statistic } from "antd";
|
||||
import Dinero from "dinero.js";
|
||||
import _ from "lodash";
|
||||
import { Space, Statistic } from "antd";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
reconcileByAssocLine,
|
||||
reconcileByPrice,
|
||||
} from "./job-reconciliation-totals.utility";
|
||||
|
||||
export default function JobReconciliationTotals({
|
||||
billLines,
|
||||
jobLines,
|
||||
selectedBillLines,
|
||||
selectedJobLines,
|
||||
jobLineState,
|
||||
billLineState,
|
||||
}) {
|
||||
const [errors, setErrors] = useState([]);
|
||||
const { t } = useTranslation();
|
||||
const [selectedBillLines, setSelectedBillLines] = billLineState;
|
||||
const [selectedJobLines, setSelectedJobLines] = jobLineState;
|
||||
|
||||
const totals = useMemo(() => {
|
||||
const jlLookup = _.keyBy(selectedJobLines, (i) => i);
|
||||
@@ -20,7 +27,6 @@ export default function JobReconciliationTotals({
|
||||
joblinesTotal: jobLines
|
||||
.filter((jl) => !!jlLookup[jl.id])
|
||||
.reduce((acc, val) => {
|
||||
console.log("acc :>> ", val);
|
||||
return acc.add(
|
||||
Dinero({ amount: val.act_price * 100 }).multiply(val.part_qty || 1)
|
||||
);
|
||||
@@ -38,15 +44,53 @@ export default function JobReconciliationTotals({
|
||||
}, [billLines, jobLines, selectedBillLines, selectedJobLines]);
|
||||
|
||||
return (
|
||||
<Space direction="horizontal">
|
||||
<Statistic
|
||||
title={t("jobs.labels.reconciliation.joblinestotal")}
|
||||
value={totals.joblinesTotal.toFormat()}
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.reconciliation.billlinestotal")}
|
||||
value={totals.billLinesTotal.toFormat()}
|
||||
/>
|
||||
</Space>
|
||||
<div>
|
||||
<Space direction="horizontal">
|
||||
<Statistic
|
||||
title={t("jobs.labels.reconciliation.joblinestotal")}
|
||||
value={totals.joblinesTotal.toFormat()}
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.reconciliation.billlinestotal")}
|
||||
value={totals.billLinesTotal.toFormat()}
|
||||
/>
|
||||
<Button
|
||||
onClick={() =>
|
||||
reconcileByAssocLine(
|
||||
jobLines,
|
||||
jobLineState,
|
||||
billLines,
|
||||
billLineState,
|
||||
setErrors
|
||||
)
|
||||
}
|
||||
>
|
||||
{t("jobs.labels.reconciliation.byassoc")}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() =>
|
||||
reconcileByPrice(
|
||||
jobLines,
|
||||
jobLineState,
|
||||
billLines,
|
||||
billLineState,
|
||||
setErrors
|
||||
)
|
||||
}
|
||||
>
|
||||
{t("jobs.labels.reconciliation.byprice")}
|
||||
</Button>
|
||||
</Space>
|
||||
{errors.length > 0 && (
|
||||
<div>
|
||||
{t("general.labels.errors")}
|
||||
<ul>
|
||||
{errors.map((error, idx) => (
|
||||
<li key={idx}>{error}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user