IO-2162 Update smart scheduling server side.
This commit is contained in:
@@ -536,7 +536,16 @@ exports.QUERY_UPCOMING_APPOINTMENTS = `query QUERY_UPCOMING_APPOINTMENTS($now: t
|
||||
arrJobs: jobs(where: {scheduled_in: {_gte: $now}, suspended: {_eq: false}}) {
|
||||
id
|
||||
scheduled_in
|
||||
actual_in
|
||||
scheduled_completion
|
||||
ro_number
|
||||
ownr_fn
|
||||
ownr_ln
|
||||
ownr_co_nm
|
||||
alt_transport
|
||||
actual_completion
|
||||
inproduction
|
||||
status
|
||||
labhrs: joblines_aggregate(where: {mod_lbr_ty: {_neq: "LAR"}, removed: {_eq: false}}) {
|
||||
aggregate {
|
||||
sum {
|
||||
@@ -554,9 +563,15 @@ exports.QUERY_UPCOMING_APPOINTMENTS = `query QUERY_UPCOMING_APPOINTMENTS($now: t
|
||||
}
|
||||
compJobs: jobs(where: {_and: [{suspended: {_eq: false}}, {_or: [{scheduled_completion: {_gte: $now}}, {actual_completion: {_gte: $now}}]}]}) {
|
||||
id
|
||||
status
|
||||
ro_number
|
||||
scheduled_completion
|
||||
actual_completion
|
||||
scheduled_in
|
||||
ownr_fn
|
||||
ownr_ln
|
||||
ownr_co_nm
|
||||
inproduction
|
||||
labhrs: joblines_aggregate(where: {mod_lbr_ty: {_neq: "LAR"}, removed: {_eq: false}}) {
|
||||
aggregate {
|
||||
sum {
|
||||
@@ -574,15 +589,20 @@ exports.QUERY_UPCOMING_APPOINTMENTS = `query QUERY_UPCOMING_APPOINTMENTS($now: t
|
||||
}
|
||||
prodJobs: jobs(where: {inproduction: {_eq: true}, suspended: {_eq: false}}) {
|
||||
id
|
||||
actual_in
|
||||
scheduled_in
|
||||
actual_completion
|
||||
scheduled_completion
|
||||
labhrs: joblines_aggregate(where: {_and: [{mod_lbr_ty: {_neq: "LAR"}}, {removed: {_eq: false}}]}) {
|
||||
inproduction
|
||||
ro_number
|
||||
labhrs: joblines_aggregate(where: {mod_lbr_ty: {_neq: "LAR"}, removed: {_eq: false}}) {
|
||||
aggregate {
|
||||
sum {
|
||||
mod_lb_hrs
|
||||
}
|
||||
}
|
||||
}
|
||||
larhrs: joblines_aggregate(where: {_and: [{mod_lbr_ty: {_eq: "LAR"}}, {removed: {_eq: false}}]}) {
|
||||
larhrs: joblines_aggregate(where: {mod_lbr_ty: {_eq: "LAR"}, removed: {_eq: false}}) {
|
||||
aggregate {
|
||||
sum {
|
||||
mod_lb_hrs
|
||||
@@ -590,7 +610,8 @@ exports.QUERY_UPCOMING_APPOINTMENTS = `query QUERY_UPCOMING_APPOINTMENTS($now: t
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
|
||||
exports.QUERY_EMPLOYEE_PIN = `query QUERY_EMPLOYEE_PIN($shopId: uuid!, $employeeId: String!) {
|
||||
employees(where: {_and: {shopid: {_eq: $shopId}, employee_number: {_eq: $employeeId}}}) {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user