Refactored capturing of resp. centers. + added auto allocate BOD-131

This commit is contained in:
Patrick Fic
2020-05-20 16:21:17 -07:00
parent 0dbacf0b9e
commit d8a4c87d3a
24 changed files with 3251 additions and 203 deletions

View File

@@ -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);