Added automatic reconciliation for jobs. BOD-406
This commit is contained in:
@@ -1295,6 +1295,27 @@
|
|||||||
</translation>
|
</translation>
|
||||||
</translations>
|
</translations>
|
||||||
</concept_node>
|
</concept_node>
|
||||||
|
<concept_node>
|
||||||
|
<name>from</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>other</name>
|
<name>other</name>
|
||||||
<definition_loaded>false</definition_loaded>
|
<definition_loaded>false</definition_loaded>
|
||||||
@@ -17254,6 +17275,158 @@
|
|||||||
</translation>
|
</translation>
|
||||||
</translations>
|
</translations>
|
||||||
</concept_node>
|
</concept_node>
|
||||||
|
<folder_node>
|
||||||
|
<name>reconciliation</name>
|
||||||
|
<children>
|
||||||
|
<concept_node>
|
||||||
|
<name>billlinestotal</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>
|
||||||
|
<name>byassoc</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>
|
||||||
|
<name>byprice</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>
|
||||||
|
<name>joblinestotal</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>
|
||||||
|
<name>multipleactprices</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>
|
||||||
|
<name>multiplebilllines</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>
|
||||||
|
<name>multiplebillsforactprice</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>
|
||||||
|
</children>
|
||||||
|
</folder_node>
|
||||||
<concept_node>
|
<concept_node>
|
||||||
<name>reconciliationheader</name>
|
<name>reconciliationheader</name>
|
||||||
<definition_loaded>false</definition_loaded>
|
<definition_loaded>false</definition_loaded>
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ export default function JobReconciliationModalComponent({ job, bills }) {
|
|||||||
<Row>
|
<Row>
|
||||||
<JobReconciliationTotals
|
<JobReconciliationTotals
|
||||||
jobLines={jobLineData}
|
jobLines={jobLineData}
|
||||||
selectedJobLines={jobLineState[0]}
|
jobLineState={jobLineState}
|
||||||
billLines={invoiceLineData}
|
billLines={invoiceLineData}
|
||||||
selectedBillLines={billLineState[0]}
|
billLineState={billLineState}
|
||||||
/>
|
/>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
import React, { useMemo } from "react";
|
import { Button, Space, Statistic } from "antd";
|
||||||
import Dinero from "dinero.js";
|
import Dinero from "dinero.js";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { Space, Statistic } from "antd";
|
import React, { useMemo, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import {
|
||||||
|
reconcileByAssocLine,
|
||||||
|
reconcileByPrice,
|
||||||
|
} from "./job-reconciliation-totals.utility";
|
||||||
|
|
||||||
export default function JobReconciliationTotals({
|
export default function JobReconciliationTotals({
|
||||||
billLines,
|
billLines,
|
||||||
jobLines,
|
jobLines,
|
||||||
selectedBillLines,
|
jobLineState,
|
||||||
selectedJobLines,
|
billLineState,
|
||||||
}) {
|
}) {
|
||||||
|
const [errors, setErrors] = useState([]);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const [selectedBillLines, setSelectedBillLines] = billLineState;
|
||||||
|
const [selectedJobLines, setSelectedJobLines] = jobLineState;
|
||||||
|
|
||||||
const totals = useMemo(() => {
|
const totals = useMemo(() => {
|
||||||
const jlLookup = _.keyBy(selectedJobLines, (i) => i);
|
const jlLookup = _.keyBy(selectedJobLines, (i) => i);
|
||||||
@@ -20,7 +27,6 @@ export default function JobReconciliationTotals({
|
|||||||
joblinesTotal: jobLines
|
joblinesTotal: jobLines
|
||||||
.filter((jl) => !!jlLookup[jl.id])
|
.filter((jl) => !!jlLookup[jl.id])
|
||||||
.reduce((acc, val) => {
|
.reduce((acc, val) => {
|
||||||
console.log("acc :>> ", val);
|
|
||||||
return acc.add(
|
return acc.add(
|
||||||
Dinero({ amount: val.act_price * 100 }).multiply(val.part_qty || 1)
|
Dinero({ amount: val.act_price * 100 }).multiply(val.part_qty || 1)
|
||||||
);
|
);
|
||||||
@@ -38,15 +44,53 @@ export default function JobReconciliationTotals({
|
|||||||
}, [billLines, jobLines, selectedBillLines, selectedJobLines]);
|
}, [billLines, jobLines, selectedBillLines, selectedJobLines]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Space direction="horizontal">
|
<div>
|
||||||
<Statistic
|
<Space direction="horizontal">
|
||||||
title={t("jobs.labels.reconciliation.joblinestotal")}
|
<Statistic
|
||||||
value={totals.joblinesTotal.toFormat()}
|
title={t("jobs.labels.reconciliation.joblinestotal")}
|
||||||
/>
|
value={totals.joblinesTotal.toFormat()}
|
||||||
<Statistic
|
/>
|
||||||
title={t("jobs.labels.reconciliation.billlinestotal")}
|
<Statistic
|
||||||
value={totals.billLinesTotal.toFormat()}
|
title={t("jobs.labels.reconciliation.billlinestotal")}
|
||||||
/>
|
value={totals.billLinesTotal.toFormat()}
|
||||||
</Space>
|
/>
|
||||||
|
<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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import i18next from "i18next";
|
||||||
|
import _ from "lodash";
|
||||||
|
export const reconcileByAssocLine = (
|
||||||
|
jobLines,
|
||||||
|
jobLineState,
|
||||||
|
billLines,
|
||||||
|
billLineState,
|
||||||
|
setErrors
|
||||||
|
) => {
|
||||||
|
const [selectedBillLines, setSelectedBillLines] = billLineState;
|
||||||
|
const [selectedJobLines, setSelectedJobLines] = jobLineState;
|
||||||
|
|
||||||
|
const allJoblinesFromBills = billLines
|
||||||
|
.filter((bl) => !!bl.joblineid)
|
||||||
|
.map((bl) => bl.joblineid);
|
||||||
|
|
||||||
|
const duplicatedJobLinesbyInvoiceId = _.filter(
|
||||||
|
allJoblinesFromBills,
|
||||||
|
(val, i, iteratee) => _.includes(iteratee, val, i + 1)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (duplicatedJobLinesbyInvoiceId.length > 0)
|
||||||
|
setErrors((errors) => [
|
||||||
|
...errors,
|
||||||
|
..._.uniqBy(duplicatedJobLinesbyInvoiceId).map((dupedId) =>
|
||||||
|
i18next.t("jobs.labels.reconciliation.multiplebilllines", {
|
||||||
|
line_desc: jobLines.find((j) => j.id === dupedId).line_desc,
|
||||||
|
})
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
|
setSelectedBillLines(
|
||||||
|
_.union(
|
||||||
|
selectedBillLines,
|
||||||
|
billLines.filter((bl) => !!bl.joblineid).map((bl) => bl.id)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
setSelectedJobLines(
|
||||||
|
_.union(selectedJobLines, _.uniqBy(allJoblinesFromBills))
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const reconcileByPrice = (
|
||||||
|
jobLines,
|
||||||
|
jobLineState,
|
||||||
|
billLines,
|
||||||
|
billLineState,
|
||||||
|
setErrors
|
||||||
|
) => {
|
||||||
|
const [selectedBillLines, setSelectedBillLines] = billLineState;
|
||||||
|
const [selectedJobLines, setSelectedJobLines] = jobLineState;
|
||||||
|
|
||||||
|
const allActPricesFromJobs = jobLines.map((jl) => jl.act_price);
|
||||||
|
const duplicateActPrices = _.filter(
|
||||||
|
allActPricesFromJobs,
|
||||||
|
(val, i, iteratee) => _.includes(iteratee, val, i + 1)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (duplicateActPrices.length > 0)
|
||||||
|
setErrors((errors) => [
|
||||||
|
...errors,
|
||||||
|
..._.uniqBy(duplicateActPrices).map((dupeAp) =>
|
||||||
|
i18next.t("jobs.labels.reconciliation.multipleactprices", {
|
||||||
|
act_price: dupeAp,
|
||||||
|
})
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const foundJobLines = [];
|
||||||
|
var foundBillLines = [];
|
||||||
|
const actPricesWithMoreThan1MatchingBill = [];
|
||||||
|
|
||||||
|
jobLines.forEach((jl) => {
|
||||||
|
const matchingBillLineIds = billLines
|
||||||
|
.filter((bl) => bl.actual_price === jl.act_price)
|
||||||
|
.map((bl) => bl.id);
|
||||||
|
|
||||||
|
if (matchingBillLineIds.length > 1) {
|
||||||
|
actPricesWithMoreThan1MatchingBill.push(jl.act_price);
|
||||||
|
}
|
||||||
|
|
||||||
|
foundBillLines = [...foundBillLines, ...matchingBillLineIds];
|
||||||
|
if (matchingBillLineIds.length > 0) {
|
||||||
|
foundJobLines.push(jl.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setErrors((errors) => [
|
||||||
|
...errors,
|
||||||
|
..._.uniqBy(duplicateActPrices).map((dupeAp) =>
|
||||||
|
i18next.t("jobs.labels.reconciliation.multipleactprices", {
|
||||||
|
act_price: dupeAp,
|
||||||
|
})
|
||||||
|
),
|
||||||
|
..._.uniqBy(actPricesWithMoreThan1MatchingBill).map((act_price) =>
|
||||||
|
i18next.t("jobs.labels.reconciliation.multiplebillsforactprice", {
|
||||||
|
act_price: act_price,
|
||||||
|
})
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
|
setSelectedBillLines(_.union(selectedBillLines, _.uniqBy(foundBillLines)));
|
||||||
|
|
||||||
|
setSelectedJobLines(_.union(selectedJobLines, _.uniqBy(foundJobLines)));
|
||||||
|
};
|
||||||
@@ -96,6 +96,7 @@
|
|||||||
},
|
},
|
||||||
"labels": {
|
"labels": {
|
||||||
"entered": "Entered",
|
"entered": "Entered",
|
||||||
|
"from": "From",
|
||||||
"other": "--Not On Estimate--",
|
"other": "--Not On Estimate--",
|
||||||
"reconciled": "Reconciled!",
|
"reconciled": "Reconciled!",
|
||||||
"unreconciled": "Unreconciled"
|
"unreconciled": "Unreconciled"
|
||||||
@@ -1048,6 +1049,15 @@
|
|||||||
"partstotal": "Parts Total",
|
"partstotal": "Parts Total",
|
||||||
"rates": "Rates",
|
"rates": "Rates",
|
||||||
"rates_subtotal": "Rates Subtotal",
|
"rates_subtotal": "Rates Subtotal",
|
||||||
|
"reconciliation": {
|
||||||
|
"billlinestotal": "Bill Lines Total",
|
||||||
|
"byassoc": "By Line Association",
|
||||||
|
"byprice": "By Price",
|
||||||
|
"joblinestotal": "Job Lines Total",
|
||||||
|
"multipleactprices": "${{act_price}} is the price for multiple job lines.",
|
||||||
|
"multiplebilllines": "{{line_desc}} has 2 or more bill lines associated to it.",
|
||||||
|
"multiplebillsforactprice": "Found more than 1 bill matching ${{act_price}} retail price."
|
||||||
|
},
|
||||||
"reconciliationheader": "Parts & Sublet Reconciliation",
|
"reconciliationheader": "Parts & Sublet Reconciliation",
|
||||||
"sale_labor": "Sales - Labor",
|
"sale_labor": "Sales - Labor",
|
||||||
"sale_parts": "Sales - Parts",
|
"sale_parts": "Sales - Parts",
|
||||||
|
|||||||
@@ -96,6 +96,7 @@
|
|||||||
},
|
},
|
||||||
"labels": {
|
"labels": {
|
||||||
"entered": "",
|
"entered": "",
|
||||||
|
"from": "",
|
||||||
"other": "",
|
"other": "",
|
||||||
"reconciled": "",
|
"reconciled": "",
|
||||||
"unreconciled": ""
|
"unreconciled": ""
|
||||||
@@ -1048,6 +1049,15 @@
|
|||||||
"partstotal": "",
|
"partstotal": "",
|
||||||
"rates": "Tarifas",
|
"rates": "Tarifas",
|
||||||
"rates_subtotal": "",
|
"rates_subtotal": "",
|
||||||
|
"reconciliation": {
|
||||||
|
"billlinestotal": "",
|
||||||
|
"byassoc": "",
|
||||||
|
"byprice": "",
|
||||||
|
"joblinestotal": "",
|
||||||
|
"multipleactprices": "",
|
||||||
|
"multiplebilllines": "",
|
||||||
|
"multiplebillsforactprice": ""
|
||||||
|
},
|
||||||
"reconciliationheader": "",
|
"reconciliationheader": "",
|
||||||
"sale_labor": "",
|
"sale_labor": "",
|
||||||
"sale_parts": "",
|
"sale_parts": "",
|
||||||
|
|||||||
@@ -96,6 +96,7 @@
|
|||||||
},
|
},
|
||||||
"labels": {
|
"labels": {
|
||||||
"entered": "",
|
"entered": "",
|
||||||
|
"from": "",
|
||||||
"other": "",
|
"other": "",
|
||||||
"reconciled": "",
|
"reconciled": "",
|
||||||
"unreconciled": ""
|
"unreconciled": ""
|
||||||
@@ -1048,6 +1049,15 @@
|
|||||||
"partstotal": "",
|
"partstotal": "",
|
||||||
"rates": "Les taux",
|
"rates": "Les taux",
|
||||||
"rates_subtotal": "",
|
"rates_subtotal": "",
|
||||||
|
"reconciliation": {
|
||||||
|
"billlinestotal": "",
|
||||||
|
"byassoc": "",
|
||||||
|
"byprice": "",
|
||||||
|
"joblinestotal": "",
|
||||||
|
"multipleactprices": "",
|
||||||
|
"multiplebilllines": "",
|
||||||
|
"multiplebillsforactprice": ""
|
||||||
|
},
|
||||||
"reconciliationheader": "",
|
"reconciliationheader": "",
|
||||||
"sale_labor": "",
|
"sale_labor": "",
|
||||||
"sale_parts": "",
|
"sale_parts": "",
|
||||||
|
|||||||
Reference in New Issue
Block a user