Compare commits
53 Commits
rrScratch1
...
rrScratch3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
288c8e6347 | ||
|
|
56738f800c | ||
|
|
bedf4f2c02 | ||
|
|
6032ff0e5d | ||
|
|
77268d5f5b | ||
|
|
1b3abf17ec | ||
|
|
0ef68afa0c | ||
|
|
12b4ae3b8d | ||
|
|
3cfd445894 | ||
|
|
b510eec9aa | ||
|
|
e92bab0455 | ||
|
|
4de3d3c6fc | ||
|
|
e5eac0933f | ||
|
|
a3c71fdfc0 | ||
|
|
a6b3bd573e | ||
|
|
18373fc865 | ||
|
|
3ae8ed8496 | ||
|
|
78750d3d96 | ||
|
|
90edf94fee | ||
|
|
3507e60356 | ||
|
|
43feb16950 | ||
|
|
827f1c2c40 | ||
|
|
58f5ed1ce7 | ||
|
|
c1e3c08652 | ||
|
|
d885bac7d0 | ||
|
|
065fb72677 | ||
|
|
ddc6141480 | ||
|
|
fa7da3cad0 | ||
|
|
f1bad01cec | ||
|
|
3d6498f938 | ||
|
|
7bc137fa79 | ||
|
|
dafe9de753 | ||
|
|
78a8474a24 | ||
|
|
910d388e05 | ||
|
|
9faad53b99 | ||
|
|
3b07055d5a | ||
|
|
ec29a22984 | ||
|
|
2b1836d450 | ||
|
|
ae7d150a6c | ||
|
|
123066f1cd | ||
|
|
b2184a2d11 | ||
|
|
a153cca3c0 | ||
|
|
35c7c32c8e | ||
|
|
9b1c8fa72b | ||
|
|
6d6b64ebc3 | ||
|
|
c954695d3c | ||
|
|
338d8e2136 | ||
|
|
6674206b4f | ||
|
|
c46ad521d1 | ||
|
|
66e5bec4d8 | ||
|
|
0d3161ef84 | ||
|
|
1cd11bdc18 | ||
|
|
9cce2696e2 |
@@ -30,7 +30,7 @@ Send a JSON object with one or more of the following fields to update:
|
|||||||
- `email` (string, shop's email, not user email)
|
- `email` (string, shop's email, not user email)
|
||||||
- `timezone` (string)
|
- `timezone` (string)
|
||||||
- `phone` (string)
|
- `phone` (string)
|
||||||
- `logo_img_path` (object, e.g. `{ src, width, height, headerMargin }`)
|
- `logo_img_path` (string)
|
||||||
|
|
||||||
Any fields not included in the request body will remain unchanged.
|
Any fields not included in the request body will remain unchanged.
|
||||||
|
|
||||||
@@ -50,12 +50,7 @@ Content-Type: application/json
|
|||||||
"email": "shop@example.com",
|
"email": "shop@example.com",
|
||||||
"timezone": "America/Chicago",
|
"timezone": "America/Chicago",
|
||||||
"phone": "555-123-4567",
|
"phone": "555-123-4567",
|
||||||
"logo_img_path": {
|
"logo_img_path": "https://example.com/logo.png"
|
||||||
"src": "https://example.com/logo.png",
|
|
||||||
"width": "200",
|
|
||||||
"height": "100",
|
|
||||||
"headerMargin": 10
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
1075
client/package-lock.json
generated
1075
client/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"proxy": "http://localhost:4000",
|
"proxy": "http://localhost:4000",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@amplitude/analytics-browser": "^2.30.1",
|
"@amplitude/analytics-browser": "^2.31.3",
|
||||||
"@ant-design/pro-layout": "^7.22.6",
|
"@ant-design/pro-layout": "^7.22.6",
|
||||||
"@apollo/client": "^3.13.9",
|
"@apollo/client": "^3.13.9",
|
||||||
"@emotion/is-prop-valid": "^1.4.0",
|
"@emotion/is-prop-valid": "^1.4.0",
|
||||||
@@ -19,11 +19,11 @@
|
|||||||
"@firebase/firestore": "^4.9.2",
|
"@firebase/firestore": "^4.9.2",
|
||||||
"@firebase/messaging": "^0.12.22",
|
"@firebase/messaging": "^0.12.22",
|
||||||
"@jsreport/browser-client": "^3.1.0",
|
"@jsreport/browser-client": "^3.1.0",
|
||||||
"@reduxjs/toolkit": "^2.10.1",
|
"@reduxjs/toolkit": "^2.11.0",
|
||||||
"@sentry/cli": "^2.58.2",
|
"@sentry/cli": "^2.58.2",
|
||||||
"@sentry/react": "^9.43.0",
|
"@sentry/react": "^9.43.0",
|
||||||
"@sentry/vite-plugin": "^4.6.0",
|
"@sentry/vite-plugin": "^4.6.1",
|
||||||
"@splitsoftware/splitio-react": "^2.6.0",
|
"@splitsoftware/splitio-react": "^2.6.1",
|
||||||
"@tanem/react-nprogress": "^5.0.56",
|
"@tanem/react-nprogress": "^5.0.56",
|
||||||
"antd": "^5.28.1",
|
"antd": "^5.28.1",
|
||||||
"apollo-link-logger": "^2.0.1",
|
"apollo-link-logger": "^2.0.1",
|
||||||
@@ -33,16 +33,16 @@
|
|||||||
"classnames": "^2.5.1",
|
"classnames": "^2.5.1",
|
||||||
"css-box-model": "^1.2.1",
|
"css-box-model": "^1.2.1",
|
||||||
"dayjs": "^1.11.19",
|
"dayjs": "^1.11.19",
|
||||||
"dayjs-business-days2": "^1.3.1",
|
"dayjs-business-days2": "^1.3.2",
|
||||||
"dinero.js": "^1.9.1",
|
"dinero.js": "^1.9.1",
|
||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"env-cmd": "^10.1.0",
|
"env-cmd": "^10.1.0",
|
||||||
"exifr": "^7.1.3",
|
"exifr": "^7.1.3",
|
||||||
"graphql": "^16.12.0",
|
"graphql": "^16.12.0",
|
||||||
"i18next": "^25.6.2",
|
"i18next": "^25.7.1",
|
||||||
"i18next-browser-languagedetector": "^8.2.0",
|
"i18next-browser-languagedetector": "^8.2.0",
|
||||||
"immutability-helper": "^3.1.1",
|
"immutability-helper": "^3.1.1",
|
||||||
"libphonenumber-js": "^1.12.26",
|
"libphonenumber-js": "^1.12.31",
|
||||||
"lightningcss": "^1.30.2",
|
"lightningcss": "^1.30.2",
|
||||||
"logrocket": "^9.0.2",
|
"logrocket": "^9.0.2",
|
||||||
"markerjs2": "^2.32.7",
|
"markerjs2": "^2.32.7",
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
"normalize-url": "^8.1.0",
|
"normalize-url": "^8.1.0",
|
||||||
"object-hash": "^3.0.0",
|
"object-hash": "^3.0.0",
|
||||||
"phone": "^3.1.67",
|
"phone": "^3.1.67",
|
||||||
"posthog-js": "^1.294.0",
|
"posthog-js": "^1.299.0",
|
||||||
"prop-types": "^15.8.1",
|
"prop-types": "^15.8.1",
|
||||||
"query-string": "^9.3.1",
|
"query-string": "^9.3.1",
|
||||||
"raf-schd": "^4.0.3",
|
"raf-schd": "^4.0.3",
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
"react-resizable": "^3.0.5",
|
"react-resizable": "^3.0.5",
|
||||||
"react-router-dom": "^6.30.0",
|
"react-router-dom": "^6.30.0",
|
||||||
"react-sticky": "^6.0.3",
|
"react-sticky": "^6.0.3",
|
||||||
"react-virtuoso": "^4.14.1",
|
"react-virtuoso": "^4.16.1",
|
||||||
"recharts": "^2.15.2",
|
"recharts": "^2.15.2",
|
||||||
"redux": "^5.0.1",
|
"redux": "^5.0.1",
|
||||||
"redux-actions": "^3.0.3",
|
"redux-actions": "^3.0.3",
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
"redux-saga": "^1.4.2",
|
"redux-saga": "^1.4.2",
|
||||||
"redux-state-sync": "^3.1.4",
|
"redux-state-sync": "^3.1.4",
|
||||||
"reselect": "^5.1.1",
|
"reselect": "^5.1.1",
|
||||||
"sass": "^1.94.0",
|
"sass": "^1.94.2",
|
||||||
"socket.io-client": "^4.8.1",
|
"socket.io-client": "^4.8.1",
|
||||||
"styled-components": "^6.1.19",
|
"styled-components": "^6.1.19",
|
||||||
"subscriptions-transport-ws": "^0.11.0",
|
"subscriptions-transport-ws": "^0.11.0",
|
||||||
@@ -140,8 +140,8 @@
|
|||||||
"@emotion/babel-plugin": "^11.13.5",
|
"@emotion/babel-plugin": "^11.13.5",
|
||||||
"@emotion/react": "^11.14.0",
|
"@emotion/react": "^11.14.0",
|
||||||
"@eslint/js": "^9.39.1",
|
"@eslint/js": "^9.39.1",
|
||||||
"@playwright/test": "^1.56.1",
|
"@playwright/test": "^1.57.0",
|
||||||
"@sentry/webpack-plugin": "^4.6.0",
|
"@sentry/webpack-plugin": "^4.6.1",
|
||||||
"@testing-library/dom": "^10.4.1",
|
"@testing-library/dom": "^10.4.1",
|
||||||
"@testing-library/jest-dom": "^6.9.1",
|
"@testing-library/jest-dom": "^6.9.1",
|
||||||
"@testing-library/react": "^16.3.0",
|
"@testing-library/react": "^16.3.0",
|
||||||
@@ -153,19 +153,19 @@
|
|||||||
"eslint-plugin-react": "^7.37.5",
|
"eslint-plugin-react": "^7.37.5",
|
||||||
"globals": "^15.15.0",
|
"globals": "^15.15.0",
|
||||||
"jsdom": "^26.0.0",
|
"jsdom": "^26.0.0",
|
||||||
"memfs": "^4.51.0",
|
"memfs": "^4.51.1",
|
||||||
"os-browserify": "^0.3.0",
|
"os-browserify": "^0.3.0",
|
||||||
"playwright": "^1.56.1",
|
"playwright": "^1.57.0",
|
||||||
"react-error-overlay": "^6.1.0",
|
"react-error-overlay": "^6.1.0",
|
||||||
"redux-logger": "^3.0.6",
|
"redux-logger": "^3.0.6",
|
||||||
"source-map-explorer": "^2.5.3",
|
"source-map-explorer": "^2.5.3",
|
||||||
"vite": "^7.2.2",
|
"vite": "^7.2.6",
|
||||||
"vite-plugin-babel": "^1.3.2",
|
"vite-plugin-babel": "^1.3.2",
|
||||||
"vite-plugin-eslint": "^1.8.1",
|
"vite-plugin-eslint": "^1.8.1",
|
||||||
"vite-plugin-node-polyfills": "^0.24.0",
|
"vite-plugin-node-polyfills": "^0.24.0",
|
||||||
"vite-plugin-pwa": "^1.1.0",
|
"vite-plugin-pwa": "^1.2.0",
|
||||||
"vite-plugin-style-import": "^2.0.0",
|
"vite-plugin-style-import": "^2.0.0",
|
||||||
"vitest": "^3.2.4",
|
"vitest": "^3.2.4",
|
||||||
"workbox-window": "^7.3.0"
|
"workbox-window": "^7.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -425,6 +425,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dms-equal-height-col {
|
||||||
|
display: flex; // make the Col a flex container
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the direct child is an AntD Card, make it fill the column */
|
||||||
|
.dms-equal-height-col > .ant-card {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Optional: if you want the card body to fill vertically too */
|
||||||
|
.dms-equal-height-col > .ant-card .ant-card-body {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
//.rbc-time-header-gutter {
|
//.rbc-time-header-gutter {
|
||||||
// padding: 0;
|
// padding: 0;
|
||||||
//}
|
//}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { CalculateBillTotal } from "../bill-form/bill-form.totals.utility";
|
|||||||
import { handleUpload as handleLocalUpload } from "../documents-local-upload/documents-local-upload.utility";
|
import { handleUpload as handleLocalUpload } from "../documents-local-upload/documents-local-upload.utility";
|
||||||
import { handleUpload } from "../documents-upload/documents-upload.utility";
|
import { handleUpload } from "../documents-upload/documents-upload.utility";
|
||||||
import { handleUpload as handleUploadToImageProxy } from "../documents-upload-imgproxy/documents-upload-imgproxy.utility";
|
import { handleUpload as handleUploadToImageProxy } from "../documents-upload-imgproxy/documents-upload-imgproxy.utility";
|
||||||
|
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
billEnterModal: selectBillEnterModal,
|
billEnterModal: selectBillEnterModal,
|
||||||
@@ -450,7 +451,9 @@ function BillEnterModalContainer({ billEnterModal, toggleModalVisible, bodyshop,
|
|||||||
setEnterAgain(false);
|
setEnterAgain(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<BillFormContainer form={form} disableInvNumber={billEnterModal.context.disableInvNumber} />
|
<RbacWrapper action="bills:enter">
|
||||||
|
<BillFormContainer form={form} disableInvNumber={billEnterModal.context.disableInvNumber} />
|
||||||
|
</RbacWrapper>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -142,17 +142,37 @@ export default function JobLifecycleDashboardComponent({ data, bodyshop, ...card
|
|||||||
title={t("job_lifecycle.content.legend_title")}
|
title={t("job_lifecycle.content.legend_title")}
|
||||||
style={{ marginTop: "10px" }}
|
style={{ marginTop: "10px" }}
|
||||||
>
|
>
|
||||||
<div>
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
flexWrap: "wrap",
|
||||||
|
gap: 8
|
||||||
|
}}
|
||||||
|
>
|
||||||
{lifecycleData.summations.map((key) => (
|
{lifecycleData.summations.map((key) => (
|
||||||
<Tag key={key.status} color={key.color} style={{ width: "13vh", padding: "4px", margin: "4px" }}>
|
<Tag
|
||||||
|
key={key.status}
|
||||||
|
color={key.color}
|
||||||
|
style={{
|
||||||
|
// IMPORTANT: let the tag grow with its content
|
||||||
|
width: "auto",
|
||||||
|
padding: 0,
|
||||||
|
margin: 0,
|
||||||
|
display: "inline-flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
boxSizing: "border-box"
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
aria-label={`${key.status} | ${key.roundedPercentage} | ${key.humanReadable}`}
|
aria-label={`${key.status} | ${key.roundedPercentage} | ${key.humanReadable}`}
|
||||||
title={`${key.status} | ${key.roundedPercentage} | ${key.humanReadable}`}
|
title={`${key.status} | ${key.roundedPercentage} | ${key.humanReadable}`}
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: "var(--tag-wrapper-bg)",
|
backgroundColor: "var(--tag-wrapper-bg)",
|
||||||
color: "var(--tag-wrapper-text)",
|
color: "var(--tag-wrapper-text)",
|
||||||
padding: "4px",
|
padding: "4px 8px",
|
||||||
textAlign: "center"
|
textAlign: "center",
|
||||||
|
whiteSpace: "nowrap" // keep it on one line while letting the pill expand
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{key.status} [{lifecycleData.statusCounts[key.status]}] ({key.roundedPercentage})
|
{key.status} [{lifecycleData.statusCounts[key.status]}] ({key.roundedPercentage})
|
||||||
|
|||||||
@@ -24,10 +24,11 @@ export default connect(mapStateToProps, mapDispatchToProps)(DmsAllocationsSummar
|
|||||||
* @param bodyshop
|
* @param bodyshop
|
||||||
* @param jobId
|
* @param jobId
|
||||||
* @param title
|
* @param title
|
||||||
|
* @param onAllocationsChange
|
||||||
* @returns {JSX.Element}
|
* @returns {JSX.Element}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
export function DmsAllocationsSummary({ mode, socket, bodyshop, jobId, title }) {
|
export function DmsAllocationsSummary({ mode, socket, bodyshop, jobId, title, onAllocationsChange }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [allocationsSummary, setAllocationsSummary] = useState([]);
|
const [allocationsSummary, setAllocationsSummary] = useState([]);
|
||||||
|
|
||||||
@@ -48,11 +49,17 @@ export function DmsAllocationsSummary({ mode, socket, bodyshop, jobId, title })
|
|||||||
setAllocationsSummary(list);
|
setAllocationsSummary(list);
|
||||||
// Preserve side-channel used by the post form for discrepancy checks
|
// Preserve side-channel used by the post form for discrepancy checks
|
||||||
socket.allocationsSummary = list;
|
socket.allocationsSummary = list;
|
||||||
|
if (onAllocationsChange) onAllocationsChange(list);
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
// Best-effort; leave table empty on error
|
// Best-effort; leave table empty on error
|
||||||
setAllocationsSummary([]);
|
setAllocationsSummary([]);
|
||||||
socket && (socket.allocationsSummary = []);
|
if (socket) {
|
||||||
|
socket.allocationsSummary = [];
|
||||||
|
}
|
||||||
|
if (onAllocationsChange) {
|
||||||
|
onAllocationsChange([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [socket, jobId, mode, allocationsEvent]);
|
}, [socket, jobId, mode, allocationsEvent]);
|
||||||
|
|
||||||
@@ -124,12 +131,14 @@ export function DmsAllocationsSummary({ mode, socket, bodyshop, jobId, title })
|
|||||||
{ totalSale: Dinero(), totalCost: Dinero() }
|
{ totalSale: Dinero(), totalCost: Dinero() }
|
||||||
) || { totalSale: Dinero(), totalCost: Dinero() };
|
) || { totalSale: Dinero(), totalCost: Dinero() };
|
||||||
|
|
||||||
|
const hasNonZeroSaleTotal = totals.totalSale.getAmount() !== 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table.Summary.Row>
|
<Table.Summary.Row>
|
||||||
<Table.Summary.Cell>
|
<Table.Summary.Cell>
|
||||||
<Typography.Title level={4}>{t("general.labels.totals")}</Typography.Title>
|
<Typography.Title level={4}>{t("general.labels.totals")}</Typography.Title>
|
||||||
</Table.Summary.Cell>
|
</Table.Summary.Cell>
|
||||||
<Table.Summary.Cell>{totals.totalSale.toFormat()}</Table.Summary.Cell>
|
<Table.Summary.Cell>{hasNonZeroSaleTotal ? totals.totalSale.toFormat() : null}</Table.Summary.Cell>
|
||||||
<Table.Summary.Cell />
|
<Table.Summary.Cell />
|
||||||
<Table.Summary.Cell />
|
<Table.Summary.Cell />
|
||||||
<Table.Summary.Cell />
|
<Table.Summary.Cell />
|
||||||
|
|||||||
@@ -0,0 +1,342 @@
|
|||||||
|
import { Alert, Button, Card, Table, Tabs, Typography } from "antd";
|
||||||
|
import { SyncOutlined } from "@ant-design/icons";
|
||||||
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { createStructuredSelector } from "reselect";
|
||||||
|
import { resolveRROpCodeFromBodyshop } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
|
|
||||||
|
const mapStateToProps = createStructuredSelector({
|
||||||
|
bodyshop: selectBodyshop
|
||||||
|
});
|
||||||
|
const mapDispatchToProps = () => ({});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(RrAllocationsSummary);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize job allocations into a flat list for display / preview building.
|
||||||
|
* @param ack
|
||||||
|
* @returns {{
|
||||||
|
* center: *,
|
||||||
|
* sale: *,
|
||||||
|
* partsSale: *,
|
||||||
|
* partsTaxableSale: *,
|
||||||
|
* partsNonTaxableSale: *,
|
||||||
|
* laborTaxableSale: *,
|
||||||
|
* laborNonTaxableSale: *,
|
||||||
|
* extrasSale: *,
|
||||||
|
* extrasTaxableSale: *,
|
||||||
|
* extrasNonTaxableSale: *,
|
||||||
|
* cost: *,
|
||||||
|
* profitCenter: *,
|
||||||
|
* costCenter: *
|
||||||
|
* }[]|*[]}
|
||||||
|
*/
|
||||||
|
function normalizeJobAllocations(ack) {
|
||||||
|
if (!ack || !Array.isArray(ack.jobAllocations)) return [];
|
||||||
|
|
||||||
|
return ack.jobAllocations.map((row) => ({
|
||||||
|
center: row.center,
|
||||||
|
|
||||||
|
// legacy "sale" (total) if we ever want to show it again
|
||||||
|
sale: row.sale || row.totalSale || null,
|
||||||
|
|
||||||
|
// bucketed sales used to build split ROGOG/ROLABOR
|
||||||
|
partsSale: row.partsSale || null,
|
||||||
|
partsTaxableSale: row.partsTaxableSale || null,
|
||||||
|
partsNonTaxableSale: row.partsNonTaxableSale || null,
|
||||||
|
laborTaxableSale: row.laborTaxableSale || null,
|
||||||
|
laborNonTaxableSale: row.laborNonTaxableSale || null,
|
||||||
|
extrasSale: row.extrasSale || null,
|
||||||
|
extrasTaxableSale: row.extrasTaxableSale || null,
|
||||||
|
extrasNonTaxableSale: row.extrasNonTaxableSale || null,
|
||||||
|
|
||||||
|
cost: row.cost || null,
|
||||||
|
profitCenter: row.profitCenter || null,
|
||||||
|
costCenter: row.costCenter || null
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RR-specific DMS Allocations Summary
|
||||||
|
* Focused on what we actually send to RR:
|
||||||
|
* - ROGOG (split by taxable / non-taxable segments)
|
||||||
|
* - ROLABOR shell
|
||||||
|
*
|
||||||
|
* The heavy lifting (ROGOG/ROLABOR split, cost allocation, tax flags)
|
||||||
|
* is now done on the backend via buildRogogFromAllocations/buildRolaborFromRogog.
|
||||||
|
* This component just renders the preview from `ack.rogg` / `ack.rolabor`.
|
||||||
|
*/
|
||||||
|
export function RrAllocationsSummary({ socket, bodyshop, jobId, title, onAllocationsChange, opCode }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [roggPreview, setRoggPreview] = useState(null);
|
||||||
|
const [rolaborPreview, setRolaborPreview] = useState(null);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
// Prefer the user-selected OpCode (from DmsContainer), fall back to config default
|
||||||
|
const effectiveOpCode = useMemo(() => opCode || resolveRROpCodeFromBodyshop(bodyshop), [opCode, bodyshop]);
|
||||||
|
|
||||||
|
const fetchAllocations = useCallback(() => {
|
||||||
|
if (!socket || !jobId) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
socket.emit("rr-calculate-allocations", { jobId, opCode: effectiveOpCode }, (ack) => {
|
||||||
|
if (ack && ack.ok === false) {
|
||||||
|
setRoggPreview(null);
|
||||||
|
setRolaborPreview(null);
|
||||||
|
setError(ack.error || t("dms.labels.allocations_error"));
|
||||||
|
if (socket) {
|
||||||
|
socket.allocationsSummary = [];
|
||||||
|
socket.rrAllocationsRaw = ack;
|
||||||
|
}
|
||||||
|
if (onAllocationsChange) {
|
||||||
|
onAllocationsChange([]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const jobAllocRows = normalizeJobAllocations(ack);
|
||||||
|
|
||||||
|
setRoggPreview(ack?.rogg || null);
|
||||||
|
setRolaborPreview(ack?.rolabor || null);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
if (socket) {
|
||||||
|
socket.allocationsSummary = jobAllocRows;
|
||||||
|
socket.rrAllocationsRaw = ack;
|
||||||
|
}
|
||||||
|
if (onAllocationsChange) {
|
||||||
|
onAllocationsChange(jobAllocRows);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
setRoggPreview(null);
|
||||||
|
setRolaborPreview(null);
|
||||||
|
setError(t("dms.labels.allocations_error"));
|
||||||
|
if (socket) {
|
||||||
|
socket.allocationsSummary = [];
|
||||||
|
}
|
||||||
|
if (onAllocationsChange) {
|
||||||
|
onAllocationsChange([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [socket, jobId, t, onAllocationsChange, effectiveOpCode]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchAllocations();
|
||||||
|
}, [fetchAllocations]);
|
||||||
|
|
||||||
|
const segmentLabelMap = {
|
||||||
|
partsTaxable: "Parts Taxable",
|
||||||
|
partsNonTaxable: "Parts Non-Taxable",
|
||||||
|
extrasTaxable: "Extras Taxable",
|
||||||
|
extrasNonTaxable: "Extras Non-Taxable",
|
||||||
|
laborTaxable: "Labor Taxable",
|
||||||
|
laborNonTaxable: "Labor Non-Taxable"
|
||||||
|
};
|
||||||
|
|
||||||
|
const roggRows = useMemo(() => {
|
||||||
|
if (!roggPreview || !Array.isArray(roggPreview.ops)) return [];
|
||||||
|
|
||||||
|
const rows = [];
|
||||||
|
roggPreview.ops.forEach((op) => {
|
||||||
|
const rowOpCode = opCode || op.opCode;
|
||||||
|
|
||||||
|
(op.lines || []).forEach((line, idx) => {
|
||||||
|
const baseDesc = line.itemDesc;
|
||||||
|
const segmentKind = op.segmentKind;
|
||||||
|
const segmentCount = op.segmentCount || 0;
|
||||||
|
const segmentLabel = segmentLabelMap[segmentKind] || segmentKind;
|
||||||
|
const displayDesc = segmentCount > 1 && segmentLabel ? `${baseDesc} (${segmentLabel})` : baseDesc;
|
||||||
|
|
||||||
|
rows.push({
|
||||||
|
key: `${op.jobNo}-${idx}`,
|
||||||
|
opCode: rowOpCode,
|
||||||
|
jobNo: op.jobNo,
|
||||||
|
breakOut: line.breakOut,
|
||||||
|
itemType: line.itemType,
|
||||||
|
itemDesc: displayDesc,
|
||||||
|
custQty: line.custQty,
|
||||||
|
custPayTypeFlag: line.custPayTypeFlag,
|
||||||
|
custTxblNtxblFlag: line.custTxblNtxblFlag,
|
||||||
|
custPrice: line.amount?.custPrice,
|
||||||
|
dlrCost: line.amount?.dlrCost,
|
||||||
|
// segment metadata for visual styling
|
||||||
|
segmentKind,
|
||||||
|
segmentCount
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return rows;
|
||||||
|
}, [roggPreview, opCode, segmentLabelMap]);
|
||||||
|
|
||||||
|
const rolaborRows = useMemo(() => {
|
||||||
|
if (!rolaborPreview || !Array.isArray(rolaborPreview.ops)) return [];
|
||||||
|
|
||||||
|
return rolaborPreview.ops.map((op, idx) => {
|
||||||
|
const rowOpCode = opCode || op.opCode;
|
||||||
|
|
||||||
|
return {
|
||||||
|
key: `${op.jobNo}-${idx}`,
|
||||||
|
opCode: rowOpCode,
|
||||||
|
jobNo: op.jobNo,
|
||||||
|
custPayTypeFlag: op.custPayTypeFlag,
|
||||||
|
custTxblNtxblFlag: op.custTxblNtxblFlag,
|
||||||
|
payType: op.bill?.payType,
|
||||||
|
amtType: op.amount?.amtType,
|
||||||
|
custPrice: op.amount?.custPrice,
|
||||||
|
totalAmt: op.amount?.totalAmt
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}, [rolaborPreview, opCode]);
|
||||||
|
|
||||||
|
// Totals for ROGOG (sum custPrice + dlrCost over all lines)
|
||||||
|
const roggTotals = useMemo(() => {
|
||||||
|
if (!roggPreview || !Array.isArray(roggPreview.ops)) {
|
||||||
|
return { totalCustPrice: "0.00", totalDlrCost: "0.00" };
|
||||||
|
}
|
||||||
|
|
||||||
|
let totalCustCents = 0;
|
||||||
|
let totalCostCents = 0;
|
||||||
|
|
||||||
|
roggPreview.ops.forEach((op) => {
|
||||||
|
(op.lines || []).forEach((line) => {
|
||||||
|
const cp = parseFloat(line.amount?.custPrice || "0");
|
||||||
|
if (!Number.isNaN(cp)) {
|
||||||
|
totalCustCents += Math.round(cp * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
const dc = parseFloat(line.amount?.dlrCost || "0");
|
||||||
|
if (!Number.isNaN(dc)) {
|
||||||
|
totalCostCents += Math.round(dc * 100);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
totalCustPrice: (totalCustCents / 100).toFixed(2),
|
||||||
|
totalDlrCost: (totalCostCents / 100).toFixed(2)
|
||||||
|
};
|
||||||
|
}, [roggPreview]);
|
||||||
|
|
||||||
|
const roggColumns = [
|
||||||
|
{ title: "JobNo", dataIndex: "jobNo", key: "jobNo" },
|
||||||
|
{ title: "OpCode", dataIndex: "opCode", key: "opCode" },
|
||||||
|
{ title: "BreakOut", dataIndex: "breakOut", key: "breakOut" },
|
||||||
|
{ title: "ItemType", dataIndex: "itemType", key: "itemType" },
|
||||||
|
{ title: "ItemDesc", dataIndex: "itemDesc", key: "itemDesc" },
|
||||||
|
{ title: "CustQty", dataIndex: "custQty", key: "custQty" },
|
||||||
|
{ title: "CustTxblFlag", dataIndex: "custTxblNtxblFlag", key: "custTxblNtxblFlag" },
|
||||||
|
{ title: "CustPrice", dataIndex: "custPrice", key: "custPrice" },
|
||||||
|
{ title: "DlrCost", dataIndex: "dlrCost", key: "dlrCost" }
|
||||||
|
];
|
||||||
|
|
||||||
|
const rolaborColumns = [
|
||||||
|
{ title: "JobNo", dataIndex: "jobNo", key: "jobNo" },
|
||||||
|
{ title: "OpCode", dataIndex: "opCode", key: "opCode" },
|
||||||
|
{ title: "CustPayType", dataIndex: "custPayTypeFlag", key: "custPayTypeFlag" },
|
||||||
|
{ title: "CustTxblFlag", dataIndex: "custTxblNtxblFlag", key: "custTxblNtxblFlag" },
|
||||||
|
{ title: "PayType", dataIndex: "payType", key: "payType" },
|
||||||
|
{ title: "AmtType", dataIndex: "amtType", key: "amtType" },
|
||||||
|
{ title: "CustPrice", dataIndex: "custPrice", key: "custPrice" },
|
||||||
|
{ title: "TotalAmt", dataIndex: "totalAmt", key: "totalAmt" }
|
||||||
|
];
|
||||||
|
|
||||||
|
const tabItems = [
|
||||||
|
{
|
||||||
|
key: "rogog",
|
||||||
|
label: "ROGOG Preview",
|
||||||
|
children: (
|
||||||
|
<>
|
||||||
|
<Typography.Paragraph type="secondary" style={{ marginBottom: 8 }}>
|
||||||
|
OpCode: <strong>{effectiveOpCode}</strong>. Only centers with RR GOG mapping (rr_gogcode & rr_item_type)
|
||||||
|
are included. Totals below reflect exactly what will be sent in ROGOG, with parts, extras, and labor split
|
||||||
|
into taxable / non-taxable segments.
|
||||||
|
</Typography.Paragraph>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
pagination={false}
|
||||||
|
columns={roggColumns}
|
||||||
|
rowKey="key"
|
||||||
|
dataSource={roggRows}
|
||||||
|
locale={{ emptyText: "No ROGOG lines would be generated." }}
|
||||||
|
scroll={{ x: true }}
|
||||||
|
// 👇 visually highlight splits; especially taxable/non-taxable labor segments
|
||||||
|
rowClassName={(record) => {
|
||||||
|
if (
|
||||||
|
record.segmentCount > 1 &&
|
||||||
|
(record.segmentKind === "laborTaxable" || record.segmentKind === "laborNonTaxable")
|
||||||
|
) {
|
||||||
|
return "rr-allocations-tax-split-row";
|
||||||
|
}
|
||||||
|
if (record.segmentCount > 1) {
|
||||||
|
return "rr-allocations-split-row";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}}
|
||||||
|
summary={() => {
|
||||||
|
const hasCustTotal = Number(roggTotals.totalCustPrice) !== 0;
|
||||||
|
const hasCostTotal = Number(roggTotals.totalDlrCost) !== 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table.Summary.Row>
|
||||||
|
<Table.Summary.Cell index={0}>
|
||||||
|
<Typography.Title level={5}>{t("general.labels.totals")}</Typography.Title>
|
||||||
|
</Table.Summary.Cell>
|
||||||
|
<Table.Summary.Cell index={1} />
|
||||||
|
<Table.Summary.Cell index={2} />
|
||||||
|
<Table.Summary.Cell index={3} />
|
||||||
|
<Table.Summary.Cell index={4} />
|
||||||
|
<Table.Summary.Cell index={5} />
|
||||||
|
<Table.Summary.Cell index={6} />
|
||||||
|
<Table.Summary.Cell index={7}>{hasCustTotal ? roggTotals.totalCustPrice : null}</Table.Summary.Cell>
|
||||||
|
<Table.Summary.Cell index={8}>{hasCostTotal ? roggTotals.totalDlrCost : null}</Table.Summary.Cell>
|
||||||
|
</Table.Summary.Row>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "rolabor",
|
||||||
|
label: "ROLABOR Preview",
|
||||||
|
children: (
|
||||||
|
<>
|
||||||
|
<Typography.Paragraph type="secondary" style={{ marginBottom: 8 }}>
|
||||||
|
This mirrors the shell that would be sent for ROLABOR when all financials are carried in GOG.
|
||||||
|
</Typography.Paragraph>
|
||||||
|
<Table
|
||||||
|
pagination={false}
|
||||||
|
columns={rolaborColumns}
|
||||||
|
rowKey="key"
|
||||||
|
dataSource={rolaborRows}
|
||||||
|
locale={{ emptyText: "No ROLABOR lines would be generated." }}
|
||||||
|
scroll={{ x: true }}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card
|
||||||
|
title={title}
|
||||||
|
extra={
|
||||||
|
<Button onClick={fetchAllocations} aria-label={t("general.actions.refresh")}>
|
||||||
|
<SyncOutlined />
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{bodyshop.pbs_configuration?.disablebillwip && (
|
||||||
|
<Alert type="warning" message={t("jobs.labels.dms.disablebillwip")} />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{error && <Alert type="error" style={{ marginTop: 8, marginBottom: 8 }} message={error} />}
|
||||||
|
|
||||||
|
<Tabs defaultActiveKey="rogog" items={tabItems} />
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -13,7 +13,14 @@ const mapDispatchToProps = () => ({});
|
|||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsLogEvents);
|
export default connect(mapStateToProps, mapDispatchToProps)(DmsLogEvents);
|
||||||
|
|
||||||
export function DmsLogEvents({ logs, detailsOpen, detailsNonce, isDarkMode, colorizeJson = false }) {
|
export function DmsLogEvents({
|
||||||
|
logs,
|
||||||
|
detailsOpen,
|
||||||
|
detailsNonce,
|
||||||
|
isDarkMode,
|
||||||
|
colorizeJson = false,
|
||||||
|
showDetails = true
|
||||||
|
}) {
|
||||||
const [openSet, setOpenSet] = useState(() => new Set());
|
const [openSet, setOpenSet] = useState(() => new Set());
|
||||||
|
|
||||||
// Inject JSON highlight styles once (only when colorize is enabled)
|
// Inject JSON highlight styles once (only when colorize is enabled)
|
||||||
@@ -54,8 +61,10 @@ export function DmsLogEvents({ logs, detailsOpen, detailsNonce, isDarkMode, colo
|
|||||||
() =>
|
() =>
|
||||||
(logs || []).map((raw, idx) => {
|
(logs || []).map((raw, idx) => {
|
||||||
const { level, message, timestamp, meta } = normalizeLog(raw);
|
const { level, message, timestamp, meta } = normalizeLog(raw);
|
||||||
const hasMeta = !isEmpty(meta);
|
|
||||||
const isOpen = openSet.has(idx);
|
// Only treat meta as "present" when we are allowed to show details
|
||||||
|
const hasMeta = !isEmpty(meta) && showDetails;
|
||||||
|
const isOpen = hasMeta && openSet.has(idx);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key: idx,
|
key: idx,
|
||||||
@@ -101,7 +110,7 @@ export function DmsLogEvents({ logs, detailsOpen, detailsNonce, isDarkMode, colo
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
[logs, openSet, colorizeJson]
|
[logs, openSet, colorizeJson, isDarkMode, showDetails]
|
||||||
);
|
);
|
||||||
|
|
||||||
return <Timeline pending reverse items={items} />;
|
return <Timeline pending reverse items={items} />;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import DmsCdkMakesRefetch from "../dms-cdk-makes/dms-cdk-makes.refetch.component
|
|||||||
import DateTimePicker from "../form-date-time-picker/form-date-time-picker.component.jsx";
|
import DateTimePicker from "../form-date-time-picker/form-date-time-picker.component.jsx";
|
||||||
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
||||||
import { DMS_MAP } from "../../utils/dmsUtils";
|
import { DMS_MAP } from "../../utils/dmsUtils";
|
||||||
|
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CDK-like DMS post form:
|
* CDK-like DMS post form:
|
||||||
@@ -38,14 +39,23 @@ import { DMS_MAP } from "../../utils/dmsUtils";
|
|||||||
* @param job
|
* @param job
|
||||||
* @param logsRef
|
* @param logsRef
|
||||||
* @param mode
|
* @param mode
|
||||||
|
* @param allocationsSummary
|
||||||
* @returns {JSX.Element}
|
* @returns {JSX.Element}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode }) {
|
export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode, allocationsSummary }) {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [, /*unused*/ setTick] = useState(0); // handy if you need a forceUpdate later
|
const [, /*unused*/ setTick] = useState(0); // handy if you need a forceUpdate later
|
||||||
|
|
||||||
|
const {
|
||||||
|
treatments: { Fortellis }
|
||||||
|
} = useSplitTreatments({
|
||||||
|
attributes: {},
|
||||||
|
names: ["Fortellis"],
|
||||||
|
splitKey: bodyshop.imexshopid
|
||||||
|
});
|
||||||
|
|
||||||
const initialValues = useMemo(
|
const initialValues = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
story: `${t("jobs.labels.dms.defaultstory", {
|
story: `${t("jobs.labels.dms.defaultstory", {
|
||||||
@@ -111,15 +121,19 @@ export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode }
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Totals & discrepancy
|
// Totals & discrepancy
|
||||||
const totals = socket?.allocationsSummary
|
const totals = useMemo(() => {
|
||||||
? socket.allocationsSummary.reduce(
|
if (!allocationsSummary || allocationsSummary.length === 0) {
|
||||||
(acc, val) => ({
|
return { totalSale: Dinero(), totalCost: Dinero() };
|
||||||
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
}
|
||||||
totalCost: acc.totalCost.add(Dinero(val.cost))
|
|
||||||
}),
|
return allocationsSummary.reduce(
|
||||||
{ totalSale: Dinero(), totalCost: Dinero() }
|
(acc, val) => ({
|
||||||
)
|
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
||||||
: { totalSale: Dinero(), totalCost: Dinero() };
|
totalCost: acc.totalCost.add(Dinero(val.cost))
|
||||||
|
}),
|
||||||
|
{ totalSale: Dinero(), totalCost: Dinero() }
|
||||||
|
);
|
||||||
|
}, [allocationsSummary]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card title={t("jobs.labels.dms.postingform")}>
|
<Card title={t("jobs.labels.dms.postingform")}>
|
||||||
@@ -205,7 +219,7 @@ export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode }
|
|||||||
<Row gutter={[16, 12]}>
|
<Row gutter={[16, 12]}>
|
||||||
<Col span={24}>
|
<Col span={24}>
|
||||||
<Form.Item name="story" label={t("jobs.fields.dms.story")} rules={[{ required: true }]}>
|
<Form.Item name="story" label={t("jobs.fields.dms.story")} rules={[{ required: true }]}>
|
||||||
<Input.TextArea maxLength={240} />
|
<Input.TextArea maxLength={Fortellis.treatment === "on" ? 40 : 240} showCount />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
@@ -373,7 +387,10 @@ export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode }
|
|||||||
const payersOk =
|
const payersOk =
|
||||||
payers.length > 0 &&
|
payers.length > 0 &&
|
||||||
payers.every((p) => p?.name && p.dms_acctnumber && (p.amount ?? "") !== "" && p.controlnumber);
|
payers.every((p) => p?.name && p.dms_acctnumber && (p.amount ?? "") !== "" && p.controlnumber);
|
||||||
const nonRrDiscrepancyGate = socket?.allocationsSummary ? discrep.getAmount() !== 0 : true;
|
|
||||||
|
const hasAllocations = allocationsSummary && allocationsSummary.length > 0;
|
||||||
|
const nonRrDiscrepancyGate = hasAllocations ? discrep.getAmount() !== 0 : true;
|
||||||
|
|
||||||
const disablePost = !payersOk || nonRrDiscrepancyGate;
|
const disablePost = !payersOk || nonRrDiscrepancyGate;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -19,20 +19,55 @@ export default connect(mapStateToProps, mapDispatchToProps)(DmsPostForm);
|
|||||||
* @param socket
|
* @param socket
|
||||||
* @param job
|
* @param job
|
||||||
* @param logsRef
|
* @param logsRef
|
||||||
|
* @param key
|
||||||
|
* @param allocationsSummary
|
||||||
|
* @param rrOpCodeParts
|
||||||
|
* @param onChangeRrOpCodeParts
|
||||||
* @returns {JSX.Element|null}
|
* @returns {JSX.Element|null}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
export function DmsPostForm({ mode, bodyshop, socket, job, logsRef }) {
|
export function DmsPostForm({
|
||||||
|
mode,
|
||||||
|
bodyshop,
|
||||||
|
socket,
|
||||||
|
job,
|
||||||
|
logsRef,
|
||||||
|
key,
|
||||||
|
allocationsSummary,
|
||||||
|
rrOpCodeParts,
|
||||||
|
onChangeRrOpCodeParts
|
||||||
|
}) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case DMS_MAP.reynolds:
|
case DMS_MAP.reynolds:
|
||||||
return <RRPostForm bodyshop={bodyshop} socket={socket} job={job} logsRef={logsRef} />;
|
return (
|
||||||
|
<RRPostForm
|
||||||
|
bodyshop={bodyshop}
|
||||||
|
socket={socket}
|
||||||
|
job={job}
|
||||||
|
logsRef={logsRef}
|
||||||
|
key={key}
|
||||||
|
allocationsSummary={allocationsSummary}
|
||||||
|
opCodeParts={rrOpCodeParts}
|
||||||
|
onChangeOpCodeParts={onChangeRrOpCodeParts}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
// CDK (legacy /ws), Fortellis (CDK-over-WSS), and PBS share the same UI;
|
// CDK (legacy /ws), Fortellis (CDK-over-WSS), and PBS share the same UI;
|
||||||
// we pass mode down so the child can choose the correct event name.
|
// we pass mode down so the child can choose the correct event name.
|
||||||
case DMS_MAP.fortellis:
|
case DMS_MAP.fortellis:
|
||||||
case DMS_MAP.cdk:
|
case DMS_MAP.cdk:
|
||||||
case DMS_MAP.pbs:
|
case DMS_MAP.pbs:
|
||||||
return <CdkLikePostForm mode={mode} bodyshop={bodyshop} socket={socket} job={job} logsRef={logsRef} />;
|
return (
|
||||||
|
<CdkLikePostForm
|
||||||
|
mode={mode}
|
||||||
|
bodyshop={bodyshop}
|
||||||
|
socket={socket}
|
||||||
|
job={job}
|
||||||
|
logsRef={logsRef}
|
||||||
|
key={key}
|
||||||
|
allocationsSummary={allocationsSummary}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ReloadOutlined } from "@ant-design/icons";
|
import { ReloadOutlined, RollbackOutlined } from "@ant-design/icons";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
@@ -26,19 +26,36 @@ import dayjs from "../../utils/day";
|
|||||||
* @param socket
|
* @param socket
|
||||||
* @param job
|
* @param job
|
||||||
* @param logsRef
|
* @param logsRef
|
||||||
|
* @param allocationsSummary
|
||||||
|
* @param opCodeParts // { prefix, base, suffix } from container
|
||||||
|
* @param onChangeOpCodeParts // (partsWithFlags) => void
|
||||||
* @returns {JSX.Element}
|
* @returns {JSX.Element}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
export default function RRPostForm({ bodyshop, socket, job, logsRef }) {
|
export default function RRPostForm({
|
||||||
|
bodyshop,
|
||||||
|
socket,
|
||||||
|
job,
|
||||||
|
logsRef,
|
||||||
|
allocationsSummary,
|
||||||
|
opCodeParts,
|
||||||
|
onChangeOpCodeParts
|
||||||
|
}) {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
// Capture the baseline/default OpCode parts ONCE per mount (tied to resetKey in container)
|
||||||
|
const [baselineOpCodeParts] = useState(() => ({
|
||||||
|
prefix: opCodeParts?.prefix ?? "",
|
||||||
|
base: opCodeParts?.base ?? "",
|
||||||
|
suffix: opCodeParts?.suffix ?? ""
|
||||||
|
}));
|
||||||
|
|
||||||
// Advisors
|
// Advisors
|
||||||
const [advisors, setAdvisors] = useState([]);
|
const [advisors, setAdvisors] = useState([]);
|
||||||
const [advLoading, setAdvLoading] = useState(false);
|
const [advLoading, setAdvLoading] = useState(false);
|
||||||
|
|
||||||
const getAdvisorNumber = (a) => a?.advisorId;
|
const getAdvisorNumber = (a) => a?.advisorId;
|
||||||
|
|
||||||
const getAdvisorLabel = (a) => `${a?.firstName || ""} ${a?.lastName || ""}`.trim();
|
const getAdvisorLabel = (a) => `${a?.firstName || ""} ${a?.lastName || ""}`.trim();
|
||||||
|
|
||||||
const fetchRrAdvisors = (refresh = false) => {
|
const fetchRrAdvisors = (refresh = false) => {
|
||||||
@@ -97,32 +114,99 @@ export default function RRPostForm({ bodyshop, socket, job, logsRef }) {
|
|||||||
: job.v_model_yr)) ||
|
: job.v_model_yr)) ||
|
||||||
2019
|
2019
|
||||||
}-01-01`
|
}-01-01`
|
||||||
)
|
),
|
||||||
|
opPrefix: opCodeParts?.prefix ?? "",
|
||||||
|
opBase: opCodeParts?.base ?? "",
|
||||||
|
opSuffix: opCodeParts?.suffix ?? ""
|
||||||
}),
|
}),
|
||||||
[job, t]
|
[job, t, opCodeParts]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Keep the RR OpCode parts in sync with DmsContainer state
|
||||||
|
const opPrefixWatch = Form.useWatch("opPrefix", form);
|
||||||
|
const opBaseWatch = Form.useWatch("opBase", form);
|
||||||
|
const opSuffixWatch = Form.useWatch("opSuffix", form);
|
||||||
|
|
||||||
|
// Detect if current form values differ from baseline defaults
|
||||||
|
const isCustomOpCode = useMemo(() => {
|
||||||
|
const current = {
|
||||||
|
prefix: opPrefixWatch !== undefined ? opPrefixWatch : (baselineOpCodeParts.prefix ?? ""),
|
||||||
|
base: opBaseWatch !== undefined ? opBaseWatch : (baselineOpCodeParts.base ?? ""),
|
||||||
|
suffix: opSuffixWatch !== undefined ? opSuffixWatch : (baselineOpCodeParts.suffix ?? "")
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
current.prefix !== (baselineOpCodeParts.prefix ?? "") ||
|
||||||
|
current.base !== (baselineOpCodeParts.base ?? "") ||
|
||||||
|
current.suffix !== (baselineOpCodeParts.suffix ?? "")
|
||||||
|
);
|
||||||
|
}, [opPrefixWatch, opBaseWatch, opSuffixWatch, baselineOpCodeParts]);
|
||||||
|
|
||||||
|
// Push changes up to container with some metadata
|
||||||
|
useEffect(() => {
|
||||||
|
if (!onChangeOpCodeParts) return;
|
||||||
|
|
||||||
|
const parts = {
|
||||||
|
prefix: opPrefixWatch || "",
|
||||||
|
base: opBaseWatch || "",
|
||||||
|
suffix: opSuffixWatch || "",
|
||||||
|
isCustom: isCustomOpCode
|
||||||
|
};
|
||||||
|
|
||||||
|
onChangeOpCodeParts(parts);
|
||||||
|
}, [opPrefixWatch, opBaseWatch, opSuffixWatch, isCustomOpCode, onChangeOpCodeParts]);
|
||||||
|
|
||||||
const handleFinish = (values) => {
|
const handleFinish = (values) => {
|
||||||
if (!socket) return;
|
if (!socket) return;
|
||||||
|
|
||||||
|
const { opPrefix, opBase, opSuffix, ...rest } = values;
|
||||||
|
|
||||||
|
const combinedOpCode = `${opPrefix || ""}${opBase || ""}${opSuffix || ""}`.trim();
|
||||||
|
|
||||||
|
const txEnvelope = {
|
||||||
|
...rest,
|
||||||
|
opPrefix,
|
||||||
|
opBase,
|
||||||
|
opSuffix
|
||||||
|
};
|
||||||
|
|
||||||
|
if (combinedOpCode) {
|
||||||
|
txEnvelope.opCode = combinedOpCode;
|
||||||
|
}
|
||||||
|
|
||||||
socket.emit("rr-export-job", {
|
socket.emit("rr-export-job", {
|
||||||
bodyshopId: bodyshop?.id,
|
bodyshopId: bodyshop?.id,
|
||||||
jobId: job.id,
|
jobId: job.id,
|
||||||
job,
|
job,
|
||||||
txEnvelope: values
|
txEnvelope
|
||||||
});
|
});
|
||||||
|
|
||||||
logsRef?.current?.scrollIntoView({ behavior: "smooth" });
|
logsRef?.current?.scrollIntoView({ behavior: "smooth" });
|
||||||
};
|
};
|
||||||
|
|
||||||
// Discrepancy is ignored for RR; we still show totals for operator context
|
// Discrepancy is ignored for RR; we still show totals for operator context.
|
||||||
const totals = socket?.allocationsSummary
|
// Use the lifted allocationsSummary from the container instead of reading from the socket.
|
||||||
? socket.allocationsSummary.reduce(
|
const totals = useMemo(() => {
|
||||||
(acc, val) => ({
|
if (!allocationsSummary || allocationsSummary.length === 0) {
|
||||||
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
return { totalSale: Dinero(), totalCost: Dinero() };
|
||||||
totalCost: acc.totalCost.add(Dinero(val.cost))
|
}
|
||||||
}),
|
|
||||||
{ totalSale: Dinero(), totalCost: Dinero() }
|
return allocationsSummary.reduce(
|
||||||
)
|
(acc, val) => ({
|
||||||
: { totalSale: Dinero(), totalCost: Dinero() };
|
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
||||||
|
totalCost: acc.totalCost.add(Dinero(val.cost))
|
||||||
|
}),
|
||||||
|
{ totalSale: Dinero(), totalCost: Dinero() }
|
||||||
|
);
|
||||||
|
}, [allocationsSummary]);
|
||||||
|
|
||||||
|
const handleResetOpCode = () => {
|
||||||
|
form.setFieldsValue({
|
||||||
|
opPrefix: baselineOpCodeParts.prefix,
|
||||||
|
opBase: baselineOpCodeParts.base,
|
||||||
|
opSuffix: baselineOpCodeParts.suffix
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card title={t("jobs.labels.dms.postingform")}>
|
<Card title={t("jobs.labels.dms.postingform")}>
|
||||||
@@ -171,10 +255,57 @@ export default function RRPostForm({ bodyshop, socket, job, logsRef }) {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
{/* Make Override */}
|
{/* RR OpCode (prefix / base / suffix) */}
|
||||||
<Col xs={24} sm={12} md={12} lg={8}>
|
<Col xs={24} sm={12} md={12} lg={8}>
|
||||||
<Form.Item name="makeOverride" label={t("jobs.fields.dms.make_override")}>
|
<Form.Item
|
||||||
<Input allowClear placeholder={t("general.actions.optional")} />
|
required
|
||||||
|
label={
|
||||||
|
<Space size="small" align="center">
|
||||||
|
{t("jobs.fields.dms.rr_opcode", "RR OpCode")}
|
||||||
|
{isCustomOpCode && (
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
icon={<RollbackOutlined />}
|
||||||
|
onClick={handleResetOpCode}
|
||||||
|
style={{ padding: 0 }}
|
||||||
|
>
|
||||||
|
{t("jobs.fields.dms.rr_opcode_reset", "Reset")}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Space.Compact block>
|
||||||
|
<Form.Item name="opPrefix" noStyle>
|
||||||
|
<Input
|
||||||
|
allowClear
|
||||||
|
maxLength={4}
|
||||||
|
style={{ width: "30%" }}
|
||||||
|
placeholder={t("jobs.fields.dms.rr_opcode_prefix", "Prefix")}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="opBase"
|
||||||
|
noStyle
|
||||||
|
rules={[{ required: true, message: t("general.validation.required") }]}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
allowClear
|
||||||
|
maxLength={10}
|
||||||
|
style={{ width: "40%" }}
|
||||||
|
placeholder={t("jobs.fields.dms.rr_opcode_base", "Base")}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="opSuffix" noStyle>
|
||||||
|
<Input
|
||||||
|
allowClear
|
||||||
|
maxLength={4}
|
||||||
|
style={{ width: "30%" }}
|
||||||
|
placeholder={t("jobs.fields.dms.rr_opcode_suffix", "Suffix")}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Space.Compact>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
|
|||||||
@@ -222,17 +222,37 @@ export function JobLifecycleComponent({ bodyshop, job, statuses }) {
|
|||||||
</div>
|
</div>
|
||||||
</BlurWrapperComponent>
|
</BlurWrapperComponent>
|
||||||
<Card type="inner" title={t("job_lifecycle.content.legend_title")} style={{ marginTop: "10px" }}>
|
<Card type="inner" title={t("job_lifecycle.content.legend_title")} style={{ marginTop: "10px" }}>
|
||||||
<div>
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
flexWrap: "wrap",
|
||||||
|
gap: 8
|
||||||
|
}}
|
||||||
|
>
|
||||||
{lifecycleData.durations.summations.map((key) => (
|
{lifecycleData.durations.summations.map((key) => (
|
||||||
<Tag key={key.status} color={key.color} style={{ width: "13vh", padding: "4px", margin: "4px" }}>
|
<Tag
|
||||||
|
key={key.status}
|
||||||
|
color={key.color}
|
||||||
|
style={{
|
||||||
|
// let the tag grow with its content
|
||||||
|
width: "auto",
|
||||||
|
padding: 0,
|
||||||
|
margin: 0,
|
||||||
|
display: "inline-flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
boxSizing: "border-box"
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
aria-label={`${key.status} | ${key.roundedPercentage} | ${key.humanReadable}`}
|
aria-label={`${key.status} | ${key.roundedPercentage} | ${key.humanReadable}`}
|
||||||
title={`${key.status} | ${key.roundedPercentage} | ${key.humanReadable}`}
|
title={`${key.status} | ${key.roundedPercentage} | ${key.humanReadable}`}
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: "var(--tag-wrapper-bg)",
|
backgroundColor: "var(--tag-wrapper-bg)",
|
||||||
color: "var(--tag-wrapper-text)",
|
color: "var(--tag-wrapper-text)",
|
||||||
padding: "4px",
|
padding: "4px 8px",
|
||||||
textAlign: "center"
|
textAlign: "center",
|
||||||
|
whiteSpace: "nowrap" // single line; tag gets wider instead of text escaping
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{key.status} (
|
{key.status} (
|
||||||
|
|||||||
@@ -35,16 +35,14 @@ export function JobsDocumentsImgproxyDownloadButton({ galleryImages, identifier,
|
|||||||
...galleryImages.other.filter((image) => image.isSelected)
|
...galleryImages.other.filter((image) => image.isSelected)
|
||||||
];
|
];
|
||||||
|
|
||||||
function downloadProgress(progressEvent) {
|
const downloadProgress = ({ loaded }) => {
|
||||||
setDownload((currentDownloadState) => {
|
setDownload((currentDownloadState) => ({
|
||||||
return {
|
downloaded: loaded ?? 0,
|
||||||
downloaded: progressEvent.loaded || 0,
|
speed: (loaded ?? 0) - (currentDownloadState?.downloaded ?? 0)
|
||||||
speed: (progressEvent.loaded || 0) - ((currentDownloadState && currentDownloadState.downloaded) || 0)
|
}));
|
||||||
};
|
};
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function standardMediaDownload(bufferData) {
|
const standardMediaDownload = (bufferData) => {
|
||||||
try {
|
try {
|
||||||
const a = document.createElement("a");
|
const a = document.createElement("a");
|
||||||
const url = window.URL.createObjectURL(new Blob([bufferData]));
|
const url = window.URL.createObjectURL(new Blob([bufferData]));
|
||||||
@@ -55,29 +53,26 @@ export function JobsDocumentsImgproxyDownloadButton({ galleryImages, identifier,
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
setDownload(null);
|
setDownload(null);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const handleDownload = async () => {
|
const handleDownload = async () => {
|
||||||
logImEXEvent("jobs_documents_download");
|
logImEXEvent("jobs_documents_download");
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await axios({
|
const { data } = await axios({
|
||||||
url: "/media/imgproxy/download",
|
url: "/media/imgproxy/download",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
responseType: "blob",
|
responseType: "blob",
|
||||||
data: { jobId, documentids: imagesToDownload.map((_) => _.id) },
|
data: { jobId, documentids: imagesToDownload.map((_) => _.id) },
|
||||||
onDownloadProgress: downloadProgress
|
onDownloadProgress: downloadProgress
|
||||||
});
|
});
|
||||||
|
|
||||||
setLoading(false);
|
|
||||||
setDownload(null);
|
|
||||||
|
|
||||||
// Use the response data (Blob) to trigger download
|
// Use the response data (Blob) to trigger download
|
||||||
standardMediaDownload(response.data);
|
standardMediaDownload(data);
|
||||||
} catch {
|
} catch {
|
||||||
|
// handle error (optional)
|
||||||
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setDownload(null);
|
setDownload(null);
|
||||||
// handle error (optional)
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -76,14 +76,14 @@ function JobsDocumentsImgproxyComponent({
|
|||||||
<SyncOutlined />
|
<SyncOutlined />
|
||||||
</Button>
|
</Button>
|
||||||
<JobsDocumentsGallerySelectAllComponent galleryImages={galleryImages} setGalleryImages={setGalleryImages} />
|
<JobsDocumentsGallerySelectAllComponent galleryImages={galleryImages} setGalleryImages={setGalleryImages} />
|
||||||
|
{!billId && (
|
||||||
|
<JobsDocumentsGalleryReassign galleryImages={galleryImages} callback={fetchThumbnails || refetch} />
|
||||||
|
)}
|
||||||
<JobsDocumentsDownloadButton galleryImages={galleryImages} identifier={downloadIdentifier} jobId={jobId} />
|
<JobsDocumentsDownloadButton galleryImages={galleryImages} identifier={downloadIdentifier} jobId={jobId} />
|
||||||
<JobsDocumentsDeleteButton
|
<JobsDocumentsDeleteButton
|
||||||
galleryImages={galleryImages}
|
galleryImages={galleryImages}
|
||||||
deletionCallback={billsCallback || fetchThumbnails || refetch}
|
deletionCallback={billsCallback || fetchThumbnails || refetch}
|
||||||
/>
|
/>
|
||||||
{!billId && (
|
|
||||||
<JobsDocumentsGalleryReassign galleryImages={galleryImages} callback={fetchThumbnails || refetch} />
|
|
||||||
)}
|
|
||||||
</Space>
|
</Space>
|
||||||
</Col>
|
</Col>
|
||||||
{!hasMediaAccess && (
|
{!hasMediaAccess && (
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export default function JobsDocumentsImgproxyDeleteButton({ galleryImages, delet
|
|||||||
okButtonProps={{ danger: true }}
|
okButtonProps={{ danger: true }}
|
||||||
cancelText={t("general.actions.cancel")}
|
cancelText={t("general.actions.cancel")}
|
||||||
>
|
>
|
||||||
<Button disabled={imagesToDelete.length < 1} loading={loading}>
|
<Button danger disabled={imagesToDelete.length < 1} loading={loading}>
|
||||||
{t("documents.actions.delete")}
|
{t("documents.actions.delete")}
|
||||||
</Button>
|
</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
|
|||||||
@@ -107,8 +107,8 @@ export function JobsDocumentsLocalGallery({
|
|||||||
<a href={CreateExplorerLinkForJob({ jobid: job.id })}>
|
<a href={CreateExplorerLinkForJob({ jobid: job.id })}>
|
||||||
<Button>{t("documents.labels.openinexplorer")}</Button>
|
<Button>{t("documents.labels.openinexplorer")}</Button>
|
||||||
</a>
|
</a>
|
||||||
<JobsDocumentsLocalGalleryReassign jobid={job.id} />
|
|
||||||
<JobsDocumentsLocalGallerySelectAllComponent jobid={job.id} />
|
<JobsDocumentsLocalGallerySelectAllComponent jobid={job.id} />
|
||||||
|
<JobsDocumentsLocalGalleryReassign jobid={job.id} />
|
||||||
<JobsLocalGalleryDownloadButton job={job} />
|
<JobsLocalGalleryDownloadButton job={job} />
|
||||||
<JobsDocumentsLocalDeleteButton jobid={job.id} />
|
<JobsDocumentsLocalDeleteButton jobid={job.id} />
|
||||||
</Space>
|
</Space>
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ export function JobsDocumentsLocalDeleteButton({ bodyshop, getJobMedia, allMedia
|
|||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const imagesToDelete = (allMedia?.[jobid] || []).filter((i) => i.isSelected);
|
||||||
|
|
||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
logImEXEvent("job_documents_delete");
|
logImEXEvent("job_documents_delete");
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -36,7 +38,7 @@ export function JobsDocumentsLocalDeleteButton({ bodyshop, getJobMedia, allMedia
|
|||||||
`${bodyshop.localmediaserverhttp}/jobs/delete`,
|
`${bodyshop.localmediaserverhttp}/jobs/delete`,
|
||||||
{
|
{
|
||||||
jobid: jobid,
|
jobid: jobid,
|
||||||
files: (allMedia?.[jobid] || []).filter((i) => i.isSelected).map((i) => i.filename)
|
files: imagesToDelete.map((i) => i.filename)
|
||||||
},
|
},
|
||||||
{ headers: { ims_token: bodyshop.localmediatoken } }
|
{ headers: { ims_token: bodyshop.localmediatoken } }
|
||||||
);
|
);
|
||||||
@@ -60,14 +62,17 @@ export function JobsDocumentsLocalDeleteButton({ bodyshop, getJobMedia, allMedia
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
|
disabled={imagesToDelete.length < 1}
|
||||||
icon={<QuestionCircleOutlined style={{ color: "red" }} />}
|
icon={<QuestionCircleOutlined style={{ color: "red" }} />}
|
||||||
onConfirm={handleDelete}
|
onConfirm={handleDelete}
|
||||||
title={t("documents.labels.confirmdelete")}
|
title={t("documents.labels.confirmdelete")}
|
||||||
okText={t("general.actions.delete")}
|
okText={t("general.actions.delete")}
|
||||||
okButtonProps={{ type: "danger" }}
|
okButtonProps={{ danger: true }}
|
||||||
cancelText={t("general.actions.cancel")}
|
cancelText={t("general.actions.cancel")}
|
||||||
>
|
>
|
||||||
<Button loading={loading}>{t("documents.actions.delete")}</Button>
|
<Button danger disabled={imagesToDelete.length < 1} loading={loading}>
|
||||||
|
{t("documents.actions.delete")}
|
||||||
|
</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Button } from "antd";
|
import { Button, Space } from "antd";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import cleanAxios from "../../utils/CleanAxios";
|
import cleanAxios from "../../utils/CleanAxios";
|
||||||
|
import formatBytes from "../../utils/formatbytes";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { selectAllMedia } from "../../redux/media/media.selectors";
|
import { selectAllMedia } from "../../redux/media/media.selectors";
|
||||||
@@ -19,45 +19,63 @@ export default connect(mapStateToProps, mapDispatchToProps)(JobsLocalGalleryDown
|
|||||||
|
|
||||||
export function JobsLocalGalleryDownloadButton({ bodyshop, allMedia, job }) {
|
export function JobsLocalGalleryDownloadButton({ bodyshop, allMedia, job }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [download, setDownload] = useState(null);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [download, setDownload] = useState(false);
|
||||||
|
|
||||||
function downloadProgress(progressEvent) {
|
const imagesToDownload = (allMedia?.[job.id] || []).filter((i) => i.isSelected);
|
||||||
setDownload((currentDownloadState) => {
|
|
||||||
return {
|
const downloadProgress = ({ loaded }) => {
|
||||||
downloaded: progressEvent.loaded || 0,
|
setDownload((currentDownloadState) => ({
|
||||||
speed: (progressEvent.loaded || 0) - (currentDownloadState?.downloaded || 0)
|
downloaded: loaded || 0,
|
||||||
};
|
speed: (loaded || 0) - (currentDownloadState?.downloaded || 0)
|
||||||
});
|
}));
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const standardMediaDownload = (bufferData, filename) => {
|
||||||
|
try {
|
||||||
|
const a = document.createElement("a");
|
||||||
|
const url = window.URL.createObjectURL(new Blob([bufferData]));
|
||||||
|
a.href = url;
|
||||||
|
a.download = `${filename}.zip`;
|
||||||
|
a.click();
|
||||||
|
} catch {
|
||||||
|
setLoading(false);
|
||||||
|
setDownload(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleDownload = async () => {
|
const handleDownload = async () => {
|
||||||
const theDownloadedZip = await cleanAxios.post(
|
const { localmediaserverhttp, localmediatoken } = bodyshop;
|
||||||
`${bodyshop.localmediaserverhttp}/jobs/download`,
|
const { id, ro_number } = job;
|
||||||
{
|
setLoading(true);
|
||||||
jobid: job.id,
|
try {
|
||||||
files: (allMedia?.[job.id] || []).filter((i) => i.isSelected).map((i) => i.filename)
|
const response = await cleanAxios.post(
|
||||||
},
|
`${localmediaserverhttp}/jobs/download`,
|
||||||
{
|
{
|
||||||
headers: { ims_token: bodyshop.localmediatoken },
|
jobid: id,
|
||||||
responseType: "arraybuffer",
|
files: imagesToDownload.map((i) => i.filename)
|
||||||
onDownloadProgress: downloadProgress
|
},
|
||||||
}
|
{
|
||||||
);
|
headers: { ims_token: localmediatoken },
|
||||||
setDownload(null);
|
responseType: "arraybuffer",
|
||||||
standardMediaDownload(theDownloadedZip.data, job.ro_number);
|
onDownloadProgress: downloadProgress
|
||||||
|
}
|
||||||
|
);
|
||||||
|
standardMediaDownload(response.data, ro_number);
|
||||||
|
} catch {
|
||||||
|
// handle error (optional)
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
setDownload(null);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button loading={!!download} onClick={handleDownload}>
|
<Button disabled={imagesToDownload < 1} loading={download || loading} onClick={handleDownload}>
|
||||||
{t("documents.actions.download")}
|
<Space>
|
||||||
|
<span>{t("documents.actions.download")}</span>
|
||||||
|
{download && <span>{`(${formatBytes(download.downloaded)} @ ${formatBytes(download.speed)} / second)`}</span>}
|
||||||
|
</Space>
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function standardMediaDownload(bufferData, filename) {
|
|
||||||
const a = document.createElement("a");
|
|
||||||
const url = window.URL.createObjectURL(new Blob([bufferData]));
|
|
||||||
a.href = url;
|
|
||||||
a.download = `${filename}.zip`;
|
|
||||||
a.click();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
|||||||
<Input onBlur={handleBlur} />
|
<Input onBlur={handleBlur} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
{hasDMSKey && (
|
{hasDMSKey && !bodyshop.rr_dealerid && (
|
||||||
<>
|
<>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||||
@@ -408,23 +408,25 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
|||||||
>
|
>
|
||||||
<Input onBlur={handleBlur} />
|
<Input onBlur={handleBlur} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
{hasDMSKey && !bodyshop.rr_dealerid && (
|
||||||
label={t("bodyshop.fields.responsibilitycenter_accountitem")}
|
<>
|
||||||
key={`${index}accountitem`}
|
<Form.Item
|
||||||
name={[field.name, "accountitem"]}
|
label={t("bodyshop.fields.responsibilitycenter_accountitem")}
|
||||||
rules={[{ required: true }]}
|
key={`${index}accountitem`}
|
||||||
>
|
name={[field.name, "accountitem"]}
|
||||||
<Input onBlur={handleBlur} />
|
rules={[{ required: true }]}
|
||||||
</Form.Item>
|
>
|
||||||
{hasDMSKey && (
|
<Input onBlur={handleBlur} />
|
||||||
<Form.Item
|
</Form.Item>
|
||||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
<Form.Item
|
||||||
key={`${index}dms_acctnumber`}
|
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||||
name={[field.name, "dms_acctnumber"]}
|
key={`${index}dms_acctnumber`}
|
||||||
rules={[{ required: true }]}
|
name={[field.name, "dms_acctnumber"]}
|
||||||
>
|
rules={[{ required: true }]}
|
||||||
<Input onBlur={handleBlur} />
|
>
|
||||||
</Form.Item>
|
<Input onBlur={handleBlur} />
|
||||||
|
</Form.Item>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{bodyshop.cdk_dealerid && (
|
{bodyshop.cdk_dealerid && (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const mapDispatchToProps = () => ({
|
|||||||
export function TechHeader({ technician }) {
|
export function TechHeader({ technician }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
return (
|
return (
|
||||||
<Header style={{ textAlign: "center" }}>
|
<Header style={{ textAlign: "center", height: "auto", overflow: "visible" }}>
|
||||||
<Typography.Title style={{ color: "#fff" }}>
|
<Typography.Title style={{ color: "#fff" }}>
|
||||||
{technician
|
{technician
|
||||||
? t("tech.labels.loggedin", {
|
? t("tech.labels.loggedin", {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useMutation, useQuery } from "@apollo/client";
|
import { useMutation, useQuery } from "@apollo/client";
|
||||||
import { Button, Card, Col, Form, InputNumber, Popover, Row, Select } from "antd";
|
import { Button, Card, Form, InputNumber, Popover, Select, Space } from "antd";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
@@ -130,102 +130,12 @@ export function TechClockOffButton({
|
|||||||
cost_center: isShiftTicket ? "timetickets.labels.shift" : technician ? technician.cost_center : null
|
cost_center: isShiftTicket ? "timetickets.labels.shift" : technician ? technician.cost_center : null
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Row gutter={[16, 16]}>
|
<Space direction="vertical">
|
||||||
<Col span={!isShiftTicket ? 8 : 24}>
|
{!isShiftTicket ? (
|
||||||
{!isShiftTicket ? (
|
<div>
|
||||||
<div>
|
|
||||||
<Form.Item
|
|
||||||
label={t("timetickets.fields.actualhrs")}
|
|
||||||
name="actualhrs"
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: true
|
|
||||||
//message: t("general.validation.required"),
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<InputNumber min={0} precision={1} />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
label={t("timetickets.fields.productivehrs")}
|
|
||||||
name="productivehrs"
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: true
|
|
||||||
//message: t("general.validation.required"),
|
|
||||||
},
|
|
||||||
({ getFieldValue }) => ({
|
|
||||||
validator(rule, value) {
|
|
||||||
if (!bodyshop.tt_enforce_hours_for_tech_console) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
if (!value || getFieldValue("cost_center") === null || !lineTicketData)
|
|
||||||
return Promise.resolve();
|
|
||||||
|
|
||||||
//Check the cost center,
|
|
||||||
const totals = CalculateAllocationsTotals(
|
|
||||||
bodyshop,
|
|
||||||
lineTicketData.joblines,
|
|
||||||
lineTicketData.timetickets,
|
|
||||||
lineTicketData.jobs_by_pk.lbr_adjustments
|
|
||||||
);
|
|
||||||
|
|
||||||
const fieldTypeToCheck = hasDmsKey ? "mod_lbr_ty" : "cost_center";
|
|
||||||
|
|
||||||
const costCenterDiff =
|
|
||||||
Math.round(
|
|
||||||
totals.find((total) => total[fieldTypeToCheck] === getFieldValue("cost_center"))
|
|
||||||
?.difference * 10
|
|
||||||
) / 10;
|
|
||||||
|
|
||||||
if (value > costCenterDiff)
|
|
||||||
return Promise.reject(t("timetickets.validation.hoursenteredmorethanavailable"));
|
|
||||||
else {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<InputNumber min={0} precision={1} />
|
|
||||||
</Form.Item>
|
|
||||||
</div>
|
|
||||||
) : null}
|
|
||||||
<Form.Item
|
|
||||||
name="cost_center"
|
|
||||||
label={t("timetickets.fields.cost_center")}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: true
|
|
||||||
//message: t("general.validation.required"),
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Select disabled={isShiftTicket}>
|
|
||||||
{isShiftTicket ? (
|
|
||||||
<Select.Option value="timetickets.labels.shift">{t("timetickets.labels.shift")}</Select.Option>
|
|
||||||
) : (
|
|
||||||
emps &&
|
|
||||||
emps.rates.map((item) => (
|
|
||||||
<Select.Option key={item.cost_center}>
|
|
||||||
{item.cost_center === "timetickets.labels.shift"
|
|
||||||
? t(item.cost_center)
|
|
||||||
: hasDmsKey
|
|
||||||
? t(`joblines.fields.lbr_types.${item.cost_center.toUpperCase()}`)
|
|
||||||
: item.cost_center}
|
|
||||||
</Select.Option>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
{isShiftTicket ? (
|
|
||||||
<div></div>
|
|
||||||
) : (
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="status"
|
label={t("timetickets.fields.actualhrs")}
|
||||||
label={t("jobs.fields.status")}
|
name="actualhrs"
|
||||||
initialValue={lineTicketData && lineTicketData.jobs_by_pk.status}
|
|
||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
required: true
|
required: true
|
||||||
@@ -233,35 +143,121 @@ export function TechClockOffButton({
|
|||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Select>
|
<InputNumber min={0} precision={1} />
|
||||||
{bodyshop.md_ro_statuses.production_statuses.map((item) => (
|
|
||||||
<Select.Option key={item}></Select.Option>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
<Form.Item
|
||||||
<Button type="primary" htmlType="submit" loading={loading}>
|
label={t("timetickets.fields.productivehrs")}
|
||||||
{t("general.actions.save")}
|
name="productivehrs"
|
||||||
</Button>
|
rules={[
|
||||||
<TechJobClockoutDelete completedCallback={completedCallback} timeTicketId={timeTicketId} />
|
{
|
||||||
</Col>
|
required: true
|
||||||
{!isShiftTicket && (
|
//message: t("general.validation.required"),
|
||||||
<Col span={16}>
|
},
|
||||||
<LaborAllocationContainer
|
({ getFieldValue }) => ({
|
||||||
jobid={jobId || null}
|
validator(rule, value) {
|
||||||
loading={queryLoading}
|
if (!bodyshop.tt_enforce_hours_for_tech_console) {
|
||||||
lineTicketData={lineTicketData}
|
return Promise.resolve();
|
||||||
/>
|
}
|
||||||
</Col>
|
if (!value || getFieldValue("cost_center") === null || !lineTicketData)
|
||||||
|
return Promise.resolve();
|
||||||
|
|
||||||
|
//Check the cost center,
|
||||||
|
const totals = CalculateAllocationsTotals(
|
||||||
|
bodyshop,
|
||||||
|
lineTicketData.joblines,
|
||||||
|
lineTicketData.timetickets,
|
||||||
|
lineTicketData.jobs_by_pk.lbr_adjustments
|
||||||
|
);
|
||||||
|
|
||||||
|
const fieldTypeToCheck = hasDmsKey ? "mod_lbr_ty" : "cost_center";
|
||||||
|
|
||||||
|
const costCenterDiff =
|
||||||
|
Math.round(
|
||||||
|
totals.find((total) => total[fieldTypeToCheck] === getFieldValue("cost_center"))
|
||||||
|
?.difference * 10
|
||||||
|
) / 10;
|
||||||
|
|
||||||
|
if (value > costCenterDiff)
|
||||||
|
return Promise.reject(t("timetickets.validation.hoursenteredmorethanavailable"));
|
||||||
|
else {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<InputNumber min={0} precision={1} />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<Form.Item
|
||||||
|
name="cost_center"
|
||||||
|
label={t("timetickets.fields.cost_center")}
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
required: true
|
||||||
|
//message: t("general.validation.required"),
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Select disabled={isShiftTicket}>
|
||||||
|
{isShiftTicket ? (
|
||||||
|
<Select.Option value="timetickets.labels.shift">{t("timetickets.labels.shift")}</Select.Option>
|
||||||
|
) : (
|
||||||
|
emps &&
|
||||||
|
emps.rates.map((item) => (
|
||||||
|
<Select.Option key={item.cost_center}>
|
||||||
|
{item.cost_center === "timetickets.labels.shift"
|
||||||
|
? t(item.cost_center)
|
||||||
|
: hasDmsKey
|
||||||
|
? t(`joblines.fields.lbr_types.${item.cost_center.toUpperCase()}`)
|
||||||
|
: item.cost_center}
|
||||||
|
</Select.Option>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
{isShiftTicket ? (
|
||||||
|
<div></div>
|
||||||
|
) : (
|
||||||
|
<Form.Item
|
||||||
|
name="status"
|
||||||
|
label={t("jobs.fields.status")}
|
||||||
|
initialValue={lineTicketData && lineTicketData.jobs_by_pk.status}
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
required: true
|
||||||
|
//message: t("general.validation.required"),
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Select>
|
||||||
|
{bodyshop.md_ro_statuses.production_statuses.map((item) => (
|
||||||
|
<Select.Option key={item}></Select.Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
</Row>
|
<Button type="primary" htmlType="submit" loading={loading}>
|
||||||
|
{t("general.actions.save")}
|
||||||
|
</Button>
|
||||||
|
<TechJobClockoutDelete completedCallback={completedCallback} timeTicketId={timeTicketId} />
|
||||||
|
{!isShiftTicket && (
|
||||||
|
<LaborAllocationContainer jobid={jobId || null} loading={queryLoading} lineTicketData={lineTicketData} />
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover content={overlay} trigger="click">
|
<Popover
|
||||||
|
content={<div style={{ maxHeight: "75vh", overflowY: "auto" }}>{overlay}</div>}
|
||||||
|
trigger="click"
|
||||||
|
getPopupContainer={() => document.querySelector("#time-ticket-modal")}
|
||||||
|
>
|
||||||
<Button loading={loading} {...otherBtnProps}>
|
<Button loading={loading} {...otherBtnProps}>
|
||||||
{t("timetickets.actions.clockout")}
|
{t("timetickets.actions.clockout")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import DmsPostForm from "../../components/dms-post-form/dms-post-form.component"
|
|||||||
import DmsLogEvents from "../../components/dms-log-events/dms-log-events.component";
|
import DmsLogEvents from "../../components/dms-log-events/dms-log-events.component";
|
||||||
import DmsCustomerSelector from "../../components/dms-customer-selector/dms-customer-selector.component";
|
import DmsCustomerSelector from "../../components/dms-customer-selector/dms-customer-selector.component";
|
||||||
import DmsAllocationsSummary from "../../components/dms-allocations-summary/dms-allocations-summary.component";
|
import DmsAllocationsSummary from "../../components/dms-allocations-summary/dms-allocations-summary.component";
|
||||||
|
import RrAllocationsSummary from "../../components/dms-allocations-summary/rr-dms-allocations-summary.component";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop
|
bodyshop: selectBodyshop
|
||||||
@@ -65,13 +66,6 @@ const DMS_SOCKET_EVENTS = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, insertAuditTrail }) {
|
export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, insertAuditTrail }) {
|
||||||
const { t } = useTranslation();
|
|
||||||
const history = useNavigate();
|
|
||||||
const search = queryString.parse(useLocation().search);
|
|
||||||
const { jobId } = search;
|
|
||||||
|
|
||||||
const notification = useNotification();
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
treatments: { Fortellis }
|
treatments: { Fortellis }
|
||||||
} = useSplitTreatments({
|
} = useSplitTreatments({
|
||||||
@@ -80,9 +74,46 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
splitKey: bodyshop.imexshopid
|
splitKey: bodyshop.imexshopid
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [resetAfterReconnect, setResetAfterReconnect] = useState(false);
|
||||||
|
const [allocationsSummary, setAllocationsSummary] = useState(null);
|
||||||
|
|
||||||
// Compute a single normalized mode and pick the proper socket
|
// Compute a single normalized mode and pick the proper socket
|
||||||
const mode = getDmsMode(bodyshop, Fortellis.treatment); // "rr" | "fortellis" | "cdk" | "pbs" | "none"
|
const mode = getDmsMode(bodyshop, Fortellis.treatment); // "rr" | "fortellis" | "cdk" | "pbs" | "none"
|
||||||
|
|
||||||
|
// RR-only: derive default OpCode parts from bodyshop RR configuration
|
||||||
|
const isRrMode = mode === DMS_MAP.reynolds;
|
||||||
|
|
||||||
|
const deriveDefaultRrOpCodeParts = () => {
|
||||||
|
if (!isRrMode) return null;
|
||||||
|
|
||||||
|
const cfg = bodyshop?.rr_configuration || {};
|
||||||
|
|
||||||
|
// Adjust these paths to match your real schema.
|
||||||
|
const defaults =
|
||||||
|
cfg.opCodeDefault ||
|
||||||
|
cfg.op_code_default ||
|
||||||
|
cfg.op_codes?.default ||
|
||||||
|
cfg.defaults?.opCode ||
|
||||||
|
cfg.defaults ||
|
||||||
|
cfg.default ||
|
||||||
|
{};
|
||||||
|
|
||||||
|
const prefix = defaults.prefix ?? defaults.opCodePrefix ?? "";
|
||||||
|
const base = defaults.base ?? defaults.opCodeBase ?? "";
|
||||||
|
const suffix = defaults.suffix ?? defaults.opCodeSuffix ?? "";
|
||||||
|
|
||||||
|
return { prefix, base, suffix };
|
||||||
|
};
|
||||||
|
|
||||||
|
const [rrOpCodeParts, setRrOpCodeParts] = useState(() => deriveDefaultRrOpCodeParts());
|
||||||
|
|
||||||
|
const history = useNavigate();
|
||||||
|
const search = queryString.parse(useLocation().search);
|
||||||
|
const { jobId } = search;
|
||||||
|
|
||||||
|
const notification = useNotification();
|
||||||
|
|
||||||
const { socket: wsssocket } = useSocket();
|
const { socket: wsssocket } = useSocket();
|
||||||
const activeSocket = useMemo(() => (isWssMode(mode) ? wsssocket : legacySocket), [mode, wsssocket]);
|
const activeSocket = useMemo(() => (isWssMode(mode) ? wsssocket : legacySocket), [mode, wsssocket]);
|
||||||
|
|
||||||
@@ -91,6 +122,12 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
// One place to set log level
|
// One place to set log level
|
||||||
const [logLevel, setLogLevel] = useState(mode === DMS_MAP.pbs ? "INFO" : "DEBUG");
|
const [logLevel, setLogLevel] = useState(mode === DMS_MAP.pbs ? "INFO" : "DEBUG");
|
||||||
|
|
||||||
|
const rrOpCodeCombined = useMemo(() => {
|
||||||
|
if (!rrOpCodeParts || !rrOpCodeParts.base) return "";
|
||||||
|
const { prefix, base, suffix } = rrOpCodeParts;
|
||||||
|
return `${prefix || ""}${base}${suffix || ""}`;
|
||||||
|
}, [rrOpCodeParts]);
|
||||||
|
|
||||||
const setActiveLogLevel = (level) => {
|
const setActiveLogLevel = (level) => {
|
||||||
if (!activeSocket) return;
|
if (!activeSocket) return;
|
||||||
activeSocket.emit("set-log-level", level);
|
activeSocket.emit("set-log-level", level);
|
||||||
@@ -134,12 +171,51 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
[mode]
|
[mode]
|
||||||
);
|
);
|
||||||
|
|
||||||
const transportLabel = isWssMode(mode) ? "App Socket (WSS)" : "Legacy Socket (WS)";
|
const transportLabel = isWssMode(mode) ? "(WSS)" : "(WS)";
|
||||||
|
|
||||||
const bannerMessage = `Posting to ${providerLabel} | ${transportLabel} | ${
|
const bannerMessage = `Posting to ${providerLabel} | ${transportLabel} | ${
|
||||||
isConnected ? "Connected" : "Disconnected"
|
isConnected ? "Connected" : "Disconnected"
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
const resetKey = useMemo(() => `${mode || "none"}-${jobId || "none"}`, [mode, jobId]);
|
||||||
|
|
||||||
|
// 🔄 Hard reset of local + server-side DMS context when the page/job loads
|
||||||
|
useEffect(() => {
|
||||||
|
// Clear any local ephemeral state that might be stale
|
||||||
|
setLogs([]);
|
||||||
|
setRrOpenRoLimit(false);
|
||||||
|
setrrValidationPending(false);
|
||||||
|
setAllocationsSummary(null);
|
||||||
|
|
||||||
|
// RR OpCode parts: reset to config defaults when job/mode changes
|
||||||
|
setRrOpCodeParts(deriveDefaultRrOpCodeParts());
|
||||||
|
|
||||||
|
if (!activeSocket) return;
|
||||||
|
|
||||||
|
const emitReset = () => {
|
||||||
|
// Generic reset; server can branch on `mode` if needed
|
||||||
|
activeSocket.emit("dms-reset-context", { jobId, mode });
|
||||||
|
};
|
||||||
|
|
||||||
|
if (activeSocket.connected) {
|
||||||
|
// WSS usually lands here
|
||||||
|
emitReset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Legacy WS: wait for the connect before emitting reset
|
||||||
|
const handleConnectOnce = () => {
|
||||||
|
emitReset();
|
||||||
|
activeSocket.off("connect", handleConnectOnce);
|
||||||
|
};
|
||||||
|
|
||||||
|
activeSocket.on("connect", handleConnectOnce);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
activeSocket.off("connect", handleConnectOnce);
|
||||||
|
};
|
||||||
|
}, [jobId, mode, activeSocket]);
|
||||||
|
|
||||||
const handleExportFailed = (payload = {}) => {
|
const handleExportFailed = (payload = {}) => {
|
||||||
const { title, friendlyMessage, error: errText, severity, errorCode, vendorStatusCode } = payload;
|
const { title, friendlyMessage, error: errText, severity, errorCode, vendorStatusCode } = payload;
|
||||||
|
|
||||||
@@ -148,10 +224,10 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
errText ||
|
errText ||
|
||||||
t("dms.errors.exportfailedgeneric", "We couldn't complete the export. Please try again.");
|
t("dms.errors.exportfailedgeneric", "We couldn't complete the export. Please try again.");
|
||||||
|
|
||||||
const vendorTitle = title || (mode === DMS_MAP.reynolds ? "Reynolds" : "DMS");
|
const vendorTitle = title || (isRrMode ? "Reynolds" : "DMS");
|
||||||
|
|
||||||
const isRrOpenRoLimit =
|
const isRrOpenRoLimit =
|
||||||
mode === DMS_MAP.reynolds &&
|
isRrMode &&
|
||||||
(vendorStatusCode === 507 ||
|
(vendorStatusCode === 507 ||
|
||||||
/MAX_OPEN_ROS/i.test(String(errorCode || "")) ||
|
/MAX_OPEN_ROS/i.test(String(errorCode || "")) ||
|
||||||
/maximum number of open repair orders/i.test(String(msg || "").toLowerCase()));
|
/maximum number of open repair orders/i.test(String(msg || "").toLowerCase()));
|
||||||
@@ -187,8 +263,8 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
});
|
});
|
||||||
setSelectedHeader("dms");
|
setSelectedHeader("dms");
|
||||||
setBreadcrumbs([
|
setBreadcrumbs([
|
||||||
{ link: "/manage/accounting/receivables", label: t("titles.bc.accounting-receivables") },
|
{ link: "/manage/accounting/receivables", label: t("titles.bc.accounting-receivables") }
|
||||||
{ link: "/manage/dms", label: t("titles.bc.dms") }
|
// { link: "/manage/dms", label: t("titles.bc.dms") }
|
||||||
]);
|
]);
|
||||||
}, [t, setBreadcrumbs, setSelectedHeader]);
|
}, [t, setBreadcrumbs, setSelectedHeader]);
|
||||||
|
|
||||||
@@ -207,6 +283,11 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
const onConnect = () => {
|
const onConnect = () => {
|
||||||
setIsConnected(true);
|
setIsConnected(true);
|
||||||
setActiveLogLevel(logLevel);
|
setActiveLogLevel(logLevel);
|
||||||
|
|
||||||
|
if (resetAfterReconnect) {
|
||||||
|
activeSocket.emit("dms-reset-context", { jobId, mode });
|
||||||
|
setResetAfterReconnect(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onDisconnect = () => setIsConnected(false);
|
const onDisconnect = () => setIsConnected(false);
|
||||||
@@ -218,7 +299,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
{
|
{
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
level: "warn",
|
level: "warn",
|
||||||
message: `Reconnected to ${mode === DMS_MAP.reynolds ? "RR" : mode === DMS_MAP.fortellis ? "Fortellis" : "DMS"} Export Service`
|
message: `Reconnected to ${isRrMode ? "RR" : mode === DMS_MAP.fortellis ? "Fortellis" : "DMS"} Export Service`
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
@@ -235,22 +316,17 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
activeSocket.on("connect_error", onConnectError);
|
activeSocket.on("connect_error", onConnectError);
|
||||||
|
|
||||||
// Logs
|
// Logs
|
||||||
const onLog =
|
const onLog = isRrMode
|
||||||
mode === DMS_MAP.reynolds
|
? (payload = {}) => {
|
||||||
? (payload = {}) => {
|
const normalized = {
|
||||||
const normalized = {
|
timestamp: payload.timestamp ? new Date(payload.timestamp) : payload.ts ? new Date(payload.ts) : new Date(),
|
||||||
timestamp: payload.timestamp
|
level: (payload.level || "INFO").toUpperCase(),
|
||||||
? new Date(payload.timestamp)
|
message: payload.message || payload.msg || "",
|
||||||
: payload.ts
|
meta: payload.meta ?? payload.ctx ?? payload.details ?? null
|
||||||
? new Date(payload.ts)
|
};
|
||||||
: new Date(),
|
setLogs((prev) => [...prev, normalized]);
|
||||||
level: (payload.level || "INFO").toUpperCase(),
|
}
|
||||||
message: payload.message || payload.msg || "",
|
: (payload) => setLogs((prev) => [...prev, payload]);
|
||||||
meta: payload.meta ?? payload.ctx ?? payload.details ?? null
|
|
||||||
};
|
|
||||||
setLogs((prev) => [...prev, normalized]);
|
|
||||||
}
|
|
||||||
: (payload) => setLogs((prev) => [...prev, payload]);
|
|
||||||
|
|
||||||
if (channels.log) activeSocket.on(channels.log, onLog);
|
if (channels.log) activeSocket.on(channels.log, onLog);
|
||||||
|
|
||||||
@@ -308,9 +384,8 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mode === DMS_MAP.reynolds && channels.partialResult) activeSocket.on(channels.partialResult, onPartialResult);
|
if (isRrMode && channels.partialResult) activeSocket.on(channels.partialResult, onPartialResult);
|
||||||
if (mode === DMS_MAP.reynolds && channels.validationNeeded)
|
if (isRrMode && channels.validationNeeded) activeSocket.on(channels.validationNeeded, onValidationRequired);
|
||||||
activeSocket.on(channels.validationNeeded, onValidationRequired);
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
activeSocket.off("connect", onConnect);
|
activeSocket.off("connect", onConnect);
|
||||||
@@ -322,10 +397,8 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
if (channels.exportSuccess) activeSocket.off(channels.exportSuccess, onExportSuccess);
|
if (channels.exportSuccess) activeSocket.off(channels.exportSuccess, onExportSuccess);
|
||||||
if (channels.exportFailed) activeSocket.off(channels.exportFailed, handleExportFailed);
|
if (channels.exportFailed) activeSocket.off(channels.exportFailed, handleExportFailed);
|
||||||
|
|
||||||
if (mode === DMS_MAP.reynolds && channels.partialResult)
|
if (isRrMode && channels.partialResult) activeSocket.off(channels.partialResult, onPartialResult);
|
||||||
activeSocket.off(channels.partialResult, onPartialResult);
|
if (isRrMode && channels.validationNeeded) activeSocket.off(channels.validationNeeded, onValidationRequired);
|
||||||
if (mode === DMS_MAP.reynolds && channels.validationNeeded)
|
|
||||||
activeSocket.off(channels.validationNeeded, onValidationRequired);
|
|
||||||
|
|
||||||
// Only tear down legacy socket listeners; don't disconnect WSS from here
|
// Only tear down legacy socket listeners; don't disconnect WSS from here
|
||||||
if (!isWssMode(mode)) {
|
if (!isWssMode(mode)) {
|
||||||
@@ -358,24 +431,57 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
<AlertComponent style={{ marginBottom: 10 }} message={bannerMessage} type="warning" showIcon closable />
|
<AlertComponent style={{ marginBottom: 10 }} message={bannerMessage} type="warning" showIcon closable />
|
||||||
|
|
||||||
<Row gutter={[16, 16]}>
|
<Row gutter={[16, 16]}>
|
||||||
<Col md={24} lg={10}>
|
<Col md={24} lg={10} className="dms-equal-height-col">
|
||||||
<DmsAllocationsSummary
|
{!isRrMode ? (
|
||||||
title={
|
<DmsAllocationsSummary
|
||||||
<span>
|
key={resetKey}
|
||||||
<Link
|
onAllocationsChange={setAllocationsSummary}
|
||||||
to={`/manage/jobs/${data && data.jobs_by_pk.id}`}
|
title={
|
||||||
>{`${data?.jobs_by_pk && data.jobs_by_pk.ro_number}`}</Link>
|
<span>
|
||||||
{` | ${OwnerNameDisplayFunction(data.jobs_by_pk)} | ${data.jobs_by_pk.v_model_yr || ""} ${data.jobs_by_pk.v_make_desc || ""} ${data.jobs_by_pk.v_model_desc || ""}`}
|
<Link
|
||||||
</span>
|
to={`/manage/jobs/${data && data.jobs_by_pk.id}`}
|
||||||
}
|
>{`${data?.jobs_by_pk && data.jobs_by_pk.ro_number}`}</Link>
|
||||||
socket={activeSocket}
|
{` | ${OwnerNameDisplayFunction(data.jobs_by_pk)} | ${data.jobs_by_pk.v_model_yr || ""} ${
|
||||||
jobId={jobId}
|
data.jobs_by_pk.v_make_desc || ""
|
||||||
mode={mode}
|
} ${data.jobs_by_pk.v_model_desc || ""}`}
|
||||||
/>
|
</span>
|
||||||
|
}
|
||||||
|
socket={activeSocket}
|
||||||
|
jobId={jobId}
|
||||||
|
mode={mode}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<RrAllocationsSummary
|
||||||
|
key={resetKey}
|
||||||
|
onAllocationsChange={setAllocationsSummary}
|
||||||
|
title={
|
||||||
|
<span>
|
||||||
|
<Link to={`/manage/jobs/${data && data.jobs_by_pk.id}`}>
|
||||||
|
{data?.jobs_by_pk && data.jobs_by_pk.ro_number}
|
||||||
|
</Link>
|
||||||
|
{` | ${OwnerNameDisplayFunction(data.jobs_by_pk)} | ${
|
||||||
|
data.jobs_by_pk.v_model_yr || ""
|
||||||
|
} ${data.jobs_by_pk.v_make_desc || ""} ${data.jobs_by_pk.v_model_desc || ""}`}
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
socket={activeSocket}
|
||||||
|
jobId={jobId}
|
||||||
|
opCode={rrOpCodeCombined}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col md={24} lg={14}>
|
<Col md={24} lg={14} className="dms-equal-height-col">
|
||||||
<DmsPostForm socket={activeSocket} job={data?.jobs_by_pk} logsRef={logsRef} mode={mode} />
|
<DmsPostForm
|
||||||
|
key={resetKey}
|
||||||
|
socket={activeSocket}
|
||||||
|
job={data?.jobs_by_pk}
|
||||||
|
logsRef={logsRef}
|
||||||
|
mode={mode}
|
||||||
|
allocationsSummary={allocationsSummary}
|
||||||
|
rrOpCodeParts={rrOpCodeParts}
|
||||||
|
onChangeRrOpCodeParts={setRrOpCodeParts}
|
||||||
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<DmsCustomerSelector
|
<DmsCustomerSelector
|
||||||
@@ -397,13 +503,18 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
title={t("jobs.labels.dms.logs")}
|
title={t("jobs.labels.dms.logs")}
|
||||||
extra={
|
extra={
|
||||||
<Space wrap>
|
<Space wrap>
|
||||||
<Switch
|
{isRrMode && (
|
||||||
checked={colorizeJson}
|
<>
|
||||||
onChange={setColorizeJson}
|
<Switch
|
||||||
checkedChildren="Color JSON"
|
checked={colorizeJson}
|
||||||
unCheckedChildren="Plain JSON"
|
onChange={setColorizeJson}
|
||||||
/>
|
checkedChildren="Color JSON"
|
||||||
<Button onClick={toggleDetailsAll}>{detailsOpen ? "Collapse All" : "Expand All"}</Button>
|
unCheckedChildren="Plain JSON"
|
||||||
|
/>
|
||||||
|
<Button onClick={toggleDetailsAll}>{detailsOpen ? "Collapse All" : "Expand All"}</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
placeholder="Log Level"
|
placeholder="Log Level"
|
||||||
value={logLevel}
|
value={logLevel}
|
||||||
@@ -422,11 +533,14 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setLogs([]);
|
setLogs([]);
|
||||||
|
setResetAfterReconnect(true);
|
||||||
if (isWssMode(mode)) {
|
if (isWssMode(mode)) {
|
||||||
setActiveLogLevel(logLevel);
|
setActiveLogLevel(logLevel);
|
||||||
}
|
}
|
||||||
activeSocket.disconnect();
|
if (activeSocket) {
|
||||||
activeSocket.connect();
|
activeSocket.disconnect();
|
||||||
|
setTimeout(() => activeSocket.connect(), 100);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Reconnect
|
Reconnect
|
||||||
@@ -436,9 +550,12 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
>
|
>
|
||||||
<DmsLogEvents
|
<DmsLogEvents
|
||||||
logs={logs}
|
logs={logs}
|
||||||
detailsOpen={detailsOpen}
|
// Only honour details/colorized JSON in RR mode;
|
||||||
|
// in other modes DmsLogEvents can render a simple, flat list.
|
||||||
|
detailsOpen={isRrMode ? detailsOpen : false}
|
||||||
detailsNonce={detailsNonce}
|
detailsNonce={detailsNonce}
|
||||||
colorizeJson={colorizeJson}
|
colorizeJson={isRrMode ? colorizeJson : false}
|
||||||
|
showDetails={isRrMode}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ import {
|
|||||||
validatePasswordResetSuccess
|
validatePasswordResetSuccess
|
||||||
} from "./user.actions";
|
} from "./user.actions";
|
||||||
import UserActionTypes from "./user.types";
|
import UserActionTypes from "./user.types";
|
||||||
//import * as amplitude from '@amplitude/analytics-browser';
|
import posthog from "posthog-js";
|
||||||
import posthog from 'posthog-js';
|
import { bodyshopHasDmsKey, determineDMSTypeByBodyshop, DMS_MAP } from "../../utils/dmsUtils";
|
||||||
|
|
||||||
const fpPromise = FingerprintJS.load();
|
const fpPromise = FingerprintJS.load();
|
||||||
|
|
||||||
@@ -269,11 +269,11 @@ export function* signInSuccessSaga({ payload }) {
|
|||||||
instanceSeg,
|
instanceSeg,
|
||||||
...(isParts
|
...(isParts
|
||||||
? [
|
? [
|
||||||
InstanceRenderManager({
|
InstanceRenderManager({
|
||||||
imex: "ImexPartsManagement",
|
imex: "ImexPartsManagement",
|
||||||
rome: "RomePartsManagement"
|
rome: "RomePartsManagement"
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
: [])
|
: [])
|
||||||
];
|
];
|
||||||
window.$crisp.push(["set", "session:segments", [segs]]);
|
window.$crisp.push(["set", "session:segments", [segs]]);
|
||||||
@@ -375,17 +375,30 @@ export function* SetAuthLevelFromShopDetails({ payload }) {
|
|||||||
const isParts = yield select((state) => state.application.isPartsEntry === true);
|
const isParts = yield select((state) => state.application.isPartsEntry === true);
|
||||||
const instanceSeg = InstanceRenderManager({ imex: "imex", rome: "rome" });
|
const instanceSeg = InstanceRenderManager({ imex: "imex", rome: "rome" });
|
||||||
|
|
||||||
let featureSegments;
|
const featureSegments =
|
||||||
if (payload.features?.allAccess === true) {
|
payload.features?.allAccess === true
|
||||||
featureSegments = ["allAccess"];
|
? ["allAccess"]
|
||||||
} else {
|
: [
|
||||||
const featureKeys = Object.keys(payload.features).filter(
|
"basic",
|
||||||
(key) =>
|
...Object.keys(payload.features).filter(
|
||||||
payload.features[key] === true ||
|
(key) =>
|
||||||
(typeof payload.features[key] === "string" && !isNaN(Date.parse(payload.features[key])))
|
payload.features[key] === true ||
|
||||||
);
|
(typeof payload.features[key] === "string" && !isNaN(Date.parse(payload.features[key])))
|
||||||
featureSegments = ["basic", ...featureKeys];
|
)
|
||||||
}
|
];
|
||||||
|
|
||||||
|
const hasDmsKey = bodyshopHasDmsKey(payload);
|
||||||
|
const dmsType = hasDmsKey ? determineDMSTypeByBodyshop(payload) : null;
|
||||||
|
|
||||||
|
const additionalSegments = [
|
||||||
|
dmsType === DMS_MAP.cdk && DMS_MAP.cdk.toUpperCase(),
|
||||||
|
dmsType === DMS_MAP.pbs && DMS_MAP.pbs.toUpperCase(),
|
||||||
|
dmsType === DMS_MAP.reynolds && DMS_MAP.reynolds.toUpperCase(),
|
||||||
|
payload.accountingconfig?.qbo === true && "QBO",
|
||||||
|
payload.accountingconfig?.qbo === false && !hasDmsKey && "QBD"
|
||||||
|
].filter(Boolean);
|
||||||
|
|
||||||
|
featureSegments.push(...additionalSegments);
|
||||||
|
|
||||||
const regionSeg = payload.region_config ? `region:${payload.region_config}` : null;
|
const regionSeg = payload.region_config ? `region:${payload.region_config}` : null;
|
||||||
const segments = [instanceSeg, ...(regionSeg ? [regionSeg] : []), ...featureSegments];
|
const segments = [instanceSeg, ...(regionSeg ? [regionSeg] : []), ...featureSegments];
|
||||||
|
|||||||
@@ -3223,6 +3223,7 @@
|
|||||||
"parts_not_recieved_vendor": "Parts Not Received by Vendor",
|
"parts_not_recieved_vendor": "Parts Not Received by Vendor",
|
||||||
"parts_received_not_scheduled": "Parts Received for Jobs Not Scheduled",
|
"parts_received_not_scheduled": "Parts Received for Jobs Not Scheduled",
|
||||||
"payments_by_date": "Payments by Date",
|
"payments_by_date": "Payments by Date",
|
||||||
|
"payments_by_date_excel": "Payments by Date - Excel",
|
||||||
"payments_by_date_payment": "Payments by Date and Payment Type",
|
"payments_by_date_payment": "Payments by Date and Payment Type",
|
||||||
"payments_by_date_type": "Payments by Date and Customer Type",
|
"payments_by_date_type": "Payments by Date and Customer Type",
|
||||||
"production_by_category": "Production by Category",
|
"production_by_category": "Production by Category",
|
||||||
|
|||||||
@@ -3220,6 +3220,7 @@
|
|||||||
"parts_not_recieved_vendor": "",
|
"parts_not_recieved_vendor": "",
|
||||||
"parts_received_not_scheduled": "",
|
"parts_received_not_scheduled": "",
|
||||||
"payments_by_date": "",
|
"payments_by_date": "",
|
||||||
|
"payments_by_date_excel": "",
|
||||||
"payments_by_date_payment": "",
|
"payments_by_date_payment": "",
|
||||||
"payments_by_date_type": "",
|
"payments_by_date_type": "",
|
||||||
"production_by_category": "",
|
"production_by_category": "",
|
||||||
|
|||||||
@@ -3220,6 +3220,7 @@
|
|||||||
"parts_not_recieved_vendor": "",
|
"parts_not_recieved_vendor": "",
|
||||||
"parts_received_not_scheduled": "",
|
"parts_received_not_scheduled": "",
|
||||||
"payments_by_date": "",
|
"payments_by_date": "",
|
||||||
|
"payments_by_date_excel": "",
|
||||||
"payments_by_date_payment": "",
|
"payments_by_date_payment": "",
|
||||||
"payments_by_date_type": "",
|
"payments_by_date_type": "",
|
||||||
"production_by_category": "",
|
"production_by_category": "",
|
||||||
|
|||||||
@@ -1218,6 +1218,18 @@ export const TemplateList = (type, context) => {
|
|||||||
},
|
},
|
||||||
group: "customers"
|
group: "customers"
|
||||||
},
|
},
|
||||||
|
payments_by_date_excel: {
|
||||||
|
title: i18n.t("reportcenter.templates.payments_by_date_excel"),
|
||||||
|
subject: i18n.t("reportcenter.templates.payments_by_date_excel"),
|
||||||
|
key: "payments_by_date_excel",
|
||||||
|
reporttype: "excel",
|
||||||
|
disabled: false,
|
||||||
|
rangeFilter: {
|
||||||
|
object: i18n.t("reportcenter.labels.objects.payments"),
|
||||||
|
field: i18n.t("payments.fields.date")
|
||||||
|
},
|
||||||
|
group: "customers"
|
||||||
|
},
|
||||||
schedule: {
|
schedule: {
|
||||||
title: i18n.t("reportcenter.templates.schedule"),
|
title: i18n.t("reportcenter.templates.schedule"),
|
||||||
subject: i18n.t("reportcenter.templates.schedule"),
|
subject: i18n.t("reportcenter.templates.schedule"),
|
||||||
|
|||||||
@@ -70,3 +70,26 @@ export const isWssMode = (mode) => {
|
|||||||
*/
|
*/
|
||||||
export const bodyshopHasDmsKey = (bodyshop) =>
|
export const bodyshopHasDmsKey = (bodyshop) =>
|
||||||
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid;
|
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve RR OpCode from bodyshop.rr_configuration.defaults
|
||||||
|
* Is Duplicated on server/rr/rr-utils.js
|
||||||
|
* @param bodyshop
|
||||||
|
* @returns {`${string}${string}${string}`}
|
||||||
|
*/
|
||||||
|
export const resolveRROpCodeFromBodyshop = (bodyshop) => {
|
||||||
|
if (!bodyshop) throw new Error("bodyshop is required");
|
||||||
|
|
||||||
|
const cfg = bodyshop?.rr_configuration || {};
|
||||||
|
const defaults = cfg?.defaults || {};
|
||||||
|
|
||||||
|
const prefix = (defaults.prefix ?? "").toString().trim();
|
||||||
|
const base = (defaults.base ?? "").toString().trim();
|
||||||
|
const suffix = (defaults.suffix ?? "").toString().trim();
|
||||||
|
|
||||||
|
if (!prefix && !base && !suffix) {
|
||||||
|
throw new Error("No RR OpCode parts found in bodyshop configuration");
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${prefix}${base}${suffix}`;
|
||||||
|
};
|
||||||
|
|||||||
@@ -3698,6 +3698,7 @@
|
|||||||
- deliverchecklist
|
- deliverchecklist
|
||||||
- depreciation_taxes
|
- depreciation_taxes
|
||||||
- dms_allocation
|
- dms_allocation
|
||||||
|
- dms_id
|
||||||
- driveable
|
- driveable
|
||||||
- employee_body
|
- employee_body
|
||||||
- employee_csr
|
- employee_csr
|
||||||
@@ -3975,6 +3976,7 @@
|
|||||||
- deliverchecklist
|
- deliverchecklist
|
||||||
- depreciation_taxes
|
- depreciation_taxes
|
||||||
- dms_allocation
|
- dms_allocation
|
||||||
|
- dms_id
|
||||||
- driveable
|
- driveable
|
||||||
- employee_body
|
- employee_body
|
||||||
- employee_csr
|
- employee_csr
|
||||||
@@ -4264,6 +4266,7 @@
|
|||||||
- deliverchecklist
|
- deliverchecklist
|
||||||
- depreciation_taxes
|
- depreciation_taxes
|
||||||
- dms_allocation
|
- dms_allocation
|
||||||
|
- dms_id
|
||||||
- driveable
|
- driveable
|
||||||
- employee_body
|
- employee_body
|
||||||
- employee_csr
|
- employee_csr
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-- Could not auto-generate a down migration.
|
||||||
|
-- Please write an appropriate down migration for the SQL below:
|
||||||
|
-- alter table "public"."media_analytics" add column "unique_documents" numeric
|
||||||
|
-- null;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
alter table "public"."media_analytics" add column "unique_documents" numeric
|
||||||
|
null;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-- Could not auto-generate a down migration.
|
||||||
|
-- Please write an appropriate down migration for the SQL below:
|
||||||
|
-- alter table "public"."media_analytics" add column "duplicate_documents" numeric
|
||||||
|
-- null;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
alter table "public"."media_analytics" add column "duplicate_documents" numeric
|
||||||
|
null;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-- Could not auto-generate a down migration.
|
||||||
|
-- Please write an appropriate down migration for the SQL below:
|
||||||
|
-- alter table "public"."media_analytics_detail" add column "unique_documents" numeric
|
||||||
|
-- null;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
alter table "public"."media_analytics_detail" add column "unique_documents" numeric
|
||||||
|
null;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-- Could not auto-generate a down migration.
|
||||||
|
-- Please write an appropriate down migration for the SQL below:
|
||||||
|
-- alter table "public"."media_analytics_detail" add column "duplicate_documents" numeric
|
||||||
|
-- null;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
alter table "public"."media_analytics_detail" add column "duplicate_documents" numeric
|
||||||
|
null;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
alter table "public"."media_analytics_detail" rename column "unique_document_count" to "unique_documents";
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
alter table "public"."media_analytics_detail" rename column "unique_documents" to "unique_document_count";
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
alter table "public"."media_analytics_detail" rename column "duplicate_count" to "duplicate_documents";
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
alter table "public"."media_analytics_detail" rename column "duplicate_documents" to "duplicate_count";
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-- Could not auto-generate a down migration.
|
||||||
|
-- Please write an appropriate down migration for the SQL below:
|
||||||
|
-- alter table "public"."jobs" add column "dms_id" text
|
||||||
|
-- null;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
alter table "public"."jobs" add column "dms_id" text
|
||||||
|
null;
|
||||||
857
package-lock.json
generated
857
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
26
package.json
26
package.json
@@ -18,14 +18,14 @@
|
|||||||
"job-totals-fixtures:local": "docker exec node-app /usr/bin/node /app/download-job-totals-fixtures.js"
|
"job-totals-fixtures:local": "docker exec node-app /usr/bin/node /app/download-job-totals-fixtures.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-cloudwatch-logs": "^3.932.0",
|
"@aws-sdk/client-cloudwatch-logs": "^3.943.0",
|
||||||
"@aws-sdk/client-elasticache": "^3.932.0",
|
"@aws-sdk/client-elasticache": "^3.943.0",
|
||||||
"@aws-sdk/client-s3": "^3.932.0",
|
"@aws-sdk/client-s3": "^3.943.0",
|
||||||
"@aws-sdk/client-secrets-manager": "^3.932.0",
|
"@aws-sdk/client-secrets-manager": "^3.943.0",
|
||||||
"@aws-sdk/client-ses": "^3.932.0",
|
"@aws-sdk/client-ses": "^3.943.0",
|
||||||
"@aws-sdk/credential-provider-node": "^3.932.0",
|
"@aws-sdk/credential-provider-node": "^3.943.0",
|
||||||
"@aws-sdk/lib-storage": "^3.932.0",
|
"@aws-sdk/lib-storage": "^3.943.0",
|
||||||
"@aws-sdk/s3-request-presigner": "^3.932.0",
|
"@aws-sdk/s3-request-presigner": "^3.943.0",
|
||||||
"@opensearch-project/opensearch": "^2.13.0",
|
"@opensearch-project/opensearch": "^2.13.0",
|
||||||
"@socket.io/admin-ui": "^0.5.1",
|
"@socket.io/admin-ui": "^0.5.1",
|
||||||
"@socket.io/redis-adapter": "^8.3.0",
|
"@socket.io/redis-adapter": "^8.3.0",
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
"axios": "^1.13.2",
|
"axios": "^1.13.2",
|
||||||
"axios-curlirize": "^2.0.0",
|
"axios-curlirize": "^2.0.0",
|
||||||
"better-queue": "^3.8.12",
|
"better-queue": "^3.8.12",
|
||||||
"bullmq": "^5.63.2",
|
"bullmq": "^5.65.1",
|
||||||
"chart.js": "^4.5.1",
|
"chart.js": "^4.5.1",
|
||||||
"cloudinary": "^2.8.0",
|
"cloudinary": "^2.8.0",
|
||||||
"compression": "^1.8.1",
|
"compression": "^1.8.1",
|
||||||
@@ -63,19 +63,19 @@
|
|||||||
"phone": "^3.1.67",
|
"phone": "^3.1.67",
|
||||||
"query-string": "7.1.3",
|
"query-string": "7.1.3",
|
||||||
"recursive-diff": "^1.0.9",
|
"recursive-diff": "^1.0.9",
|
||||||
"rimraf": "^6.1.0",
|
"rimraf": "^6.1.2",
|
||||||
"skia-canvas": "^3.0.8",
|
"skia-canvas": "^3.0.8",
|
||||||
"soap": "^1.6.0",
|
"soap": "^1.6.0",
|
||||||
"socket.io": "^4.8.1",
|
"socket.io": "^4.8.1",
|
||||||
"socket.io-adapter": "^2.5.5",
|
"socket.io-adapter": "^2.5.5",
|
||||||
"ssh2-sftp-client": "^11.0.0",
|
"ssh2-sftp-client": "^11.0.0",
|
||||||
"twilio": "^5.10.5",
|
"twilio": "^5.10.6",
|
||||||
"uuid": "^11.1.0",
|
"uuid": "^11.1.0",
|
||||||
"winston": "^3.18.3",
|
"winston": "^3.18.3",
|
||||||
"winston-cloudwatch": "^6.3.0",
|
"winston-cloudwatch": "^6.3.0",
|
||||||
"xml-formatter": "^3.6.7",
|
"xml-formatter": "^3.6.7",
|
||||||
"xml2js": "^0.6.2",
|
"xml2js": "^0.6.2",
|
||||||
"xmlbuilder2": "^4.0.0",
|
"xmlbuilder2": "^4.0.3",
|
||||||
"yazl": "^3.3.1"
|
"yazl": "^3.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
"globals": "^15.15.0",
|
"globals": "^15.15.0",
|
||||||
"mock-require": "^3.0.3",
|
"mock-require": "^3.0.3",
|
||||||
"p-limit": "^3.1.0",
|
"p-limit": "^3.1.0",
|
||||||
"prettier": "^3.6.2",
|
"prettier": "^3.7.3",
|
||||||
"supertest": "^7.1.4",
|
"supertest": "^7.1.4",
|
||||||
"vitest": "^3.2.4"
|
"vitest": "^3.2.4"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,11 +136,7 @@ async function GetFortellisMakes(req, cdk_dealerid) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.log("fortellis-replace-makes-models-response", "ERROR", req.user.email, null, {
|
return result.data?.data;
|
||||||
cdk_dealerid,
|
|
||||||
xml: result
|
|
||||||
});
|
|
||||||
return result.data;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("fortellis-replace-makes-models-error", "ERROR", req.user.email, null, {
|
logger.log("fortellis-replace-makes-models-error", "ERROR", req.user.email, null, {
|
||||||
cdk_dealerid,
|
cdk_dealerid,
|
||||||
@@ -166,14 +162,17 @@ exports.fortellis = async function ReloadFortellisMakes(req, res) {
|
|||||||
|
|
||||||
//Insert the new ones.
|
//Insert the new ones.
|
||||||
|
|
||||||
|
|
||||||
const insertResult = await client.setHeaders({ Authorization: BearerToken }).request(queries.INSERT_DMS_VEHICLES, {
|
const insertResult = await client.setHeaders({ Authorization: BearerToken }).request(queries.INSERT_DMS_VEHICLES, {
|
||||||
vehicles: newList.map((i) => {
|
//Below filtering is requried due to schema requirements.
|
||||||
|
//Does not make sense for there to be empty entries, but leaving in to prevent prod issues.
|
||||||
|
vehicles: newList.filter(i => i.make && i.model && i.make !== '' && i.model !== '' && i.fullMakeName && i.fullModelName && i.fullMakeName !== '' && i.fullModelName !== '').map((i) => {
|
||||||
return {
|
return {
|
||||||
bodyshopid,
|
bodyshopid,
|
||||||
makecode: i.makeCode,
|
makecode: i.make,
|
||||||
modelcode: i.modelCode,
|
modelcode: i.model,
|
||||||
make: i.makeFullName,
|
make: i.fullMakeName,
|
||||||
model: i.modelFullName
|
model: i.fullModelName
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -219,8 +219,6 @@ const CreateRepairOrderTag = (job, errorCallback) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const repairCosts = CreateCosts(job);
|
const repairCosts = CreateCosts(job);
|
||||||
const jobline = CreateJobLines(job.joblines);
|
|
||||||
const timeticket = CreateTimeTickets(job.timetickets);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ret = {
|
const ret = {
|
||||||
@@ -290,8 +288,100 @@ const CreateRepairOrderTag = (job, errorCallback) => {
|
|||||||
(job.date_exported && moment(job.date_exported).tz(job.bodyshop.timezone).format(DateFormat)) || "",
|
(job.date_exported && moment(job.date_exported).tz(job.bodyshop.timezone).format(DateFormat)) || "",
|
||||||
DateVoid: (job.date_void && moment(job.date_void).tz(job.bodyshop.timezone).format(DateFormat)) || ""
|
DateVoid: (job.date_void && moment(job.date_void).tz(job.bodyshop.timezone).format(DateFormat)) || ""
|
||||||
},
|
},
|
||||||
JobLineDetails: { jobline },
|
JobLineDetails: (function () {
|
||||||
TimeTicketDetails: { timeticket },
|
const joblineSource = Array.isArray(job.joblines) ? job.joblines : job.joblines ? [job.joblines] : [];
|
||||||
|
if (joblineSource.length === 0) return { jobline: [] };
|
||||||
|
return {
|
||||||
|
jobline: joblineSource.map((jl = {}) => ({
|
||||||
|
line_description: jl.line_desc || jl.line_description || "",
|
||||||
|
oem_part_no: jl.oem_partno || jl.oem_part_no || "",
|
||||||
|
alt_part_no: jl.alt_partno || jl.alt_part_no || "",
|
||||||
|
op_code_desc: jl.op_code_desc || "",
|
||||||
|
part_type: jl.part_type || "",
|
||||||
|
part_qty: jl.part_qty ?? jl.quantity ?? 0,
|
||||||
|
part_price: jl.act_price ?? jl.part_price ?? 0,
|
||||||
|
labor_type: jl.mod_lbr_ty || jl.labor_type || "",
|
||||||
|
labor_hours: jl.mod_lb_hrs ?? jl.labor_hours ?? 0,
|
||||||
|
labor_sale: jl.lbr_amt ?? jl.labor_sale ?? 0
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
})(),
|
||||||
|
BillsDetails: (function () {
|
||||||
|
const billsSource = Array.isArray(job.bills) ? job.bills : job.bills ? [job.bills] : [];
|
||||||
|
if (billsSource.length === 0) return { BillDetails: [] };
|
||||||
|
return {
|
||||||
|
BillDetails: billsSource.map(
|
||||||
|
({
|
||||||
|
billlines = [],
|
||||||
|
date = "",
|
||||||
|
is_credit_memo = false,
|
||||||
|
invoice_number = "",
|
||||||
|
isinhouse = false,
|
||||||
|
vendor = {}
|
||||||
|
} = {}) => ({
|
||||||
|
BillLines: {
|
||||||
|
BillLine: billlines.map((bl = {}) => ({
|
||||||
|
line_description: bl.line_desc || bl.line_description || "",
|
||||||
|
part_price: bl.actual_price ?? bl.part_price ?? bl.act_price ?? 0,
|
||||||
|
actual_cost: bl.actual_cost ?? 0,
|
||||||
|
cost_center: bl.cost_center || "",
|
||||||
|
deductedfromlbr: bl.deductedfromlbr || false,
|
||||||
|
part_qty: bl.quantity ?? bl.part_qty ?? 0,
|
||||||
|
oem_part_no: bl.oem_partno || bl.oem_part_no || "",
|
||||||
|
alt_part_no: bl.alt_partno || bl.alt_part_no || ""
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
date,
|
||||||
|
is_credit_memo,
|
||||||
|
invoice_number,
|
||||||
|
isinhouse,
|
||||||
|
vendorName: vendor.name || ""
|
||||||
|
})
|
||||||
|
)
|
||||||
|
};
|
||||||
|
})(),
|
||||||
|
JobNotes: (function () {
|
||||||
|
const notesSource = Array.isArray(job.notes) ? job.notes : job.notes ? [job.notes] : [];
|
||||||
|
if (notesSource.length === 0) return { JobNote: [] };
|
||||||
|
return {
|
||||||
|
JobNote: notesSource.map((note = {}) => ({
|
||||||
|
created_at: note.created_at || "",
|
||||||
|
created_by: note.created_by || "",
|
||||||
|
critical: note.critical || false,
|
||||||
|
private: note.private || false,
|
||||||
|
text: note.text || "",
|
||||||
|
type: note.type || ""
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
})(),
|
||||||
|
TimeTicketDetails: (function () {
|
||||||
|
const ticketSource = Array.isArray(job.timetickets)
|
||||||
|
? job.timetickets
|
||||||
|
: job.timetickets
|
||||||
|
? [job.timetickets]
|
||||||
|
: [];
|
||||||
|
if (ticketSource.length === 0) return { timeticket: [] };
|
||||||
|
return {
|
||||||
|
timeticket: ticketSource.map((ticket = {}) => ({
|
||||||
|
date: ticket.date || "",
|
||||||
|
employee:
|
||||||
|
ticket.employee && ticket.employee.employee_number
|
||||||
|
? ticket.employee.employee_number
|
||||||
|
.trim()
|
||||||
|
.concat(" - ", ticket.employee.first_name.trim(), " ", ticket.employee.last_name.trim())
|
||||||
|
.trim()
|
||||||
|
: "",
|
||||||
|
productive_hrs: ticket.productivehrs ?? 0,
|
||||||
|
actual_hrs: ticket.actualhrs ?? 0,
|
||||||
|
cost_center: ticket.cost_center || "",
|
||||||
|
flat_rate: ticket.flat_rate || false,
|
||||||
|
rate: ticket.rate ?? 0,
|
||||||
|
ticket_cost: ticket.flat_rate
|
||||||
|
? ticket.rate * (ticket.productivehrs || 0)
|
||||||
|
: ticket.rate * (ticket.actualhrs || 0)
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
})(),
|
||||||
Sales: {
|
Sales: {
|
||||||
Labour: {
|
Labour: {
|
||||||
Aluminum: Dinero(job.job_totals.rates.laa.total).toFormat(DineroFormat),
|
Aluminum: Dinero(job.job_totals.rates.laa.total).toFormat(DineroFormat),
|
||||||
@@ -636,42 +726,3 @@ const CreateCosts = (job) => {
|
|||||||
}, 0)
|
}, 0)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const CreateJobLines = (joblines) => {
|
|
||||||
const repairLines = [];
|
|
||||||
joblines.forEach((jobline) => {
|
|
||||||
repairLines.push({
|
|
||||||
line_description: jobline.line_desc,
|
|
||||||
oem_part_no: jobline.oem_partno,
|
|
||||||
alt_part_no: jobline.alt_partno,
|
|
||||||
op_code_desc: jobline.op_code_desc,
|
|
||||||
part_type: jobline.part_type,
|
|
||||||
part_qty: jobline.part_qty,
|
|
||||||
part_price: jobline.act_price,
|
|
||||||
labor_type: jobline.mod_lbr_ty,
|
|
||||||
labor_hours: jobline.mod_lb_hrs,
|
|
||||||
labor_sale: jobline.lbr_amt
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return repairLines;
|
|
||||||
};
|
|
||||||
|
|
||||||
const CreateTimeTickets = (timetickets) => {
|
|
||||||
const timeTickets = [];
|
|
||||||
timetickets.forEach((ticket) => {
|
|
||||||
timeTickets.push({
|
|
||||||
date: ticket.date,
|
|
||||||
employee: ticket.employee.employee_number
|
|
||||||
.trim()
|
|
||||||
.concat(" - ", ticket.employee.first_name.trim(), " ", ticket.employee.last_name.trim())
|
|
||||||
.trim(),
|
|
||||||
productive_hrs: ticket.productivehrs,
|
|
||||||
actual_hrs: ticket.actualhrs,
|
|
||||||
cost_center: ticket.cost_center,
|
|
||||||
flat_rate: ticket.flat_rate,
|
|
||||||
rate: ticket.rate,
|
|
||||||
ticket_cost: ticket.flat_rate ? ticket.rate * ticket.productive_hrs : ticket.rate * ticket.actual_hrs
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return timeTickets;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -55,7 +55,9 @@ exports.default = async (req, res) => {
|
|||||||
"patrick.fic@convenient-brands.com",
|
"patrick.fic@convenient-brands.com",
|
||||||
"bradley.rhoades@convenient-brands.com",
|
"bradley.rhoades@convenient-brands.com",
|
||||||
"jrome@rometech.com",
|
"jrome@rometech.com",
|
||||||
"ivana@imexsystems.ca"
|
"ivana@imexsystems.ca",
|
||||||
|
"support@imexsystems.ca",
|
||||||
|
"sarah@rometech.com"
|
||||||
],
|
],
|
||||||
subject: `RO Usage Report - ${moment().format("MM/DD/YYYY")}`,
|
subject: `RO Usage Report - ${moment().format("MM/DD/YYYY")}`,
|
||||||
text: `
|
text: `
|
||||||
|
|||||||
@@ -249,14 +249,14 @@ async function MakeFortellisCall({
|
|||||||
socket?.recordid,
|
socket?.recordid,
|
||||||
{
|
{
|
||||||
wsmessage: "",//message,
|
wsmessage: "",//message,
|
||||||
curl: error.config.curl.curlCommand,
|
curl: error?.config.curlCommand,
|
||||||
reqid: error.request.headers["Request-Id"] || null,
|
reqid: error.config?.headers["Request-Id"] || null,
|
||||||
subscriptionId: error.request.headers["Subscription-Id"] || null,
|
subscriptionId: error.config?.headers["Subscription-Id"] || null,
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
throw new FortellisApiError(`Fortellis API call failed for ${apiName}: ${error.message}`, errorDetails);
|
throw new FortellisApiError(`Fortellis API call failed for ${apiName}: ${error.message} | ${errorDetails?.errorData?.message}`, errorDetails);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,7 +318,7 @@ const FortellisActions = {
|
|||||||
GetMakeModel: {
|
GetMakeModel: {
|
||||||
url: isProduction
|
url: isProduction
|
||||||
? "https://api.fortellis.io/cdk/drive/makemodel/v2/bulk"
|
? "https://api.fortellis.io/cdk/drive/makemodel/v2/bulk"
|
||||||
: "https://api.fortellis.io/cdk-test/drive/makemodel/v2",
|
: "https://api.fortellis.io/cdk-test/drive/makemodel/v2/bulk",
|
||||||
type: "get",
|
type: "get",
|
||||||
apiName: "CDK Drive Get Make Model Lite"
|
apiName: "CDK Drive Get Make Model Lite"
|
||||||
},
|
},
|
||||||
@@ -384,13 +384,13 @@ const FortellisActions = {
|
|||||||
type: "post",
|
type: "post",
|
||||||
apiName: "CDK Drive Post Accounts GL"
|
apiName: "CDK Drive Post Accounts GL"
|
||||||
},
|
},
|
||||||
TranBatchWip: {
|
// TranBatchWip: {
|
||||||
url: isProduction
|
// url: isProduction
|
||||||
? "https://api.fortellis.io/cdk/drive/glpost/transBatchWIP"
|
// ? "https://api.fortellis.io/cdk/drive/glpost/transBatchWIP"
|
||||||
: "https://api.fortellis.io/cdk-test/drive/glpost/transBatchWIP",
|
// : "https://api.fortellis.io/cdk-test/drive/glpost/transBatchWIP",
|
||||||
type: "post",
|
// type: "post",
|
||||||
apiName: "CDK Drive Post Accounts GL"
|
// apiName: "CDK Drive Post Accounts GL"
|
||||||
},
|
// },
|
||||||
PostBatchWip: {
|
PostBatchWip: {
|
||||||
url: isProduction
|
url: isProduction
|
||||||
? "https://api.fortellis.io/cdk/drive/glpost/postBatchWIP"
|
? "https://api.fortellis.io/cdk/drive/glpost/postBatchWIP"
|
||||||
|
|||||||
@@ -968,9 +968,9 @@ async function InsertServiceVehicleHistory({ socket, redisHelpers, JobData }) {
|
|||||||
openTime: moment(JobData.actual_in).tz(JobData.bodyshop.timezone).format("HH:mm:ss"),
|
openTime: moment(JobData.actual_in).tz(JobData.bodyshop.timezone).format("HH:mm:ss"),
|
||||||
closeDate: moment(JobData.invoice_date).tz(JobData.bodyshop.timezone).format("YYYY-MM-DD"),
|
closeDate: moment(JobData.invoice_date).tz(JobData.bodyshop.timezone).format("YYYY-MM-DD"),
|
||||||
closeTime: moment(JobData.invoice_date).tz(JobData.bodyshop.timezone).format("HH:mm:ss"),
|
closeTime: moment(JobData.invoice_date).tz(JobData.bodyshop.timezone).format("HH:mm:ss"),
|
||||||
comments: txEnvelope.story, // has to be between 0 and 40.
|
comments: txEnvelope.story?.slice(0, 40), // has to be between 0 and 40.
|
||||||
cashierId: JobData.bodyshop.cdk_configuration.cashierid,
|
cashierId: JobData.bodyshop.cdk_configuration.cashierid,
|
||||||
referenceNumber: JobData.bodyshop.cdk_configuration.cashierid
|
referenceNumber: JobData.ro_number.match(/\d+/g)[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1221,7 +1221,7 @@ query ENTEGRAL_EXPORT($bodyshopid: uuid!) {
|
|||||||
}`;
|
}`;
|
||||||
|
|
||||||
exports.KAIZEN_QUERY = `query KAIZEN_EXPORT($start: timestamptz, $bodyshopid: uuid!, $end: timestamptz) {
|
exports.KAIZEN_QUERY = `query KAIZEN_EXPORT($start: timestamptz, $bodyshopid: uuid!, $end: timestamptz) {
|
||||||
bodyshops_by_pk(id: $bodyshopid){
|
bodyshops_by_pk(id: $bodyshopid) {
|
||||||
id
|
id
|
||||||
shopname
|
shopname
|
||||||
address1
|
address1
|
||||||
@@ -1249,15 +1249,24 @@ exports.KAIZEN_QUERY = `query KAIZEN_EXPORT($start: timestamptz, $bodyshopid: uu
|
|||||||
bills {
|
bills {
|
||||||
billlines {
|
billlines {
|
||||||
actual_cost
|
actual_cost
|
||||||
|
actual_price
|
||||||
cost_center
|
cost_center
|
||||||
|
deductedfromlbr
|
||||||
id
|
id
|
||||||
|
line_desc
|
||||||
quantity
|
quantity
|
||||||
}
|
}
|
||||||
|
date
|
||||||
federal_tax_rate
|
federal_tax_rate
|
||||||
id
|
id
|
||||||
is_credit_memo
|
is_credit_memo
|
||||||
|
invoice_number
|
||||||
|
isinhouse
|
||||||
local_tax_rate
|
local_tax_rate
|
||||||
state_tax_rate
|
state_tax_rate
|
||||||
|
vendor {
|
||||||
|
name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
created_at
|
created_at
|
||||||
clm_no
|
clm_no
|
||||||
@@ -1299,7 +1308,7 @@ exports.KAIZEN_QUERY = `query KAIZEN_EXPORT($start: timestamptz, $bodyshopid: uu
|
|||||||
joblines(where: {removed: {_eq: false}}) {
|
joblines(where: {removed: {_eq: false}}) {
|
||||||
act_price
|
act_price
|
||||||
alt_partno
|
alt_partno
|
||||||
billlines(order_by: {bill: {date: desc_nulls_last}} limit: 1) {
|
billlines(order_by: {bill: {date: desc_nulls_last}}, limit: 1) {
|
||||||
actual_cost
|
actual_cost
|
||||||
actual_price
|
actual_price
|
||||||
quantity
|
quantity
|
||||||
@@ -1322,8 +1331,8 @@ exports.KAIZEN_QUERY = `query KAIZEN_EXPORT($start: timestamptz, $bodyshopid: uu
|
|||||||
mod_lbr_ty
|
mod_lbr_ty
|
||||||
oem_partno
|
oem_partno
|
||||||
op_code_desc
|
op_code_desc
|
||||||
parts_order_lines(order_by: {parts_order: {order_date: desc_nulls_last}} limit: 1){
|
parts_order_lines(order_by: {parts_order: {order_date: desc_nulls_last}}, limit: 1) {
|
||||||
parts_order{
|
parts_order {
|
||||||
id
|
id
|
||||||
order_date
|
order_date
|
||||||
}
|
}
|
||||||
@@ -1342,6 +1351,14 @@ exports.KAIZEN_QUERY = `query KAIZEN_EXPORT($start: timestamptz, $bodyshopid: uu
|
|||||||
jobid
|
jobid
|
||||||
totalliquidcost
|
totalliquidcost
|
||||||
}
|
}
|
||||||
|
notes {
|
||||||
|
created_at
|
||||||
|
created_by
|
||||||
|
critical
|
||||||
|
private
|
||||||
|
text
|
||||||
|
type
|
||||||
|
}
|
||||||
ownr_addr1
|
ownr_addr1
|
||||||
ownr_addr2
|
ownr_addr2
|
||||||
ownr_city
|
ownr_city
|
||||||
@@ -2178,8 +2195,6 @@ mutation UPDATE_BILLS($billids: [uuid!]!, $bill: bills_set_input!, $logs: [expor
|
|||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exports.UPDATE_OLD_TRANSITION = `mutation UPDATE_OLD_TRANSITION($jobid: uuid!, $existingTransition: transitions_set_input!){
|
exports.UPDATE_OLD_TRANSITION = `mutation UPDATE_OLD_TRANSITION($jobid: uuid!, $existingTransition: transitions_set_input!){
|
||||||
update_transitions(where:{jobid:{_eq:$jobid}, end:{_is_null:true
|
update_transitions(where:{jobid:{_eq:$jobid}, end:{_is_null:true
|
||||||
}}, _set:$existingTransition){
|
}}, _set:$existingTransition){
|
||||||
@@ -3149,11 +3164,17 @@ exports.DELETE_PHONE_NUMBER_OPT_OUT = `
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
||||||
exports.INSERT_MEDIA_ANALYTICS = `
|
exports.INSERT_MEDIA_ANALYTICS = `
|
||||||
mutation INSERT_MEDIA_ANALYTICS($mediaObject: media_analytics_insert_input!) {
|
mutation INSERT_MEDIA_ANALYTICS($mediaObject: media_analytics_insert_input!) {
|
||||||
insert_media_analytics_one(object: $mediaObject) {
|
insert_media_analytics_one(object: $mediaObject) {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`;
|
||||||
|
|
||||||
|
exports.SET_JOB_DMS_ID = `mutation SetJobDmsId($id: uuid!, $dms_id: String!) {
|
||||||
|
update_jobs_by_pk(pk_columns: { id: $id }, _set: { dms_id: $dms_id }) {
|
||||||
|
id
|
||||||
|
dms_id
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
|||||||
@@ -134,13 +134,16 @@ const insertUserAssociation = async (uid, email, shopId) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* PATCH handler for updating bodyshop fields.
|
* PATCH handler for updating bodyshop fields.
|
||||||
* Allows patching: shopname, address1, address2, city, state, zip_post, country, email, timezone, phone, logo_img_path
|
* Allows patching: shopname, address1, address2, city, state, zip_post, country, email, timezone, phone
|
||||||
|
* Also allows updating logo_img_path via a simple logoUrl string, which is expanded to the full object.
|
||||||
* @param req
|
* @param req
|
||||||
* @param res
|
* @param res
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
const patchPartsManagementProvisioning = async (req, res) => {
|
const patchPartsManagementProvisioning = async (req, res) => {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
|
|
||||||
|
// Fields that can be directly patched 1:1
|
||||||
const allowedFields = [
|
const allowedFields = [
|
||||||
"shopname",
|
"shopname",
|
||||||
"address1",
|
"address1",
|
||||||
@@ -151,31 +154,58 @@ const patchPartsManagementProvisioning = async (req, res) => {
|
|||||||
"country",
|
"country",
|
||||||
"email",
|
"email",
|
||||||
"timezone",
|
"timezone",
|
||||||
"phone",
|
"phone"
|
||||||
"logo_img_path"
|
// NOTE: logo_img_path is handled separately via logoUrl
|
||||||
];
|
];
|
||||||
|
|
||||||
const updateFields = {};
|
const updateFields = {};
|
||||||
|
|
||||||
|
// Copy over simple scalar fields if present
|
||||||
for (const field of allowedFields) {
|
for (const field of allowedFields) {
|
||||||
if (req.body[field] !== undefined) {
|
if (req.body[field] !== undefined) {
|
||||||
updateFields[field] = req.body[field];
|
updateFields[field] = req.body[field];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle logo update via a simple href string, same behavior as provision route
|
||||||
|
if (typeof req.body.logo_img_path === "string") {
|
||||||
|
const trimmed = req.body.logo_img_path.trim();
|
||||||
|
if (trimmed) {
|
||||||
|
updateFields.logo_img_path = {
|
||||||
|
src: trimmed,
|
||||||
|
width: "",
|
||||||
|
height: "",
|
||||||
|
headerMargin: DefaultNewShop.logo_img_path.headerMargin
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Object.keys(updateFields).length === 0) {
|
if (Object.keys(updateFields).length === 0) {
|
||||||
return res.status(400).json({ error: "No valid fields provided for update." });
|
return res.status(400).json({ error: "No valid fields provided for update." });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the bodyshop has an external_shop_id before allowing patch
|
// Check that the bodyshop has an external_shop_id before allowing patch
|
||||||
try {
|
try {
|
||||||
// Fetch the bodyshop by id
|
|
||||||
const shopResp = await client.request(
|
const shopResp = await client.request(
|
||||||
`query GetBodyshop($id: uuid!) { bodyshops_by_pk(id: $id) { id external_shop_id } }`,
|
`query GetBodyshop($id: uuid!) {
|
||||||
|
bodyshops_by_pk(id: $id) {
|
||||||
|
id
|
||||||
|
external_shop_id
|
||||||
|
}
|
||||||
|
}`,
|
||||||
{ id }
|
{ id }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!shopResp.bodyshops_by_pk?.external_shop_id) {
|
if (!shopResp.bodyshops_by_pk?.external_shop_id) {
|
||||||
return res.status(400).json({ error: "Cannot patch: bodyshop does not have an external_shop_id." });
|
return res.status(400).json({ error: "Cannot patch: bodyshop does not have an external_shop_id." });
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res.status(500).json({ error: "Failed to validate bodyshop external_shop_id.", detail: err });
|
return res.status(500).json({
|
||||||
|
error: "Failed to validate bodyshop external_shop_id.",
|
||||||
|
detail: err
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await client.request(UPDATE_BODYSHOP_BY_ID, { id, fields: updateFields });
|
const resp = await client.request(UPDATE_BODYSHOP_BY_ID, { id, fields: updateFields });
|
||||||
if (!resp.update_bodyshops_by_pk) {
|
if (!resp.update_bodyshops_by_pk) {
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ const alternateTransportChangedBuilder = (data) => {
|
|||||||
* @returns {{app: {jobId, jobRoNumber: *, bodyShopId: *, key: string, body: string, variables: Object, recipients: *[]}, email: {jobId, jobRoNumber: *, bodyShopName: *, body: string, recipients: *[]}, fcm: {recipients: *[]}}}
|
* @returns {{app: {jobId, jobRoNumber: *, bodyShopId: *, key: string, body: string, variables: Object, recipients: *[]}, email: {jobId, jobRoNumber: *, bodyShopName: *, body: string, recipients: *[]}, fcm: {recipients: *[]}}}
|
||||||
*/
|
*/
|
||||||
const billPostedBuilder = (data) => {
|
const billPostedBuilder = (data) => {
|
||||||
const facing = data?.data?.isinhouse ? "in-house" : "vendor";
|
const facing = data?.data?.isinhouse ? "An In House" : "A Vendor";
|
||||||
const body = `An ${facing} ${data?.data?.is_credit_memo ? "credit memo" : "bill"} has been posted.`.trim();
|
const body = `${facing} ${data?.data?.is_credit_memo ? "credit memo" : "bill"} has been posted.`.trim();
|
||||||
|
|
||||||
return buildNotification(data, "notifications.job.billPosted", body, {
|
return buildNotification(data, "notifications.job.billPosted", body, {
|
||||||
isInHouse: data?.data?.isinhouse,
|
isInHouse: data?.data?.isinhouse,
|
||||||
|
|||||||
1222
server/rr/rr-calculate-allocations.js
Normal file
1222
server/rr/rr-calculate-allocations.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,8 @@ const { buildRRRepairOrderPayload } = require("./rr-job-helpers");
|
|||||||
const { buildClientAndOpts } = require("./rr-lookup");
|
const { buildClientAndOpts } = require("./rr-lookup");
|
||||||
const CreateRRLogEvent = require("./rr-logger-event");
|
const CreateRRLogEvent = require("./rr-logger-event");
|
||||||
const { extractRrResponsibilityCenters } = require("./rr-responsibility-centers");
|
const { extractRrResponsibilityCenters } = require("./rr-responsibility-centers");
|
||||||
const CdkCalculateAllocations = require("../cdk/cdk-calculate-allocations").default;
|
const CdkCalculateAllocations = require("./rr-calculate-allocations").default;
|
||||||
|
const { resolveRROpCodeFromBodyshop } = require("./rr-utils");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Derive RR status information from response object.
|
* Derive RR status information from response object.
|
||||||
@@ -90,11 +91,15 @@ const exportJobToRR = async (args) => {
|
|||||||
const story = txEnvelope?.story ? String(txEnvelope.story).trim() : null;
|
const story = txEnvelope?.story ? String(txEnvelope.story).trim() : null;
|
||||||
const makeOverride = txEnvelope?.makeOverride ? String(txEnvelope.makeOverride).trim() : null;
|
const makeOverride = txEnvelope?.makeOverride ? String(txEnvelope.makeOverride).trim() : null;
|
||||||
|
|
||||||
|
// Optional RR OpCode segments coming from the FE (RRPostForm)
|
||||||
|
const opPrefix = txEnvelope?.opPrefix ?? txEnvelope?.op_prefix ?? null;
|
||||||
|
const opBase = txEnvelope?.opBase ?? txEnvelope?.op_base ?? null;
|
||||||
|
const opSuffix = txEnvelope?.opSuffix ?? txEnvelope?.op_suffix ?? null;
|
||||||
|
|
||||||
// RR-only extras
|
// RR-only extras
|
||||||
let rrCentersConfig = null;
|
let rrCentersConfig = null;
|
||||||
let allocations = null;
|
let allocations = null;
|
||||||
let opCode = null;
|
let opCode = null;
|
||||||
// let taxCode = null;
|
|
||||||
|
|
||||||
// 1) Responsibility center config (for visibility / debugging)
|
// 1) Responsibility center config (for visibility / debugging)
|
||||||
try {
|
try {
|
||||||
@@ -116,33 +121,49 @@ const exportJobToRR = async (args) => {
|
|||||||
|
|
||||||
// 2) Allocations (sales + cost by center, with rr_* metadata already attached)
|
// 2) Allocations (sales + cost by center, with rr_* metadata already attached)
|
||||||
try {
|
try {
|
||||||
allocations = await CdkCalculateAllocations(socket, job.id);
|
const allocResult = await CdkCalculateAllocations(socket, job.id);
|
||||||
|
|
||||||
|
// We only need the per-center job allocations for RO.GOG / ROLABOR.
|
||||||
|
allocations = Array.isArray(allocResult?.jobAllocations) ? allocResult.jobAllocations : [];
|
||||||
|
|
||||||
CreateRRLogEvent(socket, "SILLY", "RR allocations resolved", {
|
CreateRRLogEvent(socket, "SILLY", "RR allocations resolved", {
|
||||||
hasAllocations: Array.isArray(allocations),
|
hasAllocations: allocations.length > 0,
|
||||||
count: Array.isArray(allocations) ? allocations.length : 0
|
count: allocations.length,
|
||||||
|
taxAllocCount: Array.isArray(allocResult?.taxAllocArray) ? allocResult.taxAllocArray.length : 0,
|
||||||
|
ttlAdjCount: Array.isArray(allocResult?.ttlAdjArray) ? allocResult.ttlAdjArray.length : 0,
|
||||||
|
ttlTaxAdjCount: Array.isArray(allocResult?.ttlTaxAdjArray) ? allocResult.ttlTaxAdjArray.length : 0
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
CreateRRLogEvent(socket, "ERROR", "Failed to calculate RR allocations", {
|
CreateRRLogEvent(socket, "ERROR", "Failed to calculate RR allocations", {
|
||||||
message: e?.message,
|
message: e?.message,
|
||||||
stack: e?.stack
|
stack: e?.stack
|
||||||
});
|
});
|
||||||
allocations = null; // We still proceed with a header-only RO if this fails.
|
// Proceed with a header-only RO if allocations fail.
|
||||||
|
allocations = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3) OpCode (global, but overridable)
|
const resolvedBaseOpCode = resolveRROpCodeFromBodyshop(bodyshop);
|
||||||
// - baseOpCode can come from bodyshop or rrCentersConfig (you'll map it in onboarding)
|
|
||||||
// - txEnvelope can carry an explicit override field (opCode/opcode/op_code)
|
|
||||||
const baseOpCode = bodyshop?.rr_configuration?.baseOpCode || "28TOZ"; // TODO Change / implement default handling policy
|
|
||||||
|
|
||||||
const opCodeOverride = txEnvelope?.opCode || txEnvelope?.opcode || txEnvelope?.op_code || null;
|
let opCodeOverride = txEnvelope?.opCode || txEnvelope?.opcode || txEnvelope?.op_code || null;
|
||||||
|
|
||||||
if (opCodeOverride || baseOpCode) {
|
// If the FE only sends segments, combine them here.
|
||||||
opCode = String(opCodeOverride || baseOpCode).trim() || null;
|
if (!opCodeOverride && (opPrefix || opBase || opSuffix)) {
|
||||||
|
const combined = `${opPrefix || ""}${opBase || ""}${opSuffix || ""}`.trim();
|
||||||
|
if (combined) {
|
||||||
|
opCodeOverride = combined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opCodeOverride || resolvedBaseOpCode) {
|
||||||
|
opCode = String(opCodeOverride || resolvedBaseOpCode).trim() || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateRRLogEvent(socket, "SILLY", "RR OP config resolved", {
|
CreateRRLogEvent(socket, "SILLY", "RR OP config resolved", {
|
||||||
opCode
|
opCode,
|
||||||
|
baseFromConfig: resolvedBaseOpCode,
|
||||||
|
opPrefix,
|
||||||
|
opBase,
|
||||||
|
opSuffix
|
||||||
});
|
});
|
||||||
|
|
||||||
// Build RO payload for create.
|
// Build RO payload for create.
|
||||||
|
|||||||
@@ -54,7 +54,43 @@ const asN2 = (dineroLike) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Build RO.GOG structure for the reynolds-rome-client `createRepairOrder` payload
|
* Build RO.GOG structure for the reynolds-rome-client `createRepairOrder` payload
|
||||||
* from CDK allocations.
|
* from allocations.
|
||||||
|
*
|
||||||
|
* Supports the allocation shape:
|
||||||
|
* {
|
||||||
|
* center,
|
||||||
|
* partsSale,
|
||||||
|
* partsTaxableSale,
|
||||||
|
* partsNonTaxableSale,
|
||||||
|
* laborTaxableSale,
|
||||||
|
* laborNonTaxableSale,
|
||||||
|
* extrasSale,
|
||||||
|
* extrasTaxableSale,
|
||||||
|
* extrasNonTaxableSale,
|
||||||
|
* totalSale,
|
||||||
|
* cost,
|
||||||
|
* profitCenter,
|
||||||
|
* costCenter
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* For each center, we can emit up to 6 GOG *segments*:
|
||||||
|
* - taxable parts (CustTxblNTxblFlag="T")
|
||||||
|
* - non-taxable parts (CustTxblNTxblFlag="N")
|
||||||
|
* - taxable extras (CustTxblNTxblFlag="T")
|
||||||
|
* - non-taxable extras (CustTxblNTxblFlag="N")
|
||||||
|
* - taxable labor (CustTxblNTxblFlag="T")
|
||||||
|
* - non-taxable labor (CustTxblNTxblFlag="N")
|
||||||
|
*
|
||||||
|
* IMPORTANT:
|
||||||
|
* Each segment becomes its OWN JobNo / AllGogOpCodeInfo, with exactly one
|
||||||
|
* AllGogLineItmInfo inside. This keeps a clean 1:1 mapping between:
|
||||||
|
* - <AllGogOpCodeInfo> (ROGOG)
|
||||||
|
* - <OpCodeLaborInfo> (ROLABOR)
|
||||||
|
* and ensures taxable/non-taxable flags line up by JobNo.
|
||||||
|
*
|
||||||
|
* We attach segmentKind/segmentIndex/segmentCount metadata on each op
|
||||||
|
* for UI/debug purposes. The XML templates can safely ignore these.
|
||||||
|
*
|
||||||
* @param {Array} allocations
|
* @param {Array} allocations
|
||||||
* @param {Object} opts
|
* @param {Object} opts
|
||||||
* @param {string} opts.opCode - RR OpCode for the job (global, overridable)
|
* @param {string} opts.opCode - RR OpCode for the job (global, overridable)
|
||||||
@@ -67,45 +103,176 @@ const buildRogogFromAllocations = (allocations, { opCode, payType = "Cust", roNo
|
|||||||
|
|
||||||
const ops = [];
|
const ops = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize various "money-like" shapes to integer cents.
|
||||||
|
* Supports:
|
||||||
|
* - Dinero instances (getAmount / toUnit)
|
||||||
|
* - { cents }
|
||||||
|
* - { amount, precision }
|
||||||
|
* - plain numbers (treated as units, e.g. dollars)
|
||||||
|
*/
|
||||||
|
const toCents = (value) => {
|
||||||
|
if (!value) return 0;
|
||||||
|
|
||||||
|
if (typeof value.getAmount === "function") {
|
||||||
|
return value.getAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value.toUnit === "function") {
|
||||||
|
const unit = value.toUnit();
|
||||||
|
return Number.isFinite(unit) ? Math.round(unit * 100) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value.cents === "number") {
|
||||||
|
return value.cents;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value.amount === "number") {
|
||||||
|
const precision = typeof value.precision === "number" ? value.precision : 2;
|
||||||
|
if (precision === 2) return value.amount;
|
||||||
|
const factor = Math.pow(10, 2 - precision);
|
||||||
|
return Math.round(value.amount * factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value === "number") {
|
||||||
|
return Math.round(value * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const asMoneyLike = (amountCents) => ({
|
||||||
|
amount: amountCents || 0,
|
||||||
|
precision: 2
|
||||||
|
});
|
||||||
|
|
||||||
for (const alloc of allocations) {
|
for (const alloc of allocations) {
|
||||||
const pc = alloc?.profitCenter || {};
|
const pc = alloc?.profitCenter || {};
|
||||||
const breakOut = pc.rr_gogcode;
|
const breakOut = pc.rr_gogcode;
|
||||||
const itemType = pc.rr_item_type;
|
const itemType = pc.rr_item_type;
|
||||||
|
|
||||||
// Only centers that have been configured for RR GOG are included
|
// Only centers configured for RR GOG are included
|
||||||
if (!breakOut || !itemType) continue;
|
if (!breakOut || !itemType) continue;
|
||||||
|
|
||||||
const saleN2 = asN2(alloc.sale);
|
const partsTaxableCents = toCents(alloc.partsTaxableSale);
|
||||||
const costN2 = asN2(alloc.cost);
|
const partsNonTaxableCents = toCents(alloc.partsNonTaxableSale);
|
||||||
|
const extrasTaxableCents = toCents(alloc.extrasTaxableSale);
|
||||||
|
const extrasNonTaxableCents = toCents(alloc.extrasNonTaxableSale);
|
||||||
|
const laborTaxableCents = toCents(alloc.laborTaxableSale);
|
||||||
|
const laborNonTaxableCents = toCents(alloc.laborNonTaxableSale);
|
||||||
|
const costCents = toCents(alloc.cost);
|
||||||
|
|
||||||
const itemDesc = pc.accountdesc || pc.accountname || alloc.center || "";
|
const segments = [];
|
||||||
const jobNo = String(ops.length + 1); // 1-based JobNo
|
|
||||||
|
|
||||||
ops.push({
|
// 1) Taxable parts segment -> "T"
|
||||||
opCode,
|
if (partsTaxableCents !== 0) {
|
||||||
jobNo,
|
segments.push({
|
||||||
lines: [
|
kind: "partsTaxable",
|
||||||
{
|
saleCents: partsTaxableCents,
|
||||||
breakOut,
|
txFlag: "T"
|
||||||
itemType,
|
});
|
||||||
itemDesc,
|
}
|
||||||
custQty: "1.0",
|
|
||||||
// warrQty: "0.0",
|
// 2) Non-taxable parts segment -> "N"
|
||||||
// intrQty: "0.0",
|
if (partsNonTaxableCents !== 0) {
|
||||||
custPayTypeFlag: "C",
|
segments.push({
|
||||||
// warrPayTypeFlag: "W",
|
kind: "partsNonTaxable",
|
||||||
// intrPayTypeFlag: "I",
|
saleCents: partsNonTaxableCents,
|
||||||
custTxblNtxblFlag: pc.rr_cust_txbl_flag || "T",
|
txFlag: "N"
|
||||||
// warrTxblNtxblFlag: "N",
|
});
|
||||||
// intrTxblNtxblFlag: "N",
|
}
|
||||||
amount: {
|
|
||||||
payType,
|
// 3) Taxable extras -> "T"
|
||||||
amtType: "Unit",
|
if (extrasTaxableCents !== 0) {
|
||||||
custPrice: saleN2,
|
segments.push({
|
||||||
dlrCost: costN2
|
kind: "extrasTaxable",
|
||||||
}
|
saleCents: extrasTaxableCents,
|
||||||
|
txFlag: "T"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4) Non-taxable extras -> "N"
|
||||||
|
if (extrasNonTaxableCents !== 0) {
|
||||||
|
segments.push({
|
||||||
|
kind: "extrasNonTaxable",
|
||||||
|
saleCents: extrasNonTaxableCents,
|
||||||
|
txFlag: "N"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5) Taxable labor segment -> "T"
|
||||||
|
if (laborTaxableCents !== 0) {
|
||||||
|
segments.push({
|
||||||
|
kind: "laborTaxable",
|
||||||
|
saleCents: laborTaxableCents,
|
||||||
|
txFlag: "T"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6) Non-tax labor segment -> "N"
|
||||||
|
if (laborNonTaxableCents !== 0) {
|
||||||
|
segments.push({
|
||||||
|
kind: "laborNonTaxable",
|
||||||
|
saleCents: laborNonTaxableCents,
|
||||||
|
txFlag: "N"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!segments.length) continue;
|
||||||
|
|
||||||
|
// Proportionally split cost across segments based on their sale amounts
|
||||||
|
const totalCostCents = costCents;
|
||||||
|
const totalSaleCents = segments.reduce((sum, seg) => sum + seg.saleCents, 0);
|
||||||
|
|
||||||
|
let remainingCostCents = totalCostCents;
|
||||||
|
|
||||||
|
segments.forEach((seg, idx) => {
|
||||||
|
let segCost = 0;
|
||||||
|
|
||||||
|
if (totalCostCents > 0 && totalSaleCents > 0) {
|
||||||
|
if (idx === segments.length - 1) {
|
||||||
|
// Last segment gets the remainder to avoid rounding drift
|
||||||
|
segCost = remainingCostCents;
|
||||||
|
} else {
|
||||||
|
segCost = Math.round((seg.saleCents / totalSaleCents) * totalCostCents);
|
||||||
|
remainingCostCents -= segCost;
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
|
|
||||||
|
seg.costCents = segCost;
|
||||||
|
});
|
||||||
|
|
||||||
|
const itemDescBase = pc.accountdesc || pc.accountname || alloc.center || "";
|
||||||
|
const segmentCount = segments.length;
|
||||||
|
|
||||||
|
// Each segment becomes its own op / JobNo with a single line
|
||||||
|
segments.forEach((seg, idx) => {
|
||||||
|
const jobNo = String(ops.length + 1); // global, 1-based JobNo across all centers/segments
|
||||||
|
|
||||||
|
const line = {
|
||||||
|
breakOut,
|
||||||
|
itemType,
|
||||||
|
itemDesc: itemDescBase,
|
||||||
|
custQty: "1.0",
|
||||||
|
custPayTypeFlag: "C",
|
||||||
|
custTxblNtxblFlag: seg.txFlag || "N",
|
||||||
|
amount: {
|
||||||
|
payType,
|
||||||
|
amtType: "Unit",
|
||||||
|
custPrice: asN2(asMoneyLike(seg.saleCents)),
|
||||||
|
dlrCost: asN2(asMoneyLike(seg.costCents))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ops.push({
|
||||||
|
opCode,
|
||||||
|
jobNo,
|
||||||
|
lines: [line], // exactly one AllGogLineItmInfo per AllGogOpCodeInfo
|
||||||
|
// Extra metadata for UI / debugging
|
||||||
|
segmentKind: seg.kind,
|
||||||
|
segmentIndex: idx,
|
||||||
|
segmentCount
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +287,12 @@ const buildRogogFromAllocations = (allocations, { opCode, payType = "Cust", roNo
|
|||||||
/**
|
/**
|
||||||
* Build RO.ROLABOR structure for the reynolds-rome-client `createRepairOrder` payload
|
* Build RO.ROLABOR structure for the reynolds-rome-client `createRepairOrder` payload
|
||||||
* from an already-built RO.GOG structure.
|
* from an already-built RO.GOG structure.
|
||||||
|
*
|
||||||
|
* We still keep a 1:1 mapping with GOG ops: each op gets a corresponding
|
||||||
|
* OpCodeLaborInfo entry using the same JobNo and the same tax flag as its
|
||||||
|
* GOG line. Labor-specific details (hrs/rate) remain zeroed out, and the
|
||||||
|
* DMS can ignore non-labor ops by virtue of the zero hours/amounts.
|
||||||
|
*
|
||||||
* @param {Object} rogg - result of buildRogogFromAllocations
|
* @param {Object} rogg - result of buildRogogFromAllocations
|
||||||
* @param {Object} opts
|
* @param {Object} opts
|
||||||
* @param {string} [opts.payType="Cust"]
|
* @param {string} [opts.payType="Cust"]
|
||||||
@@ -131,16 +304,18 @@ const buildRolaborFromRogog = (rogg, { payType = "Cust" } = {}) => {
|
|||||||
const ops = rogg.ops.map((op) => {
|
const ops = rogg.ops.map((op) => {
|
||||||
const firstLine = op.lines?.[0] || {};
|
const firstLine = op.lines?.[0] || {};
|
||||||
|
|
||||||
|
// Pull tax flag from the GOG line.
|
||||||
|
// Prefer the property we set in buildRogogFromAllocations (custTxblNTxblFlag),
|
||||||
|
// but also accept custTxblNtxblFlag in case we ever change naming.
|
||||||
|
const txFlag = firstLine.custTxblNtxblFlag ?? "N";
|
||||||
|
|
||||||
|
const linePayType = firstLine.custPayTypeFlag || "C";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
opCode: op.opCode,
|
opCode: op.opCode,
|
||||||
jobNo: op.jobNo,
|
jobNo: op.jobNo,
|
||||||
custPayTypeFlag: firstLine.custPayTypeFlag || "C",
|
custPayTypeFlag: linePayType,
|
||||||
// warrPayTypeFlag: firstLine.warrPayTypeFlag || "W",
|
custTxblNtxblFlag: txFlag,
|
||||||
// intrPayTypeFlag: firstLine.intrPayTypeFlag || "I",
|
|
||||||
custTxblNtxblFlag: firstLine.custTxblNtxblFlag || "N",
|
|
||||||
// warrTxblNtxblFlag: firstLine.warrTxblNtxblFlag || "N",
|
|
||||||
// intrTxblNtxblFlag: firstLine.intrTxblNtxblFlag || "N",
|
|
||||||
// vlrCode: undefined,
|
|
||||||
bill: {
|
bill: {
|
||||||
payType,
|
payType,
|
||||||
jobTotalHrs: "0",
|
jobTotalHrs: "0",
|
||||||
@@ -194,10 +369,8 @@ const QueryJobData = async (ctx = {}, jobId) => {
|
|||||||
* @param advisorNo
|
* @param advisorNo
|
||||||
* @param story
|
* @param story
|
||||||
* @param makeOverride
|
* @param makeOverride
|
||||||
* @param bodyshop
|
|
||||||
* @param allocations
|
* @param allocations
|
||||||
* @param {string} [opCode] - RR OpCode for this RO (global default / override)
|
* @param {string} [opCode] - RR OpCode for this RO (global default / override)
|
||||||
* @param {string} [taxCode] - RR tax code for header tax (e.g. state/prov code)
|
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
const buildRRRepairOrderPayload = ({
|
const buildRRRepairOrderPayload = ({
|
||||||
@@ -208,7 +381,6 @@ const buildRRRepairOrderPayload = ({
|
|||||||
makeOverride,
|
makeOverride,
|
||||||
allocations,
|
allocations,
|
||||||
opCode
|
opCode
|
||||||
// taxCode
|
|
||||||
} = {}) => {
|
} = {}) => {
|
||||||
const customerNo = selectedCustomer?.customerNo
|
const customerNo = selectedCustomer?.customerNo
|
||||||
? String(selectedCustomer.customerNo).trim()
|
? String(selectedCustomer.customerNo).trim()
|
||||||
@@ -259,7 +431,6 @@ const buildRRRepairOrderPayload = ({
|
|||||||
|
|
||||||
if (haveAllocations) {
|
if (haveAllocations) {
|
||||||
const effectiveOpCode = (opCode && String(opCode).trim()) || null;
|
const effectiveOpCode = (opCode && String(opCode).trim()) || null;
|
||||||
// const effectiveTaxCode = (taxCode && String(taxCode).trim()) || null;
|
|
||||||
|
|
||||||
if (effectiveOpCode) {
|
if (effectiveOpCode) {
|
||||||
// Build RO.GOG and RO.LABOR in the new normalized shape
|
// Build RO.GOG and RO.LABOR in the new normalized shape
|
||||||
@@ -277,24 +448,6 @@ const buildRRRepairOrderPayload = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- TAX HEADER TEMPORARILY DISABLED ---
|
|
||||||
// We intentionally do NOT attach payload.tax right now so that the Mustache
|
|
||||||
// section that renders <TaxCodeInfo> stays false and no TaxCodeInfo is sent.
|
|
||||||
//
|
|
||||||
// Keeping this commented-out for future enablement once RR confirms header
|
|
||||||
// tax handling behaviour.
|
|
||||||
//
|
|
||||||
// if (effectiveTaxCode) {
|
|
||||||
// const taxInfo = buildTaxFromAllocations(allocations, {
|
|
||||||
// taxCode: effectiveTaxCode,
|
|
||||||
// payType: "Cust"
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// if (taxInfo) {
|
|
||||||
// payload.tax = taxInfo;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return payload;
|
return payload;
|
||||||
@@ -400,23 +553,49 @@ const normalizeVehicleCandidates = (res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a minimal Rolabor structure in the new normalized shape.
|
* Build split labor lines from job allocations.
|
||||||
*
|
* @param jobAllocations
|
||||||
* Useful for tests or for scenarios where you want a single zero-dollar
|
* @returns {*[]}
|
||||||
* Rolabor op but don't have GOG data. Shape matches payload.rolabor for the
|
|
||||||
* reynolds-rome-client builders.
|
|
||||||
*
|
|
||||||
* @param {Object} opts
|
|
||||||
* @param {string} opts.opCode
|
|
||||||
* @param {number|string} [opts.jobNo=1]
|
|
||||||
* @param {string} [opts.payType="Cust"]
|
|
||||||
* @returns {null|{ops: Array}}
|
|
||||||
*/
|
*/
|
||||||
|
const buildSplitLaborLinesFromAllocations = (jobAllocations) => {
|
||||||
|
const lines = [];
|
||||||
|
|
||||||
|
for (const alloc of jobAllocations || []) {
|
||||||
|
const { center, laborTaxableSale, laborNonTaxableSale, profitCenter, costCenter } = alloc;
|
||||||
|
|
||||||
|
// Taxable labor
|
||||||
|
if (laborTaxableSale && !laborTaxableSale.isZero()) {
|
||||||
|
lines.push({
|
||||||
|
centerName: center,
|
||||||
|
profitCenter,
|
||||||
|
costCenter,
|
||||||
|
amount: laborTaxableSale,
|
||||||
|
isTaxable: true,
|
||||||
|
source: "labor"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non-taxable labor
|
||||||
|
if (laborNonTaxableSale && !laborNonTaxableSale.isZero()) {
|
||||||
|
lines.push({
|
||||||
|
centerName: center,
|
||||||
|
profitCenter,
|
||||||
|
costCenter,
|
||||||
|
amount: laborNonTaxableSale,
|
||||||
|
isTaxable: false,
|
||||||
|
source: "labor"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
QueryJobData,
|
QueryJobData,
|
||||||
buildRRRepairOrderPayload,
|
buildRRRepairOrderPayload,
|
||||||
makeCustomerSearchPayloadFromJob,
|
makeCustomerSearchPayloadFromJob,
|
||||||
|
buildSplitLaborLinesFromAllocations,
|
||||||
makeVehicleSearchPayloadFromJob,
|
makeVehicleSearchPayloadFromJob,
|
||||||
normalizeCustomerCandidates,
|
normalizeCustomerCandidates,
|
||||||
normalizeVehicleCandidates,
|
normalizeVehicleCandidates,
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ const safeMeta = (meta) => {
|
|||||||
const CreateRRLogEvent = (socket, level = "INFO", message = "", meta = null) => {
|
const CreateRRLogEvent = (socket, level = "INFO", message = "", meta = null) => {
|
||||||
const ts = Date.now();
|
const ts = Date.now();
|
||||||
const lvl = String(level || "INFO").toUpperCase();
|
const lvl = String(level || "INFO").toUpperCase();
|
||||||
|
const normLevel = lvl.toLowerCase();
|
||||||
const msg = typeof message === "string" ? message : (message?.toString?.() ?? JSON.stringify(message));
|
const msg = typeof message === "string" ? message : (message?.toString?.() ?? JSON.stringify(message));
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
@@ -54,12 +55,13 @@ const CreateRRLogEvent = (socket, level = "INFO", message = "", meta = null) =>
|
|||||||
meta: safeMeta(meta)
|
meta: safeMeta(meta)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Console
|
// Central logger (Winston + CloudWatch + S3)
|
||||||
try {
|
try {
|
||||||
const fn = logger?.logger?.[lvl.toLowerCase()] ?? logger?.logger?.info ?? console.log;
|
// user = "RR", record = null, meta = payload.meta
|
||||||
fn(`[RR] ${new Date(ts).toISOString()} | ${lvl} | ${msg}`, payload.meta);
|
logger.log(`[RR] ${msg}`, normLevel, "RR", null, payload.meta);
|
||||||
} catch {
|
} catch {
|
||||||
// ignore console failures
|
// Fallback console
|
||||||
|
console.log(`[RR] ${new Date(ts).toISOString()} | ${lvl} | ${msg}`, payload.meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Socket
|
// Socket
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const CreateRRLogEvent = require("./rr-logger-event");
|
const CreateRRLogEvent = require("./rr-logger-event");
|
||||||
const { rrCombinedSearch, rrGetAdvisors, buildClientAndOpts } = require("./rr-lookup");
|
const { rrCombinedSearch, rrGetAdvisors, buildClientAndOpts } = require("./rr-lookup");
|
||||||
const { QueryJobData } = require("./rr-job-helpers");
|
const { QueryJobData, buildRogogFromAllocations, buildRolaborFromRogog } = require("./rr-job-helpers");
|
||||||
const { exportJobToRR, finalizeRRRepairOrder } = require("./rr-job-export");
|
const { exportJobToRR, finalizeRRRepairOrder } = require("./rr-job-export");
|
||||||
const CdkCalculateAllocations = require("../cdk/cdk-calculate-allocations").default;
|
const RRCalculateAllocations = require("./rr-calculate-allocations").default;
|
||||||
const { createRRCustomer } = require("./rr-customers");
|
const { createRRCustomer } = require("./rr-customers");
|
||||||
const { ensureRRServiceVehicle } = require("./rr-service-vehicles");
|
const { ensureRRServiceVehicle } = require("./rr-service-vehicles");
|
||||||
const { classifyRRVendorError } = require("./rr-errors");
|
const { classifyRRVendorError } = require("./rr-errors");
|
||||||
@@ -16,6 +16,7 @@ const {
|
|||||||
defaultRRTTL,
|
defaultRRTTL,
|
||||||
RRCacheEnums
|
RRCacheEnums
|
||||||
} = require("./rr-utils");
|
} = require("./rr-utils");
|
||||||
|
const { resolveRROpCodeFromBodyshop } = require("./rr-utils");
|
||||||
const { GraphQLClient } = require("graphql-request");
|
const { GraphQLClient } = require("graphql-request");
|
||||||
const queries = require("../graphql-client/queries");
|
const queries = require("../graphql-client/queries");
|
||||||
|
|
||||||
@@ -122,6 +123,47 @@ const getBodyshopForSocket = async ({ bodyshopId, socket }) => {
|
|||||||
return bodyshop;
|
return bodyshop;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GraphQL mutation to set job.dms_id
|
||||||
|
* @param socket
|
||||||
|
* @param jobId
|
||||||
|
* @param dmsId
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
const setJobDmsIdForSocket = async ({ socket, jobId, dmsId }) => {
|
||||||
|
if (!jobId || !dmsId) {
|
||||||
|
CreateRRLogEvent(socket, "WARN", "setJobDmsIdForSocket called without jobId or dmsId", {
|
||||||
|
jobId,
|
||||||
|
dmsId
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const endpoint = process.env.GRAPHQL_ENDPOINT;
|
||||||
|
if (!endpoint) throw new Error("GRAPHQL_ENDPOINT not configured");
|
||||||
|
|
||||||
|
const token = (socket?.data && socket.data.authToken) || (socket?.handshake?.auth && socket.handshake.auth.token);
|
||||||
|
if (!token) throw new Error("Missing auth token for setJobDmsIdForSocket");
|
||||||
|
|
||||||
|
const client = new GraphQLClient(endpoint, {});
|
||||||
|
await client
|
||||||
|
.setHeaders({ Authorization: `Bearer ${token}` })
|
||||||
|
.request(queries.SET_JOB_DMS_ID, { id: jobId, dms_id: String(dmsId) });
|
||||||
|
|
||||||
|
CreateRRLogEvent(socket, "INFO", "Linked job.dms_id to RR RO", {
|
||||||
|
jobId,
|
||||||
|
dmsId: String(dmsId)
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
CreateRRLogEvent(socket, "ERROR", "Failed to set job.dms_id after RR create/update", {
|
||||||
|
jobId,
|
||||||
|
dmsId,
|
||||||
|
message: err?.message || String(err),
|
||||||
|
stack: err?.stack
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* Build advisors cache namespace and field
|
* Build advisors cache namespace and field
|
||||||
* @param bodyshopId
|
* @param bodyshopId
|
||||||
@@ -607,6 +649,22 @@ const registerRREvents = ({ socket, redisHelpers }) => {
|
|||||||
|
|
||||||
const outsdRoNo = data?.outsdRoNo ?? job?.ro_number ?? job?.id ?? null;
|
const outsdRoNo = data?.outsdRoNo ?? job?.ro_number ?? job?.id ?? null;
|
||||||
|
|
||||||
|
// ✅ Persist DMS RO number on the job (jobs.dms_id)
|
||||||
|
if (dmsRoNo) {
|
||||||
|
await setJobDmsIdForSocket({ socket, jobId: rid, dmsId: dmsRoNo });
|
||||||
|
} else {
|
||||||
|
CreateRRLogEvent(socket, "WARN", "RR export succeeded but no DMS RO number was returned", {
|
||||||
|
jobId: rid,
|
||||||
|
resultPreview: {
|
||||||
|
roNo: result?.roNo,
|
||||||
|
data: {
|
||||||
|
dmsRoNo: data?.dmsRoNo,
|
||||||
|
outsdRoNo: data?.outsdRoNo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await redisHelpers.setSessionTransactionData(
|
await redisHelpers.setSessionTransactionData(
|
||||||
socket.id,
|
socket.id,
|
||||||
ns,
|
ns,
|
||||||
@@ -895,13 +953,101 @@ const registerRREvents = ({ socket, redisHelpers }) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("rr-calculate-allocations", async (jobid, cb) => {
|
// RR allocations preview (RR-only)
|
||||||
|
// Accepts either:
|
||||||
|
// - legacy: (jobid, cb)
|
||||||
|
// - new: ({ jobId, opCode, opPrefix, opBase, opSuffix }, cb)
|
||||||
|
socket.on("rr-calculate-allocations", async (payload, cb) => {
|
||||||
|
// Normalize arguments
|
||||||
|
const isObjectPayload = payload && typeof payload === "object";
|
||||||
|
const jobid = isObjectPayload ? payload.jobId || payload.jobid || payload.id : payload;
|
||||||
|
|
||||||
|
const opCodeFromClient =
|
||||||
|
isObjectPayload &&
|
||||||
|
(payload.opCode ||
|
||||||
|
payload.opcode ||
|
||||||
|
payload.op_code ||
|
||||||
|
(payload.opPrefix || payload.opBase || payload.opSuffix
|
||||||
|
? `${payload.opPrefix || ""}${payload.opBase || ""}${payload.opSuffix || ""}`.trim()
|
||||||
|
: null));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: begin", { jobid });
|
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: begin", { jobid, opCodeFromClient });
|
||||||
const allocations = await CdkCalculateAllocations(socket, jobid);
|
|
||||||
cb?.(allocations);
|
const raw = await RRCalculateAllocations(socket, jobid);
|
||||||
socket.emit("rr-calculate-allocations:result", allocations);
|
|
||||||
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: success", { items: allocations?.length });
|
// If the helper returns an explicit error shape, just pass it through.
|
||||||
|
if (raw && raw.ok === false) {
|
||||||
|
cb?.(raw);
|
||||||
|
socket.emit("rr-calculate-allocations:result", raw);
|
||||||
|
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: helper returned error", {
|
||||||
|
jobid,
|
||||||
|
error: raw.error
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let ack;
|
||||||
|
let jobAllocations;
|
||||||
|
|
||||||
|
if (Array.isArray(raw)) {
|
||||||
|
// Legacy shape: plain allocations array
|
||||||
|
jobAllocations = raw;
|
||||||
|
ack = { jobAllocations: raw };
|
||||||
|
} else {
|
||||||
|
ack = raw || {};
|
||||||
|
jobAllocations = Array.isArray(ack.jobAllocations) ? ack.jobAllocations : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start with client-supplied OpCode (if any); fall back to defaults.
|
||||||
|
let opCode = opCodeFromClient || null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { bodyshopId } = await getSessionOrSocket(redisHelpers, socket);
|
||||||
|
const bodyshop = await getBodyshopForSocket({ bodyshopId, socket });
|
||||||
|
|
||||||
|
// resolveRROpCodeFromBodyshop(bodyshop, existingOverride?)
|
||||||
|
opCode = resolveRROpCodeFromBodyshop(bodyshop, opCode);
|
||||||
|
|
||||||
|
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: resolved OpCode", {
|
||||||
|
opCode,
|
||||||
|
opCodeFromClient
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
CreateRRLogEvent(socket, "WARN", "rr-calculate-allocations: bodyshop lookup failed, using existing OpCode", {
|
||||||
|
error: e.message,
|
||||||
|
opCodeFromClient
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let rogg = null;
|
||||||
|
let rolabor = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
rogg = buildRogogFromAllocations(jobAllocations, { opCode, payType: "Cust" });
|
||||||
|
if (rogg) {
|
||||||
|
rolabor = buildRolaborFromRogog(rogg, { payType: "Cust" });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
CreateRRLogEvent(socket, "WARN", "rr-calculate-allocations: failed to build ROGOG/ROLABOR preview", {
|
||||||
|
error: e.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const enriched = {
|
||||||
|
...ack,
|
||||||
|
rogg,
|
||||||
|
rolabor
|
||||||
|
};
|
||||||
|
|
||||||
|
cb?.(enriched);
|
||||||
|
socket.emit("rr-calculate-allocations:result", enriched);
|
||||||
|
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: success", {
|
||||||
|
jobid,
|
||||||
|
jobAllocations: jobAllocations.length,
|
||||||
|
hasRogg: !!rogg,
|
||||||
|
hasRolabor: !!rolabor
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
CreateRRLogEvent(socket, "ERROR", "rr-calculate-allocations: failed", { error: e.message, jobid });
|
CreateRRLogEvent(socket, "ERROR", "rr-calculate-allocations: failed", { error: e.message, jobid });
|
||||||
cb?.({ ok: false, error: e.message });
|
cb?.({ ok: false, error: e.message });
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const { buildClientAndOpts, rrCombinedSearch } = require("./rr-lookup");
|
const { buildClientAndOpts, rrCombinedSearch } = require("./rr-lookup");
|
||||||
const CreateRRLogEvent = require("./rr-logger-event");
|
const CreateRRLogEvent = require("./rr-logger-event");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pick and normalize VIN from inputs
|
* Pick and normalize VIN from inputs
|
||||||
* @param vin
|
* @param vin
|
||||||
@@ -29,6 +28,20 @@ const pickCustNo = ({ selectedCustomerNo, custNo, customerNo }) => {
|
|||||||
return c != null ? String(c).trim() : "";
|
return c != null ? String(c).trim() : "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple length sanitizer for outbound strings
|
||||||
|
* Returns undefined if value is null/undefined/empty after trim.
|
||||||
|
*/
|
||||||
|
const sanitizeLength = (value, maxLen) => {
|
||||||
|
if (value == null) return undefined;
|
||||||
|
let s = String(value).trim();
|
||||||
|
if (!s) return undefined;
|
||||||
|
if (maxLen && s.length > maxLen) {
|
||||||
|
s = s.slice(0, maxLen);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract owner customer numbers from combined search results
|
* Extract owner customer numbers from combined search results
|
||||||
* @param res
|
* @param res
|
||||||
@@ -181,65 +194,57 @@ const ensureRRServiceVehicle = async (args = {}) => {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Preflight shouldn't be fatal; log and continue to insert (idempotency will still be handled)
|
// Preflight shouldn't be fatal; log and continue to insert (idempotency will still be handled)
|
||||||
CreateRRLogEvent(socket, "WARN", "{SV} VIN preflight lookup failed; continuing to insert", {
|
CreateRRLogEvent(socket, "warn", "{SV} VIN preflight lookup failed; continuing to insert", {
|
||||||
vin: vinStr,
|
vin: vinStr,
|
||||||
error: e?.message
|
error: e?.message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Attempt insert (idempotent) ---
|
// Vendor says: MODEL DESCRIPTION HAS MAXIMUM LENGTH OF 20
|
||||||
// IMPORTANT: The current RR lib build validates `vehicleServInfo.customerNo`.
|
const rawModelDesc = job?.v_model_desc;
|
||||||
// To be future-proof, we also include top-level `customerNo`.
|
const safeModelDesc = sanitizeLength(rawModelDesc, 20);
|
||||||
|
if (rawModelDesc && safeModelDesc && rawModelDesc.trim() !== safeModelDesc) {
|
||||||
|
CreateRRLogEvent(socket, "warn", "{SV} Truncated model description to 20 chars", {
|
||||||
|
original: rawModelDesc,
|
||||||
|
truncated: safeModelDesc
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const insertPayload = {
|
const insertPayload = {
|
||||||
// === Core Vehicle Identity (MANDATORY for success) ===
|
|
||||||
vin: vinStr.toUpperCase(), // "1FDWX34Y28EB01395"
|
vin: vinStr.toUpperCase(), // "1FDWX34Y28EB01395"
|
||||||
|
|
||||||
// Required: 2-character make code (from v_make_desc → known mapping)
|
// 2-character make code (from v_make_desc → known mapping)
|
||||||
vehicleMake: deriveMakeCode(job.v_make_desc), // → "FR" for Ford
|
vehicleMake: deriveMakeCode(job?.v_make_desc), // → "FR" for Ford
|
||||||
|
|
||||||
// Required: 2-digit year (last 2 digits of v_model_yr)
|
|
||||||
year: job?.v_model_yr || undefined,
|
year: job?.v_model_yr || undefined,
|
||||||
|
|
||||||
// Required: Model number — fallback strategy per ERA behavior
|
// Model description (RR: max length 20)
|
||||||
// Most Ford trucks use "T" = Truck. Some systems accept actual code.
|
modelDesc: safeModelDesc,
|
||||||
// CAN BE (P)assenger , (T)ruck, (O)ther
|
|
||||||
|
// Model number / carline / other optional fields
|
||||||
mdlNo: undefined,
|
mdlNo: undefined,
|
||||||
|
carline: undefined,
|
||||||
// === Descriptive Fields (highly recommended) ===
|
extClrDesc: sanitizeLength(job?.v_color, 30), // safe, configurable if vendor complains
|
||||||
modelDesc: job?.v_model_desc?.trim() || undefined, // "F-350 SD"
|
|
||||||
carline: job?.v_model_desc?.trim() || undefined, // Series line
|
|
||||||
extClrDesc: job?.v_color?.trim() || undefined, // "Red"
|
|
||||||
|
|
||||||
// Optional but helpful
|
|
||||||
accentClr: undefined,
|
accentClr: undefined,
|
||||||
|
aircond: undefined,
|
||||||
// === VehicleDetail Flags (CRITICAL — cause silent fails or error 303 if missing) ===
|
pwrstr: undefined,
|
||||||
aircond: undefined, // "Y", // Nearly all modern vehicles have A/C
|
transm: undefined,
|
||||||
pwrstr: undefined, // "Y", // Power steering = yes on 99% of vehicles post-1990
|
turbo: undefined,
|
||||||
transm: undefined, // "A", // Default to Automatic — change to "M" only if known manual
|
engineConfig: undefined,
|
||||||
turbo: undefined, //"N", // 2008 F-350 6.4L Power Stroke has turbo, but field is optional
|
trim: undefined,
|
||||||
engineConfig: undefined, //"V8", // or "6.4L Diesel" — optional but nice
|
|
||||||
trim: undefined, //"XLT", // You don't have this — safe to omit or guess
|
|
||||||
|
|
||||||
// License plate
|
// License plate
|
||||||
licNo: license ? String(license).trim() : undefined,
|
licNo: sanitizeLength(license ? String(license) : undefined, 20),
|
||||||
|
|
||||||
// === VehicleServInfo (attributes on the element) ===
|
|
||||||
customerNo: custNoStr, // fallback (some builds read this)
|
|
||||||
stockId: job.ro_number || undefined, // Use RO as stock# — common pattern
|
|
||||||
|
|
||||||
|
customerNo: custNoStr,
|
||||||
|
stockId: sanitizeLength(job?.ro_number, 20), // RO as stock#, truncated for safety
|
||||||
vehicleServInfo: {
|
vehicleServInfo: {
|
||||||
customerNo: custNoStr, // REQUIRED — this is what toServiceVehicleView() validates
|
customerNo: custNoStr, // REQUIRED — this is what toServiceVehicleView() validates
|
||||||
// Optional but increases success rate
|
salesmanNo: undefined,
|
||||||
salesmanNo: undefined, // You don't have advisor yet — omit
|
|
||||||
inServiceDate: undefined,
|
inServiceDate: undefined,
|
||||||
// Optional — safe to include if you want
|
|
||||||
productionDate: undefined,
|
productionDate: undefined,
|
||||||
modelMaintCode: undefined,
|
modelMaintCode: undefined,
|
||||||
teamCode: undefined,
|
teamCode: undefined,
|
||||||
// Extended warranty — omit unless you sell contracts
|
|
||||||
vehExtWarranty: undefined,
|
vehExtWarranty: undefined,
|
||||||
// Advisor — omit unless you know who the service advisor is
|
|
||||||
advisor: undefined
|
advisor: undefined
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -182,6 +182,29 @@ const getTransactionType = (jobid) => `rr:${jobid}`;
|
|||||||
*/
|
*/
|
||||||
const defaultRRTTL = 60 * 60;
|
const defaultRRTTL = 60 * 60;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve RR OpCode from bodyshop.rr_configuration.defaults
|
||||||
|
* Is Duplicated on client/src/utils/dmsUtils.js
|
||||||
|
* @param bodyshop
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
const resolveRROpCodeFromBodyshop = (bodyshop) => {
|
||||||
|
if (!bodyshop) throw new Error("bodyshop is required");
|
||||||
|
|
||||||
|
const cfg = bodyshop?.rr_configuration || {};
|
||||||
|
const defaults = cfg?.defaults || {};
|
||||||
|
|
||||||
|
const prefix = (defaults.prefix ?? "").toString().trim();
|
||||||
|
const base = (defaults.base ?? "").toString().trim();
|
||||||
|
const suffix = (defaults.suffix ?? "").toString().trim();
|
||||||
|
|
||||||
|
if (!prefix && !base && !suffix) {
|
||||||
|
throw new Error("No RR OpCode parts found in bodyshop configuration");
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${prefix}${base}${suffix}`;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
RRCacheEnums,
|
RRCacheEnums,
|
||||||
defaultRRTTL,
|
defaultRRTTL,
|
||||||
@@ -189,5 +212,6 @@ module.exports = {
|
|||||||
ownersFromVinBlocks,
|
ownersFromVinBlocks,
|
||||||
makeVehicleSearchPayloadFromJob,
|
makeVehicleSearchPayloadFromJob,
|
||||||
normalizeCustomerCandidates,
|
normalizeCustomerCandidates,
|
||||||
readAdvisorNo
|
readAdvisorNo,
|
||||||
|
resolveRROpCodeFromBodyshop
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -67,6 +67,34 @@ const redisSocketEvents = ({ io, redisHelpers, ioHelpers, logger }) => {
|
|||||||
|
|
||||||
// Register Socket Events
|
// Register Socket Events
|
||||||
const registerSocketEvents = (socket) => {
|
const registerSocketEvents = (socket) => {
|
||||||
|
// DMS reset events (clear per-socket DMS transactional cache)
|
||||||
|
const registerDmsResetEvents = (socket) => {
|
||||||
|
socket.on("dms-reset-context", async ({ jobId, mode } = {}, ack) => {
|
||||||
|
try {
|
||||||
|
// This clears all transactional session data for this socket
|
||||||
|
// (RR txEnvelope/JobData/SelectedCustomer/PendingRO/etc, Fortellis, etc.)
|
||||||
|
await clearSessionTransactionData(socket.id);
|
||||||
|
|
||||||
|
createLogEvent(
|
||||||
|
socket,
|
||||||
|
"debug",
|
||||||
|
`DMS reset-context: cleared transactional session data` +
|
||||||
|
(jobId ? ` (jobId=${jobId})` : "") +
|
||||||
|
(mode ? ` (mode=${mode})` : "")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (typeof ack === "function") {
|
||||||
|
ack({ ok: true });
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
createLogEvent(socket, "error", `DMS reset-context failed: ${error.message}`);
|
||||||
|
if (typeof ack === "function") {
|
||||||
|
ack({ ok: false, error: error.message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Token Update Events
|
// Token Update Events
|
||||||
const registerUpdateEvents = (socket) => {
|
const registerUpdateEvents = (socket) => {
|
||||||
let latestTokenTimestamp = 0;
|
let latestTokenTimestamp = 0;
|
||||||
@@ -164,7 +192,9 @@ const redisSocketEvents = ({ io, redisHelpers, ioHelpers, logger }) => {
|
|||||||
// Optional: clear transactional session
|
// Optional: clear transactional session
|
||||||
try {
|
try {
|
||||||
await clearSessionTransactionData(socket.id);
|
await clearSessionTransactionData(socket.id);
|
||||||
} catch {}
|
} catch {
|
||||||
|
//
|
||||||
|
}
|
||||||
// Leave all rooms except the default room (socket.id)
|
// Leave all rooms except the default room (socket.id)
|
||||||
const rooms = Array.from(socket.rooms).filter((room) => room !== socket.id);
|
const rooms = Array.from(socket.rooms).filter((room) => room !== socket.id);
|
||||||
for (const room of rooms) {
|
for (const room of rooms) {
|
||||||
@@ -363,6 +393,7 @@ const redisSocketEvents = ({ io, redisHelpers, ioHelpers, logger }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Call Handlers
|
// Call Handlers
|
||||||
|
registerDmsResetEvents(socket);
|
||||||
registerRoomAndBroadcastEvents(socket);
|
registerRoomAndBroadcastEvents(socket);
|
||||||
registerUpdateEvents(socket);
|
registerUpdateEvents(socket);
|
||||||
registerMessagingEvents(socket);
|
registerMessagingEvents(socket);
|
||||||
|
|||||||
@@ -115,6 +115,33 @@ function SetLegacyWebsocketHandlers(io) {
|
|||||||
socket.on("disconnect", () => {
|
socket.on("disconnect", () => {
|
||||||
createLogEvent(socket, "DEBUG", `User disconnected.`);
|
createLogEvent(socket, "DEBUG", `User disconnected.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// DMS reset for legacy WS (CDK / PBS)
|
||||||
|
socket.on("dms-reset-context", ({ jobId, mode } = {}, ack) => {
|
||||||
|
try {
|
||||||
|
// Clear any per-socket DMS state that can leak across jobs
|
||||||
|
socket.selectedCustomerId = null; // CDK / PBS AR
|
||||||
|
socket.txEnvelope = null; // PBS AP export
|
||||||
|
socket.apAllocations = null; // PBS AP allocations
|
||||||
|
|
||||||
|
createLogEvent(
|
||||||
|
socket,
|
||||||
|
"DEBUG",
|
||||||
|
`DMS reset-context (legacy WS): cleared per-socket state` +
|
||||||
|
(jobId ? ` (jobId=${jobId})` : "") +
|
||||||
|
(mode ? ` (mode=${mode})` : "")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (typeof ack === "function") {
|
||||||
|
ack({ ok: true });
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
createLogEvent(socket, "ERROR", `DMS reset-context (legacy WS) failed: ${error.message}`);
|
||||||
|
if (typeof ack === "function") {
|
||||||
|
ack({ ok: false, error: error.message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user