IO-2162 Update smart scheduling server side.

This commit is contained in:
Patrick Fic
2023-02-02 11:06:05 -08:00
parent 20e84668a5
commit c04a690dc3
2 changed files with 56 additions and 74 deletions

View File

@@ -41,9 +41,9 @@ exports.job = async (req, res) => {
(bucket) =>
bucket.gte <= jobHrs && (!!bucket.lt ? bucket.lt > jobHrs : true)
)[0];
const load = {
productionTotal: {},
productionHours: 0,
};
//Set the current load.
ssbuckets.forEach((bucket) => {
@@ -70,27 +70,6 @@ exports.job = async (req, res) => {
// );
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)) {
@@ -102,21 +81,27 @@ exports.job = async (req, res) => {
item.labhrs.aggregate.sum.mod_lb_hrs +
item.larhrs.aggregate.sum.mod_lb_hrs;
const itemDate = moment(item.scheduled_in)
const AddJobForSchedulingCalc = !item.inproduction;
const itemDate = moment(item.actual_in || item.scheduled_in)
.tz(timezone)
.format("yyyy-MM-DD");
if (isSameBucket) {
if (!!load[itemDate]) {
load[itemDate].hoursIn = (load[itemDate].hoursIn || 0) + jobHours;
load[itemDate].jobsIn.push(item);
load[itemDate].hoursIn =
(load[itemDate].hoursIn || 0) + AddJobForSchedulingCalc
? jobHours
: 0;
if (AddJobForSchedulingCalc) load[itemDate].jobsIn.push(item);
} else {
load[itemDate] = {
jobsIn: [item],
jobsIn: AddJobForSchedulingCalc ? [item] : [],
jobsOut: [],
hoursIn: jobHours,
hoursIn: AddJobForSchedulingCalc ? jobHours : 0,
};
}
}
if (!load[itemDate]) {
load[itemDate] = {
jobsIn: [],
@@ -139,52 +124,28 @@ exports.job = async (req, res) => {
const inProdJobs = filteredProdJobsList.find((p) => p.id === item.id);
const inArrJobs = filteredArrJobs.find((p) => p.id === item.id);
if (!(inProdJobs || inArrJobs)) {
//Job isn't found in production or coming in.
//is it going today or scheduled to go today?
if (
moment(item.actual_completion || item.scheduled_completion)
.tz(timezone)
.isSame(moment().tz(timezone), "day")
) {
console.log("Job is going today anyways, ignore it.", item);
return;
}
const AddJobForSchedulingCalc = inProdJobs || inArrJobs;
if (
moment(item.actual_completion || item.scheduled_completion)
.tz(timezone)
.isBefore(moment().tz(timezone), "day")
) {
console.log("Job should have already gone. Ignoring it.", item);
return;
}
console.log("PROBLEM JOB", item);
problemJobs.push({
...item,
code: "Job is scheduled for completion, but it is not marked in production nor is it an arriving job in this period. Check the scheduled in and completion dates",
});
return;
const itemDate = moment(
item.actual_completion || item.scheduled_completion
)
.tz(timezone)
.format("yyyy-MM-DD");
if (!!load[itemDate]) {
load[itemDate].hoursOut =
(load[itemDate].hoursOut || 0) + AddJobForSchedulingCalc
? item.labhrs.aggregate.sum.mod_lb_hrs +
item.larhrs.aggregate.sum.mod_lb_hrs
: 0;
if (AddJobForSchedulingCalc) load[itemDate].jobsOut.push(item);
} else {
const itemDate = moment(
item.actual_completion || item.scheduled_completion
)
.tz(timezone)
.format("yyyy-MM-DD");
if (!!load[itemDate]) {
load[itemDate].hoursOut =
(load[itemDate].hoursOut || 0) +
item.labhrs.aggregate.sum.mod_lb_hrs +
item.larhrs.aggregate.sum.mod_lb_hrs;
load[itemDate].jobsOut.push(item);
} else {
load[itemDate] = {
jobsOut: [item],
hoursOut:
item.labhrs.aggregate.sum.mod_lb_hrs +
item.larhrs.aggregate.sum.mod_lb_hrs,
};
}
load[itemDate] = {
jobsOut: AddJobForSchedulingCalc ? [item] : [],
hoursOut: AddJobForSchedulingCalc
? item.labhrs.aggregate.sum.mod_lb_hrs +
item.larhrs.aggregate.sum.mod_lb_hrs
: 0,
};
}
});