Added scheduling routes for smart scheduling BOD-4
This commit is contained in:
@@ -32,6 +32,8 @@ exports.default = async (req, res) => {
|
||||
|
||||
//Is this a two tier, or 3 tier setup?
|
||||
const isThreeTier = bodyshop.accountingconfig.tiers === 3;
|
||||
const twoTierPref = bodyshop.accountingconfig.twotierpref;
|
||||
|
||||
if (isThreeTier) {
|
||||
QbXmlToExecute.push({
|
||||
id: jobId,
|
||||
@@ -43,13 +45,25 @@ exports.default = async (req, res) => {
|
||||
QbXmlToExecute.push({
|
||||
id: jobId,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: generateJobQbxml(jobs_by_pk, bodyshop, isThreeTier, 2),
|
||||
qbxml: generateJobQbxml(
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
2,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
|
||||
QbXmlToExecute.push({
|
||||
id: jobId,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: generateJobQbxml(jobs_by_pk, bodyshop, isThreeTier, 3),
|
||||
qbxml: generateJobQbxml(
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
3,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
//Generate the actual invoice.
|
||||
QbXmlToExecute.push({
|
||||
@@ -115,7 +129,7 @@ const generateOwnerTier = (jobs_by_pk) => {
|
||||
}`;
|
||||
};
|
||||
|
||||
const generateJobQbxml = (jobs_by_pk, bodyshop, isThreeTier, tierLevel) => {
|
||||
const generateJobQbxml = (jobs_by_pk, bodyshop, isThreeTier, tierLevel, twoTierPref) => {
|
||||
let Name;
|
||||
let ParentRefName;
|
||||
|
||||
|
||||
@@ -108,3 +108,23 @@ query QUERY_INVOICES_FOR_PAYABLES_EXPORT($invoices: [uuid!]!) {
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports.QUERY_UPCOMING_APPOINTMENTS = `
|
||||
query QUERY_UPCOMING_APPOINTMENTS($now: timestamptz!) {
|
||||
appointments(where: {start: {_gt: $now}}) {
|
||||
start
|
||||
isintake
|
||||
id
|
||||
job {
|
||||
joblines_aggregate {
|
||||
aggregate {
|
||||
sum {
|
||||
mod_lb_hrs
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
47
server/scheduling/scheduling-job.js
Normal file
47
server/scheduling/scheduling-job.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const path = require("path");
|
||||
const queries = require("../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
});
|
||||
|
||||
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: {
|
||||
Authorization: BearerToken,
|
||||
},
|
||||
});
|
||||
|
||||
const result = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.QUERY_UPCOMING_APPOINTMENTS, {
|
||||
now: new Date(),
|
||||
});
|
||||
|
||||
const possibleDates = [];
|
||||
|
||||
//Temp
|
||||
possibleDates.push(new Date());
|
||||
possibleDates.push(new Date());
|
||||
possibleDates.push(new Date());
|
||||
possibleDates.push(new Date());
|
||||
possibleDates.push(new Date());
|
||||
//Get a list of upcoming appointments
|
||||
//Get the config for each day
|
||||
|
||||
res.json(possibleDates);
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
res.status(400).send(error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user