Compare commits

...

37 Commits

Author SHA1 Message Date
Dave
043471fdbc feature/IO-3385-Remove-CASL-From-Rome - Remove CASL Report from Rome Customers. 2025-10-15 11:46:51 -04:00
Dave Richer
13a44b9a59 Merged in hotfix/2025-10-10 (pull request #2628)
Hotfix/2025 10 10 - Change BullMQ Key Delimiters based on system logs.

Approved-by: Patrick Fic
2025-10-11 01:35:51 +00:00
Dave
8e6c809fc6 Update 2025-10-10 16:02:56 -04:00
Dave
41afedd02c Change Delemiters in BullMQ, was using an invalid : 2025-10-10 15:58:32 -04:00
Allan Carr
11e0c3e507 Merged in hotfix/2025-10-09 (pull request #2624)
Hotfix/2025 10 09
2025-10-09 17:57:20 +00:00
Allan Carr
6c1c7c9c2c Merged in feature/IO-3386-carfax-rps (pull request #2623)
Feature/IO-3386 carfax rps
2025-10-09 17:55:21 +00:00
Allan Carr
36dfed80fb IO-3386 CARFAX RPS adjustment
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-10-08 19:31:46 -07:00
Dave Richer
e3df22160b Merged in release/2025-10-17 (pull request #2621)
Release/2025 10 17 into master-AIO - IO-3330, IO-3356, IO-3365, IO-3368, IO-3373, IO-3386, IO-3388, IO-3389, IO-3390, IO-3395
2025-10-08 01:22:16 +00:00
Allan Carr
0ccfe6f3aa IO-3368 CARFAX Adjustments for OP_CODE
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-10-07 13:02:44 -07:00
Allan Carr
34d70f6a18 Merged in feature/IO-3373-Dashboard-Component-Redux-Fix (pull request #2618)
IO-3373 Remove Cache Eviction

Approved-by: Dave Richer
2025-10-07 18:40:51 +00:00
Allan Carr
fc1bf213c7 Merged in feature/IO-3395-Postback-Payment-Date (pull request #2614)
IO-3395 Postback Payment Date

Approved-by: Dave Richer
2025-10-07 18:40:28 +00:00
Allan Carr
4dc72986d0 IO-3373 Remove Cache Eviction
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-10-07 11:07:12 -07:00
Allan Carr
f19b9cb8e1 IO-3395 Postback Payment Date
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-10-07 10:59:10 -07:00
Allan Carr
c9ade68dc9 Merged in feature/IO-3386-carfax-rps (pull request #2610)
IO-3386 Cleanup To extension

Approved-by: Dave Richer
2025-10-07 16:16:15 +00:00
Allan Carr
0d247a38d2 Merged in feature/IO-3373-Dashboard-Component-Redux-Fix (pull request #2609)
IO-3373 Dashboard Component Redux Fix

Approved-by: Dave Richer
2025-10-07 16:15:49 +00:00
Dave Richer
595ffa02ba Merged in feature/IO-3390-parts-management-2 (pull request #2615)
feature/IO-3390-Parts-Management-2 - Add Job status patch route, Bodyshop Patch route, remove PAO from simplified parts filter.
2025-10-07 16:13:24 +00:00
Dave
d573335eb0 feature/IO-3390-Parts-Management-2 - Add Job status patch route, Bodyshop Patch route, remove PAO from simplified parts filter. 2025-10-07 12:11:53 -04:00
Allan Carr
bdd5056c9a IO-3395 Postback Payment Date
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-10-06 21:35:31 -07:00
Allan Carr
4f6db827e7 IO-3395 Postback Payment Date
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-10-06 17:50:19 -07:00
Patrick Fic
e50bbc3bcc Merged in hotfix/2025-10-06-remove-amplitude (pull request #2613)
Hotfix/2025 10 06 remove amplitude
2025-10-06 15:35:46 +00:00
Patrick Fic
15792cb0ef Merged in hotfix/2025-10-06-remove-amplitude (pull request #2612)
Hotfix/2025 10 06 remove amplitude
2025-10-06 15:33:23 +00:00
Patrick Fic
856a24d496 Remove console log. 2025-10-06 08:33:01 -07:00
Patrick Fic
74d6bcc004 Remove amplitude. 2025-10-06 08:19:43 -07:00
Allan Carr
2af95de353 IO-3386 Cleanup To extension
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-10-03 12:13:42 -07:00
Allan Carr
7ffb2c1aad IO-3373 Dashboard Component Redux Fix
This properly saves the components with out triggering a redux flush

Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-10-03 12:11:09 -07:00
Allan Carr
cf3f94bf98 Merged in feature/IO-3386-carfax-rps (pull request #2606)
Feature/IO-3386 carfax rps

Approved-by: Patrick Fic
2025-10-03 18:29:39 +00:00
Allan Carr
4899297539 IO-3386 CARFAX RPS
Add Brad Rhoades to Report

Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-10-03 11:24:10 -07:00
Allan Carr
0bd8e862e4 Merged in IO-3389-Parts-Scanning-Part-# (pull request #2605)
IO-3389 Parts Scanning with Part # Update

Approved-by: Patrick Fic
2025-10-03 17:54:21 +00:00
Allan Carr
4afafef98f Merged in feature/IO-3368-QB-Bill-Accumulator (pull request #2607)
Feature/IO-3368 QB Bill Accumulator

Approved-by: Patrick Fic
2025-10-03 17:53:38 +00:00
Allan Carr
48a3220c49 Merged in feature/IO-3365-Bills-Filtering-Server-Side (pull request #2608)
IO-3365 Bills Filtering Server Side

Approved-by: Patrick Fic
2025-10-03 17:51:22 +00:00
Allan Carr
7bc105ea46 IO-3368 QB Bill Accumulator
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-10-02 21:26:41 -07:00
Allan Carr
ac4fcf1694 IO-3368 QB Bill Accumulator
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-10-02 21:22:35 -07:00
Allan Carr
678a87f55d Merge branch 'release/2025-10-17' into feature/IO-3386-carfax-rps
Signed-off-by: Allan Carr <allan@imexsystems.ca>

# Conflicts:
#	hasura/metadata/cron_triggers.yaml
2025-10-02 18:36:42 -07:00
Allan Carr
9e977d9a58 IO-3386 CARFAX RPS
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-10-02 18:34:40 -07:00
Allan Carr
43f822e6ad Merge branch 'master-AIO' into feature/IO-3386-carfax-rps 2025-10-02 18:32:46 -07:00
Allan Carr
7239698a21 IO-3389 Parts Scanning with Part # Update
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-10-02 15:49:31 -07:00
Patrick Fic
5e308f13d3 IO-3386 2025-10-01 14:47:32 -07:00
40 changed files with 2623 additions and 1716 deletions

View File

@@ -0,0 +1,61 @@
# PATCH /integrations/parts-management/job/:id/status
Update (patch) the status of a job created under parts management. This endpoint is only available
for jobs whose parent bodyshop has an `external_shop_id` (i.e., is provisioned for parts
management).
## Endpoint
```
PATCH /integrations/parts-management/job/:id/status
```
- `:id` is the UUID of the job to update.
## Request Headers
- `Authorization`: (if required by your integration middleware)
- `Content-Type: application/json`
## Request Body
Send a JSON object with the following field:
- `status` (string, required): The new status for the job.
Example:
```
PATCH /integrations/parts-management/job/123e4567-e89b-12d3-a456-426614174000/status
Content-Type: application/json
{
"status": "IN_PROGRESS"
}
```
## Success Response
- **200 OK**
- Returns the updated job object with the new status.
```
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"status": "IN_PROGRESS",
...
}
```
## Error Responses
- **400 Bad Request**: Missing status field, or parent bodyshop does not have an `external_shop_id`.
- **404 Not Found**: No job found with the given ID.
- **500 Internal Server Error**: Unexpected error.
## Notes
- Only jobs whose parent bodyshop has an `external_shop_id` can be patched via this route.
- Fields other than `status` will be ignored if included in the request body.
- The route is protected by the same middleware as other parts management endpoints.

View File

@@ -0,0 +1,86 @@
# PATCH /integrations/parts-management/provision/:id
Update (patch) select fields for a parts management bodyshop. Only available for shops that have an
`external_shop_id` (i.e., are provisioned for parts management).
## Endpoint
```
PATCH /integrations/parts-management/provision/:id
```
- `:id` is the UUID of the bodyshop to update.
## Request Headers
- `Authorization`: (if required by your integration middleware)
- `Content-Type: application/json`
## Request Body
Send a JSON object with one or more of the following fields to update:
- `shopname` (string)
- `address1` (string)
- `address2` (string, optional)
- `city` (string)
- `state` (string)
- `zip_post` (string)
- `country` (string)
- `email` (string, shop's email, not user email)
- `timezone` (string)
- `phone` (string)
- `logo_img_path` (object, e.g. `{ src, width, height, headerMargin }`)
Any fields not included in the request body will remain unchanged.
## Example Request
```
PATCH /integrations/parts-management/provision/123e4567-e89b-12d3-a456-426614174000
Content-Type: application/json
{
"shopname": "New Shop Name",
"address1": "123 Main St",
"city": "Springfield",
"state": "IL",
"zip_post": "62704",
"country": "USA",
"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
}
}
```
## Success Response
- **200 OK**
- Returns the updated shop object with the patched fields.
```
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"shopname": "New Shop Name",
...
}
```
## Error Responses
- **400 Bad Request**: No valid fields provided, or shop does not have an `external_shop_id`.
- **404 Not Found**: No shop found with the given ID.
- **500 Internal Server Error**: Unexpected error.
## Notes
- Only shops with an `external_shop_id` can be patched via this route.
- Fields not listed above will be ignored if included in the request body.
- The route is protected by the same middleware as other parts management endpoints.

728
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -8,56 +8,56 @@
"private": true,
"proxy": "http://localhost:4000",
"dependencies": {
"@amplitude/analytics-browser": "^2.23.5",
"@amplitude/analytics-browser": "^2.25.2",
"@ant-design/pro-layout": "^7.22.6",
"@apollo/client": "^3.13.9",
"@emotion/is-prop-valid": "^1.4.0",
"@fingerprintjs/fingerprintjs": "^4.6.1",
"@firebase/analytics": "^0.10.17",
"@firebase/app": "^0.14.2",
"@firebase/app": "^0.14.3",
"@firebase/auth": "^1.10.8",
"@firebase/firestore": "^4.9.1",
"@firebase/firestore": "^4.9.2",
"@firebase/messaging": "^0.12.22",
"@jsreport/browser-client": "^3.1.0",
"@reduxjs/toolkit": "^2.9.0",
"@sentry/cli": "^2.53.0",
"@sentry/cli": "^2.56.0",
"@sentry/react": "^9.43.0",
"@sentry/vite-plugin": "^4.3.0",
"@splitsoftware/splitio-react": "^2.3.1",
"@splitsoftware/splitio-react": "^2.5.0",
"@tanem/react-nprogress": "^5.0.53",
"antd": "^5.27.3",
"antd": "^5.27.4",
"apollo-link-logger": "^2.0.1",
"apollo-link-sentry": "^4.4.0",
"autosize": "^6.0.1",
"axios": "^1.11.0",
"axios": "^1.12.2",
"classnames": "^2.5.1",
"css-box-model": "^1.2.1",
"dayjs": "^1.11.18",
"dayjs-business-days2": "^1.3.0",
"dinero.js": "^1.9.1",
"dotenv": "^17.2.2",
"dotenv": "^17.2.3",
"env-cmd": "^10.1.0",
"exifr": "^7.1.3",
"graphql": "^16.11.0",
"i18next": "^25.5.2",
"i18next": "^25.5.3",
"i18next-browser-languagedetector": "^8.2.0",
"immutability-helper": "^3.1.1",
"libphonenumber-js": "^1.12.15",
"libphonenumber-js": "^1.12.23",
"lightningcss": "^1.30.2",
"logrocket": "^9.0.2",
"markerjs2": "^2.32.6",
"markerjs2": "^2.32.7",
"memoize-one": "^6.0.0",
"normalize-url": "^8.0.2",
"normalize-url": "^8.1.0",
"object-hash": "^3.0.0",
"phone": "^3.1.67",
"posthog-js": "^1.261.7",
"posthog-js": "^1.271.0",
"prop-types": "^15.8.1",
"query-string": "^9.2.2",
"query-string": "^9.3.1",
"raf-schd": "^4.0.3",
"react": "^18.3.1",
"react-big-calendar": "^1.19.4",
"react-color": "^2.19.3",
"react-cookie": "^8.0.1",
"lightningcss": "^1.30.1",
"react-dom": "^18.3.1",
"react-drag-listview": "^2.0.0",
"react-grid-gallery": "^1.0.1",
@@ -73,7 +73,7 @@
"react-resizable": "^3.0.5",
"react-router-dom": "^6.30.0",
"react-sticky": "^6.0.3",
"react-virtuoso": "^4.14.0",
"react-virtuoso": "^4.14.1",
"recharts": "^2.15.2",
"redux": "^5.0.1",
"redux-actions": "^3.0.3",
@@ -81,7 +81,7 @@
"redux-saga": "^1.3.0",
"redux-state-sync": "^3.1.4",
"reselect": "^5.1.1",
"sass": "^1.92.0",
"sass": "^1.93.2",
"socket.io-client": "^4.8.1",
"styled-components": "^6.1.19",
"subscriptions-transport-ws": "^0.11.0",
@@ -133,33 +133,33 @@
"@rollup/rollup-linux-x64-gnu": "4.6.1"
},
"devDependencies": {
"@ant-design/icons": "^6.0.0",
"@ant-design/icons": "^6.1.0",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/preset-react": "^7.27.1",
"@dotenvx/dotenvx": "^1.49.0",
"@dotenvx/dotenvx": "^1.51.0",
"@emotion/babel-plugin": "^11.13.5",
"@emotion/react": "^11.14.0",
"@eslint/js": "^9.33.0",
"@playwright/test": "^1.55.0",
"@sentry/webpack-plugin": "^4.1.1",
"@eslint/js": "^9.37.0",
"@playwright/test": "^1.56.0",
"@sentry/webpack-plugin": "^4.3.0",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.8.0",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.0",
"@vitejs/plugin-react": "^4.6.0",
"browserslist": "^4.25.3",
"browserslist": "^4.26.3",
"browserslist-to-esbuild": "^2.1.1",
"chalk": "^5.6.0",
"eslint": "^9.33.0",
"chalk": "^5.6.2",
"eslint": "^9.37.0",
"eslint-plugin-react": "^7.37.5",
"globals": "^15.15.0",
"jsdom": "^26.0.0",
"memfs": "^4.36.3",
"memfs": "^4.48.1",
"os-browserify": "^0.3.0",
"playwright": "^1.55.0",
"playwright": "^1.56.0",
"react-error-overlay": "^6.1.0",
"redux-logger": "^3.0.6",
"source-map-explorer": "^2.5.3",
"vite": "^7.1.3",
"vite": "^7.1.9",
"vite-plugin-babel": "^1.3.2",
"vite-plugin-eslint": "^1.8.1",
"vite-plugin-node-polyfills": "^0.24.0",

View File

@@ -1,17 +1,17 @@
import Icon, { SyncOutlined } from "@ant-design/icons";
import { cloneDeep } from "lodash";
import { useMutation, useQuery } from "@apollo/client";
import { Button, Dropdown, Space } from "antd";
import { PageHeader } from "@ant-design/pro-layout";
import { useMemo, useState } from "react";
import { useMemo, useState, useEffect } from "react";
import { Responsive, WidthProvider } from "react-grid-layout";
import { useTranslation } from "react-i18next";
import { MdClose } from "react-icons/md";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { logImEXEvent } from "../../firebase/firebase.utils";
import { UPDATE_DASHBOARD_LAYOUT } from "../../graphql/user.queries";
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
import { UPDATE_DASHBOARD_LAYOUT, QUERY_USER_DASHBOARD_LAYOUT } from "../../graphql/user.queries";
import { QUERY_DASHBOARD_BODYSHOP } from "../../graphql/bodyshop.queries";
import { selectCurrentUser } from "../../redux/user/user.selectors";
import AlertComponent from "../alert/alert.component";
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
import { GenerateDashboardData } from "./dashboard-grid.utils";
@@ -24,128 +24,179 @@ import "./dashboard-grid.styles.scss";
const ResponsiveReactGridLayout = WidthProvider(Responsive);
const mapStateToProps = createStructuredSelector({
currentUser: selectCurrentUser,
bodyshop: selectBodyshop
currentUser: selectCurrentUser
});
const mapDispatchToProps = () => ({
//setUserLanguage: language => dispatch(setUserLanguage(language))
});
export function DashboardGridComponent({ currentUser, bodyshop }) {
export function DashboardGridComponent({ currentUser }) {
const { t } = useTranslation();
const [state, setState] = useState(() => {
const persisted = bodyshop.associations[0].user.dashboardlayout;
// Normalize persisted structure to avoid malformed shapes that can cause recursive layout recalculations
if (persisted) {
return {
items: Array.isArray(persisted.items) ? persisted.items : [],
layout: Array.isArray(persisted.layout) ? persisted.layout : [],
layouts: typeof persisted.layouts === "object" && !Array.isArray(persisted.layouts) ? persisted.layouts : {},
cols: persisted.cols
};
}
return { items: [], layout: [], layouts: {}, cols: 12 };
});
const notification = useNotification();
// Memoize the query document so Apollo doesn't treat each render as a brand-new query causing continuous re-fetches
const dashboardQueryDoc = useMemo(() => createDashboardQuery(state.items), [state.items]);
// Constants for layout defaults
const DEFAULT_COLS = 12;
const DEFAULT_Y_POSITION = 1000;
const GRID_BREAKPOINTS = { lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 };
const GRID_COLS = { lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 };
const { loading, error, data, refetch } = useQuery(dashboardQueryDoc, {
// Fetch dashboard layout data
const { data: layoutData } = useQuery(QUERY_USER_DASHBOARD_LAYOUT, {
variables: { email: currentUser.email },
fetchPolicy: "network-only",
nextFetchPolicy: "network-only",
skip: !currentUser?.email
});
// Fetch minimal bodyshop data for components
const {
loading,
error,
data: bodyshopData
} = useQuery(QUERY_DASHBOARD_BODYSHOP, {
fetchPolicy: "network-only",
nextFetchPolicy: "network-only"
});
const [updateLayout] = useMutation(UPDATE_DASHBOARD_LAYOUT);
const handleLayoutChange = async (layout, layouts) => {
// Memoize layout state initialization
const initialState = useMemo(() => {
const persisted = layoutData?.users?.[0]?.dashboardlayout;
if (persisted) {
const { items = [], layout = [], layouts = {}, cols = DEFAULT_COLS } = persisted;
return {
items: Array.isArray(items) ? items : [],
layout: Array.isArray(layout) ? layout : [],
layouts: typeof layouts === "object" && !Array.isArray(layouts) ? layouts : {},
cols
};
}
return { items: [], layout: [], layouts: {}, cols: DEFAULT_COLS };
}, [layoutData]);
const [state, setState] = useState(initialState);
// Update state when layout data changes
useEffect(() => {
if (layoutData?.users?.[0]?.dashboardlayout) {
const { items = [], layout = [], layouts = {}, cols = DEFAULT_COLS } = layoutData.users[0].dashboardlayout;
setState({
items: Array.isArray(items) ? items : [],
layout: Array.isArray(layout) ? layout : [],
layouts: typeof layouts === "object" && !Array.isArray(layouts) ? layouts : {},
cols
});
}
}, [layoutData]);
// Get bodyshop data for components
const bodyshop = bodyshopData?.dashboard_bodyshops?.[0];
// DRY helper function to update layout in database and cache
const updateLayoutAndCache = async (updatedLayout, errorContext = "updating layout") => {
try {
logImEXEvent("dashboard_change_layout");
setState((prev) => ({ ...prev, layout, layouts }));
const result = await updateLayout({
variables: {
email: currentUser.email,
layout: { ...state, layout, layouts }
}
const { data: result } = await updateLayout({
variables: { email: currentUser.email, layout: updatedLayout }
});
if (result?.errors && result.errors.length) {
const errorMessages = result.errors.map((e) => e?.message || String(e));
const { errors = [] } = result?.update_users?.returning?.[0] || {};
if (errors.length) {
const errorMessages = errors.map(({ message }) => message || String(error));
notification.error({
message: t("dashboard.errors.updatinglayout", {
message: errorMessages.join("; ")
})
});
return false;
}
return true;
} catch (err) {
// Catch any unexpected errors (including potential cyclic JSON issues) so the promise never rejects unhandled
console.error("Dashboard layout update failed", err);
console.error(`Dashboard ${errorContext} failed`, err);
notification.error({
message: t("dashboard.errors.updatinglayout", {
message: err?.message || String(err)
})
});
return false;
}
};
const handleRemoveComponent = (key) => {
// Memoize the query document so Apollo doesn't treat each render as a brand-new query causing continuous re-fetches
const dashboardQueryDoc = useMemo(() => createDashboardQuery(state.items), [state.items]);
const {
loading: dashboardLoading,
error: dashboardError,
data: dashboardQueryData,
refetch
} = useQuery(dashboardQueryDoc, {
fetchPolicy: "network-only",
nextFetchPolicy: "network-only"
});
const dashboardData = useMemo(() => GenerateDashboardData(dashboardQueryData), [dashboardQueryData]);
// Memoize existing layout keys to prevent unnecessary recalculations
const existingLayoutKeys = useMemo(() => state.items.map(({ i }) => i), [state.items]);
// Memoize menu items to prevent unnecessary recalculations
const menuItems = useMemo(
() =>
Object.entries(componentList).map(([key, { label }]) => ({
key,
label,
value: key,
disabled: existingLayoutKeys.includes(key)
})),
[existingLayoutKeys]
);
if (loading || dashboardLoading) return <LoadingSkeleton message={t("general.labels.loading")} />;
if (error || dashboardError) return <AlertComponent message={(error || dashboardError).message} type="error" />;
const handleLayoutChange = async (layout, layouts) => {
logImEXEvent("dashboard_change_layout");
setState((prev) => ({ ...prev, layout, layouts }));
await updateLayoutAndCache({ ...state, layout, layouts }, "layout change");
};
const handleRemoveComponent = async (key) => {
logImEXEvent("dashboard_remove_component", { name: key });
const idxToRemove = state.items.findIndex((i) => i.i === key);
const items = cloneDeep(state.items);
items.splice(idxToRemove, 1);
setState({ ...state, items });
const updatedState = { ...state, items: state.items.filter((item) => item.i !== key) };
setState(updatedState);
await updateLayoutAndCache(updatedState, "component removal");
};
const handleAddComponent = (e) => {
// Avoid passing the full AntD menu click event (contains circular refs) to analytics
logImEXEvent("dashboard_add_component", { key: e.key });
const compSpec = componentList[e.key] || {};
const minW = compSpec.minW || 1;
const minH = compSpec.minH || 1;
const baseW = compSpec.w || 2;
const baseH = compSpec.h || 2;
setState((prev) => {
const nextItems = [
...prev.items,
{
i: e.key,
// Position near bottom: use a large y so RGL places it last without triggering cascading relayout loops
x: (prev.items.length * 2) % (prev.cols || 12),
y: 1000,
w: Math.max(baseW, minW),
h: Math.max(baseH, minH)
}
];
return { ...prev, items: nextItems };
});
const handleAddComponent = async ({ key }) => {
logImEXEvent("dashboard_add_component", { key });
const { minW = 1, minH = 1, w: baseW = 2, h: baseH = 2 } = componentList[key] || {};
const nextItems = [
...state.items,
{
i: key,
x: (state.items.length * 2) % (state.cols || DEFAULT_COLS),
y: DEFAULT_Y_POSITION,
w: Math.max(baseW, minW),
h: Math.max(baseH, minH)
}
];
const updatedState = { ...state, items: nextItems };
setState(updatedState);
await updateLayoutAndCache(updatedState, "component addition");
};
const dashboardData = useMemo(() => GenerateDashboardData(data), [data]);
const existingLayoutKeys = state.items.map((i) => i.i);
const menuItems = Object.keys(componentList).map((key) => ({
key: key,
label: componentList[key].label,
value: key,
disabled: existingLayoutKeys.includes(key)
}));
const menu = { items: menuItems, onClick: handleAddComponent };
if (error) return <AlertComponent message={error.message} type="error" />;
return (
<div>
<PageHeader
extra={
<Space>
<Button onClick={() => refetch()}>
<Button onClick={refetch}>
<SyncOutlined />
</Button>
<Dropdown menu={menu} trigger={["click"]}>
@@ -157,22 +208,19 @@ export function DashboardGridComponent({ currentUser, bodyshop }) {
<ResponsiveReactGridLayout
className="layout"
breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}
cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }}
breakpoints={GRID_BREAKPOINTS}
cols={GRID_COLS}
layouts={state.layouts}
onLayoutChange={handleLayoutChange}
>
{state.items.map((item) => {
const spec = componentList[item.i] || {};
const TheComponent = spec.component;
const minW = spec.minW || 1;
const minH = spec.minH || 1;
// Ensure current width/height respect minimums to avoid react-grid-layout prop warnings
const { component: TheComponent, minW = 1, minH = 1, w: specW, h: specH } = componentList[item.i] || {};
const safeItem = {
...item,
w: Math.max(item.w || spec.w || minW, minW),
h: Math.max(item.h || spec.h || minH, minH)
w: Math.max(item.w || specW || minW, minW),
h: Math.max(item.h || specH || minH, minH)
};
return (
<div
key={safeItem.i}

View File

@@ -97,7 +97,7 @@ export function JobLinesComponent({
filteredInfo: {
...(isPartsEntry
? {
part_type: ["PAN", "PAC", "PAR", "PAL", "PAA", "PAM", "PAP", "PAS", "PASL", "PAG", "PAO"]
part_type: ["PAN", "PAC", "PAR", "PAL", "PAA", "PAM", "PAP", "PAS", "PASL", "PAG"] //"PAO" Removed by request
}
: {})
}

View File

@@ -425,7 +425,15 @@ export function ShopInfoGeneral({ form, bodyshop }) {
]
: [])
]
: [])
: []),
<Form.Item
key="accumulatePayableLines"
name={["accountingconfig", "accumulatePayableLines"]}
label={t("bodyshop.fields.accumulatePayableLines")}
valuePropName="checked"
>
<Switch />
</Form.Item>
]}
</LayoutFormRow>
<FeatureWrapper featureName="scoreboard" noauth={() => null}>

View File

@@ -4,7 +4,7 @@ import { getAuth, updatePassword, updateProfile } from "@firebase/auth";
import { getFirestore } from "@firebase/firestore";
import { getMessaging, getToken, onMessage } from "@firebase/messaging";
import { store } from "../redux/store";
import * as amplitude from '@amplitude/analytics-browser';
//import * as amplitude from '@amplitude/analytics-browser';
import posthog from 'posthog-js'
const config = JSON.parse(import.meta.env.VITE_APP_FIREBASE_CONFIG);
@@ -91,14 +91,14 @@ export const logImEXEvent = (eventName, additionalParams, stateProp = null) => {
// dbevent: false,
// env: `master-AIO|${import.meta.env.VITE_APP_GIT_SHA_DATE}`
// });
console.log(
"%c[Analytics]",
"background-color: green ;font-weight:bold;",
eventName,
eventParams
);
// console.log(
// "%c[Analytics]",
// "background-color: green ;font-weight:bold;",
// eventName,
// eventParams
// );
logEvent(analytics, eventName, eventParams);
amplitude.track(eventName, eventParams);
//amplitude.track(eventName, eventParams);
posthog.capture(eventName, eventParams);
} finally {

View File

@@ -363,3 +363,25 @@ export const GET_ACTIVE_EMPLOYEES_IN_SHOP = gql`
}
}
`;
export const QUERY_MINIMAL_BODYSHOP = gql`
query QUERY_MINIMAL_BODYSHOP {
bodyshops(where: { associations: { active: { _eq: true } } }) {
id
shopname
associations(where: { active: { _eq: true } }) {
user {
email
}
}
}
}
`;
export const QUERY_DASHBOARD_BODYSHOP = gql`
query QUERY_DASHBOARD_BODYSHOP {
dashboard_bodyshops: bodyshops(where: { associations: { active: { _eq: true } } }) {
id
prodtargethrs
md_ro_statuses
}
}
`;

View File

@@ -135,3 +135,12 @@ export const UPDATE_NOTIFICATIONS_AUTOADD = gql`
}
}
`;
export const QUERY_USER_DASHBOARD_LAYOUT = gql`
query QUERY_USER_DASHBOARD_LAYOUT($email: String!) {
users(where: { email: { _eq: $email } }) {
email
dashboardlayout
}
}
`;

View File

@@ -14,7 +14,7 @@ import { persistor, store } from "./redux/store";
import reportWebVitals from "./reportWebVitals";
import "./translations/i18n";
import "./utils/CleanAxios";
import * as amplitude from "@amplitude/analytics-browser";
//import * as amplitude from "@amplitude/analytics-browser";
import { PostHogProvider } from "posthog-js/react";
import posthog from "posthog-js";
@@ -26,23 +26,23 @@ registerSW({ immediate: true });
// Dinero.globalLocale = "en-CA";
Dinero.globalRoundingMode = "HALF_EVEN";
amplitude.init(import.meta.env.VITE_APP_AMP_KEY, {
defaultTracking: true,
serverUrl: import.meta.env.VITE_APP_AMP_URL
// {
// attribution: {
// excludeReferrers: true,
// initialEmptyValue: true,
// resetSessionOnNewCampaign: true,
// },
// fileDownloads: true,
// formInteractions: true,
// pageViews: {
// trackHistoryChanges: 'all'
// },
// sessions: true
// }
});
// amplitude.init(import.meta.env.VITE_APP_AMP_KEY, {
// defaultTracking: true,
// serverUrl: import.meta.env.VITE_APP_AMP_URL
// // {
// // attribution: {
// // excludeReferrers: true,
// // initialEmptyValue: true,
// // resetSessionOnNewCampaign: true,
// // },
// // fileDownloads: true,
// // formInteractions: true,
// // pageViews: {
// // trackHistoryChanges: 'all'
// // },
// // sessions: true
// // }
// });
posthog.init(import.meta.env.VITE_PUBLIC_POSTHOG_KEY, {
autocapture: false,

View File

@@ -49,7 +49,7 @@ import {
validatePasswordResetSuccess
} from "./user.actions";
import UserActionTypes from "./user.types";
import * as amplitude from '@amplitude/analytics-browser';
//import * as amplitude from '@amplitude/analytics-browser';
import posthog from 'posthog-js';
const fpPromise = FingerprintJS.load();
@@ -92,7 +92,7 @@ export function* isUserAuthenticated() {
}
LogRocket.identify(user.email);
amplitude.setUserId(user.email);
//amplitude.setUserId(user.email);
posthog.identify(user.email);
const eulaQuery = yield client.query({
@@ -139,7 +139,7 @@ export function* signOutStart() {
imexshopid: state.user.bodyshop.imexshopid,
type: "messaging"
});
amplitude.reset();
//amplitude.reset();
} catch {
console.log("No FCM token. Skipping unsubscribe.");
}
@@ -365,7 +365,7 @@ export function* SetAuthLevelFromShopDetails({ payload }) {
}
try {
amplitude.setGroup('Shop', payload.shopname);
//amplitude.setGroup('Shop', payload.shopname);
window.$crisp.push(["set", "user:company", [payload.shopname]]);
if (authRecord[0] && authRecord[0].user.validemail) {
window.$crisp.push(["set", "user:email", [authRecord[0].user.email]]);

View File

@@ -281,6 +281,7 @@
},
"fields": {
"ReceivableCustomField": "QBO Receivable Custom Field {{number}}",
"accumulatePayableLines": "Accumulate Payable Lines",
"address1": "Address 1",
"address2": "Address 2",
"appt_alt_transport": "Appointment Alternative Transportation Options",

View File

@@ -281,6 +281,7 @@
},
"fields": {
"ReceivableCustomField": "",
"accumulatePayableLines": "",
"address1": "",
"address2": "",
"appt_alt_transport": "",

View File

@@ -281,6 +281,7 @@
},
"fields": {
"ReceivableCustomField": "",
"accumulatePayableLines": "",
"address1": "",
"address2": "",
"appt_alt_transport": "",

View File

@@ -15,21 +15,29 @@ export const EmailSettings = {
export const TemplateList = (type, context) => {
//const { bodyshop } = store.getState().user;
const casl = InstanceRenderManager({
imex: {
casl_authorization: {
title: i18n.t("printcenter.jobs.casl_authorization"),
description: "",
subject: i18n.t("printcenter.jobs.casl_authorization"),
key: "casl_authorization",
disabled: false,
group: "authorization",
regions: {
CA: true
}
}
},
rome: {}
});
return {
//If there's no type or the type is job, send it back.
...(!type || type === "job"
? {
casl_authorization: {
title: i18n.t("printcenter.jobs.casl_authorization"),
description: "",
subject: i18n.t("printcenter.jobs.casl_authorization"),
key: "casl_authorization",
disabled: false,
group: "authorization",
regions: {
CA: true
}
},
...casl,
fippa_authorization: {
title: i18n.t("printcenter.jobs.fippa_authorization"),
description: "",

View File

@@ -207,6 +207,9 @@ services:
aws --endpoint-url=http://localstack:4566 secretsmanager create-secret --name CHATTER_PRIVATE_KEY --secret-string file:///tmp/certs/io-ftp-test.key
aws --endpoint-url=http://localstack:4566 logs create-log-group --log-group-name development --region ca-central-1
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket imex-large-log --create-bucket-configuration LocationConstraint=ca-central-1
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket imex-carfax-uploads --create-bucket-configuration LocationConstraint=ca-central-1
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket rome-carfax-uploads --create-bucket-configuration LocationConstraint=ca-central-1
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket rps-carfax-uploads --create-bucket-configuration LocationConstraint=ca-central-1
"
networks:

View File

@@ -120,6 +120,8 @@ services:
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket imex-job-totals --create-bucket-configuration LocationConstraint=ca-central-1
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket parts-estimates --create-bucket-configuration LocationConstraint=ca-central-1
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket imex-carfax-uploads --create-bucket-configuration LocationConstraint=ca-central-1
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket rome-carfax-uploads --create-bucket-configuration LocationConstraint=ca-central-1
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket rps-carfax-uploads --create-bucket-configuration LocationConstraint=ca-central-1
"
# Node App: The Main IMEX API
node-app:

View File

@@ -15,6 +15,15 @@
- name: x-imex-auth
value_from_env: DATAPUMP_AUTH
comment: Project Mexico
- name: CARFAX RPS Data Pump
webhook: '{{HASURA_API_URL}}/data/carfaxrps'
schedule: 15 7 * * 0
include_in_metadata: true
payload: {}
headers:
- name: x-imex-auth
value_from_env: DATAPUMP_AUTH
comment: Project Mexico
- name: Chatter Data Pump
webhook: '{{HASURA_API_URL}}/data/chatter'
schedule: 45 5 * * *

2155
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -18,40 +18,40 @@
"job-totals-fixtures:local": "docker exec node-app /usr/bin/node /app/download-job-totals-fixtures.js"
},
"dependencies": {
"@aws-sdk/client-cloudwatch-logs": "^3.882.0",
"@aws-sdk/client-elasticache": "^3.882.0",
"@aws-sdk/client-s3": "^3.882.0",
"@aws-sdk/client-secrets-manager": "^3.882.0",
"@aws-sdk/client-ses": "^3.882.0",
"@aws-sdk/credential-provider-node": "^3.882.0",
"@aws-sdk/lib-storage": "^3.882.0",
"@aws-sdk/s3-request-presigner": "^3.882.0",
"@aws-sdk/client-cloudwatch-logs": "^3.901.0",
"@aws-sdk/client-elasticache": "^3.901.0",
"@aws-sdk/client-s3": "^3.901.0",
"@aws-sdk/client-secrets-manager": "^3.901.0",
"@aws-sdk/client-ses": "^3.901.0",
"@aws-sdk/credential-provider-node": "^3.901.0",
"@aws-sdk/lib-storage": "^3.903.0",
"@aws-sdk/s3-request-presigner": "^3.901.0",
"@opensearch-project/opensearch": "^2.13.0",
"@socket.io/admin-ui": "^0.5.1",
"@socket.io/redis-adapter": "^8.3.0",
"archiver": "^7.0.1",
"aws4": "^1.13.2",
"axios": "^1.11.0",
"axios": "^1.12.2",
"better-queue": "^3.8.12",
"bullmq": "^5.58.5",
"bullmq": "^5.61.0",
"chart.js": "^4.5.0",
"cloudinary": "^2.7.0",
"compression": "^1.8.1",
"cookie-parser": "^1.4.7",
"cors": "^2.8.5",
"crisp-status-reporter": "^1.2.2",
"dd-trace": "^5.65.0",
"dd-trace": "^5.70.0",
"dinero.js": "^1.9.1",
"dotenv": "^17.2.2",
"dotenv": "^17.2.3",
"express": "^4.21.1",
"firebase-admin": "^13.5.0",
"graphql": "^16.11.0",
"graphql-request": "^6.1.0",
"intuit-oauth": "^4.2.0",
"ioredis": "^5.7.0",
"ioredis": "^5.8.1",
"json-2-csv": "^5.5.9",
"jsonwebtoken": "^9.0.2",
"juice": "^11.0.1",
"juice": "^11.0.3",
"lodash": "^4.17.21",
"moment": "^2.30.1",
"moment-timezone": "^0.6.0",
@@ -62,22 +62,22 @@
"query-string": "7.1.3",
"recursive-diff": "^1.0.9",
"rimraf": "^6.0.1",
"skia-canvas": "^3.0.6",
"soap": "^1.3.0",
"skia-canvas": "^3.0.8",
"soap": "^1.5.0",
"socket.io": "^4.8.1",
"socket.io-adapter": "^2.5.5",
"ssh2-sftp-client": "^11.0.0",
"twilio": "^5.9.0",
"twilio": "^5.10.2",
"uuid": "^11.1.0",
"winston": "^3.17.0",
"winston": "^3.18.3",
"winston-cloudwatch": "^6.3.0",
"xml2js": "^0.6.2",
"xmlbuilder2": "^3.1.1",
"yazl": "^3.3.1"
},
"devDependencies": {
"@eslint/js": "^9.35.0",
"eslint": "^9.35.0",
"@eslint/js": "^9.37.0",
"eslint": "^9.37.0",
"eslint-plugin-react": "^7.37.5",
"globals": "^15.15.0",
"mock-require": "^3.0.3",

View File

@@ -205,21 +205,49 @@ async function InsertVendorRecord(oauthClient, qbo_realmId, req, bill) {
async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop) {
const { accounts, taxCodes, classes } = await QueryMetaData(oauthClient, qbo_realmId, req, bill.job.shopid);
let lines;
if (bodyshop.accountingconfig.accumulatePayableLines === true) {
lines = Object.values(
bill.billlines.reduce((acc, il) => {
const { cost_center, actual_cost, quantity = 1 } = il;
const lines = bill.billlines.map((il) =>
generateBillLine(
il,
accounts,
bill.job.class,
bodyshop.md_responsibility_centers.sales_tax_codes,
classes,
taxCodes,
bodyshop.md_responsibility_centers.costs,
bodyshop.accountingconfig,
bodyshop.region_config
)
);
if (!acc[cost_center]) {
acc[cost_center] = { ...il, actual_cost: 0, quantity: 1 };
}
acc[cost_center].actual_cost += Math.round(actual_cost * quantity * 100);
return acc;
}, {})
).map((il) => {
il.actual_cost /= 100;
return generateBillLine(
il,
accounts,
bill.job.class,
bodyshop.md_responsibility_centers.sales_tax_codes,
classes,
taxCodes,
bodyshop.md_responsibility_centers.costs,
bodyshop.accountingconfig,
bodyshop.region_config
);
});
} else {
lines = bill.billlines.map((il) =>
generateBillLine(
il,
accounts,
bill.job.class,
bodyshop.md_responsibility_centers.sales_tax_codes,
classes,
taxCodes,
bodyshop.md_responsibility_centers.costs,
bodyshop.accountingconfig,
bodyshop.region_config
)
);
}
//QB USA with GST
//This was required for the No. 1 Collision Group.
if (
@@ -241,7 +269,7 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop)
Amount: Dinero({
amount: Math.round(
bill.billlines.reduce((acc, val) => {
return acc + (val.applicable_taxes?.federal ? (val.actual_cost * val.quantity ?? 0) : 0);
return acc + (val.applicable_taxes?.federal ? val.actual_cost * val.quantity || 0 : 0);
}, 0) * 100
)
})

View File

@@ -46,6 +46,28 @@ exports.default = async (req, res) => {
};
const generateBill = (bill, bodyshop) => {
let lines;
if (bodyshop.accountingconfig.accumulatePayableLines === true) {
lines = Object.values(
bill.billlines.reduce((acc, il) => {
const { cost_center, actual_cost, quantity = 1 } = il;
if (!acc[cost_center]) {
acc[cost_center] = { ...il, actual_cost: 0, quantity: 1 };
}
acc[cost_center].actual_cost += Math.round(actual_cost * quantity * 100);
return acc;
}, {})
).map((il) => {
il.actual_cost /= 100;
return generateBillLine(il, bodyshop.md_responsibility_centers, bill.job.class);
});
} else {
lines = bill.billlines.map((il) => generateBillLine(il, bodyshop.md_responsibility_centers, bill.job.class));
}
const billQbxmlObj = {
QBXML: {
QBXMLMsgsRq: {
@@ -67,9 +89,7 @@ const generateBill = (bill, bodyshop) => {
}),
RefNumber: bill.invoice_number,
Memo: `RO ${bill.job.ro_number || ""}`,
ExpenseLineAdd: bill.billlines.map((il) =>
generateBillLine(il, bodyshop.md_responsibility_centers, bill.job.class)
)
ExpenseLineAdd: lines
}
}
}

442
server/data/carfax-rps.js Normal file
View File

@@ -0,0 +1,442 @@
const queries = require("../graphql-client/queries");
const moment = require("moment-timezone");
const logger = require("../utils/logger");
const fs = require("fs");
const client = require("../graphql-client/graphql-client").rpsClient;
const { sendServerEmail, sendMexicoBillingEmail } = require("../email/sendemail");
const crypto = require("crypto");
const { ftpSetup, uploadToS3 } = require("./carfax");
let Client = require("ssh2-sftp-client");
const AHDateFormat = "YYYY-MM-DD";
const NON_ASCII_REGEX = /[^\x20-\x7E]/g;
const S3_BUCKET_NAME = "rps-carfax-uploads";
const carfaxExportRps = async (req, res) => {
// Only process if in production environment.
if (process.env.NODE_ENV !== "production") {
return res.sendStatus(403);
}
// Only process if the appropriate token is provided.
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
return res.sendStatus(401);
}
// Send immediate response and continue processing.
res.status(202).json({
success: true,
message: "Processing request ...",
timestamp: new Date().toISOString()
});
try {
logger.log("CARFAX-RPS-start", "DEBUG", "api", null, null);
const allJSONResults = [];
const allErrors = [];
const { bodyshops } = await client.request(queries.GET_CARFAX_RPS_SHOPS); //Query for the List of Bodyshop Clients.
const specificShopIds = req.body.bodyshopIds; // ['uuid];
const { start, end, skipUpload, ignoreDateFilter } = req.body; //YYYY-MM-DD
const shopsToProcess =
specificShopIds?.length > 0 ? bodyshops.filter((shop) => specificShopIds.includes(shop.id)) : bodyshops;
logger.log("CARFAX-RPS-shopsToProcess-generated", "DEBUG", "api", null, null);
if (shopsToProcess.length === 0) {
logger.log("CARFAX-RPS-shopsToProcess-empty", "DEBUG", "api", null, null);
return;
}
await processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allJSONResults, allErrors);
await sendServerEmail({
subject: `Project Mexico RPS Report ${moment().format("MM-DD-YY")}`,
text: `Total Count: ${allJSONResults.reduce((a, v) => a + v.count, 0)}\nErrors:\n${JSON.stringify(allErrors, null, 2)}\n\nUploaded:\n${JSON.stringify(
allJSONResults.map((x) => ({
imexshopid: x.imexshopid,
filename: x.filename,
count: x.count,
result: x.result
})),
null,
2
)}`,
to: ["bradley.rhoades@convenient-brands.com"]
});
logger.log("CARFAX-RPS-end", "DEBUG", "api", null, null);
} catch (error) {
logger.log("CARFAX-RPS-error", "ERROR", "api", null, { error: error.message, stack: error.stack });
}
};
async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allJSONResults, allErrors) {
for (const bodyshop of shopsToProcess) {
const shopid = bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
const erroredJobs = [];
try {
logger.log("CARFAX-RPS-start-shop-extract", "DEBUG", "api", bodyshop.id, {
shopname: bodyshop.shopname
});
const { jobs, bodyshops_by_pk } = await client.request(queries.CARFAX_RPS_QUERY, {
bodyshopid: bodyshop.id,
...(ignoreDateFilter
? {}
: {
starttz: start ? moment(start).startOf("day") : moment().subtract(7, "days").startOf("day"),
...(end && { endtz: moment(end).endOf("day") }),
start: start
? moment(start).startOf("day").format(AHDateFormat)
: moment().subtract(7, "days").startOf("day").format(AHDateFormat),
...(end && { endtz: moment(end).endOf("day").format(AHDateFormat) })
})
});
const carfaxObject = {
shopid: shopid,
shop_name: bodyshop.shopname,
job: jobs.map((j) =>
CreateRepairOrderTag({ ...j, bodyshop: bodyshops_by_pk }, function ({ job, error }) {
erroredJobs.push({ job: job, error: error.toString() });
})
)
};
if (erroredJobs.length > 0) {
logger.log("CARFAX-RPS-failed-jobs", "ERROR", "api", bodyshop.id, {
count: erroredJobs.length,
jobs: JSON.stringify(erroredJobs.map((j) => j.job.id))
});
}
const jsonObj = {
bodyshopid: bodyshop.id,
imexshopid: shopid,
json: JSON.stringify(carfaxObject, null, 2),
filename: `${shopid}_${moment().format("DDMMYYYY_HHMMss")}.json`,
count: carfaxObject.job.length
};
if (skipUpload) {
fs.writeFileSync(`./logs/${jsonObj.filename}`, jsonObj.json);
uploadToS3(jsonObj, S3_BUCKET_NAME);
} else {
await uploadViaSFTP(jsonObj);
await sendMexicoBillingEmail({
subject: `${shopid.replace(/_/g, "").toUpperCase()}_MexicoRPS_${moment().format("MMDDYYYY")} ROs ${jsonObj.count} Error ${errorCode(jsonObj)}`,
text: `Errors:\n${JSON.stringify(
erroredJobs.map((ej) => ({
jobid: ej.job?.id,
error: ej.error
})),
null,
2
)}\n\nUploaded:\n${JSON.stringify(
{
bodyshopid: bodyshop.id,
imexshopid: shopid,
count: jsonObj.count,
filename: jsonObj.filename,
result: jsonObj.result
},
null,
2
)}`
});
}
allJSONResults.push({
bodyshopid: bodyshop.id,
imexshopid: shopid,
count: jsonObj.count,
filename: jsonObj.filename,
result: jsonObj.result
});
logger.log("CARFAX-RPS-end-shop-extract", "DEBUG", "api", bodyshop.id, {
shopname: bodyshop.shopname
});
} catch (error) {
//Error at the shop level.
logger.log("CARFAX-RPS-error-shop", "ERROR", "api", bodyshop.id, { error: error.message, stack: error.stack });
allErrors.push({
bodyshopid: bodyshop.id,
imexshopid: shopid,
CARFAXid: bodyshop.CARFAXid,
fatal: true,
errors: [error.toString()]
});
} finally {
allErrors.push({
bodyshopid: bodyshop.id,
imexshopid: shopid,
CARFAXid: bodyshop.CARFAXid,
errors: erroredJobs.map((ej) => ({
jobid: ej.job?.id,
error: ej.error
}))
});
}
}
}
async function uploadViaSFTP(jsonObj) {
const sftp = new Client();
sftp.on("error", (errors) =>
logger.log("CARFAX-RPS-sftp-connection-error", "ERROR", "api", jsonObj.bodyshopid, {
error: errors.message,
stack: errors.stack
})
);
try {
// Upload to S3 first.
uploadToS3(jsonObj, S3_BUCKET_NAME);
//Connect to the FTP and upload all.
await sftp.connect(ftpSetup);
try {
jsonObj.result = await sftp.put(Buffer.from(jsonObj.json), `${jsonObj.filename}`);
logger.log("CARFAX-RPS-sftp-upload", "DEBUG", "api", jsonObj.bodyshopid, {
imexshopid: jsonObj.imexshopid,
filename: jsonObj.filename,
result: jsonObj.result
});
} catch (error) {
logger.log("CARFAX-RPS-sftp-upload-error", "ERROR", "api", jsonObj.bodyshopid, {
filename: jsonObj.filename,
error: error.message,
stack: error.stack
});
throw error;
}
} catch (error) {
logger.log("CARFAX-RPS-sftp-error", "ERROR", "api", jsonObj.bodyshopid, {
error: error.message,
stack: error.stack
});
throw error;
} finally {
sftp.end();
}
}
const CreateRepairOrderTag = (job, errorCallback) => {
try {
const subtotalEntry = job.totals.find((total) => total.TTL_TYPECD === "");
const subtotal = subtotalEntry ? subtotalEntry.T_AMT : 0;
const ret = {
ro_number: crypto.createHash("md5").update(job.id, "utf8").digest("hex"),
v_vin: job.v_vin || "",
v_year: job.v_model_yr
? parseInt(job.v_model_yr.match(/\d/g))
? parseInt(job.v_model_yr.match(/\d/g).join(""), 10)
: ""
: "",
v_make: job.v_makedesc || "",
v_model: job.v_model || "",
date_estimated: moment(job.created_at).tz("America/Winnipeg").format(AHDateFormat) || "",
data_opened: moment(job.created_at).tz("America/Winnipeg").format(AHDateFormat) || "",
date_invoiced: [job.close_date, job.created_at].find((date) => date)
? moment([job.close_date, job.created_at].find((date) => date))
.tz("America/Winnipeg")
.format(AHDateFormat)
: "",
loss_date: job.loss_date ? moment(job.loss_date).format(AHDateFormat) : "",
ins_co_nm: job.ins_co_nm || "",
loss_desc: job.loss_desc || "",
theft_ind: job.theft_ind,
tloss_ind: job.tlos_ind,
subtotal: subtotal,
areaofdamage: {
impact1: generateAreaOfDamage(job.impact_1 || ""),
impact2: generateAreaOfDamage(job.impact_2 || "")
},
jobLines: job.joblines.length > 0 ? job.joblines.map((jl) => GenerateDetailLines(jl)) : [generateNullDetailLine()]
};
return ret;
} catch (error) {
logger.log("CARFAX-RPS-job-data-error", "ERROR", "api", null, { error: error.message, stack: error.stack });
errorCallback({ jobid: job.id, error });
}
};
const GenerateDetailLines = (line) => {
const ret = {
line_desc: line.line_desc ? line.line_desc.replace(NON_ASCII_REGEX, "") : null,
oem_partno: line.oem_partno ? line.oem_partno.replace(NON_ASCII_REGEX, "") : null,
alt_partno: line.alt_partno ? line.alt_partno.replace(NON_ASCII_REGEX, "") : null,
op_code: line.lbr_op || null,
op_code_desc: generateOpCodeDescription(line.lbr_op),
lbr_ty: generateLaborType(line.mod_lbr_ty),
lbr_hrs: line.mod_lb_hrs || 0,
part_qty: line.part_qty || 0,
part_type: generatePartType(line.part_type),
act_price: line.act_price || 0
};
return ret;
};
const generateNullDetailLine = () => {
return {
line_desc: null,
oem_partno: null,
alt_partno: null,
lbr_ty: null,
part_qty: 0,
part_type: null,
act_price: 0
};
};
const generateAreaOfDamage = (loc) => {
const areaMap = {
"01": "Right Front Corner",
"02": "Right Front Side",
"03": "Right Side",
"04": "Right Rear Side",
"05": "Right Rear Corner",
"06": "Rear",
"07": "Left Rear Corner",
"08": "Left Rear Side",
"09": "Left Side",
10: "Left Front Side",
11: "Left Front Corner",
12: "Front",
13: "Rollover",
14: "Uknown",
15: "Total Loss",
16: "Non-Collision",
19: "All Over",
25: "Hood",
26: "Deck Lid",
27: "Roof",
28: "Undercarriage",
34: "All Over"
};
return areaMap[loc] || null;
};
const generateLaborType = (type) => {
const laborTypeMap = {
laa: "Aluminum",
lab: "Body",
lad: "Diagnostic",
lae: "Electrical",
laf: "Frame",
lag: "Glass",
lam: "Mechanical",
lar: "Refinish",
las: "Structural",
lau: "Other - LAU",
la1: "Other - LA1",
la2: "Other - LA2",
la3: "Other - LA3",
la4: "Other - LA4",
null: "Other",
mapa: "Paint Materials",
mash: "Shop Materials",
rates_subtotal: "Labor Total",
"timetickets.labels.shift": "Shift",
"timetickets.labels.amshift": "Morning Shift",
"timetickets.labels.ambreak": "Morning Break",
"timetickets.labels.pmshift": "Afternoon Shift",
"timetickets.labels.pmbreak": "Afternoon Break",
"timetickets.labels.lunch": "Lunch"
};
return laborTypeMap[type?.toLowerCase()] || null;
};
const generatePartType = (type) => {
const partTypeMap = {
paa: "Aftermarket",
pae: "Existing",
pag: "Glass",
pal: "LKQ",
pan: "OEM",
pao: "Other",
pas: "Sublet",
pasl: "Sublet",
ccc: "CC Cleaning",
ccd: "CC Damage Waiver",
ccdr: "CC Daily Rate",
ccf: "CC Refuel",
ccm: "CC Mileage",
prt_dsmk_total: "Line Item Adjustment"
};
return partTypeMap[type?.toLowerCase()] || null;
};
const generateOpCodeDescription = (type) => {
const opCodeMap = {
OP0: "REMOVE / REPLACE PARTIAL",
OP1: "REFINISH / REPAIR",
OP10: "REPAIR , PARTIAL",
OP100: "REPLACE PRE-PRICED",
OP101: "REMOVE/REPLACE RECYCLED PART",
OP103: "REMOVE / REPLACE PARTIAL",
OP104: "REMOVE / REPLACE PARTIAL LABOUR",
OP105: "!!ADJUST MANUALLY!!",
OP106: "REPAIR , PARTIAL",
OP107: "CHIPGUARD",
OP108: "MULTI TONE",
OP109: "REPLACE PRE-PRICED",
OP11: "REMOVE / REPLACE",
OP110: "REFINISH / REPAIR",
OP111: "REMOVE / REPLACE",
OP112: "REMOVE / REPLACE",
OP113: "REPLACE PRE-PRICED",
OP114: "REPLACE PRE-PRICED",
OP12: "REMOVE / REPLACE PARTIAL",
OP120: "REPAIR , PARTIAL",
OP13: "ADDITIONAL COSTS",
OP14: "ADDITIONAL OPERATIONS",
OP15: "BLEND",
OP16: "SUBLET",
OP17: "POLICY LIMIT ADJUSTMENT",
OP18: "APPEAR ALLOWANCE",
OP2: "REMOVE / INSTALL",
OP24: "CHIPGUARD",
OP25: "TWO TONE",
OP26: "PAINTLESS DENT REPAIR",
OP260: "SUBLET",
OP3: "ADDITIONAL LABOR",
OP4: "ALIGNMENT",
OP5: "OVERHAUL",
OP6: "REFINISH",
OP7: "INSPECT",
OP8: "CHECK / ADJUST",
OP9: "REPAIR"
};
return opCodeMap[type?.toUpperCase()] || null;
};
const errorCode = ({ count, filename, results }) => {
if (count === 0) return 1;
if (!filename) return 3;
const sftpErrorCode = results?.sftpError?.code;
if (sftpErrorCode && ["ECONNREFUSED", "ENOTFOUND", "ETIMEDOUT", "ECONNRESET"].includes(sftpErrorCode)) {
return 4;
}
if (sftpErrorCode) return 7;
return 0;
};
module.exports = {
default: carfaxExportRps,
ftpSetup
};

View File

@@ -37,12 +37,12 @@ const S3_BUCKET_NAME = InstanceManager({
const region = InstanceManager.InstanceRegion;
const isLocal = isString(process.env?.LOCALSTACK_HOSTNAME) && !isEmpty(process.env?.LOCALSTACK_HOSTNAME);
const uploadToS3 = (jsonObj) => {
const uploadToS3 = (jsonObj, bucketName = S3_BUCKET_NAME) => {
const webPath = isLocal
? `https://${S3_BUCKET_NAME}.s3.localhost.localstack.cloud:4566/${jsonObj.filename}`
: `https://${S3_BUCKET_NAME}.s3.${region}.amazonaws.com/${jsonObj.filename}`;
? `https://${bucketName}.s3.localhost.localstack.cloud:4566/${jsonObj.filename}`
: `https://${bucketName}.s3.${region}.amazonaws.com/${jsonObj.filename}`;
uploadFileToS3({ bucketName: S3_BUCKET_NAME, key: jsonObj.filename, content: jsonObj.json })
uploadFileToS3({ bucketName: bucketName, key: jsonObj.filename, content: jsonObj.json })
.then(() => {
logger.log("CARFAX-s3-upload", "DEBUG", "api", jsonObj.bodyshopid, {
imexshopid: jsonObj.imexshopid,
@@ -61,7 +61,7 @@ const uploadToS3 = (jsonObj) => {
});
};
exports.default = async (req, res) => {
const carfaxExport = async (req, res) => {
// Only process if in production environment.
if (process.env.NODE_ENV !== "production") {
return res.sendStatus(403);
@@ -80,7 +80,7 @@ exports.default = async (req, res) => {
try {
logger.log("CARFAX-start", "DEBUG", "api", null, null);
const allXMLResults = [];
const allJSONResults = [];
const allErrors = [];
const { bodyshops } = await client.request(queries.GET_CARFAX_SHOPS); //Query for the List of Bodyshop Clients.
@@ -96,12 +96,12 @@ exports.default = async (req, res) => {
return;
}
await processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allXMLResults, allErrors);
await processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allJSONResults, allErrors);
await sendServerEmail({
subject: `Project Mexico Report ${moment().format("MM-DD-YY")}`,
text: `Errors:\n${JSON.stringify(allErrors, null, 2)}\n\nUploaded:\n${JSON.stringify(
allXMLResults.map((x) => ({
text: `Total Count: ${allJSONResults.reduce((a, v) => a + v.count, 0)}\nErrors:\n${JSON.stringify(allErrors, null, 2)}\n\nUploaded:\n${JSON.stringify(
allJSONResults.map((x) => ({
imexshopid: x.imexshopid,
filename: x.filename,
count: x.count,
@@ -109,7 +109,8 @@ exports.default = async (req, res) => {
})),
null,
2
)}`
)}`,
to: ["bradley.rhoades@convenient-brands.com"]
});
logger.log("CARFAX-end", "DEBUG", "api", null, null);
@@ -118,7 +119,7 @@ exports.default = async (req, res) => {
}
};
async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allXMLResults, allErrors) {
async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allJSONResults, allErrors) {
for (const bodyshop of shopsToProcess) {
const shopid = bodyshop.imexshopid?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
const erroredJobs = [];
@@ -195,7 +196,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
});
}
allXMLResults.push({
allJSONResults.push({
bodyshopid: bodyshop.id,
imexshopid: shopid,
count: jsonObj.count,
@@ -335,6 +336,7 @@ const GenerateDetailLines = (line) => {
line_desc: line.line_desc ? line.line_desc.replace(NON_ASCII_REGEX, "") : null,
oem_partno: line.oem_partno ? line.oem_partno.replace(NON_ASCII_REGEX, "") : null,
alt_partno: line.alt_partno ? line.alt_partno.replace(NON_ASCII_REGEX, "") : null,
op_code: line.lbr_op || null,
op_code_desc: line.op_code_desc ? line.op_code_desc.replace(NON_ASCII_REGEX, "") : null,
lbr_ty: generateLaborType(line.mod_lbr_ty),
lbr_hrs: line.mod_lb_hrs || 0,
@@ -447,3 +449,9 @@ const errorCode = ({ count, filename, results }) => {
if (sftpErrorCode) return 7;
return 0;
};
module.exports = {
default: carfaxExport,
ftpSetup,
uploadToS3
};

View File

@@ -7,4 +7,5 @@ exports.usageReport = require("./usageReport").default;
exports.podium = require("./podium").default;
exports.emsUpload = require("./emsUpload").default;
exports.carfax = require("./carfax").default;
exports.carfaxRps = require("./carfax-rps").default;
exports.vehicletype = require("./vehicletype/vehicletype").default;

View File

@@ -44,8 +44,9 @@ const logEmail = async (req, email) => {
}
};
const sendServerEmail = async ({ subject, text }) => {
const sendServerEmail = async ({ subject, text, to = [] }) => {
if (process.env.NODE_ENV === undefined) return;
try {
mailer.sendMail(
{
@@ -53,7 +54,7 @@ const sendServerEmail = async ({ subject, text }) => {
imex: `ImEX Online API - ${process.env.NODE_ENV} <noreply@imex.online>`,
rome: `Rome Online API - ${process.env.NODE_ENV} <noreply@romeonline.io>`
}),
to: ["support@thinkimex.com"],
to: ["support@imexsystems.ca", ...to],
subject: subject,
text: text,
ses: {
@@ -68,7 +69,7 @@ const sendServerEmail = async ({ subject, text }) => {
},
// eslint-disable-next-line no-unused-vars
(err, info) => {
logger.log("server-email-failure", err ? "error" : "debug", null, null, {
logger.log("server-email-send", err ? "error" : "debug", null, null, {
message: err?.message,
stack: err?.stack
});
@@ -103,7 +104,7 @@ const sendMexicoBillingEmail = async ({ subject, text }) => {
},
// eslint-disable-next-line no-unused-vars
(err, info) => {
logger.log("server-email-failure", err ? "error" : "debug", null, null, {
logger.log("server-email-send", err ? "error" : "debug", null, null, {
message: err?.message,
stack: err?.stack
});
@@ -258,7 +259,10 @@ const sendTaskEmail = async ({ to, subject, type = "text", html, text, attachmen
// eslint-disable-next-line no-unused-vars
(err, info) => {
// (message, type, user, record, meta
logger.log("server-email", err ? "error" : "debug", null, null, { message: err?.message, stack: err?.stack });
logger.log("server-email-send", err ? "error" : "debug", null, null, {
message: err?.message,
stack: err?.stack
});
}
);
} catch (error) {

View File

@@ -11,9 +11,25 @@ const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
}
});
const rpsClient =
process.env.RPS_GRAPHQL_ENDPOINT && process.env.RPS_HASURA_ADMIN_SECRET
? new GraphQLClient(process.env.RPS_GRAPHQL_ENDPOINT, {
headers: {
"x-hasura-admin-secret": process.env.RPS_HASURA_ADMIN_SECRET
}
})
: null;
if (!rpsClient) {
//System log to disable RPS functions
console.log(`RPS secrets are not set. Client is not configured.`, "WARN", "redis", "api", {});
}
const unauthorizedClient = new GraphQLClient(process.env.GRAPHQL_ENDPOINT);
module.exports = {
client,
rpsClient,
unauthorizedClient
};

View File

@@ -904,6 +904,7 @@ exports.CARFAX_QUERY = `query CARFAX_EXPORT($start: timestamptz, $bodyshopid: uu
line_desc
mod_lb_hrs
mod_lbr_ty
lbr_op
oem_partno
op_code_desc
part_type
@@ -921,6 +922,41 @@ exports.CARFAX_QUERY = `query CARFAX_EXPORT($start: timestamptz, $bodyshopid: uu
}
}`;
exports.CARFAX_RPS_QUERY = `query CARFAX_RPS_EXPORT($starttz: timestamptz, $endtz: timestamptz,$start: date, $end: date, $bodyshopid: uuid!) {
bodyshops_by_pk(id: $bodyshopid) {
id
shopname
}
jobs(where: {_and: [{_or: [{close_date: {_gt: $start, _lte: $end}}, {created_at: {_gt: $starttz, _lte: $endtz}, close_date: {_is_null: true}}]}, {_not: {_and: [{close_date: {_is_null: true}}, {created_at: {_is_null: true}}]}}, {bodyshopid: {_eq: $bodyshopid}}, {v_vin: {_is_null: false}}]}) {
close_date
created_at
id
ins_co_nm
impact_1
impact_2
joblines {
act_price
alt_partno
line_desc
mod_lb_hrs
mod_lbr_ty
oem_partno
lbr_op
part_type
part_qty
}
loss_date
loss_desc
theft_ind
tlos_ind
totals
v_makedesc
v_model
v_model_yr
v_vin
}
}`;
exports.CLAIMSCORP_QUERY = `query CLAIMSCORP_EXPORT($start: timestamptz, $bodyshopid: uuid!, $end: timestamptz) {
bodyshops_by_pk(id: $bodyshopid){
id
@@ -1867,6 +1903,13 @@ exports.GET_CARFAX_SHOPS = `query GET_CARFAX_SHOPS {
}
}`;
exports.GET_CARFAX_RPS_SHOPS = `query GET_CARFAX_RPS_SHOPS {
bodyshops(where: {carfax_exclude: {_neq: "true"}}){
id
shopname
}
}`;
exports.GET_CLAIMSCORP_SHOPS = `query GET_CLAIMSCORP_SHOPS {
bodyshops(where: {claimscorpid: {_is_null: false}, _or: {claimscorpid: {_neq: ""}}}){
id
@@ -2859,6 +2902,7 @@ exports.GET_BODYSHOP_BY_ID = `
intellipay_config
state
notification_followers
timezone
}
}
`;
@@ -2950,6 +2994,7 @@ query GET_JOBID_BY_MERCHANTID_RONUMBER($merchantID: String!, $roNumber: String!)
id
intellipay_config
email
timezone
}
}
}`;
@@ -2959,6 +3004,7 @@ query GET_BODYSHOP_BY_MERCHANTID($merchantID: String!) {
bodyshops(where: {intellipay_merchant_id: {_eq: $merchantID}}) {
id
email
timezone
}
}`;

View File

@@ -7,7 +7,8 @@ const {
CREATE_SHOP,
DELETE_VENDORS_BY_SHOP,
DELETE_SHOP,
CREATE_USER
CREATE_USER,
UPDATE_BODYSHOP_BY_ID
} = require("../partsManagement.queries");
/**
@@ -131,6 +132,61 @@ const insertUserAssociation = async (uid, email, shopId) => {
return resp.insert_users_one;
};
/**
* PATCH handler for updating bodyshop fields.
* Allows patching: shopname, address1, address2, city, state, zip_post, country, email, timezone, phone, logo_img_path
* @param req
* @param res
* @returns {Promise<void>}
*/
const patchPartsManagementProvisioning = async (req, res) => {
const { id } = req.params;
const allowedFields = [
"shopname",
"address1",
"address2",
"city",
"state",
"zip_post",
"country",
"email",
"timezone",
"phone",
"logo_img_path"
];
const updateFields = {};
for (const field of allowedFields) {
if (req.body[field] !== undefined) {
updateFields[field] = req.body[field];
}
}
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 } }`,
{ 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 });
}
try {
const resp = await client.request(UPDATE_BODYSHOP_BY_ID, { id, fields: updateFields });
if (!resp.update_bodyshops_by_pk) {
return res.status(404).json({ error: "Bodyshop not found." });
}
return res.json(resp.update_bodyshops_by_pk);
} catch (err) {
return res.status(500).json({ error: "Failed to update bodyshop.", detail: err });
}
};
/**
* Handles provisioning a new shop for parts management.
* @param req
@@ -259,4 +315,4 @@ const partsManagementProvisioning = async (req, res) => {
}
};
module.exports = partsManagementProvisioning;
module.exports = { partsManagementProvisioning, patchPartsManagementProvisioning };

View File

@@ -298,6 +298,25 @@ const UPDATE_JOBLINE_BY_PK = `
}
`;
const UPDATE_BODYSHOP_BY_ID = `
mutation UpdateBodyshopById($id: uuid!, $fields: bodyshops_set_input!) {
update_bodyshops_by_pk(pk_columns: { id: $id }, _set: $fields) {
id
shopname
address1
address2
city
state
zip_post
country
email
timezone
phone
logo_img_path
}
}
`;
module.exports = {
GET_BODYSHOP_STATUS,
GET_VEHICLE_BY_SHOP_VIN,
@@ -329,5 +348,6 @@ module.exports = {
DELETE_PARTS_ORDERS_BY_JOB_IDS,
UPSERT_JOBLINES,
GET_JOBLINE_IDS_BY_JOBID_UNQSEQ,
UPDATE_JOBLINE_BY_PK
UPDATE_JOBLINE_BY_PK,
UPDATE_BODYSHOP_BY_ID
};

View File

@@ -48,7 +48,9 @@ const handleCommentBasedPayment = async (values, decodedComment, logger, logMeta
payer: "Customer",
type: getPaymentType(ipMapping, values.cardtype),
jobid: p.jobid,
date: moment(Date.now()),
date: moment()
.tz(bodyshop?.bodyshops_by_pk?.timezone ?? "UTC")
.format("YYYY-MM-DD"),
payment_responses: {
data: {
amount: values.total,

View File

@@ -97,7 +97,9 @@ const handleInvoiceBasedPayment = async (values, logger, logMeta, res) => {
payer: "Customer",
type: getPaymentType(ipMapping, values.cardtype),
jobid: job.id,
date: moment(Date.now())
date: moment()
.tz(bodyshop?.timezone ?? "UTC")
.format("YYYY-MM-DD")
}
});

View File

@@ -0,0 +1,40 @@
const client = require("../graphql-client/graphql-client").client;
const { UPDATE_JOB_BY_ID } = require("../integrations/partsManagement/partsManagement.queries");
/**
* PATCH handler to update job status (parts management only)
* @param req
* @param res
* @returns {Promise<void>}
*/
module.exports = async (req, res) => {
const { id } = req.params;
const { status } = req.body;
if (!status) {
return res.status(400).json({ error: "Missing required field: status" });
}
try {
// Fetch job to get shopid
const jobResp = await client.request(`query GetJob($id: uuid!) { jobs_by_pk(id: $id) { id shopid } }`, { id });
const job = jobResp.jobs_by_pk;
if (!job) {
return res.status(404).json({ error: "Job not found" });
}
// Fetch bodyshop to check external_shop_id
const shopResp = await client.request(
`query GetBodyshop($id: uuid!) { bodyshops_by_pk(id: $id) { id external_shop_id } }`,
{ id: job.shopid }
);
if (!shopResp.bodyshops_by_pk || !shopResp.bodyshops_by_pk.external_shop_id) {
return res.status(400).json({ error: "Cannot patch: parent bodyshop does not have an external_shop_id." });
}
// Update job status
const updateResp = await client.request(UPDATE_JOB_BY_ID, { id, job: { status } });
if (!updateResp.update_jobs_by_pk) {
return res.status(404).json({ error: "Job not found after update" });
}
return res.json(updateResp.update_jobs_by_pk);
} catch (err) {
return res.status(500).json({ error: "Failed to update job status.", detail: err });
}
};

View File

@@ -92,7 +92,7 @@ const loadAppQueue = async ({ pubClient, logger, redisHelpers, ioRedis }) => {
"consolidate-notifications",
{ jobId, recipients },
{
jobId: `consolidate:${jobId}`,
jobId: `consolidate-${jobId}`,
delay: APP_CONSOLIDATION_DELAY,
attempts: 3,
backoff: LOCK_EXPIRATION
@@ -288,7 +288,7 @@ const dispatchAppsToQueue = async ({ appsToDispatch }) => {
await appQueue.add(
"add-notification",
{ jobId, bodyShopId, key, variables, recipients, body, jobRoNumber },
{ jobId: `${jobId}:${Date.now()}` }
{ jobId: `${jobId}-${Date.now()}` }
);
devDebugLogger(`Added notification to queue for jobId ${jobId} with ${recipients.length} recipients`);
}

View File

@@ -86,7 +86,7 @@ const loadEmailQueue = async ({ pubClient, logger }) => {
"consolidate-emails",
{ jobId, jobRoNumber, bodyShopName, bodyShopTimezone },
{
jobId: `consolidate:${jobId}`,
jobId: `consolidate-${jobId}`,
delay: EMAIL_CONSOLIDATION_DELAY,
attempts: 3,
backoff: LOCK_EXPIRATION
@@ -252,7 +252,7 @@ const dispatchEmailsToQueue = async ({ emailsToDispatch, logger }) => {
await emailAddQueue.add(
"add-email-notification",
{ jobId, jobRoNumber, bodyShopName, bodyShopTimezone, body, recipients },
{ jobId: `${jobId}:${Date.now()}` }
{ jobId: `${jobId}-${Date.now()}` }
);
devDebugLogger(`Added email notification to queue for jobId ${jobId} with ${recipients.length} recipients`);
}

View File

@@ -82,22 +82,35 @@ exports.partsScan = async function (req, res) {
criticalIds.add(jobline.id);
}
if (update_field && update_value) {
const result = await client.setHeaders({ Authorization: BearerToken }).request(queries.UPDATE_JOB_LINE, {
lineId: jobline.id,
line: { [update_field]: update_value, manual_line: true }
});
const auditResult = await client
.setHeaders({ Authorization: BearerToken })
.request(queries.INSERT_AUDIT_TRAIL, {
auditObj: {
bodyshopid: data.jobs_by_pk.bodyshop.id,
jobid,
operation: `Jobline (#${jobline.line_no} ${jobline.line_desc}/${jobline.id}) ${update_field} updated from ${jobline[update_field]} to ${update_value}. Lined marked as manual line.`,
type: "partscanupdate",
useremail: req.user.email
let actualUpdateField = update_field;
if (update_field === "part_number") {
// Determine which part number field to update based on the match
if (!jobline.oem_partno) {
actualUpdateField = "oem_partno";
} else {
if (regex) {
actualUpdateField = regex.test(jobline.oem_partno || "") ? "oem_partno" : "alt_partno";
} else {
actualUpdateField = jobline.oem_partno === value ? "oem_partno" : "alt_partno";
}
}
}
if (actualUpdateField) {
await client.setHeaders({ Authorization: BearerToken }).request(queries.UPDATE_JOB_LINE, {
lineId: jobline.id,
line: { [actualUpdateField]: update_value, manual_line: true }
});
}
await client.setHeaders({ Authorization: BearerToken }).request(queries.INSERT_AUDIT_TRAIL, {
auditObj: {
bodyshopid: data.jobs_by_pk.bodyshop.id,
jobid,
operation: `Jobline (#${jobline.line_no} ${jobline.line_desc}/${jobline.id}) ${update_field} updated from ${jobline[update_field]} to ${update_value}. Lined marked as manual line.`,
type: "partscanupdate",
useremail: req.user.email
}
});
}
//break; // No need to evaluate further rules for this jobline

View File

@@ -1,6 +1,6 @@
const express = require("express");
const router = express.Router();
const { autohouse, claimscorp, chatter, kaizen, usageReport, podium, carfax } = require("../data/data");
const { autohouse, claimscorp, chatter, kaizen, usageReport, podium, carfax, carfaxRps } = require("../data/data");
router.post("/ah", autohouse);
router.post("/cc", claimscorp);
@@ -9,5 +9,6 @@ router.post("/kaizen", kaizen);
router.post("/usagereport", usageReport);
router.post("/podium", podium);
router.post("/carfax", carfax);
router.post("/carfaxrps", carfaxRps);
module.exports = router;

View File

@@ -19,11 +19,15 @@ if (typeof VSSTA_INTEGRATION_SECRET === "string" && VSSTA_INTEGRATION_SECRET.len
if (typeof PARTS_MANAGEMENT_INTEGRATION_SECRET === "string" && PARTS_MANAGEMENT_INTEGRATION_SECRET.length > 0) {
const XML_BODY_LIMIT = "10mb"; // Set a limit for XML body size
const partsManagementProvisioning = require("../integrations/partsManagement/endpoints/partsManagementProvisioning");
const {
partsManagementProvisioning,
patchPartsManagementProvisioning
} = require("../integrations/partsManagement/endpoints/partsManagementProvisioning");
const partsManagementDeprovisioning = require("../integrations/partsManagement/endpoints/partsManagementDeprovisioning");
const partsManagementIntegrationMiddleware = require("../middleware/partsManagementIntegrationMiddleware");
const partsManagementVehicleDamageEstimateAddRq = require("../integrations/partsManagement/endpoints/vehicleDamageEstimateAddRq");
const partsManagementVehicleDamageEstimateChqRq = require("../integrations/partsManagement/endpoints/vehicleDamageEstimateChgRq");
const patchJobStatus = require("../job/patchJobStatus");
/**
* Route to handle Vehicle Damage Estimate Add Request
@@ -55,6 +59,20 @@ if (typeof PARTS_MANAGEMENT_INTEGRATION_SECRET === "string" && PARTS_MANAGEMENT_
* Route to handle Parts Management Provisioning
*/
router.post("/parts-management/provision", partsManagementIntegrationMiddleware, partsManagementProvisioning);
/**
* PATCH route to update Parts Management Provisioning info
*/
router.patch(
"/parts-management/provision/:id",
partsManagementIntegrationMiddleware,
patchPartsManagementProvisioning
);
/**
* PATCH route to update job status (parts management only)
*/
router.patch("/parts-management/job/:id/status", partsManagementIntegrationMiddleware, patchJobStatus);
} else {
logger.logger.warn("PARTS_MANAGEMENT_INTEGRATION_SECRET is not set — skipping /parts-management/provision route");
}