From 0dbacf0b9e8f793e2a6267d54c6c880036bd8671 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Wed, 20 May 2020 10:03:03 -0700 Subject: [PATCH] Fixed bugs on parts allocations + added totals BOD-131 --- .../job-totals-table/job-totals.utility.js | 1 - ...jobs-close-allocation-button.component.jsx | 3 + ...jobs-close-labmat-allocation.component.jsx | 26 +------- .../jobs-close-parts-allocation.component.jsx | 12 +++- .../jobs-close-totals.component.jsx | 60 +++++++++++++++++++ ...p-info.responsibilitycenters.component.jsx | 2 +- .../pages/jobs-close/jobs-close.component.jsx | 45 ++++++++++++-- .../pages/jobs-close/jobs-close.container.jsx | 1 - 8 files changed, 118 insertions(+), 32 deletions(-) create mode 100644 client/src/components/jobs-close-totals/jobs-close-totals.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 73bee0b4a..818d8c3c7 100644 --- a/client/src/components/job-totals-table/job-totals.utility.js +++ b/client/src/components/job-totals-table/job-totals.utility.js @@ -215,7 +215,6 @@ 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": diff --git a/client/src/components/jobs-close-allocation-button/jobs-close-allocation-button.component.jsx b/client/src/components/jobs-close-allocation-button/jobs-close-allocation-button.component.jsx index 00242bf88..30f606b5a 100644 --- a/client/src/components/jobs-close-allocation-button/jobs-close-allocation-button.component.jsx +++ b/client/src/components/jobs-close-allocation-button/jobs-close-allocation-button.component.jsx @@ -22,10 +22,12 @@ export function JobsCloseLabmatAllocationButton({ const [visible, setVisible] = useState(false); const [state, setState] = useState({ center: "", amount: 0 }); const { t } = useTranslation(); + const handleAllocate = () => { const existingIndex = allocation.allocations.findIndex( (e) => e.center === state.center ); + console.log("handleAllocate -> existingIndex", existingIndex); const newAllocations = allocation.allocations.slice(0); if (existingIndex > -1) { @@ -41,6 +43,7 @@ export function JobsCloseLabmatAllocationButton({ amount: Dinero({ amount: state.amount * 100 }), }); } + setAllocations((labMatState) => { return { ...labMatState, diff --git a/client/src/components/jobs-close-labmat-allocation/jobs-close-labmat-allocation.component.jsx b/client/src/components/jobs-close-labmat-allocation/jobs-close-labmat-allocation.component.jsx index f7d6e3cea..d325fe7aa 100644 --- a/client/src/components/jobs-close-labmat-allocation/jobs-close-labmat-allocation.component.jsx +++ b/client/src/components/jobs-close-labmat-allocation/jobs-close-labmat-allocation.component.jsx @@ -1,28 +1,18 @@ +import Dinero from "dinero.js"; import React from "react"; import { useTranslation } from "react-i18next"; import AllocationButton from "../jobs-close-allocation-button/jobs-close-allocation-button.component"; -import Dinero from "dinero.js"; import AllocationTags from "../jobs-close-allocation-tags/jobs-close-allocation-tags.component"; -import { List } from "antd"; export default function JobCloseLabMatAllocation({ labmatAllocations, setLabmatAllocations, + labMatTotalAllocation }) { const { t } = useTranslation(); - const allocatedTotalsArray = Object.keys(labmatAllocations) - .filter((i) => !i.includes("subtotal")) - .map((i) => labmatAllocations[i].allocations) - .flat(); - const allocatedTotal = Dinero({ - amount: allocatedTotalsArray.reduce((acc, val) => { - console.log("acc", acc); - return (acc = acc + val.amount.getAmount()); - }, 0), - }); return (
@@ -81,22 +71,12 @@ export default function JobCloseLabMatAllocation({ {labmatAllocations.subtotal.toFormat()} - {allocatedTotal.toFormat()} + {labMatTotalAllocation.toFormat()} - -
- - {allocatedTotalsArray.map((i, idx) => ( - {`${ - i.center - } ${i.amount.toFormat()}`} - ))} - -
); } diff --git a/client/src/components/jobs-close-parts-allocation/jobs-close-parts-allocation.component.jsx b/client/src/components/jobs-close-parts-allocation/jobs-close-parts-allocation.component.jsx index 234568183..13a040fcb 100644 --- a/client/src/components/jobs-close-parts-allocation/jobs-close-parts-allocation.component.jsx +++ b/client/src/components/jobs-close-parts-allocation/jobs-close-parts-allocation.component.jsx @@ -7,6 +7,7 @@ import AllocationTags from "../jobs-close-allocation-tags/jobs-close-allocation- export default function JobsClosePartsAllocation({ partsAllocations, setPartsAllocations, + partsAllocatedTotal, }) { const { t } = useTranslation(); @@ -65,8 +66,15 @@ export default function JobsClosePartsAllocation({ })} - - + + {Dinero({ + amount: Object.keys(partsAllocations).reduce((acc, val) => { + return (acc = + acc + partsAllocations[val].total.getAmount()); + }, 0), + }).toFormat()} + + {partsAllocatedTotal.toFormat()} diff --git a/client/src/components/jobs-close-totals/jobs-close-totals.component.jsx b/client/src/components/jobs-close-totals/jobs-close-totals.component.jsx new file mode 100644 index 000000000..eb778c8c9 --- /dev/null +++ b/client/src/components/jobs-close-totals/jobs-close-totals.component.jsx @@ -0,0 +1,60 @@ +import { Descriptions, Statistic } from "antd"; +import React from "react"; +import { useTranslation } from "react-i18next"; +export default function JobsCloseTotals({ + jobTotals, + labMatTotal, + partsTotal, +}) { + const { t } = useTranslation(); + return ( +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ ); +} diff --git a/client/src/components/shop-info/shop-info.responsibilitycenters.component.jsx b/client/src/components/shop-info/shop-info.responsibilitycenters.component.jsx index 6b18d26af..a7a53f865 100644 --- a/client/src/components/shop-info/shop-info.responsibilitycenters.component.jsx +++ b/client/src/components/shop-info/shop-info.responsibilitycenters.component.jsx @@ -1,5 +1,5 @@ import { DeleteFilled } from "@ant-design/icons"; -import { Button, Form, Input, Select, Row, Col } from "antd"; +import { Button, Form, Input, Select } from "antd"; import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import styled from "styled-components"; diff --git a/client/src/pages/jobs-close/jobs-close.component.jsx b/client/src/pages/jobs-close/jobs-close.component.jsx index 95492c4dd..47efb52cc 100644 --- a/client/src/pages/jobs-close/jobs-close.component.jsx +++ b/client/src/pages/jobs-close/jobs-close.component.jsx @@ -4,6 +4,8 @@ import { createStructuredSelector } from "reselect"; import JobsCloseLaborMaterialAllocation from "../../components/jobs-close-labmat-allocation/jobs-close-labmat-allocation.component"; import { selectBodyshop } from "../../redux/user/user.selectors"; import JobsClosePartsAllocation from "../../components/jobs-close-parts-allocation/jobs-close-parts-allocation.component"; +import Dinero from "dinero.js"; +import JobsCloseTotals from "../../components/jobs-close-totals/jobs-close-totals.component"; const mapStateToProps = createStructuredSelector({ //currentUser: selectCurrentUser @@ -20,24 +22,59 @@ export function JobsCloseComponent({ job, bodyshop, jobTotals }) { return acc; }, {}) ); + console.log("JobsCloseComponent -> labmatAllocations", labmatAllocations); - const [partsAllocations, setPartsAllocations] = useState( - Object.keys(jobTotals.parts.parts.list).reduce((acc, val) => { + const [partsAllocations, setPartsAllocations] = useState({ + ...Object.keys(jobTotals.parts.parts.list).reduce((acc, val) => { acc[val] = { ...jobTotals.parts.parts.list[val], allocations: [] }; return acc; - }, {}) - ); + }, {}), + sublet: { + ...jobTotals.parts.sublets, + allocations: [], + }, + }); + + console.log("JobsCloseComponent -> partsAllocations", partsAllocations); + + const labmatAllocatedTotalsArray = Object.keys(labmatAllocations) + .filter((i) => !i.includes("subtotal")) + .map((i) => labmatAllocations[i].allocations) + .flat(); + + const labmatAllocatedTotal = Dinero({ + amount: labmatAllocatedTotalsArray.reduce((acc, val) => { + return (acc = acc + val.amount.getAmount()); + }, 0), + }); + + const partsAllocatedTotalsArray = Object.keys(partsAllocations) + .map((i) => partsAllocations[i].allocations) + .flat(); + + const partsAllocatedTotal = Dinero({ + amount: partsAllocatedTotalsArray.reduce((acc, val) => { + return (acc = acc + val.amount.getAmount()); + }, 0), + }); return (
+
); diff --git a/client/src/pages/jobs-close/jobs-close.container.jsx b/client/src/pages/jobs-close/jobs-close.container.jsx index 6e10a7f15..9db92b84b 100644 --- a/client/src/pages/jobs-close/jobs-close.container.jsx +++ b/client/src/pages/jobs-close/jobs-close.container.jsx @@ -50,7 +50,6 @@ export function JobsCloseContainer({ setBreadcrumbs, bodyshop }) { ]); }, [setBreadcrumbs, t, jobId, data]); - console.log("Container rerender"); if (loading) return ; if (error) return ;