From 94777bf661bc966e517e086b32100ca1c93cc285 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Tue, 19 May 2020 17:59:02 -0700 Subject: [PATCH] Added parts table for job close BOD-131 --- .../job-totals-table/job-totals.utility.js | 20 +++++ ...obs-close-allocation-button.component.jsx} | 23 +++--- .../jobs-close-allocation-tags.component.jsx} | 16 ++-- ...jobs-close-labmat-allocation.component.jsx | 17 ++-- .../jobs-close-parts-allocation.component.jsx | 78 +++++++++++++++++++ .../pages/jobs-close/jobs-close.component.jsx | 13 ++++ 6 files changed, 141 insertions(+), 26 deletions(-) rename client/src/components/{jobs-close-labmat-allocation/jobs-close-labmat-allocation.button.component.jsx => jobs-close-allocation-button/jobs-close-allocation-button.component.jsx} (84%) rename client/src/components/{jobs-close-labmat-allocation/jobs-close-labmat-allocation.allocation-tags.component.jsx => jobs-close-allocation-tags/jobs-close-allocation-tags.component.jsx} (61%) create mode 100644 client/src/components/jobs-close-parts-allocation/jobs-close-parts-allocation.component.jsx diff --git a/client/src/components/job-totals-table/job-totals.utility.js b/client/src/components/job-totals-table/job-totals.utility.js index 0b1ae7db3..73bee0b4a 100644 --- a/client/src/components/job-totals-table/job-totals.utility.js +++ b/client/src/components/job-totals-table/job-totals.utility.js @@ -215,6 +215,7 @@ function CalculateRatesTotals(ratesList, shoprates) { function CalculatePartsTotals(jobLines) { const ret = jobLines.reduce( (acc, value) => { + console.log("Parts Calc", value.act_price, value.part_qty, value); switch (value.part_type) { case "PAA": case "PAC": @@ -229,6 +230,24 @@ function CalculatePartsTotals(jobLines) { ...acc, parts: { ...acc.parts, + list: { + ...acc.parts.list, + [value.part_type]: + acc.parts.list[value.part_type] && + acc.parts.list[value.part_type].total + ? { + total: acc.parts.list[value.part_type].total.add( + Dinero({ amount: value.act_price * 100 }).multiply( + value.part_qty + ) + ), + } + : { + total: Dinero({ + amount: (value.act_price || 0) * 100, + }).multiply(value.part_qty), + }, + }, subtotal: acc.parts.subtotal.add( Dinero({ amount: value.act_price * 100 }).multiply( value.part_qty @@ -255,6 +274,7 @@ function CalculatePartsTotals(jobLines) { }, { parts: { + list: {}, subtotal: Dinero({ amount: 0 }), adjustments: Dinero({ amount: 0 }), total: Dinero({ amount: 0 }), diff --git a/client/src/components/jobs-close-labmat-allocation/jobs-close-labmat-allocation.button.component.jsx b/client/src/components/jobs-close-allocation-button/jobs-close-allocation-button.component.jsx similarity index 84% rename from client/src/components/jobs-close-labmat-allocation/jobs-close-labmat-allocation.button.component.jsx rename to client/src/components/jobs-close-allocation-button/jobs-close-allocation-button.component.jsx index 27b9a3c4a..00242bf88 100644 --- a/client/src/components/jobs-close-labmat-allocation/jobs-close-labmat-allocation.button.component.jsx +++ b/client/src/components/jobs-close-allocation-button/jobs-close-allocation-button.component.jsx @@ -14,20 +14,20 @@ const mapStateToProps = createStructuredSelector({ const { Option } = Select; export function JobsCloseLabmatAllocationButton({ - labmatAllocationKey, - labmatAllocation, - setLabmatAllocations, + allocationKey, + allocation, + setAllocations, bodyshop, }) { const [visible, setVisible] = useState(false); const [state, setState] = useState({ center: "", amount: 0 }); const { t } = useTranslation(); const handleAllocate = () => { - const existingIndex = labmatAllocation.allocations.findIndex( + const existingIndex = allocation.allocations.findIndex( (e) => e.center === state.center ); - const newAllocations = labmatAllocation.allocations.slice(0); + const newAllocations = allocation.allocations.slice(0); if (existingIndex > -1) { newAllocations[existingIndex] = { center: state.center, @@ -41,17 +41,19 @@ export function JobsCloseLabmatAllocationButton({ amount: Dinero({ amount: state.amount * 100 }), }); } - setLabmatAllocations((labMatState) => { + setAllocations((labMatState) => { return { ...labMatState, - [labmatAllocationKey]: { - ...labmatAllocation, + [allocationKey]: { + ...allocation, allocations: newAllocations, }, }; }); + + setState({ center: "", amount: 0 }); }; - const showAllocation = labmatAllocation.total.getAmount() > 0; + const showAllocation = allocation.total.getAmount() > 0; if (!showAllocation) return null; return ( @@ -71,8 +73,9 @@ export function JobsCloseLabmatAllocationButton({ setState({ ...state, amount: val })} - max={labmatAllocation.total.getAmount() / 100} + max={allocation.total.getAmount() / 100} />