Compare commits
53 Commits
rrScratch1
...
rrScratch3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
288c8e6347 | ||
|
|
56738f800c | ||
|
|
bedf4f2c02 | ||
|
|
6032ff0e5d | ||
|
|
77268d5f5b | ||
|
|
1b3abf17ec | ||
|
|
0ef68afa0c | ||
|
|
12b4ae3b8d | ||
|
|
3cfd445894 | ||
|
|
b510eec9aa | ||
|
|
e92bab0455 | ||
|
|
4de3d3c6fc | ||
|
|
e5eac0933f | ||
|
|
a3c71fdfc0 | ||
|
|
a6b3bd573e | ||
|
|
18373fc865 | ||
|
|
3ae8ed8496 | ||
|
|
78750d3d96 | ||
|
|
90edf94fee | ||
|
|
3507e60356 | ||
|
|
43feb16950 | ||
|
|
827f1c2c40 | ||
|
|
58f5ed1ce7 | ||
|
|
c1e3c08652 | ||
|
|
d885bac7d0 | ||
|
|
065fb72677 | ||
|
|
ddc6141480 | ||
|
|
fa7da3cad0 | ||
|
|
f1bad01cec | ||
|
|
3d6498f938 | ||
|
|
7bc137fa79 | ||
|
|
dafe9de753 | ||
|
|
78a8474a24 | ||
|
|
910d388e05 | ||
|
|
9faad53b99 | ||
|
|
3b07055d5a | ||
|
|
ec29a22984 | ||
|
|
2b1836d450 | ||
|
|
ae7d150a6c | ||
|
|
123066f1cd | ||
|
|
b2184a2d11 | ||
|
|
a153cca3c0 | ||
|
|
35c7c32c8e | ||
|
|
9b1c8fa72b | ||
|
|
6d6b64ebc3 | ||
|
|
c954695d3c | ||
|
|
338d8e2136 | ||
|
|
6674206b4f | ||
|
|
c46ad521d1 | ||
|
|
66e5bec4d8 | ||
|
|
0d3161ef84 | ||
|
|
1cd11bdc18 | ||
|
|
9cce2696e2 |
@@ -30,7 +30,7 @@ Send a JSON object with one or more of the following fields to update:
|
||||
- `email` (string, shop's email, not user email)
|
||||
- `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
1075
client/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,6 +425,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
.dms-equal-height-col {
|
||||
display: flex; // make the Col a flex container
|
||||
}
|
||||
|
||||
/* If the direct child is an AntD Card, make it fill the column */
|
||||
.dms-equal-height-col > .ant-card {
|
||||
flex: 1 1 auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* Optional: if you want the card body to fill vertically too */
|
||||
.dms-equal-height-col > .ant-card .ant-card-body {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
//.rbc-time-header-gutter {
|
||||
// padding: 0;
|
||||
//}
|
||||
|
||||
@@ -26,6 +26,7 @@ import { CalculateBillTotal } from "../bill-form/bill-form.totals.utility";
|
||||
import { handleUpload as handleLocalUpload } from "../documents-local-upload/documents-local-upload.utility";
|
||||
import { handleUpload } from "../documents-upload/documents-upload.utility";
|
||||
import { handleUpload as handleUploadToImageProxy } from "../documents-upload-imgproxy/documents-upload-imgproxy.utility";
|
||||
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
billEnterModal: selectBillEnterModal,
|
||||
@@ -450,7 +451,9 @@ function BillEnterModalContainer({ billEnterModal, toggleModalVisible, bodyshop,
|
||||
setEnterAgain(false);
|
||||
}}
|
||||
>
|
||||
<BillFormContainer form={form} disableInvNumber={billEnterModal.context.disableInvNumber} />
|
||||
<RbacWrapper action="bills:enter">
|
||||
<BillFormContainer form={form} disableInvNumber={billEnterModal.context.disableInvNumber} />
|
||||
</RbacWrapper>
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -124,12 +131,14 @@ export function DmsAllocationsSummary({ mode, socket, bodyshop, jobId, title })
|
||||
{ totalSale: Dinero(), totalCost: Dinero() }
|
||||
) || { totalSale: Dinero(), totalCost: Dinero() };
|
||||
|
||||
const hasNonZeroSaleTotal = totals.totalSale.getAmount() !== 0;
|
||||
|
||||
return (
|
||||
<Table.Summary.Row>
|
||||
<Table.Summary.Cell>
|
||||
<Typography.Title level={4}>{t("general.labels.totals")}</Typography.Title>
|
||||
</Table.Summary.Cell>
|
||||
<Table.Summary.Cell>{totals.totalSale.toFormat()}</Table.Summary.Cell>
|
||||
<Table.Summary.Cell>{hasNonZeroSaleTotal ? totals.totalSale.toFormat() : null}</Table.Summary.Cell>
|
||||
<Table.Summary.Cell />
|
||||
<Table.Summary.Cell />
|
||||
<Table.Summary.Cell />
|
||||
|
||||
@@ -0,0 +1,342 @@
|
||||
import { Alert, Button, Card, Table, Tabs, Typography } from "antd";
|
||||
import { SyncOutlined } from "@ant-design/icons";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { resolveRROpCodeFromBodyshop } from "../../utils/dmsUtils.js";
|
||||
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
});
|
||||
const mapDispatchToProps = () => ({});
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(RrAllocationsSummary);
|
||||
|
||||
/**
|
||||
* Normalize job allocations into a flat list for display / preview building.
|
||||
* @param ack
|
||||
* @returns {{
|
||||
* center: *,
|
||||
* sale: *,
|
||||
* partsSale: *,
|
||||
* partsTaxableSale: *,
|
||||
* partsNonTaxableSale: *,
|
||||
* laborTaxableSale: *,
|
||||
* laborNonTaxableSale: *,
|
||||
* extrasSale: *,
|
||||
* extrasTaxableSale: *,
|
||||
* extrasNonTaxableSale: *,
|
||||
* cost: *,
|
||||
* profitCenter: *,
|
||||
* costCenter: *
|
||||
* }[]|*[]}
|
||||
*/
|
||||
function normalizeJobAllocations(ack) {
|
||||
if (!ack || !Array.isArray(ack.jobAllocations)) return [];
|
||||
|
||||
return ack.jobAllocations.map((row) => ({
|
||||
center: row.center,
|
||||
|
||||
// legacy "sale" (total) if we ever want to show it again
|
||||
sale: row.sale || row.totalSale || null,
|
||||
|
||||
// bucketed sales used to build split ROGOG/ROLABOR
|
||||
partsSale: row.partsSale || null,
|
||||
partsTaxableSale: row.partsTaxableSale || null,
|
||||
partsNonTaxableSale: row.partsNonTaxableSale || null,
|
||||
laborTaxableSale: row.laborTaxableSale || null,
|
||||
laborNonTaxableSale: row.laborNonTaxableSale || null,
|
||||
extrasSale: row.extrasSale || null,
|
||||
extrasTaxableSale: row.extrasTaxableSale || null,
|
||||
extrasNonTaxableSale: row.extrasNonTaxableSale || null,
|
||||
|
||||
cost: row.cost || null,
|
||||
profitCenter: row.profitCenter || null,
|
||||
costCenter: row.costCenter || null
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* RR-specific DMS Allocations Summary
|
||||
* Focused on what we actually send to RR:
|
||||
* - ROGOG (split by taxable / non-taxable segments)
|
||||
* - ROLABOR shell
|
||||
*
|
||||
* The heavy lifting (ROGOG/ROLABOR split, cost allocation, tax flags)
|
||||
* is now done on the backend via buildRogogFromAllocations/buildRolaborFromRogog.
|
||||
* This component just renders the preview from `ack.rogg` / `ack.rolabor`.
|
||||
*/
|
||||
export function RrAllocationsSummary({ socket, bodyshop, jobId, title, onAllocationsChange, opCode }) {
|
||||
const { t } = useTranslation();
|
||||
const [roggPreview, setRoggPreview] = useState(null);
|
||||
const [rolaborPreview, setRolaborPreview] = useState(null);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
// Prefer the user-selected OpCode (from DmsContainer), fall back to config default
|
||||
const effectiveOpCode = useMemo(() => opCode || resolveRROpCodeFromBodyshop(bodyshop), [opCode, bodyshop]);
|
||||
|
||||
const fetchAllocations = useCallback(() => {
|
||||
if (!socket || !jobId) return;
|
||||
|
||||
try {
|
||||
socket.emit("rr-calculate-allocations", { jobId, opCode: effectiveOpCode }, (ack) => {
|
||||
if (ack && ack.ok === false) {
|
||||
setRoggPreview(null);
|
||||
setRolaborPreview(null);
|
||||
setError(ack.error || t("dms.labels.allocations_error"));
|
||||
if (socket) {
|
||||
socket.allocationsSummary = [];
|
||||
socket.rrAllocationsRaw = ack;
|
||||
}
|
||||
if (onAllocationsChange) {
|
||||
onAllocationsChange([]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const jobAllocRows = normalizeJobAllocations(ack);
|
||||
|
||||
setRoggPreview(ack?.rogg || null);
|
||||
setRolaborPreview(ack?.rolabor || null);
|
||||
setError(null);
|
||||
|
||||
if (socket) {
|
||||
socket.allocationsSummary = jobAllocRows;
|
||||
socket.rrAllocationsRaw = ack;
|
||||
}
|
||||
if (onAllocationsChange) {
|
||||
onAllocationsChange(jobAllocRows);
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
setRoggPreview(null);
|
||||
setRolaborPreview(null);
|
||||
setError(t("dms.labels.allocations_error"));
|
||||
if (socket) {
|
||||
socket.allocationsSummary = [];
|
||||
}
|
||||
if (onAllocationsChange) {
|
||||
onAllocationsChange([]);
|
||||
}
|
||||
}
|
||||
}, [socket, jobId, t, onAllocationsChange, effectiveOpCode]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchAllocations();
|
||||
}, [fetchAllocations]);
|
||||
|
||||
const segmentLabelMap = {
|
||||
partsTaxable: "Parts Taxable",
|
||||
partsNonTaxable: "Parts Non-Taxable",
|
||||
extrasTaxable: "Extras Taxable",
|
||||
extrasNonTaxable: "Extras Non-Taxable",
|
||||
laborTaxable: "Labor Taxable",
|
||||
laborNonTaxable: "Labor Non-Taxable"
|
||||
};
|
||||
|
||||
const roggRows = useMemo(() => {
|
||||
if (!roggPreview || !Array.isArray(roggPreview.ops)) return [];
|
||||
|
||||
const rows = [];
|
||||
roggPreview.ops.forEach((op) => {
|
||||
const rowOpCode = opCode || op.opCode;
|
||||
|
||||
(op.lines || []).forEach((line, idx) => {
|
||||
const baseDesc = line.itemDesc;
|
||||
const segmentKind = op.segmentKind;
|
||||
const segmentCount = op.segmentCount || 0;
|
||||
const segmentLabel = segmentLabelMap[segmentKind] || segmentKind;
|
||||
const displayDesc = segmentCount > 1 && segmentLabel ? `${baseDesc} (${segmentLabel})` : baseDesc;
|
||||
|
||||
rows.push({
|
||||
key: `${op.jobNo}-${idx}`,
|
||||
opCode: rowOpCode,
|
||||
jobNo: op.jobNo,
|
||||
breakOut: line.breakOut,
|
||||
itemType: line.itemType,
|
||||
itemDesc: displayDesc,
|
||||
custQty: line.custQty,
|
||||
custPayTypeFlag: line.custPayTypeFlag,
|
||||
custTxblNtxblFlag: line.custTxblNtxblFlag,
|
||||
custPrice: line.amount?.custPrice,
|
||||
dlrCost: line.amount?.dlrCost,
|
||||
// segment metadata for visual styling
|
||||
segmentKind,
|
||||
segmentCount
|
||||
});
|
||||
});
|
||||
});
|
||||
return rows;
|
||||
}, [roggPreview, opCode, segmentLabelMap]);
|
||||
|
||||
const rolaborRows = useMemo(() => {
|
||||
if (!rolaborPreview || !Array.isArray(rolaborPreview.ops)) return [];
|
||||
|
||||
return rolaborPreview.ops.map((op, idx) => {
|
||||
const rowOpCode = opCode || op.opCode;
|
||||
|
||||
return {
|
||||
key: `${op.jobNo}-${idx}`,
|
||||
opCode: rowOpCode,
|
||||
jobNo: op.jobNo,
|
||||
custPayTypeFlag: op.custPayTypeFlag,
|
||||
custTxblNtxblFlag: op.custTxblNtxblFlag,
|
||||
payType: op.bill?.payType,
|
||||
amtType: op.amount?.amtType,
|
||||
custPrice: op.amount?.custPrice,
|
||||
totalAmt: op.amount?.totalAmt
|
||||
};
|
||||
});
|
||||
}, [rolaborPreview, opCode]);
|
||||
|
||||
// Totals for ROGOG (sum custPrice + dlrCost over all lines)
|
||||
const roggTotals = useMemo(() => {
|
||||
if (!roggPreview || !Array.isArray(roggPreview.ops)) {
|
||||
return { totalCustPrice: "0.00", totalDlrCost: "0.00" };
|
||||
}
|
||||
|
||||
let totalCustCents = 0;
|
||||
let totalCostCents = 0;
|
||||
|
||||
roggPreview.ops.forEach((op) => {
|
||||
(op.lines || []).forEach((line) => {
|
||||
const cp = parseFloat(line.amount?.custPrice || "0");
|
||||
if (!Number.isNaN(cp)) {
|
||||
totalCustCents += Math.round(cp * 100);
|
||||
}
|
||||
|
||||
const dc = parseFloat(line.amount?.dlrCost || "0");
|
||||
if (!Number.isNaN(dc)) {
|
||||
totalCostCents += Math.round(dc * 100);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
totalCustPrice: (totalCustCents / 100).toFixed(2),
|
||||
totalDlrCost: (totalCostCents / 100).toFixed(2)
|
||||
};
|
||||
}, [roggPreview]);
|
||||
|
||||
const roggColumns = [
|
||||
{ title: "JobNo", dataIndex: "jobNo", key: "jobNo" },
|
||||
{ title: "OpCode", dataIndex: "opCode", key: "opCode" },
|
||||
{ title: "BreakOut", dataIndex: "breakOut", key: "breakOut" },
|
||||
{ title: "ItemType", dataIndex: "itemType", key: "itemType" },
|
||||
{ title: "ItemDesc", dataIndex: "itemDesc", key: "itemDesc" },
|
||||
{ title: "CustQty", dataIndex: "custQty", key: "custQty" },
|
||||
{ title: "CustTxblFlag", dataIndex: "custTxblNtxblFlag", key: "custTxblNtxblFlag" },
|
||||
{ title: "CustPrice", dataIndex: "custPrice", key: "custPrice" },
|
||||
{ title: "DlrCost", dataIndex: "dlrCost", key: "dlrCost" }
|
||||
];
|
||||
|
||||
const rolaborColumns = [
|
||||
{ title: "JobNo", dataIndex: "jobNo", key: "jobNo" },
|
||||
{ title: "OpCode", dataIndex: "opCode", key: "opCode" },
|
||||
{ title: "CustPayType", dataIndex: "custPayTypeFlag", key: "custPayTypeFlag" },
|
||||
{ title: "CustTxblFlag", dataIndex: "custTxblNtxblFlag", key: "custTxblNtxblFlag" },
|
||||
{ title: "PayType", dataIndex: "payType", key: "payType" },
|
||||
{ title: "AmtType", dataIndex: "amtType", key: "amtType" },
|
||||
{ title: "CustPrice", dataIndex: "custPrice", key: "custPrice" },
|
||||
{ title: "TotalAmt", dataIndex: "totalAmt", key: "totalAmt" }
|
||||
];
|
||||
|
||||
const tabItems = [
|
||||
{
|
||||
key: "rogog",
|
||||
label: "ROGOG Preview",
|
||||
children: (
|
||||
<>
|
||||
<Typography.Paragraph type="secondary" style={{ marginBottom: 8 }}>
|
||||
OpCode: <strong>{effectiveOpCode}</strong>. Only centers with RR GOG mapping (rr_gogcode & rr_item_type)
|
||||
are included. Totals below reflect exactly what will be sent in ROGOG, with parts, extras, and labor split
|
||||
into taxable / non-taxable segments.
|
||||
</Typography.Paragraph>
|
||||
|
||||
<Table
|
||||
pagination={false}
|
||||
columns={roggColumns}
|
||||
rowKey="key"
|
||||
dataSource={roggRows}
|
||||
locale={{ emptyText: "No ROGOG lines would be generated." }}
|
||||
scroll={{ x: true }}
|
||||
// 👇 visually highlight splits; especially taxable/non-taxable labor segments
|
||||
rowClassName={(record) => {
|
||||
if (
|
||||
record.segmentCount > 1 &&
|
||||
(record.segmentKind === "laborTaxable" || record.segmentKind === "laborNonTaxable")
|
||||
) {
|
||||
return "rr-allocations-tax-split-row";
|
||||
}
|
||||
if (record.segmentCount > 1) {
|
||||
return "rr-allocations-split-row";
|
||||
}
|
||||
return "";
|
||||
}}
|
||||
summary={() => {
|
||||
const hasCustTotal = Number(roggTotals.totalCustPrice) !== 0;
|
||||
const hasCostTotal = Number(roggTotals.totalDlrCost) !== 0;
|
||||
|
||||
return (
|
||||
<Table.Summary.Row>
|
||||
<Table.Summary.Cell index={0}>
|
||||
<Typography.Title level={5}>{t("general.labels.totals")}</Typography.Title>
|
||||
</Table.Summary.Cell>
|
||||
<Table.Summary.Cell index={1} />
|
||||
<Table.Summary.Cell index={2} />
|
||||
<Table.Summary.Cell index={3} />
|
||||
<Table.Summary.Cell index={4} />
|
||||
<Table.Summary.Cell index={5} />
|
||||
<Table.Summary.Cell index={6} />
|
||||
<Table.Summary.Cell index={7}>{hasCustTotal ? roggTotals.totalCustPrice : null}</Table.Summary.Cell>
|
||||
<Table.Summary.Cell index={8}>{hasCostTotal ? roggTotals.totalDlrCost : null}</Table.Summary.Cell>
|
||||
</Table.Summary.Row>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
},
|
||||
{
|
||||
key: "rolabor",
|
||||
label: "ROLABOR Preview",
|
||||
children: (
|
||||
<>
|
||||
<Typography.Paragraph type="secondary" style={{ marginBottom: 8 }}>
|
||||
This mirrors the shell that would be sent for ROLABOR when all financials are carried in GOG.
|
||||
</Typography.Paragraph>
|
||||
<Table
|
||||
pagination={false}
|
||||
columns={rolaborColumns}
|
||||
rowKey="key"
|
||||
dataSource={rolaborRows}
|
||||
locale={{ emptyText: "No ROLABOR lines would be generated." }}
|
||||
scroll={{ x: true }}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<Card
|
||||
title={title}
|
||||
extra={
|
||||
<Button onClick={fetchAllocations} aria-label={t("general.actions.refresh")}>
|
||||
<SyncOutlined />
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{bodyshop.pbs_configuration?.disablebillwip && (
|
||||
<Alert type="warning" message={t("jobs.labels.dms.disablebillwip")} />
|
||||
)}
|
||||
|
||||
{error && <Alert type="error" style={{ marginTop: 8, marginBottom: 8 }} message={error} />}
|
||||
|
||||
<Tabs defaultActiveKey="rogog" items={tabItems} />
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -13,7 +13,14 @@ const mapDispatchToProps = () => ({});
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsLogEvents);
|
||||
|
||||
export function DmsLogEvents({ logs, detailsOpen, detailsNonce, isDarkMode, colorizeJson = false }) {
|
||||
export function DmsLogEvents({
|
||||
logs,
|
||||
detailsOpen,
|
||||
detailsNonce,
|
||||
isDarkMode,
|
||||
colorizeJson = false,
|
||||
showDetails = true
|
||||
}) {
|
||||
const [openSet, setOpenSet] = useState(() => new Set());
|
||||
|
||||
// Inject JSON highlight styles once (only when colorize is enabled)
|
||||
@@ -54,8 +61,10 @@ export function DmsLogEvents({ logs, detailsOpen, detailsNonce, isDarkMode, colo
|
||||
() =>
|
||||
(logs || []).map((raw, idx) => {
|
||||
const { level, message, timestamp, meta } = normalizeLog(raw);
|
||||
const hasMeta = !isEmpty(meta);
|
||||
const isOpen = openSet.has(idx);
|
||||
|
||||
// Only treat meta as "present" when we are allowed to show details
|
||||
const hasMeta = !isEmpty(meta) && showDetails;
|
||||
const isOpen = hasMeta && openSet.has(idx);
|
||||
|
||||
return {
|
||||
key: idx,
|
||||
@@ -101,7 +110,7 @@ export function DmsLogEvents({ logs, detailsOpen, detailsNonce, isDarkMode, colo
|
||||
)
|
||||
};
|
||||
}),
|
||||
[logs, openSet, colorizeJson]
|
||||
[logs, openSet, colorizeJson, isDarkMode, showDetails]
|
||||
);
|
||||
|
||||
return <Timeline pending reverse items={items} />;
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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} (
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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 && (
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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", {
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -26,6 +26,7 @@ import DmsPostForm from "../../components/dms-post-form/dms-post-form.component"
|
||||
import DmsLogEvents from "../../components/dms-log-events/dms-log-events.component";
|
||||
import DmsCustomerSelector from "../../components/dms-customer-selector/dms-customer-selector.component";
|
||||
import DmsAllocationsSummary from "../../components/dms-allocations-summary/dms-allocations-summary.component";
|
||||
import RrAllocationsSummary from "../../components/dms-allocations-summary/rr-dms-allocations-summary.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
@@ -65,13 +66,6 @@ const DMS_SOCKET_EVENTS = {
|
||||
};
|
||||
|
||||
export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, insertAuditTrail }) {
|
||||
const { t } = useTranslation();
|
||||
const history = useNavigate();
|
||||
const search = queryString.parse(useLocation().search);
|
||||
const { jobId } = search;
|
||||
|
||||
const notification = useNotification();
|
||||
|
||||
const {
|
||||
treatments: { Fortellis }
|
||||
} = useSplitTreatments({
|
||||
@@ -80,9 +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]);
|
||||
|
||||
@@ -91,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);
|
||||
@@ -134,12 +171,51 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
||||
[mode]
|
||||
);
|
||||
|
||||
const transportLabel = isWssMode(mode) ? "App Socket (WSS)" : "Legacy Socket (WS)";
|
||||
const transportLabel = isWssMode(mode) ? "(WSS)" : "(WS)";
|
||||
|
||||
const bannerMessage = `Posting to ${providerLabel} | ${transportLabel} | ${
|
||||
isConnected ? "Connected" : "Disconnected"
|
||||
}`;
|
||||
|
||||
const resetKey = useMemo(() => `${mode || "none"}-${jobId || "none"}`, [mode, jobId]);
|
||||
|
||||
// 🔄 Hard reset of local + server-side DMS context when the page/job loads
|
||||
useEffect(() => {
|
||||
// Clear any local ephemeral state that might be stale
|
||||
setLogs([]);
|
||||
setRrOpenRoLimit(false);
|
||||
setrrValidationPending(false);
|
||||
setAllocationsSummary(null);
|
||||
|
||||
// RR OpCode parts: reset to config defaults when job/mode changes
|
||||
setRrOpCodeParts(deriveDefaultRrOpCodeParts());
|
||||
|
||||
if (!activeSocket) return;
|
||||
|
||||
const emitReset = () => {
|
||||
// Generic reset; server can branch on `mode` if needed
|
||||
activeSocket.emit("dms-reset-context", { jobId, mode });
|
||||
};
|
||||
|
||||
if (activeSocket.connected) {
|
||||
// WSS usually lands here
|
||||
emitReset();
|
||||
return;
|
||||
}
|
||||
|
||||
// Legacy WS: wait for the connect before emitting reset
|
||||
const handleConnectOnce = () => {
|
||||
emitReset();
|
||||
activeSocket.off("connect", handleConnectOnce);
|
||||
};
|
||||
|
||||
activeSocket.on("connect", handleConnectOnce);
|
||||
|
||||
return () => {
|
||||
activeSocket.off("connect", handleConnectOnce);
|
||||
};
|
||||
}, [jobId, mode, activeSocket]);
|
||||
|
||||
const handleExportFailed = (payload = {}) => {
|
||||
const { title, friendlyMessage, error: errText, severity, errorCode, vendorStatusCode } = payload;
|
||||
|
||||
@@ -148,10 +224,10 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
||||
errText ||
|
||||
t("dms.errors.exportfailedgeneric", "We couldn't complete the export. Please try again.");
|
||||
|
||||
const vendorTitle = title || (mode === DMS_MAP.reynolds ? "Reynolds" : "DMS");
|
||||
const vendorTitle = title || (isRrMode ? "Reynolds" : "DMS");
|
||||
|
||||
const isRrOpenRoLimit =
|
||||
mode === DMS_MAP.reynolds &&
|
||||
isRrMode &&
|
||||
(vendorStatusCode === 507 ||
|
||||
/MAX_OPEN_ROS/i.test(String(errorCode || "")) ||
|
||||
/maximum number of open repair orders/i.test(String(msg || "").toLowerCase()));
|
||||
@@ -187,8 +263,8 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
||||
});
|
||||
setSelectedHeader("dms");
|
||||
setBreadcrumbs([
|
||||
{ link: "/manage/accounting/receivables", label: t("titles.bc.accounting-receivables") },
|
||||
{ link: "/manage/dms", label: t("titles.bc.dms") }
|
||||
{ link: "/manage/accounting/receivables", label: t("titles.bc.accounting-receivables") }
|
||||
// { link: "/manage/dms", label: t("titles.bc.dms") }
|
||||
]);
|
||||
}, [t, setBreadcrumbs, setSelectedHeader]);
|
||||
|
||||
@@ -207,6 +283,11 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
||||
const onConnect = () => {
|
||||
setIsConnected(true);
|
||||
setActiveLogLevel(logLevel);
|
||||
|
||||
if (resetAfterReconnect) {
|
||||
activeSocket.emit("dms-reset-context", { jobId, mode });
|
||||
setResetAfterReconnect(false);
|
||||
}
|
||||
};
|
||||
|
||||
const onDisconnect = () => setIsConnected(false);
|
||||
@@ -218,7 +299,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
||||
{
|
||||
timestamp: new Date(),
|
||||
level: "warn",
|
||||
message: `Reconnected to ${mode === DMS_MAP.reynolds ? "RR" : mode === DMS_MAP.fortellis ? "Fortellis" : "DMS"} Export Service`
|
||||
message: `Reconnected to ${isRrMode ? "RR" : mode === DMS_MAP.fortellis ? "Fortellis" : "DMS"} Export Service`
|
||||
}
|
||||
]);
|
||||
};
|
||||
@@ -235,22 +316,17 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
||||
activeSocket.on("connect_error", onConnectError);
|
||||
|
||||
// Logs
|
||||
const onLog =
|
||||
mode === DMS_MAP.reynolds
|
||||
? (payload = {}) => {
|
||||
const normalized = {
|
||||
timestamp: payload.timestamp
|
||||
? new Date(payload.timestamp)
|
||||
: payload.ts
|
||||
? new Date(payload.ts)
|
||||
: new Date(),
|
||||
level: (payload.level || "INFO").toUpperCase(),
|
||||
message: payload.message || payload.msg || "",
|
||||
meta: payload.meta ?? payload.ctx ?? payload.details ?? null
|
||||
};
|
||||
setLogs((prev) => [...prev, normalized]);
|
||||
}
|
||||
: (payload) => setLogs((prev) => [...prev, payload]);
|
||||
const onLog = isRrMode
|
||||
? (payload = {}) => {
|
||||
const normalized = {
|
||||
timestamp: payload.timestamp ? new Date(payload.timestamp) : payload.ts ? new Date(payload.ts) : new Date(),
|
||||
level: (payload.level || "INFO").toUpperCase(),
|
||||
message: payload.message || payload.msg || "",
|
||||
meta: payload.meta ?? payload.ctx ?? payload.details ?? null
|
||||
};
|
||||
setLogs((prev) => [...prev, normalized]);
|
||||
}
|
||||
: (payload) => setLogs((prev) => [...prev, payload]);
|
||||
|
||||
if (channels.log) activeSocket.on(channels.log, onLog);
|
||||
|
||||
@@ -308,9 +384,8 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
||||
]);
|
||||
};
|
||||
|
||||
if (mode === DMS_MAP.reynolds && channels.partialResult) activeSocket.on(channels.partialResult, onPartialResult);
|
||||
if (mode === DMS_MAP.reynolds && channels.validationNeeded)
|
||||
activeSocket.on(channels.validationNeeded, onValidationRequired);
|
||||
if (isRrMode && channels.partialResult) activeSocket.on(channels.partialResult, onPartialResult);
|
||||
if (isRrMode && channels.validationNeeded) activeSocket.on(channels.validationNeeded, onValidationRequired);
|
||||
|
||||
return () => {
|
||||
activeSocket.off("connect", onConnect);
|
||||
@@ -322,10 +397,8 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
||||
if (channels.exportSuccess) activeSocket.off(channels.exportSuccess, onExportSuccess);
|
||||
if (channels.exportFailed) activeSocket.off(channels.exportFailed, handleExportFailed);
|
||||
|
||||
if (mode === DMS_MAP.reynolds && channels.partialResult)
|
||||
activeSocket.off(channels.partialResult, onPartialResult);
|
||||
if (mode === DMS_MAP.reynolds && channels.validationNeeded)
|
||||
activeSocket.off(channels.validationNeeded, onValidationRequired);
|
||||
if (isRrMode && channels.partialResult) activeSocket.off(channels.partialResult, onPartialResult);
|
||||
if (isRrMode && channels.validationNeeded) activeSocket.off(channels.validationNeeded, onValidationRequired);
|
||||
|
||||
// Only tear down legacy socket listeners; don't disconnect WSS from here
|
||||
if (!isWssMode(mode)) {
|
||||
@@ -358,24 +431,57 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
||||
<AlertComponent style={{ marginBottom: 10 }} message={bannerMessage} type="warning" showIcon closable />
|
||||
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col md={24} lg={10}>
|
||||
<DmsAllocationsSummary
|
||||
title={
|
||||
<span>
|
||||
<Link
|
||||
to={`/manage/jobs/${data && data.jobs_by_pk.id}`}
|
||||
>{`${data?.jobs_by_pk && data.jobs_by_pk.ro_number}`}</Link>
|
||||
{` | ${OwnerNameDisplayFunction(data.jobs_by_pk)} | ${data.jobs_by_pk.v_model_yr || ""} ${data.jobs_by_pk.v_make_desc || ""} ${data.jobs_by_pk.v_model_desc || ""}`}
|
||||
</span>
|
||||
}
|
||||
socket={activeSocket}
|
||||
jobId={jobId}
|
||||
mode={mode}
|
||||
/>
|
||||
<Col md={24} lg={10} className="dms-equal-height-col">
|
||||
{!isRrMode ? (
|
||||
<DmsAllocationsSummary
|
||||
key={resetKey}
|
||||
onAllocationsChange={setAllocationsSummary}
|
||||
title={
|
||||
<span>
|
||||
<Link
|
||||
to={`/manage/jobs/${data && data.jobs_by_pk.id}`}
|
||||
>{`${data?.jobs_by_pk && data.jobs_by_pk.ro_number}`}</Link>
|
||||
{` | ${OwnerNameDisplayFunction(data.jobs_by_pk)} | ${data.jobs_by_pk.v_model_yr || ""} ${
|
||||
data.jobs_by_pk.v_make_desc || ""
|
||||
} ${data.jobs_by_pk.v_model_desc || ""}`}
|
||||
</span>
|
||||
}
|
||||
socket={activeSocket}
|
||||
jobId={jobId}
|
||||
mode={mode}
|
||||
/>
|
||||
) : (
|
||||
<RrAllocationsSummary
|
||||
key={resetKey}
|
||||
onAllocationsChange={setAllocationsSummary}
|
||||
title={
|
||||
<span>
|
||||
<Link to={`/manage/jobs/${data && data.jobs_by_pk.id}`}>
|
||||
{data?.jobs_by_pk && data.jobs_by_pk.ro_number}
|
||||
</Link>
|
||||
{` | ${OwnerNameDisplayFunction(data.jobs_by_pk)} | ${
|
||||
data.jobs_by_pk.v_model_yr || ""
|
||||
} ${data.jobs_by_pk.v_make_desc || ""} ${data.jobs_by_pk.v_model_desc || ""}`}
|
||||
</span>
|
||||
}
|
||||
socket={activeSocket}
|
||||
jobId={jobId}
|
||||
opCode={rrOpCodeCombined}
|
||||
/>
|
||||
)}
|
||||
</Col>
|
||||
|
||||
<Col md={24} lg={14}>
|
||||
<DmsPostForm socket={activeSocket} job={data?.jobs_by_pk} logsRef={logsRef} mode={mode} />
|
||||
<Col md={24} lg={14} className="dms-equal-height-col">
|
||||
<DmsPostForm
|
||||
key={resetKey}
|
||||
socket={activeSocket}
|
||||
job={data?.jobs_by_pk}
|
||||
logsRef={logsRef}
|
||||
mode={mode}
|
||||
allocationsSummary={allocationsSummary}
|
||||
rrOpCodeParts={rrOpCodeParts}
|
||||
onChangeRrOpCodeParts={setRrOpCodeParts}
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<DmsCustomerSelector
|
||||
@@ -397,13 +503,18 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
||||
title={t("jobs.labels.dms.logs")}
|
||||
extra={
|
||||
<Space wrap>
|
||||
<Switch
|
||||
checked={colorizeJson}
|
||||
onChange={setColorizeJson}
|
||||
checkedChildren="Color JSON"
|
||||
unCheckedChildren="Plain JSON"
|
||||
/>
|
||||
<Button onClick={toggleDetailsAll}>{detailsOpen ? "Collapse All" : "Expand All"}</Button>
|
||||
{isRrMode && (
|
||||
<>
|
||||
<Switch
|
||||
checked={colorizeJson}
|
||||
onChange={setColorizeJson}
|
||||
checkedChildren="Color JSON"
|
||||
unCheckedChildren="Plain JSON"
|
||||
/>
|
||||
<Button onClick={toggleDetailsAll}>{detailsOpen ? "Collapse All" : "Expand All"}</Button>
|
||||
</>
|
||||
)}
|
||||
|
||||
<Select
|
||||
placeholder="Log Level"
|
||||
value={logLevel}
|
||||
@@ -422,11 +533,14 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
||||
<Button
|
||||
onClick={() => {
|
||||
setLogs([]);
|
||||
setResetAfterReconnect(true);
|
||||
if (isWssMode(mode)) {
|
||||
setActiveLogLevel(logLevel);
|
||||
}
|
||||
activeSocket.disconnect();
|
||||
activeSocket.connect();
|
||||
if (activeSocket) {
|
||||
activeSocket.disconnect();
|
||||
setTimeout(() => activeSocket.connect(), 100);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Reconnect
|
||||
@@ -436,9 +550,12 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
||||
>
|
||||
<DmsLogEvents
|
||||
logs={logs}
|
||||
detailsOpen={detailsOpen}
|
||||
// Only honour details/colorized JSON in RR mode;
|
||||
// in other modes DmsLogEvents can render a simple, flat list.
|
||||
detailsOpen={isRrMode ? detailsOpen : false}
|
||||
detailsNonce={detailsNonce}
|
||||
colorizeJson={colorizeJson}
|
||||
colorizeJson={isRrMode ? colorizeJson : false}
|
||||
showDetails={isRrMode}
|
||||
/>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -3223,6 +3223,7 @@
|
||||
"parts_not_recieved_vendor": "Parts Not Received by Vendor",
|
||||
"parts_received_not_scheduled": "Parts Received for Jobs Not Scheduled",
|
||||
"payments_by_date": "Payments by Date",
|
||||
"payments_by_date_excel": "Payments by Date - Excel",
|
||||
"payments_by_date_payment": "Payments by Date and Payment Type",
|
||||
"payments_by_date_type": "Payments by Date and Customer Type",
|
||||
"production_by_category": "Production by Category",
|
||||
|
||||
@@ -3220,6 +3220,7 @@
|
||||
"parts_not_recieved_vendor": "",
|
||||
"parts_received_not_scheduled": "",
|
||||
"payments_by_date": "",
|
||||
"payments_by_date_excel": "",
|
||||
"payments_by_date_payment": "",
|
||||
"payments_by_date_type": "",
|
||||
"production_by_category": "",
|
||||
|
||||
@@ -3220,6 +3220,7 @@
|
||||
"parts_not_recieved_vendor": "",
|
||||
"parts_received_not_scheduled": "",
|
||||
"payments_by_date": "",
|
||||
"payments_by_date_excel": "",
|
||||
"payments_by_date_payment": "",
|
||||
"payments_by_date_type": "",
|
||||
"production_by_category": "",
|
||||
|
||||
@@ -1218,6 +1218,18 @@ export const TemplateList = (type, context) => {
|
||||
},
|
||||
group: "customers"
|
||||
},
|
||||
payments_by_date_excel: {
|
||||
title: i18n.t("reportcenter.templates.payments_by_date_excel"),
|
||||
subject: i18n.t("reportcenter.templates.payments_by_date_excel"),
|
||||
key: "payments_by_date_excel",
|
||||
reporttype: "excel",
|
||||
disabled: false,
|
||||
rangeFilter: {
|
||||
object: i18n.t("reportcenter.labels.objects.payments"),
|
||||
field: i18n.t("payments.fields.date")
|
||||
},
|
||||
group: "customers"
|
||||
},
|
||||
schedule: {
|
||||
title: i18n.t("reportcenter.templates.schedule"),
|
||||
subject: i18n.t("reportcenter.templates.schedule"),
|
||||
|
||||
@@ -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}`;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Could not auto-generate a down migration.
|
||||
-- Please write an appropriate down migration for the SQL below:
|
||||
-- alter table "public"."media_analytics" add column "unique_documents" numeric
|
||||
-- null;
|
||||
@@ -0,0 +1,2 @@
|
||||
alter table "public"."media_analytics" add column "unique_documents" numeric
|
||||
null;
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Could not auto-generate a down migration.
|
||||
-- Please write an appropriate down migration for the SQL below:
|
||||
-- alter table "public"."media_analytics" add column "duplicate_documents" numeric
|
||||
-- null;
|
||||
@@ -0,0 +1,2 @@
|
||||
alter table "public"."media_analytics" add column "duplicate_documents" numeric
|
||||
null;
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Could not auto-generate a down migration.
|
||||
-- Please write an appropriate down migration for the SQL below:
|
||||
-- alter table "public"."media_analytics_detail" add column "unique_documents" numeric
|
||||
-- null;
|
||||
@@ -0,0 +1,2 @@
|
||||
alter table "public"."media_analytics_detail" add column "unique_documents" numeric
|
||||
null;
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Could not auto-generate a down migration.
|
||||
-- Please write an appropriate down migration for the SQL below:
|
||||
-- alter table "public"."media_analytics_detail" add column "duplicate_documents" numeric
|
||||
-- null;
|
||||
@@ -0,0 +1,2 @@
|
||||
alter table "public"."media_analytics_detail" add column "duplicate_documents" numeric
|
||||
null;
|
||||
@@ -0,0 +1 @@
|
||||
alter table "public"."media_analytics_detail" rename column "unique_document_count" to "unique_documents";
|
||||
@@ -0,0 +1 @@
|
||||
alter table "public"."media_analytics_detail" rename column "unique_documents" to "unique_document_count";
|
||||
@@ -0,0 +1 @@
|
||||
alter table "public"."media_analytics_detail" rename column "duplicate_count" to "duplicate_documents";
|
||||
@@ -0,0 +1 @@
|
||||
alter table "public"."media_analytics_detail" rename column "duplicate_documents" to "duplicate_count";
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Could not auto-generate a down migration.
|
||||
-- Please write an appropriate down migration for the SQL below:
|
||||
-- alter table "public"."jobs" add column "dms_id" text
|
||||
-- null;
|
||||
@@ -0,0 +1,2 @@
|
||||
alter table "public"."jobs" add column "dms_id" text
|
||||
null;
|
||||
857
package-lock.json
generated
857
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
26
package.json
26
package.json
@@ -18,14 +18,14 @@
|
||||
"job-totals-fixtures:local": "docker exec node-app /usr/bin/node /app/download-job-totals-fixtures.js"
|
||||
},
|
||||
"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"
|
||||
}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
})
|
||||
});
|
||||
|
||||
@@ -219,8 +219,6 @@ const CreateRepairOrderTag = (job, errorCallback) => {
|
||||
}
|
||||
|
||||
const repairCosts = CreateCosts(job);
|
||||
const jobline = CreateJobLines(job.joblines);
|
||||
const timeticket = CreateTimeTickets(job.timetickets);
|
||||
|
||||
try {
|
||||
const ret = {
|
||||
@@ -290,8 +288,100 @@ const CreateRepairOrderTag = (job, errorCallback) => {
|
||||
(job.date_exported && moment(job.date_exported).tz(job.bodyshop.timezone).format(DateFormat)) || "",
|
||||
DateVoid: (job.date_void && moment(job.date_void).tz(job.bodyshop.timezone).format(DateFormat)) || ""
|
||||
},
|
||||
JobLineDetails: { jobline },
|
||||
TimeTicketDetails: { timeticket },
|
||||
JobLineDetails: (function () {
|
||||
const joblineSource = Array.isArray(job.joblines) ? job.joblines : job.joblines ? [job.joblines] : [];
|
||||
if (joblineSource.length === 0) return { jobline: [] };
|
||||
return {
|
||||
jobline: joblineSource.map((jl = {}) => ({
|
||||
line_description: jl.line_desc || jl.line_description || "",
|
||||
oem_part_no: jl.oem_partno || jl.oem_part_no || "",
|
||||
alt_part_no: jl.alt_partno || jl.alt_part_no || "",
|
||||
op_code_desc: jl.op_code_desc || "",
|
||||
part_type: jl.part_type || "",
|
||||
part_qty: jl.part_qty ?? jl.quantity ?? 0,
|
||||
part_price: jl.act_price ?? jl.part_price ?? 0,
|
||||
labor_type: jl.mod_lbr_ty || jl.labor_type || "",
|
||||
labor_hours: jl.mod_lb_hrs ?? jl.labor_hours ?? 0,
|
||||
labor_sale: jl.lbr_amt ?? jl.labor_sale ?? 0
|
||||
}))
|
||||
};
|
||||
})(),
|
||||
BillsDetails: (function () {
|
||||
const billsSource = Array.isArray(job.bills) ? job.bills : job.bills ? [job.bills] : [];
|
||||
if (billsSource.length === 0) return { BillDetails: [] };
|
||||
return {
|
||||
BillDetails: billsSource.map(
|
||||
({
|
||||
billlines = [],
|
||||
date = "",
|
||||
is_credit_memo = false,
|
||||
invoice_number = "",
|
||||
isinhouse = false,
|
||||
vendor = {}
|
||||
} = {}) => ({
|
||||
BillLines: {
|
||||
BillLine: billlines.map((bl = {}) => ({
|
||||
line_description: bl.line_desc || bl.line_description || "",
|
||||
part_price: bl.actual_price ?? bl.part_price ?? bl.act_price ?? 0,
|
||||
actual_cost: bl.actual_cost ?? 0,
|
||||
cost_center: bl.cost_center || "",
|
||||
deductedfromlbr: bl.deductedfromlbr || false,
|
||||
part_qty: bl.quantity ?? bl.part_qty ?? 0,
|
||||
oem_part_no: bl.oem_partno || bl.oem_part_no || "",
|
||||
alt_part_no: bl.alt_partno || bl.alt_part_no || ""
|
||||
}))
|
||||
},
|
||||
date,
|
||||
is_credit_memo,
|
||||
invoice_number,
|
||||
isinhouse,
|
||||
vendorName: vendor.name || ""
|
||||
})
|
||||
)
|
||||
};
|
||||
})(),
|
||||
JobNotes: (function () {
|
||||
const notesSource = Array.isArray(job.notes) ? job.notes : job.notes ? [job.notes] : [];
|
||||
if (notesSource.length === 0) return { JobNote: [] };
|
||||
return {
|
||||
JobNote: notesSource.map((note = {}) => ({
|
||||
created_at: note.created_at || "",
|
||||
created_by: note.created_by || "",
|
||||
critical: note.critical || false,
|
||||
private: note.private || false,
|
||||
text: note.text || "",
|
||||
type: note.type || ""
|
||||
}))
|
||||
};
|
||||
})(),
|
||||
TimeTicketDetails: (function () {
|
||||
const ticketSource = Array.isArray(job.timetickets)
|
||||
? job.timetickets
|
||||
: job.timetickets
|
||||
? [job.timetickets]
|
||||
: [];
|
||||
if (ticketSource.length === 0) return { timeticket: [] };
|
||||
return {
|
||||
timeticket: ticketSource.map((ticket = {}) => ({
|
||||
date: ticket.date || "",
|
||||
employee:
|
||||
ticket.employee && ticket.employee.employee_number
|
||||
? ticket.employee.employee_number
|
||||
.trim()
|
||||
.concat(" - ", ticket.employee.first_name.trim(), " ", ticket.employee.last_name.trim())
|
||||
.trim()
|
||||
: "",
|
||||
productive_hrs: ticket.productivehrs ?? 0,
|
||||
actual_hrs: ticket.actualhrs ?? 0,
|
||||
cost_center: ticket.cost_center || "",
|
||||
flat_rate: ticket.flat_rate || false,
|
||||
rate: ticket.rate ?? 0,
|
||||
ticket_cost: ticket.flat_rate
|
||||
? ticket.rate * (ticket.productivehrs || 0)
|
||||
: ticket.rate * (ticket.actualhrs || 0)
|
||||
}))
|
||||
};
|
||||
})(),
|
||||
Sales: {
|
||||
Labour: {
|
||||
Aluminum: Dinero(job.job_totals.rates.laa.total).toFormat(DineroFormat),
|
||||
@@ -636,42 +726,3 @@ const CreateCosts = (job) => {
|
||||
}, 0)
|
||||
};
|
||||
};
|
||||
|
||||
const CreateJobLines = (joblines) => {
|
||||
const repairLines = [];
|
||||
joblines.forEach((jobline) => {
|
||||
repairLines.push({
|
||||
line_description: jobline.line_desc,
|
||||
oem_part_no: jobline.oem_partno,
|
||||
alt_part_no: jobline.alt_partno,
|
||||
op_code_desc: jobline.op_code_desc,
|
||||
part_type: jobline.part_type,
|
||||
part_qty: jobline.part_qty,
|
||||
part_price: jobline.act_price,
|
||||
labor_type: jobline.mod_lbr_ty,
|
||||
labor_hours: jobline.mod_lb_hrs,
|
||||
labor_sale: jobline.lbr_amt
|
||||
});
|
||||
});
|
||||
return repairLines;
|
||||
};
|
||||
|
||||
const CreateTimeTickets = (timetickets) => {
|
||||
const timeTickets = [];
|
||||
timetickets.forEach((ticket) => {
|
||||
timeTickets.push({
|
||||
date: ticket.date,
|
||||
employee: ticket.employee.employee_number
|
||||
.trim()
|
||||
.concat(" - ", ticket.employee.first_name.trim(), " ", ticket.employee.last_name.trim())
|
||||
.trim(),
|
||||
productive_hrs: ticket.productivehrs,
|
||||
actual_hrs: ticket.actualhrs,
|
||||
cost_center: ticket.cost_center,
|
||||
flat_rate: ticket.flat_rate,
|
||||
rate: ticket.rate,
|
||||
ticket_cost: ticket.flat_rate ? ticket.rate * ticket.productive_hrs : ticket.rate * ticket.actual_hrs
|
||||
});
|
||||
});
|
||||
return timeTickets;
|
||||
};
|
||||
|
||||
@@ -55,7 +55,9 @@ exports.default = async (req, res) => {
|
||||
"patrick.fic@convenient-brands.com",
|
||||
"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: `
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1221,7 +1221,7 @@ query ENTEGRAL_EXPORT($bodyshopid: uuid!) {
|
||||
}`;
|
||||
|
||||
exports.KAIZEN_QUERY = `query KAIZEN_EXPORT($start: timestamptz, $bodyshopid: uuid!, $end: timestamptz) {
|
||||
bodyshops_by_pk(id: $bodyshopid){
|
||||
bodyshops_by_pk(id: $bodyshopid) {
|
||||
id
|
||||
shopname
|
||||
address1
|
||||
@@ -1249,15 +1249,24 @@ exports.KAIZEN_QUERY = `query KAIZEN_EXPORT($start: timestamptz, $bodyshopid: uu
|
||||
bills {
|
||||
billlines {
|
||||
actual_cost
|
||||
actual_price
|
||||
cost_center
|
||||
deductedfromlbr
|
||||
id
|
||||
line_desc
|
||||
quantity
|
||||
}
|
||||
date
|
||||
federal_tax_rate
|
||||
id
|
||||
is_credit_memo
|
||||
invoice_number
|
||||
isinhouse
|
||||
local_tax_rate
|
||||
state_tax_rate
|
||||
vendor {
|
||||
name
|
||||
}
|
||||
}
|
||||
created_at
|
||||
clm_no
|
||||
@@ -1299,7 +1308,7 @@ exports.KAIZEN_QUERY = `query KAIZEN_EXPORT($start: timestamptz, $bodyshopid: uu
|
||||
joblines(where: {removed: {_eq: false}}) {
|
||||
act_price
|
||||
alt_partno
|
||||
billlines(order_by: {bill: {date: desc_nulls_last}} limit: 1) {
|
||||
billlines(order_by: {bill: {date: desc_nulls_last}}, limit: 1) {
|
||||
actual_cost
|
||||
actual_price
|
||||
quantity
|
||||
@@ -1322,8 +1331,8 @@ exports.KAIZEN_QUERY = `query KAIZEN_EXPORT($start: timestamptz, $bodyshopid: uu
|
||||
mod_lbr_ty
|
||||
oem_partno
|
||||
op_code_desc
|
||||
parts_order_lines(order_by: {parts_order: {order_date: desc_nulls_last}} limit: 1){
|
||||
parts_order{
|
||||
parts_order_lines(order_by: {parts_order: {order_date: desc_nulls_last}}, limit: 1) {
|
||||
parts_order {
|
||||
id
|
||||
order_date
|
||||
}
|
||||
@@ -1342,6 +1351,14 @@ exports.KAIZEN_QUERY = `query KAIZEN_EXPORT($start: timestamptz, $bodyshopid: uu
|
||||
jobid
|
||||
totalliquidcost
|
||||
}
|
||||
notes {
|
||||
created_at
|
||||
created_by
|
||||
critical
|
||||
private
|
||||
text
|
||||
type
|
||||
}
|
||||
ownr_addr1
|
||||
ownr_addr2
|
||||
ownr_city
|
||||
@@ -2178,8 +2195,6 @@ mutation UPDATE_BILLS($billids: [uuid!]!, $bill: bills_set_input!, $logs: [expor
|
||||
}
|
||||
}`;
|
||||
|
||||
|
||||
|
||||
exports.UPDATE_OLD_TRANSITION = `mutation UPDATE_OLD_TRANSITION($jobid: uuid!, $existingTransition: transitions_set_input!){
|
||||
update_transitions(where:{jobid:{_eq:$jobid}, end:{_is_null:true
|
||||
}}, _set:$existingTransition){
|
||||
@@ -3149,11 +3164,17 @@ exports.DELETE_PHONE_NUMBER_OPT_OUT = `
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
exports.INSERT_MEDIA_ANALYTICS = `
|
||||
mutation INSERT_MEDIA_ANALYTICS($mediaObject: media_analytics_insert_input!) {
|
||||
insert_media_analytics_one(object: $mediaObject) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`
|
||||
`;
|
||||
|
||||
exports.SET_JOB_DMS_ID = `mutation SetJobDmsId($id: uuid!, $dms_id: String!) {
|
||||
update_jobs_by_pk(pk_columns: { id: $id }, _set: { dms_id: $dms_id }) {
|
||||
id
|
||||
dms_id
|
||||
}
|
||||
}`;
|
||||
|
||||
@@ -134,13 +134,16 @@ const insertUserAssociation = async (uid, email, shopId) => {
|
||||
|
||||
/**
|
||||
* PATCH handler for updating bodyshop fields.
|
||||
* 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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
1222
server/rr/rr-calculate-allocations.js
Normal file
1222
server/rr/rr-calculate-allocations.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,8 @@ const { buildRRRepairOrderPayload } = require("./rr-job-helpers");
|
||||
const { buildClientAndOpts } = require("./rr-lookup");
|
||||
const CreateRRLogEvent = require("./rr-logger-event");
|
||||
const { extractRrResponsibilityCenters } = require("./rr-responsibility-centers");
|
||||
const CdkCalculateAllocations = require("../cdk/cdk-calculate-allocations").default;
|
||||
const CdkCalculateAllocations = require("./rr-calculate-allocations").default;
|
||||
const { resolveRROpCodeFromBodyshop } = require("./rr-utils");
|
||||
|
||||
/**
|
||||
* Derive RR status information from response object.
|
||||
@@ -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 {
|
||||
@@ -116,33 +121,49 @@ const exportJobToRR = async (args) => {
|
||||
|
||||
// 2) Allocations (sales + cost by center, with rr_* metadata already attached)
|
||||
try {
|
||||
allocations = await CdkCalculateAllocations(socket, job.id);
|
||||
const allocResult = await CdkCalculateAllocations(socket, job.id);
|
||||
|
||||
// We only need the per-center job allocations for RO.GOG / ROLABOR.
|
||||
allocations = Array.isArray(allocResult?.jobAllocations) ? allocResult.jobAllocations : [];
|
||||
|
||||
CreateRRLogEvent(socket, "SILLY", "RR allocations resolved", {
|
||||
hasAllocations: Array.isArray(allocations),
|
||||
count: Array.isArray(allocations) ? allocations.length : 0
|
||||
hasAllocations: allocations.length > 0,
|
||||
count: allocations.length,
|
||||
taxAllocCount: Array.isArray(allocResult?.taxAllocArray) ? allocResult.taxAllocArray.length : 0,
|
||||
ttlAdjCount: Array.isArray(allocResult?.ttlAdjArray) ? allocResult.ttlAdjArray.length : 0,
|
||||
ttlTaxAdjCount: Array.isArray(allocResult?.ttlTaxAdjArray) ? allocResult.ttlTaxAdjArray.length : 0
|
||||
});
|
||||
} catch (e) {
|
||||
CreateRRLogEvent(socket, "ERROR", "Failed to calculate RR allocations", {
|
||||
message: e?.message,
|
||||
stack: e?.stack
|
||||
});
|
||||
allocations = null; // We still proceed with a header-only RO if this fails.
|
||||
// Proceed with a header-only RO if allocations fail.
|
||||
allocations = [];
|
||||
}
|
||||
|
||||
// 3) OpCode (global, but overridable)
|
||||
// - 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.
|
||||
|
||||
@@ -54,7 +54,43 @@ const asN2 = (dineroLike) => {
|
||||
|
||||
/**
|
||||
* Build RO.GOG structure for the reynolds-rome-client `createRepairOrder` payload
|
||||
* from CDK allocations.
|
||||
* from allocations.
|
||||
*
|
||||
* Supports the allocation shape:
|
||||
* {
|
||||
* center,
|
||||
* partsSale,
|
||||
* partsTaxableSale,
|
||||
* partsNonTaxableSale,
|
||||
* laborTaxableSale,
|
||||
* laborNonTaxableSale,
|
||||
* extrasSale,
|
||||
* extrasTaxableSale,
|
||||
* extrasNonTaxableSale,
|
||||
* totalSale,
|
||||
* cost,
|
||||
* profitCenter,
|
||||
* costCenter
|
||||
* }
|
||||
*
|
||||
* For each center, we can emit up to 6 GOG *segments*:
|
||||
* - taxable parts (CustTxblNTxblFlag="T")
|
||||
* - non-taxable parts (CustTxblNTxblFlag="N")
|
||||
* - taxable extras (CustTxblNTxblFlag="T")
|
||||
* - non-taxable extras (CustTxblNTxblFlag="N")
|
||||
* - taxable labor (CustTxblNTxblFlag="T")
|
||||
* - non-taxable labor (CustTxblNTxblFlag="N")
|
||||
*
|
||||
* IMPORTANT:
|
||||
* Each segment becomes its OWN JobNo / AllGogOpCodeInfo, with exactly one
|
||||
* AllGogLineItmInfo inside. This keeps a clean 1:1 mapping between:
|
||||
* - <AllGogOpCodeInfo> (ROGOG)
|
||||
* - <OpCodeLaborInfo> (ROLABOR)
|
||||
* and ensures taxable/non-taxable flags line up by JobNo.
|
||||
*
|
||||
* We attach segmentKind/segmentIndex/segmentCount metadata on each op
|
||||
* for UI/debug purposes. The XML templates can safely ignore these.
|
||||
*
|
||||
* @param {Array} allocations
|
||||
* @param {Object} opts
|
||||
* @param {string} opts.opCode - RR OpCode for the job (global, overridable)
|
||||
@@ -67,45 +103,176 @@ const buildRogogFromAllocations = (allocations, { opCode, payType = "Cust", roNo
|
||||
|
||||
const ops = [];
|
||||
|
||||
/**
|
||||
* Normalize various "money-like" shapes to integer cents.
|
||||
* Supports:
|
||||
* - Dinero instances (getAmount / toUnit)
|
||||
* - { cents }
|
||||
* - { amount, precision }
|
||||
* - plain numbers (treated as units, e.g. dollars)
|
||||
*/
|
||||
const toCents = (value) => {
|
||||
if (!value) return 0;
|
||||
|
||||
if (typeof value.getAmount === "function") {
|
||||
return value.getAmount();
|
||||
}
|
||||
|
||||
if (typeof value.toUnit === "function") {
|
||||
const unit = value.toUnit();
|
||||
return Number.isFinite(unit) ? Math.round(unit * 100) : 0;
|
||||
}
|
||||
|
||||
if (typeof value.cents === "number") {
|
||||
return value.cents;
|
||||
}
|
||||
|
||||
if (typeof value.amount === "number") {
|
||||
const precision = typeof value.precision === "number" ? value.precision : 2;
|
||||
if (precision === 2) return value.amount;
|
||||
const factor = Math.pow(10, 2 - precision);
|
||||
return Math.round(value.amount * factor);
|
||||
}
|
||||
|
||||
if (typeof value === "number") {
|
||||
return Math.round(value * 100);
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
const asMoneyLike = (amountCents) => ({
|
||||
amount: amountCents || 0,
|
||||
precision: 2
|
||||
});
|
||||
|
||||
for (const alloc of allocations) {
|
||||
const pc = alloc?.profitCenter || {};
|
||||
const breakOut = pc.rr_gogcode;
|
||||
const itemType = pc.rr_item_type;
|
||||
|
||||
// Only centers that have been configured for RR GOG are included
|
||||
// Only centers configured for RR GOG are included
|
||||
if (!breakOut || !itemType) continue;
|
||||
|
||||
const saleN2 = asN2(alloc.sale);
|
||||
const costN2 = asN2(alloc.cost);
|
||||
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);
|
||||
|
||||
const itemDesc = pc.accountdesc || pc.accountname || alloc.center || "";
|
||||
const jobNo = String(ops.length + 1); // 1-based JobNo
|
||||
const segments = [];
|
||||
|
||||
ops.push({
|
||||
opCode,
|
||||
jobNo,
|
||||
lines: [
|
||||
{
|
||||
breakOut,
|
||||
itemType,
|
||||
itemDesc,
|
||||
custQty: "1.0",
|
||||
// warrQty: "0.0",
|
||||
// intrQty: "0.0",
|
||||
custPayTypeFlag: "C",
|
||||
// warrPayTypeFlag: "W",
|
||||
// intrPayTypeFlag: "I",
|
||||
custTxblNtxblFlag: pc.rr_cust_txbl_flag || "T",
|
||||
// warrTxblNtxblFlag: "N",
|
||||
// intrTxblNtxblFlag: "N",
|
||||
amount: {
|
||||
payType,
|
||||
amtType: "Unit",
|
||||
custPrice: saleN2,
|
||||
dlrCost: costN2
|
||||
}
|
||||
// 1) Taxable parts segment -> "T"
|
||||
if (partsTaxableCents !== 0) {
|
||||
segments.push({
|
||||
kind: "partsTaxable",
|
||||
saleCents: partsTaxableCents,
|
||||
txFlag: "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",
|
||||
saleCents: laborTaxableCents,
|
||||
txFlag: "T"
|
||||
});
|
||||
}
|
||||
|
||||
// 6) Non-tax labor segment -> "N"
|
||||
if (laborNonTaxableCents !== 0) {
|
||||
segments.push({
|
||||
kind: "laborNonTaxable",
|
||||
saleCents: laborNonTaxableCents,
|
||||
txFlag: "N"
|
||||
});
|
||||
}
|
||||
|
||||
if (!segments.length) continue;
|
||||
|
||||
// Proportionally split cost across segments based on their sale amounts
|
||||
const totalCostCents = costCents;
|
||||
const totalSaleCents = segments.reduce((sum, seg) => sum + seg.saleCents, 0);
|
||||
|
||||
let remainingCostCents = totalCostCents;
|
||||
|
||||
segments.forEach((seg, idx) => {
|
||||
let segCost = 0;
|
||||
|
||||
if (totalCostCents > 0 && totalSaleCents > 0) {
|
||||
if (idx === segments.length - 1) {
|
||||
// Last segment gets the remainder to avoid rounding drift
|
||||
segCost = remainingCostCents;
|
||||
} else {
|
||||
segCost = Math.round((seg.saleCents / totalSaleCents) * totalCostCents);
|
||||
remainingCostCents -= segCost;
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
seg.costCents = segCost;
|
||||
});
|
||||
|
||||
const itemDescBase = pc.accountdesc || pc.accountname || alloc.center || "";
|
||||
const segmentCount = segments.length;
|
||||
|
||||
// Each segment becomes its own op / JobNo with a single line
|
||||
segments.forEach((seg, idx) => {
|
||||
const jobNo = String(ops.length + 1); // global, 1-based JobNo across all centers/segments
|
||||
|
||||
const line = {
|
||||
breakOut,
|
||||
itemType,
|
||||
itemDesc: itemDescBase,
|
||||
custQty: "1.0",
|
||||
custPayTypeFlag: "C",
|
||||
custTxblNtxblFlag: seg.txFlag || "N",
|
||||
amount: {
|
||||
payType,
|
||||
amtType: "Unit",
|
||||
custPrice: asN2(asMoneyLike(seg.saleCents)),
|
||||
dlrCost: asN2(asMoneyLike(seg.costCents))
|
||||
}
|
||||
};
|
||||
|
||||
ops.push({
|
||||
opCode,
|
||||
jobNo,
|
||||
lines: [line], // exactly one AllGogLineItmInfo per AllGogOpCodeInfo
|
||||
// Extra metadata for UI / debugging
|
||||
segmentKind: seg.kind,
|
||||
segmentIndex: idx,
|
||||
segmentCount
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -120,6 +287,12 @@ const buildRogogFromAllocations = (allocations, { opCode, payType = "Cust", roNo
|
||||
/**
|
||||
* Build RO.ROLABOR structure for the reynolds-rome-client `createRepairOrder` payload
|
||||
* 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"]
|
||||
@@ -131,16 +304,18 @@ const buildRolaborFromRogog = (rogg, { payType = "Cust" } = {}) => {
|
||||
const ops = rogg.ops.map((op) => {
|
||||
const firstLine = op.lines?.[0] || {};
|
||||
|
||||
// Pull tax flag from the GOG line.
|
||||
// Prefer the property we set in buildRogogFromAllocations (custTxblNTxblFlag),
|
||||
// but also accept custTxblNtxblFlag in case we ever change naming.
|
||||
const txFlag = firstLine.custTxblNtxblFlag ?? "N";
|
||||
|
||||
const linePayType = firstLine.custPayTypeFlag || "C";
|
||||
|
||||
return {
|
||||
opCode: op.opCode,
|
||||
jobNo: op.jobNo,
|
||||
custPayTypeFlag: firstLine.custPayTypeFlag || "C",
|
||||
// warrPayTypeFlag: firstLine.warrPayTypeFlag || "W",
|
||||
// intrPayTypeFlag: firstLine.intrPayTypeFlag || "I",
|
||||
custTxblNtxblFlag: firstLine.custTxblNtxblFlag || "N",
|
||||
// warrTxblNtxblFlag: firstLine.warrTxblNtxblFlag || "N",
|
||||
// intrTxblNtxblFlag: firstLine.intrTxblNtxblFlag || "N",
|
||||
// vlrCode: undefined,
|
||||
custPayTypeFlag: linePayType,
|
||||
custTxblNtxblFlag: txFlag,
|
||||
bill: {
|
||||
payType,
|
||||
jobTotalHrs: "0",
|
||||
@@ -194,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 = ({
|
||||
@@ -208,7 +381,6 @@ const buildRRRepairOrderPayload = ({
|
||||
makeOverride,
|
||||
allocations,
|
||||
opCode
|
||||
// taxCode
|
||||
} = {}) => {
|
||||
const customerNo = selectedCustomer?.customerNo
|
||||
? String(selectedCustomer.customerNo).trim()
|
||||
@@ -259,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
|
||||
@@ -277,24 +448,6 @@ const buildRRRepairOrderPayload = ({
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- TAX HEADER TEMPORARILY DISABLED ---
|
||||
// We intentionally do NOT attach payload.tax right now so that the Mustache
|
||||
// section that renders <TaxCodeInfo> stays false and no TaxCodeInfo is sent.
|
||||
//
|
||||
// Keeping this commented-out for future enablement once RR confirms header
|
||||
// tax handling behaviour.
|
||||
//
|
||||
// if (effectiveTaxCode) {
|
||||
// const taxInfo = buildTaxFromAllocations(allocations, {
|
||||
// taxCode: effectiveTaxCode,
|
||||
// payType: "Cust"
|
||||
// });
|
||||
//
|
||||
// if (taxInfo) {
|
||||
// payload.tax = taxInfo;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
return payload;
|
||||
@@ -400,23 +553,49 @@ const normalizeVehicleCandidates = (res) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Build a minimal Rolabor structure in the new normalized shape.
|
||||
*
|
||||
* Useful for tests or for scenarios where you want a single zero-dollar
|
||||
* Rolabor op but don't have GOG data. Shape matches payload.rolabor for the
|
||||
* reynolds-rome-client builders.
|
||||
*
|
||||
* @param {Object} opts
|
||||
* @param {string} opts.opCode
|
||||
* @param {number|string} [opts.jobNo=1]
|
||||
* @param {string} [opts.payType="Cust"]
|
||||
* @returns {null|{ops: Array}}
|
||||
* Build split labor lines from job allocations.
|
||||
* @param jobAllocations
|
||||
* @returns {*[]}
|
||||
*/
|
||||
const buildSplitLaborLinesFromAllocations = (jobAllocations) => {
|
||||
const lines = [];
|
||||
|
||||
for (const alloc of jobAllocations || []) {
|
||||
const { center, laborTaxableSale, laborNonTaxableSale, profitCenter, costCenter } = alloc;
|
||||
|
||||
// Taxable labor
|
||||
if (laborTaxableSale && !laborTaxableSale.isZero()) {
|
||||
lines.push({
|
||||
centerName: center,
|
||||
profitCenter,
|
||||
costCenter,
|
||||
amount: laborTaxableSale,
|
||||
isTaxable: true,
|
||||
source: "labor"
|
||||
});
|
||||
}
|
||||
|
||||
// Non-taxable labor
|
||||
if (laborNonTaxableSale && !laborNonTaxableSale.isZero()) {
|
||||
lines.push({
|
||||
centerName: center,
|
||||
profitCenter,
|
||||
costCenter,
|
||||
amount: laborNonTaxableSale,
|
||||
isTaxable: false,
|
||||
source: "labor"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
QueryJobData,
|
||||
buildRRRepairOrderPayload,
|
||||
makeCustomerSearchPayloadFromJob,
|
||||
buildSplitLaborLinesFromAllocations,
|
||||
makeVehicleSearchPayloadFromJob,
|
||||
normalizeCustomerCandidates,
|
||||
normalizeVehicleCandidates,
|
||||
|
||||
@@ -45,6 +45,7 @@ const safeMeta = (meta) => {
|
||||
const CreateRRLogEvent = (socket, level = "INFO", message = "", meta = null) => {
|
||||
const ts = Date.now();
|
||||
const lvl = String(level || "INFO").toUpperCase();
|
||||
const normLevel = lvl.toLowerCase();
|
||||
const msg = typeof message === "string" ? message : (message?.toString?.() ?? JSON.stringify(message));
|
||||
|
||||
const payload = {
|
||||
@@ -54,12 +55,13 @@ const CreateRRLogEvent = (socket, level = "INFO", message = "", meta = null) =>
|
||||
meta: safeMeta(meta)
|
||||
};
|
||||
|
||||
// Console
|
||||
// Central logger (Winston + CloudWatch + S3)
|
||||
try {
|
||||
const fn = logger?.logger?.[lvl.toLowerCase()] ?? logger?.logger?.info ?? console.log;
|
||||
fn(`[RR] ${new Date(ts).toISOString()} | ${lvl} | ${msg}`, payload.meta);
|
||||
// user = "RR", record = null, meta = payload.meta
|
||||
logger.log(`[RR] ${msg}`, normLevel, "RR", null, payload.meta);
|
||||
} catch {
|
||||
// ignore console failures
|
||||
// Fallback console
|
||||
console.log(`[RR] ${new Date(ts).toISOString()} | ${lvl} | ${msg}`, payload.meta);
|
||||
}
|
||||
|
||||
// Socket
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const CreateRRLogEvent = require("./rr-logger-event");
|
||||
const { rrCombinedSearch, rrGetAdvisors, buildClientAndOpts } = require("./rr-lookup");
|
||||
const { QueryJobData } = require("./rr-job-helpers");
|
||||
const { QueryJobData, buildRogogFromAllocations, buildRolaborFromRogog } = require("./rr-job-helpers");
|
||||
const { exportJobToRR, finalizeRRRepairOrder } = require("./rr-job-export");
|
||||
const CdkCalculateAllocations = require("../cdk/cdk-calculate-allocations").default;
|
||||
const RRCalculateAllocations = require("./rr-calculate-allocations").default;
|
||||
const { createRRCustomer } = require("./rr-customers");
|
||||
const { ensureRRServiceVehicle } = require("./rr-service-vehicles");
|
||||
const { classifyRRVendorError } = require("./rr-errors");
|
||||
@@ -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,13 +953,101 @@ const registerRREvents = ({ socket, redisHelpers }) => {
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("rr-calculate-allocations", async (jobid, cb) => {
|
||||
// RR allocations preview (RR-only)
|
||||
// Accepts either:
|
||||
// - legacy: (jobid, cb)
|
||||
// - new: ({ jobId, opCode, opPrefix, opBase, opSuffix }, cb)
|
||||
socket.on("rr-calculate-allocations", async (payload, cb) => {
|
||||
// Normalize arguments
|
||||
const isObjectPayload = payload && typeof payload === "object";
|
||||
const jobid = isObjectPayload ? payload.jobId || payload.jobid || payload.id : payload;
|
||||
|
||||
const opCodeFromClient =
|
||||
isObjectPayload &&
|
||||
(payload.opCode ||
|
||||
payload.opcode ||
|
||||
payload.op_code ||
|
||||
(payload.opPrefix || payload.opBase || payload.opSuffix
|
||||
? `${payload.opPrefix || ""}${payload.opBase || ""}${payload.opSuffix || ""}`.trim()
|
||||
: null));
|
||||
|
||||
try {
|
||||
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: begin", { jobid });
|
||||
const allocations = await CdkCalculateAllocations(socket, jobid);
|
||||
cb?.(allocations);
|
||||
socket.emit("rr-calculate-allocations:result", allocations);
|
||||
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: success", { items: allocations?.length });
|
||||
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: begin", { jobid, opCodeFromClient });
|
||||
|
||||
const raw = await RRCalculateAllocations(socket, jobid);
|
||||
|
||||
// If the helper returns an explicit error shape, just pass it through.
|
||||
if (raw && raw.ok === false) {
|
||||
cb?.(raw);
|
||||
socket.emit("rr-calculate-allocations:result", raw);
|
||||
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: helper returned error", {
|
||||
jobid,
|
||||
error: raw.error
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let ack;
|
||||
let jobAllocations;
|
||||
|
||||
if (Array.isArray(raw)) {
|
||||
// Legacy shape: plain allocations array
|
||||
jobAllocations = raw;
|
||||
ack = { jobAllocations: raw };
|
||||
} else {
|
||||
ack = raw || {};
|
||||
jobAllocations = Array.isArray(ack.jobAllocations) ? ack.jobAllocations : [];
|
||||
}
|
||||
|
||||
// Start with client-supplied OpCode (if any); fall back to defaults.
|
||||
let opCode = opCodeFromClient || null;
|
||||
|
||||
try {
|
||||
const { bodyshopId } = await getSessionOrSocket(redisHelpers, socket);
|
||||
const bodyshop = await getBodyshopForSocket({ bodyshopId, socket });
|
||||
|
||||
// resolveRROpCodeFromBodyshop(bodyshop, existingOverride?)
|
||||
opCode = resolveRROpCodeFromBodyshop(bodyshop, opCode);
|
||||
|
||||
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: resolved OpCode", {
|
||||
opCode,
|
||||
opCodeFromClient
|
||||
});
|
||||
} catch (e) {
|
||||
CreateRRLogEvent(socket, "WARN", "rr-calculate-allocations: bodyshop lookup failed, using existing OpCode", {
|
||||
error: e.message,
|
||||
opCodeFromClient
|
||||
});
|
||||
}
|
||||
|
||||
let rogg = null;
|
||||
let rolabor = null;
|
||||
|
||||
try {
|
||||
rogg = buildRogogFromAllocations(jobAllocations, { opCode, payType: "Cust" });
|
||||
if (rogg) {
|
||||
rolabor = buildRolaborFromRogog(rogg, { payType: "Cust" });
|
||||
}
|
||||
} catch (e) {
|
||||
CreateRRLogEvent(socket, "WARN", "rr-calculate-allocations: failed to build ROGOG/ROLABOR preview", {
|
||||
error: e.message
|
||||
});
|
||||
}
|
||||
|
||||
const enriched = {
|
||||
...ack,
|
||||
rogg,
|
||||
rolabor
|
||||
};
|
||||
|
||||
cb?.(enriched);
|
||||
socket.emit("rr-calculate-allocations:result", enriched);
|
||||
CreateRRLogEvent(socket, "DEBUG", "rr-calculate-allocations: success", {
|
||||
jobid,
|
||||
jobAllocations: jobAllocations.length,
|
||||
hasRogg: !!rogg,
|
||||
hasRolabor: !!rolabor
|
||||
});
|
||||
} catch (e) {
|
||||
CreateRRLogEvent(socket, "ERROR", "rr-calculate-allocations: failed", { error: e.message, jobid });
|
||||
cb?.({ ok: false, error: e.message });
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const { buildClientAndOpts, rrCombinedSearch } = require("./rr-lookup");
|
||||
const CreateRRLogEvent = require("./rr-logger-event");
|
||||
|
||||
/**
|
||||
* Pick and normalize VIN from inputs
|
||||
* @param vin
|
||||
@@ -29,6 +28,20 @@ const pickCustNo = ({ selectedCustomerNo, custNo, customerNo }) => {
|
||||
return c != null ? String(c).trim() : "";
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple length sanitizer for outbound strings
|
||||
* Returns undefined if value is null/undefined/empty after trim.
|
||||
*/
|
||||
const sanitizeLength = (value, maxLen) => {
|
||||
if (value == null) return undefined;
|
||||
let s = String(value).trim();
|
||||
if (!s) return undefined;
|
||||
if (maxLen && s.length > maxLen) {
|
||||
s = s.slice(0, maxLen);
|
||||
}
|
||||
return s;
|
||||
};
|
||||
|
||||
/**
|
||||
* Extract owner customer numbers from combined search results
|
||||
* @param res
|
||||
@@ -181,65 +194,57 @@ const ensureRRServiceVehicle = async (args = {}) => {
|
||||
}
|
||||
} catch (e) {
|
||||
// Preflight shouldn't be fatal; log and continue to insert (idempotency will still be handled)
|
||||
CreateRRLogEvent(socket, "WARN", "{SV} VIN preflight lookup failed; continuing to insert", {
|
||||
CreateRRLogEvent(socket, "warn", "{SV} VIN preflight lookup failed; continuing to insert", {
|
||||
vin: vinStr,
|
||||
error: e?.message
|
||||
});
|
||||
}
|
||||
|
||||
// --- Attempt insert (idempotent) ---
|
||||
// IMPORTANT: The current RR lib build validates `vehicleServInfo.customerNo`.
|
||||
// To be future-proof, we also include top-level `customerNo`.
|
||||
// Vendor says: MODEL DESCRIPTION HAS MAXIMUM LENGTH OF 20
|
||||
const rawModelDesc = job?.v_model_desc;
|
||||
const safeModelDesc = sanitizeLength(rawModelDesc, 20);
|
||||
if (rawModelDesc && safeModelDesc && rawModelDesc.trim() !== safeModelDesc) {
|
||||
CreateRRLogEvent(socket, "warn", "{SV} Truncated model description to 20 chars", {
|
||||
original: rawModelDesc,
|
||||
truncated: safeModelDesc
|
||||
});
|
||||
}
|
||||
|
||||
const insertPayload = {
|
||||
// === Core Vehicle Identity (MANDATORY for success) ===
|
||||
vin: vinStr.toUpperCase(), // "1FDWX34Y28EB01395"
|
||||
|
||||
// Required: 2-character make code (from v_make_desc → known mapping)
|
||||
vehicleMake: deriveMakeCode(job.v_make_desc), // → "FR" for Ford
|
||||
|
||||
// Required: 2-digit year (last 2 digits of v_model_yr)
|
||||
// 2-character make code (from v_make_desc → known mapping)
|
||||
vehicleMake: deriveMakeCode(job?.v_make_desc), // → "FR" for Ford
|
||||
year: job?.v_model_yr || undefined,
|
||||
|
||||
// Required: Model number — fallback strategy per ERA behavior
|
||||
// Most Ford trucks use "T" = Truck. Some systems accept actual code.
|
||||
// CAN BE (P)assenger , (T)ruck, (O)ther
|
||||
// Model description (RR: max length 20)
|
||||
modelDesc: safeModelDesc,
|
||||
|
||||
// Model number / carline / other optional fields
|
||||
mdlNo: undefined,
|
||||
|
||||
// === Descriptive Fields (highly recommended) ===
|
||||
modelDesc: job?.v_model_desc?.trim() || undefined, // "F-350 SD"
|
||||
carline: job?.v_model_desc?.trim() || undefined, // Series line
|
||||
extClrDesc: job?.v_color?.trim() || undefined, // "Red"
|
||||
|
||||
// Optional but helpful
|
||||
carline: undefined,
|
||||
extClrDesc: sanitizeLength(job?.v_color, 30), // safe, configurable if vendor complains
|
||||
accentClr: undefined,
|
||||
|
||||
// === VehicleDetail Flags (CRITICAL — cause silent fails or error 303 if missing) ===
|
||||
aircond: undefined, // "Y", // Nearly all modern vehicles have A/C
|
||||
pwrstr: undefined, // "Y", // Power steering = yes on 99% of vehicles post-1990
|
||||
transm: undefined, // "A", // Default to Automatic — change to "M" only if known manual
|
||||
turbo: undefined, //"N", // 2008 F-350 6.4L Power Stroke has turbo, but field is optional
|
||||
engineConfig: undefined, //"V8", // or "6.4L Diesel" — optional but nice
|
||||
trim: undefined, //"XLT", // You don't have this — safe to omit or guess
|
||||
aircond: undefined,
|
||||
pwrstr: undefined,
|
||||
transm: undefined,
|
||||
turbo: undefined,
|
||||
engineConfig: undefined,
|
||||
trim: undefined,
|
||||
|
||||
// License plate
|
||||
licNo: license ? String(license).trim() : undefined,
|
||||
|
||||
// === VehicleServInfo (attributes on the element) ===
|
||||
customerNo: custNoStr, // fallback (some builds read this)
|
||||
stockId: job.ro_number || undefined, // Use RO as stock# — common pattern
|
||||
licNo: sanitizeLength(license ? String(license) : undefined, 20),
|
||||
|
||||
customerNo: custNoStr,
|
||||
stockId: sanitizeLength(job?.ro_number, 20), // RO as stock#, truncated for safety
|
||||
vehicleServInfo: {
|
||||
customerNo: custNoStr, // REQUIRED — this is what toServiceVehicleView() validates
|
||||
// Optional but increases success rate
|
||||
salesmanNo: undefined, // You don't have advisor yet — omit
|
||||
salesmanNo: undefined,
|
||||
inServiceDate: undefined,
|
||||
// Optional — safe to include if you want
|
||||
productionDate: undefined,
|
||||
modelMaintCode: undefined,
|
||||
teamCode: undefined,
|
||||
// Extended warranty — omit unless you sell contracts
|
||||
vehExtWarranty: undefined,
|
||||
// Advisor — omit unless you know who the service advisor is
|
||||
advisor: undefined
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -67,6 +67,34 @@ const redisSocketEvents = ({ io, redisHelpers, ioHelpers, logger }) => {
|
||||
|
||||
// Register Socket Events
|
||||
const registerSocketEvents = (socket) => {
|
||||
// DMS reset events (clear per-socket DMS transactional cache)
|
||||
const registerDmsResetEvents = (socket) => {
|
||||
socket.on("dms-reset-context", async ({ jobId, mode } = {}, ack) => {
|
||||
try {
|
||||
// This clears all transactional session data for this socket
|
||||
// (RR txEnvelope/JobData/SelectedCustomer/PendingRO/etc, Fortellis, etc.)
|
||||
await clearSessionTransactionData(socket.id);
|
||||
|
||||
createLogEvent(
|
||||
socket,
|
||||
"debug",
|
||||
`DMS reset-context: cleared transactional session data` +
|
||||
(jobId ? ` (jobId=${jobId})` : "") +
|
||||
(mode ? ` (mode=${mode})` : "")
|
||||
);
|
||||
|
||||
if (typeof ack === "function") {
|
||||
ack({ ok: true });
|
||||
}
|
||||
} catch (error) {
|
||||
createLogEvent(socket, "error", `DMS reset-context failed: ${error.message}`);
|
||||
if (typeof ack === "function") {
|
||||
ack({ ok: false, error: error.message });
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Token Update Events
|
||||
const registerUpdateEvents = (socket) => {
|
||||
let latestTokenTimestamp = 0;
|
||||
@@ -164,7 +192,9 @@ const redisSocketEvents = ({ io, redisHelpers, ioHelpers, logger }) => {
|
||||
// Optional: clear transactional session
|
||||
try {
|
||||
await clearSessionTransactionData(socket.id);
|
||||
} catch {}
|
||||
} catch {
|
||||
//
|
||||
}
|
||||
// Leave all rooms except the default room (socket.id)
|
||||
const rooms = Array.from(socket.rooms).filter((room) => room !== socket.id);
|
||||
for (const room of rooms) {
|
||||
@@ -363,6 +393,7 @@ const redisSocketEvents = ({ io, redisHelpers, ioHelpers, logger }) => {
|
||||
};
|
||||
|
||||
// Call Handlers
|
||||
registerDmsResetEvents(socket);
|
||||
registerRoomAndBroadcastEvents(socket);
|
||||
registerUpdateEvents(socket);
|
||||
registerMessagingEvents(socket);
|
||||
|
||||
@@ -115,6 +115,33 @@ function SetLegacyWebsocketHandlers(io) {
|
||||
socket.on("disconnect", () => {
|
||||
createLogEvent(socket, "DEBUG", `User disconnected.`);
|
||||
});
|
||||
|
||||
// DMS reset for legacy WS (CDK / PBS)
|
||||
socket.on("dms-reset-context", ({ jobId, mode } = {}, ack) => {
|
||||
try {
|
||||
// Clear any per-socket DMS state that can leak across jobs
|
||||
socket.selectedCustomerId = null; // CDK / PBS AR
|
||||
socket.txEnvelope = null; // PBS AP export
|
||||
socket.apAllocations = null; // PBS AP allocations
|
||||
|
||||
createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`DMS reset-context (legacy WS): cleared per-socket state` +
|
||||
(jobId ? ` (jobId=${jobId})` : "") +
|
||||
(mode ? ` (mode=${mode})` : "")
|
||||
);
|
||||
|
||||
if (typeof ack === "function") {
|
||||
ack({ ok: true });
|
||||
}
|
||||
} catch (error) {
|
||||
createLogEvent(socket, "ERROR", `DMS reset-context (legacy WS) failed: ${error.message}`);
|
||||
if (typeof ack === "function") {
|
||||
ack({ ok: false, error: error.message });
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user