feature/IO-3587-Comission-Cut - Implement
This commit is contained in:
@@ -1,20 +1,9 @@
|
||||
const Dinero = require("dinero.js");
|
||||
const queries = require("../graphql-client/queries");
|
||||
const logger = require("../utils/logger");
|
||||
const { CalculateExpectedHoursForJob, CalculateTicketsHoursForJob } = require("./pay-all");
|
||||
|
||||
// Dinero.defaultCurrency = "USD";
|
||||
// Dinero.globalLocale = "en-CA";
|
||||
Dinero.globalRoundingMode = "HALF_EVEN";
|
||||
|
||||
const get = (obj, key) => {
|
||||
return key.split(".").reduce((o, x) => {
|
||||
return typeof o == "undefined" || o === null ? o : o[x];
|
||||
}, obj);
|
||||
};
|
||||
|
||||
exports.calculatelabor = async function (req, res) {
|
||||
const { jobid, calculateOnly } = req.body;
|
||||
const { jobid } = req.body;
|
||||
logger.log("job-payroll-calculate-labor", "DEBUG", req.user.email, jobid, null);
|
||||
|
||||
const BearerToken = req.BearerToken;
|
||||
@@ -41,23 +30,19 @@ exports.calculatelabor = async function (req, res) {
|
||||
Object.keys(employeeHash).forEach((employeeIdKey) => {
|
||||
//At the employee level.
|
||||
Object.keys(employeeHash[employeeIdKey]).forEach((laborTypeKey) => {
|
||||
//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];
|
||||
}
|
||||
const expected = employeeHash[employeeIdKey][laborTypeKey];
|
||||
const claimed = ticketHash?.[employeeIdKey]?.[laborTypeKey];
|
||||
|
||||
totals.push({
|
||||
employeeid: employeeIdKey,
|
||||
rate: rateKey,
|
||||
mod_lbr_ty: laborTypeKey,
|
||||
expectedHours,
|
||||
claimedHours: claimedHours || 0
|
||||
});
|
||||
if (claimed) {
|
||||
delete ticketHash[employeeIdKey][laborTypeKey];
|
||||
}
|
||||
|
||||
totals.push({
|
||||
employeeid: employeeIdKey,
|
||||
rate: expected.rate,
|
||||
mod_lbr_ty: laborTypeKey,
|
||||
expectedHours: expected.hours,
|
||||
claimedHours: claimed?.hours || 0
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -65,23 +50,14 @@ exports.calculatelabor = async function (req, res) {
|
||||
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];
|
||||
}
|
||||
const claimed = ticketHash[employeeIdKey][laborTypeKey];
|
||||
|
||||
totals.push({
|
||||
employeeid: employeeIdKey,
|
||||
rate: rateKey,
|
||||
mod_lbr_ty: laborTypeKey,
|
||||
expectedHours,
|
||||
claimedHours: claimedHours || 0
|
||||
});
|
||||
totals.push({
|
||||
employeeid: employeeIdKey,
|
||||
rate: claimed.rate,
|
||||
mod_lbr_ty: laborTypeKey,
|
||||
expectedHours: 0,
|
||||
claimedHours: claimed.hours || 0
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -101,6 +77,6 @@ exports.calculatelabor = async function (req, res) {
|
||||
jobid: jobid,
|
||||
error
|
||||
});
|
||||
res.status(503).send();
|
||||
res.status(400).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user