diff --git a/electron/decoder/decoder.js b/electron/decoder/decoder.js index f5e985b..8a84e02 100644 --- a/electron/decoder/decoder.js +++ b/electron/decoder/decoder.js @@ -433,7 +433,7 @@ async function DecodePfmFile(extensionlessFilePath,) { let pflLines = records.map((record) => { return ( _.pick(record, [ - "MAT_TYPE", "CAL_PRETHR" + "MATL_TYPE", "CAL_PRETHR" ]) ); }); diff --git a/electron/estimate-scrubber/estimate-scrubber.js b/electron/estimate-scrubber/estimate-scrubber.js index 17d3833..44c0ae1 100644 --- a/electron/estimate-scrubber/estimate-scrubber.js +++ b/electron/estimate-scrubber/estimate-scrubber.js @@ -8,6 +8,31 @@ const axios = require("axios"); const TestJson = require("./A.json"); const { BrowserWindow } = require("electron"); +// Function to write job object to logs subfolder +async function writeJobToLogsFolder(job, fileName) { + try { + // 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) { + log.error('Error writing job object to logs folder:', error); + throw error; + } +} + async function ScrubEstimate({ job }) { //TODO: Fetch these from ImEX Online API. const basicAuthUser = "Imex"; @@ -30,11 +55,31 @@ async function ScrubEstimate({ job }) { job.g_ttl_amt = job.clm_total; delete job.clm_total; + //Adjust the rates field to be MAT_TYPE instead of MATL_TYPE + if (job.rates && Array.isArray(job.rates)) { + job.rates.forEach(rate => { + if (rate.MATL_TYPE) { + rate.MAT_TYPE = rate.MATL_TYPE; + delete rate.MATL_TYPE; + } + }); + } + console.log("*** ~ ScrubEstimate ~ job:", job); - log.debug("Estimate Scrubber Job Data:", job); + log.log("Estimate Scrubber Job Data:", job); + //Build the JSON Form Data const fileName = `RPSTest-${job.id}-${Date.now()}`; + + // Write job object to logs subfolder + try { + await writeJobToLogsFolder(job, fileName); + } catch (error) { + 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`); @@ -49,7 +94,7 @@ async function ScrubEstimate({ job }) { const resultPDFUrl = result?.data?.[0] || `https://www.insurtechtoolkit.com/analysis/${fileName}.pdf`; - log.debug("Estimate Scrubber Result:", result.data, resultPDFUrl); + log.log("Estimate Scrubber Result:", result.data, resultPDFUrl); const pdfWindow = new BrowserWindow({ webPreferences: { diff --git a/package.json b/package.json index 406b30f..477f47e 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.1", + "version": "1.4.2-alpha.2", "main": "electron/main.js", "homepage": "./", "dependencies": { diff --git a/src/ipc/ipc-estimate-utils.js b/src/ipc/ipc-estimate-utils.js index ed43a61..45f9ce7 100644 --- a/src/ipc/ipc-estimate-utils.js +++ b/src/ipc/ipc-estimate-utils.js @@ -20,7 +20,7 @@ export function CalculateVehicleAge(job) { const parsedYr = parseInt(job.v_model_yr); const vehicleYr = dayjs().year() + 1 - 2000 >= parsedYr ? 2000 + parsedYr : 1900 + parsedYr; const closeDate = job.close_date ? dayjs(job.close_date) : dayjs(); - const lossDate = job.loss_date ? dayjs(job.loss_date) : dayjs(); + const lossDate = job.loss_date ? dayjs.utc(job.loss_date) : dayjs(); let ret; if (closeDate.isSameOrAfter(dayjs("2023-04-01"))) {