IO-117 WIP PBS
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Button, Table, Col , Checkbox} from "antd";
|
import { Button, Table, Col, Checkbox } from "antd";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
@@ -23,15 +23,26 @@ export function DmsCustomerSelector({ bodyshop }) {
|
|||||||
const [customerList, setcustomerList] = useState([]);
|
const [customerList, setcustomerList] = useState([]);
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const [selectedCustomer, setSelectedCustomer] = useState(null);
|
const [selectedCustomer, setSelectedCustomer] = useState(null);
|
||||||
|
const [dmsType, setDmsType] = useState("cdk");
|
||||||
|
|
||||||
socket.on("cdk-select-customer", (customerList, callback) => {
|
socket.on("cdk-select-customer", (customerList, callback) => {
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
setDmsType("cdk");
|
||||||
setcustomerList(customerList);
|
setcustomerList(customerList);
|
||||||
});
|
});
|
||||||
|
socket.on("pbs-select-customer", (customerList, callback) => {
|
||||||
|
setVisible(true);
|
||||||
|
setDmsType("pbs");
|
||||||
|
setcustomerList(customerList);
|
||||||
|
console.log(
|
||||||
|
"🚀 ~ file: dms-customer-selector.component.jsx ~ line 37 ~ socket.on ~ customerList",
|
||||||
|
customerList
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
const onUseSelected = () => {
|
const onUseSelected = () => {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
socket.emit("cdk-selected-customer", selectedCustomer);
|
socket.emit(`${dmsType}-selected-customer`, selectedCustomer);
|
||||||
setSelectedCustomer(null);
|
setSelectedCustomer(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -50,7 +61,7 @@ export function DmsCustomerSelector({ bodyshop }) {
|
|||||||
setSelectedCustomer(null);
|
setSelectedCustomer(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const columns = [
|
const cdkColumns = [
|
||||||
{
|
{
|
||||||
title: t("jobs.fields.dms.id"),
|
title: t("jobs.fields.dms.id"),
|
||||||
dataIndex: ["id", "value"],
|
dataIndex: ["id", "value"],
|
||||||
@@ -60,13 +71,14 @@ export function DmsCustomerSelector({ bodyshop }) {
|
|||||||
title: t("jobs.fields.dms.vinowner"),
|
title: t("jobs.fields.dms.vinowner"),
|
||||||
dataIndex: "vinOwner",
|
dataIndex: "vinOwner",
|
||||||
key: "vinOwner",
|
key: "vinOwner",
|
||||||
render: (text, record) => <Checkbox disabled checked={record.vinOwner}/>
|
render: (text, record) => <Checkbox disabled checked={record.vinOwner} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("jobs.fields.dms.name1"),
|
title: t("jobs.fields.dms.name1"),
|
||||||
dataIndex: ["name1", "fullName"],
|
dataIndex: ["name1", "fullName"],
|
||||||
key: "name1",
|
key: "name1",
|
||||||
sorter: (a, b) => alphaSort(a.name1?.fullName, b.name1?.fullName),
|
sorter: (a, b) =>
|
||||||
|
alphaSort(a.name1 && a.name1.fullName, b.name1 && b.name1.fullName),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -74,11 +86,43 @@ export function DmsCustomerSelector({ bodyshop }) {
|
|||||||
//dataIndex: ["name2", "fullName"],
|
//dataIndex: ["name2", "fullName"],
|
||||||
key: "address",
|
key: "address",
|
||||||
render: (record, value) =>
|
render: (record, value) =>
|
||||||
`${record?.address?.addressLine[0]}, ${record.address?.city} ${record.address?.stateOrProvince} ${record.address?.postalCode}`,
|
`${record.address && record.address.addressLine[0]}, ${
|
||||||
|
record.address && record.address.city
|
||||||
|
} ${record.address && record.address.stateOrProvince} ${
|
||||||
|
record.address && record.address.postalCode
|
||||||
|
}`,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!visible) return <></>;
|
const pbsColumns = [
|
||||||
|
{
|
||||||
|
title: t("jobs.fields.dms.id"),
|
||||||
|
dataIndex: "ContactId",
|
||||||
|
key: "ContactId",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("jobs.fields.dms.vinowner"),
|
||||||
|
dataIndex: "vinOwner",
|
||||||
|
key: "vinOwner",
|
||||||
|
render: (text, record) => <Checkbox disabled checked={record.vinOwner} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("jobs.fields.dms.name1"),
|
||||||
|
key: "name1",
|
||||||
|
sorter: (a, b) => alphaSort(a.LastName, b.LastName),
|
||||||
|
render: (text, record) =>
|
||||||
|
`${record.FirstName || ""} ${record.LastName || ""}`,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
title: t("jobs.fields.dms.address"),
|
||||||
|
key: "address",
|
||||||
|
render: (record, value) =>
|
||||||
|
`${record.Address}, ${record.City} ${record.State} ${record.ZipCode}`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!visible) return null;
|
||||||
return (
|
return (
|
||||||
<Col span={24}>
|
<Col span={24}>
|
||||||
<Table
|
<Table
|
||||||
@@ -104,13 +148,17 @@ export function DmsCustomerSelector({ bodyshop }) {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
pagination={{ position: "top" }}
|
pagination={{ position: "top" }}
|
||||||
columns={columns}
|
columns={dmsType === "cdk" ? cdkColumns : pbsColumns}
|
||||||
rowKey={(record) => record.id.value}
|
rowKey={(record) =>
|
||||||
|
dmsType === "cdk" ? record.id.value : record.ContactId
|
||||||
|
}
|
||||||
dataSource={customerList}
|
dataSource={customerList}
|
||||||
//onChange={handleTableChange}
|
//onChange={handleTableChange}
|
||||||
rowSelection={{
|
rowSelection={{
|
||||||
onSelect: (props) => {
|
onSelect: (record) => {
|
||||||
setSelectedCustomer(props.id.value);
|
setSelectedCustomer(
|
||||||
|
dmsType === "cdk" ? record.id.value : record.ContactId
|
||||||
|
);
|
||||||
},
|
},
|
||||||
type: "radio",
|
type: "radio",
|
||||||
selectedRowKeys: [selectedCustomer],
|
selectedRowKeys: [selectedCustomer],
|
||||||
|
|||||||
@@ -30,16 +30,52 @@ exports.default = async function (socket, { txEnvelope, jobid }) {
|
|||||||
const JobData = await QueryJobData(socket, jobid);
|
const JobData = await QueryJobData(socket, jobid);
|
||||||
socket.JobData = JobData;
|
socket.JobData = JobData;
|
||||||
|
|
||||||
socket.DmsVeh = await QueryVehicleFromDms(socket);
|
//Query for the Vehicle record to get the associated customer.
|
||||||
|
// socket.DmsVeh = await QueryVehicleFromDms(socket);
|
||||||
|
//Todo: Need to validate the lines and methods below.
|
||||||
|
if (socket.DmsVeh && socket.DmsVeh.CustomerRef) {
|
||||||
|
//Get the associated customer from the Vehicle Record.
|
||||||
|
socket.DMSVehCustomer = await QueryCustomerBycodeFromDms(
|
||||||
|
socket,
|
||||||
|
socket.DmsVeh.CustomerRef
|
||||||
|
);
|
||||||
|
}
|
||||||
|
socket.DMSCustList = await QueryCustomersFromDms(socket);
|
||||||
|
|
||||||
|
socket.emit("pbs-select-customer", [
|
||||||
|
...(socket.DMSVehCustomer
|
||||||
|
? [{ ...socket.DMSVehCustomer, vinOwner: true }]
|
||||||
|
: []),
|
||||||
|
...socket.DMSCustList,
|
||||||
|
]);
|
||||||
|
} catch (error) {
|
||||||
|
CdkBase.createLogEvent(
|
||||||
|
socket,
|
||||||
|
"ERROR",
|
||||||
|
`Error encountered in PbsJobExport. ${error}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.PbsSelectedCustomer = async function PbsSelectedCustomer(
|
||||||
|
socket,
|
||||||
|
selectedCustomerId
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
CdkBase.createLogEvent(
|
||||||
|
socket,
|
||||||
|
"DEBUG",
|
||||||
|
`User selected customer ${selectedCustomerId || "NEW"}`
|
||||||
|
);
|
||||||
|
|
||||||
socket.DmsCustList = await QueryCustomersFromDms(socket);
|
|
||||||
//Upsert the contact information as per Wafaa's Email.
|
//Upsert the contact information as per Wafaa's Email.
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"DEBUG",
|
"DEBUG",
|
||||||
`Upserting contact information to DMS for ${socket.JobData.ownr_fn} ${socket.JobData.ownr_ln} ${socket.JobData.ownr_co_nm}`
|
`Upserting contact information to DMS for ${socket.JobData.ownr_fn} ${socket.JobData.ownr_ln} ${socket.JobData.ownr_co_nm}`
|
||||||
);
|
);
|
||||||
const ownerRef = await UpsertContactData(socket);
|
const ownerRef = await UpsertContactData(socket, selectedCustomerId);
|
||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"DEBUG",
|
"DEBUG",
|
||||||
@@ -56,28 +92,29 @@ exports.default = async function (socket, { txEnvelope, jobid }) {
|
|||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"ERROR",
|
"ERROR",
|
||||||
`Error encountered in PbsJobExport. ${error}`
|
`Error encountered in CdkSelectedCustomer. ${error}`
|
||||||
);
|
);
|
||||||
|
await InsertFailedExportLog(socket, error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function CheckForErrors(socket, response) {
|
async function CheckForErrors(socket, response) {
|
||||||
if (response.WasSuccessful) {
|
if (response.WasSuccessful === undefined || response.WasSuccessful === true) {
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"DEBUG",
|
"DEBUG",
|
||||||
`Succesful response from DMS:. ${response.Message}`
|
`Succesful response from DMS. ${response.Message || ""}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"ERROR",
|
"ERROR",
|
||||||
`Error received from DMS:. ${response.Message}`
|
`Error received from DMS: ${response.Message}`
|
||||||
);
|
);
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"TRACE",
|
||||||
`Error received from DMS:. ${JSON.stringify(response)}`
|
`Error received from DMS: ${JSON.stringify(response)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,7 +181,9 @@ async function QueryCustomersFromDms(socket) {
|
|||||||
SerialNumber: socket.JobData.bodyshop.pbs_serialnumber,
|
SerialNumber: socket.JobData.bodyshop.pbs_serialnumber,
|
||||||
//ContactId: "00000000000000000000000000000000",
|
//ContactId: "00000000000000000000000000000000",
|
||||||
ContactCode: socket.JobData.owner.accountingid,
|
ContactCode: socket.JobData.owner.accountingid,
|
||||||
FirstName: socket.JobData.ownr_fn,
|
FirstName: socket.JobData.ownr_co_nm
|
||||||
|
? socket.JobData.ownr_co_nm
|
||||||
|
: socket.JobData.ownr_fn,
|
||||||
LastName: socket.JobData.ownr_ln,
|
LastName: socket.JobData.ownr_ln,
|
||||||
PhoneNumber: socket.JobData.ownr_ph1,
|
PhoneNumber: socket.JobData.ownr_ph1,
|
||||||
// EmailAddress: "String",
|
// EmailAddress: "String",
|
||||||
@@ -160,7 +199,43 @@ async function QueryCustomersFromDms(socket) {
|
|||||||
{ auth: PBS_CREDENTIALS }
|
{ auth: PBS_CREDENTIALS }
|
||||||
);
|
);
|
||||||
CheckForErrors(socket, CustomerGetResponse);
|
CheckForErrors(socket, CustomerGetResponse);
|
||||||
return CustomerGetResponse;
|
return CustomerGetResponse && CustomerGetResponse.Contacts;
|
||||||
|
} catch (error) {
|
||||||
|
CdkBase.createLogEvent(
|
||||||
|
socket,
|
||||||
|
"ERROR",
|
||||||
|
`Error in QueryCustomersFromDms - ${error}`
|
||||||
|
);
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function QueryCustomerBycodeFromDms(socket, CustomerRef) {
|
||||||
|
try {
|
||||||
|
const { data: CustomerGetResponse } = await axios.post(
|
||||||
|
PBS_ENDPOINTS.ContactGet,
|
||||||
|
{
|
||||||
|
SerialNumber: socket.JobData.bodyshop.pbs_serialnumber,
|
||||||
|
ContactId: CustomerRef,
|
||||||
|
//ContactCode: socket.JobData.owner.accountingid,
|
||||||
|
//FirstName: socket.JobData.ownr_co_nm
|
||||||
|
// ? socket.JobData.ownr_co_nm
|
||||||
|
// : socket.JobData.ownr_fn,
|
||||||
|
//LastName: socket.JobData.ownr_ln,
|
||||||
|
//PhoneNumber: socket.JobData.ownr_ph1,
|
||||||
|
// EmailAddress: "String",
|
||||||
|
// ModifiedSince: "0001-01-01T00:00:00.0000000Z",
|
||||||
|
// ModifiedUntil: "0001-01-01T00:00:00.0000000Z",
|
||||||
|
// ContactIdList: ["00000000000000000000000000000000"],
|
||||||
|
// IncludeInactive: false,
|
||||||
|
// PayableAccount: "String",
|
||||||
|
// ReceivableAccount: "String",
|
||||||
|
// DriverLicense: "String",
|
||||||
|
// ZipCode: "String",
|
||||||
|
},
|
||||||
|
{ auth: PBS_CREDENTIALS }
|
||||||
|
);
|
||||||
|
CheckForErrors(socket, CustomerGetResponse);
|
||||||
|
return CustomerGetResponse && CustomerGetResponse.Contacts;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
@@ -171,14 +246,14 @@ async function QueryCustomersFromDms(socket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function UpsertContactData(socket) {
|
async function UpsertContactData(socket, selectedCustomerId) {
|
||||||
try {
|
try {
|
||||||
const { data: ContactChangeResponse } = await axios.post(
|
const { data: ContactChangeResponse } = await axios.post(
|
||||||
PBS_ENDPOINTS.ContactChange,
|
PBS_ENDPOINTS.ContactChange,
|
||||||
{
|
{
|
||||||
ContactInfo: {
|
ContactInfo: {
|
||||||
// Id: socket.JobData.owner.id,
|
// Id: socket.JobData.owner.id,
|
||||||
ContactId: socket.JobData.owner.id,
|
...(selectedCustomerId ? { ContactId: selectedCustomerId } : {}),
|
||||||
SerialNumber: socket.JobData.bodyshop.pbs_serialnumber,
|
SerialNumber: socket.JobData.bodyshop.pbs_serialnumber,
|
||||||
Code: socket.JobData.owner.accountingid,
|
Code: socket.JobData.owner.accountingid,
|
||||||
...(socket.JobData.ownr_co_nm
|
...(socket.JobData.ownr_co_nm
|
||||||
@@ -531,3 +606,20 @@ async function MarkJobExported(socket, jobid) {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function InsertFailedExportLog(socket, error) {
|
||||||
|
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {});
|
||||||
|
const result = await client
|
||||||
|
.setHeaders({ Authorization: `Bearer ${socket.handshake.auth.token}` })
|
||||||
|
.request(queries.INSERT_EXPORT_LOG, {
|
||||||
|
log: {
|
||||||
|
bodyshopid: socket.JobData.bodyshop.id,
|
||||||
|
jobid: socket.JobData.id,
|
||||||
|
successful: false,
|
||||||
|
message: [error],
|
||||||
|
useremail: socket.user.email,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const CdkCalculateAllocations =
|
|||||||
require("../cdk/cdk-calculate-allocations").default;
|
require("../cdk/cdk-calculate-allocations").default;
|
||||||
const { isArray } = require("lodash");
|
const { isArray } = require("lodash");
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
const PbsExportJob = require("../accounting/pbs/pbs-job-export").default;
|
const {default: PbsExportJob, PbsSelectedCustomer} = require("../accounting/pbs/pbs-job-export");
|
||||||
|
|
||||||
io.use(function (socket, next) {
|
io.use(function (socket, next) {
|
||||||
try {
|
try {
|
||||||
@@ -113,6 +113,15 @@ io.on("connection", (socket) => {
|
|||||||
socket.on("pbs-export-job", (jobid) => {
|
socket.on("pbs-export-job", (jobid) => {
|
||||||
PbsExportJob(socket, jobid);
|
PbsExportJob(socket, jobid);
|
||||||
});
|
});
|
||||||
|
socket.on("pbs-selected-customer", (selectedCustomerId) => {
|
||||||
|
createLogEvent(
|
||||||
|
socket,
|
||||||
|
"DEBUG",
|
||||||
|
`User selected customer ID ${selectedCustomerId}`
|
||||||
|
);
|
||||||
|
socket.selectedCustomerId = selectedCustomerId;
|
||||||
|
PbsSelectedCustomer(socket, selectedCustomerId);
|
||||||
|
});
|
||||||
//End PBS
|
//End PBS
|
||||||
|
|
||||||
socket.on("disconnect", () => {
|
socket.on("disconnect", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user