Additional WIP Fortellis.

This commit is contained in:
Patrick Fic
2025-09-11 08:45:34 -07:00
parent 1728982b2b
commit 661678eb1c
3 changed files with 92 additions and 100 deletions

View File

@@ -87,7 +87,7 @@ async function FetchSubscriptions({ redisHelpers, socket, jobid }) {
return SubscriptionMeta;
}
} catch (error) {
CreateFortellisLogEvent(socket, "ERROR", `Error fetching subscription metadata`, {
CreateFortellisLogEvent(socket, "ERROR", `Error fetching subscription metadata.`, {
error: error.message,
stack: error.stack
});
@@ -315,22 +315,22 @@ const FortellisActions = {
url: isProduction
? "https://api.fortellis.io/cdk/drive/glpost/startWIP"
: "https://api.fortellis.io/cdk-test/drive/glpost/startWIP",
type: "put",
apiName: "CDK Drive Post Accounting GL",
type: "post",
apiName: "CDK Drive Post Accounts GL WIP",
},
TranBatchWip: {
url: isProduction
? "https://api.fortellis.io/cdk/drive/glpost/transBatchWIP"
: "https://api.fortellis.io/cdk-test/drive/glpost/transBatchWIP",
type: "put",
apiName: "CDK Drive Post Accounting GL",
type: "post",
apiName: "CDK Drive Post Accounts GL WIP",
},
PostBatchWip: {
url: isProduction
? "https://api.fortellis.io/cdk/drive/glpost/transBatchWIP"
? "https://api.fortellis.io/cdk/drive/glpost/postBatchWIP"
: "https://api.fortellis.io/cdk-test/drive/glpost/postBatchWIP",
type: "put",
apiName: "CDK Drive Post Accounting GL",
type: "post",
apiName: "CDK Drive Post Accounts GL WIP",
},
};

View File

@@ -95,23 +95,24 @@ async function FortellisJobExport({
async function FortellisSelectedCustomer({ socket, redisHelpers, ioHelpers, selectedCustomerId, jobid }) {
try {
const {
// setSessionData,
// getSessionData,
// addUserSocketMapping,
// removeUserSocketMapping,
// refreshUserSocketTTL,
// getUserSocketMappingByBodyshop,
setSessionTransactionData,
getSessionTransactionData,
//clearSessionTransactionData
} = redisHelpers;
await setSessionTransactionData(socket.id, getTransactionType(jobid), FortellisCacheEnums.selectedCustomerId, selectedCustomerId, defaultFortellisTTL);
const JobData = await getSessionTransactionData(socket.id, getTransactionType(jobid), FortellisCacheEnums.JobData);
const txEnvelope = await getSessionTransactionData(socket.id, getTransactionType(jobid), FortellisCacheEnums.txEnvelope);
const DMSVid = await redisHelpers.getSessionTransactionData(socket.id, getTransactionType(JobData.id), FortellisCacheEnums.DMSVid);
const {
// setSessionData,
// getSessionData,
// addUserSocketMapping,
// removeUserSocketMapping,
// refreshUserSocketTTL,
// getUserSocketMappingByBodyshop,
setSessionTransactionData,
getSessionTransactionData,
//clearSessionTransactionData
} = redisHelpers;
await setSessionTransactionData(socket.id, getTransactionType(jobid), FortellisCacheEnums.selectedCustomerId, selectedCustomerId, defaultFortellisTTL);
const JobData = await getSessionTransactionData(socket.id, getTransactionType(jobid), FortellisCacheEnums.JobData);
const txEnvelope = await getSessionTransactionData(socket.id, getTransactionType(jobid), FortellisCacheEnums.txEnvelope);
const DMSVid = await redisHelpers.getSessionTransactionData(socket.id, getTransactionType(JobData.id), FortellisCacheEnums.DMSVid);
try {
let DMSCust;
@@ -181,7 +182,7 @@ async function FortellisSelectedCustomer({ socket, redisHelpers, ioHelpers, sele
CreateFortellisLogEvent(
socket,
"DEBUG",
`{6} Attempting to post Transaction with ID ${socket.DMSTransHeader.transID}`
`{6} Attempting to post Transaction with ID ${DMSTransHeader.transID}`
);
const DmsBatchTxnPost = await PostDmsBatchWip({ socket, redisHelpers, JobData });
@@ -191,17 +192,17 @@ async function FortellisSelectedCustomer({ socket, redisHelpers, ioHelpers, sele
//something
CreateFortellisLogEvent(socket, "DEBUG", `{6} Successfully posted sransaction to DMS.`);
await MarkJobExported(socket, socket.JobData.id);
await MarkJobExported({ socket, jobid: JobData.id });
CreateFortellisLogEvent(socket, "DEBUG", `{5} Updating Service Vehicle History.`);
socket.DMSVehHistory = await InsertServiceVehicleHistory(socket);
socket.emit("export-success", socket.JobData.id);
socket.emit("export-success", JobData.id);
} else {
//Get the error code
CreateFortellisLogEvent(
socket,
"DEBUG",
`{6.1} Getting errors for Transaction ID ${socket.DMSTransHeader.transID}`
`{6.1} Getting errors for Transaction ID ${DMSTransHeader.transID}`
);
// socket.DmsError = await QueryDmsErrWip(socket);
// //Delete the transaction
@@ -219,7 +220,11 @@ async function FortellisSelectedCustomer({ socket, redisHelpers, ioHelpers, sele
}
} catch (error) {
// CdkBase.createLogEvent(socket, "ERROR", `Error encountered in CdkSelectedCustomer. ${error}`);
// await InsertFailedExportLog(socket, error);
CreateFortellisLogEvent(socket, "ERROR", `Error in FortellisSelectedCustomer - ${error}`, {
error: error.message,
stack: error.stack
});
await InsertFailedExportLog({ socket, JobData, error });
} finally {
//Ensure we always insert logEvents
//GQL to insert logevents.
@@ -872,7 +877,7 @@ async function UpdateDmsVehicle({ socket, redisHelpers, JobData, DMSVeh, DMSCust
...DMSVehToSend,
dealer: {
...DMSVehToSend.dealer, //TODO: Check why company is blank on a queried record.
comapny: "77",
company: "77",
...((txEnvelope.inservicedate || DMSVehToSend.dealer.inServiceDate) && {
inServiceDate:
txEnvelope.dms_unsold === true
@@ -1095,6 +1100,8 @@ async function UpdateDmsVehicle({ socket, redisHelpers, JobData, DMSVeh, DMSCust
async function InsertDmsStartWip({ socket, redisHelpers, JobData }) {
try {
const txEnvelope = await redisHelpers.getSessionTransactionData(socket.id, getTransactionType(JobData.id), FortellisCacheEnums.txEnvelope);
const result = await MakeFortellisCall({
...FortellisActions.StartWip,
headers: {},
@@ -1102,18 +1109,18 @@ async function InsertDmsStartWip({ socket, redisHelpers, JobData }) {
socket,
jobid: JobData.id,
body: {
"acctgDate": moment().tz(socket.JobData.bodyshop.timezone).format("YYYY-MM-DD"),
"desc": socket.txEnvelope.story && socket.txEnvelope.story.replace(replaceSpecialRegex, ""),
"acctgDate": moment().tz(JobData.bodyshop.timezone).format("YYYY-MM-DD"),
"desc": txEnvelope.story && txEnvelope.story.replace(replaceSpecialRegex, ""),
"docType": "10",
"m13Flag": "0",
"refer": socket.JobData.ro_number,
"refer": JobData.ro_number,
// "rtnCode": "",
// "sendline": "",
// "groupName": "",
"srcCo": socket.JobData.bodyshop.cdk_configuration.srcco,
"srcJrnl": socket.txEnvelope.journal,
"srcCo": JobData.bodyshop.cdk_configuration.srcco,
"srcJrnl": txEnvelope.journal,
"transID": "",
"userID": socket.JobData.bodyshop.cdk_configuration.cashierid,
"userID": JobData.bodyshop.cdk_configuration.cashierid,
"userName": "BSMS"
},
@@ -1136,7 +1143,7 @@ async function InsertDmsBatchWip({ socket, redisHelpers, JobData }) {
});
return result;
} catch (error) {
CreateFortellisLogEvent(socket, "ERROR", `Error in InsertDmsBatchWip - ${error}`, { request: error.request });
CreateFortellisLogEvent(socket, "ERROR", `Error in InsertDmsBatchWip - ${error}`, { request: error.request, stack: error.stack });
}
}
@@ -1172,7 +1179,7 @@ async function InsertDmsBatchWip({ socket, redisHelpers, JobData }) {
// }
async function GenerateTransWips({ socket, redisHelpers, JobData }) {
const allocations = await CalculateAllocations(socket, socket.JobData.id, true); //3rd prop sets fortellis to true to maintain logging.
const allocations = await CalculateAllocations(socket, JobData.id, true); //3rd prop sets fortellis to true to maintain logging.
const wips = [];
const DMSTransHeader = await redisHelpers.getSessionTransactionData(socket.id, getTransactionType(JobData.id), FortellisCacheEnums.DMSTransHeader);
@@ -1245,22 +1252,6 @@ async function GenerateTransWips({ socket, redisHelpers, JobData }) {
}
if (alloc.tax) {
// if (alloc.cost.getAmount() > 0) {
// const item = {
// acct: alloc.costCenter.dms_acctnumber,
// cntl: JobData.ro_number,
// cntl2: null,
// credtMemoNo: null,
// postAmt: alloc.cost.getAmount(),
// postDesc: null,
// prod: null,
// statCnt: 1,
// transID: DMSTransHeader.transID,
// trgtCoID: JobData.bodyshop.cdk_configuration.srcco,
// };
// wips.push(item);
// }
if (alloc.sale.getAmount() > 0) {
const item2 = {
@@ -1421,53 +1412,54 @@ async function PostDmsBatchWip({ socket, redisHelpers, JobData }) {
// }
// }
// 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,
// metadata: socket.transWips
// },
// bill: {
// exported: true,
// exported_at: new Date()
// }
// });
async function MarkJobExported({ socket, jobid }) {
// return result;
// }
CreateFortellisLogEvent(socket, "ERROR", `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,
metadata: socket.transWips
},
bill: {
exported: true,
exported_at: new Date()
}
});
// async function InsertFailedExportLog(socket, error) {
// try {
// 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: JSON.stringify(error),
// useremail: socket.user.email
// }
// });
return result;
}
// return result;
// } catch (error2) {
// CdkBase.createLogEvent(socket, "ERROR", `Error in InsertFailedExportLog - ${error} - ${JSON.stringify(error2)}`);
// }
// }
async function InsertFailedExportLog({ socket, JobData, error }) {
try {
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: JobData.bodyshop.id,
jobid: JobData.id,
successful: false,
message: JSON.stringify(error),
useremail: socket.user.email
}
});
return result;
} catch (error2) {
CreateFortellisLogEvent(socket, "ERROR", `Error in InsertFailedExportLog - ${error}`, { message: error2.message, stack: error2.stack });
}
}
exports.getTransactionType = getTransactionType;
exports.FortellisJobExport = FortellisJobExport;