a-fas / mt940js

Swift MT940 bank statement javascript parser
Apache License 2.0
32 stars 17 forks source link

Can't handle swift with no TAG 61 #12

Closed nickidk4 closed 5 years ago

nickidk4 commented 5 years ago

If swift does not contain tag 61 it fails with error: TypeError: Cannot read property 'details' of undefined

Code must check if t is not undefined.

parser.js:279

if (tag instanceof Tags.TagTransactionDetails) {
  let t = statement.transactions[statement.transactions.length - 1];
  (t != undefined) ? t.details += (t.details && '\n') + tag.fields.transactionDetails : null;
}
a-fas commented 5 years ago

details is '' by default - https://github.com/a-fas/mt940js/blob/master/lib/parser.js#L273 Does this mean that you have tag 86 without preceding tag 61 ?

P.S. example would help ;) all of real bugs should be unit tested, and UTs require examples ... ;)

nickidk4 commented 5 years ago

Yes I have a swift with a tag 86 wihout preceeding tag 61 :)

Tag 61 is optional.

a-fas commented 5 years ago

really need an example. This does not make sense to me. The main information in the transaction is it's amount, so tag 61 is kind of header for tag 86. it can exist without 86 but the opposite does not make sense.

nickidk4 commented 5 years ago

I have censored an example swift for you here :) And yes it doesn't make sense not to include the 61 tag..

{1:F01ESSEDK22AXXX7000000000}{2:O0000000000000BBHCUS33LXXX02305811441800000000N}{3:{108:D87R000000001380}}{4:
:20:X00240000000000K
:25:2000000
:28C:8/1
:60F:C180924DKK0000000,54
:62F:C180924DKK0000000,54
:86:00127589001
DKK XXXX XXXX DK CB(MT) SMF 30
JAPAN XXXXXX XXXXXX BANK, LTD.
RE  SMTB XXXXXXX COVERED BOND
(MID TERM XXXX) XXXXXXXX XXXX FUND
-}{5:{CHK:DBDD000XXX00}{DLM:}{CAC:VALIDATION SUCCESS}}
a-fas commented 5 years ago

ok ... so it is at the very end ... it is kind of comment to the whole statement ... I'll see what can be done btw seems to be a part of the spec in this way: https://www2.swift.com/knowledgecentre/publications/us9m_20180720/2.0?topic=ajc.htm%23genajc

nickidk4 commented 5 years ago

I see.. So tag 86 can be both like a comment to the transaction (61) and to the swift itself.

a-fas commented 5 years ago

check the latest code, should be in informationToAccountOwner at the statement level https://github.com/a-fas/mt940js/blob/master/test/parser.test.js#L255

nickidk4 commented 5 years ago

Works :)