Compare commits

..

36 Commits

Author SHA1 Message Date
Dave
288c8e6347 RrScratch3 - Tax / Extras Improvements 2025-12-05 13:17:25 -05:00
Dave
56738f800c Merge remote-tracking branch 'origin/feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration' into rrScratch3 2025-12-05 12:13:57 -05:00
Dave
bedf4f2c02 Merge branch 'feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration' into rrScratch3 2025-12-05 12:13:27 -05:00
Dave Richer
6032ff0e5d Merged in release/2025-12-05 (pull request #2690)
feature/IO-3457-Job-Lifecycle-Tags
2025-12-04 21:23:48 +00:00
Dave Richer
77268d5f5b Merged in feature/IO-3457-job-lifecyle-tags (pull request #2689)
feature/IO-3457-Job-Lifecycle-Tags
2025-12-04 21:23:27 +00:00
Dave
1b3abf17ec feature/IO-3457-Job-Lifecycle-Tags 2025-12-04 16:22:41 -05:00
Dave
0ef68afa0c feature/IO-3456-Broken-Image - Fix issue 2025-12-04 14:30:42 -05:00
Dave
12b4ae3b8d Merge remote-tracking branch 'origin/release/2025-12-05' into feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration 2025-12-04 14:22:41 -05:00
Dave Richer
3cfd445894 Merged in feature/IO-3456-Broken-Image-Path (pull request #2687)
feature/IO-3456-Broken-Image - Fix issue
2025-12-04 19:22:03 +00:00
Dave
b510eec9aa feature/IO-3456-Broken-Image - Fix issue 2025-12-04 14:20:58 -05:00
Dave
e92bab0455 Scratch 2025-12-04 14:12:11 -05:00
Dave
4de3d3c6fc Merge remote-tracking branch 'origin/release/2025-12-05' into feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration 2025-12-03 14:04:41 -05:00
Allan Carr
e5eac0933f Merged in feature/IO-3262-Tech-Console-Job-Clock-Out (pull request #2685)
IO-3262 Add email address to Usage Report

Approved-by: Dave Richer
2025-12-03 19:04:08 +00:00
Allan Carr
a3c71fdfc0 IO-3262 Add email address to Usage Report
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-12-03 10:28:20 -08:00
Dave
a6b3bd573e rrScratch3 - Remove unused fields in RR from responsibility centers 2025-12-02 15:08:49 -05:00
Dave
18373fc865 rrScratch3 - Capture external DMS Id 2025-12-02 15:00:11 -05:00
Dave
3ae8ed8496 rrScratch3 - Progress Commit 2025-12-02 14:10:31 -05:00
Allan Carr
78750d3d96 Merged in feature/IO-3262-Tech-Console-Job-Clock-Out (pull request #2682)
IO-3262 Tech Console Job Clock Out

Approved-by: Dave Richer
2025-12-02 18:59:41 +00:00
Allan Carr
90edf94fee IO-3262 Tech Console Job Clock Out
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-12-01 12:50:11 -08:00
Dave
3507e60356 Merge branch 'feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration' of bitbucket.org:snaptsoft/bodyshop into feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration 2025-12-01 13:02:44 -05:00
Dave
43feb16950 rrScratch3 - Progress Commit 2025-12-01 13:02:13 -05:00
Dave
827f1c2c40 rrScratch3 - Progress Commit 2025-11-28 14:41:00 -05:00
Patrick Fic
58f5ed1ce7 Comment unrequired fortellis API. 2025-11-28 10:31:13 -08:00
Dave
c1e3c08652 feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Fixes to Caching of allocations summary 2025-11-28 11:29:48 -05:00
Dave
d885bac7d0 Merge remote-tracking branch 'origin/release/2025-12-05' into feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration 2025-11-28 10:50:08 -05:00
Allan Carr
065fb72677 Merged in feature/IO-3452-Documents-Adjustments (pull request #2678)
IO-3452 Documents Adjustments

Approved-by: Dave Richer
2025-11-28 15:49:40 +00:00
Allan Carr
ddc6141480 IO-3452 Documents Adjustments
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-11-27 13:15:26 -08:00
Dave
fa7da3cad0 feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration / Merges and adjustments 2025-11-26 15:37:34 -05:00
Patrick Fic
f1bad01cec Fortellis certification updates. 2025-11-26 11:09:37 -08:00
Dave
3d6498f938 Merge remote-tracking branch 'origin/release/2025-12-05' into feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration 2025-11-26 11:30:33 -05:00
Allan Carr
7bc137fa79 Merged in feature/IO-3450-Additional-Crisp-Segments (pull request #2675)
Feature/IO-3450 Additional Crisp Segments

Approved-by: Dave Richer
2025-11-26 16:30:07 +00:00
Allan Carr
dafe9de753 IO-3450 Grammer Correction
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-11-25 18:10:10 -08:00
Allan Carr
78a8474a24 IO-3450 Additional Crisp Segments
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-11-25 17:56:19 -08:00
Dave Richer
123066f1cd Merged in release/2025-11-21 (pull request #2671)
Release/2025 11 21 into Master-AIO - IO-3435 IO-3445 IO-3440 IO-3446
2025-11-21 19:19:15 +00:00
Allan Carr
a153cca3c0 Merged in feature/IO-3440-Payment-By-Date-Excel (pull request #2669)
IO-3440 Payment By Date - Excel
2025-11-21 00:26:54 +00:00
Allan Carr
35c7c32c8e IO-3440 Payment By Date - Excel
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-11-20 16:29:05 -08:00
40 changed files with 2444 additions and 1292 deletions

View File

@@ -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)
- `timezone` (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.
@@ -50,12 +50,7 @@ Content-Type: application/json
"email": "shop@example.com",
"timezone": "America/Chicago",
"phone": "555-123-4567",
"logo_img_path": {
"src": "https://example.com/logo.png",
"width": "200",
"height": "100",
"headerMargin": 10
}
"logo_img_path": "https://example.com/logo.png"
}
```

1075
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@
"private": true,
"proxy": "http://localhost:4000",
"dependencies": {
"@amplitude/analytics-browser": "^2.30.1",
"@amplitude/analytics-browser": "^2.31.3",
"@ant-design/pro-layout": "^7.22.6",
"@apollo/client": "^3.13.9",
"@emotion/is-prop-valid": "^1.4.0",
@@ -19,11 +19,11 @@
"@firebase/firestore": "^4.9.2",
"@firebase/messaging": "^0.12.22",
"@jsreport/browser-client": "^3.1.0",
"@reduxjs/toolkit": "^2.10.1",
"@reduxjs/toolkit": "^2.11.0",
"@sentry/cli": "^2.58.2",
"@sentry/react": "^9.43.0",
"@sentry/vite-plugin": "^4.6.0",
"@splitsoftware/splitio-react": "^2.6.0",
"@sentry/vite-plugin": "^4.6.1",
"@splitsoftware/splitio-react": "^2.6.1",
"@tanem/react-nprogress": "^5.0.56",
"antd": "^5.28.1",
"apollo-link-logger": "^2.0.1",
@@ -33,16 +33,16 @@
"classnames": "^2.5.1",
"css-box-model": "^1.2.1",
"dayjs": "^1.11.19",
"dayjs-business-days2": "^1.3.1",
"dayjs-business-days2": "^1.3.2",
"dinero.js": "^1.9.1",
"dotenv": "^17.2.3",
"env-cmd": "^10.1.0",
"exifr": "^7.1.3",
"graphql": "^16.12.0",
"i18next": "^25.6.2",
"i18next": "^25.7.1",
"i18next-browser-languagedetector": "^8.2.0",
"immutability-helper": "^3.1.1",
"libphonenumber-js": "^1.12.26",
"libphonenumber-js": "^1.12.31",
"lightningcss": "^1.30.2",
"logrocket": "^9.0.2",
"markerjs2": "^2.32.7",
@@ -50,7 +50,7 @@
"normalize-url": "^8.1.0",
"object-hash": "^3.0.0",
"phone": "^3.1.67",
"posthog-js": "^1.294.0",
"posthog-js": "^1.299.0",
"prop-types": "^15.8.1",
"query-string": "^9.3.1",
"raf-schd": "^4.0.3",
@@ -73,7 +73,7 @@
"react-resizable": "^3.0.5",
"react-router-dom": "^6.30.0",
"react-sticky": "^6.0.3",
"react-virtuoso": "^4.14.1",
"react-virtuoso": "^4.16.1",
"recharts": "^2.15.2",
"redux": "^5.0.1",
"redux-actions": "^3.0.3",
@@ -81,7 +81,7 @@
"redux-saga": "^1.4.2",
"redux-state-sync": "^3.1.4",
"reselect": "^5.1.1",
"sass": "^1.94.0",
"sass": "^1.94.2",
"socket.io-client": "^4.8.1",
"styled-components": "^6.1.19",
"subscriptions-transport-ws": "^0.11.0",
@@ -140,8 +140,8 @@
"@emotion/babel-plugin": "^11.13.5",
"@emotion/react": "^11.14.0",
"@eslint/js": "^9.39.1",
"@playwright/test": "^1.56.1",
"@sentry/webpack-plugin": "^4.6.0",
"@playwright/test": "^1.57.0",
"@sentry/webpack-plugin": "^4.6.1",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.0",
@@ -153,19 +153,19 @@
"eslint-plugin-react": "^7.37.5",
"globals": "^15.15.0",
"jsdom": "^26.0.0",
"memfs": "^4.51.0",
"memfs": "^4.51.1",
"os-browserify": "^0.3.0",
"playwright": "^1.56.1",
"playwright": "^1.57.0",
"react-error-overlay": "^6.1.0",
"redux-logger": "^3.0.6",
"source-map-explorer": "^2.5.3",
"vite": "^7.2.2",
"vite": "^7.2.6",
"vite-plugin-babel": "^1.3.2",
"vite-plugin-eslint": "^1.8.1",
"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",
"vitest": "^3.2.4",
"workbox-window": "^7.3.0"
"workbox-window": "^7.4.0"
}
}

View File

@@ -142,17 +142,37 @@ export default function JobLifecycleDashboardComponent({ data, bodyshop, ...card
title={t("job_lifecycle.content.legend_title")}
style={{ marginTop: "10px" }}
>
<div>
<div
style={{
display: "flex",
flexWrap: "wrap",
gap: 8
}}
>
{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
aria-label={`${key.status} | ${key.roundedPercentage} | ${key.humanReadable}`}
title={`${key.status} | ${key.roundedPercentage} | ${key.humanReadable}`}
style={{
backgroundColor: "var(--tag-wrapper-bg)",
color: "var(--tag-wrapper-text)",
padding: "4px",
textAlign: "center"
padding: "4px 8px",
textAlign: "center",
whiteSpace: "nowrap" // keep it on one line while letting the pill expand
}}
>
{key.status} [{lifecycleData.statusCounts[key.status]}] ({key.roundedPercentage})

View File

@@ -24,10 +24,11 @@ export default connect(mapStateToProps, mapDispatchToProps)(DmsAllocationsSummar
* @param bodyshop
* @param jobId
* @param title
* @param onAllocationsChange
* @returns {JSX.Element}
* @constructor
*/
export function DmsAllocationsSummary({ mode, socket, bodyshop, jobId, title }) {
export function DmsAllocationsSummary({ mode, socket, bodyshop, jobId, title, onAllocationsChange }) {
const { t } = useTranslation();
const [allocationsSummary, setAllocationsSummary] = useState([]);
@@ -48,11 +49,17 @@ export function DmsAllocationsSummary({ mode, socket, bodyshop, jobId, title })
setAllocationsSummary(list);
// Preserve side-channel used by the post form for discrepancy checks
socket.allocationsSummary = list;
if (onAllocationsChange) onAllocationsChange(list);
});
} catch {
// Best-effort; leave table empty on error
setAllocationsSummary([]);
socket && (socket.allocationsSummary = []);
if (socket) {
socket.allocationsSummary = [];
}
if (onAllocationsChange) {
onAllocationsChange([]);
}
}
}, [socket, jobId, mode, allocationsEvent]);

View File

@@ -4,6 +4,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { resolveRROpCodeFromBodyshop } from "../../utils/dmsUtils.js";
import { selectBodyshop } from "../../redux/user/user.selectors";
@@ -17,7 +18,21 @@ export default connect(mapStateToProps, mapDispatchToProps)(RrAllocationsSummary
/**
* Normalize job allocations into a flat list for display / preview building.
* @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) {
if (!ack || !Array.isArray(ack.jobAllocations)) return [];
@@ -30,9 +45,13 @@ function normalizeJobAllocations(ack) {
// bucketed sales used to build split ROGOG/ROLABOR
partsSale: row.partsSale || null,
partsTaxableSale: row.partsTaxableSale || null,
partsNonTaxableSale: row.partsNonTaxableSale || null,
laborTaxableSale: row.laborTaxableSale || null,
laborNonTaxableSale: row.laborNonTaxableSale || null,
extrasSale: row.extrasSale || null,
extrasTaxableSale: row.extrasTaxableSale || null,
extrasNonTaxableSale: row.extrasNonTaxableSale || null,
cost: row.cost || null,
profitCenter: row.profitCenter || null,
@@ -50,17 +69,20 @@ function normalizeJobAllocations(ack) {
* is now done on the backend via buildRogogFromAllocations/buildRolaborFromRogog.
* This component just renders the preview from `ack.rogg` / `ack.rolabor`.
*/
export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
export function RrAllocationsSummary({ socket, bodyshop, jobId, title, onAllocationsChange, opCode }) {
const { t } = useTranslation();
const [roggPreview, setRoggPreview] = useState(null);
const [rolaborPreview, setRolaborPreview] = useState(null);
const [error, setError] = useState(null);
// Prefer the user-selected OpCode (from DmsContainer), fall back to config default
const effectiveOpCode = useMemo(() => opCode || resolveRROpCodeFromBodyshop(bodyshop), [opCode, bodyshop]);
const fetchAllocations = useCallback(() => {
if (!socket || !jobId) return;
try {
socket.emit("rr-calculate-allocations", jobId, (ack) => {
socket.emit("rr-calculate-allocations", { jobId, opCode: effectiveOpCode }, (ack) => {
if (ack && ack.ok === false) {
setRoggPreview(null);
setRolaborPreview(null);
@@ -69,6 +91,9 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
socket.allocationsSummary = [];
socket.rrAllocationsRaw = ack;
}
if (onAllocationsChange) {
onAllocationsChange([]);
}
return;
}
@@ -82,6 +107,9 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
socket.allocationsSummary = jobAllocRows;
socket.rrAllocationsRaw = ack;
}
if (onAllocationsChange) {
onAllocationsChange(jobAllocRows);
}
});
} catch {
setRoggPreview(null);
@@ -90,25 +118,32 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
if (socket) {
socket.allocationsSummary = [];
}
if (onAllocationsChange) {
onAllocationsChange([]);
}
}
}, [socket, jobId, t]);
}, [socket, jobId, t, onAllocationsChange, effectiveOpCode]);
useEffect(() => {
fetchAllocations();
}, [fetchAllocations]);
const opCode = bodyshop?.rr_configuration?.baseOpCode || "28TOZ";
const segmentLabelMap = {
partsExtras: "Parts/Extras",
laborTaxable: "Taxable Labor",
laborNonTaxable: "Non-Taxable Labor"
partsTaxable: "Parts Taxable",
partsNonTaxable: "Parts Non-Taxable",
extrasTaxable: "Extras Taxable",
extrasNonTaxable: "Extras Non-Taxable",
laborTaxable: "Labor Taxable",
laborNonTaxable: "Labor Non-Taxable"
};
const roggRows = useMemo(() => {
if (!roggPreview || !Array.isArray(roggPreview.ops)) return [];
const rows = [];
roggPreview.ops.forEach((op) => {
const rowOpCode = opCode || op.opCode;
(op.lines || []).forEach((line, idx) => {
const baseDesc = line.itemDesc;
const segmentKind = op.segmentKind;
@@ -118,7 +153,7 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
rows.push({
key: `${op.jobNo}-${idx}`,
opCode: op.opCode,
opCode: rowOpCode,
jobNo: op.jobNo,
breakOut: line.breakOut,
itemType: line.itemType,
@@ -135,22 +170,27 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
});
});
return rows;
}, [roggPreview]);
}, [roggPreview, opCode, segmentLabelMap]);
const rolaborRows = useMemo(() => {
if (!rolaborPreview || !Array.isArray(rolaborPreview.ops)) return [];
return rolaborPreview.ops.map((op, idx) => ({
key: `${op.jobNo}-${idx}`,
opCode: op.opCode,
jobNo: op.jobNo,
custPayTypeFlag: op.custPayTypeFlag,
custTxblNtxblFlag: op.custTxblNtxblFlag,
payType: op.bill?.payType,
amtType: op.amount?.amtType,
custPrice: op.amount?.custPrice,
totalAmt: op.amount?.totalAmt
}));
}, [rolaborPreview]);
return rolaborPreview.ops.map((op, idx) => {
const rowOpCode = opCode || op.opCode;
return {
key: `${op.jobNo}-${idx}`,
opCode: rowOpCode,
jobNo: op.jobNo,
custPayTypeFlag: op.custPayTypeFlag,
custTxblNtxblFlag: op.custTxblNtxblFlag,
payType: op.bill?.payType,
amtType: op.amount?.amtType,
custPrice: op.amount?.custPrice,
totalAmt: op.amount?.totalAmt
};
});
}, [rolaborPreview, opCode]);
// Totals for ROGOG (sum custPrice + dlrCost over all lines)
const roggTotals = useMemo(() => {
@@ -211,9 +251,11 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title }) {
children: (
<>
<Typography.Paragraph type="secondary" style={{ marginBottom: 8 }}>
OpCode: <strong>{opCode}</strong>. Only centers with RR GOG mapping (rr_gogcode &amp; rr_item_type) are
included. Totals below reflect exactly what will be sent in ROGOG.
OpCode: <strong>{effectiveOpCode}</strong>. Only centers with RR GOG mapping (rr_gogcode &amp; rr_item_type)
are included. Totals below reflect exactly what will be sent in ROGOG, with parts, extras, and labor split
into taxable / non-taxable segments.
</Typography.Paragraph>
<Table
pagination={false}
columns={roggColumns}

View File

@@ -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 CurrencyInput from "../form-items-formatted/currency-form-item.component";
import { DMS_MAP } from "../../utils/dmsUtils";
import { useSplitTreatments } from "@splitsoftware/splitio-react";
/**
* CDK-like DMS post form:
@@ -38,14 +39,23 @@ import { DMS_MAP } from "../../utils/dmsUtils";
* @param job
* @param logsRef
* @param mode
* @param allocationsSummary
* @returns {JSX.Element}
* @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 { t } = useTranslation();
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(
() => ({
story: `${t("jobs.labels.dms.defaultstory", {
@@ -111,15 +121,19 @@ export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode }
};
// Totals & discrepancy
const totals = socket?.allocationsSummary
? socket.allocationsSummary.reduce(
(acc, val) => ({
totalSale: acc.totalSale.add(Dinero(val.sale)),
totalCost: acc.totalCost.add(Dinero(val.cost))
}),
{ totalSale: Dinero(), totalCost: Dinero() }
)
: { totalSale: Dinero(), totalCost: Dinero() };
const totals = useMemo(() => {
if (!allocationsSummary || allocationsSummary.length === 0) {
return { totalSale: Dinero(), totalCost: Dinero() };
}
return allocationsSummary.reduce(
(acc, val) => ({
totalSale: acc.totalSale.add(Dinero(val.sale)),
totalCost: acc.totalCost.add(Dinero(val.cost))
}),
{ totalSale: Dinero(), totalCost: Dinero() }
);
}, [allocationsSummary]);
return (
<Card title={t("jobs.labels.dms.postingform")}>
@@ -205,7 +219,7 @@ export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode }
<Row gutter={[16, 12]}>
<Col span={24}>
<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>
</Col>
</Row>
@@ -373,7 +387,10 @@ export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode }
const payersOk =
payers.length > 0 &&
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;
return (

View File

@@ -19,20 +19,55 @@ export default connect(mapStateToProps, mapDispatchToProps)(DmsPostForm);
* @param socket
* @param job
* @param logsRef
* @param key
* @param allocationsSummary
* @param rrOpCodeParts
* @param onChangeRrOpCodeParts
* @returns {JSX.Element|null}
* @constructor
*/
export function DmsPostForm({ mode, bodyshop, socket, job, logsRef }) {
export function DmsPostForm({
mode,
bodyshop,
socket,
job,
logsRef,
key,
allocationsSummary,
rrOpCodeParts,
onChangeRrOpCodeParts
}) {
switch (mode) {
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;
// we pass mode down so the child can choose the correct event name.
case DMS_MAP.fortellis:
case DMS_MAP.cdk:
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:
return null;

View File

@@ -1,4 +1,4 @@
import { ReloadOutlined } from "@ant-design/icons";
import { ReloadOutlined, RollbackOutlined } from "@ant-design/icons";
import {
Button,
Card,
@@ -26,19 +26,36 @@ import dayjs from "../../utils/day";
* @param socket
* @param job
* @param logsRef
* @param allocationsSummary
* @param opCodeParts // { prefix, base, suffix } from container
* @param onChangeOpCodeParts // (partsWithFlags) => void
* @returns {JSX.Element}
* @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 { 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
const [advisors, setAdvisors] = useState([]);
const [advLoading, setAdvLoading] = useState(false);
const getAdvisorNumber = (a) => a?.advisorId;
const getAdvisorLabel = (a) => `${a?.firstName || ""} ${a?.lastName || ""}`.trim();
const fetchRrAdvisors = (refresh = false) => {
@@ -97,32 +114,99 @@ export default function RRPostForm({ bodyshop, socket, job, logsRef }) {
: job.v_model_yr)) ||
2019
}-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) => {
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", {
bodyshopId: bodyshop?.id,
jobId: job.id,
job,
txEnvelope: values
txEnvelope
});
logsRef?.current?.scrollIntoView({ behavior: "smooth" });
};
// Discrepancy is ignored for RR; we still show totals for operator context
const totals = socket?.allocationsSummary
? socket.allocationsSummary.reduce(
(acc, val) => ({
totalSale: acc.totalSale.add(Dinero(val.sale)),
totalCost: acc.totalCost.add(Dinero(val.cost))
}),
{ totalSale: Dinero(), totalCost: Dinero() }
)
: { totalSale: Dinero(), totalCost: Dinero() };
// Discrepancy is ignored for RR; we still show totals for operator context.
// Use the lifted allocationsSummary from the container instead of reading from the socket.
const totals = useMemo(() => {
if (!allocationsSummary || allocationsSummary.length === 0) {
return { totalSale: Dinero(), totalCost: Dinero() };
}
return allocationsSummary.reduce(
(acc, val) => ({
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 (
<Card title={t("jobs.labels.dms.postingform")}>
@@ -171,10 +255,57 @@ export default function RRPostForm({ bodyshop, socket, job, logsRef }) {
</Form.Item>
</Col>
{/* Make Override */}
{/* RR OpCode (prefix / base / suffix) */}
<Col xs={24} sm={12} md={12} lg={8}>
<Form.Item name="makeOverride" label={t("jobs.fields.dms.make_override")}>
<Input allowClear placeholder={t("general.actions.optional")} />
<Form.Item
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>
</Col>

View File

@@ -222,17 +222,37 @@ export function JobLifecycleComponent({ bodyshop, job, statuses }) {
</div>
</BlurWrapperComponent>
<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) => (
<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
aria-label={`${key.status} | ${key.roundedPercentage} | ${key.humanReadable}`}
title={`${key.status} | ${key.roundedPercentage} | ${key.humanReadable}`}
style={{
backgroundColor: "var(--tag-wrapper-bg)",
color: "var(--tag-wrapper-text)",
padding: "4px",
textAlign: "center"
padding: "4px 8px",
textAlign: "center",
whiteSpace: "nowrap" // single line; tag gets wider instead of text escaping
}}
>
{key.status} (

View File

@@ -35,16 +35,14 @@ export function JobsDocumentsImgproxyDownloadButton({ galleryImages, identifier,
...galleryImages.other.filter((image) => image.isSelected)
];
function downloadProgress(progressEvent) {
setDownload((currentDownloadState) => {
return {
downloaded: progressEvent.loaded || 0,
speed: (progressEvent.loaded || 0) - ((currentDownloadState && currentDownloadState.downloaded) || 0)
};
});
}
const downloadProgress = ({ loaded }) => {
setDownload((currentDownloadState) => ({
downloaded: loaded ?? 0,
speed: (loaded ?? 0) - (currentDownloadState?.downloaded ?? 0)
}));
};
function standardMediaDownload(bufferData) {
const standardMediaDownload = (bufferData) => {
try {
const a = document.createElement("a");
const url = window.URL.createObjectURL(new Blob([bufferData]));
@@ -55,29 +53,26 @@ export function JobsDocumentsImgproxyDownloadButton({ galleryImages, identifier,
setLoading(false);
setDownload(null);
}
}
};
const handleDownload = async () => {
logImEXEvent("jobs_documents_download");
setLoading(true);
try {
const response = await axios({
const { data } = await axios({
url: "/media/imgproxy/download",
method: "POST",
responseType: "blob",
data: { jobId, documentids: imagesToDownload.map((_) => _.id) },
onDownloadProgress: downloadProgress
});
setLoading(false);
setDownload(null);
// Use the response data (Blob) to trigger download
standardMediaDownload(response.data);
standardMediaDownload(data);
} catch {
// handle error (optional)
} finally {
setLoading(false);
setDownload(null);
// handle error (optional)
}
};

View File

@@ -76,14 +76,14 @@ function JobsDocumentsImgproxyComponent({
<SyncOutlined />
</Button>
<JobsDocumentsGallerySelectAllComponent galleryImages={galleryImages} setGalleryImages={setGalleryImages} />
{!billId && (
<JobsDocumentsGalleryReassign galleryImages={galleryImages} callback={fetchThumbnails || refetch} />
)}
<JobsDocumentsDownloadButton galleryImages={galleryImages} identifier={downloadIdentifier} jobId={jobId} />
<JobsDocumentsDeleteButton
galleryImages={galleryImages}
deletionCallback={billsCallback || fetchThumbnails || refetch}
/>
{!billId && (
<JobsDocumentsGalleryReassign galleryImages={galleryImages} callback={fetchThumbnails || refetch} />
)}
</Space>
</Col>
{!hasMediaAccess && (

View File

@@ -67,7 +67,7 @@ export default function JobsDocumentsImgproxyDeleteButton({ galleryImages, delet
okButtonProps={{ danger: true }}
cancelText={t("general.actions.cancel")}
>
<Button disabled={imagesToDelete.length < 1} loading={loading}>
<Button danger disabled={imagesToDelete.length < 1} loading={loading}>
{t("documents.actions.delete")}
</Button>
</Popconfirm>

View File

@@ -107,8 +107,8 @@ export function JobsDocumentsLocalGallery({
<a href={CreateExplorerLinkForJob({ jobid: job.id })}>
<Button>{t("documents.labels.openinexplorer")}</Button>
</a>
<JobsDocumentsLocalGalleryReassign jobid={job.id} />
<JobsDocumentsLocalGallerySelectAllComponent jobid={job.id} />
<JobsDocumentsLocalGalleryReassign jobid={job.id} />
<JobsLocalGalleryDownloadButton job={job} />
<JobsDocumentsLocalDeleteButton jobid={job.id} />
</Space>

View File

@@ -28,6 +28,8 @@ export function JobsDocumentsLocalDeleteButton({ bodyshop, getJobMedia, allMedia
const [loading, setLoading] = useState(false);
const imagesToDelete = (allMedia?.[jobid] || []).filter((i) => i.isSelected);
const handleDelete = async () => {
logImEXEvent("job_documents_delete");
setLoading(true);
@@ -36,7 +38,7 @@ export function JobsDocumentsLocalDeleteButton({ bodyshop, getJobMedia, allMedia
`${bodyshop.localmediaserverhttp}/jobs/delete`,
{
jobid: jobid,
files: (allMedia?.[jobid] || []).filter((i) => i.isSelected).map((i) => i.filename)
files: imagesToDelete.map((i) => i.filename)
},
{ headers: { ims_token: bodyshop.localmediatoken } }
);
@@ -60,14 +62,17 @@ export function JobsDocumentsLocalDeleteButton({ bodyshop, getJobMedia, allMedia
return (
<Popconfirm
disabled={imagesToDelete.length < 1}
icon={<QuestionCircleOutlined style={{ color: "red" }} />}
onConfirm={handleDelete}
title={t("documents.labels.confirmdelete")}
okText={t("general.actions.delete")}
okButtonProps={{ type: "danger" }}
okButtonProps={{ danger: true }}
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>
);
}

View File

@@ -1,8 +1,8 @@
import { Button } from "antd";
import { Button, Space } from "antd";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import cleanAxios from "../../utils/CleanAxios";
import formatBytes from "../../utils/formatbytes";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectAllMedia } from "../../redux/media/media.selectors";
@@ -19,45 +19,63 @@ export default connect(mapStateToProps, mapDispatchToProps)(JobsLocalGalleryDown
export function JobsLocalGalleryDownloadButton({ bodyshop, allMedia, job }) {
const { t } = useTranslation();
const [download, setDownload] = useState(null);
const [loading, setLoading] = useState(false);
const [download, setDownload] = useState(false);
function downloadProgress(progressEvent) {
setDownload((currentDownloadState) => {
return {
downloaded: progressEvent.loaded || 0,
speed: (progressEvent.loaded || 0) - (currentDownloadState?.downloaded || 0)
};
});
}
const imagesToDownload = (allMedia?.[job.id] || []).filter((i) => i.isSelected);
const downloadProgress = ({ loaded }) => {
setDownload((currentDownloadState) => ({
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 theDownloadedZip = await cleanAxios.post(
`${bodyshop.localmediaserverhttp}/jobs/download`,
{
jobid: job.id,
files: (allMedia?.[job.id] || []).filter((i) => i.isSelected).map((i) => i.filename)
},
{
headers: { ims_token: bodyshop.localmediatoken },
responseType: "arraybuffer",
onDownloadProgress: downloadProgress
}
);
setDownload(null);
standardMediaDownload(theDownloadedZip.data, job.ro_number);
const { localmediaserverhttp, localmediatoken } = bodyshop;
const { id, ro_number } = job;
setLoading(true);
try {
const response = await cleanAxios.post(
`${localmediaserverhttp}/jobs/download`,
{
jobid: id,
files: imagesToDownload.map((i) => i.filename)
},
{
headers: { ims_token: localmediatoken },
responseType: "arraybuffer",
onDownloadProgress: downloadProgress
}
);
standardMediaDownload(response.data, ro_number);
} catch {
// handle error (optional)
} finally {
setLoading(false);
setDownload(null);
}
};
return (
<Button loading={!!download} onClick={handleDownload}>
{t("documents.actions.download")}
<Button disabled={imagesToDownload < 1} loading={download || loading} onClick={handleDownload}>
<Space>
<span>{t("documents.actions.download")}</span>
{download && <span>{`(${formatBytes(download.downloaded)} @ ${formatBytes(download.speed)} / second)`}</span>}
</Space>
</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();
}

View File

@@ -322,7 +322,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
<Input onBlur={handleBlur} />
</Form.Item>
{hasDMSKey && (
{hasDMSKey && !bodyshop.rr_dealerid && (
<>
<Form.Item
label={t("bodyshop.fields.dms.dms_acctnumber")}
@@ -408,23 +408,25 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
>
<Input onBlur={handleBlur} />
</Form.Item>
<Form.Item
label={t("bodyshop.fields.responsibilitycenter_accountitem")}
key={`${index}accountitem`}
name={[field.name, "accountitem"]}
rules={[{ required: true }]}
>
<Input onBlur={handleBlur} />
</Form.Item>
{hasDMSKey && (
<Form.Item
label={t("bodyshop.fields.dms.dms_acctnumber")}
key={`${index}dms_acctnumber`}
name={[field.name, "dms_acctnumber"]}
rules={[{ required: true }]}
>
<Input onBlur={handleBlur} />
</Form.Item>
{hasDMSKey && !bodyshop.rr_dealerid && (
<>
<Form.Item
label={t("bodyshop.fields.responsibilitycenter_accountitem")}
key={`${index}accountitem`}
name={[field.name, "accountitem"]}
rules={[{ required: true }]}
>
<Input onBlur={handleBlur} />
</Form.Item>
<Form.Item
label={t("bodyshop.fields.dms.dms_acctnumber")}
key={`${index}dms_acctnumber`}
name={[field.name, "dms_acctnumber"]}
rules={[{ required: true }]}
>
<Input onBlur={handleBlur} />
</Form.Item>
</>
)}
{bodyshop.cdk_dealerid && (
<Form.Item

View File

@@ -16,7 +16,7 @@ const mapDispatchToProps = () => ({
export function TechHeader({ technician }) {
const { t } = useTranslation();
return (
<Header style={{ textAlign: "center" }}>
<Header style={{ textAlign: "center", height: "auto", overflow: "visible" }}>
<Typography.Title style={{ color: "#fff" }}>
{technician
? t("tech.labels.loggedin", {

View File

@@ -1,5 +1,5 @@
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 { useState } from "react";
import { useTranslation } from "react-i18next";
@@ -130,102 +130,12 @@ export function TechClockOffButton({
cost_center: isShiftTicket ? "timetickets.labels.shift" : technician ? technician.cost_center : null
}}
>
<Row gutter={[16, 16]}>
<Col span={!isShiftTicket ? 8 : 24}>
{!isShiftTicket ? (
<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>
) : (
<Space direction="vertical">
{!isShiftTicket ? (
<div>
<Form.Item
name="status"
label={t("jobs.fields.status")}
initialValue={lineTicketData && lineTicketData.jobs_by_pk.status}
label={t("timetickets.fields.actualhrs")}
name="actualhrs"
rules={[
{
required: true
@@ -233,35 +143,121 @@ export function TechClockOffButton({
}
]}
>
<Select>
{bodyshop.md_ro_statuses.production_statuses.map((item) => (
<Select.Option key={item}></Select.Option>
))}
</Select>
<InputNumber min={0} precision={1} />
</Form.Item>
)}
<Button type="primary" htmlType="submit" loading={loading}>
{t("general.actions.save")}
</Button>
<TechJobClockoutDelete completedCallback={completedCallback} timeTicketId={timeTicketId} />
</Col>
{!isShiftTicket && (
<Col span={16}>
<LaborAllocationContainer
jobid={jobId || null}
loading={queryLoading}
lineTicketData={lineTicketData}
/>
</Col>
<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
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>
</div>
</Card>
);
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}>
{t("timetickets.actions.clockout")}
</Button>

View File

@@ -66,15 +66,6 @@ const DMS_SOCKET_EVENTS = {
};
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 {
treatments: { Fortellis }
} = useSplitTreatments({
@@ -83,10 +74,46 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
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
const mode = getDmsMode(bodyshop, Fortellis.treatment); // "rr" | "fortellis" | "cdk" | "pbs" | "none"
// RR-only: derive default OpCode parts from bodyshop RR configuration
const isRrMode = mode === DMS_MAP.reynolds;
const deriveDefaultRrOpCodeParts = () => {
if (!isRrMode) return null;
const cfg = bodyshop?.rr_configuration || {};
// Adjust these paths to match your real schema.
const defaults =
cfg.opCodeDefault ||
cfg.op_code_default ||
cfg.op_codes?.default ||
cfg.defaults?.opCode ||
cfg.defaults ||
cfg.default ||
{};
const prefix = defaults.prefix ?? defaults.opCodePrefix ?? "";
const base = defaults.base ?? defaults.opCodeBase ?? "";
const suffix = defaults.suffix ?? defaults.opCodeSuffix ?? "";
return { prefix, base, suffix };
};
const [rrOpCodeParts, setRrOpCodeParts] = useState(() => deriveDefaultRrOpCodeParts());
const history = useNavigate();
const search = queryString.parse(useLocation().search);
const { jobId } = search;
const notification = useNotification();
const { socket: wsssocket } = useSocket();
const 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
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) => {
if (!activeSocket) return;
activeSocket.emit("set-log-level", level);
@@ -152,6 +185,10 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
setLogs([]);
setRrOpenRoLimit(false);
setrrValidationPending(false);
setAllocationsSummary(null);
// RR OpCode parts: reset to config defaults when job/mode changes
setRrOpCodeParts(deriveDefaultRrOpCodeParts());
if (!activeSocket) return;
@@ -398,6 +435,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
{!isRrMode ? (
<DmsAllocationsSummary
key={resetKey}
onAllocationsChange={setAllocationsSummary}
title={
<span>
<Link
@@ -415,6 +453,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
) : (
<RrAllocationsSummary
key={resetKey}
onAllocationsChange={setAllocationsSummary}
title={
<span>
<Link to={`/manage/jobs/${data && data.jobs_by_pk.id}`}>
@@ -427,12 +466,22 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
}
socket={activeSocket}
jobId={jobId}
opCode={rrOpCodeCombined}
/>
)}
</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>
<DmsCustomerSelector

View File

@@ -49,8 +49,8 @@ import {
validatePasswordResetSuccess
} from "./user.actions";
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();
@@ -269,11 +269,11 @@ export function* signInSuccessSaga({ payload }) {
instanceSeg,
...(isParts
? [
InstanceRenderManager({
imex: "ImexPartsManagement",
rome: "RomePartsManagement"
})
]
InstanceRenderManager({
imex: "ImexPartsManagement",
rome: "RomePartsManagement"
})
]
: [])
];
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 instanceSeg = InstanceRenderManager({ imex: "imex", rome: "rome" });
let featureSegments;
if (payload.features?.allAccess === true) {
featureSegments = ["allAccess"];
} else {
const featureKeys = Object.keys(payload.features).filter(
(key) =>
payload.features[key] === true ||
(typeof payload.features[key] === "string" && !isNaN(Date.parse(payload.features[key])))
);
featureSegments = ["basic", ...featureKeys];
}
const featureSegments =
payload.features?.allAccess === true
? ["allAccess"]
: [
"basic",
...Object.keys(payload.features).filter(
(key) =>
payload.features[key] === true ||
(typeof payload.features[key] === "string" && !isNaN(Date.parse(payload.features[key])))
)
];
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 segments = [instanceSeg, ...(regionSeg ? [regionSeg] : []), ...featureSegments];

View File

@@ -1221,7 +1221,7 @@ export const TemplateList = (type, context) => {
payments_by_date_excel: {
title: i18n.t("reportcenter.templates.payments_by_date_excel"),
subject: i18n.t("reportcenter.templates.payments_by_date_excel"),
key: "payments_by_date",
key: "payments_by_date_excel",
reporttype: "excel",
disabled: false,
rangeFilter: {

View File

@@ -70,3 +70,26 @@ export const isWssMode = (mode) => {
*/
export const bodyshopHasDmsKey = (bodyshop) =>
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}`;
};

View File

@@ -3698,6 +3698,7 @@
- deliverchecklist
- depreciation_taxes
- dms_allocation
- dms_id
- driveable
- employee_body
- employee_csr
@@ -3975,6 +3976,7 @@
- deliverchecklist
- depreciation_taxes
- dms_allocation
- dms_id
- driveable
- employee_body
- employee_csr
@@ -4264,6 +4266,7 @@
- deliverchecklist
- depreciation_taxes
- dms_allocation
- dms_id
- driveable
- employee_body
- employee_csr

View File

@@ -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;

View File

@@ -0,0 +1,2 @@
alter table "public"."jobs" add column "dms_id" text
null;

857
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -18,14 +18,14 @@
"job-totals-fixtures:local": "docker exec node-app /usr/bin/node /app/download-job-totals-fixtures.js"
},
"dependencies": {
"@aws-sdk/client-cloudwatch-logs": "^3.932.0",
"@aws-sdk/client-elasticache": "^3.932.0",
"@aws-sdk/client-s3": "^3.932.0",
"@aws-sdk/client-secrets-manager": "^3.932.0",
"@aws-sdk/client-ses": "^3.932.0",
"@aws-sdk/credential-provider-node": "^3.932.0",
"@aws-sdk/lib-storage": "^3.932.0",
"@aws-sdk/s3-request-presigner": "^3.932.0",
"@aws-sdk/client-cloudwatch-logs": "^3.943.0",
"@aws-sdk/client-elasticache": "^3.943.0",
"@aws-sdk/client-s3": "^3.943.0",
"@aws-sdk/client-secrets-manager": "^3.943.0",
"@aws-sdk/client-ses": "^3.943.0",
"@aws-sdk/credential-provider-node": "^3.943.0",
"@aws-sdk/lib-storage": "^3.943.0",
"@aws-sdk/s3-request-presigner": "^3.943.0",
"@opensearch-project/opensearch": "^2.13.0",
"@socket.io/admin-ui": "^0.5.1",
"@socket.io/redis-adapter": "^8.3.0",
@@ -34,7 +34,7 @@
"axios": "^1.13.2",
"axios-curlirize": "^2.0.0",
"better-queue": "^3.8.12",
"bullmq": "^5.63.2",
"bullmq": "^5.65.1",
"chart.js": "^4.5.1",
"cloudinary": "^2.8.0",
"compression": "^1.8.1",
@@ -63,19 +63,19 @@
"phone": "^3.1.67",
"query-string": "7.1.3",
"recursive-diff": "^1.0.9",
"rimraf": "^6.1.0",
"rimraf": "^6.1.2",
"skia-canvas": "^3.0.8",
"soap": "^1.6.0",
"socket.io": "^4.8.1",
"socket.io-adapter": "^2.5.5",
"ssh2-sftp-client": "^11.0.0",
"twilio": "^5.10.5",
"twilio": "^5.10.6",
"uuid": "^11.1.0",
"winston": "^3.18.3",
"winston-cloudwatch": "^6.3.0",
"xml-formatter": "^3.6.7",
"xml2js": "^0.6.2",
"xmlbuilder2": "^4.0.0",
"xmlbuilder2": "^4.0.3",
"yazl": "^3.3.1"
},
"devDependencies": {
@@ -85,7 +85,7 @@
"globals": "^15.15.0",
"mock-require": "^3.0.3",
"p-limit": "^3.1.0",
"prettier": "^3.6.2",
"prettier": "^3.7.3",
"supertest": "^7.1.4",
"vitest": "^3.2.4"
}

View File

@@ -136,11 +136,7 @@ async function GetFortellisMakes(req, cdk_dealerid) {
}
});
logger.log("fortellis-replace-makes-models-response", "ERROR", req.user.email, null, {
cdk_dealerid,
xml: result
});
return result.data;
return result.data?.data;
} catch (error) {
logger.log("fortellis-replace-makes-models-error", "ERROR", req.user.email, null, {
cdk_dealerid,
@@ -166,14 +162,17 @@ exports.fortellis = async function ReloadFortellisMakes(req, res) {
//Insert the new ones.
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 {
bodyshopid,
makecode: i.makeCode,
modelcode: i.modelCode,
make: i.makeFullName,
model: i.modelFullName
makecode: i.make,
modelcode: i.model,
make: i.fullMakeName,
model: i.fullModelName
};
})
});

View File

@@ -55,7 +55,9 @@ exports.default = async (req, res) => {
"patrick.fic@convenient-brands.com",
"bradley.rhoades@convenient-brands.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")}`,
text: `

View File

@@ -249,14 +249,14 @@ async function MakeFortellisCall({
socket?.recordid,
{
wsmessage: "",//message,
curl: error.config.curl.curlCommand,
reqid: error.request.headers["Request-Id"] || null,
subscriptionId: error.request.headers["Subscription-Id"] || null,
curl: error?.config.curlCommand,
reqid: error.config?.headers["Request-Id"] || null,
subscriptionId: error.config?.headers["Subscription-Id"] || null,
},
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: {
url: isProduction
? "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",
apiName: "CDK Drive Get Make Model Lite"
},
@@ -384,13 +384,13 @@ const FortellisActions = {
type: "post",
apiName: "CDK Drive Post Accounts GL"
},
TranBatchWip: {
url: isProduction
? "https://api.fortellis.io/cdk/drive/glpost/transBatchWIP"
: "https://api.fortellis.io/cdk-test/drive/glpost/transBatchWIP",
type: "post",
apiName: "CDK Drive Post Accounts GL"
},
// TranBatchWip: {
// url: isProduction
// ? "https://api.fortellis.io/cdk/drive/glpost/transBatchWIP"
// : "https://api.fortellis.io/cdk-test/drive/glpost/transBatchWIP",
// type: "post",
// apiName: "CDK Drive Post Accounts GL"
// },
PostBatchWip: {
url: isProduction
? "https://api.fortellis.io/cdk/drive/glpost/postBatchWIP"

View File

@@ -968,9 +968,9 @@ async function InsertServiceVehicleHistory({ socket, redisHelpers, JobData }) {
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"),
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,
referenceNumber: JobData.bodyshop.cdk_configuration.cashierid
referenceNumber: JobData.ro_number.match(/\d+/g)[0]
}
}
});

View File

@@ -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!){
update_transitions(where:{jobid:{_eq:$jobid}, end:{_is_null:true
}}, _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
}
}`;

View File

@@ -134,13 +134,16 @@ const insertUserAssociation = async (uid, email, shopId) => {
/**
* 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 res
* @returns {Promise<void>}
*/
const patchPartsManagementProvisioning = async (req, res) => {
const { id } = req.params;
// Fields that can be directly patched 1:1
const allowedFields = [
"shopname",
"address1",
@@ -151,31 +154,58 @@ const patchPartsManagementProvisioning = async (req, res) => {
"country",
"email",
"timezone",
"phone",
"logo_img_path"
"phone"
// NOTE: logo_img_path is handled separately via logoUrl
];
const updateFields = {};
// Copy over simple scalar fields if present
for (const field of allowedFields) {
if (req.body[field] !== undefined) {
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) {
return res.status(400).json({ error: "No valid fields provided for update." });
}
// Check that the bodyshop has an external_shop_id before allowing patch
try {
// Fetch the bodyshop by id
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 }
);
if (!shopResp.bodyshops_by_pk?.external_shop_id) {
return res.status(400).json({ error: "Cannot patch: bodyshop does not have an external_shop_id." });
}
} 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 {
const resp = await client.request(UPDATE_BODYSHOP_BY_ID, { id, fields: updateFields });
if (!resp.update_bodyshops_by_pk) {

View File

@@ -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: *[]}}}
*/
const billPostedBuilder = (data) => {
const facing = data?.data?.isinhouse ? "in-house" : "vendor";
const body = `An ${facing} ${data?.data?.is_credit_memo ? "credit memo" : "bill"} has been posted.`.trim();
const facing = data?.data?.isinhouse ? "An In House" : "A Vendor";
const body = `${facing} ${data?.data?.is_credit_memo ? "credit memo" : "bill"} has been posted.`.trim();
return buildNotification(data, "notifications.job.billPosted", body, {
isInHouse: data?.data?.isinhouse,

View File

@@ -1,7 +1,7 @@
/**
* THIS IS A COPY of CDKCalculateAllocations, modified to:
* - 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
*
* Original comments follow.
@@ -49,15 +49,24 @@ const summarizeAllocationsArray = (arr) =>
/**
* Internal per-center bucket shape for *sales*.
* 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() {
const zero = Dinero();
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
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.
* Now stores *buckets* instead of a single Dinero per center.
*/
function buildProfitCenterHash(job, debugLog) {
function buildProfitCenterHash(job, debugLog, taxContext) {
let hasMapaLine = false;
let hasMashLine = false;
@@ -215,6 +435,15 @@ function buildProfitCenterHash(job, debugLog) {
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);
}
@@ -229,7 +458,7 @@ function buildProfitCenterHash(job, debugLog) {
amount: Math.round(rate * 100)
}).multiply(val.mod_lb_hrs);
if (isLaborTaxable(val)) {
if (isLaborTaxable(val, taxContext)) {
bucket.laborTaxableSale = bucket.laborTaxableSale.add(laborAmount);
} else {
bucket.laborNonTaxableSale = bucket.laborNonTaxableSale.add(laborAmount);
@@ -245,9 +474,13 @@ function buildProfitCenterHash(job, debugLog) {
centers: Object.entries(profitCenterHash).map(([center, b]) => ({
center,
parts: summarizeMoney(b.partsSale),
partsTaxable: summarizeMoney(b.partsTaxableSale),
partsNonTaxable: summarizeMoney(b.partsNonTaxableSale),
laborTaxable: summarizeMoney(b.laborTaxableSale),
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,
hasMapaLine,
hasMashLine,
debugLog
debugLog,
taxContext
}) {
// MAPA
// MAPA (paint materials)
if (!hasMapaLine && job.job_totals.rates.mapa.total.amount > 0) {
const mapaAccountName = selectedDmsAllocationConfig.profits.MAPA;
const mapaAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === mapaAccountName);
if (mapaAccount) {
const amount = Dinero(job.job_totals.rates.mapa.total);
const taxable = isMapaTaxable(taxContext);
debugLog("Adding MAPA Line Manually", {
mapaAccountName,
amount: summarizeMoney(Dinero(job.job_totals.rates.mapa.total))
amount: summarizeMoney(amount),
taxable
});
const bucket = ensureCenterBucket(profitCenterHash, mapaAccountName);
bucket.extrasSale = bucket.extrasSale.add(Dinero(job.job_totals.rates.mapa.total));
addExtras(bucket, amount, taxable);
} else {
debugLog("NO MAPA ACCOUNT FOUND!!", { mapaAccountName });
}
}
// MASH
// MASH (shop materials)
if (!hasMashLine && job.job_totals.rates.mash.total.amount > 0) {
const mashAccountName = selectedDmsAllocationConfig.profits.MASH;
const mashAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === mashAccountName);
if (mashAccount) {
const amount = Dinero(job.job_totals.rates.mash.total);
const taxable = isMashTaxable(taxContext);
debugLog("Adding MASH Line Manually", {
mashAccountName,
amount: summarizeMoney(Dinero(job.job_totals.rates.mash.total))
amount: summarizeMoney(amount),
taxable
});
const bucket = ensureCenterBucket(profitCenterHash, mashAccountName);
bucket.extrasSale = bucket.extrasSale.add(Dinero(job.job_totals.rates.mash.total));
addExtras(bucket, amount, taxable);
} else {
debugLog("NO MASH ACCOUNT FOUND!!", { mashAccountName });
}
@@ -440,9 +682,17 @@ function applyMaterialsCosting({ job, bodyshop, selectedDmsAllocationConfig, cos
/**
* 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;
// 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);
if (towAccount) {
const amount = Dinero({
amount: Math.round((job.towing_payable || 0) * 100)
});
const taxable = isTowTaxable(taxContext);
debugLog("Adding towing_payable to TOW account", {
towAccountName,
towing_payable: job.towing_payable
towing_payable: job.towing_payable,
taxable
});
const bucket = ensureCenterBucket(profitCenterHash, towAccountName);
bucket.extrasSale = bucket.extrasSale.add(
Dinero({
amount: Math.round((job.towing_payable || 0) * 100)
})
);
addExtras(bucket, amount, taxable);
} else {
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);
if (towAccount) {
const amount = Dinero({
amount: Math.round((job.storage_payable || 0) * 100)
});
const taxable = isTowTaxable(taxContext);
debugLog("Adding storage_payable to TOW account", {
storageAccountName,
storage_payable: job.storage_payable
storage_payable: job.storage_payable,
taxable
});
const bucket = ensureCenterBucket(profitCenterHash, storageAccountName);
bucket.extrasSale = bucket.extrasSale.add(
Dinero({
amount: Math.round((job.storage_payable || 0) * 100)
})
);
addExtras(bucket, amount, taxable);
} else {
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);
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", {
otherAccountName,
adjustment_bottom_line: job.adjustment_bottom_line
adjustment_bottom_line: job.adjustment_bottom_line,
taxable
});
const bucket = ensureCenterBucket(profitCenterHash, otherAccountName);
bucket.extrasSale = bucket.extrasSale.add(
Dinero({
amount: Math.round((job.adjustment_bottom_line || 0) * 100)
})
);
addExtras(bucket, amount, taxable);
} else {
debugLog("NO PAO ACCOUNT FOUND!!", { otherAccountName });
}
@@ -521,14 +777,6 @@ function applyExtras({ job, bodyshop, selectedDmsAllocationConfig, profitCenterH
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).
* These also feed into the *sales* buckets.
@@ -539,7 +787,8 @@ function applyRomeProfileAdjustments({
selectedDmsAllocationConfig,
profitCenterHash,
debugLog,
connectionData
connectionData,
taxContext
}) {
// Only relevant for Rome instances
if (!InstanceManager({ rome: true })) return profitCenterHash;
@@ -557,6 +806,8 @@ function applyRomeProfileAdjustments({
rateKeys: Object.keys(rateMap)
});
const extrasTaxable = !!(taxContext && taxContext.hasAnyTax);
// Parts adjustments
Object.keys(partsAdjustments).forEach((key) => {
const accountName = selectedDmsAllocationConfig.profits[key];
@@ -566,12 +817,13 @@ function applyRomeProfileAdjustments({
const bucket = ensureCenterBucket(profitCenterHash, accountName);
const adjMoney = Dinero(partsAdjustments[key]);
bucket.extrasSale = bucket.extrasSale.add(adjMoney);
addExtras(bucket, adjMoney, extrasTaxable);
debugLog("Added parts adjustment", {
key,
accountName,
adjustment: summarizeMoney(adjMoney)
adjustment: summarizeMoney(adjMoney),
taxable: extrasTaxable
});
} else {
CreateRRLogEvent(
@@ -600,12 +852,13 @@ function applyRomeProfileAdjustments({
// Note: we intentionally use `rate.adjustments` here to mirror CDK behaviour
const adjMoney = Dinero(rate.adjustments);
bucket.extrasSale = bucket.extrasSale.add(adjMoney);
addExtras(bucket, adjMoney, extrasTaxable);
debugLog("Added rate adjustment", {
key,
accountName,
adjustment: summarizeMoney(adjMoney)
adjustment: summarizeMoney(adjMoney),
taxable: extrasTaxable
});
} else {
CreateRRLogEvent(
@@ -627,9 +880,13 @@ function applyRomeProfileAdjustments({
* {
* center,
* partsSale,
* partsTaxableSale,
* partsNonTaxableSale,
* laborTaxableSale,
* laborNonTaxableSale,
* extrasSale,
* extrasTaxableSale,
* extrasNonTaxableSale,
* totalSale,
* cost,
* profitCenter,
@@ -642,10 +899,8 @@ function buildJobAllocations(bodyshop, profitCenterHash, costCenterHash, debugLo
const jobAllocations = centers.map((center) => {
const bucket = profitCenterHash[center] || emptyCenterBucket();
const totalSale = bucket.partsSale
.add(bucket.laborTaxableSale)
.add(bucket.laborNonTaxableSale)
.add(bucket.extrasSale);
const extrasSale = bucket.extrasSale;
const totalSale = bucket.partsSale.add(bucket.laborTaxableSale).add(bucket.laborNonTaxableSale).add(extrasSale);
const profitCenter = bodyshop.md_responsibility_centers.profits.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 {
center,
// Parts
partsSale: bucket.partsSale,
partsTaxableSale: bucket.partsTaxableSale,
partsNonTaxableSale: bucket.partsNonTaxableSale,
// Labor
laborTaxableSale: bucket.laborTaxableSale,
laborNonTaxableSale: bucket.laborNonTaxableSale,
extrasSale: bucket.extrasSale,
// Extras
extrasSale,
extrasTaxableSale: bucket.extrasTaxableSale,
extrasNonTaxableSale: bucket.extrasNonTaxableSale,
totalSale,
cost: costCenterHash[center] || Dinero(),
@@ -671,9 +936,13 @@ function buildJobAllocations(bodyshop, profitCenterHash, costCenterHash, debugLo
jobAllocations.map((row) => ({
center: row.center,
parts: summarizeMoney(row.partsSale),
partsTaxable: summarizeMoney(row.partsTaxableSale),
partsNonTaxable: summarizeMoney(row.partsNonTaxableSale),
laborTaxable: summarizeMoney(row.laborTaxableSale),
laborNonTaxable: summarizeMoney(row.laborNonTaxableSale),
extras: summarizeMoney(row.extrasSale),
extrasTaxable: summarizeMoney(row.extrasTaxableSale),
extrasNonTaxable: summarizeMoney(row.extrasNonTaxableSale),
totalSale: summarizeMoney(row.totalSale),
cost: summarizeMoney(row.cost)
}))
@@ -781,12 +1050,35 @@ function calculateAllocations(connectionData, job) {
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
let taxAllocations = buildTaxAllocations(bodyshop, job);
debugLog("Initial taxAllocations", summarizeTaxAllocations(taxAllocations));
// 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
const selectedDmsAllocationConfig =
@@ -811,7 +1103,8 @@ function calculateAllocations(connectionData, job) {
profitCenterHash: initialProfitHash,
hasMapaLine,
hasMashLine,
debugLog
debugLog,
taxContext
});
// 6) Materials costing (MAPA/MASH cost side)
@@ -830,7 +1123,8 @@ function calculateAllocations(connectionData, job) {
selectedDmsAllocationConfig,
profitCenterHash,
taxAllocations,
debugLog
debugLog,
taxContext
}));
// 8) Rome-only profile-level adjustments
@@ -840,16 +1134,21 @@ function calculateAllocations(connectionData, job) {
selectedDmsAllocationConfig,
profitCenterHash,
debugLog,
connectionData
connectionData,
taxContext
});
debugLog("profitCenterHash before jobAllocations build", {
centers: Object.entries(profitCenterHash || {}).map(([center, b]) => ({
center,
parts: summarizeMoney(b.partsSale),
partsTaxable: summarizeMoney(b.partsTaxableSale),
partsNonTaxable: summarizeMoney(b.partsNonTaxableSale),
laborTaxable: summarizeMoney(b.laborTaxableSale),
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", {

View File

@@ -3,6 +3,7 @@ const { buildClientAndOpts } = require("./rr-lookup");
const CreateRRLogEvent = require("./rr-logger-event");
const { extractRrResponsibilityCenters } = require("./rr-responsibility-centers");
const CdkCalculateAllocations = require("./rr-calculate-allocations").default;
const { resolveRROpCodeFromBodyshop } = require("./rr-utils");
/**
* 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 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
let rrCentersConfig = null;
let allocations = null;
let opCode = null;
// let taxCode = null;
// 1) Responsibility center config (for visibility / debugging)
try {
@@ -137,19 +142,28 @@ const exportJobToRR = async (args) => {
allocations = [];
}
// 3) OpCode (global, but overridable)
// - 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 resolvedBaseOpCode = resolveRROpCodeFromBodyshop(bodyshop);
const opCodeOverride = txEnvelope?.opCode || txEnvelope?.opcode || txEnvelope?.op_code || null;
let opCodeOverride = txEnvelope?.opCode || txEnvelope?.opcode || txEnvelope?.op_code || null;
if (opCodeOverride || baseOpCode) {
opCode = String(opCodeOverride || baseOpCode).trim() || null;
// If the FE only sends segments, combine them here.
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", {
opCode
opCode,
baseFromConfig: resolvedBaseOpCode,
opPrefix,
opBase,
opSuffix
});
// Build RO payload for create.

View File

@@ -56,32 +56,39 @@ const asN2 = (dineroLike) => {
* Build RO.GOG structure for the reynolds-rome-client `createRepairOrder` payload
* from allocations.
*
* Supports the new allocation shape:
* Supports the allocation shape:
* {
* center,
* partsSale,
* partsTaxableSale,
* partsNonTaxableSale,
* laborTaxableSale,
* laborNonTaxableSale,
* extrasSale,
* extrasTaxableSale,
* extrasNonTaxableSale,
* totalSale,
* cost,
* profitCenter,
* costCenter
* }
*
* For each center, we can emit up to 3 GOG *segments*:
* - parts+extras (uses profitCenter.rr_cust_txbl_flag)
* - taxable labor (CustTxblNTxblFlag="T")
* - non-tax labor (CustTxblNTxblFlag="N")
* For each center, we can emit up to 6 GOG *segments*:
* - taxable parts (CustTxblNTxblFlag="T")
* - non-taxable parts (CustTxblNTxblFlag="N")
* - taxable extras (CustTxblNTxblFlag="T")
* - non-taxable extras (CustTxblNTxblFlag="N")
* - taxable labor (CustTxblNTxblFlag="T")
* - non-taxable labor (CustTxblNTxblFlag="N")
*
* IMPORTANT CHANGE:
* IMPORTANT:
* 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)
* - <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.
*
* @param {Array} allocations
@@ -147,27 +154,53 @@ const buildRogogFromAllocations = (allocations, { opCode, payType = "Cust", roNo
// Only centers configured for RR GOG are included
if (!breakOut || !itemType) continue;
const partsCents = toCents(alloc.partsSale);
const extrasCents = toCents(alloc.extrasSale);
const partsTaxableCents = toCents(alloc.partsTaxableSale);
const partsNonTaxableCents = toCents(alloc.partsNonTaxableSale);
const extrasTaxableCents = toCents(alloc.extrasTaxableSale);
const extrasNonTaxableCents = toCents(alloc.extrasNonTaxableSale);
const laborTaxableCents = toCents(alloc.laborTaxableSale);
const laborNonTaxableCents = toCents(alloc.laborNonTaxableSale);
const costCents = toCents(alloc.cost);
// Parts + extras share a single segment
const partsExtrasCents = partsCents + extrasCents;
const segments = [];
// 1) Parts + extras segment (respect center's default tax flag)
if (partsExtrasCents !== 0) {
// 1) Taxable parts segment -> "T"
if (partsTaxableCents !== 0) {
segments.push({
kind: "partsExtras",
saleCents: partsExtrasCents,
txFlag: pc.rr_cust_txbl_flag || "N"
kind: "partsTaxable",
saleCents: partsTaxableCents,
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) {
segments.push({
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) {
segments.push({
kind: "laborNonTaxable",
@@ -254,6 +287,12 @@ const buildRogogFromAllocations = (allocations, { opCode, payType = "Cust", roNo
/**
* Build RO.ROLABOR structure for the reynolds-rome-client `createRepairOrder` payload
* 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} opts
* @param {string} [opts.payType="Cust"]
@@ -330,10 +369,8 @@ const QueryJobData = async (ctx = {}, jobId) => {
* @param advisorNo
* @param story
* @param makeOverride
* @param bodyshop
* @param allocations
* @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}
*/
const buildRRRepairOrderPayload = ({
@@ -344,7 +381,6 @@ const buildRRRepairOrderPayload = ({
makeOverride,
allocations,
opCode
// taxCode
} = {}) => {
const customerNo = selectedCustomer?.customerNo
? String(selectedCustomer.customerNo).trim()
@@ -395,7 +431,6 @@ const buildRRRepairOrderPayload = ({
if (haveAllocations) {
const effectiveOpCode = (opCode && String(opCode).trim()) || null;
// const effectiveTaxCode = (taxCode && String(taxCode).trim()) || null;
if (effectiveOpCode) {
// Build RO.GOG and RO.LABOR in the new normalized shape

View File

@@ -16,6 +16,7 @@ const {
defaultRRTTL,
RRCacheEnums
} = require("./rr-utils");
const { resolveRROpCodeFromBodyshop } = require("./rr-utils");
const { GraphQLClient } = require("graphql-request");
const queries = require("../graphql-client/queries");
@@ -122,6 +123,47 @@ const getBodyshopForSocket = async ({ bodyshopId, socket }) => {
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
* @param bodyshopId
@@ -607,6 +649,22 @@ const registerRREvents = ({ socket, redisHelpers }) => {
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(
socket.id,
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 {
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: begin", { jobid });
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: begin", { jobid, opCodeFromClient });
const raw = await RRCalculateAllocations(socket, jobid);
@@ -924,16 +999,24 @@ const registerRREvents = ({ socket, redisHelpers }) => {
jobAllocations = Array.isArray(ack.jobAllocations) ? ack.jobAllocations : [];
}
// Try to derive OpCode from bodyshop; fall back to default
let opCode = "28TOZ";
// Start with client-supplied OpCode (if any); fall back to defaults.
let opCode = opCodeFromClient || null;
try {
const { bodyshopId } = await getSessionOrSocket(redisHelpers, socket);
const bodyshop = await getBodyshopForSocket({ bodyshopId, socket });
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) {
CreateRRLogEvent(socket, "WARN", "rr-calculate-allocations: bodyshop lookup failed, using default OpCode", {
error: e.message
CreateRRLogEvent(socket, "WARN", "rr-calculate-allocations: bodyshop lookup failed, using existing OpCode", {
error: e.message,
opCodeFromClient
});
}

View File

@@ -182,6 +182,29 @@ const getTransactionType = (jobid) => `rr:${jobid}`;
*/
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 = {
RRCacheEnums,
defaultRRTTL,
@@ -189,5 +212,6 @@ module.exports = {
ownersFromVinBlocks,
makeVehicleSearchPayloadFromJob,
normalizeCustomerCandidates,
readAdvisorNo
readAdvisorNo,
resolveRROpCodeFromBodyshop
};