Merge branch 'test' into feature/qbo

This commit is contained in:
Patrick Fic
2021-09-16 17:04:57 -07:00
26 changed files with 19061 additions and 610 deletions

View File

@@ -47,16 +47,40 @@ exports.default = async function (socket, jobid) {
},
};
//Determine if there are MAPA and MASH lines already on the estimate.
//If there are, don't do anything extra (mitchell estimate)
//Otherwise, calculate them and add them to the default MAPA and MASH centers.
let hasMapaLine = false;
let hasMashLine = false;
const profitCenterHash = job.joblines.reduce((acc, val) => {
//Check the Parts Assignment
if (val.db_ref === "936008") {
//If either of these DB REFs change, they also need to change in job-totals/job-costing calculations.
hasMapaLine = true;
}
if (val.db_ref === "936007") {
hasMashLine = true;
}
if (val.profitcenter_part) {
if (!acc[val.profitcenter_part]) acc[val.profitcenter_part] = Dinero();
acc[val.profitcenter_part] = acc[val.profitcenter_part].add(
Dinero({
amount: Math.round((val.act_price || 0) * 100),
}).multiply(val.part_qty || 0)
);
let DineroAmount = Dinero({
amount: Math.round(val.act_price * 100),
}).multiply(val.part_qty || 1);
if (val.prt_dsmk_p && val.prt_dsmk_p !== 0) {
// console.log("Have a part discount", val);
DineroAmount = DineroAmount.add(
DineroAmount.percentage(Math.abs(val.prt_dsmk_p || 0)).multiply(
val.prt_dsmk_p > 0 ? 1 : -1
)
);
}
acc[val.profitcenter_part] =
acc[val.profitcenter_part].add(DineroAmount);
}
if (val.profitcenter_labor) {
//Check the Labor Assignment.
@@ -79,7 +103,8 @@ exports.default = async function (socket, jobid) {
bill_val.billlines.map((line_val) => {
if (!bill_acc[line_val.cost_center])
bill_acc[line_val.cost_center] = Dinero();
const lineDinero = Dinero({
let lineDinero = Dinero({
amount: Math.round((line_val.actual_cost || 0) * 100),
})
.multiply(line_val.quantity)
@@ -87,32 +112,73 @@ exports.default = async function (socket, jobid) {
bill_acc[line_val.cost_center] =
bill_acc[line_val.cost_center].add(lineDinero);
//Add appropriate tax amounts.
const {
applicable_taxes: { local, state, federal },
} = line_val;
if (local) {
taxAllocations.local.cost = taxAllocations.local.cost.add(
lineDinero.percentage(bill_val.local_tax_rate || 0)
);
}
if (state) {
taxAllocations.state.cost = taxAllocations.state.cost.add(
lineDinero.percentage(bill_val.state_tax_rate || 0)
);
}
if (federal) {
taxAllocations.federal.cost = taxAllocations.federal.cost.add(
lineDinero.percentage(bill_val.federal_tax_rate || 0)
);
}
return null;
});
return bill_acc;
}, {});
job.timetickets.forEach((ticket) => {
//Get the total amount of the ticket.
let TicketTotal = Dinero({
amount: Math.round(
ticket.rate *
(ticket.employee && ticket.employee.flat_rate
? ticket.productivehrs || 0
: ticket.actualhrs || 0) *
100
),
});
//Add it to the right cost center.
if (!costCenterHash[ticket.cost_center])
costCenterHash[ticket.cost_center] = Dinero();
costCenterHash[ticket.cost_center] =
costCenterHash[ticket.cost_center].add(TicketTotal);
});
if (!hasMapaLine && job.job_totals.rates.mapa.total.amount > 0) {
// console.log("Adding MAPA Line Manually.");
const mapaAccountName =
bodyshop.md_responsibility_centers.defaults.profits.MAPA;
const mapaAccount = bodyshop.md_responsibility_centers.profits.find(
(c) => c.name === mapaAccountName
);
if (mapaAccount) {
if (!profitCenterHash[mapaAccountName])
profitCenterHash[mapaAccountName] = Dinero();
profitCenterHash[mapaAccountName] = profitCenterHash[
mapaAccountName
].add(Dinero(job.job_totals.rates.mapa.total));
} else {
//console.log("NO MAPA ACCOUNT FOUND!!");
}
}
if (!hasMashLine && job.job_totals.rates.mash.total.amount > 0) {
// console.log("Adding MASH Line Manually.");
const mashAccountName =
bodyshop.md_responsibility_centers.defaults.profits.MASH;
const mashAccount = bodyshop.md_responsibility_centers.profits.find(
(c) => c.name === mashAccountName
);
if (mashAccount) {
if (!profitCenterHash[mashAccountName])
profitCenterHash[mashAccountName] = Dinero();
profitCenterHash[mashAccountName] = profitCenterHash[
mashAccountName
].add(Dinero(job.job_totals.rates.mash.total));
} else {
// console.log("NO MASH ACCOUNT FOUND!!");
}
}
const jobAllocations = _.union(
Object.keys(profitCenterHash),
Object.keys(costCenterHash)
@@ -141,7 +207,9 @@ exports.default = async function (socket, jobid) {
taxAllocations[key].sale.getAmount() > 0 ||
taxAllocations[key].cost.getAmount() > 0
)
.map((key) => taxAllocations[key]),
.map((key) => {
return { ...taxAllocations[key], tax: key };
}),
];
} catch (error) {
CdkBase.createLogEvent(

View File

@@ -8,14 +8,11 @@ require("dotenv").config({
const GraphQLClient = require("graphql-request").GraphQLClient;
const soap = require("soap");
const queries = require("../graphql-client/queries");
const CdkBase = require("../web-sockets/web-socket");
const CdkWsdl = require("./cdk-wsdl").default;
const logger = require("../utils/logger");
const Dinero = require("dinero.js");
const _ = require("lodash");
const { CDK_CREDENTIALS, CheckCdkResponseForError } = require("./cdk-wsdl");
const { performance } = require("perf_hooks");
const apiGqlClient = require("../graphql-client/graphql-client").client;
// exports.default = async function (socket, cdk_dealerid) {
// try {
@@ -87,6 +84,7 @@ exports.default = async function ReloadCdkMakes(req, res) {
count: newList.length,
}
);
res.sendStatus(200);
} catch (error) {
logger.log(
"cdk-replace-makes-models-error",
@@ -98,6 +96,7 @@ exports.default = async function ReloadCdkMakes(req, res) {
error,
}
);
res.status(500).json(error);
}
};
@@ -108,7 +107,7 @@ async function GetCdkMakes(req, cdk_dealerid) {
try {
const soapClientVehicleInsert = await soap.createClientAsync(
CdkWsdl.VehicleInsert
CdkWsdl.VehicleInsertUpdate
);
const soapResponseVehicleSearch =

View File

@@ -11,6 +11,8 @@ const queries = require("../graphql-client/queries");
const CdkBase = require("../web-sockets/web-socket");
const CdkWsdl = require("./cdk-wsdl").default;
const { CDK_CREDENTIALS, CheckCdkResponseForError } = require("./cdk-wsdl");
const CalcualteAllocations = require("./cdk-calculate-allocations").default;
const moment = require("moment");
exports.default = async function (socket, { txEnvelope, jobid }) {
@@ -44,7 +46,7 @@ exports.default = async function (socket, { txEnvelope, jobid }) {
CdkBase.createLogEvent(
socket,
"DEBUG",
`{2.1} Querying the Vehicle using the DMSVid: ${socket.DMSVid}`
`{2.1} Querying the Vehicle using the DMSVid: ${socket.DMSVid.vehiclesVehId}`
);
socket.DMSVeh = await QueryDmsVehicleById(socket, JobData, socket.DMSVid);
@@ -73,7 +75,9 @@ exports.default = async function (socket, { txEnvelope, jobid }) {
socket.DMSCustList = await QueryDmsCustomerByName(socket, JobData);
socket.emit("cdk-select-customer", [
...(socket.DMSVehCustomer ? [socket.DMSVehCustomer] : []),
...(socket.DMSVehCustomer
? [{ ...socket.DMSVehCustomer, vinOwner: true }]
: []),
...socket.DMSCustList,
]);
} catch (error) {
@@ -82,14 +86,6 @@ exports.default = async function (socket, { txEnvelope, jobid }) {
"ERROR",
`Error encountered in CdkJobExport. ${error}`
);
} finally {
//Ensure we always insert logEvents
//GQL to insert logevents.
CdkBase.createLogEvent(
socket,
"DEBUG",
`Capturing log events to database.`
);
}
};
@@ -146,18 +142,80 @@ async function CdkSelectedCustomer(socket, selectedCustomerId) {
);
socket.DMSVeh = await UpdateDmsVehicle(socket);
}
CdkBase.createLogEvent(
socket,
"DEBUG",
`{5}Updating Service Vehicle History.`
`{5} Creating Transaction header with Dms Start WIP`
);
await InsertServiceVehicleHistory(socket);
socket.DMSTransHeader = await InsertDmsStartWip(socket);
CdkBase.createLogEvent(
socket,
"DEBUG",
`{5.1} Creating Transaction with ID ${socket.DMSTransHeader.transID}`
);
socket.DMSBatchTxn = await InsertDmsBatchWip(socket);
CdkBase.createLogEvent(
socket,
"DEBUG",
`{6} Attempting to post Transaction with ID ${socket.DMSTransHeader.transID}`
);
socket.DmsBatchTxnPost = await PostDmsBatchWip(socket);
if (socket.DmsBatchTxnPost.code === "success") {
//something
CdkBase.createLogEvent(
socket,
"DEBUG",
`{6} Successfully posted sransaction to DMS.`
);
await MarkJobExported(socket, socket.JobData.id);
CdkBase.createLogEvent(
socket,
"DEBUG",
`{5} Updating Service Vehicle History. ***SKIPPING FOR NOW TO PRESERVE RO NUMBERS ***`
);
//socket.DMSVehHistory = await InsertServiceVehicleHistory(socket);
socket.emit("export-success", socket.JobData.id);
} else {
//Get the error code
CdkBase.createLogEvent(
socket,
"DEBUG",
`{6.1} Getting errors for Transaction ID ${socket.DMSTransHeader.transID}`
);
socket.DmsError = await QueryDmsErrWip(socket);
//Delete the transaction
CdkBase.createLogEvent(
socket,
"DEBUG",
`{6.2} Deleting Transaction ID ${socket.DMSTransHeader.transID}`
);
socket.DmsBatchTxnPost = await DeleteDmsWip(socket);
//Emit the error in a nice way .
socket.DmsError.errMsg
.split("|")
.map(
(e) =>
e !== null &&
e !== "" &&
CdkBase.createLogEvent(
socket,
"ERROR",
`Error(s) encountered in posting transaction. ${e}`
)
);
}
} catch (error) {
CdkBase.createLogEvent(
socket,
"ERROR",
`Error encountered in CdkSelectedCustomer. ${error}`
);
await InsertFailedExportLog(socket, error);
} finally {
//Ensure we always insert logEvents
//GQL to insert logevents.
@@ -509,7 +567,7 @@ async function InsertDmsCustomer(socket, newCustomerNumber) {
await soapClientCustomerInsertUpdate.insertAsync(
{
arg0: CDK_CREDENTIALS,
arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid },
arg2: { userId: null },
arg3: {
//Copied the required fields from the other integration.
@@ -519,7 +577,12 @@ async function InsertDmsCustomer(socket, newCustomerNumber) {
addressLine: socket.JobData.ownr_addr1,
city: socket.JobData.ownr_city,
country: null,
postalCode: socket.JobData.ownr_zip,
postalCode:
socket.JobData.ownr_zip &&
socket.JobData.ownr_zip //TODO Need to remove for US Based customers.
.toUpperCase()
.replace(/\W/g, "")
.replace(/(...)/, "$1 "),
stateOrProvince: socket.JobData.ownr_st,
},
contactInfo: {
@@ -527,6 +590,10 @@ async function InsertDmsCustomer(socket, newCustomerNumber) {
main: true,
value: socket.JobData.ownr_ph1,
},
email: {
desc: socket.JobData.ownr_ea ? "Other" : "CustomerDeclined",
value: socket.JobData.ownr_ea ? "Other" : null,
},
},
demographics: null,
name1: {
@@ -539,6 +606,10 @@ async function InsertDmsCustomer(socket, newCustomerNumber) {
suffix: null,
title: null,
},
//TODO - REMOVE THIS AFTER TESTING.
...(process.env.NODE_ENV !== "production"
? { arStatus: { dealerField1: "Testing" } }
: {}),
},
},
@@ -751,7 +822,7 @@ async function InsertServiceVehicleHistory(socket) {
closeDate: moment(socket.JobData.invoice_date).format("YYYY-MM-DD"),
closeTime: moment(socket.JobData.invoice_date).format("HH:MM:SS"),
comments: socket.txEnvelope.story,
cashierID: socket.JobData.bodyshop.cdk_configuration.cashierid, //NEEDS TO BE PROVIDED BY DEALER.
cashierID: socket.JobData.bodyshop.cdk_configuration.cashierid,
},
});
@@ -779,8 +850,7 @@ async function InsertServiceVehicleHistory(socket) {
`soapClientServiceHistoryInsert.serviceHistoryHeaderInsert response.`
);
CheckCdkResponseForError(socket, soapResponseServiceHistoryInsert);
const VehicleFromDMS = result && result.return && result.return.vehicle;
return VehicleFromDMS;
return result && result.return;
} catch (error) {
CdkBase.createLogEvent(
socket,
@@ -797,19 +867,20 @@ async function InsertDmsStartWip(socket) {
);
const soapResponseAccountingGLInsertUpdate =
await soapClientAccountingGLInsertUpdate.startWIPAsync({
await soapClientAccountingGLInsertUpdate.doStartWIPAsync({
arg0: CDK_CREDENTIALS,
arg1: { id: socket.JobData.bodyshop.cdk_dealerid },
arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid },
arg2: {
acctgDate: moment().toISOString(),
acctgDate: moment().format("YYYY-MM-DD"),
//socket.JobData.invoice_date
desc: socket.txEnvelope.story,
docType: 7 || 10, //Need to check what this usually would be?
docType: 10 || 7, //Need to check what this usually would be? Apparently it is almost always 10 or 7.
//1 Cash Receipt , 2 Check, 3 Journal Voucher, 4 Parts invoice, 5 Payable Invoice, 6 Recurring Entry, 7 Repair Order Invoice, 8 Vehicle Purchase Invoice, 9 Vehicle Sale Invoice, 10 Other, 11 Payroll, 12 Finance Charge, 13 FMLR Invoice, 14 Parts Credit Memo, 15 Manufacturer Document, 16 FMLR Credit Memo
m13Flag: 0,
refer: socket.JobData.ro_number,
srcCo: socket.txEnvelope.journal,
srcCo: socket.JobData.bodyshop.cdk_configuration.srcco,
srcJrnl: socket.txEnvelope.journal,
userID: "?", //Where is this coming from?
userID: socket.JobData.bodyshop.cdk_configuration.cashierid, //Where is this coming from?
//userName: "IMEX",
},
});
@@ -820,13 +891,13 @@ async function InsertDmsStartWip(socket) {
CdkBase.createXmlEvent(
socket,
rawRequest,
`soapClientAccountingGLInsertUpdate.startWIPAsync request.`
`soapClientAccountingGLInsertUpdate.doStartWIPAsync request.`
);
CdkBase.createLogEvent(
socket,
"TRACE",
`soapClientAccountingGLInsertUpdate.startWIPAsync Result ${JSON.stringify(
`soapClientAccountingGLInsertUpdate.doStartWIPAsync Result ${JSON.stringify(
result,
null,
2
@@ -835,17 +906,383 @@ async function InsertDmsStartWip(socket) {
CdkBase.createXmlEvent(
socket,
rawResponse,
`soapClientAccountingGLInsertUpdate.startWIPAsync response.`
`soapClientAccountingGLInsertUpdate.doStartWIPAsync response.`
);
CheckCdkResponseForError(socket, soapResponseAccountingGLInsertUpdate);
const VehicleFromDMS = result && result.return && result.return.vehicle;
return VehicleFromDMS;
const TransactionHeader = result && result.return;
return TransactionHeader;
} catch (error) {
CdkBase.createLogEvent(
socket,
"ERROR",
`Error in QueryDmsVehicleById - ${error}`
`Error in InsertDmsStartWip - ${error}`
);
throw new Error(error);
}
}
async function InsertDmsBatchWip(socket) {
try {
const soapClientAccountingGLInsertUpdate = await soap.createClientAsync(
CdkWsdl.AccountingGLInsertUpdate
);
const soapResponseAccountingGLInsertUpdate =
await soapClientAccountingGLInsertUpdate.doTransBatchWIPAsync({
arg0: CDK_CREDENTIALS,
arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid },
arg2: {
transWIPs: await GenerateTransWips(socket),
},
});
const [result, rawResponse, , rawRequest] =
soapResponseAccountingGLInsertUpdate;
CdkBase.createXmlEvent(
socket,
rawRequest,
`soapClientAccountingGLInsertUpdate.doTransBatchWIPAsync request.`
);
CdkBase.createLogEvent(
socket,
"TRACE",
`soapClientAccountingGLInsertUpdate.doTransBatchWIPAsync Result ${JSON.stringify(
result,
null,
2
)}`
);
CdkBase.createXmlEvent(
socket,
rawResponse,
`soapClientAccountingGLInsertUpdate.doTransBatchWIPAsync response.`
);
CheckCdkResponseForError(socket, soapResponseAccountingGLInsertUpdate);
const BatchWipResult = result && result.return;
return BatchWipResult;
} catch (error) {
CdkBase.createLogEvent(
socket,
"ERROR",
`Error in InsertDmsBatchWip - ${error}`
);
throw new Error(error);
}
}
async function GenerateTransWips(socket) {
const allocations = await CalcualteAllocations(socket, socket.JobData.id);
const wips = [];
allocations.forEach((alloc) => {
//Add the sale item from each allocation.
if (alloc.sale.getAmount() > 0 && !alloc.tax) {
const item = {
acct: alloc.profitCenter.dms_acctnumber,
cntl: socket.JobData.ro_number,
cntl2: null,
credtMemoNo: null,
postAmt: alloc.sale.multiply(-1).getAmount(),
postDesc: null,
prod: null,
statCnt: 1,
transID: socket.DMSTransHeader.transID,
trgtCoID: socket.JobData.bodyshop.cdk_configuration.srcco,
};
wips.push(item);
}
//Add the cost Item.
if (alloc.cost.getAmount() > 0 && !alloc.tax) {
const item = {
acct: alloc.costCenter.dms_acctnumber,
cntl: socket.JobData.ro_number,
cntl2: null,
credtMemoNo: null,
postAmt: alloc.cost.getAmount(),
postDesc: null,
prod: null,
statCnt: 1,
transID: socket.DMSTransHeader.transID,
trgtCoID: socket.JobData.bodyshop.cdk_configuration.srcco,
};
wips.push(item);
const itemWip = {
acct: alloc.costCenter.dms_wip_acctnumber,
cntl: socket.JobData.ro_number,
cntl2: null,
credtMemoNo: null,
postAmt: alloc.cost.multiply(-1).getAmount(),
postDesc: null,
prod: null,
statCnt: 1,
transID: socket.DMSTransHeader.transID,
trgtCoID: socket.JobData.bodyshop.cdk_configuration.srcco,
};
wips.push(itemWip);
//Add to the WIP account.
}
if (alloc.tax) {
// if (alloc.cost.getAmount() > 0) {
// const item = {
// acct: alloc.costCenter.dms_acctnumber,
// cntl: socket.JobData.ro_number,
// cntl2: null,
// credtMemoNo: null,
// postAmt: alloc.cost.getAmount(),
// postDesc: null,
// prod: null,
// statCnt: 1,
// transID: socket.DMSTransHeader.transID,
// trgtCoID: socket.JobData.bodyshop.cdk_configuration.srcco,
// };
// wips.push(item);
// }
if (alloc.sale.getAmount() > 0) {
const item2 = {
acct: alloc.profitCenter.dms_acctnumber,
cntl: socket.JobData.ro_number,
cntl2: null,
credtMemoNo: null,
postAmt: alloc.sale.multiply(-1).getAmount(),
postDesc: null,
prod: null,
statCnt: 1,
transID: socket.DMSTransHeader.transID,
trgtCoID: socket.JobData.bodyshop.cdk_configuration.srcco,
};
wips.push(item2);
}
}
});
socket.txEnvelope.payers.forEach((payer) => {
const item = {
acct: payer.dms_acctnumber,
cntl: payer.controlnumber,
cntl2: null,
credtMemoNo: null,
postAmt: Math.round(payer.amount * 100),
postDesc: null,
prod: null,
statCnt: 1,
transID: socket.DMSTransHeader.transID,
trgtCoID: socket.JobData.bodyshop.cdk_configuration.srcco,
};
wips.push(item);
});
//should validate that the wips = 0
console.log(
"WIPS TOTAL",
wips.reduce((acc, val) => {
console.log(val);
console.log(acc + val.postAmt);
return acc + val.postAmt;
}, 0)
);
return wips;
}
async function PostDmsBatchWip(socket) {
try {
const soapClientAccountingGLInsertUpdate = await soap.createClientAsync(
CdkWsdl.AccountingGLInsertUpdate
);
const soapResponseAccountingGLInsertUpdate =
await soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync({
arg0: CDK_CREDENTIALS,
arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid },
arg2: {
postWIP: { opCode: "P", transID: socket.DMSTransHeader.transID },
},
});
const [result, rawResponse, , rawRequest] =
soapResponseAccountingGLInsertUpdate;
CdkBase.createXmlEvent(
socket,
rawRequest,
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync request.`
);
CdkBase.createLogEvent(
socket,
"TRACE",
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync Result ${JSON.stringify(
result,
null,
2
)}`
);
CdkBase.createXmlEvent(
socket,
rawResponse,
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync response.`
);
// CheckCdkResponseForError(socket, soapResponseAccountingGLInsertUpdate);
const PostResult = result && result.return;
return PostResult;
} catch (error) {
CdkBase.createLogEvent(
socket,
"ERROR",
`Error in PostDmsBatchWip - ${error}`
);
throw new Error(error);
}
}
async function QueryDmsErrWip(socket) {
try {
const soapClientAccountingGLInsertUpdate = await soap.createClientAsync(
CdkWsdl.AccountingGLInsertUpdate
);
const soapResponseAccountingGLInsertUpdate =
await soapClientAccountingGLInsertUpdate.doErrWIPAsync({
arg0: CDK_CREDENTIALS,
arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid },
arg2: socket.DMSTransHeader.transID,
});
const [result, rawResponse, , rawRequest] =
soapResponseAccountingGLInsertUpdate;
CdkBase.createXmlEvent(
socket,
rawRequest,
`soapClientAccountingGLInsertUpdate.doErrWIPAsync request.`
);
CdkBase.createLogEvent(
socket,
"TRACE",
`soapClientAccountingGLInsertUpdate.doErrWIPAsync Result ${JSON.stringify(
result,
null,
2
)}`
);
CdkBase.createXmlEvent(
socket,
rawResponse,
`soapClientAccountingGLInsertUpdate.doErrWIPAsync response.`
);
CheckCdkResponseForError(socket, soapResponseAccountingGLInsertUpdate);
const PostResult = result && result.return;
return PostResult;
} catch (error) {
CdkBase.createLogEvent(
socket,
"ERROR",
`Error in QueryDmsErrWip - ${error}`
);
throw new Error(error);
}
}
async function DeleteDmsWip(socket) {
try {
const soapClientAccountingGLInsertUpdate = await soap.createClientAsync(
CdkWsdl.AccountingGLInsertUpdate
);
const soapResponseAccountingGLInsertUpdate =
await soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync({
arg0: CDK_CREDENTIALS,
arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid },
arg2: {
postWIP: { opCode: "D", transID: socket.DMSTransHeader.transID },
},
});
const [result, rawResponse, , rawRequest] =
soapResponseAccountingGLInsertUpdate;
CdkBase.createXmlEvent(
socket,
rawRequest,
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync request.`
);
CdkBase.createLogEvent(
socket,
"TRACE",
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync Result ${JSON.stringify(
result,
null,
2
)}`
);
CdkBase.createXmlEvent(
socket,
rawResponse,
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync response.`
);
CheckCdkResponseForError(socket, soapResponseAccountingGLInsertUpdate);
const PostResult = result && result.return;
return PostResult;
} catch (error) {
CdkBase.createLogEvent(
socket,
"ERROR",
`Error in PostDmsBatchWip - ${error}`
);
throw new Error(error);
}
}
async function MarkJobExported(socket, jobid) {
CdkBase.createLogEvent(
socket,
"DEBUG",
`Marking job as exported for id ${jobid}`
);
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {});
const result = await client
.setHeaders({ Authorization: `Bearer ${socket.handshake.auth.token}` })
.request(queries.MARK_JOB_EXPORTED, {
jobId: jobid,
job: {
status:
socket.JobData.bodyshop.md_ro_statuses.default_exported ||
"Exported*",
date_exported: new Date(),
},
log: {
bodyshopid: socket.JobData.bodyshop.id,
jobid: jobid,
successful: true,
useremail: socket.user.email,
},
});
return result;
}
async function InsertFailedExportLog(socket, error) {
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {});
const result = await client
.setHeaders({ Authorization: `Bearer ${socket.handshake.auth.token}` })
.request(queries.INSERT_EXPORT_LOG, {
log: {
bodyshopid: socket.JobData.bodyshop.id,
jobid: socket.JobData.id,
successful: false,
message: [error],
useremail: socket.user.email,
},
});
return result;
}

View File

@@ -78,6 +78,7 @@ exports.checkIndividualResult = checkIndividualResult;
const cdkDomain = "https://uat-3pa.dmotorworks.com";
exports.default = {
// VehicleSearch: `${cdkDomain}/pip-vehicle/services/VehicleSearch?wsdl`,
HelpDataBase: `${cdkDomain}/pip-help-database-location/services/HelpDatabaseLocation?wsdl`,
AccountingGLInsertUpdate: `${cdkDomain}/pip-accounting-gl/services/AccountingGLInsertUpdate?wsdl`,
VehicleInsertUpdate: `${cdkDomain}/pip-vehicle/services/VehicleInsertUpdate?wsdl`,
CustomerInsertUpdate: `${cdkDomain}/pip-customer/services/CustomerInsertUpdate?wsdl`,

View File

@@ -140,6 +140,7 @@ query QUERY_JOBS_FOR_CDK_EXPORT($id: uuid!) {
ownr_zip
ownr_city
ownr_st
ownr_ea
ins_co_nm
job_totals
rate_la1
@@ -177,9 +178,11 @@ query QUERY_JOBS_FOR_CDK_EXPORT($id: uuid!) {
ca_customer_gst
bodyshop {
id
md_ro_statuses
md_responsibility_centers
accountingconfig
cdk_dealerid
cdk_configuration
}
owner {
accountingid
@@ -951,106 +954,117 @@ affected_rows
`;
exports.GET_CDK_ALLOCATIONS = `
query QUERY_JOB_CLOSE_DETAILS($id: uuid!) {
jobs_by_pk(id: $id) {
bodyshop{
id
md_responsibility_centers
}
ro_number
invoice_allocation
ins_co_id
exports.GET_CDK_ALLOCATIONS = `query QUERY_JOB_CLOSE_DETAILS($id: uuid!) {
jobs_by_pk(id: $id) {
bodyshop {
id
ded_amt
ded_status
depreciation_taxes
other_amount_payable
towing_payable
storage_payable
adjustment_bottom_line
federal_tax_rate
state_tax_rate
local_tax_rate
tax_tow_rt
tax_str_rt
tax_paint_mat_rt
tax_sub_rt
tax_lbr_rt
tax_levies_rt
parts_tax_rates
job_totals
rate_la1
rate_la2
rate_la3
rate_la4
rate_laa
rate_lab
rate_lad
rate_lae
rate_laf
rate_lag
rate_lam
rate_lar
rate_las
rate_lau
rate_ma2s
rate_ma2t
rate_ma3s
rate_mabl
rate_macs
rate_mahw
rate_mapa
rate_mash
rate_matd
status
date_exported
date_invoiced
voided
scheduled_completion
actual_completion
scheduled_delivery
actual_delivery
scheduled_in
actual_in
bills {
id
federal_tax_rate
local_tax_rate
state_tax_rate
is_credit_memo
billlines {
actual_cost
cost_center
id
quantity
applicable_taxes
}
}
joblines(where: { removed: { _eq: false } }) {
id
removed
tax_part
line_desc
prt_dsmk_p
prt_dsmk_m
part_type
oem_partno
db_price
act_price
part_qty
mod_lbr_ty
db_hrs
mod_lb_hrs
lbr_op
lbr_amt
op_code_desc
profitcenter_labor
profitcenter_part
prt_dsmk_p
md_responsibility_centers
cdk_configuration
}
ro_number
invoice_allocation
ins_co_id
id
ded_amt
ded_status
depreciation_taxes
other_amount_payable
towing_payable
storage_payable
adjustment_bottom_line
federal_tax_rate
state_tax_rate
local_tax_rate
tax_tow_rt
tax_str_rt
tax_paint_mat_rt
tax_sub_rt
tax_lbr_rt
tax_levies_rt
parts_tax_rates
job_totals
rate_la1
rate_la2
rate_la3
rate_la4
rate_laa
rate_lab
rate_lad
rate_lae
rate_laf
rate_lag
rate_lam
rate_lar
rate_las
rate_lau
rate_ma2s
rate_ma2t
rate_ma3s
rate_mabl
rate_macs
rate_mahw
rate_mapa
rate_mash
rate_matd
status
date_exported
date_invoiced
voided
scheduled_completion
actual_completion
scheduled_delivery
actual_delivery
scheduled_in
actual_in
timetickets {
id
actualhrs
cost_center
productivehrs
rate
employee {
flat_rate
}
}
bills(where: {isinhouse: {_eq: false}}) {
id
federal_tax_rate
local_tax_rate
state_tax_rate
is_credit_memo
billlines {
actual_cost
cost_center
id
quantity
applicable_taxes
}
}
joblines(where: {removed: {_eq: false}}) {
id
removed
tax_part
line_desc
prt_dsmk_p
prt_dsmk_m
part_type
oem_partno
db_price
db_ref
act_price
part_qty
mod_lbr_ty
db_hrs
mod_lb_hrs
lbr_op
lbr_amt
op_code_desc
profitcenter_labor
profitcenter_part
prt_dsmk_p
}
}
}
`;
exports.GET_QBO_AUTH = `query GET_QBO_AUTH($email: String!) {
@@ -1066,3 +1080,29 @@ exports.SET_QBO_AUTH = `mutation SET_QBO_AUTH($email: String!, $qbo_auth: jsonb!
}
}
`;
exports.MARK_JOB_EXPORTED = `
mutation MARK_JOB_EXPORTED($jobId: uuid!, $job: jobs_set_input!, $log: exportlog_insert_input!) {
update_jobs(where: {id: {_eq: $jobId}}, _set: $job) {
returning {
id
date_exported
status
alt_transport
ro_number
production_vars
lbr_adjustments
}
}
insert_exportlog_one(object: $log) {
id
}
}
`;
exports.INSERT_EXPORT_LOG = `
mutation INSERT_EXPORT_LOG($log: exportlog_insert_input!) {
insert_exportlog_one(object: $log) {
id
}
}
`;

View File

@@ -50,7 +50,11 @@ io.on("connection", (socket) => {
socket.on("set-log-level", (level) => {
socket.log_level = level;
createLogEvent(socket, "DEBUG", `Updated log level to ${level}`);
socket.emit("log-event", {
timestamp: new Date(),
level: "INFO",
message: `Updated log level to ${level}`,
});
});
socket.on("cdk-export-job", (jobid) => {