Files
bodyshop/client/src/components/labor-allocations-table/labor-allocations-table.utility.js
2021-02-04 18:15:00 -08:00

35 lines
1.1 KiB
JavaScript

export const CalculateAllocationsTotals = (
responsibilitycenters,
joblines,
timetickets,
adjustments = []
) => {
const jobCodes = joblines.map((item) => item.mod_lbr_ty);
//.filter((value, index, self) => self.indexOf(value) === index && !!value);
const ticketCodes = timetickets.map((item) => item.ciecacode);
//.filter((value, index, self) => self.indexOf(value) === index && !!value);
const allCodes = [...jobCodes, ...ticketCodes].filter(
(value, index, self) => self.indexOf(value) === index && !!value
);
const r = allCodes.reduce((acc, value) => {
const r = {
opcode: value,
cost_center: responsibilitycenters.defaults.costs[value],
total: joblines.reduce((acc2, val2) => {
return val2.mod_lbr_ty === value ? acc2 + val2.mod_lb_hrs : acc2;
}, 0),
adjustments: adjustments[value] || 0,
claimed: timetickets.reduce((acc3, val3) => {
return val3.ciecacode === value ? acc3 + val3.productivehrs : acc3;
}, 0),
};
r.difference = (r.total + r.adjustments - r.claimed).toFixed(2);
acc.push(r);
return acc;
}, []);
return r;
};