Refactor PPC to pull out reusable componenets.
This commit is contained in:
21
src/main/util/createDirectoryIfNotExist.ts
Normal file
21
src/main/util/createDirectoryIfNotExist.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import log from "electron-log/main";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||
|
||||
const createdDirectoryIfNotExist = async (dirpath: string) => {
|
||||
try {
|
||||
const directoryPath = path.dirname(dirpath);
|
||||
if (!fs.existsSync(directoryPath)) {
|
||||
log.info(`Directory does not exist. Creating: ${directoryPath}`);
|
||||
fs.mkdirSync(directoryPath, { recursive: true });
|
||||
}
|
||||
} catch (error) {
|
||||
log.error("Error creating directory as needed", errorTypeCheck(error));
|
||||
throw new Error(
|
||||
"Error creating directory: " + errorTypeCheck(error).message,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default createdDirectoryIfNotExist;
|
||||
@@ -0,0 +1,154 @@
|
||||
import { FieldDescriptor } from "dbffile";
|
||||
|
||||
export const envFieldLineDescriptors: FieldDescriptor[] = [
|
||||
{
|
||||
name: "EST_SYSTEM",
|
||||
type: "C",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "SW_VERSION",
|
||||
type: "C",
|
||||
size: 10,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "DB_VERSION",
|
||||
type: "C",
|
||||
size: 12,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "DB_DATE",
|
||||
type: "D",
|
||||
size: 8,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "UNQFILE_ID",
|
||||
type: "C",
|
||||
size: 8,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "RO_ID",
|
||||
type: "C",
|
||||
size: 8,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "ESTFILE_ID",
|
||||
type: "C",
|
||||
size: 38,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "SUPP_NO",
|
||||
type: "C",
|
||||
size: 3,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "EST_CTRY",
|
||||
type: "C",
|
||||
size: 3,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "TOP_SECRET",
|
||||
type: "C",
|
||||
size: 80,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "H_TRANS_ID",
|
||||
type: "C",
|
||||
size: 9,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "H_CTRL_NO",
|
||||
type: "C",
|
||||
size: 9,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "TRANS_TYPE",
|
||||
type: "C",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "STATUS",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "CREATE_DT",
|
||||
type: "D",
|
||||
size: 8,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "CREATE_TM",
|
||||
type: "C",
|
||||
size: 6,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "TRANSMT_DT",
|
||||
type: "D",
|
||||
size: 8,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "TRANSMT_TM",
|
||||
type: "C",
|
||||
size: 6,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "INCL_ADMIN",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "INCL_VEH",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "INCL_EST",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "INCL_PROFL",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "INCL_TOTAL",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "INCL_VENDR",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "EMS_VER",
|
||||
type: "C",
|
||||
size: 5,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,274 @@
|
||||
import { FieldDescriptor } from "dbffile";
|
||||
|
||||
export const linFieldDescriptors: FieldDescriptor[] = [
|
||||
{
|
||||
name: "LINE_NO",
|
||||
type: "N",
|
||||
size: 3,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "LINE_IND",
|
||||
type: "C",
|
||||
size: 3,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "LINE_REF",
|
||||
type: "N",
|
||||
size: 3,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "TRAN_CODE",
|
||||
type: "C",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "DB_REF",
|
||||
type: "C",
|
||||
size: 7,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "UNQ_SEQ",
|
||||
type: "N",
|
||||
size: 4,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "WHO_PAYS",
|
||||
type: "C",
|
||||
size: 2,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "LINE_DESC",
|
||||
type: "C",
|
||||
size: 40,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "PART_TYPE",
|
||||
type: "C",
|
||||
size: 4,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "PART_DES_J",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "GLASS_FLAG",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "OEM_PARTNO",
|
||||
type: "C",
|
||||
size: 25,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "PRICE_INC",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "ALT_PART_I",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "TAX_PART",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "DB_PRICE",
|
||||
type: "N",
|
||||
size: 9,
|
||||
decimalPlaces: 2,
|
||||
},
|
||||
{
|
||||
name: "ACT_PRICE",
|
||||
type: "N",
|
||||
size: 9,
|
||||
decimalPlaces: 2,
|
||||
},
|
||||
{
|
||||
name: "PRICE_J",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "CERT_PART",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "PART_QTY",
|
||||
type: "N",
|
||||
size: 2,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "ALT_CO_ID",
|
||||
type: "C",
|
||||
size: 20,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "ALT_PARTNO",
|
||||
type: "C",
|
||||
size: 25,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "ALT_OVERRD",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "ALT_PARTM",
|
||||
type: "C",
|
||||
size: 45,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "PRT_DSMK_P",
|
||||
type: "N",
|
||||
size: 7,
|
||||
decimalPlaces: 2,
|
||||
},
|
||||
{
|
||||
name: "PRT_DSMK_M",
|
||||
type: "N",
|
||||
size: 9,
|
||||
decimalPlaces: 2,
|
||||
},
|
||||
{
|
||||
name: "MOD_LBR_TY",
|
||||
type: "C",
|
||||
size: 4,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "DB_HRS",
|
||||
type: "N",
|
||||
size: 5,
|
||||
decimalPlaces: 1,
|
||||
},
|
||||
{
|
||||
name: "MOD_LB_HRS",
|
||||
type: "N",
|
||||
size: 5,
|
||||
decimalPlaces: 1,
|
||||
},
|
||||
{
|
||||
name: "LBR_INC",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "LBR_OP",
|
||||
type: "C",
|
||||
size: 4,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "LBR_HRS_J",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "LBR_TYP_J",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "LBR_OP_J",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "PAINT_STG",
|
||||
type: "N",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "PAINT_TONE",
|
||||
type: "N",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "LBR_TAX",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "LBR_AMT",
|
||||
type: "N",
|
||||
size: 9,
|
||||
decimalPlaces: 2,
|
||||
},
|
||||
{
|
||||
name: "MISC_AMT",
|
||||
type: "N",
|
||||
size: 9,
|
||||
decimalPlaces: 2,
|
||||
},
|
||||
{
|
||||
name: "MISC_SUBLT",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "MISC_TAX",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "BETT_TYPE",
|
||||
type: "C",
|
||||
size: 4,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
{
|
||||
name: "BETT_PCTG",
|
||||
type: "N",
|
||||
size: 8,
|
||||
decimalPlaces: 4,
|
||||
},
|
||||
{
|
||||
name: "BETT_AMT",
|
||||
type: "N",
|
||||
size: 9,
|
||||
decimalPlaces: 2,
|
||||
},
|
||||
{
|
||||
name: "BETT_TAX",
|
||||
type: "L",
|
||||
size: 1,
|
||||
decimalPlaces: 0,
|
||||
},
|
||||
];
|
||||
36
src/main/util/ems-util.ts
Normal file
36
src/main/util/ems-util.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import path from "path";
|
||||
import store from "../store/store";
|
||||
import fs from "fs";
|
||||
|
||||
const generatePpcFilePath = (filename: string): string => {
|
||||
const ppcOutFilePath: string | null = store.get("settings.ppcFilePath");
|
||||
if (!ppcOutFilePath) {
|
||||
throw new Error("PPC file path is not set");
|
||||
}
|
||||
return path.resolve(ppcOutFilePath, filename);
|
||||
};
|
||||
|
||||
const generateEmsOutFilePath = (filename: string): string => {
|
||||
const emsOutFilePath: string | null = store.get("settings.emsOutFilePath");
|
||||
if (!emsOutFilePath) {
|
||||
throw new Error("EMS Out file path is not set");
|
||||
}
|
||||
return path.resolve(emsOutFilePath, filename);
|
||||
};
|
||||
|
||||
const deleteEmsFileIfExists = async (filename: string): Promise<void> => {
|
||||
// Check if the file exists and delete it if it does
|
||||
try {
|
||||
await fs.promises.access(filename); // Check if the file exists
|
||||
await fs.promises.unlink(filename); // Delete the file
|
||||
console.log(`Existing file at ${filename} deleted.`);
|
||||
} catch (err) {
|
||||
if ((err as NodeJS.ErrnoException).code !== "ENOENT") {
|
||||
// If the error is not "file not found", rethrow it
|
||||
throw err;
|
||||
}
|
||||
console.log(`No existing file found at ${filename}.`);
|
||||
}
|
||||
};
|
||||
|
||||
export { generatePpcFilePath, generateEmsOutFilePath, deleteEmsFileIfExists };
|
||||
Reference in New Issue
Block a user