IO-1745 Resolve scheduling showing incorrect days.

This commit is contained in:
Patrick Fic
2022-03-01 14:53:42 -08:00
parent 0cd1b41ed9
commit dcf388ff7c

View File

@@ -111,10 +111,9 @@ exports.job = async (req, res) => {
} }
if ( if (
moment(item.actual_completion || item.scheduled_completion).tz(timezone).isBefore( moment(item.actual_completion || item.scheduled_completion)
moment().tz(timezone), .tz(timezone)
"day" .isBefore(moment().tz(timezone), "day")
)
) { ) {
console.log("Job should have already gone. Ignoring it.", item); console.log("Job should have already gone. Ignoring it.", item);
return; return;
@@ -128,7 +127,9 @@ exports.job = async (req, res) => {
} else { } else {
const itemDate = moment( const itemDate = moment(
item.actual_completion || item.scheduled_completion item.actual_completion || item.scheduled_completion
).tz(timezone).format("yyyy-MM-DD"); )
.tz(timezone)
.format("yyyy-MM-DD");
if (!!load[itemDate]) { if (!!load[itemDate]) {
load[itemDate].hoursOut = load[itemDate].hoursOut =
(load[itemDate].hoursOut || 0) + (load[itemDate].hoursOut || 0) +
@@ -153,14 +154,20 @@ exports.job = async (req, res) => {
const end = moment.max([ const end = moment.max([
...filteredArrJobs.map((a) => moment(a.scheduled_in).tz(timezone)), ...filteredArrJobs.map((a) => moment(a.scheduled_in).tz(timezone)),
...filteredCompJobs ...filteredCompJobs
.map((p) => moment(p.actual_completion || p.scheduled_completion).tz(timezone)) .map((p) =>
moment(p.actual_completion || p.scheduled_completion).tz(timezone)
)
.filter((p) => p.isValid() && p.isAfter(yesterday)), .filter((p) => p.isValid() && p.isAfter(yesterday)),
moment().tz(timezone).add(15, "days"), moment().tz(timezone).add(15, "days"),
]); ]);
const range = Math.round(moment.duration(end.diff(today)).asDays()); const range = Math.round(moment.duration(end.diff(today)).asDays());
for (var day = 0; day < range; day++) { for (var day = 0; day < range; day++) {
const current = moment(today).tz(timezone).add(day, "days").format("yyyy-MM-DD"); const current = moment(today)
const prev = moment(today).tz(timezone) .tz(timezone)
.add(day, "days")
.format("yyyy-MM-DD");
const prev = moment(today)
.tz(timezone)
.add(day - 1, "days") .add(day - 1, "days")
.format("yyyy-MM-DD"); .format("yyyy-MM-DD");
if (!!!load[current]) { if (!!!load[current]) {
@@ -204,7 +211,7 @@ exports.job = async (req, res) => {
loadKeys.forEach((loadKey) => { loadKeys.forEach((loadKey) => {
const isShopOpen = const isShopOpen =
(workingdays[dayOfWeekMapper(moment(loadKey).tz(timezone).day())] || false) && (workingdays[dayOfWeekMapper(moment(loadKey).day())] || false) &&
!load[loadKey].blocked; !load[loadKey].blocked;
if ( if (