fruitl00p / php-mt940

A mt940 parser in PHP
MIT License
103 stars 60 forks source link

ABNAMRO Transaction Entry Date parsing bug (using current years instead of booking year) #48

Closed RobQuistNL closed 7 years ago

RobQuistNL commented 7 years ago

Typical bug cases; we just had a customer that was reading in bank transactions, and the dates were 2017-12-15 instead of 2016-12-15.

The cause was found here; https://github.com/fruitl00p/php-mt940/blob/master/src/Parser/Banking/Mt940/Engine/Abn.php#L87-L94

As you can see in this code, only a month and date seem to be read in. The PHP Date function gets fed "mmdd" instead of "yymmdd" - and it works fine for the biggest part of the year. It will only fail if you're reading in transactions from a different year.

We had some transactions on that were 16-12-15 but got read in as 17-12-15 because the date function got fed "1215".

An example transaction looks like this:

ABNANL2A
940
ABNANL2A
:20:ABN AMRO BANK NV
:25:534334164
:28:35001/1
:60F:C161214EUR1124,58
:61:1612151215C109,65N654NONREF
:86:/TRTP/SEPA OVERBOEKING/IBAN/NL75INGB0001234567/BIC/INGBNL2A/NAME/
HR K XXXXXXX EN/OF MW H XXXXXXX/REMI/RES.NR 00042/EREF/NOTPROV
IDED
:61:1612151215D62,63N247NONREF
:86:/TRTP/SEPA INCASSO ALGEMEEN DOORLOPEND/CSID/NL36ZZZ123456780000
/NAME/XXXXXXXX B.V./MARF/000000059990/REMI//INV/1511682351 1.1
2.2016/IBAN/NL37DEUT0123456789/BIC/DEUTNL2AXXX/EREF/0123456789123
61000
:62F:C161215EUR1171,6
-

As you can see on this line there's 2 dates - 1 with a year and one without;

:61:161215---1215C109,65N654NONREF

We need to take the year in account or bank imports overlapping different years will break.

I'll be opening a PR for this issue.

fruitl00p commented 7 years ago

According to the spec There are supposed to be two dates: one is the transaction date the other the 'valuedate'. (the date they use for actual value changes of the amount ... I think)

According to that it would be more 'logical' to keep the year from the first and use it for the second too ? I can imagine that with a transaction starting on 31rst of december the value date might move to 1st of january the next year... ? But that could be checked too... Then again... It could also just differ by one day? (up or down... or maybe even more days... ?) What to do... ?

RobQuistNL commented 7 years ago

Yeah that would be a valid case.. I know that this will at least fix 99% of the problems occuring regarding these dates.

I'm not sure where else you could get a year from - using the current year (as is happening now) is definately not right. Maybe contact ABN and ask them what the intention was / is? Its not really clear for me when I look at the spec either..

fruitl00p commented 7 years ago

@RobQuistNL I've pushed a PR to try and fix this issue (#50) If you could check that it works we can merge it! :)

RobQuistNL commented 7 years ago

Looks good! Thanks for the quick response there man, appreciate it. Will test this tomorrow!

fruitl00p commented 7 years ago

@RobQuistNL great! Looking forward to the results!