Updated pay all calculations and introduction of split.

This commit is contained in:
Patrick Fic
2023-07-13 09:13:45 -07:00
parent bd7fbfff37
commit dd085be5c7
6 changed files with 278 additions and 163 deletions

View File

@@ -48,6 +48,7 @@ import JobLinesPartPriceChange from "./job-lines-part-price-change.component";
import JoblineTeamAssignment from "../job-line-team-assignment/job-line-team-assignmnent.component"; import JoblineTeamAssignment from "../job-line-team-assignment/job-line-team-assignmnent.component";
import JobLineDispatchButton from "../job-line-dispatch-button/job-line-dispatch-button.component"; import JobLineDispatchButton from "../job-line-dispatch-button/job-line-dispatch-button.component";
import JobLineBulkAssignComponent from "../job-line-bulk-assign/job-line-bulk-assign.component"; import JobLineBulkAssignComponent from "../job-line-bulk-assign/job-line-bulk-assign.component";
import { useTreatments } from "@splitsoftware/splitio-react";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop, bodyshop: selectBodyshop,
@@ -79,7 +80,11 @@ export function JobLinesComponent({
setBillEnterContext, setBillEnterContext,
}) { }) {
const [deleteJobLine] = useMutation(DELETE_JOB_LINE_BY_PK); const [deleteJobLine] = useMutation(DELETE_JOB_LINE_BY_PK);
const { Enhanced_Payroll } = useTreatments(
["Enhanced_Payroll"],
{},
bodyshop.imexshopid
);
const [selectedLines, setSelectedLines] = useState([]); const [selectedLines, setSelectedLines] = useState([]);
const [state, setState] = useState({ const [state, setState] = useState({
sortedInfo: {}, sortedInfo: {},
@@ -289,14 +294,19 @@ export function JobLinesComponent({
state.sortedInfo.columnKey === "line_ind" && state.sortedInfo.order, state.sortedInfo.columnKey === "line_ind" && state.sortedInfo.order,
responsive: ["md"], responsive: ["md"],
}, },
{ ...(Enhanced_Payroll.treatment === "on"
title: t("joblines.fields.assigned_team"), ? [
dataIndex: "assigned_team", {
key: "assigned_team", title: t("joblines.fields.assigned_team"),
render: (text, record) => ( dataIndex: "assigned_team",
<JoblineTeamAssignment disabled={jobRO} jobline={record} /> key: "assigned_team",
), render: (text, record) => (
}, <JoblineTeamAssignment disabled={jobRO} jobline={record} />
),
},
]
: []),
{ {
title: t("joblines.fields.notes"), title: t("joblines.fields.notes"),
dataIndex: "notes", dataIndex: "notes",
@@ -464,11 +474,13 @@ export function JobLinesComponent({
setSelectedLines={setSelectedLines} setSelectedLines={setSelectedLines}
job={job} job={job}
/> />
<JobLineBulkAssignComponent {Enhanced_Payroll.treatment === "on" && (
selectedLines={selectedLines} <JobLineBulkAssignComponent
setSelectedLines={setSelectedLines} selectedLines={selectedLines}
job={job} setSelectedLines={setSelectedLines}
/> job={job}
/>
)}
<Button <Button
disabled={ disabled={
(job && !job.converted) || (job && !job.converted) ||

View File

@@ -5,10 +5,13 @@ import { createStructuredSelector } from "reselect";
import { selectJobReadOnly } from "../../redux/application/application.selectors"; import { selectJobReadOnly } from "../../redux/application/application.selectors";
import LaborAllocationsTableComponent from "../labor-allocations-table/labor-allocations-table.component"; import LaborAllocationsTableComponent from "../labor-allocations-table/labor-allocations-table.component";
import TimeTicketList from "../time-ticket-list/time-ticket-list.component"; import TimeTicketList from "../time-ticket-list/time-ticket-list.component";
import PayrollLaborAllocationsTable from "../labor-allocations-table/labor-allocations-table.payroll.component"; import PayrollLaborAllocationsTable from "../labor-allocations-table/labor-allocations-table.payroll.component";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { useTreatments } from "@splitsoftware/splitio-react";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
jobRO: selectJobReadOnly, jobRO: selectJobReadOnly,
bodyshop: selectBodyshop,
}); });
export default connect(mapStateToProps, null)(JobsDetailLaborContainer); export default connect(mapStateToProps, null)(JobsDetailLaborContainer);
@@ -49,6 +52,7 @@ const adjSpan = {
}; };
export function JobsDetailLaborContainer({ export function JobsDetailLaborContainer({
bodyshop,
jobRO, jobRO,
job, job,
jobId, jobId,
@@ -59,6 +63,12 @@ export function JobsDetailLaborContainer({
techConsole, techConsole,
adjustments, adjustments,
}) { }) {
const { Enhanced_Payroll } = useTreatments(
["Enhanced_Payroll"],
{},
bodyshop.imexshopid
);
return ( return (
<Row gutter={[16, 16]}> <Row gutter={[16, 16]}>
<Col {...ticketSpan}> <Col {...ticketSpan}>
@@ -71,22 +81,26 @@ export function JobsDetailLaborContainer({
jobId={jobId} jobId={jobId}
/> />
</Col> </Col>
<Col {...adjSpan}>
<LaborAllocationsTableComponent {Enhanced_Payroll.treatment === "on" ? (
jobId={jobId} <Col {...adjSpan}>
joblines={joblines} <PayrollLaborAllocationsTable
timetickets={timetickets} jobId={jobId}
adjustments={adjustments} joblines={joblines}
/> timetickets={timetickets}
</Col> adjustments={adjustments}
<Col {...adjSpan}> />
<PayrollLaborAllocationsTable </Col>
jobId={jobId} ) : (
joblines={joblines} <Col {...adjSpan}>
timetickets={timetickets} <LaborAllocationsTableComponent
adjustments={adjustments} jobId={jobId}
/> joblines={joblines}
</Col> timetickets={timetickets}
adjustments={adjustments}
/>
</Col>
)}
</Row> </Row>
); );
} }

View File

@@ -70,7 +70,7 @@ export function PayrollLaborAllocationsTable({
sorter: (a, b) => a.total - b.total, sorter: (a, b) => a.total - b.total,
sortOrder: sortOrder:
state.sortedInfo.columnKey === "total" && state.sortedInfo.order, state.sortedInfo.columnKey === "total" && state.sortedInfo.order,
render: (text, record) => record.total.toFixed(1), render: (text, record) => record.total.toFixed(2),
}, },
{ {
title: t("jobs.labels.hrs_claimed"), title: t("jobs.labels.hrs_claimed"),
@@ -79,7 +79,7 @@ export function PayrollLaborAllocationsTable({
sorter: (a, b) => a.claimed - b.claimed, sorter: (a, b) => a.claimed - b.claimed,
sortOrder: sortOrder:
state.sortedInfo.columnKey === "claimed" && state.sortedInfo.order, state.sortedInfo.columnKey === "claimed" && state.sortedInfo.order,
render: (text, record) => record.claimed && record.claimed.toFixed(1), render: (text, record) => record.claimed && record.claimed.toFixed(2),
}, },
{ {
title: t("jobs.labels.adjustments"), title: t("jobs.labels.adjustments"),
@@ -90,7 +90,7 @@ export function PayrollLaborAllocationsTable({
state.sortedInfo.columnKey === "adjustments" && state.sortedInfo.order, state.sortedInfo.columnKey === "adjustments" && state.sortedInfo.order,
render: (text, record) => ( render: (text, record) => (
<Space wrap> <Space wrap>
{record.adjustments.toFixed(1)} {record.adjustments.toFixed(2)}
{!technician && ( {!technician && (
<LaborAllocationsAdjustmentEdit <LaborAllocationsAdjustmentEdit
jobId={jobId} jobId={jobId}
@@ -182,7 +182,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(1), record.convertedtolbr_data.mod_lb_hrs.toFixed(2),
}, },
]; ];
@@ -208,10 +208,17 @@ export function PayrollLaborAllocationsTable({
<Col span={24}> <Col span={24}>
<Button <Button
onClick={async () => { onClick={async () => {
console.log( const { data } = await axios.post("/payroll/payall", {
await axios.post("/payroll/payall", { jobid: jobId,
jobid: jobId, });
})
setTotals(
CalculateAllocationsTotals(
bodyshop,
joblines,
[...timetickets, ...data],
adjustments
)
); );
}} }}
> >
@@ -235,16 +242,16 @@ export function PayrollLaborAllocationsTable({
</Typography.Title> </Typography.Title>
</Table.Summary.Cell> </Table.Summary.Cell>
<Table.Summary.Cell> <Table.Summary.Cell>
{summary.hrs_total.toFixed(1)} {summary.hrs_total.toFixed(2)}
</Table.Summary.Cell> </Table.Summary.Cell>
<Table.Summary.Cell> <Table.Summary.Cell>
{summary.hrs_claimed.toFixed(1)} {summary.hrs_claimed.toFixed(2)}
</Table.Summary.Cell> </Table.Summary.Cell>
<Table.Summary.Cell> <Table.Summary.Cell>
{summary.adjustments.toFixed(1)} {summary.adjustments.toFixed(2)}
</Table.Summary.Cell> </Table.Summary.Cell>
<Table.Summary.Cell> <Table.Summary.Cell>
{summary.difference.toFixed(1)} {summary.difference.toFixed(2)}
</Table.Summary.Cell> </Table.Summary.Cell>
</Table.Summary.Row> </Table.Summary.Row>
)} )}

View File

@@ -49,6 +49,7 @@
"nodemailer": "^6.9.1", "nodemailer": "^6.9.1",
"phone": "^3.1.35", "phone": "^3.1.35",
"query-string": "^7.1.1", "query-string": "^7.1.1",
"recursive-diff": "^1.0.9",
"soap": "^1.0.0", "soap": "^1.0.0",
"socket.io": "^4.6.1", "socket.io": "^4.6.1",
"ssh2-sftp-client": "^9.0.4", "ssh2-sftp-client": "^9.0.4",

View File

@@ -2,6 +2,8 @@ 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 _ = require("lodash"); const _ = require("lodash");
const rdiff = require("recursive-diff");
const logger = require("../utils/logger"); const logger = require("../utils/logger");
// Dinero.defaultCurrency = "USD"; // Dinero.defaultCurrency = "USD";
// Dinero.globalLocale = "en-CA"; // Dinero.globalLocale = "en-CA";
@@ -49,7 +51,7 @@ exports.payall = async function (req, res) {
theTeam.employee_team_members.forEach((tm) => { theTeam.employee_team_members.forEach((tm) => {
//Figure out how many hours they are owed at this line, and at what rate. //Figure out how many hours they are owed at this line, and at what rate.
console.log(tm);
if (!employeeHash[tm.employee.id]) { if (!employeeHash[tm.employee.id]) {
employeeHash[tm.employee.id] = {}; employeeHash[tm.employee.id] = {};
} }
@@ -66,7 +68,7 @@ exports.payall = async function (req, res) {
] = 0; ] = 0;
} }
const hoursOwed = (tm.percentage / 100) * jobline.mod_lb_hrs; const hoursOwed = (tm.percentage * jobline.mod_lb_hrs) / 100;
employeeHash[tm.employee.id][jobline.mod_lbr_ty][ employeeHash[tm.employee.id][jobline.mod_lbr_ty][
tm.labor_rates[jobline.mod_lbr_ty] tm.labor_rates[jobline.mod_lbr_ty]
] = ] =
@@ -102,59 +104,111 @@ exports.payall = async function (req, res) {
} }
//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); // const comparison = compare(employeeHash, ticketHash);
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 ticketsToInsert = []; const ticketsToInsert = [];
//Check the ones that are different first. Source of truth will be the employee hash. recursiveDiff.forEach((diff) => {
comparison.different.forEach((differentKey) => { //Every iteration is what we would need to insert into the time ticket hash
const empVal = employeeHash[differentKey]; //so that it would match the employee hash exactly.
const ticketVal = ticketHash[differentKey];
ticketsToInsert.push({ const path = diffParser(diff);
jobid: job.id,
employeeid: differentKey.split(".")[0],
productivehrs: empVal - ticketVal,
rate: differentKey.split(".")[2],
memo: "Adjustment between expected and entered values. ",
});
});
comparison.missing_from_first
.filter((differentKey) => differentKey.split(".").length == 3)
.forEach((differentKey) => {
const empVal = employeeHash[differentKey];
const ticketVal = ticketHash[differentKey];
if (diff.op === "add") {
if (typeof diff.val === "object") {
//Multiple values to add.
Object.keys(diff.val).forEach((key) => {
ticketsToInsert.push({
jobid: job.id,
employeeid: path.employeeid,
productivehrs: diff.val[key][Object.keys(diff.val[key])[0]],
rate: Object.keys(diff.val[key])[0],
ciecacode: key,
flat_rate: true,
memo: "Add hours.",
});
});
} else {
//Only the 1 value to add.
ticketsToInsert.push({
jobid: job.id,
employeeid: path.employeeid,
productivehrs: path.hours,
rate: path.rate,
ciecacode: path.mod_lbr_ty,
flat_rate: true,
memo: "Add hours.",
});
}
} else if (diff.op === "update") {
} else {
//Has to be a delete
ticketsToInsert.push({ ticketsToInsert.push({
jobid: job.id, jobid: job.id,
employeeid: differentKey.split(".")[0], employeeid: path.employeeid,
productivehrs: empVal - ticketVal * -1, productivehrs: diff.oldVal * -1,
rate: differentKey.split(".")[2], rate: path.rate,
memo: "Entered ticket reversed to match system payroll.", ciecacode: path.mod_lbr_ty,
flat_rate: true,
memo: "Remove unneeded hours. (Rate/Unassigned).",
}); });
}); }
comparison.missing_from_second
.filter((differentKey) => differentKey.split(".").length == 3)
.forEach((differentKey) => {
const empVal = employeeHash[differentKey];
const ticketVal = ticketHash[differentKey];
ticketsToInsert.push({
jobid: job.id,
employeeid: differentKey.split(".")[0],
productivehrs: empVal - ticketVal * -1,
rate: differentKey.split(".")[2],
memo: "Entered ticket reversed to match system payroll.",
});
});
res.json({
assignmentHash,
employeeHash,
diff: getObjectDiff(employeeHash, ticketHash),
compare: compare(employeeHash, ticketHash),
}); });
// //Check the ones that are different first. Source of truth will be the employee hash.
// comparison.different.forEach((differentKey) => {
// const empVal = fetchFromObject(employeeHash, differentKey) || 0;
// const ticketVal = fetchFromObject(ticketHash, differentKey) || 0;
// const splitKey = splitEmployeeKey(differentKey);
// ticketsToInsert.push({
// 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",
@@ -170,80 +224,102 @@ exports.payall = async function (req, res) {
} }
}; };
function getObjectDiff(obj1, obj2) { // var compare = function (a, b) {
const diff = Object.keys(obj1).reduce((result, key) => { // var result = {
if (!obj2.hasOwnProperty(key)) { // different: [],
result.push(key); // missing_from_first: [],
} else if (_.isEqual(obj1[key], obj2[key])) { // missing_from_second: [],
const resultKeyIndex = result.indexOf(key); // };
result.splice(resultKeyIndex, 1);
}
return result;
}, Object.keys(obj2));
return diff; // _.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;
// })
// );
var compare = function (a, b) { // result.missing_from_second = result.missing_from_second.concat(
var result = { // _.map(deeper.missing_from_second, (sub_path) => {
different: [], // return key + "." + sub_path;
missing_from_first: [], // })
missing_from_second: [], // );
// 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) {
return {
employeeid: diff.path[0],
mod_lbr_ty: diff.path[1],
rate: diff.path[2],
hours: diff.val,
}; };
}
_.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;
};

View File

@@ -3724,6 +3724,11 @@ readable-stream@^3.0.2, readable-stream@^3.1.1, readable-stream@^3.4.0, readable
string_decoder "^1.1.1" string_decoder "^1.1.1"
util-deprecate "^1.0.1" util-deprecate "^1.0.1"
recursive-diff@^1.0.9:
version "1.0.9"
resolved "https://registry.yarnpkg.com/recursive-diff/-/recursive-diff-1.0.9.tgz#e617cbfcf125d4d73954c06997289c2d3321d5f7"
integrity sha512-5mqpskzvXDo5Vy29Vj8tH30a0+XBmY11aqWGoN/uB94UHRwndX2EuPvH+WtbqOYkrwAF718/lDo6U4CB1qSSqQ==
remote-content@^3.0.1: remote-content@^3.0.1:
version "3.0.1" version "3.0.1"
resolved "https://registry.yarnpkg.com/remote-content/-/remote-content-3.0.1.tgz#4025d0126e873fd05b1076a6bfdaf73f5db100e3" resolved "https://registry.yarnpkg.com/remote-content/-/remote-content-3.0.1.tgz#4025d0126e873fd05b1076a6bfdaf73f5db100e3"