feat(core): Add support for CI workflows and update gitignore
This commit is contained in:
98
ts/commerzbank/csv-commerzbank.classes.csvcommerzbank.ts
Normal file
98
ts/commerzbank/csv-commerzbank.classes.csvcommerzbank.ts
Normal file
@ -0,0 +1,98 @@
|
||||
import * as plugins from '../csvparser.plugins.js';
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
|
||||
export class CsvCommerzbank extends plugins.portablefinance
|
||||
.AcCsvParser<interfaces.ICommerzbankTransaction> {
|
||||
// INSTANCE
|
||||
public paymentProviderName = 'Commerzbank';
|
||||
public description: string = `a csv parser for parsing downloaded csv transaction files from Commerzbank`;
|
||||
private csvDescriptorArray: plugins.portablefinance.ICsvDescriptor[] = [];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
addCsvDecriptor(csvDescriptorArg: plugins.portablefinance.ICsvDescriptor): void {
|
||||
this.csvDescriptorArray.push(csvDescriptorArg);
|
||||
}
|
||||
|
||||
public async getTransactions(): Promise<plugins.portablefinance.IMonetaryTransaction[]> {
|
||||
const payments: interfaces.ICommerzbankOriginalTransaction[] = [];
|
||||
|
||||
for (const csvDescriptor of this.csvDescriptorArray) {
|
||||
const csvInstance = await plugins.smartcsv.Csv.createCsvFromString(csvDescriptor.contentString, {
|
||||
headers: true,
|
||||
unquote: true,
|
||||
});
|
||||
|
||||
payments.push(
|
||||
...(await csvInstance.exportAsObject())
|
||||
);
|
||||
}
|
||||
|
||||
const finalTransactionArray: interfaces.ICommerzbankTransaction[] = [];
|
||||
for (const transaction of payments) {
|
||||
// transaction.Buchungstag = transaction.Wertstellung;
|
||||
console.log(transaction);
|
||||
const finalTransaction: interfaces.ICommerzbankTransaction = {
|
||||
simpleTransaction: null,
|
||||
transactionHash: null,
|
||||
original: transaction,
|
||||
amount: plugins.smartmoney.parseEuropeanNumberString(transaction.Betrag),
|
||||
currency: transaction.Währung,
|
||||
description: transaction.Buchungstext,
|
||||
transactionDate: plugins.smarttime.ExtendedDate.fromEuropeanDate(transaction.Buchungstag),
|
||||
valuationDate: plugins.smarttime.ExtendedDate.fromEuropeanDate(transaction.Wertstellung),
|
||||
transactionType: ((): interfaces.TTransactionType => {
|
||||
switch (transaction.Umsatzart) {
|
||||
case 'Gutschrift':
|
||||
return 'Credit';
|
||||
case 'Lastschrift':
|
||||
return 'Debit';
|
||||
case 'Zinsen/Entgelte':
|
||||
return 'BankFees';
|
||||
case 'Überweisung':
|
||||
return 'ActiveTransfer';
|
||||
default:
|
||||
throw new Error(`unknown transactiontype ${transaction.Umsatzart}`);
|
||||
}
|
||||
})(),
|
||||
};
|
||||
|
||||
// lets assign the transactionHash
|
||||
finalTransaction.transactionHash = await plugins.smarthash.sha265FromObject({
|
||||
description: finalTransaction.description,
|
||||
amount: finalTransaction.amount,
|
||||
date: finalTransaction.valuationDate,
|
||||
});
|
||||
|
||||
finalTransaction.simpleTransaction = {
|
||||
id: finalTransaction.transactionHash,
|
||||
accountId: null,
|
||||
name: finalTransaction.description,
|
||||
amount: finalTransaction.amount,
|
||||
description: finalTransaction.description,
|
||||
date: finalTransaction.transactionDate,
|
||||
};
|
||||
finalTransactionArray.push(finalTransaction);
|
||||
}
|
||||
|
||||
return finalTransactionArray.map((commerzbankTransaction) => {
|
||||
const fin2021Transaction: plugins.portablefinance.IMonetaryTransaction = {
|
||||
id: null,
|
||||
data: {
|
||||
additionalIds: [],
|
||||
amount: commerzbankTransaction.amount,
|
||||
date: commerzbankTransaction.transactionDate.getTime(),
|
||||
description: commerzbankTransaction.description,
|
||||
name: commerzbankTransaction.description,
|
||||
originAccountId: null,
|
||||
originTransactionId: commerzbankTransaction.transactionHash,
|
||||
paymentAccountId: null,
|
||||
justForLooks: null,
|
||||
},
|
||||
};
|
||||
return fin2021Transaction;
|
||||
});
|
||||
}
|
||||
}
|
1
ts/commerzbank/index.ts
Normal file
1
ts/commerzbank/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './csv-commerzbank.classes.csvcommerzbank.js';
|
1
ts/commerzbank/interfaces/index.ts
Normal file
1
ts/commerzbank/interfaces/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './interfaces.commerzbanktransaction.js';
|
@ -0,0 +1,30 @@
|
||||
import * as plugins from '../../csvparser.plugins.js';
|
||||
|
||||
export interface ICommerzbankOriginalTransaction {
|
||||
Buchungstag: string;
|
||||
Wertstellung: string;
|
||||
Umsatzart: 'Überweisung' | 'Gutschrift' | 'Lastschrift' | 'Zinsen/Entgelte';
|
||||
Buchungstext: string;
|
||||
Betrag: string;
|
||||
Währung: string;
|
||||
Auftraggeberkonto: string;
|
||||
'Bankleitzahl Auftraggeberkonto': string;
|
||||
'IBAN Auftraggeberkonto': string;
|
||||
Kategorie: string;
|
||||
}
|
||||
|
||||
export type TTransactionType = 'Credit' | 'Debit' | 'ActiveTransfer' | 'BankFees';
|
||||
|
||||
export interface ICommerzbankTransaction {
|
||||
simpleTransaction: plugins.tsclass.finance.ITransaction;
|
||||
transactionHash: string;
|
||||
original: ICommerzbankOriginalTransaction;
|
||||
|
||||
// translated to English
|
||||
transactionDate: plugins.smarttime.ExtendedDate;
|
||||
valuationDate: plugins.smarttime.ExtendedDate;
|
||||
transactionType: TTransactionType;
|
||||
description: string;
|
||||
amount: number;
|
||||
currency: string;
|
||||
}
|
Reference in New Issue
Block a user