Added working days to scheduling IO-153
This commit is contained in:
@@ -31,7 +31,7 @@ exports.job = async (req, res) => {
|
||||
});
|
||||
|
||||
const { appointments, jobs } = result;
|
||||
const { ssbuckets } = result.jobs_by_pk.bodyshop;
|
||||
const { ssbuckets, workingdays } = result.jobs_by_pk.bodyshop;
|
||||
const jobHrs = result.jobs_by_pk.jobhrs.aggregate.sum.mod_lb_hrs;
|
||||
|
||||
const JobBucket = ssbuckets.filter(
|
||||
@@ -40,14 +40,14 @@ exports.job = async (req, res) => {
|
||||
)[0];
|
||||
|
||||
const bucketMatrix = {};
|
||||
|
||||
const yesterday = moment().subtract(1, "day");
|
||||
//Get latest date + add 5 days to allow for back end adding..
|
||||
const totalMatrixDays = moment
|
||||
.max([
|
||||
...appointments.map((a) => moment(a.start)),
|
||||
...jobs
|
||||
.map((p) => moment(p.scheduled_completion))
|
||||
.filter((p) => p.isValid()),
|
||||
.filter((p) => p.isValid() && p.isAfter(yesterday)),
|
||||
])
|
||||
.add("5", "days")
|
||||
.diff(moment(), "days");
|
||||
@@ -102,6 +102,7 @@ exports.job = async (req, res) => {
|
||||
(bucket) =>
|
||||
bucket.gte <= jobHrs && (!!bucket.lt ? bucket.lt > jobHrs : true)
|
||||
)[0];
|
||||
console.log(pjobBucket.id, JobBucket.id, pjobBucket.id === JobBucket.id);
|
||||
if (pjobBucket.id === JobBucket.id) {
|
||||
//Theyre the same classification. Add it to the matrix.
|
||||
const compDate = moment(pjob.scheduled_completion);
|
||||
@@ -112,7 +113,6 @@ exports.job = async (req, res) => {
|
||||
? compDate.format("yyyy-MM-DD")
|
||||
: todayIsoString
|
||||
: todayIsoString;
|
||||
console.log("bucketMatrix", bucketMatrix);
|
||||
bucketMatrix[dateToUse] = {
|
||||
...bucketMatrix[dateToUse],
|
||||
out: (bucketMatrix[dateToUse].out || 0) + 1,
|
||||
@@ -125,13 +125,37 @@ exports.job = async (req, res) => {
|
||||
const possibleDates = [];
|
||||
const bucketMatrixKeys = Object.keys(bucketMatrix);
|
||||
bucketMatrixKeys.forEach((bmkey) => {
|
||||
if (JobBucket.target > bucketMatrix[bmkey].in - bucketMatrix[bmkey].out)
|
||||
const isShopOpen = workingdays[dayOfWeekMapper(moment(bmkey).day())];
|
||||
|
||||
if (
|
||||
JobBucket.target > bucketMatrix[bmkey].in - bucketMatrix[bmkey].out &&
|
||||
isShopOpen
|
||||
)
|
||||
possibleDates.push(new Date(bmkey).toISOString().substr(0, 10));
|
||||
});
|
||||
|
||||
console.log("possibleDates", possibleDates, "bucketMatrix", bucketMatrix);
|
||||
res.json(possibleDates);
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
res.status(400).send(error);
|
||||
}
|
||||
};
|
||||
|
||||
const dayOfWeekMapper = (numberOfDay) => {
|
||||
switch (numberOfDay) {
|
||||
case 0:
|
||||
return "sunday";
|
||||
case 1:
|
||||
return "monday";
|
||||
case 2:
|
||||
return "tuesday";
|
||||
case 3:
|
||||
return "wednesday";
|
||||
case 4:
|
||||
return "thursday";
|
||||
case 5:
|
||||
return "friday";
|
||||
case 6:
|
||||
return "saturday";
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user