Add several EMS file formats.

This commit is contained in:
Patrick Fic
2025-03-19 13:26:00 -07:00
parent 5ddfe4d86f
commit 3277af73f6
17 changed files with 745 additions and 7 deletions

View File

@@ -0,0 +1,52 @@
import { DBFFile } from "dbffile";
import log from "electron-log/main";
import _ from "lodash";
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
import errorTypeCheck from "../../util/errorTypeCheck";
import { DecodedTtl, DecodedTtlLine } from "./decode-ttl.interface";
const DecodeTtl = async (
extensionlessFilePath: string
): Promise<DecodedTtl> => {
let dbf: DBFFile | null = null;
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.TTL`);
} catch (error) {
log.error("Error opening TTL File.", errorTypeCheck(error));
}
if (!dbf) {
log.error(`Could not find any TTL files at ${extensionlessFilePath}`);
throw new Error(`Could not find any TTL files at ${extensionlessFilePath}`);
}
const rawDBFRecord = await dbf.readRecords(1);
//PFT will always have only 1 row.
//Commented lines have been cross referenced with existing partner fields.
const rawTtlData: DecodedTtlLine = deepLowerCaseKeys(
_.pick(rawDBFRecord[0], [
//TODO: Add typings for EMS File Formats.
"G_TTL_AMT",
"G_BETT_AMT",
"G_RPD_AMT",
"G_DED_AMT",
"G_CUST_AMT",
"G_AA_AMT",
"N_TTL_AMT",
"PREV_NET",
"SUPP_AMT",
"N_SUPP_AMT", //Previously commented. Possible issue.
"G_UPD_AMT",
"G_TTL_DISC",
"G_TAX",
"GST_AMT",
])
);
//Apply business logic transfomrations.
return { clm_total: 0, depreciation_taxes: 0, cieca_ttl: rawTtlData };
};
export default DecodeTtl;