Establish working version of pay all and labor calculations.
This commit is contained in:
@@ -88,6 +88,7 @@ export function JobsDetailLaborContainer({
|
|||||||
jobId={jobId}
|
jobId={jobId}
|
||||||
joblines={joblines}
|
joblines={joblines}
|
||||||
timetickets={timetickets}
|
timetickets={timetickets}
|
||||||
|
refetch={refetch}
|
||||||
adjustments={adjustments}
|
adjustments={adjustments}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
@@ -97,6 +98,7 @@ export function JobsDetailLaborContainer({
|
|||||||
jobId={jobId}
|
jobId={jobId}
|
||||||
joblines={joblines}
|
joblines={joblines}
|
||||||
timetickets={timetickets}
|
timetickets={timetickets}
|
||||||
|
refetch={refetch}
|
||||||
adjustments={adjustments}
|
adjustments={adjustments}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import LaborAllocationsAdjustmentEdit from "../labor-allocations-adjustment-edit
|
|||||||
import "./labor-allocations-table.styles.scss";
|
import "./labor-allocations-table.styles.scss";
|
||||||
import { CalculateAllocationsTotals } from "./labor-allocations-table.utility";
|
import { CalculateAllocationsTotals } from "./labor-allocations-table.utility";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { onlyUnique } from "../../utils/arrayHelper";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -26,6 +27,7 @@ export function PayrollLaborAllocationsTable({
|
|||||||
bodyshop,
|
bodyshop,
|
||||||
adjustments,
|
adjustments,
|
||||||
technician,
|
technician,
|
||||||
|
refetch,
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [totals, setTotals] = useState([]);
|
const [totals, setTotals] = useState([]);
|
||||||
@@ -39,11 +41,16 @@ export function PayrollLaborAllocationsTable({
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!!joblines && !!timetickets && !!bodyshop);
|
async function CalculateTotals() {
|
||||||
|
const { data } = await axios.post("/payroll/calculatelabor", {
|
||||||
|
jobid: jobId,
|
||||||
|
});
|
||||||
|
setTotals(data);
|
||||||
|
}
|
||||||
|
|
||||||
setTotals(
|
if (!!joblines && !!timetickets && !!bodyshop) {
|
||||||
CalculateAllocationsTotals(bodyshop, joblines, timetickets, adjustments)
|
CalculateTotals();
|
||||||
);
|
}
|
||||||
if (!jobId) setTotals([]);
|
if (!jobId) setTotals([]);
|
||||||
}, [joblines, timetickets, bodyshop, adjustments, jobId]);
|
}, [joblines, timetickets, bodyshop, adjustments, jobId]);
|
||||||
|
|
||||||
@@ -54,55 +61,46 @@ export function PayrollLaborAllocationsTable({
|
|||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
title: t("timetickets.fields.cost_center"),
|
title: t("timetickets.fields.employee"),
|
||||||
dataIndex: "cost_center",
|
dataIndex: "employeeid",
|
||||||
key: "cost_center",
|
key: "employeeid",
|
||||||
defaultSortOrder: "cost_center",
|
render: (text, record) => {
|
||||||
sorter: (a, b) => alphaSort(a.cost_center, b.cost_center),
|
if (record.employeeid === undefined) {
|
||||||
sortOrder:
|
return "Unassigned";
|
||||||
state.sortedInfo.columnKey === "cost_center" && state.sortedInfo.order,
|
}
|
||||||
render: (text, record) => `${record.cost_center} (${record.mod_lbr_ty})`,
|
const emp = bodyshop.employees.find((e) => e.id === record.employeeid);
|
||||||
|
return `${emp?.first_name} ${emp?.last_name}`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("joblines.fields.mod_lbr_ty"),
|
||||||
|
dataIndex: "mod_lbr_ty",
|
||||||
|
key: "mod_lbr_ty",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("timetickets.fields.rate"),
|
||||||
|
dataIndex: "rate",
|
||||||
|
key: "rate",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("jobs.labels.hrs_total"),
|
title: t("jobs.labels.hrs_total"),
|
||||||
dataIndex: "total",
|
dataIndex: "expectedHours",
|
||||||
key: "total",
|
key: "expectedHours",
|
||||||
sorter: (a, b) => a.total - b.total,
|
sorter: (a, b) => a.expectedHours - b.expectedHours,
|
||||||
sortOrder:
|
sortOrder:
|
||||||
state.sortedInfo.columnKey === "total" && state.sortedInfo.order,
|
state.sortedInfo.columnKey === "expectedHours" &&
|
||||||
render: (text, record) => record.total.toFixed(2),
|
state.sortedInfo.order,
|
||||||
|
render: (text, record) => record.expectedHours.toFixed(5),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("jobs.labels.hrs_claimed"),
|
title: t("jobs.labels.hrs_claimed"),
|
||||||
dataIndex: "hrs_claimed",
|
dataIndex: "claimedHours",
|
||||||
key: "hrs_claimed",
|
key: "claimedHours",
|
||||||
sorter: (a, b) => a.claimed - b.claimed,
|
sorter: (a, b) => a.claimedHours - b.claimedHours,
|
||||||
sortOrder:
|
sortOrder:
|
||||||
state.sortedInfo.columnKey === "claimed" && state.sortedInfo.order,
|
state.sortedInfo.columnKey === "claimedHours" && state.sortedInfo.order,
|
||||||
render: (text, record) => record.claimed && record.claimed.toFixed(2),
|
render: (text, record) =>
|
||||||
},
|
record.claimedHours && record.claimedHours.toFixed(5),
|
||||||
{
|
|
||||||
title: t("jobs.labels.adjustments"),
|
|
||||||
dataIndex: "adjustments",
|
|
||||||
key: "adjustments",
|
|
||||||
sorter: (a, b) => a.adjustments - b.adjustments,
|
|
||||||
sortOrder:
|
|
||||||
state.sortedInfo.columnKey === "adjustments" && state.sortedInfo.order,
|
|
||||||
render: (text, record) => (
|
|
||||||
<Space wrap>
|
|
||||||
{record.adjustments.toFixed(2)}
|
|
||||||
{!technician && (
|
|
||||||
<LaborAllocationsAdjustmentEdit
|
|
||||||
jobId={jobId}
|
|
||||||
adjustments={adjustments}
|
|
||||||
mod_lbr_ty={record.opcode}
|
|
||||||
refetchQueryNames={["GET_LINE_TICKET_BY_PK"]}
|
|
||||||
>
|
|
||||||
<EditFilled />
|
|
||||||
</LaborAllocationsAdjustmentEdit>
|
|
||||||
)}
|
|
||||||
</Space>
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("jobs.labels.difference"),
|
title: t("jobs.labels.difference"),
|
||||||
@@ -112,15 +110,22 @@ export function PayrollLaborAllocationsTable({
|
|||||||
sorter: (a, b) => a.difference - b.difference,
|
sorter: (a, b) => a.difference - b.difference,
|
||||||
sortOrder:
|
sortOrder:
|
||||||
state.sortedInfo.columnKey === "difference" && state.sortedInfo.order,
|
state.sortedInfo.columnKey === "difference" && state.sortedInfo.order,
|
||||||
render: (text, record) => (
|
render: (text, record) => {
|
||||||
<strong
|
const difference = _.round(
|
||||||
style={{
|
record.expectedHours - record.claimedHours,
|
||||||
color: record.difference >= 0 ? "green" : "red",
|
5
|
||||||
}}
|
);
|
||||||
>
|
|
||||||
{_.round(record.difference, 1)}
|
return (
|
||||||
</strong>
|
<strong
|
||||||
),
|
style={{
|
||||||
|
color: difference >= 0 ? "green" : "red",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{difference}
|
||||||
|
</strong>
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const convertedTableCols = [
|
const convertedTableCols = [
|
||||||
@@ -182,7 +187,7 @@ export function PayrollLaborAllocationsTable({
|
|||||||
render: (text, record) =>
|
render: (text, record) =>
|
||||||
record.convertedtolbr_data &&
|
record.convertedtolbr_data &&
|
||||||
record.convertedtolbr_data.mod_lb_hrs &&
|
record.convertedtolbr_data.mod_lb_hrs &&
|
||||||
record.convertedtolbr_data.mod_lb_hrs.toFixed(2),
|
record.convertedtolbr_data.mod_lb_hrs.toFixed(5),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -194,10 +199,10 @@ export function PayrollLaborAllocationsTable({
|
|||||||
totals &&
|
totals &&
|
||||||
totals.reduce(
|
totals.reduce(
|
||||||
(acc, val) => {
|
(acc, val) => {
|
||||||
acc.hrs_total += val.total;
|
acc.hrs_total += val.expectedHours;
|
||||||
acc.hrs_claimed += val.claimed;
|
acc.hrs_claimed += val.claimedHours;
|
||||||
acc.adjustments += val.adjustments;
|
// acc.adjustments += val.adjustments;
|
||||||
acc.difference += val.difference;
|
acc.difference += val.expectedHours - val.claimedHours;
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{ hrs_total: 0, hrs_claimed: 0, adjustments: 0, difference: 0 }
|
{ hrs_total: 0, hrs_claimed: 0, adjustments: 0, difference: 0 }
|
||||||
@@ -211,18 +216,21 @@ export function PayrollLaborAllocationsTable({
|
|||||||
const { data } = await axios.post("/payroll/payall", {
|
const { data } = await axios.post("/payroll/payall", {
|
||||||
jobid: jobId,
|
jobid: jobId,
|
||||||
});
|
});
|
||||||
|
refetch();
|
||||||
setTotals(
|
|
||||||
CalculateAllocationsTotals(
|
|
||||||
bodyshop,
|
|
||||||
joblines,
|
|
||||||
[...timetickets, ...data],
|
|
||||||
adjustments
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Calc
|
Pay All Test
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={async () => {
|
||||||
|
const { data } = await axios.post("/payroll/calculatelabor", {
|
||||||
|
jobid: jobId,
|
||||||
|
});
|
||||||
|
setTotals(data);
|
||||||
|
refetch();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Calculate Labor
|
||||||
</Button>
|
</Button>
|
||||||
<Card title={t("jobs.labels.laborallocations")}>
|
<Card title={t("jobs.labels.laborallocations")}>
|
||||||
<Table
|
<Table
|
||||||
@@ -241,17 +249,17 @@ export function PayrollLaborAllocationsTable({
|
|||||||
{t("general.labels.totals")}
|
{t("general.labels.totals")}
|
||||||
</Typography.Title>
|
</Typography.Title>
|
||||||
</Table.Summary.Cell>
|
</Table.Summary.Cell>
|
||||||
|
<Table.Summary.Cell></Table.Summary.Cell>
|
||||||
|
<Table.Summary.Cell></Table.Summary.Cell>
|
||||||
<Table.Summary.Cell>
|
<Table.Summary.Cell>
|
||||||
{summary.hrs_total.toFixed(2)}
|
{summary.hrs_total.toFixed(5)}
|
||||||
</Table.Summary.Cell>
|
</Table.Summary.Cell>
|
||||||
<Table.Summary.Cell>
|
<Table.Summary.Cell>
|
||||||
{summary.hrs_claimed.toFixed(2)}
|
{summary.hrs_claimed.toFixed(5)}
|
||||||
</Table.Summary.Cell>
|
</Table.Summary.Cell>
|
||||||
|
|
||||||
<Table.Summary.Cell>
|
<Table.Summary.Cell>
|
||||||
{summary.adjustments.toFixed(2)}
|
{summary.difference.toFixed(5)}
|
||||||
</Table.Summary.Cell>
|
|
||||||
<Table.Summary.Cell>
|
|
||||||
{summary.difference.toFixed(2)}
|
|
||||||
</Table.Summary.Cell>
|
</Table.Summary.Cell>
|
||||||
</Table.Summary.Row>
|
</Table.Summary.Row>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ export function ShopEmployeeTeamsFormComponent({ bodyshop }) {
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<InputNumber min={0} max={100} />
|
<InputNumber min={0} max={100} precision={2}/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("joblines.fields.lbr_types.LAA")}
|
label={t("joblines.fields.lbr_types.LAA")}
|
||||||
|
|||||||
@@ -263,9 +263,9 @@ app.post(
|
|||||||
|
|
||||||
const payroll = require("./server/payroll/payroll");
|
const payroll = require("./server/payroll/payroll");
|
||||||
app.post(
|
app.post(
|
||||||
"/payroll/calculatelabortotals",
|
"/payroll/calculatelabor",
|
||||||
fb.validateFirebaseIdToken,
|
fb.validateFirebaseIdToken,
|
||||||
payroll.calculateLaborTotals
|
payroll.calculatelabor
|
||||||
);
|
);
|
||||||
app.post("/payroll/payall", fb.validateFirebaseIdToken, payroll.payall);
|
app.post("/payroll/payall", fb.validateFirebaseIdToken, payroll.payall);
|
||||||
|
|
||||||
|
|||||||
@@ -1827,6 +1827,7 @@ exports.QUERY_JOB_PAYROLL_DATA = `query QUERY_JOB_PAYROLL_DATA($id: uuid!) {
|
|||||||
jobs_by_pk(id: $id) {
|
jobs_by_pk(id: $id) {
|
||||||
bodyshop{
|
bodyshop{
|
||||||
id
|
id
|
||||||
|
md_responsibility_centers
|
||||||
employee_teams{
|
employee_teams{
|
||||||
id
|
id
|
||||||
name
|
name
|
||||||
@@ -1911,3 +1912,10 @@ exports.QUERY_JOB_PAYROLL_DATA = `query QUERY_JOB_PAYROLL_DATA($id: uuid!) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
exports.INSERT_TIME_TICKETS = `mutation INSERT_TIMETICKETS($timetickets: [timetickets_insert_input!]!) {
|
||||||
|
insert_timetickets(objects: $timetickets) {
|
||||||
|
affected_rows
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|||||||
@@ -2,14 +2,19 @@ const Dinero = require("dinero.js");
|
|||||||
const queries = require("../graphql-client/queries");
|
const queries = require("../graphql-client/queries");
|
||||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
|
const {
|
||||||
|
CalculateExpectedHoursForJob,
|
||||||
|
CalculateTicketsHoursForJob,
|
||||||
|
} = require("./pay-all");
|
||||||
|
|
||||||
// Dinero.defaultCurrency = "USD";
|
// Dinero.defaultCurrency = "USD";
|
||||||
// Dinero.globalLocale = "en-CA";
|
// Dinero.globalLocale = "en-CA";
|
||||||
Dinero.globalRoundingMode = "HALF_EVEN";
|
Dinero.globalRoundingMode = "HALF_EVEN";
|
||||||
|
|
||||||
exports.calculateLaborTotals = async function (req, res) {
|
exports.calculatelabor = async function (req, res) {
|
||||||
const BearerToken = req.headers.authorization;
|
const BearerToken = req.headers.authorization;
|
||||||
const { jobid } = req.body;
|
const { jobid, calculateOnly } = req.body;
|
||||||
logger.log("job-payroll-labor-totals", "DEBUG", req.user.email, jobid, null);
|
logger.log("job-payroll-pay-all", "DEBUG", req.user.email, jobid, null);
|
||||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: BearerToken,
|
Authorization: BearerToken,
|
||||||
@@ -24,28 +29,88 @@ exports.calculateLaborTotals = async function (req, res) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//iterate over each ticket, building a hash of team -> employee to calculate total assigned hours.
|
//iterate over each ticket, building a hash of team -> employee to calculate total assigned hours.
|
||||||
|
const { employeeHash, assignmentHash } = CalculateExpectedHoursForJob(job);
|
||||||
|
const ticketHash = CalculateTicketsHoursForJob(job);
|
||||||
|
|
||||||
const assignmentHash = { unassigned: 0 };
|
const totals = [];
|
||||||
job.joblines.forEach((jobline) => {
|
|
||||||
if (jobline.mod_lb_hrs > 0) {
|
//Iteratively go through all 4 levels of the object and create an array that can be presented.
|
||||||
//Check if the line is assigned. If not, keep track of it as an unassigned line by type.
|
// use the employee hash as the golden record (i.e. what they should have), and add what they've claimed.
|
||||||
if (jobline.assigned_team === null) {
|
//While going through, delete items from ticket hash.
|
||||||
assignmentHash.unassigned[jobline.mod_lbr_ty] =
|
//Anything left in ticket hash is an extra entered item.
|
||||||
assignmentHash.unassigned[jobline.mod_lbr_ty] + jobline.mod_lb_hrs;
|
|
||||||
} else {
|
Object.keys(employeeHash).forEach((employeeIdKey) => {
|
||||||
//Line is assigned.
|
//At the employee level.
|
||||||
if (!assignmentHash[jobline.assigned_team]) {
|
Object.keys(employeeHash[employeeIdKey]).forEach((laborTypeKey) => {
|
||||||
assignmentHash[jobline.assigned_team] = 0;
|
//At the labor level
|
||||||
|
Object.keys(employeeHash[employeeIdKey][laborTypeKey]).forEach(
|
||||||
|
(rateKey) => {
|
||||||
|
//At the rate level.
|
||||||
|
const expectedHours =
|
||||||
|
employeeHash[employeeIdKey][laborTypeKey][rateKey];
|
||||||
|
//Will the following line fail? Probably if it doesn't exist.
|
||||||
|
const claimedHours = get(
|
||||||
|
ticketHash,
|
||||||
|
`${employeeIdKey}.${laborTypeKey}.${rateKey}`
|
||||||
|
);
|
||||||
|
if (claimedHours) {
|
||||||
|
delete ticketHash[employeeIdKey][laborTypeKey][rateKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
totals.push({
|
||||||
|
employeeid: employeeIdKey,
|
||||||
|
rate: rateKey,
|
||||||
|
mod_lbr_ty: laborTypeKey,
|
||||||
|
expectedHours,
|
||||||
|
claimedHours: claimedHours || 0,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
assignmentHash[jobline.assigned_team] =
|
);
|
||||||
assignmentHash[jobline.assigned_team] + jobline.mod_lb_hrs;
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
res.json(assignmentHash);
|
|
||||||
|
Object.keys(ticketHash).forEach((employeeIdKey) => {
|
||||||
|
//At the employee level.
|
||||||
|
Object.keys(ticketHash[employeeIdKey]).forEach((laborTypeKey) => {
|
||||||
|
//At the labor level
|
||||||
|
Object.keys(ticketHash[employeeIdKey][laborTypeKey]).forEach(
|
||||||
|
(rateKey) => {
|
||||||
|
//At the rate level.
|
||||||
|
const expectedHours = 0;
|
||||||
|
//Will the following line fail? Probably if it doesn't exist.
|
||||||
|
const claimedHours = get(
|
||||||
|
ticketHash,
|
||||||
|
`${employeeIdKey}.${laborTypeKey}.${rateKey}`
|
||||||
|
);
|
||||||
|
if (claimedHours) {
|
||||||
|
delete ticketHash[employeeIdKey][laborTypeKey][rateKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
totals.push({
|
||||||
|
employeeid: employeeIdKey,
|
||||||
|
rate: rateKey,
|
||||||
|
mod_lbr_ty: laborTypeKey,
|
||||||
|
expectedHours,
|
||||||
|
claimedHours: claimedHours || 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if (assignmentHash.unassigned > 0) {
|
||||||
|
totals.push({
|
||||||
|
employeeid: undefined,
|
||||||
|
//rate: rateKey,
|
||||||
|
//mod_lbr_ty: laborTypeKey,
|
||||||
|
expectedHours: assignmentHash.unassigned,
|
||||||
|
claimedHours: 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.json(totals);
|
||||||
|
//res.json(assignmentHash);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log(
|
logger.log(
|
||||||
"job-payroll-labor-totals-error",
|
"job-payroll-calculate-labor-error",
|
||||||
"ERROR",
|
"ERROR",
|
||||||
req.user.email,
|
req.user.email,
|
||||||
jobid,
|
jobid,
|
||||||
@@ -57,3 +122,9 @@ exports.calculateLaborTotals = async function (req, res) {
|
|||||||
res.status(503).send();
|
res.status(503).send();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
get = function (obj, key) {
|
||||||
|
return key.split(".").reduce(function (o, x) {
|
||||||
|
return typeof o == "undefined" || o === null ? o : o[x];
|
||||||
|
}, obj);
|
||||||
|
};
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ const _ = require("lodash");
|
|||||||
const rdiff = require("recursive-diff");
|
const rdiff = require("recursive-diff");
|
||||||
|
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
|
const { json } = require("body-parser");
|
||||||
// Dinero.defaultCurrency = "USD";
|
// Dinero.defaultCurrency = "USD";
|
||||||
// Dinero.globalLocale = "en-CA";
|
// Dinero.globalLocale = "en-CA";
|
||||||
Dinero.globalRoundingMode = "HALF_EVEN";
|
Dinero.globalRoundingMode = "HALF_EVEN";
|
||||||
|
|
||||||
exports.payall = async function (req, res) {
|
exports.payall = async function (req, res) {
|
||||||
const BearerToken = req.headers.authorization;
|
const BearerToken = req.headers.authorization;
|
||||||
const { jobid } = req.body;
|
const { jobid, calculateOnly } = req.body;
|
||||||
logger.log("job-payroll-pay-all", "DEBUG", req.user.email, jobid, null);
|
logger.log("job-payroll-pay-all", "DEBUG", req.user.email, jobid, null);
|
||||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -28,187 +29,117 @@ exports.payall = async function (req, res) {
|
|||||||
|
|
||||||
//iterate over each ticket, building a hash of team -> employee to calculate total assigned hours.
|
//iterate over each ticket, building a hash of team -> employee to calculate total assigned hours.
|
||||||
|
|
||||||
const assignmentHash = { unassigned: 0 };
|
const { employeeHash, assignmentHash } = CalculateExpectedHoursForJob(job);
|
||||||
const employeeHash = {}; // employeeid => Cieca labor type => rate => hours. Contains how many hours each person should be paid.
|
const ticketHash = CalculateTicketsHoursForJob(job);
|
||||||
job.joblines.forEach((jobline) => {
|
|
||||||
if (jobline.mod_lb_hrs > 0) {
|
|
||||||
//Check if the line is assigned. If not, keep track of it as an unassigned line by type.
|
|
||||||
if (jobline.assigned_team === null) {
|
|
||||||
assignmentHash.unassigned =
|
|
||||||
assignmentHash.unassigned + jobline.mod_lb_hrs;
|
|
||||||
} else {
|
|
||||||
//Line is assigned.
|
|
||||||
if (!assignmentHash[jobline.assigned_team]) {
|
|
||||||
assignmentHash[jobline.assigned_team] = 0;
|
|
||||||
}
|
|
||||||
assignmentHash[jobline.assigned_team] =
|
|
||||||
assignmentHash[jobline.assigned_team] + jobline.mod_lb_hrs;
|
|
||||||
|
|
||||||
//Create the assignment breakdown.
|
|
||||||
const theTeam = job.bodyshop.employee_teams.find(
|
|
||||||
(team) => team.id === jobline.assigned_team
|
|
||||||
);
|
|
||||||
|
|
||||||
theTeam.employee_team_members.forEach((tm) => {
|
|
||||||
//Figure out how many hours they are owed at this line, and at what rate.
|
|
||||||
|
|
||||||
if (!employeeHash[tm.employee.id]) {
|
|
||||||
employeeHash[tm.employee.id] = {};
|
|
||||||
}
|
|
||||||
if (!employeeHash[tm.employee.id][jobline.mod_lbr_ty]) {
|
|
||||||
employeeHash[tm.employee.id][jobline.mod_lbr_ty] = {};
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
!employeeHash[tm.employee.id][jobline.mod_lbr_ty][
|
|
||||||
tm.labor_rates[jobline.mod_lbr_ty]
|
|
||||||
]
|
|
||||||
) {
|
|
||||||
employeeHash[tm.employee.id][jobline.mod_lbr_ty][
|
|
||||||
tm.labor_rates[jobline.mod_lbr_ty]
|
|
||||||
] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const hoursOwed = (tm.percentage * jobline.mod_lb_hrs) / 100;
|
|
||||||
employeeHash[tm.employee.id][jobline.mod_lbr_ty][
|
|
||||||
tm.labor_rates[jobline.mod_lbr_ty]
|
|
||||||
] =
|
|
||||||
employeeHash[tm.employee.id][jobline.mod_lbr_ty][
|
|
||||||
tm.labor_rates[jobline.mod_lbr_ty]
|
|
||||||
] + hoursOwed;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const ticketHash = {}; // employeeid => Cieca labor type => rate => hours.
|
|
||||||
//Calculate how much each employee has been paid so far.
|
|
||||||
job.timetickets.forEach((ticket) => {
|
|
||||||
if (!ticketHash[ticket.employeeid]) {
|
|
||||||
ticketHash[ticket.employeeid] = {};
|
|
||||||
}
|
|
||||||
if (!ticketHash[ticket.employeeid][ticket.ciecacode]) {
|
|
||||||
ticketHash[ticket.employeeid][ticket.ciecacode] = {};
|
|
||||||
}
|
|
||||||
if (!ticketHash[ticket.employeeid][ticket.ciecacode][ticket.rate]) {
|
|
||||||
ticketHash[ticket.employeeid][ticket.ciecacode][ticket.rate] = 0;
|
|
||||||
}
|
|
||||||
ticketHash[ticket.employeeid][ticket.ciecacode][ticket.rate] =
|
|
||||||
ticketHash[ticket.employeeid][ticket.ciecacode][ticket.rate] +
|
|
||||||
ticket.productivehrs;
|
|
||||||
//Add the rate
|
|
||||||
});
|
|
||||||
|
|
||||||
if (assignmentHash.unassigned > 0) {
|
if (assignmentHash.unassigned > 0) {
|
||||||
res.json({ success: false, error: "Unassigned hours." });
|
res.json({ success: false, error: "Unassigned hours." });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Calculate how much time each tech should have by labor type.
|
//Calculate how much time each tech should have by labor type.
|
||||||
// const comparison = compare(employeeHash, ticketHash);
|
//Doing this order creates a diff of changes on the ticket hash to make it the same as the employee hash.
|
||||||
const recursiveDiff = rdiff.getDiff(ticketHash, employeeHash, true); //Doing this order creates a diff of changes on the ticket hash to make it the same as the employee hash.
|
const recursiveDiff = rdiff.getDiff(ticketHash, employeeHash, true);
|
||||||
|
|
||||||
const ticketsToInsert = [];
|
const ticketsToInsert = [];
|
||||||
|
|
||||||
recursiveDiff.forEach((diff) => {
|
recursiveDiff.forEach((diff) => {
|
||||||
//Every iteration is what we would need to insert into the time ticket hash
|
//Every iteration is what we would need to insert into the time ticket hash
|
||||||
//so that it would match the employee hash exactly.
|
//so that it would match the employee hash exactly.
|
||||||
|
|
||||||
const path = diffParser(diff);
|
const path = diffParser(diff);
|
||||||
|
|
||||||
if (diff.op === "add") {
|
if (diff.op === "add") {
|
||||||
if (typeof diff.val === "object") {
|
if (typeof diff.val === "object" && Object.keys(diff.val).length > 1) {
|
||||||
//Multiple values to add.
|
//Multiple values to add.
|
||||||
Object.keys(diff.val).forEach((key) => {
|
Object.keys(diff.val).forEach((key) => {
|
||||||
|
console.log("Hours", diff.val[key][Object.keys(diff.val[key])[0]]);
|
||||||
|
console.log("Rate", Object.keys(diff.val[key])[0]);
|
||||||
ticketsToInsert.push({
|
ticketsToInsert.push({
|
||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
|
bodyshopid: job.bodyshop.id,
|
||||||
employeeid: path.employeeid,
|
employeeid: path.employeeid,
|
||||||
productivehrs: diff.val[key][Object.keys(diff.val[key])[0]],
|
productivehrs: diff.val[key][Object.keys(diff.val[key])[0]],
|
||||||
rate: Object.keys(diff.val[key])[0],
|
rate: Object.keys(diff.val[key])[0],
|
||||||
ciecacode: key,
|
ciecacode: key,
|
||||||
|
cost_center:
|
||||||
|
job.bodyshop.md_responsibility_centers.defaults.costs[key],
|
||||||
flat_rate: true,
|
flat_rate: true,
|
||||||
memo: "Add hours.",
|
memo: "*System* Hours added during Pay All function. (multi)",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
//Only the 1 value to add.
|
//Only the 1 value to add.
|
||||||
ticketsToInsert.push({
|
ticketsToInsert.push({
|
||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
|
bodyshopid: job.bodyshop.id,
|
||||||
employeeid: path.employeeid,
|
employeeid: path.employeeid,
|
||||||
productivehrs: path.hours,
|
productivehrs: path.hours,
|
||||||
rate: path.rate,
|
rate: path.rate,
|
||||||
ciecacode: path.mod_lbr_ty,
|
ciecacode: path.mod_lbr_ty,
|
||||||
flat_rate: true,
|
flat_rate: true,
|
||||||
memo: "Add hours.",
|
cost_center:
|
||||||
|
job.bodyshop.md_responsibility_centers.defaults.costs[
|
||||||
|
path.mod_lbr_ty
|
||||||
|
],
|
||||||
|
memo: "*System* Hours added during Pay All function.",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (diff.op === "update") {
|
} else if (diff.op === "update") {
|
||||||
} else {
|
} else {
|
||||||
//Has to be a delete
|
//Has to be a delete
|
||||||
ticketsToInsert.push({
|
|
||||||
jobid: job.id,
|
//////
|
||||||
employeeid: path.employeeid,
|
|
||||||
productivehrs: diff.oldVal * -1,
|
if (
|
||||||
rate: path.rate,
|
typeof diff.oldVal === "object" &&
|
||||||
ciecacode: path.mod_lbr_ty,
|
Object.keys(diff.oldVal).length > 1
|
||||||
flat_rate: true,
|
) {
|
||||||
memo: "Remove unneeded hours. (Rate/Unassigned).",
|
//Multiple oldValues to add.
|
||||||
});
|
Object.keys(diff.oldVal).forEach((key) => {
|
||||||
|
console.log(
|
||||||
|
"Hours",
|
||||||
|
diff.oldVal[key][Object.keys(diff.oldVal[key])[0]]
|
||||||
|
);
|
||||||
|
console.log("Rate", Object.keys(diff.oldVal[key])[0]);
|
||||||
|
ticketsToInsert.push({
|
||||||
|
jobid: job.id,
|
||||||
|
bodyshopid: job.bodyshop.id,
|
||||||
|
employeeid: path.employeeid,
|
||||||
|
productivehrs:
|
||||||
|
diff.oldVal[key][Object.keys(diff.oldVal[key])[0]] * -1,
|
||||||
|
rate: Object.keys(diff.oldVal[key])[0],
|
||||||
|
ciecacode: key,
|
||||||
|
cost_center:
|
||||||
|
job.bodyshop.md_responsibility_centers.defaults.costs[key],
|
||||||
|
flat_rate: true,
|
||||||
|
memo: "*System* Hours removed during Pay All function. (Change in rate, unassignment, etc.) *multi*",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
//Only the 1 value to add.
|
||||||
|
ticketsToInsert.push({
|
||||||
|
jobid: job.id,
|
||||||
|
bodyshopid: job.bodyshop.id,
|
||||||
|
employeeid: path.employeeid,
|
||||||
|
productivehrs: path.hours * -1,
|
||||||
|
rate: path.rate,
|
||||||
|
ciecacode: path.mod_lbr_ty,
|
||||||
|
cost_center:
|
||||||
|
job.bodyshop.md_responsibility_centers.defaults.costs[
|
||||||
|
path.mod_lbr_ty
|
||||||
|
],
|
||||||
|
flat_rate: true,
|
||||||
|
memo: "*System* Hours removed during Pay All function. (Change in rate, unassignment, etc.)",
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// //Check the ones that are different first. Source of truth will be the employee hash.
|
const insertResult = await client.request(queries.INSERT_TIME_TICKETS, {
|
||||||
// comparison.different.forEach((differentKey) => {
|
timetickets: ticketsToInsert.filter(
|
||||||
// const empVal = fetchFromObject(employeeHash, differentKey) || 0;
|
(ticket) => ticket.productivehrs !== 0
|
||||||
// const ticketVal = fetchFromObject(ticketHash, differentKey) || 0;
|
),
|
||||||
// const splitKey = splitEmployeeKey(differentKey);
|
});
|
||||||
|
|
||||||
// ticketsToInsert.push({
|
res.json(ticketsToInsert.filter((ticket) => ticket.productivehrs !== 0));
|
||||||
// jobid: job.id,
|
|
||||||
// employeeid: splitKey.employeeid,
|
|
||||||
// productivehrs: empVal - ticketVal,
|
|
||||||
// rate: splitKey.rate,
|
|
||||||
// ciecacode: splitKey.mod_lbr_ty,
|
|
||||||
// flat_rate: true,
|
|
||||||
// memo: "Adjustment between expected and entered values.",
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// comparison.missing_from_first //Missing from the employee hash, but present in the ticket hash.
|
|
||||||
// .filter((differentKey) => differentKey.split(".").length == 3)
|
|
||||||
// .forEach((differentKey) => {
|
|
||||||
// const empVal = fetchFromObject(employeeHash, differentKey) || 0;
|
|
||||||
// const ticketVal = fetchFromObject(ticketHash, differentKey) || 0;
|
|
||||||
// const splitKey = splitEmployeeKey(differentKey);
|
|
||||||
|
|
||||||
// ticketsToInsert.push({
|
|
||||||
// jobid: job.id,
|
|
||||||
// employeeid: differentKey.split(".")[0],
|
|
||||||
// productivehrs: empVal - ticketVal * -1,
|
|
||||||
// rate: splitKey.rate,
|
|
||||||
// ciecacode: splitKey.mod_lbr_ty,
|
|
||||||
// flat_rate: true,
|
|
||||||
// memo: "Entered ticket reversed to match system payroll.",
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// comparison.missing_from_second //Missing from the ticket hash, but present in the employee hash.
|
|
||||||
// .filter((differentKey) => differentKey.split(".").length == 3)
|
|
||||||
// .forEach((differentKey) => {
|
|
||||||
// const empVal = fetchFromObject(employeeHash, differentKey) || 0;
|
|
||||||
// const ticketVal = fetchFromObject(ticketHash, differentKey) || 0;
|
|
||||||
// const splitKey = splitEmployeeKey(differentKey);
|
|
||||||
|
|
||||||
// ticketsToInsert.push({
|
|
||||||
// jobid: job.id,
|
|
||||||
// employeeid: differentKey.split(".")[0],
|
|
||||||
// productivehrs: empVal - ticketVal * -1,
|
|
||||||
// rate: splitKey.rate,
|
|
||||||
// ciecacode: splitKey.mod_lbr_ty,
|
|
||||||
// flat_rate: true,
|
|
||||||
// memo: "Entered ticket reversed to match system payroll.",
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
res.json(ticketsToInsert);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log(
|
logger.log(
|
||||||
"job-payroll-labor-totals-error",
|
"job-payroll-labor-totals-error",
|
||||||
@@ -224,102 +155,137 @@ exports.payall = async function (req, res) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// var compare = function (a, b) {
|
|
||||||
// var result = {
|
|
||||||
// different: [],
|
|
||||||
// missing_from_first: [],
|
|
||||||
// missing_from_second: [],
|
|
||||||
// };
|
|
||||||
|
|
||||||
// _.reduce(
|
|
||||||
// a,
|
|
||||||
// function (result, value, key) {
|
|
||||||
// if (b.hasOwnProperty(key)) {
|
|
||||||
// if (_.isEqual(value, b[key])) {
|
|
||||||
// return result;
|
|
||||||
// } else {
|
|
||||||
// if (typeof a[key] != typeof {} || typeof b[key] != typeof {}) {
|
|
||||||
// //dead end.
|
|
||||||
// result.different.push(key);
|
|
||||||
// return result;
|
|
||||||
// } else {
|
|
||||||
// var deeper = compare(a[key], b[key]);
|
|
||||||
// result.different = result.different.concat(
|
|
||||||
// _.map(deeper.different, (sub_path) => {
|
|
||||||
// return key + "." + sub_path;
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
|
|
||||||
// result.missing_from_second = result.missing_from_second.concat(
|
|
||||||
// _.map(deeper.missing_from_second, (sub_path) => {
|
|
||||||
// return key + "." + sub_path;
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
|
|
||||||
// result.missing_from_first = result.missing_from_first.concat(
|
|
||||||
// _.map(deeper.missing_from_first, (sub_path) => {
|
|
||||||
// return key + "." + sub_path;
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// result.missing_from_second.push(key);
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// result
|
|
||||||
// );
|
|
||||||
|
|
||||||
// _.reduce(
|
|
||||||
// b,
|
|
||||||
// function (result, value, key) {
|
|
||||||
// if (a.hasOwnProperty(key)) {
|
|
||||||
// return result;
|
|
||||||
// } else {
|
|
||||||
// result.missing_from_first.push(key);
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// result
|
|
||||||
// );
|
|
||||||
|
|
||||||
// return result;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// function fetchFromObject(obj, prop) {
|
|
||||||
// if (typeof obj === "undefined") {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var _index = prop.indexOf(".");
|
|
||||||
// if (_index > -1) {
|
|
||||||
// return fetchFromObject(
|
|
||||||
// obj[prop.substring(0, _index)],
|
|
||||||
// prop.substr(_index + 1)
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return obj[prop];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// function splitEmployeeKey(key) {
|
|
||||||
// const splitArray = differentKey.split(".");
|
|
||||||
// // employeeid => Cieca labor type => rate
|
|
||||||
// return {
|
|
||||||
// employeeid: splitArray[0],
|
|
||||||
// mod_lbr_ty: splitArray[1],
|
|
||||||
// rate: splitArray[2],
|
|
||||||
// hours: splitArray[3],
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
function diffParser(diff) {
|
function diffParser(diff) {
|
||||||
return {
|
const type = typeof diff.oldVal;
|
||||||
employeeid: diff.path[0],
|
let mod_lbr_ty, rate, hours;
|
||||||
mod_lbr_ty: diff.path[1],
|
|
||||||
rate: diff.path[2],
|
if (diff.path.length === 1) {
|
||||||
hours: diff.val,
|
if (diff.op === "add") {
|
||||||
|
mod_lbr_ty = Object.keys(diff.val)[0];
|
||||||
|
rate = Object.keys(diff.val[mod_lbr_ty])[0];
|
||||||
|
// hours = diff.oldVal[mod_lbr_ty][rate];
|
||||||
|
} else {
|
||||||
|
mod_lbr_ty = Object.keys(diff.oldVal)[0];
|
||||||
|
rate = Object.keys(diff.oldVal[mod_lbr_ty])[0];
|
||||||
|
// hours = diff.oldVal[mod_lbr_ty][rate];
|
||||||
|
}
|
||||||
|
} else if (diff.path.length === 2) {
|
||||||
|
mod_lbr_ty = diff.path[1];
|
||||||
|
if (diff.op === "add") {
|
||||||
|
rate = Object.keys(diff.val)[0];
|
||||||
|
} else {
|
||||||
|
rate = Object.keys(diff.oldVal)[0];
|
||||||
|
}
|
||||||
|
} else if (diff.path.length === 3) {
|
||||||
|
mod_lbr_ty = diff.path[1];
|
||||||
|
rate = diff.path[2];
|
||||||
|
//hours = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set the hours
|
||||||
|
if (
|
||||||
|
typeof diff.val === "number" &&
|
||||||
|
diff.val !== null &&
|
||||||
|
diff.val !== undefined
|
||||||
|
) {
|
||||||
|
hours = diff.val;
|
||||||
|
} else if (diff.val !== null && diff.val !== undefined) {
|
||||||
|
hours = diff.val[Object.keys(diff.val)[0]];
|
||||||
|
} else if (
|
||||||
|
typeof diff.oldVal === "number" &&
|
||||||
|
diff.oldVal !== null &&
|
||||||
|
diff.oldVal !== undefined
|
||||||
|
) {
|
||||||
|
hours = diff.oldVal;
|
||||||
|
} else {
|
||||||
|
hours = diff.oldVal[Object.keys(diff.oldVal)[0]];
|
||||||
|
}
|
||||||
|
|
||||||
|
const ret = {
|
||||||
|
multiVal: false,
|
||||||
|
employeeid: diff.path[0], // Always True
|
||||||
|
mod_lbr_ty,
|
||||||
|
rate,
|
||||||
|
hours,
|
||||||
};
|
};
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function CalculateExpectedHoursForJob(job) {
|
||||||
|
const assignmentHash = { unassigned: 0 };
|
||||||
|
const employeeHash = {}; // employeeid => Cieca labor type => rate => hours. Contains how many hours each person should be paid.
|
||||||
|
job.joblines.forEach((jobline) => {
|
||||||
|
if (jobline.mod_lb_hrs != 0) {
|
||||||
|
//Check if the line is assigned. If not, keep track of it as an unassigned line by type.
|
||||||
|
if (jobline.assigned_team === null) {
|
||||||
|
assignmentHash.unassigned =
|
||||||
|
assignmentHash.unassigned + jobline.mod_lb_hrs;
|
||||||
|
} else {
|
||||||
|
//Line is assigned.
|
||||||
|
if (!assignmentHash[jobline.assigned_team]) {
|
||||||
|
assignmentHash[jobline.assigned_team] = 0;
|
||||||
|
}
|
||||||
|
assignmentHash[jobline.assigned_team] =
|
||||||
|
assignmentHash[jobline.assigned_team] + jobline.mod_lb_hrs;
|
||||||
|
|
||||||
|
//Create the assignment breakdown.
|
||||||
|
const theTeam = job.bodyshop.employee_teams.find(
|
||||||
|
(team) => team.id === jobline.assigned_team
|
||||||
|
);
|
||||||
|
|
||||||
|
theTeam.employee_team_members.forEach((tm) => {
|
||||||
|
//Figure out how many hours they are owed at this line, and at what rate.
|
||||||
|
|
||||||
|
if (!employeeHash[tm.employee.id]) {
|
||||||
|
employeeHash[tm.employee.id] = {};
|
||||||
|
}
|
||||||
|
if (!employeeHash[tm.employee.id][jobline.mod_lbr_ty]) {
|
||||||
|
employeeHash[tm.employee.id][jobline.mod_lbr_ty] = {};
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!employeeHash[tm.employee.id][jobline.mod_lbr_ty][
|
||||||
|
tm.labor_rates[jobline.mod_lbr_ty]
|
||||||
|
]
|
||||||
|
) {
|
||||||
|
employeeHash[tm.employee.id][jobline.mod_lbr_ty][
|
||||||
|
tm.labor_rates[jobline.mod_lbr_ty]
|
||||||
|
] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hoursOwed = (tm.percentage * jobline.mod_lb_hrs) / 100;
|
||||||
|
employeeHash[tm.employee.id][jobline.mod_lbr_ty][
|
||||||
|
tm.labor_rates[jobline.mod_lbr_ty]
|
||||||
|
] =
|
||||||
|
employeeHash[tm.employee.id][jobline.mod_lbr_ty][
|
||||||
|
tm.labor_rates[jobline.mod_lbr_ty]
|
||||||
|
] + hoursOwed;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return { assignmentHash, employeeHash };
|
||||||
|
}
|
||||||
|
|
||||||
|
function CalculateTicketsHoursForJob(job) {
|
||||||
|
const ticketHash = {}; // employeeid => Cieca labor type => rate => hours.
|
||||||
|
//Calculate how much each employee has been paid so far.
|
||||||
|
job.timetickets.forEach((ticket) => {
|
||||||
|
if (!ticketHash[ticket.employeeid]) {
|
||||||
|
ticketHash[ticket.employeeid] = {};
|
||||||
|
}
|
||||||
|
if (!ticketHash[ticket.employeeid][ticket.ciecacode]) {
|
||||||
|
ticketHash[ticket.employeeid][ticket.ciecacode] = {};
|
||||||
|
}
|
||||||
|
if (!ticketHash[ticket.employeeid][ticket.ciecacode][ticket.rate]) {
|
||||||
|
ticketHash[ticket.employeeid][ticket.ciecacode][ticket.rate] = 0;
|
||||||
|
}
|
||||||
|
ticketHash[ticket.employeeid][ticket.ciecacode][ticket.rate] =
|
||||||
|
ticketHash[ticket.employeeid][ticket.ciecacode][ticket.rate] +
|
||||||
|
ticket.productivehrs;
|
||||||
|
});
|
||||||
|
return ticketHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.CalculateExpectedHoursForJob = CalculateExpectedHoursForJob;
|
||||||
|
exports.CalculateTicketsHoursForJob = CalculateTicketsHoursForJob;
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
exports.calculateLaborTotals = require("./calculate-totals").calculateLaborTotals;
|
exports.calculatelabor = require("./calculate-totals").calculatelabor;
|
||||||
exports.payall = require("./pay-all").payall;
|
exports.payall = require("./pay-all").payall;
|
||||||
|
|||||||
Reference in New Issue
Block a user