Refactored job closing to be line based instead of totals based. BOD-383

This commit is contained in:
Patrick Fic
2020-09-14 13:54:11 -07:00
parent e3f108c567
commit eff49e3d25
34 changed files with 1030 additions and 822 deletions

View File

@@ -1,76 +1,38 @@
import React from "react";
import { Button } from "antd";
import { selectBodyshop } from "../../redux/user/user.selectors";
import React from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { useTranslation } from "react-i18next";
import { logImEXEvent } from "../../firebase/firebase.utils";
import Dinero from "dinero.js";
import { selectBodyshop } from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
});
export function JobsCloseAutoAllocate({
bodyshop,
labmatAllocations,
setLabmatAllocations,
partsAllocations,
setPartsAllocations,
disabled,
}) {
export function JobsCloseAutoAllocate({ bodyshop, joblines, form, disabled }) {
const { t } = useTranslation();
const handleAllocate = () => {
logImEXEvent("jobs_close_allocate_auto");
const { defaults } = bodyshop.md_responsibility_centers;
Object.keys(labmatAllocations).forEach((i) => {
const defaultProfitCenter = defaults.profits[i.toUpperCase()];
if (
!!defaultProfitCenter &&
Dinero(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 &&
Dinero(partsAllocations[i].total).getAmount() > 0
) {
setPartsAllocations((st) => {
return {
...st,
[i]: {
...partsAllocations[i],
allocations: [
{
center: defaultProfitCenter,
amount: partsAllocations[i].total,
},
],
},
};
});
}
form.setFieldsValue({
joblines: joblines.map((jl) => {
const ret = jl;
if (jl.part_type) {
ret.profitcenter_part = defaults.profits[jl.part_type.toUpperCase()];
} else {
ret.profitcenter_part = null;
}
if (jl.mod_lbr_ty) {
ret.profitcenter_labor =
defaults.profits[jl.mod_lbr_ty.toUpperCase()];
} else {
ret.profitcenter_labor = null;
}
return ret;
}),
});
};