Implement support for ING transfers
This commit is contained in:
@@ -17,38 +17,35 @@ export function loadTransactions(file: string, profile: string, server: string,
|
||||
throw new Error(`Unknown server: ${server}`);
|
||||
}
|
||||
|
||||
const parser = createParser(profileConfig);
|
||||
const parser = createParser(profileConfig, serverConfig);
|
||||
|
||||
const actualServer = new Actual(serverConfig);
|
||||
const actualServer = new Actual(serverConfig, false);
|
||||
const skipped: string[] = [];
|
||||
|
||||
const handleRow = async (data: string[]) => {
|
||||
const transaction = await parser.parseTransaction(profileConfig, data);
|
||||
const pushed = await parser.pushTransaction(data);
|
||||
|
||||
if (transaction === undefined) {
|
||||
if (!pushed) {
|
||||
skipped.push(`Skipped ==> ${data.join(" ::: ")}`);
|
||||
return;
|
||||
}
|
||||
|
||||
actualServer.pushTransaction(transaction);
|
||||
};
|
||||
|
||||
const handleClose = () => actualServer.submit()
|
||||
.then(x => {
|
||||
console.log(`Inserted: ${x.added.length}`);
|
||||
console.log(`Updated: ${x.updated.length}`);
|
||||
console.log(`Errors: ${x.errors?.length}`);
|
||||
console.log(`Skipped: ${skipped.length}`);
|
||||
const handleClose = async () => {
|
||||
try {
|
||||
const transactions = await parser.reconcile();
|
||||
const result = await actualServer.submit(transactions);
|
||||
const now = new Date();
|
||||
const date = `${now.getFullYear()}-${(now.getMonth()+1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')}`;
|
||||
const time = `${now.getHours().toString().padStart(2, '0')}-${now.getMinutes().toString().padStart(2, '0')}-${now.getSeconds().toString().padStart(2, '0')}`
|
||||
const filename = `${serverConfig.data}/import.${profile}.${server}.${date}T${time}.json`.replaceAll(/\/+/g, "/");
|
||||
|
||||
const logContent = `${JSON.stringify(x, undefined, 2)}\n\n\n\n${skipped.join("\n")}`
|
||||
const logContent = `${JSON.stringify(result, undefined, 2)}\n\n\n\n${skipped.join("\n")}`
|
||||
fs.writeFileSync(filename, logContent);
|
||||
console.log(`Detailed output written to ${filename} file.`);
|
||||
})
|
||||
.catch(x => console.error(x))
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
fs.createReadStream(file)
|
||||
.pipe(iconv.decodeStream(profileConfig.encoding ?? "utf8"))
|
||||
|
||||
Reference in New Issue
Block a user