IO-233 Additional CDK Posting
This commit is contained in:
@@ -27,9 +27,10 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId }) {
|
||||
|
||||
useEffect(() => {
|
||||
if (socket.connected) {
|
||||
socket.emit("cdk-calculate-allocations", jobId, (ack) =>
|
||||
setAllocationsSummary(ack)
|
||||
);
|
||||
socket.emit("cdk-calculate-allocations", jobId, (ack) => {
|
||||
setAllocationsSummary(ack);
|
||||
socket.allocationsSummary = ack;
|
||||
});
|
||||
}
|
||||
}, [socket, socket.connected, jobId]);
|
||||
|
||||
|
||||
@@ -265,9 +265,24 @@ export function DmsPostForm({ bodyshop, socket, job }) {
|
||||
Dinero({ amount: Math.round((payer?.amount || 0) * 100) })
|
||||
);
|
||||
});
|
||||
const discrep = Dinero(job.job_totals.totals.total_repairs).subtract(
|
||||
totalAllocated
|
||||
);
|
||||
|
||||
const totals =
|
||||
socket.allocationsSummary &&
|
||||
socket.allocationsSummary.reduce(
|
||||
(acc, val) => {
|
||||
return {
|
||||
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
||||
totalCost: acc.totalCost.add(Dinero(val.cost)),
|
||||
};
|
||||
},
|
||||
{
|
||||
totalSale: Dinero(),
|
||||
totalCost: Dinero(),
|
||||
}
|
||||
);
|
||||
const discrep = totals
|
||||
? totals.totalSale.subtract(totalAllocated)
|
||||
: Dinero();
|
||||
return (
|
||||
<Space>
|
||||
<Statistic
|
||||
@@ -276,7 +291,7 @@ export function DmsPostForm({ bodyshop, socket, job }) {
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.subtotal")}
|
||||
value={Dinero(job.job_totals.totals.total_repairs).toFormat()}
|
||||
value={(totals ? totals.totalSale : Dinero()).toFormat()}
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.dms.notallocated")}
|
||||
|
||||
@@ -47,7 +47,7 @@ export const socket = SocketIO(
|
||||
|
||||
export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
|
||||
const { t } = useTranslation();
|
||||
const [logLevel, setLogLevel] = useState("TRACE");
|
||||
const [logLevel, setLogLevel] = useState("DEBUG");
|
||||
const [logs, setLogs] = useState([]);
|
||||
const search = queryString.parse(useLocation().search);
|
||||
const { jobId } = search;
|
||||
@@ -69,9 +69,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
|
||||
}, [t, setBreadcrumbs, setSelectedHeader]);
|
||||
|
||||
useEffect(() => {
|
||||
socket.on("connected", () => {
|
||||
console.log("Connected again.");
|
||||
});
|
||||
socket.on("connect", () => socket.emit("set-log-level", logLevel));
|
||||
socket.on("reconnect", () => {
|
||||
setLogs((logs) => {
|
||||
return [
|
||||
@@ -90,10 +88,6 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
|
||||
return [...logs, payload];
|
||||
});
|
||||
});
|
||||
|
||||
socket.connect();
|
||||
socket.emit("set-log-level", logLevel);
|
||||
|
||||
return () => {
|
||||
socket.removeAllListeners();
|
||||
socket.disconnect();
|
||||
|
||||
@@ -141,7 +141,9 @@ exports.default = async function (socket, jobid) {
|
||||
taxAllocations[key].sale.getAmount() > 0 ||
|
||||
taxAllocations[key].cost.getAmount() > 0
|
||||
)
|
||||
.map((key) => taxAllocations[key]),
|
||||
.map((key) => {
|
||||
return { ...taxAllocations[key], tax: key };
|
||||
}),
|
||||
];
|
||||
} catch (error) {
|
||||
CdkBase.createLogEvent(
|
||||
|
||||
@@ -11,6 +11,8 @@ const queries = require("../graphql-client/queries");
|
||||
const CdkBase = require("../web-sockets/web-socket");
|
||||
const CdkWsdl = require("./cdk-wsdl").default;
|
||||
const { CDK_CREDENTIALS, CheckCdkResponseForError } = require("./cdk-wsdl");
|
||||
const CalcualteAllocations = require("./cdk-calculate-allocations").default;
|
||||
|
||||
const moment = require("moment");
|
||||
|
||||
exports.default = async function (socket, { txEnvelope, jobid }) {
|
||||
@@ -44,7 +46,7 @@ exports.default = async function (socket, { txEnvelope, jobid }) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`{2.1} Querying the Vehicle using the DMSVid: ${socket.DMSVid}`
|
||||
`{2.1} Querying the Vehicle using the DMSVid: ${socket.DMSVid.vehiclesVehId}`
|
||||
);
|
||||
socket.DMSVeh = await QueryDmsVehicleById(socket, JobData, socket.DMSVid);
|
||||
|
||||
@@ -149,9 +151,9 @@ async function CdkSelectedCustomer(socket, selectedCustomerId) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`{5} Updating Service Vehicle History. *** THIS IS CURRENTLY BEING SKIPPED DUE TO AN INCORRECT CASHIER ID PROVIDED BY CDK ***`
|
||||
`{5} Updating Service Vehicle History. ***SKIPPING FOR NOW TO PRESERVE RO NUMBERS ***`
|
||||
);
|
||||
//await InsertServiceVehicleHistory(socket);
|
||||
//socket.DMSVehHistory = await InsertServiceVehicleHistory(socket);
|
||||
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
@@ -162,9 +164,53 @@ async function CdkSelectedCustomer(socket, selectedCustomerId) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`{6} Creating Transaction with ID ${socket.DMSTransHeader.transID}`
|
||||
`{6.1} Creating Transaction with ID ${socket.DMSTransHeader.transID}`
|
||||
);
|
||||
|
||||
socket.DMSBatchTxn = await InsertDmsBatchWip(socket);
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`{7} Attempting to post Transaction with ID ${socket.DMSTransHeader.transID}`
|
||||
);
|
||||
socket.DmsBatchTxnPost = await PostDmsBatchWip(socket);
|
||||
if (socket.DmsBatchTxnPost.code === "success") {
|
||||
//something
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`{8} Successfully posted sransaction to DMS.`
|
||||
);
|
||||
} else {
|
||||
//Get the error code
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`{7.1} Getting errors for Transaction ID ${socket.DMSTransHeader.transID}`
|
||||
);
|
||||
socket.DmsError = await QueryDmsErrWip(socket);
|
||||
//Delete the transaction
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`{7.2} Deleting Transaction ID ${socket.DMSTransHeader.transID}`
|
||||
);
|
||||
socket.DmsBatchTxnPost = await DeleteDmsWip(socket);
|
||||
//Emit the error in a nice way .
|
||||
|
||||
socket.DmsError.errMsg
|
||||
.split("|")
|
||||
.map(
|
||||
(e) =>
|
||||
e !== null &&
|
||||
e !== "" &&
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"ERROR",
|
||||
`Error(s) encountered in posting transaction. ${e}`
|
||||
)
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
@@ -792,8 +838,7 @@ async function InsertServiceVehicleHistory(socket) {
|
||||
`soapClientServiceHistoryInsert.serviceHistoryHeaderInsert response.`
|
||||
);
|
||||
CheckCdkResponseForError(socket, soapResponseServiceHistoryInsert);
|
||||
const VehicleFromDMS = result && result.return && result.return.vehicle;
|
||||
return VehicleFromDMS;
|
||||
return result && result.return;
|
||||
} catch (error) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
@@ -814,7 +859,8 @@ async function InsertDmsStartWip(socket) {
|
||||
arg0: CDK_CREDENTIALS,
|
||||
arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid },
|
||||
arg2: {
|
||||
acctgDate: moment().toISOString(),
|
||||
acctgDate: moment().format("YYYY-MM-DD"),
|
||||
//socket.JobData.invoice_date
|
||||
desc: socket.txEnvelope.story,
|
||||
docType: 10 || 7, //Need to check what this usually would be? Apparently it is almost always 10 or 7.
|
||||
//1 Cash Receipt , 2 Check, 3 Journal Voucher, 4 Parts invoice, 5 Payable Invoice, 6 Recurring Entry, 7 Repair Order Invoice, 8 Vehicle Purchase Invoice, 9 Vehicle Sale Invoice, 10 Other, 11 Payroll, 12 Finance Charge, 13 FMLR Invoice, 14 Parts Credit Memo, 15 Manufacturer Document, 16 FMLR Credit Memo
|
||||
@@ -874,16 +920,7 @@ async function InsertDmsBatchWip(socket) {
|
||||
arg0: CDK_CREDENTIALS,
|
||||
arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid },
|
||||
arg2: {
|
||||
acctgDate: moment().toISOString(),
|
||||
desc: socket.txEnvelope.story,
|
||||
docType: 10 || 7, //Need to check what this usually would be? Apparently it is almost always 10 or 7.
|
||||
//1 Cash Receipt , 2 Check, 3 Journal Voucher, 4 Parts invoice, 5 Payable Invoice, 6 Recurring Entry, 7 Repair Order Invoice, 8 Vehicle Purchase Invoice, 9 Vehicle Sale Invoice, 10 Other, 11 Payroll, 12 Finance Charge, 13 FMLR Invoice, 14 Parts Credit Memo, 15 Manufacturer Document, 16 FMLR Credit Memo
|
||||
m13Flag: 0,
|
||||
refer: socket.JobData.ro_number,
|
||||
srcCo: socket.JobData.bodyshop.cdk_configuration.srcco,
|
||||
srcJrnl: socket.txEnvelope.journal,
|
||||
userID: socket.JobData.bodyshop.cdk_configuration.cashierid, //Where is this coming from?
|
||||
//userName: "IMEX",
|
||||
transWIPs: await GenerateTransWips(socket),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -911,8 +948,8 @@ async function InsertDmsBatchWip(socket) {
|
||||
`soapClientAccountingGLInsertUpdate.doTransBatchWIPAsync response.`
|
||||
);
|
||||
CheckCdkResponseForError(socket, soapResponseAccountingGLInsertUpdate);
|
||||
const TransactionHeader = result && result.return;
|
||||
return TransactionHeader;
|
||||
const BatchWipResult = result && result.return;
|
||||
return BatchWipResult;
|
||||
} catch (error) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
@@ -922,3 +959,263 @@ async function InsertDmsBatchWip(socket) {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function GenerateTransWips(socket) {
|
||||
const allocations = await CalcualteAllocations(socket, socket.JobData.id);
|
||||
const wips = [];
|
||||
allocations.forEach((alloc) => {
|
||||
//Add the sale item
|
||||
if (alloc.sale.getAmount() > 0 && !alloc.tax) {
|
||||
const item = {
|
||||
acct: alloc.profitCenter.dms_acctnumber,
|
||||
cntl: socket.JobData.ro_number,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: alloc.sale.multiply(-1).getAmount(),
|
||||
postDesc: null,
|
||||
prod: null,
|
||||
statCnt: 1,
|
||||
transID: socket.DMSTransHeader.transID,
|
||||
trgtCoID: socket.JobData.bodyshop.cdk_configuration.srcco,
|
||||
};
|
||||
wips.push(item);
|
||||
}
|
||||
|
||||
if (alloc.cost.getAmount() > 0 && !alloc.tax) {
|
||||
const item = {
|
||||
acct: alloc.costCenter.dms_acctnumber,
|
||||
cntl: socket.JobData.ro_number,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: alloc.cost.getAmount(),
|
||||
postDesc: null,
|
||||
prod: null,
|
||||
statCnt: 1,
|
||||
transID: socket.DMSTransHeader.transID,
|
||||
trgtCoID: socket.JobData.bodyshop.cdk_configuration.srcco,
|
||||
};
|
||||
wips.push(item);
|
||||
|
||||
const itemWip = {
|
||||
acct: alloc.costCenter.dms_wip_acctnumber,
|
||||
cntl: socket.JobData.ro_number,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: alloc.cost.multiply(-1).getAmount(),
|
||||
postDesc: null,
|
||||
prod: null,
|
||||
statCnt: 1,
|
||||
transID: socket.DMSTransHeader.transID,
|
||||
trgtCoID: socket.JobData.bodyshop.cdk_configuration.srcco,
|
||||
};
|
||||
wips.push(itemWip);
|
||||
//Add to the WIP account.
|
||||
}
|
||||
|
||||
if (alloc.tax) {
|
||||
const item = {
|
||||
acct: alloc.costCenter.dms_acctnumber,
|
||||
cntl: socket.JobData.ro_number,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: alloc.cost.getAmount(),
|
||||
postDesc: null,
|
||||
prod: null,
|
||||
statCnt: 1,
|
||||
transID: socket.DMSTransHeader.transID,
|
||||
trgtCoID: socket.JobData.bodyshop.cdk_configuration.srcco,
|
||||
};
|
||||
|
||||
wips.push(item);
|
||||
const item2 = {
|
||||
acct: alloc.profitCenter.dms_acctnumber,
|
||||
cntl: socket.JobData.ro_number,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: alloc.sale.multiply(-1).getAmount(),
|
||||
postDesc: null,
|
||||
prod: null,
|
||||
statCnt: 1,
|
||||
transID: socket.DMSTransHeader.transID,
|
||||
trgtCoID: socket.JobData.bodyshop.cdk_configuration.srcco,
|
||||
};
|
||||
wips.push(item2);
|
||||
}
|
||||
});
|
||||
|
||||
socket.txEnvelope.payers.forEach((payer) => {
|
||||
const item = {
|
||||
acct: payer.dms_acctnumber,
|
||||
cntl: payer.controlnumber,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: Math.round(payer.amount * 100),
|
||||
postDesc: null,
|
||||
prod: null,
|
||||
statCnt: 1,
|
||||
transID: socket.DMSTransHeader.transID,
|
||||
trgtCoID: socket.JobData.bodyshop.cdk_configuration.srcco,
|
||||
};
|
||||
|
||||
wips.push(item);
|
||||
});
|
||||
|
||||
//should validate that the wips = 0
|
||||
|
||||
console.log(
|
||||
"WIPS TOTAL",
|
||||
wips.reduce((acc, val) => acc + val.postAmt, 0)
|
||||
);
|
||||
|
||||
return wips;
|
||||
}
|
||||
|
||||
async function PostDmsBatchWip(socket) {
|
||||
try {
|
||||
const soapClientAccountingGLInsertUpdate = await soap.createClientAsync(
|
||||
CdkWsdl.AccountingGLInsertUpdate
|
||||
);
|
||||
|
||||
const soapResponseAccountingGLInsertUpdate =
|
||||
await soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync({
|
||||
arg0: CDK_CREDENTIALS,
|
||||
arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid },
|
||||
arg2: {
|
||||
postWIP: { opCode: "P", transID: socket.DMSTransHeader.transID },
|
||||
},
|
||||
});
|
||||
|
||||
const [result, rawResponse, , rawRequest] =
|
||||
soapResponseAccountingGLInsertUpdate;
|
||||
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
rawRequest,
|
||||
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync request.`
|
||||
);
|
||||
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"TRACE",
|
||||
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync Result ${JSON.stringify(
|
||||
result,
|
||||
null,
|
||||
2
|
||||
)}`
|
||||
);
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
rawResponse,
|
||||
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync response.`
|
||||
);
|
||||
// CheckCdkResponseForError(socket, soapResponseAccountingGLInsertUpdate);
|
||||
const PostResult = result && result.return;
|
||||
return PostResult;
|
||||
} catch (error) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"ERROR",
|
||||
`Error in PostDmsBatchWip - ${error}`
|
||||
);
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function QueryDmsErrWip(socket) {
|
||||
try {
|
||||
const soapClientAccountingGLInsertUpdate = await soap.createClientAsync(
|
||||
CdkWsdl.AccountingGLInsertUpdate
|
||||
);
|
||||
|
||||
const soapResponseAccountingGLInsertUpdate =
|
||||
await soapClientAccountingGLInsertUpdate.doErrWIPAsync({
|
||||
arg0: CDK_CREDENTIALS,
|
||||
arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid },
|
||||
arg2: socket.DMSTransHeader.transID,
|
||||
});
|
||||
|
||||
const [result, rawResponse, , rawRequest] =
|
||||
soapResponseAccountingGLInsertUpdate;
|
||||
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
rawRequest,
|
||||
`soapClientAccountingGLInsertUpdate.doErrWIPAsync request.`
|
||||
);
|
||||
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"TRACE",
|
||||
`soapClientAccountingGLInsertUpdate.doErrWIPAsync Result ${JSON.stringify(
|
||||
result,
|
||||
null,
|
||||
2
|
||||
)}`
|
||||
);
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
rawResponse,
|
||||
`soapClientAccountingGLInsertUpdate.doErrWIPAsync response.`
|
||||
);
|
||||
CheckCdkResponseForError(socket, soapResponseAccountingGLInsertUpdate);
|
||||
const PostResult = result && result.return;
|
||||
return PostResult;
|
||||
} catch (error) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"ERROR",
|
||||
`Error in QueryDmsErrWip - ${error}`
|
||||
);
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
async function DeleteDmsWip(socket) {
|
||||
try {
|
||||
const soapClientAccountingGLInsertUpdate = await soap.createClientAsync(
|
||||
CdkWsdl.AccountingGLInsertUpdate
|
||||
);
|
||||
|
||||
const soapResponseAccountingGLInsertUpdate =
|
||||
await soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync({
|
||||
arg0: CDK_CREDENTIALS,
|
||||
arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid },
|
||||
arg2: {
|
||||
postWIP: { opCode: "D", transID: socket.DMSTransHeader.transID },
|
||||
},
|
||||
});
|
||||
|
||||
const [result, rawResponse, , rawRequest] =
|
||||
soapResponseAccountingGLInsertUpdate;
|
||||
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
rawRequest,
|
||||
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync request.`
|
||||
);
|
||||
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"TRACE",
|
||||
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync Result ${JSON.stringify(
|
||||
result,
|
||||
null,
|
||||
2
|
||||
)}`
|
||||
);
|
||||
CdkBase.createXmlEvent(
|
||||
socket,
|
||||
rawResponse,
|
||||
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync response.`
|
||||
);
|
||||
CheckCdkResponseForError(socket, soapResponseAccountingGLInsertUpdate);
|
||||
const PostResult = result && result.return;
|
||||
return PostResult;
|
||||
} catch (error) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"ERROR",
|
||||
`Error in PostDmsBatchWip - ${error}`
|
||||
);
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ exports.checkIndividualResult = checkIndividualResult;
|
||||
const cdkDomain = "https://uat-3pa.dmotorworks.com";
|
||||
exports.default = {
|
||||
// VehicleSearch: `${cdkDomain}/pip-vehicle/services/VehicleSearch?wsdl`,
|
||||
HelpDataBase: `${cdkDomain}/pip-help-database-location/services/HelpDatabaseLocation?wsdl`,
|
||||
AccountingGLInsertUpdate: `${cdkDomain}/pip-accounting-gl/services/AccountingGLInsertUpdate?wsdl`,
|
||||
VehicleInsertUpdate: `${cdkDomain}/pip-vehicle/services/VehicleInsertUpdate?wsdl`,
|
||||
CustomerInsertUpdate: `${cdkDomain}/pip-customer/services/CustomerInsertUpdate?wsdl`,
|
||||
|
||||
Reference in New Issue
Block a user