Refactored capturing of resp. centers. + added auto allocate BOD-131
This commit is contained in:
@@ -28,165 +28,167 @@ export function JobsTotalsTableComponent({ bodyshop, job }) {
|
||||
<Row>
|
||||
<Descriptions
|
||||
bordered
|
||||
size='small'
|
||||
size="small"
|
||||
column={3}
|
||||
title={t("jobs.labels.rates")}>
|
||||
title={t("jobs.labels.rates")}
|
||||
>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_laa")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_laa.total.toFormat()}
|
||||
value={totals.rates.laa.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_laa.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_laa.rate})`}
|
||||
suffix={`(${totals.rates.laa.hours.toFixed(2)} @ ${
|
||||
totals.rates.laa.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lab")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lab.total.toFormat()}
|
||||
value={totals.rates.lab.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lab.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lab.rate})`}
|
||||
suffix={`(${totals.rates.lab.hours.toFixed(2)} @ ${
|
||||
totals.rates.lab.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lad")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lad.total.toFormat()}
|
||||
value={totals.rates.lad.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lad.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lad.rate})`}
|
||||
suffix={`(${totals.rates.lad.hours.toFixed(2)} @ ${
|
||||
totals.rates.lad.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lae")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lae.total.toFormat()}
|
||||
value={totals.rates.lae.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lae.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lae.rate})`}
|
||||
suffix={`(${totals.rates.lae.hours.toFixed(2)} @ ${
|
||||
totals.rates.lae.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_laf")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_laf.total.toFormat()}
|
||||
value={totals.rates.laf.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_laf.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_laf.rate})`}
|
||||
suffix={`(${totals.rates.laf.hours.toFixed(2)} @ ${
|
||||
totals.rates.laf.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lag")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lag.total.toFormat()}
|
||||
value={totals.rates.lag.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lag.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lag.rate})`}
|
||||
suffix={`(${totals.rates.lag.hours.toFixed(2)} @ ${
|
||||
totals.rates.lag.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lam")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lam.total.toFormat()}
|
||||
value={totals.rates.lam.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lam.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lam.rate})`}
|
||||
suffix={`(${totals.rates.lam.hours.toFixed(2)} @ ${
|
||||
totals.rates.lam.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lar")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lar.total.toFormat()}
|
||||
value={totals.rates.lar.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lar.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lar.rate})`}
|
||||
suffix={`(${totals.rates.lar.hours.toFixed(2)} @ ${
|
||||
totals.rates.lar.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_las")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_las.total.toFormat()}
|
||||
value={totals.rates.las.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_las.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_las.rate})`}
|
||||
suffix={`(${totals.rates.las.hours.toFixed(2)} @ ${
|
||||
totals.rates.las.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lau")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lau.total.toFormat()}
|
||||
value={totals.rates.lau.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lau.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lau.rate})`}
|
||||
suffix={`(${totals.rates.lau.hours.toFixed(2)} @ ${
|
||||
totals.rates.lau.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_la1")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_la1.total.toFormat()}
|
||||
value={totals.rates.la1.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_la1.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_la1.rate})`}
|
||||
suffix={`(${totals.rates.la1.hours.toFixed(2)} @ ${
|
||||
totals.rates.la1.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_la2")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_la2.total.toFormat()}
|
||||
value={totals.rates.la2.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_la2.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_la2.rate})`}
|
||||
suffix={`(${totals.rates.la2.hours.toFixed(2)} @ ${
|
||||
totals.rates.la2.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_la3")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_la3.total.toFormat()}
|
||||
value={totals.rates.la3.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_la3.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_la3.rate})`}
|
||||
suffix={`(${totals.rates.la3.hours.toFixed(2)} @ ${
|
||||
totals.rates.la3.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_la4")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_la4.total.toFormat()}
|
||||
value={totals.rates.la4.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_la4.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_la4.rate})`}
|
||||
suffix={`(${totals.rates.la4.hours.toFixed(2)} @ ${
|
||||
totals.rates.la4.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_atp")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_atp.total.toFormat()}
|
||||
value={totals.rates.atp.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_atp.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_atp.rate})`}
|
||||
suffix={`(${totals.rates.atp.hours.toFixed(2)} @ ${
|
||||
totals.rates.atp.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.labels.paint_mat")}>
|
||||
<Descriptions.Item label={t("jobs.labels.mapa")}>
|
||||
<Statistic
|
||||
value={totals.rates.paint_mat.total.toFormat()}
|
||||
value={totals.rates.mapa.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.paint_mat.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.paint_mat.rate})`}
|
||||
suffix={`(${totals.rates.mapa.hours.toFixed(2)} @ ${
|
||||
totals.rates.mapa.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.labels.shop_mat")}>
|
||||
<Statistic
|
||||
value={totals.rates.shop_mat.total.toFormat()}
|
||||
value={totals.rates.mash.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.shop_mat.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.shop_mat.rate})`}
|
||||
suffix={`(${totals.rates.mash.hours.toFixed(2)} @ ${
|
||||
totals.rates.mash.rate
|
||||
})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item
|
||||
style={{ color: "red" }}
|
||||
label={t("jobs.labels.rates_subtotal")}>
|
||||
label={t("jobs.labels.rates_subtotal")}
|
||||
>
|
||||
<Statistic value={totals.rates.subtotal.toFormat()} />
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
@@ -195,9 +197,10 @@ export function JobsTotalsTableComponent({ bodyshop, job }) {
|
||||
<Col span={8}>
|
||||
<Descriptions
|
||||
bordered
|
||||
size='small'
|
||||
size="small"
|
||||
column={1}
|
||||
title={t("jobs.labels.partssubletstotal")}>
|
||||
title={t("jobs.labels.partssubletstotal")}
|
||||
>
|
||||
<Descriptions.Item label={t("jobs.labels.partstotal")}>
|
||||
<Statistic
|
||||
value={totals.parts.parts.total.toFormat()}
|
||||
@@ -216,9 +219,10 @@ export function JobsTotalsTableComponent({ bodyshop, job }) {
|
||||
<Col span={8}>
|
||||
<Descriptions
|
||||
bordered
|
||||
size='small'
|
||||
size="small"
|
||||
column={1}
|
||||
title={t("jobs.labels.totals")}>
|
||||
title={t("jobs.labels.totals")}
|
||||
>
|
||||
<Descriptions.Item label={t("jobs.labels.subtotal")}>
|
||||
<Statistic value={totals.totals.subtotal.toFormat()} />
|
||||
</Descriptions.Item>
|
||||
|
||||
@@ -23,7 +23,7 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
if (!!!val.tax_part) return acc;
|
||||
if (!!job.parts_tax_rates[val.part_type]) {
|
||||
return acc.add(
|
||||
Dinero({ amount: val.act_price * 100 })
|
||||
Dinero({ amount: Math.round(val.act_price * 100) })
|
||||
.multiply(val.part_qty)
|
||||
.percentage(
|
||||
(job.parts_tax_rates[val.part_type].prt_tax_rt || 0) * 100
|
||||
@@ -43,18 +43,18 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
otherTotals.rates.rates_subtotal.percentage((job.tax_lbr_rt || 0) * 100)
|
||||
)
|
||||
.add(
|
||||
Dinero({ amount: (job.towing_payable || 0) * 100 }).percentage(
|
||||
(job.tax_tow_rt || 0) * 100
|
||||
)
|
||||
Dinero({
|
||||
amount: Math.round((job.towing_payable || 0) * 100),
|
||||
}).percentage((job.tax_tow_rt || 0) * 100)
|
||||
)
|
||||
.add(
|
||||
Dinero({ amount: (job.storage_payable || 0) * 100 }).percentage(
|
||||
(job.tax_str_rt || 0) * 100
|
||||
)
|
||||
Dinero({
|
||||
amount: Math.round((job.storage_payable || 0) * 100),
|
||||
}).percentage((job.tax_str_rt || 0) * 100)
|
||||
)
|
||||
.add(
|
||||
otherTotals.rates.paint_mat.total
|
||||
.add(otherTotals.rates.shop_mat.total)
|
||||
otherTotals.rates.mapa.total
|
||||
.add(otherTotals.rates.mash.total)
|
||||
.percentage((job.tax_paint_mat_rt || 0) * 100)
|
||||
),
|
||||
local_tax: subtotal.percentage((job.local_tax_rate || 0) * 100),
|
||||
@@ -74,91 +74,91 @@ function CalculateRatesTotals(ratesList, shoprates) {
|
||||
const jobLines = ratesList.joblines;
|
||||
|
||||
let ret = {
|
||||
rate_la1: {
|
||||
la1: {
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LA1")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
rate: ratesList.rate_la1 || 0,
|
||||
},
|
||||
rate_la2: {
|
||||
la2: {
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LA2")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
rate: ratesList.rate_la2 || 0,
|
||||
},
|
||||
rate_la3: {
|
||||
la3: {
|
||||
rate: ratesList.rate_la3 || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LA3")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_la4: {
|
||||
la4: {
|
||||
rate: ratesList.rate_la4 || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LA4")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_laa: {
|
||||
laa: {
|
||||
rate: ratesList.rate_laa || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAA")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lab: {
|
||||
lab: {
|
||||
rate: ratesList.rate_lab || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAB")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lad: {
|
||||
lad: {
|
||||
rate: ratesList.rate_lad || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAD")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lae: {
|
||||
lae: {
|
||||
rate: ratesList.rate_lae || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAE")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_laf: {
|
||||
laf: {
|
||||
rate: ratesList.rate_laf || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAF")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lag: {
|
||||
lag: {
|
||||
rate: ratesList.rate_lag || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAG")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lam: {
|
||||
lam: {
|
||||
rate: ratesList.rate_lam || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAM")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lar: {
|
||||
lar: {
|
||||
rate: ratesList.rate_lar || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAR")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_las: {
|
||||
las: {
|
||||
rate: ratesList.rate_las || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAS")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lau: {
|
||||
lau: {
|
||||
rate: ratesList.rate_lau || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAU")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_atp: {
|
||||
atp: {
|
||||
rate: shoprates.rate_atp || 0,
|
||||
hours:
|
||||
jobLines.filter((item) => item.line_desc.includes("ATS Amount"))
|
||||
@@ -178,13 +178,13 @@ function CalculateRatesTotals(ratesList, shoprates) {
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0)
|
||||
: 0,
|
||||
},
|
||||
paint_mat: {
|
||||
mapa: {
|
||||
rate: ratesList.rate_mapa || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAR")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
shop_mat: {
|
||||
mash: {
|
||||
rate: ratesList.rate_mash || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty !== "LAR")
|
||||
@@ -200,8 +200,8 @@ function CalculateRatesTotals(ratesList, shoprates) {
|
||||
.divide(10);
|
||||
subtotal = subtotal.add(ret[property].total);
|
||||
if (
|
||||
property !== "paint_mat" &&
|
||||
property !== "shop_mat"
|
||||
property !== "mapa" &&
|
||||
property !== "mash"
|
||||
//&& property !== "rate_atp"
|
||||
)
|
||||
rates_subtotal = rates_subtotal.add(ret[property].total);
|
||||
@@ -236,19 +236,19 @@ function CalculatePartsTotals(jobLines) {
|
||||
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
|
||||
)
|
||||
Dinero({
|
||||
amount: Math.round((value.act_price || 0) * 100),
|
||||
}).multiply(value.part_qty || 1)
|
||||
),
|
||||
}
|
||||
: {
|
||||
total: Dinero({
|
||||
amount: (value.act_price || 0) * 100,
|
||||
}).multiply(value.part_qty),
|
||||
amount: Math.round((value.act_price || 0) * 100),
|
||||
}).multiply(value.part_qty || 1),
|
||||
},
|
||||
},
|
||||
subtotal: acc.parts.subtotal.add(
|
||||
Dinero({ amount: value.act_price * 100 }).multiply(
|
||||
Dinero({ amount: Math.round(value.act_price * 100) }).multiply(
|
||||
value.part_qty
|
||||
)
|
||||
),
|
||||
@@ -262,7 +262,7 @@ function CalculatePartsTotals(jobLines) {
|
||||
sublets: {
|
||||
...acc.sublets,
|
||||
subtotal: acc.sublets.subtotal.add(
|
||||
Dinero({ amount: value.act_price * 100 })
|
||||
Dinero({ amount: Math.round(value.act_price * 100) })
|
||||
),
|
||||
//TODO Add Adjustments in
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { PlusCircleFilled, CloseCircleFilled } from "@ant-design/icons";
|
||||
import { Button, InputNumber, Select } from "antd";
|
||||
import Dinero from "dinero.js";
|
||||
import React, { useState } from "react";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
@@ -14,6 +14,7 @@ const mapStateToProps = createStructuredSelector({
|
||||
const { Option } = Select;
|
||||
|
||||
export function JobsCloseLabmatAllocationButton({
|
||||
remainingAmount,
|
||||
allocationKey,
|
||||
allocation,
|
||||
setAllocations,
|
||||
@@ -27,20 +28,19 @@ export function JobsCloseLabmatAllocationButton({
|
||||
const existingIndex = allocation.allocations.findIndex(
|
||||
(e) => e.center === state.center
|
||||
);
|
||||
console.log("handleAllocate -> existingIndex", existingIndex);
|
||||
|
||||
const newAllocations = allocation.allocations.slice(0);
|
||||
if (existingIndex > -1) {
|
||||
newAllocations[existingIndex] = {
|
||||
center: state.center,
|
||||
amount: newAllocations[existingIndex].amount.add(
|
||||
Dinero({ amount: state.amount * 100 })
|
||||
Dinero({ amount: (state.amount || 0) * 100 })
|
||||
),
|
||||
};
|
||||
} else {
|
||||
newAllocations.push({
|
||||
center: state.center,
|
||||
amount: Dinero({ amount: state.amount * 100 }),
|
||||
amount: Dinero({ amount: (state.amount || 0) * 100 }),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -56,7 +56,11 @@ export function JobsCloseLabmatAllocationButton({
|
||||
|
||||
setState({ center: "", amount: 0 });
|
||||
};
|
||||
|
||||
const showAllocation = allocation.total.getAmount() > 0;
|
||||
useEffect(() => {
|
||||
if (remainingAmount === 0) setVisible(false);
|
||||
}, [remainingAmount, setVisible]);
|
||||
|
||||
if (!showAllocation) return null;
|
||||
return (
|
||||
@@ -78,11 +82,13 @@ export function JobsCloseLabmatAllocationButton({
|
||||
min={0}
|
||||
value={state.amount}
|
||||
onChange={(val) => setState({ ...state, amount: val })}
|
||||
max={allocation.total.getAmount() / 100}
|
||||
max={remainingAmount / 100}
|
||||
/>
|
||||
<Button
|
||||
onClick={handleAllocate}
|
||||
disabled={state.amount === 0 || state.center === ""}
|
||||
disabled={
|
||||
state.amount === 0 || state.center === "" || remainingAmount === 0
|
||||
}
|
||||
>
|
||||
{t("jobs.actions.allocate")}
|
||||
</Button>
|
||||
|
||||
@@ -11,6 +11,7 @@ export default function JobsCloseLabMatAllocationTags({
|
||||
<Tag
|
||||
closable
|
||||
visible
|
||||
color='green'
|
||||
onClose={() => {
|
||||
setAllocations((state) => {
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import React from "react";
|
||||
import { Button } from "antd";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { useTranslation } from "react-i18next";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
|
||||
export function JobsCloseAutoAllocate({
|
||||
bodyshop,
|
||||
labmatAllocations,
|
||||
setLabmatAllocations,
|
||||
partsAllocations,
|
||||
setPartsAllocations,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const handleAllocate = () => {
|
||||
const { defaults } = bodyshop.md_responsibility_centers;
|
||||
|
||||
Object.keys(labmatAllocations).forEach((i) => {
|
||||
const defaultProfitCenter = defaults.profits[i.toUpperCase()];
|
||||
|
||||
if (!!defaultProfitCenter && labmatAllocations[i].total.getAmount() > 0) {
|
||||
setLabmatAllocations((st) => {
|
||||
return {
|
||||
...st,
|
||||
[i]: {
|
||||
...labmatAllocations[i],
|
||||
allocations: [
|
||||
{
|
||||
center: defaultProfitCenter,
|
||||
amount: labmatAllocations[i].total,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Object.keys(partsAllocations).forEach((i) => {
|
||||
const defaultProfitCenter = defaults.profits[i.toUpperCase()];
|
||||
|
||||
if (!!defaultProfitCenter && partsAllocations[i].total.getAmount() > 0) {
|
||||
setPartsAllocations((st) => {
|
||||
return {
|
||||
...st,
|
||||
[i]: {
|
||||
...partsAllocations[i],
|
||||
allocations: [
|
||||
{
|
||||
center: defaultProfitCenter,
|
||||
amount: partsAllocations[i].total,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return <Button onClick={handleAllocate}>{t("jobs.actions.autoallocate")}</Button>;
|
||||
}
|
||||
export default connect(mapStateToProps, null)(JobsCloseAutoAllocate);
|
||||
@@ -4,16 +4,13 @@ import { useTranslation } from "react-i18next";
|
||||
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 JobCloseLabMatAllocation({
|
||||
labmatAllocations,
|
||||
setLabmatAllocations,
|
||||
labMatTotalAllocation
|
||||
labMatTotalAllocation,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div style={{ display: "flex" }}>
|
||||
<table>
|
||||
@@ -53,6 +50,18 @@ export default function JobCloseLabMatAllocation({
|
||||
<td>
|
||||
<AllocationButton
|
||||
allocationKey={alloc}
|
||||
remainingAmount={labmatAllocations[alloc].total
|
||||
.subtract(
|
||||
Dinero({
|
||||
amount: labmatAllocations[alloc].allocations.reduce(
|
||||
(acc, val) => {
|
||||
return acc + val.amount.getAmount();
|
||||
},
|
||||
0
|
||||
),
|
||||
})
|
||||
)
|
||||
.getAmount()}
|
||||
allocation={labmatAllocations[alloc]}
|
||||
setAllocations={setLabmatAllocations}
|
||||
/>
|
||||
@@ -71,9 +80,9 @@ export default function JobCloseLabMatAllocation({
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>{labmatAllocations.subtotal.toFormat()}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{labMatTotalAllocation.toFormat()}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -28,7 +28,7 @@ export default function JobsClosePartsAllocation({
|
||||
{Object.keys(partsAllocations).map((alloc, idx) => {
|
||||
return (
|
||||
<tr key={idx}>
|
||||
<td>{t(`jobs.fields.${alloc}`)}</td>
|
||||
<td>{t(`jobs.fields.${alloc.toLowerCase()}`)}</td>
|
||||
<td>
|
||||
{partsAllocations[alloc].total &&
|
||||
partsAllocations[alloc].total.toFormat()}
|
||||
@@ -50,6 +50,18 @@ export default function JobsClosePartsAllocation({
|
||||
<td>
|
||||
<AllocationButton
|
||||
allocationKey={alloc}
|
||||
remainingAmount={partsAllocations[alloc].total
|
||||
.subtract(
|
||||
Dinero({
|
||||
amount: partsAllocations[alloc].allocations.reduce(
|
||||
(acc, val) => {
|
||||
return acc + val.amount.getAmount();
|
||||
},
|
||||
0
|
||||
),
|
||||
})
|
||||
)
|
||||
.getAmount()}
|
||||
allocation={partsAllocations[alloc]}
|
||||
setAllocations={setPartsAllocations}
|
||||
/>
|
||||
@@ -74,9 +86,9 @@ export default function JobsClosePartsAllocation({
|
||||
}, 0),
|
||||
}).toFormat()}
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{partsAllocatedTotal.toFormat()}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -50,6 +50,13 @@ export default function JobsCloseTotals({
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.suspense")}
|
||||
valueStyle={{
|
||||
color:
|
||||
jobTotals.totals.subtotal.subtract(labMatTotal).subtract(partsTotal)
|
||||
.getAmount() === 0
|
||||
? "green"
|
||||
: "red",
|
||||
}}
|
||||
value={jobTotals.totals.subtotal
|
||||
.subtract(labMatTotal)
|
||||
.subtract(partsTotal)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user