IO-1789 Incoming hours cap
This commit is contained in:
@@ -5,6 +5,7 @@ const Dinero = require("dinero.js");
|
||||
const moment = require("moment-timezone");
|
||||
const logger = require("../utils/logger");
|
||||
const _ = require("lodash");
|
||||
const { filter } = require("lodash");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
@@ -32,7 +33,8 @@ exports.job = async (req, res) => {
|
||||
});
|
||||
|
||||
const { jobs_by_pk, blockedDays, prodJobs, arrJobs, compJobs } = result;
|
||||
const { ssbuckets, workingdays, timezone } = result.jobs_by_pk.bodyshop;
|
||||
const { ssbuckets, workingdays, timezone, ss_configuration } =
|
||||
result.jobs_by_pk.bodyshop;
|
||||
const jobHrs = result.jobs_by_pk.jobhrs.aggregate.sum.mod_lb_hrs;
|
||||
|
||||
const JobBucket = ssbuckets.filter(
|
||||
@@ -63,29 +65,68 @@ exports.job = async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
const filteredArrJobs = arrJobs.filter(
|
||||
(j) => JobBucket.id === CheckJobBucket(ssbuckets, j)
|
||||
);
|
||||
// const filteredArrJobs = arrJobs.filter(
|
||||
// (j) => JobBucket.id === CheckJobBucket(ssbuckets, j)
|
||||
// );
|
||||
const filteredArrJobs = [];
|
||||
|
||||
// filteredArrJobs.forEach((item) => {
|
||||
// const itemDate = moment(item.scheduled_in)
|
||||
// .tz(timezone)
|
||||
// .format("yyyy-MM-DD");
|
||||
// if (!!load[itemDate]) {
|
||||
// load[itemDate].hoursIn =
|
||||
// (load[itemDate].hoursIn || 0) +
|
||||
// item.labhrs.aggregate.sum.mod_lb_hrs +
|
||||
// item.larhrs.aggregate.sum.mod_lb_hrs;
|
||||
// load[itemDate].jobsIn.push(item);
|
||||
// } else {
|
||||
// load[itemDate] = {
|
||||
// jobsIn: [item],
|
||||
// jobsOut: [],
|
||||
// hoursIn:
|
||||
// item.labhrs.aggregate.sum.mod_lb_hrs +
|
||||
// item.larhrs.aggregate.sum.mod_lb_hrs,
|
||||
// };
|
||||
// }
|
||||
// });
|
||||
|
||||
arrJobs.forEach((item) => {
|
||||
let isSameBucket = false;
|
||||
if (JobBucket.id === CheckJobBucket(ssbuckets, item)) {
|
||||
filteredArrJobs.push(item);
|
||||
isSameBucket = true;
|
||||
}
|
||||
|
||||
let jobHours =
|
||||
item.labhrs.aggregate.sum.mod_lb_hrs +
|
||||
item.larhrs.aggregate.sum.mod_lb_hrs;
|
||||
|
||||
filteredArrJobs.forEach((item) => {
|
||||
const itemDate = moment(item.scheduled_in)
|
||||
.tz(timezone)
|
||||
.format("yyyy-MM-DD");
|
||||
if (!!load[itemDate]) {
|
||||
load[itemDate].hoursIn =
|
||||
(load[itemDate].hoursIn || 0) +
|
||||
item.labhrs.aggregate.sum.mod_lb_hrs +
|
||||
item.larhrs.aggregate.sum.mod_lb_hrs;
|
||||
load[itemDate].jobsIn.push(item);
|
||||
} else {
|
||||
if (isSameBucket) {
|
||||
if (!!load[itemDate]) {
|
||||
load[itemDate].hoursIn = (load[itemDate].hoursIn || 0) + jobHours;
|
||||
load[itemDate].jobsIn.push(item);
|
||||
} else {
|
||||
load[itemDate] = {
|
||||
jobsIn: [item],
|
||||
jobsOut: [],
|
||||
hoursIn: jobHours,
|
||||
};
|
||||
}
|
||||
}
|
||||
if (!load[itemDate]) {
|
||||
load[itemDate] = {
|
||||
jobsIn: [item],
|
||||
jobsIn: [],
|
||||
jobsOut: [],
|
||||
hoursIn:
|
||||
item.labhrs.aggregate.sum.mod_lb_hrs +
|
||||
item.larhrs.aggregate.sum.mod_lb_hrs,
|
||||
hoursIn: 0,
|
||||
hoursInTotal: 0,
|
||||
};
|
||||
}
|
||||
load[itemDate].hoursInTotal =
|
||||
(load[itemDate].hoursInTotal || 0) + jobHours;
|
||||
});
|
||||
|
||||
//Get the completing jobs.
|
||||
@@ -214,11 +255,25 @@ exports.job = async (req, res) => {
|
||||
(workingdays[dayOfWeekMapper(moment(loadKey).day())] || false) &&
|
||||
!load[loadKey].blocked;
|
||||
|
||||
let isUnderDailyTotalLimit = true;
|
||||
|
||||
if (
|
||||
ss_configuration &&
|
||||
ss_configuration.dailyhrslimit &&
|
||||
ss_configuration.dailyhrslimit > 0 &&
|
||||
load[loadKey] &&
|
||||
load[loadKey].hoursInTotal &&
|
||||
load[loadKey].hoursInTotal > ss_configuration.dailyhrslimit
|
||||
) {
|
||||
isUnderDailyTotalLimit = false;
|
||||
}
|
||||
|
||||
if (
|
||||
load[loadKey].expectedLoad &&
|
||||
load[loadKey].expectedLoad[JobBucket.id] &&
|
||||
JobBucket.target > load[loadKey].expectedLoad[JobBucket.id].count &&
|
||||
isShopOpen
|
||||
isShopOpen &&
|
||||
isUnderDailyTotalLimit
|
||||
)
|
||||
possibleDates.push(new Date(loadKey).toISOString().substr(0, 10));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user