Compare commits
36 Commits
rrScratch2
...
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 | ||
|
|
123066f1cd | ||
|
|
a153cca3c0 | ||
|
|
35c7c32c8e |
@@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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]);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
|
import { resolveRROpCodeFromBodyshop } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
|
|
||||||
@@ -17,7 +18,21 @@ export default connect(mapStateToProps, mapDispatchToProps)(RrAllocationsSummary
|
|||||||
/**
|
/**
|
||||||
* Normalize job allocations into a flat list for display / preview building.
|
* Normalize job allocations into a flat list for display / preview building.
|
||||||
* @param ack
|
* @param ack
|
||||||
* @returns {{center: *, sale, partsSale, laborTaxableSale, laborNonTaxableSale, extrasSale, cost, profitCenter, costCenter}[]|*[]}
|
* @returns {{
|
||||||
|
* center: *,
|
||||||
|
* sale: *,
|
||||||
|
* partsSale: *,
|
||||||
|
* partsTaxableSale: *,
|
||||||
|
* partsNonTaxableSale: *,
|
||||||
|
* laborTaxableSale: *,
|
||||||
|
* laborNonTaxableSale: *,
|
||||||
|
* extrasSale: *,
|
||||||
|
* extrasTaxableSale: *,
|
||||||
|
* extrasNonTaxableSale: *,
|
||||||
|
* cost: *,
|
||||||
|
* profitCenter: *,
|
||||||
|
* costCenter: *
|
||||||
|
* }[]|*[]}
|
||||||
*/
|
*/
|
||||||
function normalizeJobAllocations(ack) {
|
function normalizeJobAllocations(ack) {
|
||||||
if (!ack || !Array.isArray(ack.jobAllocations)) return [];
|
if (!ack || !Array.isArray(ack.jobAllocations)) return [];
|
||||||
@@ -30,9 +45,13 @@ function normalizeJobAllocations(ack) {
|
|||||||
|
|
||||||
// bucketed sales used to build split ROGOG/ROLABOR
|
// bucketed sales used to build split ROGOG/ROLABOR
|
||||||
partsSale: row.partsSale || null,
|
partsSale: row.partsSale || null,
|
||||||
|
partsTaxableSale: row.partsTaxableSale || null,
|
||||||
|
partsNonTaxableSale: row.partsNonTaxableSale || null,
|
||||||
laborTaxableSale: row.laborTaxableSale || null,
|
laborTaxableSale: row.laborTaxableSale || null,
|
||||||
laborNonTaxableSale: row.laborNonTaxableSale || null,
|
laborNonTaxableSale: row.laborNonTaxableSale || null,
|
||||||
extrasSale: row.extrasSale || null,
|
extrasSale: row.extrasSale || null,
|
||||||
|
extrasTaxableSale: row.extrasTaxableSale || null,
|
||||||
|
extrasNonTaxableSale: row.extrasNonTaxableSale || null,
|
||||||
|
|
||||||
cost: row.cost || null,
|
cost: row.cost || null,
|
||||||
profitCenter: row.profitCenter || null,
|
profitCenter: row.profitCenter || null,
|
||||||
@@ -50,17 +69,20 @@ function normalizeJobAllocations(ack) {
|
|||||||
* is now done on the backend via buildRogogFromAllocations/buildRolaborFromRogog.
|
* is now done on the backend via buildRogogFromAllocations/buildRolaborFromRogog.
|
||||||
* This component just renders the preview from `ack.rogg` / `ack.rolabor`.
|
* This component just renders the preview from `ack.rogg` / `ack.rolabor`.
|
||||||
*/
|
*/
|
||||||
export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
export function RrAllocationsSummary({ socket, bodyshop, jobId, title, onAllocationsChange, opCode }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [roggPreview, setRoggPreview] = useState(null);
|
const [roggPreview, setRoggPreview] = useState(null);
|
||||||
const [rolaborPreview, setRolaborPreview] = useState(null);
|
const [rolaborPreview, setRolaborPreview] = useState(null);
|
||||||
const [error, setError] = 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(() => {
|
const fetchAllocations = useCallback(() => {
|
||||||
if (!socket || !jobId) return;
|
if (!socket || !jobId) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
socket.emit("rr-calculate-allocations", jobId, (ack) => {
|
socket.emit("rr-calculate-allocations", { jobId, opCode: effectiveOpCode }, (ack) => {
|
||||||
if (ack && ack.ok === false) {
|
if (ack && ack.ok === false) {
|
||||||
setRoggPreview(null);
|
setRoggPreview(null);
|
||||||
setRolaborPreview(null);
|
setRolaborPreview(null);
|
||||||
@@ -69,6 +91,9 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
|||||||
socket.allocationsSummary = [];
|
socket.allocationsSummary = [];
|
||||||
socket.rrAllocationsRaw = ack;
|
socket.rrAllocationsRaw = ack;
|
||||||
}
|
}
|
||||||
|
if (onAllocationsChange) {
|
||||||
|
onAllocationsChange([]);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +107,9 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
|||||||
socket.allocationsSummary = jobAllocRows;
|
socket.allocationsSummary = jobAllocRows;
|
||||||
socket.rrAllocationsRaw = ack;
|
socket.rrAllocationsRaw = ack;
|
||||||
}
|
}
|
||||||
|
if (onAllocationsChange) {
|
||||||
|
onAllocationsChange(jobAllocRows);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
setRoggPreview(null);
|
setRoggPreview(null);
|
||||||
@@ -90,25 +118,32 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
|||||||
if (socket) {
|
if (socket) {
|
||||||
socket.allocationsSummary = [];
|
socket.allocationsSummary = [];
|
||||||
}
|
}
|
||||||
|
if (onAllocationsChange) {
|
||||||
|
onAllocationsChange([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [socket, jobId, t]);
|
}, [socket, jobId, t, onAllocationsChange, effectiveOpCode]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAllocations();
|
fetchAllocations();
|
||||||
}, [fetchAllocations]);
|
}, [fetchAllocations]);
|
||||||
|
|
||||||
const opCode = bodyshop?.rr_configuration?.baseOpCode || "28TOZ";
|
|
||||||
|
|
||||||
const segmentLabelMap = {
|
const segmentLabelMap = {
|
||||||
partsExtras: "Parts/Extras",
|
partsTaxable: "Parts Taxable",
|
||||||
laborTaxable: "Taxable Labor",
|
partsNonTaxable: "Parts Non-Taxable",
|
||||||
laborNonTaxable: "Non-Taxable Labor"
|
extrasTaxable: "Extras Taxable",
|
||||||
|
extrasNonTaxable: "Extras Non-Taxable",
|
||||||
|
laborTaxable: "Labor Taxable",
|
||||||
|
laborNonTaxable: "Labor Non-Taxable"
|
||||||
};
|
};
|
||||||
|
|
||||||
const roggRows = useMemo(() => {
|
const roggRows = useMemo(() => {
|
||||||
if (!roggPreview || !Array.isArray(roggPreview.ops)) return [];
|
if (!roggPreview || !Array.isArray(roggPreview.ops)) return [];
|
||||||
|
|
||||||
const rows = [];
|
const rows = [];
|
||||||
roggPreview.ops.forEach((op) => {
|
roggPreview.ops.forEach((op) => {
|
||||||
|
const rowOpCode = opCode || op.opCode;
|
||||||
|
|
||||||
(op.lines || []).forEach((line, idx) => {
|
(op.lines || []).forEach((line, idx) => {
|
||||||
const baseDesc = line.itemDesc;
|
const baseDesc = line.itemDesc;
|
||||||
const segmentKind = op.segmentKind;
|
const segmentKind = op.segmentKind;
|
||||||
@@ -118,7 +153,7 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
|||||||
|
|
||||||
rows.push({
|
rows.push({
|
||||||
key: `${op.jobNo}-${idx}`,
|
key: `${op.jobNo}-${idx}`,
|
||||||
opCode: op.opCode,
|
opCode: rowOpCode,
|
||||||
jobNo: op.jobNo,
|
jobNo: op.jobNo,
|
||||||
breakOut: line.breakOut,
|
breakOut: line.breakOut,
|
||||||
itemType: line.itemType,
|
itemType: line.itemType,
|
||||||
@@ -135,22 +170,27 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
return rows;
|
return rows;
|
||||||
}, [roggPreview]);
|
}, [roggPreview, opCode, segmentLabelMap]);
|
||||||
|
|
||||||
const rolaborRows = useMemo(() => {
|
const rolaborRows = useMemo(() => {
|
||||||
if (!rolaborPreview || !Array.isArray(rolaborPreview.ops)) return [];
|
if (!rolaborPreview || !Array.isArray(rolaborPreview.ops)) return [];
|
||||||
return rolaborPreview.ops.map((op, idx) => ({
|
|
||||||
key: `${op.jobNo}-${idx}`,
|
return rolaborPreview.ops.map((op, idx) => {
|
||||||
opCode: op.opCode,
|
const rowOpCode = opCode || op.opCode;
|
||||||
jobNo: op.jobNo,
|
|
||||||
custPayTypeFlag: op.custPayTypeFlag,
|
return {
|
||||||
custTxblNtxblFlag: op.custTxblNtxblFlag,
|
key: `${op.jobNo}-${idx}`,
|
||||||
payType: op.bill?.payType,
|
opCode: rowOpCode,
|
||||||
amtType: op.amount?.amtType,
|
jobNo: op.jobNo,
|
||||||
custPrice: op.amount?.custPrice,
|
custPayTypeFlag: op.custPayTypeFlag,
|
||||||
totalAmt: op.amount?.totalAmt
|
custTxblNtxblFlag: op.custTxblNtxblFlag,
|
||||||
}));
|
payType: op.bill?.payType,
|
||||||
}, [rolaborPreview]);
|
amtType: op.amount?.amtType,
|
||||||
|
custPrice: op.amount?.custPrice,
|
||||||
|
totalAmt: op.amount?.totalAmt
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}, [rolaborPreview, opCode]);
|
||||||
|
|
||||||
// Totals for ROGOG (sum custPrice + dlrCost over all lines)
|
// Totals for ROGOG (sum custPrice + dlrCost over all lines)
|
||||||
const roggTotals = useMemo(() => {
|
const roggTotals = useMemo(() => {
|
||||||
@@ -211,9 +251,11 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
|||||||
children: (
|
children: (
|
||||||
<>
|
<>
|
||||||
<Typography.Paragraph type="secondary" style={{ marginBottom: 8 }}>
|
<Typography.Paragraph type="secondary" style={{ marginBottom: 8 }}>
|
||||||
OpCode: <strong>{opCode}</strong>. Only centers with RR GOG mapping (rr_gogcode & rr_item_type) are
|
OpCode: <strong>{effectiveOpCode}</strong>. Only centers with RR GOG mapping (rr_gogcode & rr_item_type)
|
||||||
included. Totals below reflect exactly what will be sent in ROGOG.
|
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>
|
</Typography.Paragraph>
|
||||||
|
|
||||||
<Table
|
<Table
|
||||||
pagination={false}
|
pagination={false}
|
||||||
columns={roggColumns}
|
columns={roggColumns}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -66,15 +66,6 @@ const DMS_SOCKET_EVENTS = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, insertAuditTrail }) {
|
export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, insertAuditTrail }) {
|
||||||
const { t } = useTranslation();
|
|
||||||
const [resetAfterReconnect, setResetAfterReconnect] = useState(false);
|
|
||||||
|
|
||||||
const history = useNavigate();
|
|
||||||
const search = queryString.parse(useLocation().search);
|
|
||||||
const { jobId } = search;
|
|
||||||
|
|
||||||
const notification = useNotification();
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
treatments: { Fortellis }
|
treatments: { Fortellis }
|
||||||
} = useSplitTreatments({
|
} = useSplitTreatments({
|
||||||
@@ -83,10 +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 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]);
|
||||||
|
|
||||||
@@ -95,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);
|
||||||
@@ -152,6 +185,10 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
setLogs([]);
|
setLogs([]);
|
||||||
setRrOpenRoLimit(false);
|
setRrOpenRoLimit(false);
|
||||||
setrrValidationPending(false);
|
setrrValidationPending(false);
|
||||||
|
setAllocationsSummary(null);
|
||||||
|
|
||||||
|
// RR OpCode parts: reset to config defaults when job/mode changes
|
||||||
|
setRrOpCodeParts(deriveDefaultRrOpCodeParts());
|
||||||
|
|
||||||
if (!activeSocket) return;
|
if (!activeSocket) return;
|
||||||
|
|
||||||
@@ -398,6 +435,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
{!isRrMode ? (
|
{!isRrMode ? (
|
||||||
<DmsAllocationsSummary
|
<DmsAllocationsSummary
|
||||||
key={resetKey}
|
key={resetKey}
|
||||||
|
onAllocationsChange={setAllocationsSummary}
|
||||||
title={
|
title={
|
||||||
<span>
|
<span>
|
||||||
<Link
|
<Link
|
||||||
@@ -415,6 +453,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
) : (
|
) : (
|
||||||
<RrAllocationsSummary
|
<RrAllocationsSummary
|
||||||
key={resetKey}
|
key={resetKey}
|
||||||
|
onAllocationsChange={setAllocationsSummary}
|
||||||
title={
|
title={
|
||||||
<span>
|
<span>
|
||||||
<Link to={`/manage/jobs/${data && data.jobs_by_pk.id}`}>
|
<Link to={`/manage/jobs/${data && data.jobs_by_pk.id}`}>
|
||||||
@@ -427,12 +466,22 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
}
|
}
|
||||||
socket={activeSocket}
|
socket={activeSocket}
|
||||||
jobId={jobId}
|
jobId={jobId}
|
||||||
|
opCode={rrOpCodeCombined}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col md={24} lg={14} className="dms-equal-height-col">
|
<Col md={24} lg={14} className="dms-equal-height-col">
|
||||||
<DmsPostForm key={resetKey} 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
|
||||||
|
|||||||
@@ -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];
|
||||||
|
|||||||
@@ -1221,7 +1221,7 @@ export const TemplateList = (type, context) => {
|
|||||||
payments_by_date_excel: {
|
payments_by_date_excel: {
|
||||||
title: i18n.t("reportcenter.templates.payments_by_date_excel"),
|
title: i18n.t("reportcenter.templates.payments_by_date_excel"),
|
||||||
subject: i18n.t("reportcenter.templates.payments_by_date_excel"),
|
subject: i18n.t("reportcenter.templates.payments_by_date_excel"),
|
||||||
key: "payments_by_date",
|
key: "payments_by_date_excel",
|
||||||
reporttype: "excel",
|
reporttype: "excel",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
rangeFilter: {
|
rangeFilter: {
|
||||||
|
|||||||
@@ -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"."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
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2195,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){
|
||||||
@@ -3173,3 +3171,10 @@ mutation INSERT_MEDIA_ANALYTICS($mediaObject: media_analytics_insert_input!) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
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,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* THIS IS A COPY of CDKCalculateAllocations, modified to:
|
* THIS IS A COPY of CDKCalculateAllocations, modified to:
|
||||||
* - Only calculate allocations needed for Reynolds & RR exports
|
* - Only calculate allocations needed for Reynolds & RR exports
|
||||||
* - Keep sales broken down into buckets (parts, taxable labor, non-taxable labor, extras)
|
* - Keep sales broken down into buckets (parts, taxable / non-taxable parts, taxable labor, non-taxable labor, extras)
|
||||||
* - Add extra logging for easier debugging
|
* - Add extra logging for easier debugging
|
||||||
*
|
*
|
||||||
* Original comments follow.
|
* Original comments follow.
|
||||||
@@ -49,15 +49,24 @@ const summarizeAllocationsArray = (arr) =>
|
|||||||
/**
|
/**
|
||||||
* Internal per-center bucket shape for *sales*.
|
* Internal per-center bucket shape for *sales*.
|
||||||
* We keep separate buckets for RR so we can split
|
* We keep separate buckets for RR so we can split
|
||||||
* taxable vs non-taxable labor lines later.
|
* taxable vs non-taxable parts and labor lines later.
|
||||||
*/
|
*/
|
||||||
function emptyCenterBucket() {
|
function emptyCenterBucket() {
|
||||||
const zero = Dinero();
|
const zero = Dinero();
|
||||||
return {
|
return {
|
||||||
partsSale: zero, // parts sale
|
// Parts
|
||||||
|
partsSale: zero, // total parts (taxable + non-taxable)
|
||||||
|
partsTaxableSale: zero, // parts that should be taxed in RR
|
||||||
|
partsNonTaxableSale: zero, // parts that should NOT be taxed in RR
|
||||||
|
|
||||||
|
// Labor
|
||||||
laborTaxableSale: zero, // labor that should be taxed in RR
|
laborTaxableSale: zero, // labor that should be taxed in RR
|
||||||
laborNonTaxableSale: zero, // labor that should NOT be taxed in RR
|
laborNonTaxableSale: zero, // labor that should NOT be taxed in RR
|
||||||
extrasSale: zero // MAPA/MASH/towing/storage/PAO/etc
|
|
||||||
|
// Extras (MAPA/MASH/towing/PAO/etc)
|
||||||
|
extrasSale: zero, // total extras (taxable + non-taxable)
|
||||||
|
extrasTaxableSale: zero,
|
||||||
|
extrasNonTaxableSale: zero
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,17 +164,228 @@ function buildTaxAllocations(bodyshop, job) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decide if a labor line is taxable vs non-taxable for RR.
|
* ============================
|
||||||
|
* Tax Context & Helpers
|
||||||
|
* ============================
|
||||||
*/
|
*/
|
||||||
function isLaborTaxable(line) {
|
|
||||||
return line.tax_part;
|
/**
|
||||||
|
* Build a small "tax context" object from the job + current instance.
|
||||||
|
*
|
||||||
|
* This centralises all of the "is this category taxable?" logic so that
|
||||||
|
* the rest of the allocation code just asks simple yes/no questions.
|
||||||
|
*
|
||||||
|
* IMPORTANT: we are **not** calculating any tax **amounts** here – that is
|
||||||
|
* still handled by job-costing. We only need to know if a given sale bucket
|
||||||
|
* should be treated as taxable vs non-taxable for RR (CustTxblNTxblFlag).
|
||||||
|
*/
|
||||||
|
function buildTaxContext(job = {}) {
|
||||||
|
const isImex = !!InstanceManager({ imex: true }); // Canada
|
||||||
|
const isRome = !!InstanceManager({ rome: true }); // US
|
||||||
|
|
||||||
|
const toNumber = (v) => (v == null ? 0 : Number(v) || 0);
|
||||||
|
|
||||||
|
const federalTaxRate = toNumber(job.federal_tax_rate);
|
||||||
|
const stateTaxRate = toNumber(job.state_tax_rate);
|
||||||
|
const localTaxRate = toNumber(job.local_tax_rate);
|
||||||
|
|
||||||
|
const hasFederalRate = federalTaxRate > 0;
|
||||||
|
const hasState = stateTaxRate > 0;
|
||||||
|
const hasLocal = localTaxRate > 0;
|
||||||
|
|
||||||
|
// "hasFederal" kept for backwards compatibility / logging (Canada only)
|
||||||
|
const hasFederal = isImex && hasFederalRate;
|
||||||
|
|
||||||
|
// Canada: if ANY of federal / state / local > 0, treat the job as
|
||||||
|
// "everything taxable by default", then let line-level flags override
|
||||||
|
// for parts where applicable.
|
||||||
|
const globalAllTaxCanada = isImex && (hasFederalRate || hasState || hasLocal);
|
||||||
|
|
||||||
|
const hasAnySalesTax = hasFederalRate || hasState || hasLocal;
|
||||||
|
|
||||||
|
// Parts tax rate map (PAA/PAC/…)
|
||||||
|
let partTaxRates = job.part_tax_rates || job.parts_tax_rates || {};
|
||||||
|
if (typeof partTaxRates === "string") {
|
||||||
|
try {
|
||||||
|
partTaxRates = JSON.parse(partTaxRates);
|
||||||
|
} catch {
|
||||||
|
partTaxRates = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!partTaxRates || typeof partTaxRates !== "object") {
|
||||||
|
partTaxRates = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const tax_lbr_rt = toNumber(job.tax_lbr_rt); // labour
|
||||||
|
const tax_paint_mat_rt = toNumber(job.tax_paint_mat_rt || job.tax_paint_mt_rate); // MAPA
|
||||||
|
const tax_shop_mat_rt = toNumber(job.tax_shop_mat_rt); // MASH
|
||||||
|
const tax_tow_rt = toNumber(job.tax_tow_rt); // towing
|
||||||
|
const tax_sub_rt = toNumber(job.tax_sub_rt); // sublet (rarely used directly)
|
||||||
|
|
||||||
|
const hasAnyPartsWithTax = Object.values(partTaxRates).some(
|
||||||
|
(entry) => entry && entry.prt_tax_in && toNumber(entry.prt_tax_rt) > 0
|
||||||
|
);
|
||||||
|
|
||||||
|
const hasAnyTax =
|
||||||
|
hasAnySalesTax ||
|
||||||
|
tax_lbr_rt > 0 ||
|
||||||
|
tax_paint_mat_rt > 0 ||
|
||||||
|
tax_shop_mat_rt > 0 ||
|
||||||
|
tax_tow_rt > 0 ||
|
||||||
|
tax_sub_rt > 0 ||
|
||||||
|
hasAnyPartsWithTax;
|
||||||
|
|
||||||
|
return {
|
||||||
|
isImex,
|
||||||
|
isRome,
|
||||||
|
|
||||||
|
federalTaxRate,
|
||||||
|
stateTaxRate,
|
||||||
|
localTaxRate,
|
||||||
|
|
||||||
|
hasFederal,
|
||||||
|
hasState,
|
||||||
|
hasLocal,
|
||||||
|
hasAnySalesTax,
|
||||||
|
globalAllTaxCanada,
|
||||||
|
|
||||||
|
partTaxRates,
|
||||||
|
tax_lbr_rt,
|
||||||
|
tax_paint_mat_rt,
|
||||||
|
tax_shop_mat_rt,
|
||||||
|
tax_tow_rt,
|
||||||
|
tax_sub_rt,
|
||||||
|
hasAnyPartsWithTax,
|
||||||
|
hasAnyTax
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the "PA" / part-type code (PAA/PAC/…) from a job line.
|
||||||
|
*/
|
||||||
|
function resolvePartType(line = {}) {
|
||||||
|
return line.part_type || line.partType || line.pa_code || line.pa || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decide if a *part* line is taxable vs non-taxable for RR.
|
||||||
|
*
|
||||||
|
* Rules:
|
||||||
|
* - Canada (IMEX):
|
||||||
|
* - If ANY of federal_tax_rate / state_tax_rate / local_tax_rate > 0
|
||||||
|
* => everything is taxable by default (globalAllTaxCanada),
|
||||||
|
* unless tax_part is explicitly false.
|
||||||
|
* - Otherwise, use part_tax_rates[part_type] (prt_tax_in && prt_tax_rt > 0),
|
||||||
|
* with tax_part as final override.
|
||||||
|
* - US (ROME):
|
||||||
|
* - Use part_tax_rates[part_type] (prt_tax_in && prt_tax_rt > 0),
|
||||||
|
* with tax_part as final override.
|
||||||
|
*
|
||||||
|
* - line.tax_part is treated as the *final* check:
|
||||||
|
* - tax_part === false => always non-taxable.
|
||||||
|
* - tax_part === true => always taxable, even if we have no table entry.
|
||||||
|
*/
|
||||||
|
function isPartTaxable(line = {}, taxCtx) {
|
||||||
|
if (!taxCtx) return !!line.tax_part;
|
||||||
|
|
||||||
|
const { globalAllTaxCanada, partTaxRates } = taxCtx;
|
||||||
|
|
||||||
|
// Explicit per-line override to *not* tax.
|
||||||
|
if (typeof line.tax_part === "boolean" && line.tax_part === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Canada: any federal/state/local tax rate set => all parts taxable,
|
||||||
|
// unless explicitly turned off above.
|
||||||
|
if (globalAllTaxCanada) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let taxable = false;
|
||||||
|
|
||||||
|
const partType = resolvePartType(line);
|
||||||
|
if (partType && partTaxRates && partTaxRates[partType]) {
|
||||||
|
const entry = partTaxRates[partType];
|
||||||
|
const rate = Number(entry?.prt_tax_rt || 0);
|
||||||
|
const indicator = !!entry?.prt_tax_in;
|
||||||
|
taxable = indicator && rate > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// tax_part === true is treated as "final yes" even if we didn't find
|
||||||
|
// a matching part_tax_rate entry.
|
||||||
|
if (typeof line.tax_part === "boolean" && line.tax_part === true) {
|
||||||
|
taxable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return taxable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decide if *labour* for this job is taxable.
|
||||||
|
*
|
||||||
|
* - Canada (IMEX):
|
||||||
|
* - If ANY of federal_tax_rate / state_tax_rate / local_tax_rate > 0
|
||||||
|
* (globalAllTaxCanada) => all labour is taxable.
|
||||||
|
* - Else if tax_lbr_rt > 0 => labour taxable.
|
||||||
|
* - Else => non-taxable.
|
||||||
|
* - US (ROME):
|
||||||
|
* - tax_lbr_rt > 0 => labour taxable, otherwise not.
|
||||||
|
*/
|
||||||
|
function isLaborTaxable(_line, taxCtx) {
|
||||||
|
if (!taxCtx) return false;
|
||||||
|
const { isImex, globalAllTaxCanada, tax_lbr_rt } = taxCtx;
|
||||||
|
|
||||||
|
if (isImex && globalAllTaxCanada) return true;
|
||||||
|
return tax_lbr_rt > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Taxability helpers for "extras" buckets.
|
||||||
|
* These are all job-level decisions; there are no per-line flags for them
|
||||||
|
* in the data we currently work with.
|
||||||
|
*
|
||||||
|
* Canada: if globalAllTaxCanada is true, we treat these as taxable.
|
||||||
|
*/
|
||||||
|
function isMapaTaxable(taxCtx) {
|
||||||
|
if (!taxCtx) return false;
|
||||||
|
const { isImex, globalAllTaxCanada, tax_paint_mat_rt } = taxCtx;
|
||||||
|
if (isImex && globalAllTaxCanada) return true;
|
||||||
|
return tax_paint_mat_rt > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isMashTaxable(taxCtx) {
|
||||||
|
if (!taxCtx) return false;
|
||||||
|
const { isImex, globalAllTaxCanada, tax_shop_mat_rt } = taxCtx;
|
||||||
|
if (isImex && globalAllTaxCanada) return true;
|
||||||
|
return tax_shop_mat_rt > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isTowTaxable(taxCtx) {
|
||||||
|
if (!taxCtx) return false;
|
||||||
|
const { isImex, globalAllTaxCanada, tax_tow_rt } = taxCtx;
|
||||||
|
if (isImex && globalAllTaxCanada) return true;
|
||||||
|
return tax_tow_rt > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to push an "extra" (MAPA/MASH/towing/PAO/etc) amount into the
|
||||||
|
* appropriate taxable / non-taxable buckets for a given center.
|
||||||
|
*/
|
||||||
|
function addExtras(bucket, dineroAmount, isTaxable) {
|
||||||
|
if (!bucket || !dineroAmount || typeof dineroAmount.add !== "function") return;
|
||||||
|
bucket.extrasSale = bucket.extrasSale.add(dineroAmount);
|
||||||
|
if (isTaxable) {
|
||||||
|
bucket.extrasTaxableSale = bucket.extrasTaxableSale.add(dineroAmount);
|
||||||
|
} else {
|
||||||
|
bucket.extrasNonTaxableSale = bucket.extrasNonTaxableSale.add(dineroAmount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build profitCenterHash from joblines (parts + labor) and detect MAPA/MASH presence.
|
* Build profitCenterHash from joblines (parts + labor) and detect MAPA/MASH presence.
|
||||||
* Now stores *buckets* instead of a single Dinero per center.
|
* Now stores *buckets* instead of a single Dinero per center.
|
||||||
*/
|
*/
|
||||||
function buildProfitCenterHash(job, debugLog) {
|
function buildProfitCenterHash(job, debugLog, taxContext) {
|
||||||
let hasMapaLine = false;
|
let hasMapaLine = false;
|
||||||
let hasMashLine = false;
|
let hasMashLine = false;
|
||||||
|
|
||||||
@@ -215,6 +435,15 @@ function buildProfitCenterHash(job, debugLog) {
|
|||||||
amount = amount.add(discount);
|
amount = amount.add(discount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const taxable = isPartTaxable(val, taxContext);
|
||||||
|
|
||||||
|
if (taxable) {
|
||||||
|
bucket.partsTaxableSale = bucket.partsTaxableSale.add(amount);
|
||||||
|
} else {
|
||||||
|
bucket.partsNonTaxableSale = bucket.partsNonTaxableSale.add(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep total parts for compatibility / convenience
|
||||||
bucket.partsSale = bucket.partsSale.add(amount);
|
bucket.partsSale = bucket.partsSale.add(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +458,7 @@ function buildProfitCenterHash(job, debugLog) {
|
|||||||
amount: Math.round(rate * 100)
|
amount: Math.round(rate * 100)
|
||||||
}).multiply(val.mod_lb_hrs);
|
}).multiply(val.mod_lb_hrs);
|
||||||
|
|
||||||
if (isLaborTaxable(val)) {
|
if (isLaborTaxable(val, taxContext)) {
|
||||||
bucket.laborTaxableSale = bucket.laborTaxableSale.add(laborAmount);
|
bucket.laborTaxableSale = bucket.laborTaxableSale.add(laborAmount);
|
||||||
} else {
|
} else {
|
||||||
bucket.laborNonTaxableSale = bucket.laborNonTaxableSale.add(laborAmount);
|
bucket.laborNonTaxableSale = bucket.laborNonTaxableSale.add(laborAmount);
|
||||||
@@ -245,9 +474,13 @@ function buildProfitCenterHash(job, debugLog) {
|
|||||||
centers: Object.entries(profitCenterHash).map(([center, b]) => ({
|
centers: Object.entries(profitCenterHash).map(([center, b]) => ({
|
||||||
center,
|
center,
|
||||||
parts: summarizeMoney(b.partsSale),
|
parts: summarizeMoney(b.partsSale),
|
||||||
|
partsTaxable: summarizeMoney(b.partsTaxableSale),
|
||||||
|
partsNonTaxable: summarizeMoney(b.partsNonTaxableSale),
|
||||||
laborTaxable: summarizeMoney(b.laborTaxableSale),
|
laborTaxable: summarizeMoney(b.laborTaxableSale),
|
||||||
laborNonTaxable: summarizeMoney(b.laborNonTaxableSale),
|
laborNonTaxable: summarizeMoney(b.laborNonTaxableSale),
|
||||||
extras: summarizeMoney(b.extrasSale)
|
extras: summarizeMoney(b.extrasSale),
|
||||||
|
extrasTaxable: summarizeMoney(b.extrasTaxableSale),
|
||||||
|
extrasNonTaxable: summarizeMoney(b.extrasNonTaxableSale)
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -326,39 +559,48 @@ function applyMapaMashManualLines({
|
|||||||
profitCenterHash,
|
profitCenterHash,
|
||||||
hasMapaLine,
|
hasMapaLine,
|
||||||
hasMashLine,
|
hasMashLine,
|
||||||
debugLog
|
debugLog,
|
||||||
|
taxContext
|
||||||
}) {
|
}) {
|
||||||
// MAPA
|
// MAPA (paint materials)
|
||||||
if (!hasMapaLine && job.job_totals.rates.mapa.total.amount > 0) {
|
if (!hasMapaLine && job.job_totals.rates.mapa.total.amount > 0) {
|
||||||
const mapaAccountName = selectedDmsAllocationConfig.profits.MAPA;
|
const mapaAccountName = selectedDmsAllocationConfig.profits.MAPA;
|
||||||
const mapaAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === mapaAccountName);
|
const mapaAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === mapaAccountName);
|
||||||
|
|
||||||
if (mapaAccount) {
|
if (mapaAccount) {
|
||||||
|
const amount = Dinero(job.job_totals.rates.mapa.total);
|
||||||
|
const taxable = isMapaTaxable(taxContext);
|
||||||
|
|
||||||
debugLog("Adding MAPA Line Manually", {
|
debugLog("Adding MAPA Line Manually", {
|
||||||
mapaAccountName,
|
mapaAccountName,
|
||||||
amount: summarizeMoney(Dinero(job.job_totals.rates.mapa.total))
|
amount: summarizeMoney(amount),
|
||||||
|
taxable
|
||||||
});
|
});
|
||||||
|
|
||||||
const bucket = ensureCenterBucket(profitCenterHash, mapaAccountName);
|
const bucket = ensureCenterBucket(profitCenterHash, mapaAccountName);
|
||||||
bucket.extrasSale = bucket.extrasSale.add(Dinero(job.job_totals.rates.mapa.total));
|
addExtras(bucket, amount, taxable);
|
||||||
} else {
|
} else {
|
||||||
debugLog("NO MAPA ACCOUNT FOUND!!", { mapaAccountName });
|
debugLog("NO MAPA ACCOUNT FOUND!!", { mapaAccountName });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MASH
|
// MASH (shop materials)
|
||||||
if (!hasMashLine && job.job_totals.rates.mash.total.amount > 0) {
|
if (!hasMashLine && job.job_totals.rates.mash.total.amount > 0) {
|
||||||
const mashAccountName = selectedDmsAllocationConfig.profits.MASH;
|
const mashAccountName = selectedDmsAllocationConfig.profits.MASH;
|
||||||
const mashAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === mashAccountName);
|
const mashAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === mashAccountName);
|
||||||
|
|
||||||
if (mashAccount) {
|
if (mashAccount) {
|
||||||
|
const amount = Dinero(job.job_totals.rates.mash.total);
|
||||||
|
const taxable = isMashTaxable(taxContext);
|
||||||
|
|
||||||
debugLog("Adding MASH Line Manually", {
|
debugLog("Adding MASH Line Manually", {
|
||||||
mashAccountName,
|
mashAccountName,
|
||||||
amount: summarizeMoney(Dinero(job.job_totals.rates.mash.total))
|
amount: summarizeMoney(amount),
|
||||||
|
taxable
|
||||||
});
|
});
|
||||||
|
|
||||||
const bucket = ensureCenterBucket(profitCenterHash, mashAccountName);
|
const bucket = ensureCenterBucket(profitCenterHash, mashAccountName);
|
||||||
bucket.extrasSale = bucket.extrasSale.add(Dinero(job.job_totals.rates.mash.total));
|
addExtras(bucket, amount, taxable);
|
||||||
} else {
|
} else {
|
||||||
debugLog("NO MASH ACCOUNT FOUND!!", { mashAccountName });
|
debugLog("NO MASH ACCOUNT FOUND!!", { mashAccountName });
|
||||||
}
|
}
|
||||||
@@ -440,9 +682,17 @@ function applyMaterialsCosting({ job, bodyshop, selectedDmsAllocationConfig, cos
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply non-tax extras (PVRT, towing, storage, PAO).
|
* Apply non-tax extras (PVRT, towing, storage, PAO).
|
||||||
* Extras go into the extrasSale bucket.
|
* Extras go into the extrasSale bucket (split taxable / non-taxable).
|
||||||
*/
|
*/
|
||||||
function applyExtras({ job, bodyshop, selectedDmsAllocationConfig, profitCenterHash, taxAllocations, debugLog }) {
|
function applyExtras({
|
||||||
|
job,
|
||||||
|
bodyshop,
|
||||||
|
selectedDmsAllocationConfig,
|
||||||
|
profitCenterHash,
|
||||||
|
taxAllocations,
|
||||||
|
debugLog,
|
||||||
|
taxContext
|
||||||
|
}) {
|
||||||
const { ca_bc_pvrt } = job;
|
const { ca_bc_pvrt } = job;
|
||||||
|
|
||||||
// BC PVRT -> state tax
|
// BC PVRT -> state tax
|
||||||
@@ -458,17 +708,19 @@ function applyExtras({ job, bodyshop, selectedDmsAllocationConfig, profitCenterH
|
|||||||
const towAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === towAccountName);
|
const towAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === towAccountName);
|
||||||
|
|
||||||
if (towAccount) {
|
if (towAccount) {
|
||||||
|
const amount = Dinero({
|
||||||
|
amount: Math.round((job.towing_payable || 0) * 100)
|
||||||
|
});
|
||||||
|
const taxable = isTowTaxable(taxContext);
|
||||||
|
|
||||||
debugLog("Adding towing_payable to TOW account", {
|
debugLog("Adding towing_payable to TOW account", {
|
||||||
towAccountName,
|
towAccountName,
|
||||||
towing_payable: job.towing_payable
|
towing_payable: job.towing_payable,
|
||||||
|
taxable
|
||||||
});
|
});
|
||||||
|
|
||||||
const bucket = ensureCenterBucket(profitCenterHash, towAccountName);
|
const bucket = ensureCenterBucket(profitCenterHash, towAccountName);
|
||||||
bucket.extrasSale = bucket.extrasSale.add(
|
addExtras(bucket, amount, taxable);
|
||||||
Dinero({
|
|
||||||
amount: Math.round((job.towing_payable || 0) * 100)
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
debugLog("NO TOW ACCOUNT FOUND!!", { towAccountName });
|
debugLog("NO TOW ACCOUNT FOUND!!", { towAccountName });
|
||||||
}
|
}
|
||||||
@@ -480,17 +732,19 @@ function applyExtras({ job, bodyshop, selectedDmsAllocationConfig, profitCenterH
|
|||||||
const towAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === storageAccountName);
|
const towAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === storageAccountName);
|
||||||
|
|
||||||
if (towAccount) {
|
if (towAccount) {
|
||||||
|
const amount = Dinero({
|
||||||
|
amount: Math.round((job.storage_payable || 0) * 100)
|
||||||
|
});
|
||||||
|
const taxable = isTowTaxable(taxContext);
|
||||||
|
|
||||||
debugLog("Adding storage_payable to TOW account", {
|
debugLog("Adding storage_payable to TOW account", {
|
||||||
storageAccountName,
|
storageAccountName,
|
||||||
storage_payable: job.storage_payable
|
storage_payable: job.storage_payable,
|
||||||
|
taxable
|
||||||
});
|
});
|
||||||
|
|
||||||
const bucket = ensureCenterBucket(profitCenterHash, storageAccountName);
|
const bucket = ensureCenterBucket(profitCenterHash, storageAccountName);
|
||||||
bucket.extrasSale = bucket.extrasSale.add(
|
addExtras(bucket, amount, taxable);
|
||||||
Dinero({
|
|
||||||
amount: Math.round((job.storage_payable || 0) * 100)
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
debugLog("NO STORAGE/TOW ACCOUNT FOUND!!", { storageAccountName });
|
debugLog("NO STORAGE/TOW ACCOUNT FOUND!!", { storageAccountName });
|
||||||
}
|
}
|
||||||
@@ -502,17 +756,19 @@ function applyExtras({ job, bodyshop, selectedDmsAllocationConfig, profitCenterH
|
|||||||
const otherAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === otherAccountName);
|
const otherAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === otherAccountName);
|
||||||
|
|
||||||
if (otherAccount) {
|
if (otherAccount) {
|
||||||
|
const amount = Dinero({
|
||||||
|
amount: Math.round((job.adjustment_bottom_line || 0) * 100)
|
||||||
|
});
|
||||||
|
const taxable = !!(taxContext && taxContext.hasAnyTax);
|
||||||
|
|
||||||
debugLog("Adding adjustment_bottom_line to PAO", {
|
debugLog("Adding adjustment_bottom_line to PAO", {
|
||||||
otherAccountName,
|
otherAccountName,
|
||||||
adjustment_bottom_line: job.adjustment_bottom_line
|
adjustment_bottom_line: job.adjustment_bottom_line,
|
||||||
|
taxable
|
||||||
});
|
});
|
||||||
|
|
||||||
const bucket = ensureCenterBucket(profitCenterHash, otherAccountName);
|
const bucket = ensureCenterBucket(profitCenterHash, otherAccountName);
|
||||||
bucket.extrasSale = bucket.extrasSale.add(
|
addExtras(bucket, amount, taxable);
|
||||||
Dinero({
|
|
||||||
amount: Math.round((job.adjustment_bottom_line || 0) * 100)
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
debugLog("NO PAO ACCOUNT FOUND!!", { otherAccountName });
|
debugLog("NO PAO ACCOUNT FOUND!!", { otherAccountName });
|
||||||
}
|
}
|
||||||
@@ -521,14 +777,6 @@ function applyExtras({ job, bodyshop, selectedDmsAllocationConfig, profitCenterH
|
|||||||
return { profitCenterHash, taxAllocations };
|
return { profitCenterHash, taxAllocations };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply Rome-specific profile adjustments (parts + rates).
|
|
||||||
* These also feed into the *sales* buckets.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Apply Rome-specific profile adjustments (parts + rates).
|
|
||||||
* These also feed into the *sales* buckets.
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* Apply Rome-specific profile adjustments (parts + rates).
|
* Apply Rome-specific profile adjustments (parts + rates).
|
||||||
* These also feed into the *sales* buckets.
|
* These also feed into the *sales* buckets.
|
||||||
@@ -539,7 +787,8 @@ function applyRomeProfileAdjustments({
|
|||||||
selectedDmsAllocationConfig,
|
selectedDmsAllocationConfig,
|
||||||
profitCenterHash,
|
profitCenterHash,
|
||||||
debugLog,
|
debugLog,
|
||||||
connectionData
|
connectionData,
|
||||||
|
taxContext
|
||||||
}) {
|
}) {
|
||||||
// Only relevant for Rome instances
|
// Only relevant for Rome instances
|
||||||
if (!InstanceManager({ rome: true })) return profitCenterHash;
|
if (!InstanceManager({ rome: true })) return profitCenterHash;
|
||||||
@@ -557,6 +806,8 @@ function applyRomeProfileAdjustments({
|
|||||||
rateKeys: Object.keys(rateMap)
|
rateKeys: Object.keys(rateMap)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const extrasTaxable = !!(taxContext && taxContext.hasAnyTax);
|
||||||
|
|
||||||
// Parts adjustments
|
// Parts adjustments
|
||||||
Object.keys(partsAdjustments).forEach((key) => {
|
Object.keys(partsAdjustments).forEach((key) => {
|
||||||
const accountName = selectedDmsAllocationConfig.profits[key];
|
const accountName = selectedDmsAllocationConfig.profits[key];
|
||||||
@@ -566,12 +817,13 @@ function applyRomeProfileAdjustments({
|
|||||||
const bucket = ensureCenterBucket(profitCenterHash, accountName);
|
const bucket = ensureCenterBucket(profitCenterHash, accountName);
|
||||||
|
|
||||||
const adjMoney = Dinero(partsAdjustments[key]);
|
const adjMoney = Dinero(partsAdjustments[key]);
|
||||||
bucket.extrasSale = bucket.extrasSale.add(adjMoney);
|
addExtras(bucket, adjMoney, extrasTaxable);
|
||||||
|
|
||||||
debugLog("Added parts adjustment", {
|
debugLog("Added parts adjustment", {
|
||||||
key,
|
key,
|
||||||
accountName,
|
accountName,
|
||||||
adjustment: summarizeMoney(adjMoney)
|
adjustment: summarizeMoney(adjMoney),
|
||||||
|
taxable: extrasTaxable
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
CreateRRLogEvent(
|
CreateRRLogEvent(
|
||||||
@@ -600,12 +852,13 @@ function applyRomeProfileAdjustments({
|
|||||||
|
|
||||||
// Note: we intentionally use `rate.adjustments` here to mirror CDK behaviour
|
// Note: we intentionally use `rate.adjustments` here to mirror CDK behaviour
|
||||||
const adjMoney = Dinero(rate.adjustments);
|
const adjMoney = Dinero(rate.adjustments);
|
||||||
bucket.extrasSale = bucket.extrasSale.add(adjMoney);
|
addExtras(bucket, adjMoney, extrasTaxable);
|
||||||
|
|
||||||
debugLog("Added rate adjustment", {
|
debugLog("Added rate adjustment", {
|
||||||
key,
|
key,
|
||||||
accountName,
|
accountName,
|
||||||
adjustment: summarizeMoney(adjMoney)
|
adjustment: summarizeMoney(adjMoney),
|
||||||
|
taxable: extrasTaxable
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
CreateRRLogEvent(
|
CreateRRLogEvent(
|
||||||
@@ -627,9 +880,13 @@ function applyRomeProfileAdjustments({
|
|||||||
* {
|
* {
|
||||||
* center,
|
* center,
|
||||||
* partsSale,
|
* partsSale,
|
||||||
|
* partsTaxableSale,
|
||||||
|
* partsNonTaxableSale,
|
||||||
* laborTaxableSale,
|
* laborTaxableSale,
|
||||||
* laborNonTaxableSale,
|
* laborNonTaxableSale,
|
||||||
* extrasSale,
|
* extrasSale,
|
||||||
|
* extrasTaxableSale,
|
||||||
|
* extrasNonTaxableSale,
|
||||||
* totalSale,
|
* totalSale,
|
||||||
* cost,
|
* cost,
|
||||||
* profitCenter,
|
* profitCenter,
|
||||||
@@ -642,10 +899,8 @@ function buildJobAllocations(bodyshop, profitCenterHash, costCenterHash, debugLo
|
|||||||
const jobAllocations = centers.map((center) => {
|
const jobAllocations = centers.map((center) => {
|
||||||
const bucket = profitCenterHash[center] || emptyCenterBucket();
|
const bucket = profitCenterHash[center] || emptyCenterBucket();
|
||||||
|
|
||||||
const totalSale = bucket.partsSale
|
const extrasSale = bucket.extrasSale;
|
||||||
.add(bucket.laborTaxableSale)
|
const totalSale = bucket.partsSale.add(bucket.laborTaxableSale).add(bucket.laborNonTaxableSale).add(extrasSale);
|
||||||
.add(bucket.laborNonTaxableSale)
|
|
||||||
.add(bucket.extrasSale);
|
|
||||||
|
|
||||||
const profitCenter = bodyshop.md_responsibility_centers.profits.find((c) => c.name === center);
|
const profitCenter = bodyshop.md_responsibility_centers.profits.find((c) => c.name === center);
|
||||||
const costCenter = bodyshop.md_responsibility_centers.costs.find((c) => c.name === center);
|
const costCenter = bodyshop.md_responsibility_centers.costs.find((c) => c.name === center);
|
||||||
@@ -653,10 +908,20 @@ function buildJobAllocations(bodyshop, profitCenterHash, costCenterHash, debugLo
|
|||||||
return {
|
return {
|
||||||
center,
|
center,
|
||||||
|
|
||||||
|
// Parts
|
||||||
partsSale: bucket.partsSale,
|
partsSale: bucket.partsSale,
|
||||||
|
partsTaxableSale: bucket.partsTaxableSale,
|
||||||
|
partsNonTaxableSale: bucket.partsNonTaxableSale,
|
||||||
|
|
||||||
|
// Labor
|
||||||
laborTaxableSale: bucket.laborTaxableSale,
|
laborTaxableSale: bucket.laborTaxableSale,
|
||||||
laborNonTaxableSale: bucket.laborNonTaxableSale,
|
laborNonTaxableSale: bucket.laborNonTaxableSale,
|
||||||
extrasSale: bucket.extrasSale,
|
|
||||||
|
// Extras
|
||||||
|
extrasSale,
|
||||||
|
extrasTaxableSale: bucket.extrasTaxableSale,
|
||||||
|
extrasNonTaxableSale: bucket.extrasNonTaxableSale,
|
||||||
|
|
||||||
totalSale,
|
totalSale,
|
||||||
|
|
||||||
cost: costCenterHash[center] || Dinero(),
|
cost: costCenterHash[center] || Dinero(),
|
||||||
@@ -671,9 +936,13 @@ function buildJobAllocations(bodyshop, profitCenterHash, costCenterHash, debugLo
|
|||||||
jobAllocations.map((row) => ({
|
jobAllocations.map((row) => ({
|
||||||
center: row.center,
|
center: row.center,
|
||||||
parts: summarizeMoney(row.partsSale),
|
parts: summarizeMoney(row.partsSale),
|
||||||
|
partsTaxable: summarizeMoney(row.partsTaxableSale),
|
||||||
|
partsNonTaxable: summarizeMoney(row.partsNonTaxableSale),
|
||||||
laborTaxable: summarizeMoney(row.laborTaxableSale),
|
laborTaxable: summarizeMoney(row.laborTaxableSale),
|
||||||
laborNonTaxable: summarizeMoney(row.laborNonTaxableSale),
|
laborNonTaxable: summarizeMoney(row.laborNonTaxableSale),
|
||||||
extras: summarizeMoney(row.extrasSale),
|
extras: summarizeMoney(row.extrasSale),
|
||||||
|
extrasTaxable: summarizeMoney(row.extrasTaxableSale),
|
||||||
|
extrasNonTaxable: summarizeMoney(row.extrasNonTaxableSale),
|
||||||
totalSale: summarizeMoney(row.totalSale),
|
totalSale: summarizeMoney(row.totalSale),
|
||||||
cost: summarizeMoney(row.cost)
|
cost: summarizeMoney(row.cost)
|
||||||
}))
|
}))
|
||||||
@@ -781,12 +1050,35 @@ function calculateAllocations(connectionData, job) {
|
|||||||
timetickets: Array.isArray(job.timetickets) ? job.timetickets.length : 0
|
timetickets: Array.isArray(job.timetickets) ? job.timetickets.length : 0
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const taxContext = buildTaxContext(job);
|
||||||
|
debugLog("Tax context initialised", {
|
||||||
|
isImex: taxContext.isImex,
|
||||||
|
isRome: taxContext.isRome,
|
||||||
|
federalTaxRate: taxContext.federalTaxRate,
|
||||||
|
stateTaxRate: taxContext.stateTaxRate,
|
||||||
|
localTaxRate: taxContext.localTaxRate,
|
||||||
|
hasFederal: taxContext.hasFederal,
|
||||||
|
hasState: taxContext.hasState,
|
||||||
|
hasLocal: taxContext.hasLocal,
|
||||||
|
globalAllTaxCanada: taxContext.globalAllTaxCanada,
|
||||||
|
tax_lbr_rt: taxContext.tax_lbr_rt,
|
||||||
|
tax_paint_mat_rt: taxContext.tax_paint_mat_rt,
|
||||||
|
tax_shop_mat_rt: taxContext.tax_shop_mat_rt,
|
||||||
|
tax_tow_rt: taxContext.tax_tow_rt,
|
||||||
|
hasAnyPartsWithTax: taxContext.hasAnyPartsWithTax,
|
||||||
|
hasAnyTax: taxContext.hasAnyTax
|
||||||
|
});
|
||||||
|
|
||||||
// 1) Tax allocations
|
// 1) Tax allocations
|
||||||
let taxAllocations = buildTaxAllocations(bodyshop, job);
|
let taxAllocations = buildTaxAllocations(bodyshop, job);
|
||||||
debugLog("Initial taxAllocations", summarizeTaxAllocations(taxAllocations));
|
debugLog("Initial taxAllocations", summarizeTaxAllocations(taxAllocations));
|
||||||
|
|
||||||
// 2) Profit centers from job lines + MAPA/MASH detection
|
// 2) Profit centers from job lines + MAPA/MASH detection
|
||||||
const { profitCenterHash: initialProfitHash, hasMapaLine, hasMashLine } = buildProfitCenterHash(job, debugLog);
|
const {
|
||||||
|
profitCenterHash: initialProfitHash,
|
||||||
|
hasMapaLine,
|
||||||
|
hasMashLine
|
||||||
|
} = buildProfitCenterHash(job, debugLog, taxContext);
|
||||||
|
|
||||||
// 3) DMS allocation config
|
// 3) DMS allocation config
|
||||||
const selectedDmsAllocationConfig =
|
const selectedDmsAllocationConfig =
|
||||||
@@ -811,7 +1103,8 @@ function calculateAllocations(connectionData, job) {
|
|||||||
profitCenterHash: initialProfitHash,
|
profitCenterHash: initialProfitHash,
|
||||||
hasMapaLine,
|
hasMapaLine,
|
||||||
hasMashLine,
|
hasMashLine,
|
||||||
debugLog
|
debugLog,
|
||||||
|
taxContext
|
||||||
});
|
});
|
||||||
|
|
||||||
// 6) Materials costing (MAPA/MASH cost side)
|
// 6) Materials costing (MAPA/MASH cost side)
|
||||||
@@ -830,7 +1123,8 @@ function calculateAllocations(connectionData, job) {
|
|||||||
selectedDmsAllocationConfig,
|
selectedDmsAllocationConfig,
|
||||||
profitCenterHash,
|
profitCenterHash,
|
||||||
taxAllocations,
|
taxAllocations,
|
||||||
debugLog
|
debugLog,
|
||||||
|
taxContext
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// 8) Rome-only profile-level adjustments
|
// 8) Rome-only profile-level adjustments
|
||||||
@@ -840,16 +1134,21 @@ function calculateAllocations(connectionData, job) {
|
|||||||
selectedDmsAllocationConfig,
|
selectedDmsAllocationConfig,
|
||||||
profitCenterHash,
|
profitCenterHash,
|
||||||
debugLog,
|
debugLog,
|
||||||
connectionData
|
connectionData,
|
||||||
|
taxContext
|
||||||
});
|
});
|
||||||
|
|
||||||
debugLog("profitCenterHash before jobAllocations build", {
|
debugLog("profitCenterHash before jobAllocations build", {
|
||||||
centers: Object.entries(profitCenterHash || {}).map(([center, b]) => ({
|
centers: Object.entries(profitCenterHash || {}).map(([center, b]) => ({
|
||||||
center,
|
center,
|
||||||
parts: summarizeMoney(b.partsSale),
|
parts: summarizeMoney(b.partsSale),
|
||||||
|
partsTaxable: summarizeMoney(b.partsTaxableSale),
|
||||||
|
partsNonTaxable: summarizeMoney(b.partsNonTaxableSale),
|
||||||
laborTaxable: summarizeMoney(b.laborTaxableSale),
|
laborTaxable: summarizeMoney(b.laborTaxableSale),
|
||||||
laborNonTaxable: summarizeMoney(b.laborNonTaxableSale),
|
laborNonTaxable: summarizeMoney(b.laborNonTaxableSale),
|
||||||
extras: summarizeMoney(b.extrasSale)
|
extras: summarizeMoney(b.extrasSale),
|
||||||
|
extrasTaxable: summarizeMoney(b.extrasTaxableSale),
|
||||||
|
extrasNonTaxable: summarizeMoney(b.extrasNonTaxableSale)
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
debugLog("costCenterHash before jobAllocations build", {
|
debugLog("costCenterHash before jobAllocations build", {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ 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("./rr-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 {
|
||||||
@@ -137,19 +142,28 @@ const exportJobToRR = async (args) => {
|
|||||||
allocations = [];
|
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.
|
||||||
|
|||||||
@@ -56,32 +56,39 @@ 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 allocations.
|
* from allocations.
|
||||||
*
|
*
|
||||||
* Supports the new allocation shape:
|
* Supports the allocation shape:
|
||||||
* {
|
* {
|
||||||
* center,
|
* center,
|
||||||
* partsSale,
|
* partsSale,
|
||||||
|
* partsTaxableSale,
|
||||||
|
* partsNonTaxableSale,
|
||||||
* laborTaxableSale,
|
* laborTaxableSale,
|
||||||
* laborNonTaxableSale,
|
* laborNonTaxableSale,
|
||||||
* extrasSale,
|
* extrasSale,
|
||||||
|
* extrasTaxableSale,
|
||||||
|
* extrasNonTaxableSale,
|
||||||
* totalSale,
|
* totalSale,
|
||||||
* cost,
|
* cost,
|
||||||
* profitCenter,
|
* profitCenter,
|
||||||
* costCenter
|
* costCenter
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* For each center, we can emit up to 3 GOG *segments*:
|
* For each center, we can emit up to 6 GOG *segments*:
|
||||||
* - parts+extras (uses profitCenter.rr_cust_txbl_flag)
|
* - taxable parts (CustTxblNTxblFlag="T")
|
||||||
* - taxable labor (CustTxblNTxblFlag="T")
|
* - non-taxable parts (CustTxblNTxblFlag="N")
|
||||||
* - non-tax labor (CustTxblNTxblFlag="N")
|
* - taxable extras (CustTxblNTxblFlag="T")
|
||||||
|
* - non-taxable extras (CustTxblNTxblFlag="N")
|
||||||
|
* - taxable labor (CustTxblNTxblFlag="T")
|
||||||
|
* - non-taxable labor (CustTxblNTxblFlag="N")
|
||||||
*
|
*
|
||||||
* IMPORTANT CHANGE:
|
* IMPORTANT:
|
||||||
* Each segment becomes its OWN JobNo / AllGogOpCodeInfo, with exactly one
|
* Each segment becomes its OWN JobNo / AllGogOpCodeInfo, with exactly one
|
||||||
* AllGogLineItmInfo inside. This makes the count of:
|
* AllGogLineItmInfo inside. This keeps a clean 1:1 mapping between:
|
||||||
* - <AllGogOpCodeInfo> (ROGOG)
|
* - <AllGogOpCodeInfo> (ROGOG)
|
||||||
* - <OpCodeLaborInfo> (ROLABOR)
|
* - <OpCodeLaborInfo> (ROLABOR)
|
||||||
* match 1:1, and ensures taxable/non-taxable flags line up by JobNo.
|
* and ensures taxable/non-taxable flags line up by JobNo.
|
||||||
*
|
*
|
||||||
* We now also attach segmentKind/segmentIndex/segmentCount metadata on each op
|
* We attach segmentKind/segmentIndex/segmentCount metadata on each op
|
||||||
* for UI/debug purposes. The XML templates can safely ignore these.
|
* for UI/debug purposes. The XML templates can safely ignore these.
|
||||||
*
|
*
|
||||||
* @param {Array} allocations
|
* @param {Array} allocations
|
||||||
@@ -147,27 +154,53 @@ const buildRogogFromAllocations = (allocations, { opCode, payType = "Cust", roNo
|
|||||||
// Only centers configured for RR GOG are included
|
// Only centers configured for RR GOG are included
|
||||||
if (!breakOut || !itemType) continue;
|
if (!breakOut || !itemType) continue;
|
||||||
|
|
||||||
const partsCents = toCents(alloc.partsSale);
|
const partsTaxableCents = toCents(alloc.partsTaxableSale);
|
||||||
const extrasCents = toCents(alloc.extrasSale);
|
const partsNonTaxableCents = toCents(alloc.partsNonTaxableSale);
|
||||||
|
const extrasTaxableCents = toCents(alloc.extrasTaxableSale);
|
||||||
|
const extrasNonTaxableCents = toCents(alloc.extrasNonTaxableSale);
|
||||||
const laborTaxableCents = toCents(alloc.laborTaxableSale);
|
const laborTaxableCents = toCents(alloc.laborTaxableSale);
|
||||||
const laborNonTaxableCents = toCents(alloc.laborNonTaxableSale);
|
const laborNonTaxableCents = toCents(alloc.laborNonTaxableSale);
|
||||||
const costCents = toCents(alloc.cost);
|
const costCents = toCents(alloc.cost);
|
||||||
|
|
||||||
// Parts + extras share a single segment
|
|
||||||
const partsExtrasCents = partsCents + extrasCents;
|
|
||||||
|
|
||||||
const segments = [];
|
const segments = [];
|
||||||
|
|
||||||
// 1) Parts + extras segment (respect center's default tax flag)
|
// 1) Taxable parts segment -> "T"
|
||||||
if (partsExtrasCents !== 0) {
|
if (partsTaxableCents !== 0) {
|
||||||
segments.push({
|
segments.push({
|
||||||
kind: "partsExtras",
|
kind: "partsTaxable",
|
||||||
saleCents: partsExtrasCents,
|
saleCents: partsTaxableCents,
|
||||||
txFlag: pc.rr_cust_txbl_flag || "N"
|
txFlag: "T"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2) Taxable labor segment -> "T"
|
// 2) Non-taxable parts segment -> "N"
|
||||||
|
if (partsNonTaxableCents !== 0) {
|
||||||
|
segments.push({
|
||||||
|
kind: "partsNonTaxable",
|
||||||
|
saleCents: partsNonTaxableCents,
|
||||||
|
txFlag: "N"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3) Taxable extras -> "T"
|
||||||
|
if (extrasTaxableCents !== 0) {
|
||||||
|
segments.push({
|
||||||
|
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) {
|
if (laborTaxableCents !== 0) {
|
||||||
segments.push({
|
segments.push({
|
||||||
kind: "laborTaxable",
|
kind: "laborTaxable",
|
||||||
@@ -176,7 +209,7 @@ const buildRogogFromAllocations = (allocations, { opCode, payType = "Cust", roNo
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3) Non-taxable labor segment -> "N"
|
// 6) Non-tax labor segment -> "N"
|
||||||
if (laborNonTaxableCents !== 0) {
|
if (laborNonTaxableCents !== 0) {
|
||||||
segments.push({
|
segments.push({
|
||||||
kind: "laborNonTaxable",
|
kind: "laborNonTaxable",
|
||||||
@@ -254,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"]
|
||||||
@@ -330,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 = ({
|
||||||
@@ -344,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()
|
||||||
@@ -395,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
|
||||||
|
|||||||
@@ -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,9 +953,26 @@ 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 raw = await RRCalculateAllocations(socket, jobid);
|
const raw = await RRCalculateAllocations(socket, jobid);
|
||||||
|
|
||||||
@@ -924,16 +999,24 @@ const registerRREvents = ({ socket, redisHelpers }) => {
|
|||||||
jobAllocations = Array.isArray(ack.jobAllocations) ? ack.jobAllocations : [];
|
jobAllocations = Array.isArray(ack.jobAllocations) ? ack.jobAllocations : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to derive OpCode from bodyshop; fall back to default
|
// Start with client-supplied OpCode (if any); fall back to defaults.
|
||||||
let opCode = "28TOZ";
|
let opCode = opCodeFromClient || null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { bodyshopId } = await getSessionOrSocket(redisHelpers, socket);
|
const { bodyshopId } = await getSessionOrSocket(redisHelpers, socket);
|
||||||
const bodyshop = await getBodyshopForSocket({ bodyshopId, socket });
|
const bodyshop = await getBodyshopForSocket({ bodyshopId, socket });
|
||||||
opCode = bodyshop?.rr_configuration?.baseOpCode || opCode;
|
|
||||||
|
// resolveRROpCodeFromBodyshop(bodyshop, existingOverride?)
|
||||||
|
opCode = resolveRROpCodeFromBodyshop(bodyshop, opCode);
|
||||||
|
|
||||||
|
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: resolved OpCode", {
|
||||||
|
opCode,
|
||||||
|
opCodeFromClient
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
CreateRRLogEvent(socket, "WARN", "rr-calculate-allocations: bodyshop lookup failed, using default OpCode", {
|
CreateRRLogEvent(socket, "WARN", "rr-calculate-allocations: bodyshop lookup failed, using existing OpCode", {
|
||||||
error: e.message
|
error: e.message,
|
||||||
|
opCodeFromClient
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user