Updates for dynamic ruleset choices.

This commit is contained in:
Patrick Fic
2023-02-09 12:52:57 -08:00
parent 7e12247f8b
commit 1f0bcf5611
8 changed files with 147 additions and 39 deletions

View File

@@ -8,13 +8,27 @@ const ipcTypes = require("../../src/ipc.types");
const {
NewNotification,
} = require("../notification-wrapper/notification-wrapper");
const { WhichRulesetToApply } = require("./constants");
//const Nucleus = require("nucleus-nodejs");
async function ImportJob(path) {
const b = BrowserWindow.getAllWindows()[0];
b.webContents.send(ipcTypes.default.estimate.toRenderer.estimateDecodeStart);
const newJob = await DecodeEstimate(path);
async function ImportJob(filepath) {
const parsedFilePath = path.parse(filepath);
let extensionlessFilePath = path.join(
parsedFilePath.dir,
parsedFilePath.name
);
const decodedJob = await DecodeAd1File(extensionlessFilePath);
const b = BrowserWindow.getAllWindows()[0];
b.webContents.send(ipcTypes.default.estimate.toRenderer.getCloseDate, {
filepath,
clm_no: decodedJob.CLM_NO,
});
}
async function ImportJobWithCloseDate(filepath, close_date) {
const newJob = await DecodeEstimate(filepath, false, close_date);
const b = BrowserWindow.getAllWindows()[0];
if (newJob && !newJob.ERROR) {
b.webContents.send(
ipcTypes.default.estimate.toRenderer.estimateDecodeSuccess,
@@ -35,7 +49,13 @@ async function ImportJob(path) {
}
}
async function DecodeEstimate(filePath, includeFilePathInReturnJob = false) {
exports.ImportJobWithCloseDate = ImportJobWithCloseDate;
async function DecodeEstimate(
filePath,
includeFilePathInReturnJob = false,
close_date = null
) {
const parsedFilePath = path.parse(filePath);
let extensionlessFilePath = path.join(
parsedFilePath.dir,
@@ -45,7 +65,7 @@ async function DecodeEstimate(filePath, includeFilePathInReturnJob = false) {
...(await DecodeAd1File(extensionlessFilePath)),
...(await DecodeVehFile(extensionlessFilePath)),
...(await DecodeTtlFile(extensionlessFilePath)),
...(await DecodeLinFile(extensionlessFilePath)),
...(await DecodeLinFile(extensionlessFilePath, close_date)),
...(includeFilePathInReturnJob ? { filePath } : {}),
};
@@ -286,7 +306,7 @@ async function DecodeTtlFile(extensionlessFilePath) {
return { clm_total: records[0]["G_TTL_AMT"] };
}
async function DecodeLinFile(extensionlessFilePath) {
async function DecodeLinFile(extensionlessFilePath, close_date) {
let dbf = await DBFFile.open(`${extensionlessFilePath}.LIN`);
let records = await dbf.readRecords();
let joblines = records.map((record) => {
@@ -356,12 +376,20 @@ async function DecodeLinFile(extensionlessFilePath) {
joblines.map((jobline) => {
jobline.ignore = false;
const rulesetToApply = WhichRulesetToApply(close_date);
if (false) {
jobline = V2Ruleset(jobline);
} else {
jobline = V1Ruleset(jobline);
switch (rulesetToApply) {
case "V1":
jobline = V1Ruleset(jobline, joblines);
break;
case "V2":
jobline = V2Ruleset(jobline, joblines);
break;
default:
jobline = V1Ruleset(jobline, joblines);
break;
}
return jobline;
});
@@ -373,9 +401,8 @@ async function DecodeLinFile(extensionlessFilePath) {
exports.DecodeEstimate = DecodeEstimate;
exports.ImportJob = ImportJob;
function V1Ruleset(jobline) {
function V1Ruleset(jobline, joblines) {
//These set of MPI rules are valid until April 1, 2023.
log.info(`Using V1 ruleset for line scanning.`);
//Wheel Repair Pricing PRS-82
//Verified on 08/24/21
@@ -484,11 +511,11 @@ function V1Ruleset(jobline) {
return jobline;
}
function V2Ruleset(jobline) {
function V2Ruleset(jobline, joblines) {
//This is the rules psot 04/01/2023. They are a further restrictive set, and therefore
//V1 rules are called first, and then run through this filter as well.
V1Ruleset(jobline);
V1Ruleset(jobline, joblines);
//Remove any glass related items.
if (jobline.part_type.toUpperCase() === "PAG") {
@@ -497,7 +524,10 @@ function V2Ruleset(jobline) {
//ADAS Part Line
if (
AdasDescriptions.some((d) => jobline.line_desc.toLowerCase().includes(d))
AdasDescriptions.some((d) => {
const ret = jobline.line_desc.toLowerCase().includes(d);
return ret;
})
) {
jobline.ignore = true;
}