diff --git a/electron/decoder/decoder.js b/electron/decoder/decoder.js index bfc41fc..448ac7b 100644 --- a/electron/decoder/decoder.js +++ b/electron/decoder/decoder.js @@ -184,76 +184,128 @@ async function DecodeTtlFile(extensionlessFilePath) { async function DecodeLinFile(extensionlessFilePath) { let dbf = await DBFFile.open(`${extensionlessFilePath}.LIN`); let records = await dbf.readRecords(); - let joblines = records.map((record) => - _.transform( - _.pick(record, [ - "LINE_NO", - "LINE_IND", - // "LINE_REF", - // "TRAN_CODE", - "DB_REF", - "UNQ_SEQ", - // "WHO_PAYS", - "LINE_DESC", - "PART_TYPE", - // "PART_DESCJ", - "GLASS_FLAG", - "OEM_PARTNO", - // "PRICE_INC", - // "ALT_PART_I", - // "TAX_PART", - "DB_PRICE", - "ACT_PRICE", - // "PRICE_J", - // "CERT_PART", - "PART_QTY", - // "ALT_CO_ID", - // "ALT_PARTNO", - // "ALT_OVERRD", - // "ALT_PARTM", - // "PRT_DSMK_P", - // "PRT_DSMK_M", - // "MOD_LBR_TY", - // "DB_HRS", - // "MOD_LB_HRS", - // "LBR_INC", - // "LBR_OP", - // "LBR_HRS_J", - // "LBR_TYP_J", - // "LBR_OP_J", - // "PAINT_STG", - // "PAINT_TONE", - // "LBR_TAX", - // "LBR_AMT", - // "MISC_AMT", - // "MISC_SUBLT", - // "MISC_TAX", - // "BETT_TYPE", - // "BETT_PCTG", - // "BETT_AMT", - // "BETT_TAX", - ]), - function (result, val, key) { - //Required because unq_seq gets pulled as a numeric instaed of a string. - console.log("key", key); - if (key === "UNQ_SEQ") { - return (result[key.toLowerCase()] = val.toString()); - } - return (result[key.toLowerCase()] = val); - } - ) - ); + let joblines = records + .map((record) => { + console.log( + "object", + _.pick(record, [ + "LINE_NO", + "LINE_IND", + // "LINE_REF", + // "TRAN_CODE", + "DB_REF", + "UNQ_SEQ", + // "WHO_PAYS", + "LINE_DESC", + "PART_TYPE", + // "PART_DESCJ", + "GLASS_FLAG", + "OEM_PARTNO", + // "PRICE_INC", + // "ALT_PART_I", + // "TAX_PART", + "DB_PRICE", + "ACT_PRICE", + // "PRICE_J", + // "CERT_PART", + "PART_QTY", + // "ALT_CO_ID", + // "ALT_PARTNO", + // "ALT_OVERRD", + // "ALT_PARTM", + // "PRT_DSMK_P", + // "PRT_DSMK_M", + // "MOD_LBR_TY", + // "DB_HRS", + // "MOD_LB_HRS", + // "LBR_INC", + // "LBR_OP", + // "LBR_HRS_J", + // "LBR_TYP_J", + // "LBR_OP_J", + // "PAINT_STG", + // "PAINT_TONE", + // "LBR_TAX", + // "LBR_AMT", + // "MISC_AMT", + // "MISC_SUBLT", + // "MISC_TAX", + // "BETT_TYPE", + // "BETT_PCTG", + // "BETT_AMT", + // "BETT_TAX", + ]) + ); + return _.transform( + _.pick(record, [ + "LINE_NO", + "LINE_IND", + // "LINE_REF", + // "TRAN_CODE", + "DB_REF", + "UNQ_SEQ", + // "WHO_PAYS", + "LINE_DESC", + "PART_TYPE", + // "PART_DESCJ", - const m = joblines + "OEM_PARTNO", + // "PRICE_INC", + // "ALT_PART_I", + // "TAX_PART", + "DB_PRICE", + "ACT_PRICE", + // "PRICE_J", + // "CERT_PART", + "PART_QTY", + // "ALT_CO_ID", + // "ALT_PARTNO", + // "ALT_OVERRD", + // "ALT_PARTM", + // "PRT_DSMK_P", + // "PRT_DSMK_M", + // "MOD_LBR_TY", + // "DB_HRS", + // "MOD_LB_HRS", + // "LBR_INC", + // "LBR_OP", + // "LBR_HRS_J", + // "LBR_TYP_J", + // "LBR_OP_J", + // "PAINT_STG", + // "PAINT_TONE", + // "LBR_TAX", + // "LBR_AMT", + // "MISC_AMT", + // "MISC_SUBLT", + // "MISC_TAX", + // "BETT_TYPE", + // "BETT_PCTG", + // "BETT_AMT", + // "BETT_TAX", + "GLASS_FLAG", + ]), + function (result, val, key) { + //Required because unq_seq gets pulled as a numeric instaed of a string. + console.log("key", key); + if (key === "UNQ_SEQ") { + return (result[key.toLowerCase()] = val.toString()); + } + return (result[key.toLowerCase()] = val); + } + ); + }) .filter( (jobline) => - jobline.PART_TYPE && + jobline.part_type && !jobline.db_ref.startsWith("900") && - (jobline.part_type && jobline.part_type.toUpperCase()) !== "PAG" && + jobline.part_type.toUpperCase() !== "PAG" && + jobline.part_type.toUpperCase() !== "PAS" && + jobline.part_type.toUpperCase() !== "PASL" && + jobline.part_type.toUpperCase() !== "PAE" && jobline.glass_flag === false ) .map((jobline) => { - console.log("Massagejobline", jobline); if ( (jobline.db_price === null || jobline.db_price === 0) && !!jobline.act_price && @@ -285,7 +337,6 @@ async function DecodeLinFile(extensionlessFilePath) { } delete jobline.glass_flag; - console.log(jobline); return jobline; }); diff --git a/electron/file-watcher/file-watcher.js b/electron/file-watcher/file-watcher.js index 1e8caf0..edde955 100644 --- a/electron/file-watcher/file-watcher.js +++ b/electron/file-watcher/file-watcher.js @@ -3,7 +3,6 @@ const ipcTypes = require("../../src/ipc.types"); const path = require("path"); const { DecodeEstimate } = require("../decoder/decoder"); const { BrowserWindow } = require("electron"); -const _ = require("lodash"); const { store } = require("../electron-store"); const { NewNotification, @@ -26,7 +25,7 @@ async function StartWatcher() { if (watcher) { try { - console.log("Trying to close watcher - it already existed.111"); + console.log("Trying to close watcher - it already existed."); await watcher.close(); console.log("Watcher closed successfully!"); diff --git a/hasura/migrations/1602881581659_create_table_public_targets/down.yaml b/hasura/migrations/1602881581659_create_table_public_targets/down.yaml new file mode 100644 index 0000000..58d4141 --- /dev/null +++ b/hasura/migrations/1602881581659_create_table_public_targets/down.yaml @@ -0,0 +1,5 @@ +- args: + cascade: false + read_only: false + sql: DROP TABLE "public"."targets"; + type: run_sql diff --git a/hasura/migrations/1602881581659_create_table_public_targets/up.yaml b/hasura/migrations/1602881581659_create_table_public_targets/up.yaml new file mode 100644 index 0000000..bdb42ab --- /dev/null +++ b/hasura/migrations/1602881581659_create_table_public_targets/up.yaml @@ -0,0 +1,23 @@ +- args: + cascade: false + read_only: false + sql: CREATE EXTENSION IF NOT EXISTS pgcrypto; + type: run_sql +- args: + cascade: false + read_only: false + sql: "CREATE TABLE \"public\".\"targets\"(\"id\" uuid NOT NULL DEFAULT gen_random_uuid(), + \"updated_at\" timestamptz NOT NULL DEFAULT now(), \"created_at\" timestamptz + NOT NULL DEFAULT now(), \"label\" text NOT NULL, \"config\" jsonb NOT NULL DEFAULT + jsonb_build_object(), \"start_date\" date NOT NULL, \"end_date\" date, PRIMARY + KEY (\"id\") );\nCREATE OR REPLACE FUNCTION \"public\".\"set_current_timestamp_updated_at\"()\nRETURNS + TRIGGER AS $$\nDECLARE\n _new record;\nBEGIN\n _new := NEW;\n _new.\"updated_at\" + = NOW();\n RETURN _new;\nEND;\n$$ LANGUAGE plpgsql;\nCREATE TRIGGER \"set_public_targets_updated_at\"\nBEFORE + UPDATE ON \"public\".\"targets\"\nFOR EACH ROW\nEXECUTE PROCEDURE \"public\".\"set_current_timestamp_updated_at\"();\nCOMMENT + ON TRIGGER \"set_public_targets_updated_at\" ON \"public\".\"targets\" \nIS + 'trigger to set value of column \"updated_at\" to current timestamp on row update';" + type: run_sql +- args: + name: targets + schema: public + type: add_existing_table_or_view diff --git a/hasura/migrations/1602881591377_update_permission_user_public_table_targets/down.yaml b/hasura/migrations/1602881591377_update_permission_user_public_table_targets/down.yaml new file mode 100644 index 0000000..f39ea3a --- /dev/null +++ b/hasura/migrations/1602881591377_update_permission_user_public_table_targets/down.yaml @@ -0,0 +1,6 @@ +- args: + role: user + table: + name: targets + schema: public + type: drop_select_permission diff --git a/hasura/migrations/1602881591377_update_permission_user_public_table_targets/up.yaml b/hasura/migrations/1602881591377_update_permission_user_public_table_targets/up.yaml new file mode 100644 index 0000000..c50793b --- /dev/null +++ b/hasura/migrations/1602881591377_update_permission_user_public_table_targets/up.yaml @@ -0,0 +1,20 @@ +- args: + permission: + allow_aggregations: false + backend_only: false + columns: + - id + - updated_at + - created_at + - label + - config + - start_date + - end_date + computed_fields: [] + filter: {} + limit: null + role: user + table: + name: targets + schema: public + type: create_select_permission diff --git a/hasura/migrations/1602881684708_drop_table_public_targets/down.yaml b/hasura/migrations/1602881684708_drop_table_public_targets/down.yaml new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/hasura/migrations/1602881684708_drop_table_public_targets/down.yaml @@ -0,0 +1 @@ +[] diff --git a/hasura/migrations/1602881684708_drop_table_public_targets/up.yaml b/hasura/migrations/1602881684708_drop_table_public_targets/up.yaml new file mode 100644 index 0000000..58d4141 --- /dev/null +++ b/hasura/migrations/1602881684708_drop_table_public_targets/up.yaml @@ -0,0 +1,5 @@ +- args: + cascade: false + read_only: false + sql: DROP TABLE "public"."targets"; + type: run_sql diff --git a/hasura/migrations/1602881697769_alter_table_public_bodyshops_add_column_targets/down.yaml b/hasura/migrations/1602881697769_alter_table_public_bodyshops_add_column_targets/down.yaml new file mode 100644 index 0000000..29153d6 --- /dev/null +++ b/hasura/migrations/1602881697769_alter_table_public_bodyshops_add_column_targets/down.yaml @@ -0,0 +1,5 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."bodyshops" DROP COLUMN "targets"; + type: run_sql diff --git a/hasura/migrations/1602881697769_alter_table_public_bodyshops_add_column_targets/up.yaml b/hasura/migrations/1602881697769_alter_table_public_bodyshops_add_column_targets/up.yaml new file mode 100644 index 0000000..2656d12 --- /dev/null +++ b/hasura/migrations/1602881697769_alter_table_public_bodyshops_add_column_targets/up.yaml @@ -0,0 +1,6 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."bodyshops" ADD COLUMN "targets" jsonb NULL DEFAULT + jsonb_build_object(); + type: run_sql diff --git a/hasura/migrations/1602881706088_update_permission_user_public_table_bodyshops/down.yaml b/hasura/migrations/1602881706088_update_permission_user_public_table_bodyshops/down.yaml new file mode 100644 index 0000000..6854447 --- /dev/null +++ b/hasura/migrations/1602881706088_update_permission_user_public_table_bodyshops/down.yaml @@ -0,0 +1,25 @@ +- args: + role: user + table: + name: bodyshops + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - id + - created_at + - updated_at + - shopname + computed_fields: [] + filter: + associations: + user: + authid: + _eq: X-Hasura-User-Id + role: user + table: + name: bodyshops + schema: public + type: create_select_permission diff --git a/hasura/migrations/1602881706088_update_permission_user_public_table_bodyshops/up.yaml b/hasura/migrations/1602881706088_update_permission_user_public_table_bodyshops/up.yaml new file mode 100644 index 0000000..a777f71 --- /dev/null +++ b/hasura/migrations/1602881706088_update_permission_user_public_table_bodyshops/up.yaml @@ -0,0 +1,26 @@ +- args: + role: user + table: + name: bodyshops + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - created_at + - id + - shopname + - targets + - updated_at + computed_fields: [] + filter: + associations: + user: + authid: + _eq: X-Hasura-User-Id + role: user + table: + name: bodyshops + schema: public + type: create_select_permission diff --git a/hasura/migrations/1602881715816_update_permission_user_public_table_bodyshops/down.yaml b/hasura/migrations/1602881715816_update_permission_user_public_table_bodyshops/down.yaml new file mode 100644 index 0000000..0c08e23 --- /dev/null +++ b/hasura/migrations/1602881715816_update_permission_user_public_table_bodyshops/down.yaml @@ -0,0 +1,6 @@ +- args: + role: user + table: + name: bodyshops + schema: public + type: drop_update_permission diff --git a/hasura/migrations/1602881715816_update_permission_user_public_table_bodyshops/up.yaml b/hasura/migrations/1602881715816_update_permission_user_public_table_bodyshops/up.yaml new file mode 100644 index 0000000..04abe31 --- /dev/null +++ b/hasura/migrations/1602881715816_update_permission_user_public_table_bodyshops/up.yaml @@ -0,0 +1,16 @@ +- args: + permission: + backend_only: false + columns: + - targets + filter: + associations: + user: + authid: + _eq: X-Hasura-User-Id + set: {} + role: user + table: + name: bodyshops + schema: public + type: create_update_permission diff --git a/hasura/migrations/metadata.yaml b/hasura/migrations/metadata.yaml index e64d1e2..eb3f498 100644 --- a/hasura/migrations/metadata.yaml +++ b/hasura/migrations/metadata.yaml @@ -42,15 +42,27 @@ tables: - role: user permission: columns: - - id - created_at - - updated_at + - id - shopname + - targets + - updated_at filter: associations: user: authid: _eq: X-Hasura-User-Id + update_permissions: + - role: user + permission: + columns: + - targets + filter: + associations: + user: + authid: + _eq: X-Hasura-User-Id + check: null - table: schema: public name: joblines diff --git a/src/components/atoms/price-diff-pc-formatter/price-diff-pc-formatter.atom.jsx b/src/components/atoms/price-diff-pc-formatter/price-diff-pc-formatter.atom.jsx new file mode 100644 index 0000000..0225585 --- /dev/null +++ b/src/components/atoms/price-diff-pc-formatter/price-diff-pc-formatter.atom.jsx @@ -0,0 +1,52 @@ +import React, { useMemo } from "react"; +import { connect } from "react-redux"; +import { createStructuredSelector } from "reselect"; +import { selectBodyshop } from "../../../redux/user/user.selectors"; +import "./price-diff-pc-formatter.styles.scss"; +import { AlertFilled } from "@ant-design/icons"; +const mapStateToProps = createStructuredSelector({ + bodyshop: selectBodyshop, +}); +const mapDispatchToProps = (dispatch) => ({ + //setUserLanguage: language => dispatch(setUserLanguage(language)) +}); + +export function PriceDiffPcFormatterAtom({ + bodyshop, + price_diff_pc, + group, + v_age, +}) { + const metTarget = useMemo(() => { + const targetsForGroup = bodyshop.targets[group]; + if (!targetsForGroup) return 0; + const targetPc = targetsForGroup.filter( + (t) => t.ageGte <= v_age && (t.ageLt ? t.ageLt > v_age : true) + ); + if (targetPc.length === 0) return false; + else if (targetPc.length === 1) return price_diff_pc >= targetPc[0].target; + else { + alert("Multiple targets match."); + return false; + } + }, [bodyshop, group, price_diff_pc, v_age]); + + return ( +