Merged in release/2023-02-03 (pull request #665)

release/2023-02-03

Approved-by: Patrick Fic
This commit is contained in:
Patrick Fic
2023-02-02 19:06:20 +00:00
2 changed files with 56 additions and 74 deletions

View File

@@ -536,7 +536,16 @@ exports.QUERY_UPCOMING_APPOINTMENTS = `query QUERY_UPCOMING_APPOINTMENTS($now: t
arrJobs: jobs(where: {scheduled_in: {_gte: $now}, suspended: {_eq: false}}) { arrJobs: jobs(where: {scheduled_in: {_gte: $now}, suspended: {_eq: false}}) {
id id
scheduled_in scheduled_in
actual_in
scheduled_completion
ro_number 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}}) { labhrs: joblines_aggregate(where: {mod_lbr_ty: {_neq: "LAR"}, removed: {_eq: false}}) {
aggregate { aggregate {
sum { 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}}]}]}) { compJobs: jobs(where: {_and: [{suspended: {_eq: false}}, {_or: [{scheduled_completion: {_gte: $now}}, {actual_completion: {_gte: $now}}]}]}) {
id id
status
ro_number ro_number
scheduled_completion scheduled_completion
actual_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}}) { labhrs: joblines_aggregate(where: {mod_lbr_ty: {_neq: "LAR"}, removed: {_eq: false}}) {
aggregate { aggregate {
sum { sum {
@@ -574,15 +589,20 @@ exports.QUERY_UPCOMING_APPOINTMENTS = `query QUERY_UPCOMING_APPOINTMENTS($now: t
} }
prodJobs: jobs(where: {inproduction: {_eq: true}, suspended: {_eq: false}}) { prodJobs: jobs(where: {inproduction: {_eq: true}, suspended: {_eq: false}}) {
id id
actual_in
scheduled_in
actual_completion
scheduled_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 { aggregate {
sum { sum {
mod_lb_hrs 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 { aggregate {
sum { sum {
mod_lb_hrs 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!) { exports.QUERY_EMPLOYEE_PIN = `query QUERY_EMPLOYEE_PIN($shopId: uuid!, $employeeId: String!) {
employees(where: {_and: {shopid: {_eq: $shopId}, employee_number: {_eq: $employeeId}}}) { employees(where: {_and: {shopid: {_eq: $shopId}, employee_number: {_eq: $employeeId}}}) {

View File

@@ -41,9 +41,9 @@ exports.job = async (req, res) => {
(bucket) => (bucket) =>
bucket.gte <= jobHrs && (!!bucket.lt ? bucket.lt > jobHrs : true) bucket.gte <= jobHrs && (!!bucket.lt ? bucket.lt > jobHrs : true)
)[0]; )[0];
const load = { const load = {
productionTotal: {}, productionTotal: {},
productionHours: 0,
}; };
//Set the current load. //Set the current load.
ssbuckets.forEach((bucket) => { ssbuckets.forEach((bucket) => {
@@ -70,27 +70,6 @@ exports.job = async (req, res) => {
// ); // );
const filteredArrJobs = []; 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) => { arrJobs.forEach((item) => {
let isSameBucket = false; let isSameBucket = false;
if (JobBucket.id === CheckJobBucket(ssbuckets, item)) { if (JobBucket.id === CheckJobBucket(ssbuckets, item)) {
@@ -102,21 +81,27 @@ exports.job = async (req, res) => {
item.labhrs.aggregate.sum.mod_lb_hrs + item.labhrs.aggregate.sum.mod_lb_hrs +
item.larhrs.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) .tz(timezone)
.format("yyyy-MM-DD"); .format("yyyy-MM-DD");
if (isSameBucket) { if (isSameBucket) {
if (!!load[itemDate]) { if (!!load[itemDate]) {
load[itemDate].hoursIn = (load[itemDate].hoursIn || 0) + jobHours; load[itemDate].hoursIn =
load[itemDate].jobsIn.push(item); (load[itemDate].hoursIn || 0) + AddJobForSchedulingCalc
? jobHours
: 0;
if (AddJobForSchedulingCalc) load[itemDate].jobsIn.push(item);
} else { } else {
load[itemDate] = { load[itemDate] = {
jobsIn: [item], jobsIn: AddJobForSchedulingCalc ? [item] : [],
jobsOut: [], jobsOut: [],
hoursIn: jobHours, hoursIn: AddJobForSchedulingCalc ? jobHours : 0,
}; };
} }
} }
if (!load[itemDate]) { if (!load[itemDate]) {
load[itemDate] = { load[itemDate] = {
jobsIn: [], jobsIn: [],
@@ -139,52 +124,28 @@ exports.job = async (req, res) => {
const inProdJobs = filteredProdJobsList.find((p) => p.id === item.id); const inProdJobs = filteredProdJobsList.find((p) => p.id === item.id);
const inArrJobs = filteredArrJobs.find((p) => p.id === item.id); const inArrJobs = filteredArrJobs.find((p) => p.id === item.id);
if (!(inProdJobs || inArrJobs)) { const AddJobForSchedulingCalc = 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;
}
if ( const itemDate = moment(
moment(item.actual_completion || item.scheduled_completion) item.actual_completion || item.scheduled_completion
.tz(timezone) )
.isBefore(moment().tz(timezone), "day") .tz(timezone)
) { .format("yyyy-MM-DD");
console.log("Job should have already gone. Ignoring it.", item); if (!!load[itemDate]) {
return; load[itemDate].hoursOut =
} (load[itemDate].hoursOut || 0) + AddJobForSchedulingCalc
console.log("PROBLEM JOB", item); ? item.labhrs.aggregate.sum.mod_lb_hrs +
problemJobs.push({ item.larhrs.aggregate.sum.mod_lb_hrs
...item, : 0;
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", if (AddJobForSchedulingCalc) load[itemDate].jobsOut.push(item);
});
return;
} else { } else {
const itemDate = moment( load[itemDate] = {
item.actual_completion || item.scheduled_completion jobsOut: AddJobForSchedulingCalc ? [item] : [],
) hoursOut: AddJobForSchedulingCalc
.tz(timezone) ? item.labhrs.aggregate.sum.mod_lb_hrs +
.format("yyyy-MM-DD"); item.larhrs.aggregate.sum.mod_lb_hrs
if (!!load[itemDate]) { : 0,
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,
};
}
} }
}); });