diff --git a/electron/decoder/decoder.js b/electron/decoder/decoder.js index aec1b7f..a787e6d 100644 --- a/electron/decoder/decoder.js +++ b/electron/decoder/decoder.js @@ -1,12 +1,231 @@ const { DBFFile } = require("dbffile"); +const path = require("path"); +const _ = require("lodash"); async function DecodeEstimate(filePath) { - //Path to AD1 - let dbf = await DBFFile.open("C:\\VPS\\EMS\\687_3_A.LIN"); - console.log(`DBF file contains ${dbf.recordCount} records.`); - console.log(`Field names: ${dbf.fields.map((f) => f.name).join(", ")}`); - let records = await dbf.readRecords(100); - for (let record of records) console.log(record); + const parsedFilePath = path.parse(filePath); + let extensionlessFilePath = `${parsedFilePath.dir}\\${parsedFilePath.name}`; + + const ret = { + ...(await DecodeAd1File(extensionlessFilePath)), + ...(await DecodeVehFile(extensionlessFilePath)), + ...(await DecodeTtlFile(extensionlessFilePath)), + ...(await DecodeLinFile(extensionlessFilePath)), + }; + return ret; +} + +async function DecodeAd1File(extensionlessFilePath) { + let dbf = await DBFFile.open(`${extensionlessFilePath}A.AD1`); + let records = await dbf.readRecords(1); + return _.pick(records[0], [ + // "INS_CO_ID", + "INS_CO_NM", + // "INS_ADDR1", + // "INS_ADDR2", + // "INS_CITY", + // "INS_ST", + // "INS_ZIP", + // "INS_CTRY", + + // "INS_EA", + // "POLICY_NO", + // "DED_AMT", + // "DED_STATUS", + // "ASGN_NO", + // "ASGN_DATE", + // "ASGN_TYPE", + "CLM_NO", + // "CLM_OFC_ID", + // "CLM_OFC_NM", + // "CLM_ADDR1", + // "CLM_ADDR2", + // "CLM_CITY", + // "CLM_ST", + // "CLM_ZIP", + // "CLM_CTRY", + // "CLM_PH1", + // "CLM_PH1X", + // "CLM_PH2", + // "CLM_PH2X", + // "CLM_FAX", + // "CLM_FAXX", + // "CLM_CT_LN", + // "CLM_CT_FN", + // "CLM_TITLE", + // "CLM_CT_PH", + // "CLM_CT_PHX", + // "CLM_EA", + // "PAYEE_NMS", + // "PAY_TYPE", + // "PAY_DATE", + // "PAY_CHKNM", + // "PAY_AMT", + // "AGT_CO_ID", + // "AGT_CO_NM", + // "AGT_ADDR1", + // "AGT_ADDR2", + // "AGT_CITY", + // "AGT_ST", + // "AGT_ZIP", + // "AGT_CTRY", + // "AGT_PH1", + // "AGT_PH1X", + // "AGT_PH2", + // "AGT_PH2X", + // "AGT_FAX", + // "AGT_FAXX", + // "AGT_CT_LN", + // "AGT_CT_FN", + // "AGT_CT_PH", + // "AGT_CT_PHX", + // "AGT_EA", + // "AGT_LIC_NO", + // "LOSS_DATE", + // "LOSS_TYPE", + // "LOSS_DESC", + // "THEFT_IND", + // "CAT_NO", + // "TLOS_IND", + // "CUST_PR", + // "INSD_LN", + // "INSD_FN", + // "INSD_TITLE", + // "INSD_CO_NM", + // "INSD_ADDR1", + // "INSD_ADDR2", + // "INSD_CITY", + // "INSD_ST", + // "INSD_ZIP", + // "INSD_CTRY", + // "INSD_PH1", + // "INSD_PH1X", + // "INSD_PH2", + // "INSD_PH2X", + // "INSD_FAX", + // "INSD_FAXX", + // "INSD_EA", + "OWNR_LN", + "OWNR_FN", + // "OWNR_TITLE", + // "OWNR_CO_NM", + // "OWNR_ADDR1", + // "OWNR_ADDR2", + // "OWNR_CITY", + // "OWNR_ST", + // "OWNR_ZIP", + // "OWNR_CTRY", + // "OWNR_PH1", + // "OWNR_PH1X", + // "OWNR_PH2", + // "OWNR_PH2X", + // "OWNR_FAX", + // "OWNR_FAXX", + // "OWNR_EA", + // "INS_PH1", + // "INS_PH1X", + // "INS_PH2", + // "INS_PH2X", + // "INS_FAX", + // "INS_FAXX", + // "INS_CT_LN", + // "INS_CT_FN", + // "INS_TITLE", + // "INS_CT_PH", + // "INS_CT_PHX", + // "LOSS_CAT", + ]); +} +async function DecodeVehFile(extensionlessFilePath) { + let dbf = await DBFFile.open(`${extensionlessFilePath}V.VEH`); + let records = await dbf.readRecords(1); + return _.pick(records[0], [ + // "IMPACT_1", + // "IMPACT_2", + // "DB_V_CODE", + // "PLATE_NO", + // "PLATE_ST", + "V_VIN", + // "V_COND", + // "V_PROD_DT", + "V_MODEL_YR", + // "V_MAKECODE", + "V_MAKEDESC", + "V_MODEL", + "V_TYPE", + // "V_BSTYLE", + // "V_TRIMCODE", + // "TRIM_COLOR", + // "V_MLDGCODE", + // "V_ENGINE", + // "V_COLOR", + // "V_TONE", + // "V_STAGE", + // "PAINT_CD1", + // "PAINT_CD2", + // "PAINT_CD3", + ]); +} +async function DecodeTtlFile(extensionlessFilePath) { + let dbf = await DBFFile.open(`${extensionlessFilePath}.TTL`); + let records = await dbf.readRecords(1); + return _.pick(records[0], ["CLM_TOTAL"]); +} + +async function DecodeLinFile(extensionlessFilePath) { + let dbf = await DBFFile.open(`${extensionlessFilePath}.LIN`); + let records = await dbf.readRecords(); + + let joblines = records.map((record) => + _.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 { joblines: { data: joblines } }; } exports.DecodeEstimate = DecodeEstimate; diff --git a/electron/ipc-handler.js b/electron/ipc-handler.js index 3c50f3b..3b26f57 100644 --- a/electron/ipc-handler.js +++ b/electron/ipc-handler.js @@ -8,8 +8,10 @@ require("./file-watcher/file-watcher-ipc"); console.log("*** Added IPC Handlers ***"); ipcMain.on("test", async (event, object) => { - DecodeEstimate(); - event.sender.send("test-success", { success: true }); + console.log("Received test IPC Command"); + const job = await DecodeEstimate("C:\\VPS\\EMS\\687_3_A.AD1"); + + event.reply("test-success", { status: 0, message: null, data: job }); }); // ipcMain.on("test-start", async (event, arg) => { diff --git a/electron/main.js b/electron/main.js index 201200d..54ed746 100644 --- a/electron/main.js +++ b/electron/main.js @@ -18,6 +18,8 @@ if (require("electron-squirrel-startup")) { app.quit(); } +console.log(`${__dirname}/preload.js`); + var mainWindow = null; function createWindow() { // Create the browser window. @@ -26,8 +28,11 @@ function createWindow() { height: 600, title: "ImEX RPS", webPreferences: { - nodeIntegration: true, - enableRemoteModule: true, + nodeIntegration: false, + enableRemoteModule: false, + worldSafeExecuteJavaScript: true, + contextIsolation: true, + preload: path.join(__dirname, "preload.js"), // use a preload script }, }); diff --git a/electron/preload.js b/electron/preload.js new file mode 100644 index 0000000..fa7f5f7 --- /dev/null +++ b/electron/preload.js @@ -0,0 +1,31 @@ +console.log("Running preloader!"); +const { contextBridge, ipcRenderer } = require("electron"); + +ipcRenderer.removeAllListeners(); +contextBridge.exposeInMainWorld("ipcRenderer", { + send: (channel, data) => { + // whitelist channels + // let validChannels = ["toMain"]; + // if (validChannels.includes(channel)) { + ipcRenderer.send(channel, data); + //} + }, + on: (channel, func) => { + // let validChannels = ["fromMain"]; + // if (validChannels.includes(channel)) { + // Deliberately strip event as it includes `sender` + ipcRenderer.on( + channel, + func + ///(event, ...args) => func(...args) + ); + // } + }, + removeAllListeners: (...channels) => { + // let validChannels = ["fromMain"]; + // if (validChannels.includes(channel)) { + // Deliberately strip event as it includes `sender` + ipcRenderer.removeAllListeners(...channels); + // } + }, +}); diff --git a/package.json b/package.json index c2a8400..aa937f0 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "electron-squirrel-startup": "^1.0.0", "firebase": "^7.23.0", "graphql": "^15.3.0", + "lodash": "^4.17.20", "node-sass": "^4.14.1", "react": "^16.13.1", "react-dom": "^16.13.1", diff --git a/src/components/pages/jobs/jobs.page.jsx b/src/components/pages/jobs/jobs.page.jsx index 84511ad..296fe4d 100644 --- a/src/components/pages/jobs/jobs.page.jsx +++ b/src/components/pages/jobs/jobs.page.jsx @@ -4,7 +4,7 @@ import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; import ipcTypes from "../../../ipc.types"; -const { ipcRenderer } = window.require("electron"); +const { ipcRenderer } = window; //const settings = window.require("electron-settings"); const mapStateToProps = createStructuredSelector({}); @@ -33,7 +33,7 @@ export function JobsPage() { ipcRenderer.send("test", { test: true }); }} > - TEST Generic IPC + TEST