Fixed bugs on parts allocations + added totals BOD-131
This commit is contained in:
@@ -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":
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 (
|
||||
<div style={{ display: "flex" }}>
|
||||
@@ -81,22 +71,12 @@ export default function JobCloseLabMatAllocation({
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>{labmatAllocations.subtotal.toFormat()}</td>
|
||||
<td>{allocatedTotal.toFormat()}</td>
|
||||
<td>{labMatTotalAllocation.toFormat()}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div>
|
||||
<List>
|
||||
{allocatedTotalsArray.map((i, idx) => (
|
||||
<List.Item key={idx}>{`${
|
||||
i.center
|
||||
} ${i.amount.toFormat()}`}</List.Item>
|
||||
))}
|
||||
</List>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
})}
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>
|
||||
{Dinero({
|
||||
amount: Object.keys(partsAllocations).reduce((acc, val) => {
|
||||
return (acc =
|
||||
acc + partsAllocations[val].total.getAmount());
|
||||
}, 0),
|
||||
}).toFormat()}
|
||||
</td>
|
||||
<td>{partsAllocatedTotal.toFormat()}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
@@ -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 (
|
||||
<div>
|
||||
<Descriptions
|
||||
bordered
|
||||
size="small"
|
||||
//column={1}
|
||||
title={t("jobs.labels.totals")}
|
||||
>
|
||||
<Descriptions.Item label={t("jobs.labels.partstotal")}>
|
||||
<Statistic
|
||||
value={jobTotals.parts.parts.total.toFormat()}
|
||||
suffix={`(${jobTotals.parts.parts.subtotal.toFormat()} ± ${jobTotals.parts.parts.adjustments.toFormat()})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.labels.subletstotal")}>
|
||||
<Statistic
|
||||
value={jobTotals.parts.sublets.total.toFormat()}
|
||||
suffix={`(${jobTotals.parts.sublets.subtotal.toFormat()} ± ${jobTotals.parts.sublets.adjustments.toFormat()})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.labels.subtotal")}>
|
||||
<Statistic value={jobTotals.totals.subtotal.toFormat()} />
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.labels.federal_tax_amt")}>
|
||||
<Statistic value={jobTotals.totals.federal_tax.toFormat()} />
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.labels.state_tax_amt")}>
|
||||
<Statistic value={jobTotals.totals.state_tax.toFormat()} />
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.labels.local_tax_amt")}>
|
||||
<Statistic value={jobTotals.totals.local_tax.toFormat()} />
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
<Statistic
|
||||
title={t("jobs.labels.total_repairs")}
|
||||
value={jobTotals.totals.total_repairs.toFormat()}
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.net_repairs")}
|
||||
value={jobTotals.totals.net_repairs.toFormat()}
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.suspense")}
|
||||
value={jobTotals.totals.subtotal
|
||||
.subtract(labMatTotal)
|
||||
.subtract(partsTotal)
|
||||
.toFormat()}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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";
|
||||
|
||||
@@ -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 (
|
||||
<div>
|
||||
<JobsCloseTotals
|
||||
jobTotals={jobTotals}
|
||||
labMatTotal={labmatAllocatedTotal}
|
||||
partsTotal={partsAllocatedTotal}
|
||||
/>
|
||||
<JobsCloseLaborMaterialAllocation
|
||||
labmatAllocations={labmatAllocations}
|
||||
setLabmatAllocations={setLabmatAllocations}
|
||||
labMatTotalAllocation={labmatAllocatedTotal}
|
||||
/>
|
||||
<JobsClosePartsAllocation
|
||||
partsAllocations={partsAllocations}
|
||||
setPartsAllocations={setPartsAllocations}
|
||||
partsAllocatedTotal={partsAllocatedTotal}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -50,7 +50,6 @@ export function JobsCloseContainer({ setBreadcrumbs, bodyshop }) {
|
||||
]);
|
||||
}, [setBreadcrumbs, t, jobId, data]);
|
||||
|
||||
console.log("Container rerender");
|
||||
if (loading) return <LoadingSpinner />;
|
||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user