Reformat all project files to use the prettier config file.

This commit is contained in:
Patrick Fic
2024-03-27 15:35:07 -07:00
parent b161530381
commit e1df64d592
873 changed files with 111387 additions and 125473 deletions

View File

@@ -1,118 +1,81 @@
import {Button, Space, Statistic} from "antd";
import { Button, Space, Statistic } from "antd";
import Dinero from "dinero.js";
import _ from "lodash";
import React, {useMemo, useState} from "react";
import {useTranslation} from "react-i18next";
import {reconcileByAssocLine, reconcileByPrice,} from "./job-reconciliation-totals.utility";
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,
jobLineState,
billLineState,
}) {
const [errors, setErrors] = useState([]);
const {t} = useTranslation();
const selectedBillLines = billLineState[0];
const selectedJobLines = jobLineState[0];
export default function JobReconciliationTotals({ billLines, jobLines, jobLineState, billLineState }) {
const [errors, setErrors] = useState([]);
const { t } = useTranslation();
const selectedBillLines = billLineState[0];
const selectedJobLines = jobLineState[0];
const totals = useMemo(() => {
const jlLookup = _.keyBy(selectedJobLines, (i) => i);
const billLookup = _.keyBy(selectedBillLines, (i) => i);
const totals = useMemo(() => {
const jlLookup = _.keyBy(selectedJobLines, (i) => i);
const billLookup = _.keyBy(selectedBillLines, (i) => i);
return {
joblinesTotal: jobLines
.filter((jl) => !!jlLookup[jl.id])
.reduce((acc, val) => {
return acc.add(
Dinero({amount: Math.round((val.act_price || 0) * 100)}).multiply(
val.part_qty || 1
)
);
}, Dinero()),
billLinesTotal: billLines
.filter((bl) => !!billLookup[bl.id])
.reduce((acc, val) => {
return acc.add(
Dinero({
amount: Math.round((val.actual_price || 0) * 100),
})
.multiply(val.quantity || 1)
.multiply(val.bill.is_credit_memo ? -1 : 1)
);
}, Dinero()),
};
}, [billLines, jobLines, selectedBillLines, selectedJobLines]);
return {
joblinesTotal: jobLines
.filter((jl) => !!jlLookup[jl.id])
.reduce((acc, val) => {
return acc.add(Dinero({ amount: Math.round((val.act_price || 0) * 100) }).multiply(val.part_qty || 1));
}, Dinero()),
billLinesTotal: billLines
.filter((bl) => !!billLookup[bl.id])
.reduce((acc, val) => {
return acc.add(
Dinero({
amount: Math.round((val.actual_price || 0) * 100)
})
.multiply(val.quantity || 1)
.multiply(val.bill.is_credit_memo ? -1 : 1)
);
}, Dinero())
};
}, [billLines, jobLines, selectedBillLines, selectedJobLines]);
return (
<div style={{display: "inline-block"}}>
<div>
<Space>
<Statistic
title={t("jobs.labels.reconciliation.joblinestotal")}
value={totals.joblinesTotal.toFormat()}
/>
<Statistic
title={t("jobs.labels.reconciliation.billlinestotal")}
value={totals.billLinesTotal.toFormat()}
/>
<Statistic
title={t("jobs.labels.reconciliation.discrepancy")}
value={totals.joblinesTotal
.subtract(totals.billLinesTotal)
.toFormat()}
/>
</Space>
</div>
<div>
<Space direction="horizontal">
<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>
<Button
onClick={() => {
jobLineState[1]([]);
billLineState[1]([]);
setErrors([]);
}}
>
{t("jobs.labels.reconciliation.clear")}
</Button>
</Space>
</div>
{errors.length > 0 && (
<div>
{t("general.labels.errors")}
<ul>
{errors.map((error, idx) => (
<li key={idx}>{error}</li>
))}
</ul>
</div>
)}
return (
<div style={{ display: "inline-block" }}>
<div>
<Space>
<Statistic title={t("jobs.labels.reconciliation.joblinestotal")} value={totals.joblinesTotal.toFormat()} />
<Statistic title={t("jobs.labels.reconciliation.billlinestotal")} value={totals.billLinesTotal.toFormat()} />
<Statistic
title={t("jobs.labels.reconciliation.discrepancy")}
value={totals.joblinesTotal.subtract(totals.billLinesTotal).toFormat()}
/>
</Space>
</div>
<div>
<Space direction="horizontal">
<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>
<Button
onClick={() => {
jobLineState[1]([]);
billLineState[1]([]);
setErrors([]);
}}
>
{t("jobs.labels.reconciliation.clear")}
</Button>
</Space>
</div>
{errors.length > 0 && (
<div>
{t("general.labels.errors")}
<ul>
{errors.map((error, idx) => (
<li key={idx}>{error}</li>
))}
</ul>
</div>
);
)}
</div>
);
}

View File

@@ -1,112 +1,89 @@
import i18next from "i18next";
import _ from "lodash";
export const reconcileByAssocLine = (
jobLines,
jobLineState,
billLines,
billLineState,
setErrors
) => {
const [selectedBillLines, setSelectedBillLines] = billLineState;
const [selectedJobLines, setSelectedJobLines] = jobLineState;
export const reconcileByAssocLine = (jobLines, jobLineState, billLines, billLineState, setErrors) => {
const [selectedBillLines, setSelectedBillLines] = billLineState;
const [selectedJobLines, setSelectedJobLines] = jobLineState;
const allJoblinesFromBills = billLines
.filter((bl) => bl.joblineid && bl.jobline && !bl.jobline.removed)
.map((bl) => bl.joblineid);
const allJoblinesFromBills = billLines
.filter((bl) => bl.joblineid && bl.jobline && !bl.jobline.removed)
.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) => {
return 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 &&
bl.quantity === jl.part_qty &&
!jl.removed
)
.map((bl) => bl.id);
if (matchingBillLineIds.length > 1) {
actPricesWithMoreThan1MatchingBill.push(jl.act_price);
}
foundBillLines = [...foundBillLines, ...matchingBillLineIds];
if (matchingBillLineIds.length > 0) {
foundJobLines.push(jl.id);
}
});
const duplicatedJobLinesbyInvoiceId = _.filter(allJoblinesFromBills, (val, i, iteratee) =>
_.includes(iteratee, val, i + 1)
);
if (duplicatedJobLinesbyInvoiceId.length > 0)
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,
})
),
...errors,
..._.uniqBy(duplicatedJobLinesbyInvoiceId).map((dupedId) => {
return i18next.t("jobs.labels.reconciliation.multiplebilllines", {
line_desc: jobLines.find((j) => j.id === dupedId)?.line_desc
});
})
]);
setSelectedBillLines(_.union(selectedBillLines, _.uniqBy(foundBillLines)));
setSelectedBillLines(
_.union(
selectedBillLines,
billLines.filter((bl) => !!bl.joblineid).map((bl) => bl.id)
)
);
setSelectedJobLines(_.union(selectedJobLines, _.uniqBy(foundJobLines)));
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 && bl.quantity === jl.part_qty && !jl.removed)
.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)));
};