Merge remote-tracking branch 'origin/release/2023-03-24' into feature/america
This commit is contained in:
@@ -1092,7 +1092,13 @@ async function GenerateTransWips(socket) {
|
||||
if (alloc.sale.getAmount() > 0 && !alloc.tax) {
|
||||
const item = {
|
||||
acct: alloc.profitCenter.dms_acctnumber,
|
||||
cntl: socket.JobData.ro_number,
|
||||
cntl:
|
||||
alloc.profitCenter.dms_control_override &&
|
||||
alloc.profitCenter.dms_control_override !== null &&
|
||||
alloc.profitCenter.dms_control_override !== undefined &&
|
||||
alloc.profitCenter.dms_control_override?.trim() !== ""
|
||||
? alloc.profitCenter.dms_control_override
|
||||
: socket.JobData.ro_number,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: alloc.sale.multiply(-1).getAmount(),
|
||||
@@ -1109,7 +1115,13 @@ async function GenerateTransWips(socket) {
|
||||
if (alloc.cost.getAmount() > 0 && !alloc.tax) {
|
||||
const item = {
|
||||
acct: alloc.costCenter.dms_acctnumber,
|
||||
cntl: socket.JobData.ro_number,
|
||||
cntl:
|
||||
alloc.costCenter.dms_control_override &&
|
||||
alloc.costCenter.dms_control_override !== null &&
|
||||
alloc.costCenter.dms_control_override !== undefined &&
|
||||
alloc.costCenter.dms_control_override?.trim() !== ""
|
||||
? alloc.costCenter.dms_control_override
|
||||
: socket.JobData.ro_number,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: alloc.cost.getAmount(),
|
||||
@@ -1123,7 +1135,13 @@ async function GenerateTransWips(socket) {
|
||||
|
||||
const itemWip = {
|
||||
acct: alloc.costCenter.dms_wip_acctnumber,
|
||||
cntl: socket.JobData.ro_number,
|
||||
cntl:
|
||||
alloc.costCenter.dms_control_override &&
|
||||
alloc.costCenter.dms_control_override !== null &&
|
||||
alloc.costCenter.dms_control_override !== undefined &&
|
||||
alloc.costCenter.dms_control_override?.trim() !== ""
|
||||
? alloc.costCenter.dms_control_override
|
||||
: socket.JobData.ro_number,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: alloc.cost.multiply(-1).getAmount(),
|
||||
@@ -1158,7 +1176,13 @@ async function GenerateTransWips(socket) {
|
||||
if (alloc.sale.getAmount() > 0) {
|
||||
const item2 = {
|
||||
acct: alloc.profitCenter.dms_acctnumber,
|
||||
cntl: socket.JobData.ro_number,
|
||||
cntl:
|
||||
alloc.profitCenter.dms_control_override &&
|
||||
alloc.profitCenter.dms_control_override !== null &&
|
||||
alloc.profitCenter.dms_control_override !== undefined &&
|
||||
alloc.profitCenter.dms_control_override?.trim() !== ""
|
||||
? alloc.profitCenter.dms_control_override
|
||||
: socket.JobData.ro_number,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: alloc.sale.multiply(-1).getAmount(),
|
||||
|
||||
@@ -42,14 +42,16 @@ function pollFunc(fn, timeout, interval) {
|
||||
pollFunc(getEntegralShopData, 0, 5 * 60 * 1000); //Set the metadata to refresh every 5 minutes.
|
||||
|
||||
async function getEntegralShopData() {
|
||||
await storage.init({ logging: true });
|
||||
const { bodyshops } = await client.request(queries.GET_ENTEGRAL_SHOPS);
|
||||
logger.log("set-entegral-shops-local-storage", "DEBUG", "API", null, null);
|
||||
await storage.setItem("entegralShops", bodyshops);
|
||||
return true; //Continue execution.
|
||||
// await storage.init({ logging: true });
|
||||
// const { bodyshops } = await client.request(queries.GET_ENTEGRAL_SHOPS);
|
||||
// logger.log("set-entegral-shops-local-storage", "DEBUG", "API", null, null);
|
||||
// await storage.setItem("entegralShops", bodyshops);
|
||||
// return true; //Continue execution.
|
||||
}
|
||||
|
||||
exports.default = async (req, res) => {
|
||||
res.sendStatus(200);
|
||||
return;
|
||||
//Query for the List of Bodyshop Clients.
|
||||
const job = req.body.event.data.new;
|
||||
logger.log("arms-job-update", "DEBUG", "api", job.id, null);
|
||||
|
||||
@@ -814,7 +814,11 @@ const CreateCosts = (job) => {
|
||||
].add(
|
||||
Dinero({
|
||||
amount: Math.round((ticket_val.rate || 0) * 100),
|
||||
}).multiply(ticket_val.actualhrs || ticket_val.productivehrs || 0)
|
||||
}).multiply(
|
||||
(ticket_val.flat_rate
|
||||
? ticket_val.productivehrs
|
||||
: ticket_val.actualhrs) || 0
|
||||
)
|
||||
);
|
||||
|
||||
return ticket_acc;
|
||||
|
||||
@@ -775,6 +775,7 @@ exports.AUTOHOUSE_QUERY = `query AUTOHOUSE_EXPORT($start: timestamptz, $bodyshop
|
||||
cost_center
|
||||
actualhrs
|
||||
productivehrs
|
||||
flat_rate
|
||||
}
|
||||
area_of_damage
|
||||
employee_prep_rel {
|
||||
@@ -905,7 +906,7 @@ exports.UPDATE_JOB = `
|
||||
}
|
||||
`;
|
||||
|
||||
exports.GET_JOB_BY_PK = ` query GET_JOB_BY_PK($id: uuid!) {
|
||||
exports.GET_JOB_BY_PK = `query GET_JOB_BY_PK($id: uuid!) {
|
||||
jobs_by_pk(id: $id) {
|
||||
updated_at
|
||||
alt_transport
|
||||
@@ -1733,4 +1734,28 @@ exports.GET_JOB_FOR_PPC = `query GET_JOB_FOR_PPC($jobid: uuid!) {
|
||||
timezone
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
exports.QUERY_PARTS_SCAN = `query QUERY_PARTS_SCAN ($id: uuid!) {
|
||||
jobs_by_pk(id: $id) {
|
||||
bodyshop {
|
||||
id
|
||||
md_parts_scan
|
||||
}
|
||||
joblines(where: {removed: {_eq: false}}) {
|
||||
id
|
||||
line_desc
|
||||
critical
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
exports.UPDATE_PARTS_CRITICAL = `mutation UPDATE_PARTS_CRITICAL ($IdsToMarkCritical:[uuid!]!, $jobid: uuid!){
|
||||
critical: update_joblines(where:{id:{_in:$IdsToMarkCritical}}, _set:{critical: true}){
|
||||
affected_rows
|
||||
}
|
||||
notcritical: update_joblines(where:{id:{_nin:$IdsToMarkCritical}, jobid: {_eq: $jobid}}, _set:{critical: false}){
|
||||
affected_rows
|
||||
}
|
||||
}`;
|
||||
|
||||
58
server/parts-scan/parts-scan.js
Normal file
58
server/parts-scan/parts-scan.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const Dinero = require("dinero.js");
|
||||
const queries = require("../graphql-client/queries");
|
||||
const { job } = require("../scheduling/scheduling-job");
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const logger = require("../utils/logger");
|
||||
const _ = require("lodash");
|
||||
// Dinero.defaultCurrency = "USD";
|
||||
// Dinero.globalLocale = "en-CA";
|
||||
|
||||
exports.partsScan = async function (req, res) {
|
||||
const BearerToken = req.headers.authorization;
|
||||
const { jobid } = req.body;
|
||||
logger.log("job-parts-scan", "DEBUG", req.user?.email, jobid, null);
|
||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||
headers: {
|
||||
Authorization: BearerToken,
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
//Query all jobline data using the user's authorization.
|
||||
const data = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.QUERY_PARTS_SCAN, {
|
||||
id: jobid,
|
||||
});
|
||||
|
||||
//Create RegExps once for better performance.
|
||||
const IdsToMarkCritical = [];
|
||||
const RegExpressions = data.jobs_by_pk.bodyshop.md_parts_scan.map(
|
||||
(r) => new RegExp(r.expression, r.flags)
|
||||
);
|
||||
|
||||
//Check each line against each regex rule.
|
||||
data.jobs_by_pk.joblines.forEach((jobline) => {
|
||||
RegExpressions.forEach((rExp) => {
|
||||
if (jobline.line_desc.match(rExp)) {
|
||||
IdsToMarkCritical.push(jobline);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const result = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.UPDATE_PARTS_CRITICAL, {
|
||||
IdsToMarkCritical: _.uniqBy(IdsToMarkCritical, "id").map((i) => i.id),
|
||||
jobid: jobid,
|
||||
});
|
||||
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
logger.log("job-parts-scan-error", "ERROR", req.user.email, jobid, {
|
||||
jobid,
|
||||
error,
|
||||
});
|
||||
res.status(400).json(JSON.stringify(error));
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user