IO-233 CDK Allocations Summary

This commit is contained in:
Patrick Fic
2021-08-10 13:42:53 -07:00
parent 124d68ef68
commit ed8eb51c2f
10 changed files with 419 additions and 49 deletions

View File

@@ -0,0 +1,147 @@
import { Table } from "antd";
import React, { useMemo } from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
import Dinero from "dinero.js";
import { useTranslation } from "react-i18next";
import _ from "lodash";
const mapStateToProps = createStructuredSelector({
//currentUser: selectCurrentUser
bodyshop: selectBodyshop,
});
const mapDispatchToProps = (dispatch) => ({
//setUserLanguage: language => dispatch(setUserLanguage(language))
});
export default connect(
mapStateToProps,
mapDispatchToProps
)(DmsAllocationsSummary);
export function DmsAllocationsSummary({ bodyshop, job }) {
const { t } = useTranslation();
const allocationsSummary = useMemo(() => {
const profitCenterHash = job.joblines.reduce((acc, val) => {
//Check the Parts Assignment
if (val.profitcenter_part) {
if (!acc[val.profitcenter_part]) acc[val.profitcenter_part] = Dinero();
acc[val.profitcenter_part] = acc[val.profitcenter_part].add(
Dinero({ amount: Math.round((val.act_price || 0) * 100) }).multiply(
val.part_qty || 0
)
);
}
if (val.profitcenter_labor) {
//Check the Labor Assignment.
if (!acc[val.profitcenter_labor])
acc[val.profitcenter_labor] = Dinero();
acc[val.profitcenter_labor] = acc[val.profitcenter_labor].add(
Dinero({
amount: Math.round(
job[`rate_${val.mod_lbr_ty.toLowerCase()}`] * 100
),
}).multiply(val.mod_lb_hrs)
);
}
return acc;
}, {});
const costCenterHash = job.bills.reduce((bill_acc, bill_val) => {
bill_val.billlines.map((line_val) => {
if (!bill_acc[line_val.cost_center])
bill_acc[line_val.cost_center] = Dinero();
bill_acc[line_val.cost_center] = bill_acc[line_val.cost_center].add(
Dinero({
amount: Math.round((line_val.actual_cost || 0) * 100),
})
.multiply(line_val.quantity)
.multiply(bill_val.is_credit_memo ? -1 : 1)
);
return null;
});
return bill_acc;
}, {});
console.log(
"🚀 ~ file: dms-allocations-summary.component.jsx ~ line 69 ~ costCenterHash",
costCenterHash
);
return _.union(
Object.keys(profitCenterHash),
Object.keys(costCenterHash)
).map((key) => {
console.log("Key", key);
const profitCenter = bodyshop.md_responsibility_centers.profits.find(
(c) => c.name === key
);
const costCenter = bodyshop.md_responsibility_centers.costs.find(
(c) => c.name === key
);
return {
center: key,
sale: profitCenterHash[key]
? profitCenterHash[key].toFormat()
: Dinero().toFormat(),
cost: costCenterHash[key]
? costCenterHash[key].toFormat()
: Dinero().toFormat(),
profitCenter,
costCenter,
};
});
}, [job, bodyshop.md_responsibility_centers]);
const columns = [
{
title: t("job.fields.dms.center"),
dataIndex: "center",
key: "center",
},
{
title: t("job.fields.dms.sale"),
dataIndex: "sale",
key: "sale",
},
{
title: t("job.fields.dms.cost"),
dataIndex: "cost",
key: "cost",
},
{
title: t("job.fields.dms.sale_dms_acctnumber"),
dataIndex: "sale_dms_acctnumber",
key: "sale_dms_acctnumber",
render: (text, record) =>
record.profitCenter && record.profitCenter.dms_acctnumber,
},
{
title: t("job.fields.dms.cost_dms_acctnumber"),
dataIndex: "cost_dms_acctnumber",
key: "cost_dms_acctnumber",
render: (text, record) =>
record.costCenter && record.costCenter.dms_acctnumber,
},
{
title: t("job.fields.dms.dms_wip_acctnumber"),
dataIndex: "dms_wip_acctnumber",
key: "dms_wip_acctnumber",
render: (text, record) =>
record.costCenter && record.costCenter.dms_wip_acctnumber,
},
];
return (
<Table
pagination={{ position: "top", defaultPageSize: 50 }}
columns={columns}
rowKey="center"
dataSource={allocationsSummary}
/>
);
}