From 05fb2cd7a135dfb31c5b60c15c106ecc8e5c07fb Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Fri, 7 Jan 2022 09:54:43 -0800 Subject: [PATCH] Further scheduling updates. --- .../redux/application/application.sagas.js | 36 ++++++++++++++----- server/scheduling/scheduling-job.js | 30 +++++++++++----- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/client/src/redux/application/application.sagas.js b/client/src/redux/application/application.sagas.js index fceaab4e1..969d75b18 100644 --- a/client/src/redux/application/application.sagas.js +++ b/client/src/redux/application/application.sagas.js @@ -76,17 +76,35 @@ export function* calculateScheduleLoad({ payload: end }) { let problemJobs = []; compJobs.forEach((item) => { - if (!item.scheduled_completion) - console.log("JOB HAS NO SCHEDULED COMPLETION DATE.", item); + if (!(item.actual_completion || item.scheduled_completion)) + console.log("JOB HAS NO COMPLETION DATE.", item); const inProdJobs = prodJobs.find((p) => p.id === item.id); const inArrJobs = arrJobs.find((p) => p.id === item.id); - if ( - !(inProdJobs || inArrJobs) && - !moment(item.scheduled_completion).isSame(moment(), "day") - ) { - // NOT FOUND! + 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).isSame( + moment(), + "day" + ) + ) { + console.log("Job is going today anyways, ignore it.", item); + return; + } + + if ( + moment(item.actual_completion || item.scheduled_completion).isBefore( + moment(), + "day" + ) + ) { + console.log("Job should have already gone. Ignoring it.", item); + return; + } + 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", @@ -94,7 +112,9 @@ export function* calculateScheduleLoad({ payload: end }) { return; } - const itemDate = moment(item.scheduled_completion).format("yyyy-MM-DD"); + const itemDate = moment( + item.actual_completion || item.scheduled_completion + ).format("yyyy-MM-DD"); if (!!load[itemDate]) { load[itemDate].hoursOut = (load[itemDate].hoursOut || 0) + diff --git a/server/scheduling/scheduling-job.js b/server/scheduling/scheduling-job.js index 54bad6919..c5b2e3251 100644 --- a/server/scheduling/scheduling-job.js +++ b/server/scheduling/scheduling-job.js @@ -96,14 +96,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) && - !moment(item.actual_completion || item.scheduled_completion).isSame( - moment(), - "day" - ) - ) { - // NOT FOUND! + 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).isSame( + moment(), + "day" + ) + ) { + console.log("Job is going today anyways, ignore it.", item); + return; + } + + if ( + moment(item.actual_completion || item.scheduled_completion).isBefore( + moment(), + "day" + ) + ) { + console.log("Job should have already gone. Ignoring it.", item); + return; + } console.log("PROBLEM JOB", item); problemJobs.push({ ...item,