BOD-23 Added labor pages tab + finalized time ticket tab + created allocation calculations

This commit is contained in:
Patrick Fic
2020-04-15 15:39:05 -07:00
parent 325a82ac86
commit 8e12320c19
20 changed files with 724 additions and 132 deletions

View File

@@ -0,0 +1,54 @@
import React, { useState, useEffect } from "react";
import { Typography, Row, Col } from "antd";
import { useTranslation } from "react-i18next";
import { CalculateAllocationsTotals } from "./labor-allocations-table.utility";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
});
export function LaborAllocationsTable({ joblines, timetickets, bodyshop }) {
const { t } = useTranslation();
const [totals, setTotals] = useState([]);
useEffect(() => {
if (!!joblines && !!timetickets && !!bodyshop);
setTotals(
CalculateAllocationsTotals(
bodyshop.md_responsibility_centers,
joblines,
timetickets
)
);
}, [joblines, timetickets, bodyshop]);
return (
<div>
<Typography.Title level={3}>
{t("jobs.labels.laborallocations")}
</Typography.Title>
<Row>
<Col span={12}>
<strong>{t("timetickets.fields.cost_center")}</strong>
</Col>
<Col span={6}>
<strong>{t("jobs.labels.hrs_total")}</strong>
</Col>
<Col span={6}>
<strong>{t("jobs.labels.hrs_claimed")}</strong>
</Col>
</Row>
{totals.map((t, idx) => (
<Row key={idx}>
<Col span={12}>{t.cost_center}</Col>
<Col span={6}>{t.total}</Col>
<Col span={6}>{t.claimed}</Col>
</Row>
))}
</div>
);
}
export default connect(mapStateToProps, null)(LaborAllocationsTable);

View File

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