From 09ddb85b8b3bc68c65a2d727e6a0ba384a65a1f1 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Tue, 12 Aug 2025 08:56:58 -0700 Subject: [PATCH] Add database fields. --- .../estimate-scrubber/estimate-scrubber.js | 17 ++++++------ .../default/tables/public_bodyshops.yaml | 2 ++ .../down.sql | 4 +++ .../up.sql | 2 ++ .../down.sql | 4 +++ .../up.sql | 2 ++ package.json | 2 +- .../jobs-lines-table.molecule.jsx | 2 +- .../reporting-jobs-list.molecule.jsx | 14 +++++----- src/graphql/jobs.queries.js | 5 ++++ src/redux/reporting/reporting.sagas.js | 27 +++++++++++++++++-- 11 files changed, 61 insertions(+), 20 deletions(-) create mode 100644 hasura/migrations/default/1755013061924_alter_table_public_bodyshops_add_column_phone/down.sql create mode 100644 hasura/migrations/default/1755013061924_alter_table_public_bodyshops_add_column_phone/up.sql create mode 100644 hasura/migrations/default/1755013138305_alter_table_public_bodyshops_add_column_zip_post/down.sql create mode 100644 hasura/migrations/default/1755013138305_alter_table_public_bodyshops_add_column_zip_post/up.sql diff --git a/electron/estimate-scrubber/estimate-scrubber.js b/electron/estimate-scrubber/estimate-scrubber.js index 80f2e5f..d8ce46f 100644 --- a/electron/estimate-scrubber/estimate-scrubber.js +++ b/electron/estimate-scrubber/estimate-scrubber.js @@ -1,7 +1,6 @@ -const fs = require("fs"); const log = require("electron-log"); const axios = require("axios"); - +const { path } = require("path"); const { BrowserWindow } = require("electron"); // Function to write job object to logs subfolder @@ -10,17 +9,17 @@ async function writeJobToLogsFolder(job, fileName) { // Get the directory where electron-log stores its files const logFilePath = log.transports.file.getFile().path; const logsDir = path.dirname(logFilePath); - + // Create a subfolder for job objects const jobLogsDir = path.join(logsDir, 'esjson'); - + // Ensure the directory exists await fsPromises.mkdir(jobLogsDir, { recursive: true }); - + // Write the job object as JSON const jobFilePath = path.join(jobLogsDir, `${fileName}.json`); await fsPromises.writeFile(jobFilePath, JSON.stringify(job, null, 2), 'utf8'); - + log.log(`Job object written to: ${jobFilePath}`); return jobFilePath; } catch (error) { @@ -28,7 +27,6 @@ async function writeJobToLogsFolder(job, fileName) { throw error; } } - async function ScrubEstimate({ job }) { //TODO: Fetch these from ImEX Online API. const basicAuthUser = "Imex"; @@ -60,6 +58,7 @@ async function ScrubEstimate({ job }) { } }); } + delete job.bodyshop //Bodyshop has to be passed through the object as we don't have access to the store here. //Lower case the rates & totals if (job.rates && Array.isArray(job.rates)) { @@ -83,7 +82,7 @@ async function ScrubEstimate({ job }) { } console.log("*** ~ ScrubEstimate ~ job:", job); const fileName = `RPSTest-${job.id}-${Date.now()}`; - + // Write job object to logs subfolder try { await writeJobToLogsFolder(job, fileName); @@ -91,7 +90,7 @@ async function ScrubEstimate({ job }) { log.error('Failed to write job to logs folder:', error); // Continue with the rest of the function even if this fails } - + const formData = new FormData(); const jsonString = JSON.stringify(job); formData.append("file", new Blob([jsonString], { type: "application/json" }), `${fileName}.json`); diff --git a/hasura/metadata/databases/default/tables/public_bodyshops.yaml b/hasura/metadata/databases/default/tables/public_bodyshops.yaml index 113d4b9..3c11cb8 100644 --- a/hasura/metadata/databases/default/tables/public_bodyshops.yaml +++ b/hasura/metadata/databases/default/tables/public_bodyshops.yaml @@ -33,10 +33,12 @@ select_permissions: - features - groups - id + - phone - ppd_diff_alert - shopname - targets - updated_at + - zip_post filter: associations: user: diff --git a/hasura/migrations/default/1755013061924_alter_table_public_bodyshops_add_column_phone/down.sql b/hasura/migrations/default/1755013061924_alter_table_public_bodyshops_add_column_phone/down.sql new file mode 100644 index 0000000..f98dcfd --- /dev/null +++ b/hasura/migrations/default/1755013061924_alter_table_public_bodyshops_add_column_phone/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."bodyshops" add column "phone" text +-- null; diff --git a/hasura/migrations/default/1755013061924_alter_table_public_bodyshops_add_column_phone/up.sql b/hasura/migrations/default/1755013061924_alter_table_public_bodyshops_add_column_phone/up.sql new file mode 100644 index 0000000..44eb79d --- /dev/null +++ b/hasura/migrations/default/1755013061924_alter_table_public_bodyshops_add_column_phone/up.sql @@ -0,0 +1,2 @@ +alter table "public"."bodyshops" add column "phone" text + null; diff --git a/hasura/migrations/default/1755013138305_alter_table_public_bodyshops_add_column_zip_post/down.sql b/hasura/migrations/default/1755013138305_alter_table_public_bodyshops_add_column_zip_post/down.sql new file mode 100644 index 0000000..f1f0f3a --- /dev/null +++ b/hasura/migrations/default/1755013138305_alter_table_public_bodyshops_add_column_zip_post/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."bodyshops" add column "zip_post" text +-- null; diff --git a/hasura/migrations/default/1755013138305_alter_table_public_bodyshops_add_column_zip_post/up.sql b/hasura/migrations/default/1755013138305_alter_table_public_bodyshops_add_column_zip_post/up.sql new file mode 100644 index 0000000..7e1fcce --- /dev/null +++ b/hasura/migrations/default/1755013138305_alter_table_public_bodyshops_add_column_zip_post/up.sql @@ -0,0 +1,2 @@ +alter table "public"."bodyshops" add column "zip_post" text + null; diff --git a/package.json b/package.json index 1d43d24..a579d17 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "productName": "ImEX RPS", "author": "ImEX Systems Inc. ", "description": "ImEX RPS", - "version": "1.4.2-alpha.3", + "version": "1.4.2-alpha.4", "main": "electron/main.js", "homepage": "./", "dependencies": { diff --git a/src/components/molecules/jobs-lines-table/jobs-lines-table.molecule.jsx b/src/components/molecules/jobs-lines-table/jobs-lines-table.molecule.jsx index e7b23de..ca79742 100644 --- a/src/components/molecules/jobs-lines-table/jobs-lines-table.molecule.jsx +++ b/src/components/molecules/jobs-lines-table/jobs-lines-table.molecule.jsx @@ -44,7 +44,7 @@ export default function JobLinesTableMolecule({ loading, job }) { {record.line_desc} {record.part_qty > 1 && Quantity {">"} 1} - {record.price_diff < 0 && record.db_ref?.startsWith("9005") && Negative Savings} + {record.price_diff < 0 && !record.db_ref?.startsWith("9005") && Negative Savings} {/* {record.alerts && record.alerts.length > 0 && record.alerts.map((alert) => ( diff --git a/src/components/molecules/reporting-jobs-list/reporting-jobs-list.molecule.jsx b/src/components/molecules/reporting-jobs-list/reporting-jobs-list.molecule.jsx index 955cf66..29e0013 100644 --- a/src/components/molecules/reporting-jobs-list/reporting-jobs-list.molecule.jsx +++ b/src/components/molecules/reporting-jobs-list/reporting-jobs-list.molecule.jsx @@ -236,13 +236,13 @@ export function ReportingJobsListMolecule({ size="small" pagination={false} dataSource={data} - // expandable={{ - // expandedRowRender: (record) => , - // rowExpandable: (record) => record.alerts && record.alerts.length > 0 - // }} - // scroll={{ - // x: true - // }} + expandable={{ + expandedRowRender: (record) => , + rowExpandable: (record) => record.alerts && record.alerts.length > 0 + }} + scroll={{ + x: true + }} summary={() => ( diff --git a/src/graphql/jobs.queries.js b/src/graphql/jobs.queries.js index 12feab3..59828fe 100644 --- a/src/graphql/jobs.queries.js +++ b/src/graphql/jobs.queries.js @@ -236,6 +236,11 @@ export const QUERY_JOB_ESTIMATE_SCRUBBER = gql` v_stage supp_amt g_bett_amt + bodyshop { + id + post_zip + phone + } joblines(order_by: {line_no: asc}) { line_no line_ind diff --git a/src/redux/reporting/reporting.sagas.js b/src/redux/reporting/reporting.sagas.js index 767594c..3c175b2 100644 --- a/src/redux/reporting/reporting.sagas.js +++ b/src/redux/reporting/reporting.sagas.js @@ -183,7 +183,30 @@ export function* handleCalculateScoreCard({ payload: queriedJobs }) { }); } - const jobAlerts = job.joblines + const simpleJobAlerts = []; + + job.joblines.forEach((jobline) => { + if (jobline.part_qty > 1) { + simpleJobAlerts.push({ + key: `line-${jobline.id}`, + alert: `Line ${jobline.line_no} has a quantity greater than 1 (${jobline.part_qty})`, + line_no: jobline.line_no, + line_desc: jobline.line_desc, + id: jobline.id + }); + } + if (jobline.price_diff < 0 && !jobline.db_ref?.startsWith("9005")) { + simpleJobAlerts.push({ + key: `line-${jobline.id}`, + alert: `Line ${jobline.line_no} has negative savings (${jobline.price_diff})`, + line_no: jobline.line_no, + line_desc: jobline.line_desc, + id: jobline.id + }); + } + }); + + const jobAlerts = [...simpleJobAlerts, ...job.joblines .map((jobline) => jobline.alerts?.map((alert, idx) => ({ key: idx, @@ -194,7 +217,7 @@ export function* handleCalculateScoreCard({ payload: queriedJobs }) { // } })) ) - .flat(); + .flat()]; //sum db price * percentage expected. return {