IO-233 CDK

This commit is contained in:
Patrick Fic
2021-06-30 13:41:00 -07:00
parent 11af41f3c0
commit 105ecd4221
3 changed files with 298 additions and 22 deletions

View File

@@ -105,7 +105,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
<Tag color={LogLevelHierarchy(log.level)}>{log.level}</Tag>
<span>{moment(log.timestamp).format("MM/DD/YYYY HH:MM:ss")}</span>
<Divider type="vertical" />
<span>{log.message}</span>
<span style={{ whiteSpace: "pre-line" }}>{log.message}</span>
</Space>
</Timeline.Item>
))}

View File

@@ -13,6 +13,10 @@ const CdkWsdl = require("./cdk-wsdl").default;
const IMEX_CDK_USER = process.env.IMEX_CDK_USER,
IMEX_CDK_PASSWORD = process.env.IMEX_CDK_PASSWORD;
const CDK_CREDENTIALS = {
password: IMEX_CDK_PASSWORD,
username: IMEX_CDK_USER,
};
exports.default = async function (socket, jobid) {
socket.logEvents = [];
@@ -22,24 +26,94 @@ exports.default = async function (socket, jobid) {
"DEBUG",
`Received Job export request for id ${jobid}`
);
socket["cdk-job-export"] = {};
let clVFV, clADPV, clADPC;
const JobData = await QueryJobData(socket, jobid);
console.log(JSON.stringify(JobData, null, 2));
const DealerId = JobData.bodyshop.cdk_dealerid;
CdkBase.createLogEvent(
socket,
"TRACE",
`Dealer ID detected: ${JSON.stringify(DealerId)}`
);
// Begin Calculate VID from DMS {1}
await DetermineDMSVid(socket, JobData);
//{1} Begin Calculate DMS Vehicle Id
clVFV = await CalculateDmsVid(socket, JobData);
if (clVFV.newId === "Y") {
//{1.2} This is a new Vehicle ID
CdkBase.createLogEvent(
socket,
"DEBUG",
`{1.2} clVFV DMSVid does *not* exist. clVFV: ${JSON.stringify(
clVFV,
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.`
);
//Array
const strIDS = await FindCustomerIdFromDms(socket, JobData);
if (strIDS.length > 0) {
CdkBase.createLogEvent(socket, "DEBUG", `{8.2} Customer ID(s) found.`);
} else {
CdkBase.createLogEvent(
socket,
"DEBUG",
`{8.5} Customer ID(s) *not* found.`
);
}
} else {
CdkBase.createLogEvent(
socket,
"DEBUG",
`{1.2} clVFV DMSVid does exist. clVFV: ${JSON.stringify(
clVFV,
null,
2
)}`
);
//{2} Begin Find Vehicle in DMS
clADPV = await FindVehicleInDms(socket, JobData, clVFV); //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 (clADPV.AppErrorNo === "0") {
//Vehicle was found.
CdkBase.createLogEvent(
socket,
"DEBUG",
`{1.4} Vehicle was found in the DMS. clADPV: ${JSON.stringify(
clADPV,
null,
2
)}`
);
} else {
//Vehicle was not found.
CdkBase.createLogEvent(
socket,
"DEBUG",
`{6.4} Vehicle does not exist in DMS. Will have to create one. clVFV: ${JSON.stringify(
clVFV,
null,
2
)}`
);
}
}
} catch (error) {
CdkBase.createLogEvent(
socket,
"ERROR",
`Error encountered in JobExport. ${error}`
`Error encountered in CdkJobExport. ${error}`
);
} finally {
//Ensure we always insert logEvents
@@ -61,27 +135,200 @@ async function QueryJobData(socket, jobid) {
return result.jobs_by_pk;
}
async function DetermineDMSVid(socket, JobData) {
CdkBase.createLogEvent(socket, "TRACE", "{1} Begin Determine DMS VehicleID");
async function FindCustomerIdFromDms(socket, JobData) {
const ownerName = `${JobData.ownr_ln},${JobData.ownr_fn}`;
CdkBase.createLogEvent(
socket,
"DEBUG",
`{8} Begin Read Customer from DMS using OWNER NAME: ${ownerName}`
);
try {
//Create SOAP Request for <getVehIds/>
const soapClient = await soap.createClientAsync(CdkWsdl.VehicleSearch);
const result = await soapClient.searchIDsByVINAsync(
{
arg0: { password: IMEX_CDK_PASSWORD, username: IMEX_CDK_USER },
arg1: { id: JobData.bodyshop.cdk_dealerid },
arg2: { VIN: JobData.v_vin },
},
{}
const soapClientCustomerSearch = await soap.createClientAsync(
CdkWsdl.CustomerSearch
);
console.log(result);
const soapResponseCustomerSearch =
await soapClientCustomerSearch.executeSearchBulkAsync(
{
arg0: CDK_CREDENTIALS,
arg1: { id: JobData.bodyshop.cdk_dealerid },
arg2: {
verb: "EXACT",
key: ownerName,
},
},
{}
);
CheckCdkResponseForError(socket, soapResponseCustomerSearch);
const [result, rawResponse, soapheader, rawRequest] =
soapResponseCustomerSearch;
//result format
// return: [
// {
// code: 'success',
// carInvStockNo: '',
// errorLevel: '0',
// errorMessage: '',
// newId: 'Y',
// vehiclesVehId: 'HM263407'
// }
// ]
CdkBase.createLogEvent(
socket,
"TRACE",
`soapClientCustomerSearch.executeSearchBulkAsync Result ${JSON.stringify(
result,
null,
2
)}`
);
const CustomersFromDms = result && result.return;
return CustomersFromDms;
} catch (error) {
CdkBase.createLogEvent(
socket,
"ERROR",
`Error in DetermineDMSVid - ${JSON.stringify(error, null, 2)}`
`Error in FindCustomerIdFromDms - ${JSON.stringify(error, null, 2)}`
);
}
}
async function FindVehicleInDms(socket, JobData, clVFV) {
CdkBase.createLogEvent(
socket,
"DEBUG",
`{2}/{6} Begin Find Vehicle In DMS using clVFV: ${clVFV}`
);
try {
const soapClientVehicleInsertUpdate = await soap.createClientAsync(
CdkWsdl.VehicleInsertUpdate
);
const soapResponseVehicleInsertUpdate =
await soapClientVehicleInsertUpdate.readBulkAsync(
{
arg0: CDK_CREDENTIALS,
arg1: { id: JobData.bodyshop.cdk_dealerid },
arg2: {
fileType: "VEHICLES",
vehiclesVehicleId: clVFV.vehiclesVehId,
},
},
{}
);
CheckCdkResponseForError(socket, soapResponseVehicleInsertUpdate);
const [result, rawResponse, soapheader, rawRequest] =
soapResponseVehicleInsertUpdate;
//result format
// return: [
// {
// code: 'success',
// carInvStockNo: '',
// errorLevel: '0',
// errorMessage: '',
// newId: 'Y',
// vehiclesVehId: 'HM263407'
// }
// ]
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 FindVehicleInDms - ${JSON.stringify(error, null, 2)}`
);
}
}
async function CalculateDmsVid(socket, JobData) {
CdkBase.createLogEvent(
socket,
"TRACE",
`{1} Begin Calculate DMS Vehicle ID using VIN: ${JobData.v_vin}`
);
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 },
},
{}
);
CheckCdkResponseForError(socket, soapResponseVehicleInsertUpdate);
const [result, rawResponse, soapheader, rawRequest] =
soapResponseVehicleInsertUpdate;
//result format
// return: [
// {
// code: 'success',
// carInvStockNo: '',
// errorLevel: '0',
// errorMessage: '',
// newId: 'Y',
// vehiclesVehId: 'HM263407'
// }
// ]
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)}`
);
}
}
function CheckCdkResponseForError(socket, soapResponse) {
const ResultToCheck = Array.isArray(soapResponse[0].return)
? soapResponse[0].return[0]
: soapResponse[0].return;
if (ResultToCheck.errorLevel === 0 || ResultToCheck.errorLevel === "0")
//TODO: Verify that this is the best way to detect errors.
return;
else {
CdkBase.createLogEvent(
socket,
"ERROR",
`Error detected in CDK Response - ${JSON.stringify(
ResultToCheck,
null,
2
)}`
);
throw {
errorLevel: ResultToCheck.errorLevel,
errorMessage: ResultToCheck.errorMessage,
};
}
}

View File

@@ -1,4 +1,33 @@
const path = require("path");
require("dotenv").config({
path: path.resolve(
process.cwd(),
`.env.${process.env.NODE_ENV || "development"}`
),
});
// const cdkDomain =
// process.env.NODE_ENV === "production"
// ? "https://3pa.dmotorworks.com"
// : "https://uat-3pa.dmotorworks.com";
const cdkDomain = "https://uat-3pa.dmotorworks.com";
exports.default = {
VehicleSearch:
"https://uat-3pa.dmotorworks.com/pip-vehicle/services/VehicleSearch?wsdl",
// VehicleSearch: `${cdkDomain}/pip-vehicle/services/VehicleSearch?wsdl`,
VehicleInsertUpdate: `${cdkDomain}/pip-vehicle/services/VehicleInsertUpdate?wsdl`,
CustomerInsertUpdate: `${cdkDomain}/pip-customer/services/CustomerInsertUpdate?wsdl`,
CustomerSearch: `${cdkDomain}/pip-customer/services/CustomerSearch?wsdl`,
};
// The following login credentials will be used for all PIPs and all environments (User Acceptance Testing and Production).
// Only the URLs will change from https://uat-3pa.dmoto... to https://3pa.dmoto... or https://api-dit.connect... to https://api.connect...
// Accounting GL/Accounting GL WIP Update - https://uat-3pa.dmotorworks.com/pip-accounting-gl/services/AccountingGLInsertUpdate?wsdl
// Customer Insert Update - https://uat-3pa.dmotorworks.com/pip-customer/services/CustomerInsertUpdate?wsdl
// Help Database Location - https://uat-3pa.dmotorworks.com/pip-help-database-location/services/HelpDatabaseLocation?wsdl
// Parts Inventory Insert Update - https://uat-3pa.dmotorworks.com/pip-parts-inventory/services/PartsInventoryInsertUpdate?wsdl
// Purchase Order Insert - https://uat-3pa.dmotorworks.com/pip-purchase-order/services/PurchaseOrderInsert?wsdl
// Repair Order MLS Insert Update - https://uat-3pa.dmotorworks.com/pip-repair-order-mls/services/RepairOrderMLSInsertUpdate?wsdl
// Repair Order Parts Insert Update - https://uat-3pa.dmotorworks.com/pip-repair-order-parts/services/RepairOrderPartsInsertUpdate?wsdl
// Service History Insert - https://uat-3pa.dmotorworks.com/pip-service-history-insert/services/ServiceHistoryInsert?wsdl
// Service Repair Order Update - https://uat-3pa.dmotorworks.com/pip-service-repair-order/services/ServiceRepairOrderUpdate?wsdl
// Service Vehicle Insert Update - https://uat-3pa.dmotorworks.com/pip-vehicle/services/VehicleInsertUpdate?wsdl