Add department overrides.

This commit is contained in:
Patrick Fic
2025-11-05 13:23:24 -08:00
parent c6d083ce02
commit a16c680d04
3 changed files with 91 additions and 79 deletions

View File

@@ -21,6 +21,7 @@ exports.defaultRoute = async function (req, res) {
} catch (error) { } catch (error) {
////console.log(error); ////console.log(error);
WsLogger.createLogEvent(req, "ERROR", `Error encountered in CdkCalculateAllocations. ${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}` }); 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); ////console.log(error);
const loggingFunction = isFortellis ? CreateFortellisLogEvent : WsLogger.createLogEvent; const loggingFunction = isFortellis ? CreateFortellisLogEvent : WsLogger.createLogEvent;
loggingFunction(socket, "ERROR", `Error encountered in CdkCalculateAllocations. ${error}`); loggingFunction(socket, "ERROR", `Error encountered in CdkCalculateAllocations. ${error}`);
loggingFunction(socket, "ERROR", `Error encountered in CdkCalculateAllocations. ${error.stack}`);
} }
}; };

View File

@@ -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 (!apiName) throw new Error("apiName not provided. Unable to get department without apiName.");
if (debug) { if (debug) {
console.log("API Names & Departments "); console.log("API Names & Departments ");
@@ -122,7 +122,12 @@ async function GetDepartmentId({ apiName, debug = false, SubscriptionMeta }) {
const departmentIds2 = SubscriptionMeta.apiDmsInfo //Get the subscription object. 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. .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. //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, jobid,
redisHelpers, redisHelpers,
socket, 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; const { setSessionTransactionData, getSessionTransactionData } = redisHelpers;
@@ -148,7 +154,7 @@ async function MakeFortellisCall({
const ReqId = uuid(); const ReqId = uuid();
const access_token = await GetAuthToken(); const access_token = await GetAuthToken();
const SubscriptionMeta = await FetchSubscriptions({ redisHelpers, socket, jobid, SubscriptionObject }); 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) { if (debug) {
console.log( console.log(

View File

@@ -419,9 +419,9 @@ async function QueryDmsCustomerByName({ socket, redisHelpers, JobData }) {
JobData.ownr_co_nm && JobData.ownr_co_nm.trim() !== "" JobData.ownr_co_nm && JobData.ownr_co_nm.trim() !== ""
? [["lastName", JobData.ownr_co_nm.replace(replaceSpecialRegex, "")]] ? [["lastName", JobData.ownr_co_nm.replace(replaceSpecialRegex, "")]]
: [ : [
["firstName", JobData.ownr_fn.replace(replaceSpecialRegex, "")], ["firstName", JobData.ownr_fn.replace(replaceSpecialRegex, "")],
["lastName", JobData.ownr_ln.replace(replaceSpecialRegex, "")] ["lastName", JobData.ownr_ln.replace(replaceSpecialRegex, "")]
]; ];
CreateFortellisLogEvent(socket, "DEBUG", `Begin query DMS Customer by Name using ${JSON.stringify(ownerName)} `); CreateFortellisLogEvent(socket, "DEBUG", `Begin query DMS Customer by Name using ${JSON.stringify(ownerName)} `);
@@ -525,18 +525,18 @@ async function InsertDmsCustomer({ socket, redisHelpers, JobData }) {
emailAddresses: [ emailAddresses: [
...(!_.isEmpty(JobData.ownr_ea) ...(!_.isEmpty(JobData.ownr_ea)
? [ ? [
{ {
//"uuid": "", //"uuid": "",
address: JobData.ownr_ea, address: JobData.ownr_ea,
type: "PERSONAL" type: "PERSONAL"
// "doNotEmailSource": "", // "doNotEmailSource": "",
// "doNotEmail": false, // "doNotEmail": false,
// "isPreferred": true, // "isPreferred": true,
// "transactionEmailNotificationOptIn": false, // "transactionEmailNotificationOptIn": false,
// "optInRequestDate": null, // "optInRequestDate": null,
// "optInDate": null // "optInDate": null
} }
] ]
: []) : [])
// { // {
// "uuid": "", // "uuid": "",
@@ -676,9 +676,9 @@ async function InsertDmsVehicle({ socket, redisHelpers, JobData, txEnvelope, DMS
txEnvelope.dms_unsold === true txEnvelope.dms_unsold === true
? "" ? ""
: moment(txEnvelope.inservicedate) : moment(txEnvelope.inservicedate)
//.tz(JobData.bodyshop.timezone) //.tz(JobData.bodyshop.timezone)
.startOf("day") .startOf("day")
.toISOString() .toISOString()
}), }),
//"lastServiceDate": "2011-11-23", //"lastServiceDate": "2011-11-23",
vehicleId: DMSVid.vehiclesVehId vehicleId: DMSVid.vehiclesVehId
@@ -720,8 +720,8 @@ async function InsertDmsVehicle({ socket, redisHelpers, JobData, txEnvelope, DMS
txEnvelope.dms_unsold === true txEnvelope.dms_unsold === true
? "" ? ""
: moment() : moment()
// .tz(JobData.bodyshop.timezone) // .tz(JobData.bodyshop.timezone)
.format("YYYY-MM-DD"), .format("YYYY-MM-DD"),
// "deliveryMileage": 4, // "deliveryMileage": 4,
// "doorsQuantity": 4, // "doorsQuantity": 4,
// "engineNumber": "", // "engineNumber": "",
@@ -738,8 +738,8 @@ async function InsertDmsVehicle({ socket, redisHelpers, JobData, txEnvelope, DMS
: String(JobData.plate_no).replace(/([^\w]|_)/g, "").length === 0 : String(JobData.plate_no).replace(/([^\w]|_)/g, "").length === 0
? null ? null
: String(JobData.plate_no) : String(JobData.plate_no)
.replace(/([^\w]|_)/g, "") .replace(/([^\w]|_)/g, "")
.toUpperCase(), .toUpperCase(),
make: txEnvelope.dms_make, make: txEnvelope.dms_make,
// "model": "CC10753", // "model": "CC10753",
modelAbrev: txEnvelope.dms_model, modelAbrev: txEnvelope.dms_model,
@@ -885,13 +885,13 @@ async function UpdateDmsVehicle({ socket, redisHelpers, JobData, DMSVeh, DMSCust
}, },
...(oldOwner ...(oldOwner
? [ ? [
{ {
id: { id: {
assigningPartyId: "PREVIOUS", assigningPartyId: "PREVIOUS",
value: oldOwner.id value: oldOwner.id
}
} }
] }
]
: []) : [])
]; ];
} }
@@ -921,24 +921,24 @@ async function UpdateDmsVehicle({ socket, redisHelpers, JobData, DMSVeh, DMSCust
txEnvelope.dms_unsold === true txEnvelope.dms_unsold === true
? "" ? ""
: moment(DMSVehToSend.dealer.inServiceDate || txEnvelope.inservicedate) : moment(DMSVehToSend.dealer.inServiceDate || txEnvelope.inservicedate)
// .tz(JobData.bodyshop.timezone) // .tz(JobData.bodyshop.timezone)
.toISOString() .toISOString()
}) })
}, },
vehicle: { vehicle: {
...DMSVehToSend.vehicle, ...DMSVehToSend.vehicle,
...(txEnvelope.dms_model_override ...(txEnvelope.dms_model_override
? { ? {
make: txEnvelope.dms_make, make: txEnvelope.dms_make,
modelAbrev: txEnvelope.dms_model modelAbrev: txEnvelope.dms_model
} }
: {}), : {}),
deliveryDate: deliveryDate:
txEnvelope.dms_unsold === true txEnvelope.dms_unsold === true
? "" ? ""
: moment(DMSVehToSend.vehicle.deliveryDate) : moment(DMSVehToSend.vehicle.deliveryDate)
//.tz(JobData.bodyshop.timezone) //.tz(JobData.bodyshop.timezone)
.toISOString() .toISOString()
}, },
owners: ids owners: ids
} }
@@ -1015,34 +1015,35 @@ async function InsertDmsStartWip({ socket, redisHelpers, JobData }) {
socket, socket,
jobid: JobData.id, jobid: JobData.id,
body: { body: {
// acctgDate: moment().tz(JobData.bodyshop.timezone).format("YYYY-MM-DD"), acctgDate: moment().tz(JobData.bodyshop.timezone).format("YYYY-MM-DD"),
// desc: txEnvelope.story && txEnvelope.story.replace(replaceSpecialRegex, ""), desc: txEnvelope.story && txEnvelope.story.replace(replaceSpecialRegex, ""),
// docType: "10", 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",
m13Flag: "0", m13Flag: "0",
refer: "707MISC01", refer: JobData.ro_number,
rtnCode: "", // "rtnCode": "",
sendline: "", // "sendline": "",
groupName: "", // "groupName": "",
srcCo: "77", srcCo: JobData.bodyshop.cdk_configuration.srcco,
srcJrnl: "80", srcJrnl: txEnvelope.journal,
transID: "", transID: "",
userID: "partprgm", userID: "partprgm" || JobData.bodyshop.cdk_configuration.cashierid,
userName: "PROGRAM, PARTNER" 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; return result;
} catch (error) { } catch (error) {
@@ -1092,9 +1093,9 @@ async function GenerateTransWips({ socket, redisHelpers, JobData }) {
acct: alloc.profitCenter.dms_acctnumber, acct: alloc.profitCenter.dms_acctnumber,
cntl: cntl:
alloc.profitCenter.dms_control_override && alloc.profitCenter.dms_control_override &&
alloc.profitCenter.dms_control_override !== null && alloc.profitCenter.dms_control_override !== null &&
alloc.profitCenter.dms_control_override !== undefined && alloc.profitCenter.dms_control_override !== undefined &&
alloc.profitCenter.dms_control_override?.trim() !== "" alloc.profitCenter.dms_control_override?.trim() !== ""
? alloc.profitCenter.dms_control_override ? alloc.profitCenter.dms_control_override
: JobData.ro_number, : JobData.ro_number,
cntl2: null, cntl2: null,
@@ -1115,9 +1116,9 @@ async function GenerateTransWips({ socket, redisHelpers, JobData }) {
acct: alloc.costCenter.dms_acctnumber, acct: alloc.costCenter.dms_acctnumber,
cntl: cntl:
alloc.costCenter.dms_control_override && alloc.costCenter.dms_control_override &&
alloc.costCenter.dms_control_override !== null && alloc.costCenter.dms_control_override !== null &&
alloc.costCenter.dms_control_override !== undefined && alloc.costCenter.dms_control_override !== undefined &&
alloc.costCenter.dms_control_override?.trim() !== "" alloc.costCenter.dms_control_override?.trim() !== ""
? alloc.costCenter.dms_control_override ? alloc.costCenter.dms_control_override
: JobData.ro_number, : JobData.ro_number,
cntl2: null, cntl2: null,
@@ -1135,9 +1136,9 @@ async function GenerateTransWips({ socket, redisHelpers, JobData }) {
acct: alloc.costCenter.dms_wip_acctnumber, acct: alloc.costCenter.dms_wip_acctnumber,
cntl: cntl:
alloc.costCenter.dms_control_override && alloc.costCenter.dms_control_override &&
alloc.costCenter.dms_control_override !== null && alloc.costCenter.dms_control_override !== null &&
alloc.costCenter.dms_control_override !== undefined && alloc.costCenter.dms_control_override !== undefined &&
alloc.costCenter.dms_control_override?.trim() !== "" alloc.costCenter.dms_control_override?.trim() !== ""
? alloc.costCenter.dms_control_override ? alloc.costCenter.dms_control_override
: JobData.ro_number, : JobData.ro_number,
cntl2: null, cntl2: null,
@@ -1159,9 +1160,9 @@ async function GenerateTransWips({ socket, redisHelpers, JobData }) {
acct: alloc.profitCenter.dms_acctnumber, acct: alloc.profitCenter.dms_acctnumber,
cntl: cntl:
alloc.profitCenter.dms_control_override && alloc.profitCenter.dms_control_override &&
alloc.profitCenter.dms_control_override !== null && alloc.profitCenter.dms_control_override !== null &&
alloc.profitCenter.dms_control_override !== undefined && alloc.profitCenter.dms_control_override !== undefined &&
alloc.profitCenter.dms_control_override?.trim() !== "" alloc.profitCenter.dms_control_override?.trim() !== ""
? alloc.profitCenter.dms_control_override ? alloc.profitCenter.dms_control_override
: JobData.ro_number, : JobData.ro_number,
cntl2: null, cntl2: null,
@@ -1229,7 +1230,8 @@ async function PostDmsBatchWip({ socket, redisHelpers, JobData }) {
opCode: "P", opCode: "P",
transID: DMSTransHeader.transID, transID: DMSTransHeader.transID,
transWipReqList: await GenerateTransWips({ socket, redisHelpers, JobData }) transWipReqList: await GenerateTransWips({ socket, redisHelpers, JobData })
} },
overrideDepartmentId: "D100152198"
}); });
return result; return result;
} catch (error) { } catch (error) {
@@ -1257,7 +1259,8 @@ async function QueryDmsErrWip({ socket, redisHelpers, JobData }) {
socket, socket,
jobid: JobData.id, jobid: JobData.id,
requestPathParams: DMSTransHeader.transID, requestPathParams: DMSTransHeader.transID,
body: {} body: {},
overrideDepartmentId: "D100152198"
}); });
return result; return result;
} catch (error) { } catch (error) {
@@ -1287,7 +1290,8 @@ async function DeleteDmsWip({ socket, redisHelpers, JobData }) {
body: { body: {
opCode: "D", opCode: "D",
transID: DMSTransHeader.transID transID: DMSTransHeader.transID
} },
overrideDepartmentId: "D100152198"
}); });
return result; return result;
} catch (error) { } catch (error) {