Added parts table for job close BOD-131

This commit is contained in:
Patrick Fic
2020-05-19 17:59:02 -07:00
parent bdead5b4a0
commit 94777bf661
6 changed files with 141 additions and 26 deletions

View File

@@ -215,6 +215,7 @@ function CalculateRatesTotals(ratesList, shoprates) {
function CalculatePartsTotals(jobLines) { function CalculatePartsTotals(jobLines) {
const ret = jobLines.reduce( const ret = jobLines.reduce(
(acc, value) => { (acc, value) => {
console.log("Parts Calc", value.act_price, value.part_qty, value);
switch (value.part_type) { switch (value.part_type) {
case "PAA": case "PAA":
case "PAC": case "PAC":
@@ -229,6 +230,24 @@ function CalculatePartsTotals(jobLines) {
...acc, ...acc,
parts: { parts: {
...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( subtotal: acc.parts.subtotal.add(
Dinero({ amount: value.act_price * 100 }).multiply( Dinero({ amount: value.act_price * 100 }).multiply(
value.part_qty value.part_qty
@@ -255,6 +274,7 @@ function CalculatePartsTotals(jobLines) {
}, },
{ {
parts: { parts: {
list: {},
subtotal: Dinero({ amount: 0 }), subtotal: Dinero({ amount: 0 }),
adjustments: Dinero({ amount: 0 }), adjustments: Dinero({ amount: 0 }),
total: Dinero({ amount: 0 }), total: Dinero({ amount: 0 }),

View File

@@ -14,20 +14,20 @@ const mapStateToProps = createStructuredSelector({
const { Option } = Select; const { Option } = Select;
export function JobsCloseLabmatAllocationButton({ export function JobsCloseLabmatAllocationButton({
labmatAllocationKey, allocationKey,
labmatAllocation, allocation,
setLabmatAllocations, setAllocations,
bodyshop, bodyshop,
}) { }) {
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [state, setState] = useState({ center: "", amount: 0 }); const [state, setState] = useState({ center: "", amount: 0 });
const { t } = useTranslation(); const { t } = useTranslation();
const handleAllocate = () => { const handleAllocate = () => {
const existingIndex = labmatAllocation.allocations.findIndex( const existingIndex = allocation.allocations.findIndex(
(e) => e.center === state.center (e) => e.center === state.center
); );
const newAllocations = labmatAllocation.allocations.slice(0); const newAllocations = allocation.allocations.slice(0);
if (existingIndex > -1) { if (existingIndex > -1) {
newAllocations[existingIndex] = { newAllocations[existingIndex] = {
center: state.center, center: state.center,
@@ -41,17 +41,19 @@ export function JobsCloseLabmatAllocationButton({
amount: Dinero({ amount: state.amount * 100 }), amount: Dinero({ amount: state.amount * 100 }),
}); });
} }
setLabmatAllocations((labMatState) => { setAllocations((labMatState) => {
return { return {
...labMatState, ...labMatState,
[labmatAllocationKey]: { [allocationKey]: {
...labmatAllocation, ...allocation,
allocations: newAllocations, allocations: newAllocations,
}, },
}; };
}); });
setState({ center: "", amount: 0 });
}; };
const showAllocation = labmatAllocation.total.getAmount() > 0; const showAllocation = allocation.total.getAmount() > 0;
if (!showAllocation) return null; if (!showAllocation) return null;
return ( return (
@@ -71,8 +73,9 @@ export function JobsCloseLabmatAllocationButton({
<InputNumber <InputNumber
precision={2} precision={2}
min={0} min={0}
value={state.amount}
onChange={(val) => setState({ ...state, amount: val })} onChange={(val) => setState({ ...state, amount: val })}
max={labmatAllocation.total.getAmount() / 100} max={allocation.total.getAmount() / 100}
/> />
<Button <Button
onClick={handleAllocate} onClick={handleAllocate}

View File

@@ -1,23 +1,23 @@
import React from "react"; import React from "react";
import { Tag } from "antd"; import { Tag } from "antd";
export default function JobsCloseLabMatAllocationTags({ export default function JobsCloseLabMatAllocationTags({
labmatAllocationKey, allocationKey,
labmatAllocation, allocation,
setLabmatAllocations, setAllocations,
}) { }) {
return ( return (
<div> <div>
{labmatAllocation.allocations.map((a, idx) => ( {allocation.allocations.map((a, idx) => (
<Tag <Tag
closable closable
visible visible
onClose={() => { onClose={() => {
setLabmatAllocations((state) => { setAllocations((state) => {
return { return {
...state, ...state,
[labmatAllocationKey]: { [allocationKey]: {
...labmatAllocation, ...allocation,
allocations: labmatAllocation.allocations.filter( allocations: allocation.allocations.filter(
(val, index) => index !== idx (val, index) => index !== idx
), ),
}, },

View File

@@ -1,8 +1,9 @@
import React from "react"; import React from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import AllocationButton from "./jobs-close-labmat-allocation.button.component"; import AllocationButton from "../jobs-close-allocation-button/jobs-close-allocation-button.component";
import Dinero from "dinero.js"; import Dinero from "dinero.js";
import AllocationTags from "./jobs-close-labmat-allocation.allocation-tags.component"; import AllocationTags from "../jobs-close-allocation-tags/jobs-close-allocation-tags.component";
import { List } from "antd"; import { List } from "antd";
export default function JobCloseLabMatAllocation({ export default function JobCloseLabMatAllocation({
@@ -61,16 +62,16 @@ export default function JobCloseLabMatAllocation({
</td> </td>
<td> <td>
<AllocationButton <AllocationButton
labmatAllocationKey={alloc} allocationKey={alloc}
labmatAllocation={labmatAllocations[alloc]} allocation={labmatAllocations[alloc]}
setLabmatAllocations={setLabmatAllocations} setAllocations={setLabmatAllocations}
/> />
</td> </td>
<td> <td>
<AllocationTags <AllocationTags
labmatAllocationKey={alloc} allocationKey={alloc}
labmatAllocation={labmatAllocations[alloc]} allocation={labmatAllocations[alloc]}
setLabmatAllocations={setLabmatAllocations} setAllocations={setLabmatAllocations}
/> />
</td> </td>
</tr> </tr>

View File

@@ -0,0 +1,78 @@
import React from "react";
import { useTranslation } from "react-i18next";
import Dinero from "dinero.js";
import AllocationButton from "../jobs-close-allocation-button/jobs-close-allocation-button.component";
import AllocationTags from "../jobs-close-allocation-tags/jobs-close-allocation-tags.component";
export default function JobsClosePartsAllocation({
partsAllocations,
setPartsAllocations,
}) {
const { t } = useTranslation();
return (
<div>
{
<table>
<thead>
<tr>
<th>{t("jobs.labels.laborallocations")}</th>
<th>{t("jobs.labels.totals")}</th>
<th>{t("jobs.labels.available")}</th>
<th>{t("jobs.actions.allocate")}</th>
<th>{t("jobs.labels.allocations")}</th>
</tr>
</thead>
<tbody>
{Object.keys(partsAllocations).map((alloc, idx) => {
return (
<tr key={idx}>
<td>{t(`jobs.fields.${alloc}`)}</td>
<td>
{partsAllocations[alloc].total &&
partsAllocations[alloc].total.toFormat()}
</td>
<td>
{partsAllocations[alloc].total
.subtract(
Dinero({
amount: partsAllocations[alloc].allocations.reduce(
(acc, val) => {
return acc + val.amount.getAmount();
},
0
),
})
)
.toFormat()}
</td>
<td>
<AllocationButton
allocationKey={alloc}
allocation={partsAllocations[alloc]}
setAllocations={setPartsAllocations}
/>
</td>
<td>
<AllocationTags
allocationKey={alloc}
allocation={partsAllocations[alloc]}
setAllocations={setPartsAllocations}
/>
</td>
</tr>
);
})}
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
}
</div>
);
}

View File

@@ -3,6 +3,7 @@ import { connect } from "react-redux";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
import JobsCloseLaborMaterialAllocation from "../../components/jobs-close-labmat-allocation/jobs-close-labmat-allocation.component"; import JobsCloseLaborMaterialAllocation from "../../components/jobs-close-labmat-allocation/jobs-close-labmat-allocation.component";
import { selectBodyshop } from "../../redux/user/user.selectors"; import { selectBodyshop } from "../../redux/user/user.selectors";
import JobsClosePartsAllocation from "../../components/jobs-close-parts-allocation/jobs-close-parts-allocation.component";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
//currentUser: selectCurrentUser //currentUser: selectCurrentUser
@@ -20,12 +21,24 @@ export function JobsCloseComponent({ job, bodyshop, jobTotals }) {
}, {}) }, {})
); );
const [partsAllocations, setPartsAllocations] = useState(
Object.keys(jobTotals.parts.parts.list).reduce((acc, val) => {
acc[val] = { ...jobTotals.parts.parts.list[val], allocations: [] };
return acc;
}, {})
);
return ( return (
<div> <div>
<JobsCloseLaborMaterialAllocation <JobsCloseLaborMaterialAllocation
labmatAllocations={labmatAllocations} labmatAllocations={labmatAllocations}
setLabmatAllocations={setLabmatAllocations} setLabmatAllocations={setLabmatAllocations}
/> />
<JobsClosePartsAllocation
partsAllocations={partsAllocations}
setPartsAllocations={setPartsAllocations}
/>
</div> </div>
); );
} }