IO-233 CDK Get Makes & Taxes calculation.
This commit is contained in:
@@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import Dinero from "dinero.js";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
bodyshop: selectBodyshop,
|
||||
@@ -29,11 +30,13 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId }) {
|
||||
title: t("jobs.fields.dms.sale"),
|
||||
dataIndex: "sale",
|
||||
key: "sale",
|
||||
render: (text, record) => Dinero(record.sale).toFormat(),
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.cost"),
|
||||
dataIndex: "cost",
|
||||
key: "cost",
|
||||
render: (text, record) => Dinero(record.cost).toFormat(),
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.sale_dms_acctnumber"),
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import React, { useState } from "react";
|
||||
import { Modal, Button, Table } from "antd";
|
||||
import { Modal, Button, Table, Input } from "antd";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
bodyshop: selectBodyshop,
|
||||
@@ -14,26 +16,96 @@ export default connect(mapStateToProps, mapDispatchToProps)(DmsCdkMakes);
|
||||
|
||||
export function DmsCdkMakes({ bodyshop, form, socket }) {
|
||||
const [makesList, setMakesList] = useState([]);
|
||||
const [searchText, setSearchText] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [selectedModel, setSelectedModel] = useState(null);
|
||||
const { t } = useTranslation();
|
||||
const columns = [
|
||||
{
|
||||
title: t("jobs.fields.dms.makeFullName"),
|
||||
dataIndex: "makeFullName",
|
||||
key: "makeFullName",
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.modelFullName"),
|
||||
dataIndex: "modelFullName",
|
||||
key: "modelFullName",
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.makeCode"),
|
||||
dataIndex: "makeCode",
|
||||
key: "makeCode",
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.modelCode"),
|
||||
dataIndex: "modelCode",
|
||||
key: "modelCode",
|
||||
},
|
||||
];
|
||||
|
||||
const filteredMakes =
|
||||
searchText !== "" && searchText
|
||||
? makesList.filter(
|
||||
(make) =>
|
||||
searchText
|
||||
.split(" ")
|
||||
.some((v) =>
|
||||
make.makeFullName.toLowerCase().includes(v.toLowerCase())
|
||||
) ||
|
||||
searchText
|
||||
.split(" ")
|
||||
.some((v) =>
|
||||
make.modelFullName.toLowerCase().includes(v.toLowerCase())
|
||||
)
|
||||
)
|
||||
: makesList;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Modal visible={visible} onCancel={() => setVisible(false)}>
|
||||
{JSON.stringify(makesList, null, 2)}
|
||||
<Table loading={loading} data={makesList} />
|
||||
<Modal width={"90%"} visible={visible} onCancel={() => setVisible(false)}>
|
||||
<Table
|
||||
title={() => (
|
||||
<Input.Search
|
||||
onSearch={(val) => setSearchText(val)}
|
||||
placeholder={t("general.labels.search")}
|
||||
/>
|
||||
)}
|
||||
columns={columns}
|
||||
loading={loading}
|
||||
id="id"
|
||||
dataSource={filteredMakes}
|
||||
onRow={(record) => {
|
||||
return {
|
||||
onClick: setSelectedModel(record),
|
||||
};
|
||||
}}
|
||||
rowSelection={{
|
||||
onSelect: (record, selected, ...props) => {
|
||||
console.log(
|
||||
"🚀 ~ file: dms-cdk-makes.component.jsx ~ line 85 ~ record, selected, ...props",
|
||||
record,
|
||||
selected,
|
||||
...props
|
||||
);
|
||||
|
||||
setSelectedModel(record);
|
||||
},
|
||||
|
||||
type: "radio",
|
||||
selectedRowKeys: [selectedModel && selectedModel.id],
|
||||
}}
|
||||
/>
|
||||
</Modal>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setVisible(true);
|
||||
setLoading(true);
|
||||
socket.emit(
|
||||
"cdk-get-makes",
|
||||
(bodyshop.cdk_dealerid,
|
||||
(makes) => {
|
||||
setMakesList(makes);
|
||||
setLoading(false);
|
||||
})
|
||||
);
|
||||
socket.emit("cdk-get-makes", bodyshop.cdk_dealerid, (makes) => {
|
||||
console.log("Called back", makes);
|
||||
setMakesList(makes);
|
||||
setLoading(false);
|
||||
});
|
||||
}}
|
||||
>
|
||||
Get Makes
|
||||
|
||||
@@ -2336,6 +2336,25 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
{bodyshop.cdk_dealerid && (
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.responsibilitycenter_dms_acctnumber")}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
name={[
|
||||
"md_responsibility_centers",
|
||||
"taxes",
|
||||
"federal",
|
||||
"dms_acctnumber",
|
||||
]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
)}
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.responsibilitycenter_rate")}
|
||||
rules={[
|
||||
@@ -2415,6 +2434,25 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
{bodyshop.cdk_dealerid && (
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.responsibilitycenter_dms_acctnumber")}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
name={[
|
||||
"md_responsibility_centers",
|
||||
"taxes",
|
||||
"state",
|
||||
"dms_acctnumber",
|
||||
]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
)}
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.responsibilitycenter_rate")}
|
||||
rules={[
|
||||
@@ -2506,6 +2544,25 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
>
|
||||
<InputNumber precision={2} />
|
||||
</Form.Item>
|
||||
{bodyshop.cdk_dealerid && (
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.responsibilitycenter_dms_acctnumber")}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
name={[
|
||||
"md_responsibility_centers",
|
||||
"taxes",
|
||||
"local",
|
||||
"dms_acctnumber",
|
||||
]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
)}
|
||||
</LayoutFormRow>
|
||||
<LayoutFormRow header={<div>AR</div>}>
|
||||
{/* <Form.Item
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
import DmsActions from "./dms.types";
|
||||
|
||||
export const endLoading = (options) => ({
|
||||
// type: DmsActions.END_LOADING,
|
||||
payload: options,
|
||||
});
|
||||
@@ -1,20 +0,0 @@
|
||||
import DmsActionTypes from "./dms.types";
|
||||
|
||||
const INITIAL_STATE = {
|
||||
eventLog: [],
|
||||
};
|
||||
|
||||
const dmsReducer = (state = INITIAL_STATE, action) => {
|
||||
switch (action.type) {
|
||||
// case ApplicationActionTypes.SET_SELECTED_HEADER:
|
||||
// return {
|
||||
// ...state,
|
||||
// selectedHeader: action.payload,
|
||||
// };
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default dmsReducer;
|
||||
@@ -1,14 +0,0 @@
|
||||
import { all, call } from "redux-saga/effects";
|
||||
//import DmsActionTypes from "./dms.types";
|
||||
|
||||
export function* onCalculateScheduleLoad() {
|
||||
// yield takeLatest(
|
||||
// DmsActionTypes.CALCULATE_SCHEDULE_LOAD,
|
||||
// calculateScheduleLoad
|
||||
// );
|
||||
}
|
||||
export function* calculateScheduleLoad({ payload: end }) {}
|
||||
|
||||
export function* dmsSagas() {
|
||||
yield all([call()]);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import { createSelector } from "reselect";
|
||||
|
||||
const selectDms = (state) => state.dms;
|
||||
|
||||
export const selectEventLog = createSelector(
|
||||
[selectDms],
|
||||
(dms) => dms.eventLog
|
||||
);
|
||||
@@ -1,4 +0,0 @@
|
||||
const DmsActionTypes = {
|
||||
ADD_EVENT: "ADD_EVENT",
|
||||
};
|
||||
export default DmsActionTypes;
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -1002,6 +1002,7 @@ exports.GET_CDK_ALLOCATIONS = `
|
||||
cost_center
|
||||
id
|
||||
quantity
|
||||
applicable_taxes
|
||||
}
|
||||
}
|
||||
joblines(where: { removed: { _eq: false } }) {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user