Debug level changes, vehicle upsert correction, and logic updates.
This commit is contained in:
@@ -43,11 +43,11 @@ exports.default = async function (socket, { txEnvelope, jobid }) {
|
||||
socket.recordid = jobid;
|
||||
socket.txEnvelope = txEnvelope;
|
||||
try {
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `Received Job export request for id ${jobid}`);
|
||||
CdkBase.createLogEvent(socket, "INFO", `Received Job export request for id ${jobid}`);
|
||||
|
||||
const JobData = await QueryJobData(socket, jobid);
|
||||
socket.JobData = JobData;
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `Querying the DMS for the Vehicle Record.`);
|
||||
CdkBase.createLogEvent(socket, "INFO", `Querying the DMS for the Vehicle Record.`);
|
||||
//Query for the Vehicle record to get the associated customer.
|
||||
socket.DmsVeh = await QueryVehicleFromDms(socket);
|
||||
//Todo: Need to validate the lines and methods below.
|
||||
@@ -69,39 +69,39 @@ exports.default = async function (socket, { txEnvelope, jobid }) {
|
||||
exports.PbsSelectedCustomer = async function PbsSelectedCustomer(socket, selectedCustomerId) {
|
||||
try {
|
||||
if (socket.JobData.bodyshop.pbs_configuration.disablecontactvehicle === false) {
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `User selected customer ${selectedCustomerId || "NEW"}`);
|
||||
CdkBase.createLogEvent(socket, "INFO", `User selected customer ${selectedCustomerId || "NEW"}`);
|
||||
|
||||
//Upsert the contact information as per Wafaa's Email.
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
"INFO",
|
||||
`Upserting contact information to DMS for ${socket.JobData.ownr_fn || ""
|
||||
} ${socket.JobData.ownr_ln || ""} ${socket.JobData.ownr_co_nm || ""}`
|
||||
);
|
||||
const ownerRef = await UpsertContactData(socket, selectedCustomerId);
|
||||
socket.ownerRef = ownerRef;
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `Upserting vehicle information to DMS for ${socket.JobData.v_vin}`);
|
||||
CdkBase.createLogEvent(socket, "INFO", `Upserting vehicle information to DMS for ${socket.JobData.v_vin}`);
|
||||
const vehicleRef = await UpsertVehicleData(socket, ownerRef.ReferenceId);
|
||||
socket.vehicleRef = vehicleRef;
|
||||
} else {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
"INFO",
|
||||
`Contact and Vehicle updates disabled. Skipping to accounting data insert.`
|
||||
);
|
||||
}
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `Inserting account data.`);
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `Inserting accounting posting data..`);
|
||||
CdkBase.createLogEvent(socket, "INFO", `Inserting account data.`);
|
||||
CdkBase.createLogEvent(socket, "INFO", `Inserting accounting posting data..`);
|
||||
const insertResponse = await InsertAccountPostingData(socket);
|
||||
|
||||
if (insertResponse.WasSuccessful) {
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `Marking job as exported.`);
|
||||
CdkBase.createLogEvent(socket, "INFO", `Marking job as exported.`);
|
||||
await MarkJobExported(socket, socket.JobData.id);
|
||||
|
||||
//If export succesful, check to see if an RO exists.
|
||||
//If it does, update necessary elements, otherwise create it.
|
||||
// if (socket.jobData.bodyshop.pbs_configuration.ro_posting) { //TODO: Create `ro_posting` field on
|
||||
await CreateRepairOrderInPBS(socket, socket.ownerRef, socket.VehicleRef)
|
||||
await CreateRepairOrderInPBS(socket, socket.ownerRef, socket.vehicleRef)
|
||||
// }
|
||||
socket.emit("export-success", socket.JobData.id);
|
||||
} else {
|
||||
@@ -116,22 +116,22 @@ exports.PbsSelectedCustomer = async function PbsSelectedCustomer(socket, selecte
|
||||
// Was Successful
|
||||
async function CheckForErrors(socket, response) {
|
||||
if (response.WasSuccessful === undefined || response.WasSuccessful === true) {
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `Successful response from DMS. ${response.Message || ""}`);
|
||||
CdkBase.createLogEvent(socket, "INFO", `Successful response from DMS. ${response.Message || ""}`);
|
||||
} else {
|
||||
CdkBase.createLogEvent(socket, "ERROR", `Error received from DMS: ${response.Message}`);
|
||||
CdkBase.createLogEvent(socket, "SILLY", `Error received from DMS: ${JSON.stringify(response)}`);
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `Error received from DMS: ${JSON.stringify(response)}`);
|
||||
}
|
||||
}
|
||||
|
||||
exports.CheckForErrors = CheckForErrors;
|
||||
|
||||
async function QueryJobData(socket, jobid) {
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `Querying job data for id ${jobid}`);
|
||||
CdkBase.createLogEvent(socket, "INFO", `Querying job data for id ${jobid}`);
|
||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {});
|
||||
const result = await client
|
||||
.setHeaders({ Authorization: `Bearer ${socket.handshake.auth.token}` })
|
||||
.request(queries.QUERY_JOBS_FOR_PBS_EXPORT, { id: jobid });
|
||||
CdkBase.createLogEvent(socket, "SILLY", `Job data query result ${JSON.stringify(result, null, 2)}`);
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `Job data query result ${JSON.stringify(result, null, 2)}`);
|
||||
return result.jobs_by_pk;
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ async function UpsertVehicleData(socket, ownerRef) {
|
||||
//FleetNumber: "String",
|
||||
//Status: "String",
|
||||
OwnerRef: ownerRef, // "00000000000000000000000000000000",
|
||||
ModelNumber: socket.JobData.vehicle && socket.JobData.vehicle.v_makecode,
|
||||
// ModelNumber: socket.JobData.vehicle && socket.JobData.vehicle.v_makecode,
|
||||
Make: socket.JobData.v_make_desc,
|
||||
Model: socket.JobData.v_model_desc,
|
||||
Trim: socket.JobData.vehicle && socket.JobData.vehicle.v_trimcode,
|
||||
@@ -344,7 +344,7 @@ async function UpsertVehicleData(socket, ownerRef) {
|
||||
Year: socket.JobData.v_model_yr,
|
||||
Odometer: socket.JobData.kmout,
|
||||
ExteriorColor: {
|
||||
Code: socket.JobData.v_color,
|
||||
// Code: socket.JobData.v_color,
|
||||
Description: socket.JobData.v_color
|
||||
}
|
||||
// InteriorColor: { Code: "String", Description: "String" },
|
||||
@@ -576,7 +576,7 @@ async function InsertAccountPostingData(socket) {
|
||||
}
|
||||
|
||||
async function MarkJobExported(socket, jobid) {
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `Marking job as exported for id ${jobid}`);
|
||||
CdkBase.createLogEvent(socket, "INFO", `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}` })
|
||||
@@ -626,18 +626,20 @@ async function InsertFailedExportLog(socket, error) {
|
||||
|
||||
async function CreateRepairOrderInPBS(socket) {
|
||||
try {
|
||||
|
||||
const { RepairOrders } = await RepairOrderGet(socket);
|
||||
|
||||
if (RepairOrders.length === 0) {
|
||||
const InsertedRepairOrder = await RepairOrderChange(socket)
|
||||
} else if (RepairOrders.length === 1) {
|
||||
|
||||
//Upsert Scenario
|
||||
const InsertedRepairOrder = await RepairOrderChange(socket)
|
||||
} else {
|
||||
//We had too many matches come back. Shouldn't be here.
|
||||
CdkBase.createLogEvent(socket, "ERROR", `Error in CreateRepairOrderInPBS - Multiple RO's returned by PBS. ${JSON.stringify(ExistingRepairOrderData)}`);
|
||||
socket.InsertedRepairOrder = InsertedRepairOrder;
|
||||
} else if (RepairOrders.length > 0) {
|
||||
//Find out if it's a matching RO.
|
||||
const matchingRo = RepairOrders.find(ro => ro.Memo?.toLowerCase()?.includes(socket.JobData.ro_number.toLowerCase()))
|
||||
if (!matchingRo) {
|
||||
CdkBase.createLogEvent(socket, "INFO", `ROs found for customer, but none match. Inserting record.`);
|
||||
const InsertedRepairOrder = await RepairOrderChange(socket)
|
||||
socket.InsertedRepairOrder = InsertedRepairOrder;
|
||||
} else {
|
||||
CdkBase.createLogEvent(socket, "WARN", `Repair order appears to already exist in PBS. ${matchingRo.RepairOrderNumber}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
CdkBase.createLogEvent(socket, "ERROR", `Error in CreateRepairOrderInPBS - ${error} - ${JSON.stringify(error)}`);
|
||||
@@ -652,11 +654,11 @@ async function RepairOrderGet(socket) {
|
||||
SerialNumber: socket.JobData.bodyshop.pbs_serialnumber,
|
||||
//"RepairOrderId": "374728766",
|
||||
//"RepairOrderNumber": "4" || socket.JobData.ro_number,
|
||||
"RawRepairOrderNumber": socket.JobData.ro_number,
|
||||
//"RawRepairOrderNumber": socket.JobData.ro_number,
|
||||
// "Tag": "String",
|
||||
//"ContactRef": "701de19bb6c146ffb90b9aead4ba0a82",
|
||||
//"ContactRef": socket.contactRef,
|
||||
// "ContactRefList": ["00000000000000000000000000000000"],
|
||||
// "VehicleRef": "00000000000000000000000000000000",
|
||||
"VehicleRef": socket.vehicleRef?.ReferenceId,
|
||||
// "VehicleRefList": ["00000000000000000000000000000000"],
|
||||
// "Status": "String",
|
||||
// "CashieredSince": "0001-01-01T00:00:00.0000000Z",
|
||||
@@ -686,8 +688,10 @@ async function RepairOrderChange(socket, PbsROObject) {
|
||||
//"Id": "string/00000000-0000-0000-0000-000000000000",
|
||||
//"RepairOrderId": "00000000000000000000000000000000",
|
||||
SerialNumber: socket.JobData.bodyshop.pbs_serialnumber,
|
||||
"RepairOrderNumber": socket.JobData.ro_number,
|
||||
"RawRepairOrderNumber": socket.JobData.ro_number,
|
||||
"RepairOrderNumber": "00000000000000000000000000000000",
|
||||
"RawRepairOrderNumber": "00000000000000000000000000000000",
|
||||
// "RepairOrderNumber": socket.JobData.ro_number,
|
||||
// "RawRepairOrderNumber": socket.JobData.ro_number,
|
||||
"DateOpened": moment(),
|
||||
// "DateOpenedUTC": "0001-01-01T00:00:00.0000000Z",
|
||||
// "DateCashiered": "0001-01-01T00:00:00.0000000Z",
|
||||
@@ -712,7 +716,7 @@ async function RepairOrderChange(socket, PbsROObject) {
|
||||
// "ChargeType": "String",
|
||||
// "PurchaseOrderNumber": "String",
|
||||
// "Transportation": "String",
|
||||
"Status": "CLOSED", //This doesn't seem to apply.
|
||||
"Status": "CLOSED", //This does not impact the status.
|
||||
Requests: [
|
||||
{
|
||||
// "RepairOrderRequestRef": "b1842ecad62c4279bbc2fef4f6bf6cde",
|
||||
@@ -721,7 +725,7 @@ async function RepairOrderChange(socket, PbsROObject) {
|
||||
// "CSRRef": "1ce12ac692564e94bda955d529ee911a",
|
||||
// "Skill": "GEN",
|
||||
"RequestCode": "MISC",
|
||||
"RequestDescription": "REPAIR VEHICLE AT BODYSHOP",
|
||||
"RequestDescription": "VEHICLE REPAIRED AT BODYSHOP. PLEASE REFERENCE IMEX SHOP MANAGEMENT SYSTEM.",
|
||||
"Status": "Completed",
|
||||
// "TechRef": "00000000000000000000000000000000",
|
||||
"AllowedHours": 0,
|
||||
|
||||
Reference in New Issue
Block a user