diff --git a/server/cdk/cdk-calculate-allocations.js b/server/cdk/cdk-calculate-allocations.js index c8de282db..4fca0fe9b 100644 --- a/server/cdk/cdk-calculate-allocations.js +++ b/server/cdk/cdk-calculate-allocations.js @@ -21,6 +21,7 @@ exports.defaultRoute = async function (req, res) { } catch (error) { ////console.log(error); WsLogger.createLogEvent(req, "ERROR", `Error encountered in CdkCalculateAllocations. ${error}`); + WsLogger.createLogEvent(req, "ERROR", `Error encountered in CdkCalculateAllocations. ${error.stack}`); res.status(500).json({ error: `Error encountered in CdkCalculateAllocations. ${error}` }); } }; @@ -33,6 +34,7 @@ exports.default = async function (socket, jobid, isFortellis = false) { ////console.log(error); const loggingFunction = isFortellis ? CreateFortellisLogEvent : WsLogger.createLogEvent; loggingFunction(socket, "ERROR", `Error encountered in CdkCalculateAllocations. ${error}`); + loggingFunction(socket, "ERROR", `Error encountered in CdkCalculateAllocations. ${error.stack}`); } }; diff --git a/server/fortellis/fortellis-helpers.js b/server/fortellis/fortellis-helpers.js index 56d100d2f..3a46ab484 100644 --- a/server/fortellis/fortellis-helpers.js +++ b/server/fortellis/fortellis-helpers.js @@ -110,7 +110,7 @@ async function FetchSubscriptions({ redisHelpers, socket, jobid, SubscriptionObj } } -async function GetDepartmentId({ apiName, debug = false, SubscriptionMeta }) { +async function GetDepartmentId({ apiName, debug = false, SubscriptionMeta, overrideDepartmentId }) { if (!apiName) throw new Error("apiName not provided. Unable to get department without apiName."); if (debug) { console.log("API Names & Departments "); @@ -122,7 +122,12 @@ async function GetDepartmentId({ apiName, debug = false, SubscriptionMeta }) { const departmentIds2 = SubscriptionMeta.apiDmsInfo //Get the subscription object. .find((info) => info.name === apiName)?.departments; //Departments are categorized by API name and have an array of departments. - return departmentIds2 && departmentIds2[0] && departmentIds2[0].id; //TODO: This makes the assumption that there is only 1 department. + if (overrideDepartmentId) { + return departmentIds2 && departmentIds2.find(d => d.id === overrideDepartmentId)?.id //TODO: This makes the assumption that there is only 1 department. + } else { + + return departmentIds2 && departmentIds2[0] && departmentIds2[0].id; //TODO: This makes the assumption that there is only 1 department. + } } //Highest level function call to make a call to fortellis. This should be the only call required, and it will handle all the logic for making the call. @@ -138,7 +143,8 @@ async function MakeFortellisCall({ jobid, redisHelpers, socket, - SubscriptionObject //This is used because of the get make models to bypass all of the redis calls. + SubscriptionObject, //This is used because of the get make models to bypass all of the redis calls. + overrideDepartmentId }) { const { setSessionTransactionData, getSessionTransactionData } = redisHelpers; @@ -148,7 +154,7 @@ async function MakeFortellisCall({ const ReqId = uuid(); const access_token = await GetAuthToken(); const SubscriptionMeta = await FetchSubscriptions({ redisHelpers, socket, jobid, SubscriptionObject }); - const DepartmentId = await GetDepartmentId({ apiName, debug, SubscriptionMeta }); + const DepartmentId = await GetDepartmentId({ apiName, debug, SubscriptionMeta, overrideDepartmentId }); if (debug) { console.log( diff --git a/server/fortellis/fortellis.js b/server/fortellis/fortellis.js index 1eea5c6d3..9c4a0a50c 100644 --- a/server/fortellis/fortellis.js +++ b/server/fortellis/fortellis.js @@ -419,9 +419,9 @@ async function QueryDmsCustomerByName({ socket, redisHelpers, JobData }) { JobData.ownr_co_nm && JobData.ownr_co_nm.trim() !== "" ? [["lastName", JobData.ownr_co_nm.replace(replaceSpecialRegex, "")]] : [ - ["firstName", JobData.ownr_fn.replace(replaceSpecialRegex, "")], - ["lastName", JobData.ownr_ln.replace(replaceSpecialRegex, "")] - ]; + ["firstName", JobData.ownr_fn.replace(replaceSpecialRegex, "")], + ["lastName", JobData.ownr_ln.replace(replaceSpecialRegex, "")] + ]; CreateFortellisLogEvent(socket, "DEBUG", `Begin query DMS Customer by Name using ${JSON.stringify(ownerName)} `); @@ -525,18 +525,18 @@ async function InsertDmsCustomer({ socket, redisHelpers, JobData }) { emailAddresses: [ ...(!_.isEmpty(JobData.ownr_ea) ? [ - { - //"uuid": "", - address: JobData.ownr_ea, - type: "PERSONAL" - // "doNotEmailSource": "", - // "doNotEmail": false, - // "isPreferred": true, - // "transactionEmailNotificationOptIn": false, - // "optInRequestDate": null, - // "optInDate": null - } - ] + { + //"uuid": "", + address: JobData.ownr_ea, + type: "PERSONAL" + // "doNotEmailSource": "", + // "doNotEmail": false, + // "isPreferred": true, + // "transactionEmailNotificationOptIn": false, + // "optInRequestDate": null, + // "optInDate": null + } + ] : []) // { // "uuid": "", @@ -676,9 +676,9 @@ async function InsertDmsVehicle({ socket, redisHelpers, JobData, txEnvelope, DMS txEnvelope.dms_unsold === true ? "" : moment(txEnvelope.inservicedate) - //.tz(JobData.bodyshop.timezone) - .startOf("day") - .toISOString() + //.tz(JobData.bodyshop.timezone) + .startOf("day") + .toISOString() }), //"lastServiceDate": "2011-11-23", vehicleId: DMSVid.vehiclesVehId @@ -720,8 +720,8 @@ async function InsertDmsVehicle({ socket, redisHelpers, JobData, txEnvelope, DMS txEnvelope.dms_unsold === true ? "" : moment() - // .tz(JobData.bodyshop.timezone) - .format("YYYY-MM-DD"), + // .tz(JobData.bodyshop.timezone) + .format("YYYY-MM-DD"), // "deliveryMileage": 4, // "doorsQuantity": 4, // "engineNumber": "", @@ -738,8 +738,8 @@ async function InsertDmsVehicle({ socket, redisHelpers, JobData, txEnvelope, DMS : String(JobData.plate_no).replace(/([^\w]|_)/g, "").length === 0 ? null : String(JobData.plate_no) - .replace(/([^\w]|_)/g, "") - .toUpperCase(), + .replace(/([^\w]|_)/g, "") + .toUpperCase(), make: txEnvelope.dms_make, // "model": "CC10753", modelAbrev: txEnvelope.dms_model, @@ -885,13 +885,13 @@ async function UpdateDmsVehicle({ socket, redisHelpers, JobData, DMSVeh, DMSCust }, ...(oldOwner ? [ - { - id: { - assigningPartyId: "PREVIOUS", - value: oldOwner.id - } + { + id: { + assigningPartyId: "PREVIOUS", + value: oldOwner.id } - ] + } + ] : []) ]; } @@ -921,24 +921,24 @@ async function UpdateDmsVehicle({ socket, redisHelpers, JobData, DMSVeh, DMSCust txEnvelope.dms_unsold === true ? "" : moment(DMSVehToSend.dealer.inServiceDate || txEnvelope.inservicedate) - // .tz(JobData.bodyshop.timezone) - .toISOString() + // .tz(JobData.bodyshop.timezone) + .toISOString() }) }, vehicle: { ...DMSVehToSend.vehicle, ...(txEnvelope.dms_model_override ? { - make: txEnvelope.dms_make, - modelAbrev: txEnvelope.dms_model - } + make: txEnvelope.dms_make, + modelAbrev: txEnvelope.dms_model + } : {}), deliveryDate: txEnvelope.dms_unsold === true ? "" : moment(DMSVehToSend.vehicle.deliveryDate) - //.tz(JobData.bodyshop.timezone) - .toISOString() + //.tz(JobData.bodyshop.timezone) + .toISOString() }, owners: ids } @@ -1015,34 +1015,35 @@ async function InsertDmsStartWip({ socket, redisHelpers, JobData }) { socket, jobid: JobData.id, body: { - // acctgDate: moment().tz(JobData.bodyshop.timezone).format("YYYY-MM-DD"), - // desc: txEnvelope.story && txEnvelope.story.replace(replaceSpecialRegex, ""), - // docType: "10", - // m13Flag: "0", - // refer: JobData.ro_number, - // // "rtnCode": "", - // // "sendline": "", - // // "groupName": "", - // srcCo: JobData.bodyshop.cdk_configuration.srcco, - // srcJrnl: txEnvelope.journal, - // transID: "", - // userID: "partprgm" || JobData.bodyshop.cdk_configuration.cashierid, - // userName: "PROGRAM, PARTNER" - - acctgDate: "2025-07-07", - desc: "DOCUMENT DESC. OPTIONAL REQUIREMENT", - docType: "3", + acctgDate: moment().tz(JobData.bodyshop.timezone).format("YYYY-MM-DD"), + desc: txEnvelope.story && txEnvelope.story.replace(replaceSpecialRegex, ""), + docType: "10", m13Flag: "0", - refer: "707MISC01", - rtnCode: "", - sendline: "", - groupName: "", - srcCo: "77", - srcJrnl: "80", + refer: JobData.ro_number, + // "rtnCode": "", + // "sendline": "", + // "groupName": "", + srcCo: JobData.bodyshop.cdk_configuration.srcco, + srcJrnl: txEnvelope.journal, transID: "", - userID: "partprgm", + userID: "partprgm" || JobData.bodyshop.cdk_configuration.cashierid, userName: "PROGRAM, PARTNER" - } + + // acctgDate: "2025-07-07", + // desc: "DOCUMENT DESC. OPTIONAL REQUIREMENT", + // docType: "3", + // m13Flag: "0", + // refer: "707MISC01", + // rtnCode: "", + // sendline: "", + // groupName: "", + // srcCo: "77", + // srcJrnl: "80", + // transID: "", + // userID: "partprgm", + // userName: "PROGRAM, PARTNER" + }, + //overrideDepartmentId: "D100152198" //TODO: REMOVE AFTER TESTING }); return result; } catch (error) { @@ -1092,9 +1093,9 @@ async function GenerateTransWips({ socket, redisHelpers, JobData }) { acct: alloc.profitCenter.dms_acctnumber, 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 !== null && + alloc.profitCenter.dms_control_override !== undefined && + alloc.profitCenter.dms_control_override?.trim() !== "" ? alloc.profitCenter.dms_control_override : JobData.ro_number, cntl2: null, @@ -1115,9 +1116,9 @@ async function GenerateTransWips({ socket, redisHelpers, JobData }) { acct: alloc.costCenter.dms_acctnumber, 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 !== null && + alloc.costCenter.dms_control_override !== undefined && + alloc.costCenter.dms_control_override?.trim() !== "" ? alloc.costCenter.dms_control_override : JobData.ro_number, cntl2: null, @@ -1135,9 +1136,9 @@ async function GenerateTransWips({ socket, redisHelpers, JobData }) { acct: alloc.costCenter.dms_wip_acctnumber, 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 !== null && + alloc.costCenter.dms_control_override !== undefined && + alloc.costCenter.dms_control_override?.trim() !== "" ? alloc.costCenter.dms_control_override : JobData.ro_number, cntl2: null, @@ -1159,9 +1160,9 @@ async function GenerateTransWips({ socket, redisHelpers, JobData }) { acct: alloc.profitCenter.dms_acctnumber, 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 !== null && + alloc.profitCenter.dms_control_override !== undefined && + alloc.profitCenter.dms_control_override?.trim() !== "" ? alloc.profitCenter.dms_control_override : JobData.ro_number, cntl2: null, @@ -1229,7 +1230,8 @@ async function PostDmsBatchWip({ socket, redisHelpers, JobData }) { opCode: "P", transID: DMSTransHeader.transID, transWipReqList: await GenerateTransWips({ socket, redisHelpers, JobData }) - } + }, + overrideDepartmentId: "D100152198" }); return result; } catch (error) { @@ -1257,7 +1259,8 @@ async function QueryDmsErrWip({ socket, redisHelpers, JobData }) { socket, jobid: JobData.id, requestPathParams: DMSTransHeader.transID, - body: {} + body: {}, + overrideDepartmentId: "D100152198" }); return result; } catch (error) { @@ -1287,7 +1290,8 @@ async function DeleteDmsWip({ socket, redisHelpers, JobData }) { body: { opCode: "D", transID: DMSTransHeader.transID - } + }, + overrideDepartmentId: "D100152198" }); return result; } catch (error) {