69 lines
1.9 KiB
JavaScript
69 lines
1.9 KiB
JavaScript
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,
|
|
invoiced
|
|
}) {
|
|
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} disabled={invoiced}>{t("jobs.actions.autoallocate")}</Button>;
|
|
}
|
|
export default connect(mapStateToProps, null)(JobsCloseAutoAllocate);
|