IO-233 CDK Get Makes & Taxes calculation.

This commit is contained in:
Patrick Fic
2021-08-13 15:08:44 -07:00
parent b68de683b0
commit 7d9fd06b6d
14 changed files with 240 additions and 109 deletions

View File

@@ -23,6 +23,30 @@ exports.default = async function (socket, jobid) {
const job = await QueryJobData(socket, jobid);
const { bodyshop } = job;
const taxAllocations = {
local: {
center: bodyshop.md_responsibility_centers.taxes.local.name,
sale: Dinero(job.job_totals.totals.local_tax),
cost: Dinero(),
profitCenter: bodyshop.md_responsibility_centers.taxes.local,
costCenter: bodyshop.md_responsibility_centers.taxes.local,
},
state: {
center: bodyshop.md_responsibility_centers.taxes.state.name,
sale: Dinero(job.job_totals.totals.state_tax),
cost: Dinero(),
profitCenter: bodyshop.md_responsibility_centers.taxes.state,
costCenter: bodyshop.md_responsibility_centers.taxes.state,
},
federal: {
center: bodyshop.md_responsibility_centers.taxes.federal.name,
sale: Dinero(job.job_totals.totals.federal_tax),
cost: Dinero(),
profitCenter: bodyshop.md_responsibility_centers.taxes.federal,
costCenter: bodyshop.md_responsibility_centers.taxes.federal,
},
};
const profitCenterHash = job.joblines.reduce((acc, val) => {
//Check the Parts Assignment
if (val.profitcenter_part) {
@@ -55,28 +79,44 @@ exports.default = async function (socket, jobid) {
bill_val.billlines.map((line_val) => {
if (!bill_acc[line_val.cost_center])
bill_acc[line_val.cost_center] = Dinero();
const lineDinero = Dinero({
amount: Math.round((line_val.actual_cost || 0) * 100),
})
.multiply(line_val.quantity)
.multiply(bill_val.is_credit_memo ? -1 : 1);
bill_acc[line_val.cost_center] =
bill_acc[line_val.cost_center].add(lineDinero);
//Add appropriate tax amounts.
const {
applicable_taxes: { local, state, federal },
} = line_val;
if (local) {
taxAllocations.local.cost = taxAllocations.local.cost.add(
lineDinero.percentage(bill_val.local_tax_rate || 0)
);
}
if (state) {
taxAllocations.state.cost = taxAllocations.state.cost.add(
lineDinero.percentage(bill_val.state_tax_rate || 0)
);
}
if (federal) {
taxAllocations.federal.cost = taxAllocations.federal.cost.add(
lineDinero.percentage(bill_val.federal_tax_rate || 0)
);
}
bill_acc[line_val.cost_center] = bill_acc[line_val.cost_center].add(
Dinero({
amount: Math.round((line_val.actual_cost || 0) * 100),
})
.multiply(line_val.quantity)
.multiply(bill_val.is_credit_memo ? -1 : 1)
);
return null;
});
return bill_acc;
}, {});
console.log(
"🚀 ~ file: dms-allocations-summary.component.jsx ~ line 69 ~ costCenterHash",
costCenterHash
);
return _.union(
const jobAllocations = _.union(
Object.keys(profitCenterHash),
Object.keys(costCenterHash)
).map((key) => {
console.log("Key", key);
const profitCenter = bodyshop.md_responsibility_centers.profits.find(
(c) => c.name === key
);
@@ -86,16 +126,23 @@ exports.default = async function (socket, jobid) {
return {
center: key,
sale: profitCenterHash[key]
? profitCenterHash[key].toFormat()
: Dinero().toFormat(),
cost: costCenterHash[key]
? costCenterHash[key].toFormat()
: Dinero().toFormat(),
sale: profitCenterHash[key] ? profitCenterHash[key] : Dinero(),
cost: costCenterHash[key] ? costCenterHash[key] : Dinero(),
profitCenter,
costCenter,
};
});
return [
...jobAllocations,
...Object.keys(taxAllocations)
.filter(
(key) =>
taxAllocations[key].sale.getAmount() > 0 ||
taxAllocations[key].cost.getAmount() > 0
)
.map((key) => taxAllocations[key]),
];
} catch (error) {
CdkBase.createLogEvent(
socket,

View File

@@ -13,11 +13,8 @@ const CdkWsdl = require("./cdk-wsdl").default;
const logger = require("../utils/logger");
const Dinero = require("dinero.js");
const _ = require("lodash");
const {
CDK_CREDENTIALS,
CheckCdkResponseForError,
checkIndividualResult,
} = require("./cdk-wsdl");
const { CDK_CREDENTIALS, CheckCdkResponseForError } = require("./cdk-wsdl");
const { performance } = require("perf_hooks");
exports.default = async function (socket, cdk_dealerid) {
try {
@@ -26,9 +23,7 @@ exports.default = async function (socket, cdk_dealerid) {
"DEBUG",
`Getting makes and models list from CDK.`
);
const t = await GetCdkMakes(socket, cdk_dealerid);
console.log(t);
return [];
return await GetCdkMakes(socket, cdk_dealerid);
} catch (error) {
CdkBase.createLogEvent(
socket,
@@ -42,11 +37,13 @@ async function GetCdkMakes(socket, cdk_dealerid) {
CdkBase.createLogEvent(socket, "TRACE", `{1} Begin GetCDkMakes WSDL Call`);
try {
const soapClientVehicleSearch = await soap.createClientAsync(
CdkWsdl.VehicleSearch
const soapClientVehicleInsert = await soap.createClientAsync(
CdkWsdl.VehicleInsert
);
const start = performance.now();
const soapResponseVehicleSearch =
await soapClientVehicleSearch.getVehIdsAsync(
await soapClientVehicleInsert.getMakeModelAsync(
{
arg0: CDK_CREDENTIALS,
arg1: { id: cdk_dealerid },
@@ -58,22 +55,23 @@ async function GetCdkMakes(socket, cdk_dealerid) {
const [
result, //rawResponse, soapheader, rawRequest
] = soapResponseVehicleSearch;
const end = performance.now();
CdkBase.createLogEvent(
socket,
"TRACE",
`soapResponseVehicleSearch.searchIDsByVINAsync Result ${JSON.stringify(
result,
null,
2
)}`
`soapClientVehicleInsert.getMakeModelAsync Result Length ${
result.return.length
} and took ${end - start}ms`
);
const DmsVehicle = result && result.return && result.return[0];
return DmsVehicle;
return result.return.map((element, index) => {
return { id: index, ...element };
});
} catch (error) {
CdkBase.createLogEvent(
socket,
"ERROR",
`Error in CalculateDmsVid - ${JSON.stringify(error, null, 2)}`
`Error in GetCdkMakes - ${JSON.stringify(error, null, 2)}`
);
throw new Error(error);
}

View File

@@ -11,11 +11,7 @@ const queries = require("../graphql-client/queries");
const CdkBase = require("../web-sockets/web-socket");
const CdkWsdl = require("./cdk-wsdl").default;
const logger = require("../utils/logger");
const {
CDK_CREDENTIALS,
CheckCdkResponseForError,
checkIndividualResult,
} = require("./cdk-wsdl");
const { CDK_CREDENTIALS, CheckCdkResponseForError } = require("./cdk-wsdl");
exports.default = async function (socket, jobid) {
socket.logEvents = [];

View File

@@ -82,6 +82,7 @@ exports.default = {
CustomerInsertUpdate: `${cdkDomain}/pip-customer/services/CustomerInsertUpdate?wsdl`,
CustomerSearch: `${cdkDomain}/pip-customer/services/CustomerSearch?wsdl`,
VehicleSearch: `${cdkDomain}/pip-vehicle/services/VehicleSearch?wsdl`,
VehicleInsert: `${cdkDomain}/pip-vehicle/services/VehicleInsertUpdate?wsdl`,
};
// The following login credentials will be used for all PIPs and all environments (User Acceptance Testing and Production).

View File

@@ -1002,6 +1002,7 @@ exports.GET_CDK_ALLOCATIONS = `
cost_center
id
quantity
applicable_taxes
}
}
joblines(where: { removed: { _eq: false } }) {

View File

@@ -64,8 +64,16 @@ io.on("connection", (socket) => {
});
socket.on("cdk-get-makes", async (cdk_dealerid, callback) => {
const makes = await CdkGetMakes(socket, cdk_dealerid);
callback(makes);
try {
const makes = await CdkGetMakes(socket, cdk_dealerid);
callback(makes);
} catch (error) {
createLogEvent(
socket,
"ERROR",
`Error in cdk-get-makes WS call. ${JSON.stringify(error, null, 2)}`
);
}
});
socket.on("cdk-calculate-allocations", async (jobid, callback) => {