53 lines
2.0 KiB
JavaScript
53 lines
2.0 KiB
JavaScript
const { ipcMain, dialog } = require("electron");
|
|
|
|
const ipcTypes = require("../../src/ipc.types.commonjs");
|
|
const { mainWindow } = require("../main");
|
|
const _ = require("lodash");
|
|
const { store } = require("../electron-store");
|
|
const path = require("path");
|
|
var xlsx = require("node-xlsx");
|
|
|
|
ipcMain.on(ipcTypes.default.audit.toMain.browseForFile, async (event, arg) => {
|
|
const result = await dialog.showOpenDialog(mainWindow, {
|
|
filters: [{ extensions: ["xls", "xlsx"], name: "Excel Files" }],
|
|
properties: ["openFile"]
|
|
});
|
|
if (!result.canceled) {
|
|
store.set("auditFilePath", result.filePaths);
|
|
var obj = xlsx.parse(result.filePaths[0], { cellDates: true }); // parses a file
|
|
|
|
const detailSheet = obj.find((sheet) => sheet.name === "Shop RPS Claim Detail");
|
|
const claimsArray = [];
|
|
let foundHeaderRow, foundTotalRow;
|
|
detailSheet.data.forEach((line) => {
|
|
//Check the first element. If it's claim number, we have our header row. the next one is important.
|
|
if (!foundHeaderRow && line[0] === "Claim Number") {
|
|
foundHeaderRow = true;
|
|
} else if (foundHeaderRow && !foundTotalRow && line[0] && line[0] !== "Grand Total") {
|
|
//Add it to the array
|
|
const row = {
|
|
clm_no: line[0],
|
|
close_date: line[1],
|
|
v_model_yr: line[3],
|
|
v_make_desc: line[4],
|
|
v_model: line[5],
|
|
under20kmiles: line[6],
|
|
pan_total: line[7],
|
|
paa_total: line[8],
|
|
pal_total: line[9],
|
|
pam_total: line[10],
|
|
eligible_db_price_total: Math.round((line[11] + Number.EPSILON) * 100) / 100,
|
|
eligible_act_price_total: Math.round((line[12] + Number.EPSILON) * 100) / 100,
|
|
expected_rps_dollars: Math.round((line[15] + Number.EPSILON) * 100) / 100,
|
|
actual_rps_dollars: Math.round((line[16] + Number.EPSILON) * 100) / 100
|
|
};
|
|
claimsArray.push(row);
|
|
} else {
|
|
// foundTotalRow = true;
|
|
}
|
|
});
|
|
|
|
event.sender.send(ipcTypes.default.audit.toRenderer.auditClaimsArray, claimsArray);
|
|
}
|
|
});
|