Skip to content

Commit

Permalink
Parse :86: field as additional information relating to statement
Browse files Browse the repository at this point in the history
Fixes issue raised in webschik#12, where an `:86:` field relating to the statement as a whole was being parsed as relating to a specific transaction.
  • Loading branch information
ndrsn committed Feb 26, 2020
1 parent a09dd06 commit aa0b067
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface Statement {
closingAvailableBalance?: BalanceInfo;
forwardAvailableBalance?: BalanceInfo;
transactions: Transaction[];
additionalInformation?: string;
}

export interface ReadOptions {
Expand Down
14 changes: 13 additions & 1 deletion src/tags/information-for-account-owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,22 @@ const informationTag: Tag = {
}
}

statement.transactions[state.transactionIndex].description = String.fromCharCode.apply(
var informationToAccountOwner = String.fromCharCode.apply(
String,
description
).trim();

var transactionHasDescription = statement.transactions[state.transactionIndex].description !== '';

// All :86: fields must be directly preceded by a transaction statement line (:61:),
// so if the current transaction already has a description, we may assume this is
// yet another :86: field, and therefore contains additional information about
// the statement as a whole rather than just about the transaction.
if (transactionHasDescription === false) {
statement.transactions[state.transactionIndex].description = informationToAccountOwner;
} else {
statement.additionalInformation = informationToAccountOwner;
}
}
};

Expand Down
1 change: 1 addition & 0 deletions test/cases/ing-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"referenceNumber": "INGEB",
"accountId": "0111111111",
"number": "100",
"additionalInformation": "D000001C000002D10000,99C11,01ING TESTREKENINGXXX",
"openingBalance": {
"isCredit": true,
"date": "2010-07-22",
Expand Down
2 changes: 1 addition & 1 deletion test/cases/ing-1.mta
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ POSTEN
:64:D100723EUR9945,09
:65:D100724EUR9945,09
:65:D100726EUR9945,09
:86 :D000001C000002D10000,99C11,01
:86:D000001C000002D10000,99C11,01
ING TESTREKENING
XXX

0 comments on commit aa0b067

Please sign in to comment.