WIP Line Calculations

This commit is contained in:
Patrick Fic
2020-10-16 13:18:18 -07:00
parent 4582bd0f4d
commit c94f525a3e
21 changed files with 339 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
const { DBFFile } = require("dbffile");
const path = require("path");
const _ = require("lodash");
const log = require("electron-log");
async function DecodeEstimate(filePath) {
const parsedFilePath = path.parse(filePath);
@@ -8,7 +9,6 @@ async function DecodeEstimate(filePath) {
parsedFilePath.dir,
parsedFilePath.name
);
console.log("DecodeEstimate -> extensionlessFilePath", extensionlessFilePath);
const ret = {
...(await DecodeAd1File(extensionlessFilePath)),
...(await DecodeVehFile(extensionlessFilePath)),
@@ -16,7 +16,10 @@ async function DecodeEstimate(filePath) {
...(await DecodeLinFile(extensionlessFilePath)),
};
if (ret.V_MILEAGE > 20000) return ret;
if (ret.V_MILEAGE > 20000)
return _.transform(ret, function (result, val, key) {
result[key.toLowerCase()] = val;
});
return null;
}
@@ -181,7 +184,6 @@ 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, [
@@ -233,6 +235,7 @@ async function DecodeLinFile(extensionlessFilePath) {
]),
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());
}
@@ -241,22 +244,28 @@ async function DecodeLinFile(extensionlessFilePath) {
)
);
//Perform required RPS Validations.
//Update DB Prices.
const massagedJobLines = joblines
const m = joblines
.filter(
(jobline) =>
jobline.PART_TYPE &&
!jobline.db_ref.startsWith("900") &&
(jobline.part_type && jobline.part_type.toUpperCase()) !== "PAG" &&
jobline.glass_flag === false
)
.map((jobline) => {
//
console.log("Massagejobline", jobline);
if (
(jobline.db_price === null || jobline.db_price === 0) &&
!!jobline.act_price &&
jobline.act_price > 0
) {
console.log(1, jobline.line_desc, jobline.db_price, jobline.act_price);
log.info(
"DB Price null/lower than act price",
jobline.line_desc,
jobline.db_price,
jobline.act_price
);
jobline.db_price = jobline.act_price;
}
@@ -265,14 +274,22 @@ async function DecodeLinFile(extensionlessFilePath) {
jobline.act_price &&
jobline.act_price > jobline.db_price
) {
log.info(
"Act price higher than existing db price",
jobline.line_desc,
jobline.db_price,
jobline.act_price
);
console.log(2, jobline.line_desc, jobline.db_price, jobline.act_price);
jobline.db_price = jobline.act_price;
}
delete jobline.glass_flag;
console.log(jobline);
return jobline;
});
return { joblines: { data: massagedJobLines } };
return { joblines: { data: joblines } };
}
exports.DecodeEstimate = DecodeEstimate;