IO-233 Add insert Job.
This commit is contained in:
@@ -1,10 +1,24 @@
|
||||
import { Button, Table } from "antd";
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { socket } from "../../pages/dms/dms.container";
|
||||
import PhoneFormatter from "../../utils/PhoneFormatter";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { alphaSort } from "../../utils/sorters";
|
||||
export default function DmsCustomerSelector() {
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
});
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(DmsCustomerSelector);
|
||||
|
||||
export function DmsCustomerSelector({ bodyshop }) {
|
||||
const { t } = useTranslation();
|
||||
const [customerList, setcustomerList] = useState([]);
|
||||
const [visible, setVisible] = useState(false);
|
||||
@@ -15,11 +29,24 @@ export default function DmsCustomerSelector() {
|
||||
setcustomerList(customerList);
|
||||
});
|
||||
|
||||
const onOk = () => {
|
||||
const onUseSelected = () => {
|
||||
setVisible(false);
|
||||
socket.emit("cdk-selected-customer", selectedCustomer);
|
||||
};
|
||||
|
||||
const onUseGeneric = () => {
|
||||
setVisible(false);
|
||||
socket.emit(
|
||||
"cdk-selected-customer",
|
||||
bodyshop.cdk_configuration.generic_customer_umber
|
||||
);
|
||||
};
|
||||
|
||||
const onCreateNew = () => {
|
||||
setVisible(false);
|
||||
socket.emit("cdk-selected-customer", null);
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t("dms.fields.name1"),
|
||||
@@ -27,28 +54,13 @@ export default function DmsCustomerSelector() {
|
||||
key: "name1",
|
||||
sorter: (a, b) => alphaSort(a.name1?.fullName, b.name1?.fullName),
|
||||
},
|
||||
{
|
||||
title: t("dms.fields.name2"),
|
||||
dataIndex: ["name2", "fullName"],
|
||||
key: "name2",
|
||||
sorter: (a, b) => alphaSort(a.name2?.fullName, b.name2?.fullName),
|
||||
},
|
||||
{
|
||||
title: t("dms.fields.phone"),
|
||||
dataIndex: ["contactInfo", "mainTelephoneNumber", "value"],
|
||||
key: "phone",
|
||||
render: (record, value) => (
|
||||
<PhoneFormatter>
|
||||
{record.contactInfo?.mainTelephoneNumber?.value}
|
||||
</PhoneFormatter>
|
||||
),
|
||||
},
|
||||
|
||||
{
|
||||
title: t("dms.fields.address"),
|
||||
//dataIndex: ["name2", "fullName"],
|
||||
key: "address",
|
||||
render: (record, value) =>
|
||||
`${record.address?.addressLine[0]}, ${record.address?.city} ${record.address?.stateOrProvince} ${record.address?.postalCode}`,
|
||||
`${record?.address?.addressLine[0]}, ${record.address?.city} ${record.address?.stateOrProvince} ${record.address?.postalCode}`,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -57,7 +69,21 @@ export default function DmsCustomerSelector() {
|
||||
<Table
|
||||
title={() => (
|
||||
<div>
|
||||
<Button onClick={onOk}>Select</Button>
|
||||
<Button onClick={onUseSelected}>
|
||||
{t("jobs.actions.dms.useselected")}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={onUseGeneric}
|
||||
disabled={
|
||||
!bodyshop.cdk_configuration &&
|
||||
!bodyshop.cdk_configuration.generic_customer_umber
|
||||
}
|
||||
>
|
||||
{t("jobs.actions.dms.usegeneric")}
|
||||
</Button>
|
||||
<Button onClick={onCreateNew}>
|
||||
{t("jobs.actions.dms.createnewcustomer")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
pagination={{ position: "top" }}
|
||||
|
||||
@@ -91,6 +91,12 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.dms.generic_customer_number")}
|
||||
name={["cdk_configuration", "generic_customer_number"]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</LayoutFormRow>
|
||||
<LayoutFormRow header={t("bodyshop.labels.dms.cdk.payers")}>
|
||||
<Form.List name={["cdk_configuration", "payers"]}>
|
||||
|
||||
@@ -218,7 +218,7 @@ export function JobsCloseComponent({ job, bodyshop, jobRO }) {
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber />
|
||||
<InputNumber disabled={jobRO} />
|
||||
</Form.Item>
|
||||
)}
|
||||
{bodyshop.cdk_dealerid && (
|
||||
@@ -244,7 +244,7 @@ export function JobsCloseComponent({ job, bodyshop, jobRO }) {
|
||||
}),
|
||||
]}
|
||||
>
|
||||
<InputNumber />
|
||||
<InputNumber disabled={jobRO} />
|
||||
</Form.Item>
|
||||
)}
|
||||
</LayoutFormRow>
|
||||
|
||||
@@ -91,6 +91,69 @@ exports.default = async function (socket, { jobid }) {
|
||||
}
|
||||
};
|
||||
|
||||
async function CdkSelectedCustomer(socket, selectedCustomerId) {
|
||||
try {
|
||||
if (selectedCustomerId) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"TRACE",
|
||||
`{3.1} Querying the Customer using Customer ID: ${selectedCustomerId}`
|
||||
);
|
||||
socket.DMSCust = await QueryDmsCustomerById(socket, selectedCustomerId);
|
||||
} else {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"TRACE",
|
||||
`{3.2} Generating a new customer ID.`
|
||||
);
|
||||
const newCustomerId = await GenerateDmsCustomerNumber(
|
||||
socket,
|
||||
socket.JobData
|
||||
);
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"TRACE",
|
||||
`{3.3} Inserting new customer with ID: ${newCustomerId}`
|
||||
);
|
||||
socket.DMSCust = await InsertDmsCustomer(
|
||||
socket,
|
||||
socket.JobData,
|
||||
newCustomerId
|
||||
);
|
||||
}
|
||||
|
||||
if (socket.DMSVid.newId === "Y") {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"TRACE",
|
||||
`{4.1} Inserting new vehicle with ID: ID ${socket.DMSVid.vehiclesVehId}`
|
||||
);
|
||||
} else {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"TRACE",
|
||||
`{4.2} Querying Existing Vehicle using ID ${socket.DMSVid.vehiclesVehId}`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"ERROR",
|
||||
`Error encountered in CdkSelectedCustomer. ${error}`
|
||||
);
|
||||
} finally {
|
||||
//Ensure we always insert logEvents
|
||||
//GQL to insert logevents.
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`Capturing log events to database.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
exports.CdkSelectedCustomer = CdkSelectedCustomer;
|
||||
|
||||
async function QueryJobData(socket, jobid) {
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `Querying job data for id ${jobid}`);
|
||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {});
|
||||
@@ -117,8 +180,7 @@ async function CalculateDmsVid(socket, JobData) {
|
||||
arg2: { VIN: JobData.v_vin },
|
||||
});
|
||||
CheckCdkResponseForError(socket, soapResponseVehicleInsertUpdate);
|
||||
const [result, rawResponse, soapheader, rawRequest] =
|
||||
soapResponseVehicleInsertUpdate;
|
||||
const [result, rawResponse, , rawRequest] = soapResponseVehicleInsertUpdate;
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
rawRequest,
|
||||
@@ -173,34 +235,16 @@ async function QueryDmsVehicleById(socket, JobData, DMSVid) {
|
||||
);
|
||||
|
||||
const soapResponseVehicleInsertUpdate =
|
||||
await soapClientVehicleInsertUpdate.readAsync(
|
||||
{
|
||||
arg0: CDK_CREDENTIALS,
|
||||
arg1: { id: JobData.bodyshop.cdk_dealerid },
|
||||
arg2: {
|
||||
fileType: "VEHICLES",
|
||||
vehiclesVehicleId: DMSVid.vehiclesVehId,
|
||||
},
|
||||
await soapClientVehicleInsertUpdate.readAsync({
|
||||
arg0: CDK_CREDENTIALS,
|
||||
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, soapResponseVehicleInsertUpdate);
|
||||
const [result, rawResponse, soapheader, rawRequest] =
|
||||
soapResponseVehicleInsertUpdate;
|
||||
const [result, rawResponse, , rawRequest] = soapResponseVehicleInsertUpdate;
|
||||
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
@@ -248,7 +292,7 @@ async function QueryDmsCustomerById(socket, JobData, CustomerId) {
|
||||
},
|
||||
});
|
||||
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
||||
const [result, rawResponse, soapheader, rawRequest] =
|
||||
const [result, rawResponse, , rawRequest] =
|
||||
soapResponseCustomerInsertUpdate;
|
||||
|
||||
CdkBase.createXmlEvent(
|
||||
@@ -321,8 +365,7 @@ async function QueryDmsCustomerByName(socket, JobData) {
|
||||
},
|
||||
});
|
||||
CheckCdkResponseForError(socket, soapResponseCustomerSearch);
|
||||
const [result, rawResponse, soapheader, rawRequest] =
|
||||
soapResponseCustomerSearch;
|
||||
const [result, rawResponse, , rawRequest] = soapResponseCustomerSearch;
|
||||
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
@@ -371,122 +414,156 @@ async function QueryDmsCustomerByName(socket, JobData) {
|
||||
}
|
||||
}
|
||||
|
||||
// async function CreateCustomerInDms(socket, JobData, newCustomerNumber) {
|
||||
// CdkBase.createLogEvent(socket, "DEBUG", `{11} Begin Create Customer in DMS`);
|
||||
async function GenerateDmsCustomerNumber(socket, JobData) {
|
||||
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 },
|
||||
},
|
||||
|
||||
// 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,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
{}
|
||||
);
|
||||
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
||||
const [result, rawResponse, , rawRequest] =
|
||||
soapResponseCustomerInsertUpdate;
|
||||
|
||||
// {}
|
||||
// );
|
||||
// CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
||||
// const [
|
||||
// result, //rawResponse, soapheader, rawRequest
|
||||
// ] = soapResponseCustomerInsertUpdate;
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
rawRequest,
|
||||
`soapClientCustomerInsertUpdate.getCustomerNumberAsync reqest.`
|
||||
);
|
||||
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
rawResponse,
|
||||
`soapClientCustomerInsertUpdate.getCustomerNumberAsync response.`
|
||||
);
|
||||
|
||||
// async function GenerateCustomerNumberFromDms(socket, JobData) {
|
||||
// CdkBase.createLogEvent(
|
||||
// socket,
|
||||
// "DEBUG",
|
||||
// `{10} Begin Generate Customer Number from DMS`
|
||||
// );
|
||||
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.createXmlEvent(
|
||||
socket,
|
||||
error.request,
|
||||
`soapClientCustomerInsertUpdate.getCustomerNumberAsync reqest.`,
|
||||
true
|
||||
);
|
||||
|
||||
// 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 },
|
||||
// },
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
error.response.data,
|
||||
`soapClientCustomerInsertUpdate.getCustomerNumberAsync response.`,
|
||||
true
|
||||
);
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"ERROR",
|
||||
`Error in GenerateDmsCustomerNumber - ${JSON.stringify(error, null, 2)}`
|
||||
);
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
// {}
|
||||
// );
|
||||
// CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
||||
// const [
|
||||
// result, //rawResponse, soapheader, rawRequest
|
||||
// ] = soapResponseCustomerInsertUpdate;
|
||||
async function InsertDmsCustomer(socket, JobData, newCustomerNumber) {
|
||||
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: JobData.ownr_co_nm,
|
||||
firstName: JobData.ownr_fn,
|
||||
fullname: null,
|
||||
lastName: JobData.ownr_ln,
|
||||
middleName: null,
|
||||
nameType: "Person",
|
||||
suffix: null,
|
||||
title: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
{}
|
||||
);
|
||||
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
||||
const [result, rawResponse, , rawRequest] =
|
||||
soapResponseCustomerInsertUpdate;
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
rawRequest,
|
||||
`soapClientCustomerInsertUpdate.insertAsync reqest.`
|
||||
);
|
||||
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
rawResponse,
|
||||
`soapClientCustomerInsertUpdate.insertAsync response.`
|
||||
);
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"TRACE",
|
||||
`soapClientCustomerInsertUpdate.insertAsync Result ${JSON.stringify(
|
||||
result,
|
||||
null,
|
||||
2
|
||||
)}`
|
||||
);
|
||||
const customer = result && result.return;
|
||||
return customer;
|
||||
} catch (error) {
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
error.request,
|
||||
`soapClientCustomerInsertUpdate.insertAsync reqest.`,
|
||||
true
|
||||
);
|
||||
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
error.response.data,
|
||||
`soapClientCustomerInsertUpdate.insertAsync response.`,
|
||||
true
|
||||
);
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"ERROR",
|
||||
`Error in InsertDmsCustomer - ${error}`
|
||||
);
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ require("dotenv").config({
|
||||
|
||||
const { io } = require("../../server");
|
||||
const { admin } = require("../firebase/firebase-handler");
|
||||
const CdkJobExport = require("../cdk/cdk-job-export").default;
|
||||
const {
|
||||
default: CdkJobExport,
|
||||
CdkSelectedCustomer,
|
||||
} = require("../cdk/cdk-job-export");
|
||||
const CdkGetMakes = require("../cdk/cdk-get-makes").default;
|
||||
const CdkCalculateAllocations =
|
||||
require("../cdk/cdk-calculate-allocations").default;
|
||||
@@ -60,7 +63,7 @@ io.on("connection", (socket) => {
|
||||
`User selected customer ID ${selectedCustomerId}`
|
||||
);
|
||||
socket.selectedCustomerId = selectedCustomerId;
|
||||
//CdkJobExport(socket, jobid);
|
||||
CdkSelectedCustomer(socket, selectedCustomerId);
|
||||
});
|
||||
|
||||
socket.on("cdk-get-makes", async (cdk_dealerid, callback) => {
|
||||
|
||||
Reference in New Issue
Block a user