Cleanup on schedule modal + begin smart scheduling BOD-4
This commit is contained in:
@@ -110,7 +110,20 @@ query QUERY_INVOICES_FOR_PAYABLES_EXPORT($invoices: [uuid!]!) {
|
||||
`;
|
||||
|
||||
exports.QUERY_UPCOMING_APPOINTMENTS = `
|
||||
query QUERY_UPCOMING_APPOINTMENTS($now: timestamptz!) {
|
||||
query QUERY_UPCOMING_APPOINTMENTS($now: timestamptz!, $jobId: uuid!) {
|
||||
jobs_by_pk(id: $jobId){
|
||||
bodyshop{
|
||||
ssbuckets
|
||||
}
|
||||
jobhrs: joblines_aggregate {
|
||||
aggregate {
|
||||
sum {
|
||||
mod_lb_hrs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
appointments(where: {start: {_gt: $now}}) {
|
||||
start
|
||||
isintake
|
||||
@@ -126,5 +139,6 @@ exports.QUERY_UPCOMING_APPOINTMENTS = `
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
`;
|
||||
|
||||
@@ -2,6 +2,7 @@ const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const path = require("path");
|
||||
const queries = require("../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
const moment = require("moment");
|
||||
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
@@ -14,7 +15,6 @@ exports.job = async (req, res) => {
|
||||
try {
|
||||
const BearerToken = req.headers.authorization;
|
||||
const { jobId } = req.body;
|
||||
console.log("exports.job -> jobId", jobId);
|
||||
|
||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||
headers: {
|
||||
@@ -26,8 +26,43 @@ exports.job = async (req, res) => {
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.QUERY_UPCOMING_APPOINTMENTS, {
|
||||
now: new Date(),
|
||||
jobId: jobId,
|
||||
});
|
||||
|
||||
const { appointments } = result;
|
||||
const { ssbuckets } = result.jobs_by_pk.bodyshop;
|
||||
const jobhrs = result.jobs_by_pk.jobhrs.aggregate.sum.mod_lb_hrs;
|
||||
|
||||
const JobClassification = ssbuckets.filter(
|
||||
(b) => b.gte <= jobhrs && b.lt > jobhrs
|
||||
);
|
||||
//Create a matrix of load bucket
|
||||
|
||||
const bucketMatrix = {};
|
||||
|
||||
//Get latest date + add 5 days.
|
||||
|
||||
const totalMatrixDays = moment
|
||||
.max(appointments.map((a) => moment(a.start)))
|
||||
.add("5", "days")
|
||||
.diff(moment(), "days");
|
||||
|
||||
for (var i = 0; i++; i < totalMatrixDays) {
|
||||
const theDate = moment().add(i, "days").toISOString().substr(0, 10);
|
||||
console.log("theDate", theDate);
|
||||
ssbuckets.forEach((bucket) => {
|
||||
bucketMatrix[theDate][bucket.id] = { in: 0, out: 0 };
|
||||
});
|
||||
}
|
||||
|
||||
appointments.forEach((appointment) => {
|
||||
//Get the day of the appointment.
|
||||
const appDate = moment(appointment.start).toISOString().substr(0, 10);
|
||||
!!bucketMatrix[appDate] ? {} : {};
|
||||
});
|
||||
|
||||
//Calculate the load for the shop looking forward.
|
||||
|
||||
const possibleDates = [];
|
||||
|
||||
//Temp
|
||||
|
||||
Reference in New Issue
Block a user