|
|
|
|
@@ -13,7 +13,7 @@ const CdkWsdl = require("./cdk-wsdl").default;
|
|
|
|
|
const logger = require("../utils/logger");
|
|
|
|
|
const { CDK_CREDENTIALS, CheckCdkResponseForError } = require("./cdk-wsdl");
|
|
|
|
|
|
|
|
|
|
exports.default = async function (socket, jobid) {
|
|
|
|
|
exports.default = async function (socket, { jobid }) {
|
|
|
|
|
socket.logEvents = [];
|
|
|
|
|
socket.recordid = jobid;
|
|
|
|
|
try {
|
|
|
|
|
@@ -22,8 +22,7 @@ exports.default = async function (socket, jobid) {
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`Received Job export request for id ${jobid}`
|
|
|
|
|
);
|
|
|
|
|
//The following values will be stored on the socket to allow callbacks.
|
|
|
|
|
//let DMSVid, DMSVeh, clADPC;
|
|
|
|
|
|
|
|
|
|
const JobData = await QueryJobData(socket, jobid);
|
|
|
|
|
const DealerId = JobData.bodyshop.cdk_dealerid;
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
@@ -32,135 +31,49 @@ exports.default = async function (socket, jobid) {
|
|
|
|
|
`Dealer ID detected: ${JSON.stringify(DealerId)}`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//{1} Begin Calculate DMS Vehicle Id
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`{1} Begin Calculate DMS Vehicle ID using VIN: ${JobData.v_vin}`
|
|
|
|
|
);
|
|
|
|
|
socket.DMSVid = await CalculateDmsVid(socket, JobData);
|
|
|
|
|
if (socket.DMSVid.newId === "Y") {
|
|
|
|
|
//{1.2} This is a new Vehicle ID
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`{1.2} DMSVid DMSVid does *not* exist.`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (socket.DMSVid.newId === "N") {
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`{1.2} DMSVid: ${JSON.stringify(socket.DMSVid, null, 2)}`
|
|
|
|
|
);
|
|
|
|
|
//Check if DMSCustId is Empty - which it should always be?
|
|
|
|
|
//{6.6} Should check to see if a customer exists so that we can marry it to the new vehicle.
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`{6.6} Trying to find customer ID in DMS.`
|
|
|
|
|
`{2.1} Querying the Vehicle using the DMSVid: ${socket.DmsVid}`
|
|
|
|
|
);
|
|
|
|
|
socket.DMSVeh = await QueryDmsVehicleById(socket, JobData, socket.DMSVid);
|
|
|
|
|
|
|
|
|
|
//Array
|
|
|
|
|
const strIDS = await QueryDmsCustomerByName(socket, JobData);
|
|
|
|
|
if (strIDS && strIDS.length > 0) {
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`{8.2} ${strIDS.length} Customer ID(s) found.`
|
|
|
|
|
);
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`{8.2} strIDS: ${JSON.stringify(strIDS, null, 2)}`
|
|
|
|
|
);
|
|
|
|
|
if (strIDS.length > 1) {
|
|
|
|
|
//We have multiple IDs
|
|
|
|
|
//TODO: Do we need to let the person select it?
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"WARNING",
|
|
|
|
|
`{F} Mutliple customer ids have been found (${strIDS.length})`
|
|
|
|
|
);
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`Asking for user intervention to select customer.`
|
|
|
|
|
);
|
|
|
|
|
socket.emit("cdk-select-customer", strIDS);
|
|
|
|
|
const DmsVehCustomerId =
|
|
|
|
|
socket.DMSVeh &&
|
|
|
|
|
socket.DMSVeh.owners.find((o) => o.assigningPartyId === "CURRENT");
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`{8.5} Customer ID(s) *not* found.`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//Create a customer number, then use that to insert the customer record.
|
|
|
|
|
const newCustomerNumber = await GenerateCustomerNumberFromDms(
|
|
|
|
|
socket,
|
|
|
|
|
JobData
|
|
|
|
|
);
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`{10.1} New Customer number generated. newCustomerNumber: ${newCustomerNumber}`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//Use the new customer number to insert the customer record.
|
|
|
|
|
socket.clADPC = await CreateCustomerInDms(
|
|
|
|
|
socket,
|
|
|
|
|
JobData,
|
|
|
|
|
newCustomerNumber
|
|
|
|
|
);
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`{11.1} New Customer inserted.`
|
|
|
|
|
);
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`{11.1} clADPC: ${JSON.stringify(socket.clADPC, null, 2)}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`{1.1} DMSVid DMSVid does exist.`
|
|
|
|
|
);
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`{1.1} DMSVid: ${JSON.stringify(socket.DMSVid, null, 2)}`
|
|
|
|
|
`{2.2} Querying the Customer using the ID from DMSVeh: ${DmsVehCustomerId}`
|
|
|
|
|
);
|
|
|
|
|
socket.DmsVehCustomer = await QueryDmsCustomerById(
|
|
|
|
|
socket,
|
|
|
|
|
JobData,
|
|
|
|
|
DmsVehCustomerId
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//{2} Begin Find Vehicle in DMS
|
|
|
|
|
socket.DMSVeh = await QueryDmsVehicleById(socket, JobData, socket.DMSVid); //TODO: Verify that this should always return a result. If an ID was found previously, it should be correct?
|
|
|
|
|
|
|
|
|
|
//{2.2} Check if the vehicle was found in the DMS.
|
|
|
|
|
if (socket.DMSVeh.AppErrorNo === "0") {
|
|
|
|
|
//Vehicle was found.
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`{1.4} Vehicle was found in the DMS.`
|
|
|
|
|
);
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`{1.4} DMSVeh: ${JSON.stringify(socket.DMSVeh, null, 2)}`
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
//Vehicle was not found.
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`{6.4} Vehicle does not exist in DMS. Will have to create one.`
|
|
|
|
|
);
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`{6.4} DMSVid: ${JSON.stringify(socket.DMSVid, null, 2)}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`{2.3} Querying the Customer using the name.`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
socket.DmsCustList = await QueryDmsCustomerByName(socket, JobData);
|
|
|
|
|
|
|
|
|
|
socket.emit("cdk-select-customer", [
|
|
|
|
|
...(socket.DmsVehCustomer ? socket.DmsVehCustomer : []),
|
|
|
|
|
...socket.DmsCustList,
|
|
|
|
|
]);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
@@ -192,122 +105,196 @@ async function QueryJobData(socket, jobid) {
|
|
|
|
|
return result.jobs_by_pk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function CreateCustomerInDms(socket, JobData, newCustomerNumber) {
|
|
|
|
|
CdkBase.createLogEvent(socket, "DEBUG", `{11} Begin Create Customer in DMS`);
|
|
|
|
|
|
|
|
|
|
async function CalculateDmsVid(socket, JobData) {
|
|
|
|
|
try {
|
|
|
|
|
const soapClientCustomerInsertUpdate = await soap.createClientAsync(
|
|
|
|
|
CdkWsdl.CustomerInsertUpdate
|
|
|
|
|
const soapClientVehicleInsertUpdate = await soap.createClientAsync(
|
|
|
|
|
CdkWsdl.VehicleInsertUpdate
|
|
|
|
|
);
|
|
|
|
|
const soapResponseVehicleInsertUpdate =
|
|
|
|
|
await soapClientVehicleInsertUpdate.getVehIdsAsync({
|
|
|
|
|
arg0: CDK_CREDENTIALS,
|
|
|
|
|
arg1: { id: JobData.bodyshop.cdk_dealerid },
|
|
|
|
|
arg2: { VIN: JobData.v_vin },
|
|
|
|
|
});
|
|
|
|
|
CheckCdkResponseForError(socket, soapResponseVehicleInsertUpdate);
|
|
|
|
|
const [result, rawResponse, soapheader, rawRequest] =
|
|
|
|
|
soapResponseVehicleInsertUpdate;
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
rawRequest,
|
|
|
|
|
`soapClientVehicleInsertUpdate.getVehIdsAsync reqest.`
|
|
|
|
|
);
|
|
|
|
|
const soapResponseCustomerInsertUpdate =
|
|
|
|
|
await soapClientCustomerInsertUpdate.insertAsync(
|
|
|
|
|
{
|
|
|
|
|
arg0: CDK_CREDENTIALS,
|
|
|
|
|
arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
|
|
|
|
arg2: { userId: null },
|
|
|
|
|
arg3: {
|
|
|
|
|
//Copied the required fields from the other integration.
|
|
|
|
|
//TODO: Verify whether we need to bring more information in.
|
|
|
|
|
id: { value: newCustomerNumber },
|
|
|
|
|
address: {
|
|
|
|
|
city: JobData.ownr_city,
|
|
|
|
|
country: null,
|
|
|
|
|
postalcode: JobData.ownr_zip,
|
|
|
|
|
stateOrProvince: JobData.ownr_st,
|
|
|
|
|
},
|
|
|
|
|
contactInfo: {
|
|
|
|
|
mainTelephoneNumber: { main: true, value: JobData.ownr_ph1 },
|
|
|
|
|
},
|
|
|
|
|
demographics: null,
|
|
|
|
|
name1: {
|
|
|
|
|
companyname: null,
|
|
|
|
|
firstName: JobData.ownr_fn,
|
|
|
|
|
fullname: null,
|
|
|
|
|
lastName: JobData.ownr_ln,
|
|
|
|
|
middleName: null,
|
|
|
|
|
nameType: "Person",
|
|
|
|
|
suffix: null,
|
|
|
|
|
title: null,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
);
|
|
|
|
|
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
|
|
|
|
const [
|
|
|
|
|
result, //rawResponse, soapheader, rawRequest
|
|
|
|
|
] = soapResponseCustomerInsertUpdate;
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
rawResponse,
|
|
|
|
|
`soapClientVehicleInsertUpdate.getVehIdsAsync response.`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`soapClientCustomerInsertUpdate.insertAsync Result ${JSON.stringify(
|
|
|
|
|
`soapClientVehicleInsertUpdate.getVehIdsAsync Result ${JSON.stringify(
|
|
|
|
|
result,
|
|
|
|
|
null,
|
|
|
|
|
2
|
|
|
|
|
)}`
|
|
|
|
|
);
|
|
|
|
|
const customer = result && result.return;
|
|
|
|
|
return customer;
|
|
|
|
|
|
|
|
|
|
const DmsVid = result && result.return && result.return[0];
|
|
|
|
|
return DmsVid;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
error.request,
|
|
|
|
|
`soapClientVehicleInsertUpdate.getVehIdsAsync reqest.`,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
error.response.data,
|
|
|
|
|
`soapClientVehicleInsertUpdate.getVehIdsAsync response.`,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"ERROR",
|
|
|
|
|
`Error in CreateCustomerInDms - ${JSON.stringify(error, null, 2)}`
|
|
|
|
|
`{1} Error in CalculateDmsVid - ${error}`
|
|
|
|
|
);
|
|
|
|
|
throw new Error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function GenerateCustomerNumberFromDms(socket, JobData) {
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`{10} Begin Generate Customer Number from DMS`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
async function QueryDmsVehicleById(socket, JobData, DMSVid) {
|
|
|
|
|
try {
|
|
|
|
|
const soapClientCustomerInsertUpdate = await soap.createClientAsync(
|
|
|
|
|
CdkWsdl.CustomerInsertUpdate
|
|
|
|
|
const soapClientVehicleInsertUpdate = await soap.createClientAsync(
|
|
|
|
|
CdkWsdl.VehicleInsertUpdate
|
|
|
|
|
);
|
|
|
|
|
const soapResponseCustomerInsertUpdate =
|
|
|
|
|
await soapClientCustomerInsertUpdate.getCustomerNumberAsync(
|
|
|
|
|
|
|
|
|
|
const soapResponseVehicleInsertUpdate =
|
|
|
|
|
await soapClientVehicleInsertUpdate.readAsync(
|
|
|
|
|
{
|
|
|
|
|
arg0: CDK_CREDENTIALS,
|
|
|
|
|
arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
|
|
|
|
arg2: { userId: null },
|
|
|
|
|
arg1: { id: JobData.bodyshop.cdk_dealerid },
|
|
|
|
|
arg2: {
|
|
|
|
|
fileType: "VEHICLES",
|
|
|
|
|
vehiclesVehicleId: DMSVid.vehiclesVehId,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
function (err, result, rawResponse, soapHeader, rawRequest) {
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
rawRequest,
|
|
|
|
|
`soapClientVehicleInsertUpdate.readAsync reqest.`,
|
|
|
|
|
!!err
|
|
|
|
|
);
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
rawResponse,
|
|
|
|
|
`soapClientVehicleInsertUpdate.readAsync response.`,
|
|
|
|
|
!!err
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
|
|
|
|
const [
|
|
|
|
|
result, //rawResponse, soapheader, rawRequest
|
|
|
|
|
] = soapResponseCustomerInsertUpdate;
|
|
|
|
|
CheckCdkResponseForError(socket, soapResponseVehicleInsertUpdate);
|
|
|
|
|
const [result, rawResponse, soapheader, rawRequest] =
|
|
|
|
|
soapResponseVehicleInsertUpdate;
|
|
|
|
|
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
rawRequest,
|
|
|
|
|
`soapClientVehicleInsertUpdate.readAsync reqest.`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`soapClientCustomerInsertUpdate.getCustomerNumberAsync Result ${JSON.stringify(
|
|
|
|
|
`soapClientVehicleInsertUpdate.readAsync Result ${JSON.stringify(
|
|
|
|
|
result,
|
|
|
|
|
null,
|
|
|
|
|
2
|
|
|
|
|
)}`
|
|
|
|
|
);
|
|
|
|
|
const customerNumber =
|
|
|
|
|
result && result.return && result.return.customerNumber;
|
|
|
|
|
return customerNumber;
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
rawResponse,
|
|
|
|
|
`soapClientVehicleInsertUpdate.readAsync response.`
|
|
|
|
|
);
|
|
|
|
|
const VehicleFromDMS = result && result.return && result.return.vehicle;
|
|
|
|
|
return VehicleFromDMS;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"ERROR",
|
|
|
|
|
`Error in GenerateCustomerNumberFromDms - ${JSON.stringify(
|
|
|
|
|
error,
|
|
|
|
|
`Error in QueryDmsVehicleById - ${error}`
|
|
|
|
|
);
|
|
|
|
|
throw new Error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function QueryDmsCustomerById(socket, JobData, CustomerId) {
|
|
|
|
|
try {
|
|
|
|
|
const soapClientCustomerInsertUpdate = await soap.createClientAsync(
|
|
|
|
|
CdkWsdl.CustomerInsertUpdate
|
|
|
|
|
);
|
|
|
|
|
const soapResponseCustomerInsertUpdate =
|
|
|
|
|
await soapClientCustomerInsertUpdate.readAsync({
|
|
|
|
|
arg0: CDK_CREDENTIALS,
|
|
|
|
|
arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
|
|
|
|
arg2: {
|
|
|
|
|
userId: CustomerId,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
|
|
|
|
const [result, rawResponse, soapheader, rawRequest] =
|
|
|
|
|
soapResponseCustomerInsertUpdate;
|
|
|
|
|
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
rawRequest,
|
|
|
|
|
`soapClientCustomerInsertUpdate.readAsync reqest.`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
rawResponse,
|
|
|
|
|
`soapClientCustomerInsertUpdate.readAsync response.`
|
|
|
|
|
);
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`soapClientCustomerInsertUpdate.readAsync Result ${JSON.stringify(
|
|
|
|
|
result,
|
|
|
|
|
null,
|
|
|
|
|
2
|
|
|
|
|
)}`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const CustomersFromDms =
|
|
|
|
|
result && result.return && result.return.customerParty;
|
|
|
|
|
return CustomersFromDms;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
error.request,
|
|
|
|
|
`soapClientCustomerInsertUpdate.readAsync reqest.`,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
error.response.data,
|
|
|
|
|
`soapClientCustomerInsertUpdate.readAsync response.`,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"ERROR",
|
|
|
|
|
`Error in QueryDmsCustomerById - ${error}`
|
|
|
|
|
);
|
|
|
|
|
throw new Error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -317,7 +304,7 @@ async function QueryDmsCustomerByName(socket, JobData) {
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`{8} Begin Read Customer from DMS using OWNER NAME: ${ownerName}`
|
|
|
|
|
`Begin Query DMS Customer by Name using: ${ownerName}`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
@@ -325,22 +312,30 @@ async function QueryDmsCustomerByName(socket, JobData) {
|
|
|
|
|
CdkWsdl.CustomerSearch
|
|
|
|
|
);
|
|
|
|
|
const soapResponseCustomerSearch =
|
|
|
|
|
await soapClientCustomerSearch.executeSearchAsync(
|
|
|
|
|
{
|
|
|
|
|
arg0: CDK_CREDENTIALS,
|
|
|
|
|
arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
|
|
|
|
arg2: {
|
|
|
|
|
verb: "EXACT",
|
|
|
|
|
key: ownerName,
|
|
|
|
|
},
|
|
|
|
|
await soapClientCustomerSearch.executeSearchAsync({
|
|
|
|
|
arg0: CDK_CREDENTIALS,
|
|
|
|
|
arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
|
|
|
|
arg2: {
|
|
|
|
|
verb: "EXACT",
|
|
|
|
|
key: ownerName,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
CheckCdkResponseForError(socket, soapResponseCustomerSearch);
|
|
|
|
|
const [
|
|
|
|
|
result, // rawResponse, soapheader, rawRequest
|
|
|
|
|
] = soapResponseCustomerSearch;
|
|
|
|
|
const [result, rawResponse, soapheader, rawRequest] =
|
|
|
|
|
soapResponseCustomerSearch;
|
|
|
|
|
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
rawRequest,
|
|
|
|
|
`soapClientCustomerSearch.executeSearchBulkAsync reqest.`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
rawResponse,
|
|
|
|
|
`soapClientCustomerSearch.executeSearchBulkAsync response.`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
@@ -350,110 +345,148 @@ async function QueryDmsCustomerByName(socket, JobData) {
|
|
|
|
|
2
|
|
|
|
|
)}`
|
|
|
|
|
);
|
|
|
|
|
const CustomersFromDms = result && result.return;
|
|
|
|
|
const CustomersFromDms = (result && result.return) || [];
|
|
|
|
|
return CustomersFromDms;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
error.request,
|
|
|
|
|
`soapClientCustomerSearch.executeSearchBulkAsync reqest.`,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CdkBase.createXmlEvent(
|
|
|
|
|
socket,
|
|
|
|
|
error.response.data,
|
|
|
|
|
`soapClientCustomerSearch.executeSearchBulkAsync response.`,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"ERROR",
|
|
|
|
|
`Error in QueryDmsCustomerByName - ${JSON.stringify(error, null, 2)}`
|
|
|
|
|
`Error in QueryDmsCustomerByName - ${error}`
|
|
|
|
|
);
|
|
|
|
|
throw new Error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function QueryDmsVehicleById(socket, JobData, DMSVid) {
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"DEBUG",
|
|
|
|
|
`{2}/{6} Begin Find Vehicle In DMS using DMSVid: ${DMSVid}`
|
|
|
|
|
);
|
|
|
|
|
// async function CreateCustomerInDms(socket, JobData, newCustomerNumber) {
|
|
|
|
|
// CdkBase.createLogEvent(socket, "DEBUG", `{11} Begin Create Customer in DMS`);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const soapClientVehicleInsertUpdate = await soap.createClientAsync(
|
|
|
|
|
CdkWsdl.VehicleInsertUpdate
|
|
|
|
|
);
|
|
|
|
|
// try {
|
|
|
|
|
// const soapClientCustomerInsertUpdate = await soap.createClientAsync(
|
|
|
|
|
// CdkWsdl.CustomerInsertUpdate
|
|
|
|
|
// );
|
|
|
|
|
// const soapResponseCustomerInsertUpdate =
|
|
|
|
|
// await soapClientCustomerInsertUpdate.insertAsync(
|
|
|
|
|
// {
|
|
|
|
|
// arg0: CDK_CREDENTIALS,
|
|
|
|
|
// arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
|
|
|
|
// arg2: { userId: null },
|
|
|
|
|
// arg3: {
|
|
|
|
|
// //Copied the required fields from the other integration.
|
|
|
|
|
// //TODO: Verify whether we need to bring more information in.
|
|
|
|
|
// id: { value: newCustomerNumber },
|
|
|
|
|
// address: {
|
|
|
|
|
// city: JobData.ownr_city,
|
|
|
|
|
// country: null,
|
|
|
|
|
// postalcode: JobData.ownr_zip,
|
|
|
|
|
// stateOrProvince: JobData.ownr_st,
|
|
|
|
|
// },
|
|
|
|
|
// contactInfo: {
|
|
|
|
|
// mainTelephoneNumber: { main: true, value: JobData.ownr_ph1 },
|
|
|
|
|
// },
|
|
|
|
|
// demographics: null,
|
|
|
|
|
// name1: {
|
|
|
|
|
// companyname: null,
|
|
|
|
|
// firstName: JobData.ownr_fn,
|
|
|
|
|
// fullname: null,
|
|
|
|
|
// lastName: JobData.ownr_ln,
|
|
|
|
|
// middleName: null,
|
|
|
|
|
// nameType: "Person",
|
|
|
|
|
// suffix: null,
|
|
|
|
|
// title: null,
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
|
|
const soapResponseVehicleInsertUpdate =
|
|
|
|
|
await soapClientVehicleInsertUpdate.readBulkAsync(
|
|
|
|
|
{
|
|
|
|
|
arg0: CDK_CREDENTIALS,
|
|
|
|
|
arg1: { id: JobData.bodyshop.cdk_dealerid },
|
|
|
|
|
arg2: {
|
|
|
|
|
fileType: "VEHICLES",
|
|
|
|
|
vehiclesVehicleId: DMSVid.vehiclesVehId,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
// {}
|
|
|
|
|
// );
|
|
|
|
|
// CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
|
|
|
|
// const [
|
|
|
|
|
// result, //rawResponse, soapheader, rawRequest
|
|
|
|
|
// ] = soapResponseCustomerInsertUpdate;
|
|
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
);
|
|
|
|
|
CheckCdkResponseForError(socket, soapResponseVehicleInsertUpdate);
|
|
|
|
|
const [
|
|
|
|
|
result, //rawResponse, soapheader, rawRequest
|
|
|
|
|
] = soapResponseVehicleInsertUpdate;
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`soapClientVehicleInsertUpdate.readBulkAsync Result ${JSON.stringify(
|
|
|
|
|
result,
|
|
|
|
|
null,
|
|
|
|
|
2
|
|
|
|
|
)}`
|
|
|
|
|
);
|
|
|
|
|
const VehicleFromDMS = result && result.return && result.return[0];
|
|
|
|
|
return VehicleFromDMS;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"ERROR",
|
|
|
|
|
`Error in QueryDmsVehicleById - ${JSON.stringify(error, null, 2)}`
|
|
|
|
|
);
|
|
|
|
|
throw new Error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// CdkBase.createLogEvent(
|
|
|
|
|
// socket,
|
|
|
|
|
// "TRACE",
|
|
|
|
|
// `soapClientCustomerInsertUpdate.insertAsync Result ${JSON.stringify(
|
|
|
|
|
// result,
|
|
|
|
|
// null,
|
|
|
|
|
// 2
|
|
|
|
|
// )}`
|
|
|
|
|
// );
|
|
|
|
|
// const customer = result && result.return;
|
|
|
|
|
// return customer;
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// CdkBase.createLogEvent(
|
|
|
|
|
// socket,
|
|
|
|
|
// "ERROR",
|
|
|
|
|
// `Error in CreateCustomerInDms - ${error}`
|
|
|
|
|
// );
|
|
|
|
|
// throw new Error(error);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
async function CalculateDmsVid(socket, JobData) {
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`{1} Begin Calculate DMS Vehicle ID using VIN: ${JobData.v_vin}`
|
|
|
|
|
);
|
|
|
|
|
// async function GenerateCustomerNumberFromDms(socket, JobData) {
|
|
|
|
|
// CdkBase.createLogEvent(
|
|
|
|
|
// socket,
|
|
|
|
|
// "DEBUG",
|
|
|
|
|
// `{10} Begin Generate Customer Number from DMS`
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const soapClientVehicleInsertUpdate = await soap.createClientAsync(
|
|
|
|
|
CdkWsdl.VehicleInsertUpdate
|
|
|
|
|
);
|
|
|
|
|
const soapResponseVehicleInsertUpdate =
|
|
|
|
|
await soapClientVehicleInsertUpdate.getVehIdsAsync(
|
|
|
|
|
{
|
|
|
|
|
arg0: CDK_CREDENTIALS,
|
|
|
|
|
arg1: { id: JobData.bodyshop.cdk_dealerid },
|
|
|
|
|
arg2: { VIN: JobData.v_vin },
|
|
|
|
|
},
|
|
|
|
|
// try {
|
|
|
|
|
// const soapClientCustomerInsertUpdate = await soap.createClientAsync(
|
|
|
|
|
// CdkWsdl.CustomerInsertUpdate
|
|
|
|
|
// );
|
|
|
|
|
// const soapResponseCustomerInsertUpdate =
|
|
|
|
|
// await soapClientCustomerInsertUpdate.getCustomerNumberAsync(
|
|
|
|
|
// {
|
|
|
|
|
// arg0: CDK_CREDENTIALS,
|
|
|
|
|
// arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
|
|
|
|
// arg2: { userId: null },
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
);
|
|
|
|
|
CheckCdkResponseForError(socket, soapResponseVehicleInsertUpdate);
|
|
|
|
|
const [
|
|
|
|
|
result, //rawResponse, soapheader, rawRequest
|
|
|
|
|
] = soapResponseVehicleInsertUpdate;
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"TRACE",
|
|
|
|
|
`soapClientVehicleInsertUpdate.searchIDsByVINAsync Result ${JSON.stringify(
|
|
|
|
|
result,
|
|
|
|
|
null,
|
|
|
|
|
2
|
|
|
|
|
)}`
|
|
|
|
|
);
|
|
|
|
|
const DmsVehicle = result && result.return && result.return[0];
|
|
|
|
|
return DmsVehicle;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
CdkBase.createLogEvent(
|
|
|
|
|
socket,
|
|
|
|
|
"ERROR",
|
|
|
|
|
`Error in CalculateDmsVid - ${JSON.stringify(error, null, 2)}`
|
|
|
|
|
);
|
|
|
|
|
throw new Error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// {}
|
|
|
|
|
// );
|
|
|
|
|
// CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
|
|
|
|
// const [
|
|
|
|
|
// result, //rawResponse, soapheader, rawRequest
|
|
|
|
|
// ] = soapResponseCustomerInsertUpdate;
|
|
|
|
|
|
|
|
|
|
// CdkBase.createLogEvent(
|
|
|
|
|
// socket,
|
|
|
|
|
// "TRACE",
|
|
|
|
|
// `soapClientCustomerInsertUpdate.getCustomerNumberAsync Result ${JSON.stringify(
|
|
|
|
|
// result,
|
|
|
|
|
// null,
|
|
|
|
|
// 2
|
|
|
|
|
// )}`
|
|
|
|
|
// );
|
|
|
|
|
// const customerNumber =
|
|
|
|
|
// result && result.return && result.return.customerNumber;
|
|
|
|
|
// return customerNumber;
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// CdkBase.createLogEvent(
|
|
|
|
|
// socket,
|
|
|
|
|
// "ERROR",
|
|
|
|
|
// `Error in GenerateCustomerNumberFromDms - ${JSON.stringify(
|
|
|
|
|
// error,
|
|
|
|
|
// null,
|
|
|
|
|
// 2
|
|
|
|
|
// )}`
|
|
|
|
|
// );
|
|
|
|
|
// throw new Error(error);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|