Refactored capturing of resp. centers. + added auto allocate BOD-131
This commit is contained in:
@@ -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);
|
||||
Reference in New Issue
Block a user