Added file scanning module.
This commit is contained in:
@@ -3,8 +3,37 @@ const path = require("path");
|
||||
const _ = require("lodash");
|
||||
const log = require("electron-log");
|
||||
const { store } = require("../electron-store");
|
||||
const { BrowserWindow } = require("electron");
|
||||
const ipcTypes = require("../../src/ipc.types");
|
||||
const {
|
||||
NewNotification,
|
||||
} = require("../notification-wrapper/notification-wrapper");
|
||||
|
||||
async function DecodeEstimate(filePath) {
|
||||
async function ImportJob(path) {
|
||||
const b = BrowserWindow.getAllWindows()[0];
|
||||
b.webContents.send(ipcTypes.default.estimate.toRenderer.estimateDecodeStart);
|
||||
const newJob = await DecodeEstimate(path);
|
||||
|
||||
if (newJob && !newJob.ERROR) {
|
||||
b.webContents.send(
|
||||
ipcTypes.default.estimate.toRenderer.estimateDecodeSuccess,
|
||||
newJob
|
||||
);
|
||||
log.info(`Sent job for upload. ${newJob.clm_no}`);
|
||||
NewNotification({
|
||||
title: "Job Uploaded",
|
||||
body: "A new job has been uploaded.",
|
||||
}).show();
|
||||
} else {
|
||||
log.info(`Ignored job. ${newJob.ERROR}`);
|
||||
NewNotification({
|
||||
title: "Job Ignored",
|
||||
body: newJob.ERROR,
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
|
||||
async function DecodeEstimate(filePath, includeFilePathInReturnJob = false) {
|
||||
const parsedFilePath = path.parse(filePath);
|
||||
let extensionlessFilePath = path.join(
|
||||
parsedFilePath.dir,
|
||||
@@ -15,6 +44,7 @@ async function DecodeEstimate(filePath) {
|
||||
...(await DecodeVehFile(extensionlessFilePath)),
|
||||
...(await DecodeTtlFile(extensionlessFilePath)),
|
||||
...(await DecodeLinFile(extensionlessFilePath)),
|
||||
...(includeFilePathInReturnJob ? { filePath } : {}),
|
||||
};
|
||||
|
||||
const ad2 = await DecodeAd2File(extensionlessFilePath);
|
||||
@@ -297,12 +327,12 @@ async function DecodeLinFile(extensionlessFilePath) {
|
||||
!!jobline.act_price &&
|
||||
jobline.act_price > 0
|
||||
) {
|
||||
log.info(
|
||||
"DB Price null/lower than act price",
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -311,12 +341,12 @@ 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
|
||||
);
|
||||
// log.info(
|
||||
// "Act price higher than existing db price",
|
||||
// jobline.line_desc,
|
||||
// jobline.db_price,
|
||||
// jobline.act_price
|
||||
// );
|
||||
jobline.db_price = jobline.act_price;
|
||||
}
|
||||
|
||||
@@ -344,3 +374,4 @@ async function DecodeLinFile(extensionlessFilePath) {
|
||||
}
|
||||
|
||||
exports.DecodeEstimate = DecodeEstimate;
|
||||
exports.ImportJob = ImportJob;
|
||||
|
||||
Reference in New Issue
Block a user