diff --git a/src/Parser/Banking/Mt940/Engine/Abn.php b/src/Parser/Banking/Mt940/Engine/Abn.php index ae54412..f619fe8 100644 --- a/src/Parser/Banking/Mt940/Engine/Abn.php +++ b/src/Parser/Banking/Mt940/Engine/Abn.php @@ -85,10 +85,17 @@ protected function parseTransactionAccountName() protected function parseTransactionEntryTimestamp() { $results = []; - if (preg_match('/^:61:\d{6}(\d{4})[C|D]/', $this->getCurrentTransactionData(), $results) + if (preg_match('/^:61:(\d{2})((\d{2})\d{2})((\d{2})\d{2})[C|D]/', $this->getCurrentTransactionData(), $results) && !empty($results[1]) ) { - return $this->sanitizeTimestamp($results[1], 'md'); + + list(, $valueDateY, $valueDateMD, $valueDateM, $entryDateMD, $entryDateM) = $results; + $entryDate = $valueDateY.$entryDateMD; + if ($valueDateMD !== $entryDateMD && $valueDateM > $entryDateM) { + $entryDate = ($valueDateY+1).$entryDateMD; + } + + return $this->sanitizeTimestamp($entryDate, 'ymd'); } return 0; diff --git a/test/Parser/Banking/Mt940/Engine/Abn/ParseTest.php b/test/Parser/Banking/Mt940/Engine/Abn/ParseTest.php index 1563a59..ef0a5fd 100644 --- a/test/Parser/Banking/Mt940/Engine/Abn/ParseTest.php +++ b/test/Parser/Banking/Mt940/Engine/Abn/ParseTest.php @@ -42,4 +42,40 @@ public function testParsesAllFoundStatements() $this->assertEquals('23-06-2009', $last->getStartTimestamp('d-m-Y')); $this->assertEquals('24-06-2009', $last->getEndTimestamp('d-m-Y')); } + + public function testHandleEntryYearRollover() + { + $this->engine->loadString(file_get_contents(__DIR__.'/sample2')); + $statements = $this->engine->parse(); + + $this->assertCount(1, $statements); + list($sameday, $nextDay, $nextMonth, $nextYear) = $statements[0]->getTransactions(); + + $this->assertEquals('01-01-2009', $sameday->getValueTimestamp('d-m-Y')); + $this->assertEquals('01-01-2009', $sameday->getEntryTimestamp('d-m-Y')); + + $this->assertEquals('01-01-2009', $nextDay->getValueTimestamp('d-m-Y')); + $this->assertEquals('02-01-2009', $nextDay->getEntryTimestamp('d-m-Y')); + + $this->assertEquals('01-01-2009', $nextMonth->getValueTimestamp('d-m-Y')); + $this->assertEquals('01-02-2009', $nextMonth->getEntryTimestamp('d-m-Y')); + + $this->assertEquals('31-12-2009', $nextYear->getValueTimestamp('d-m-Y')); + $this->assertEquals('01-01-2010', $nextYear->getEntryTimestamp('d-m-Y')); + } + + public function testIssue48() + { + $this->engine->loadString(file_get_contents(__DIR__.'/issue48')); + $statements = $this->engine->parse(); + + $this->assertCount(1, $statements); + $transactions = $statements[0]->getTransactions(); + + $this->assertEquals('15-12-2016', $transactions[0]->getValueTimestamp('d-m-Y')); + $this->assertEquals('15-12-2016', $transactions[0]->getEntryTimestamp('d-m-Y')); + + $this->assertEquals('15-12-2016', $transactions[1]->getValueTimestamp('d-m-Y')); + $this->assertEquals('15-12-2016', $transactions[1]->getEntryTimestamp('d-m-Y')); + } } diff --git a/test/Parser/Banking/Mt940/Engine/Abn/issue48 b/test/Parser/Banking/Mt940/Engine/Abn/issue48 new file mode 100644 index 0000000..fd604db --- /dev/null +++ b/test/Parser/Banking/Mt940/Engine/Abn/issue48 @@ -0,0 +1,18 @@ +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 +- \ No newline at end of file diff --git a/test/Parser/Banking/Mt940/Engine/Abn/sample2 b/test/Parser/Banking/Mt940/Engine/Abn/sample2 new file mode 100644 index 0000000..2c10adc --- /dev/null +++ b/test/Parser/Banking/Mt940/Engine/Abn/sample2 @@ -0,0 +1,16 @@ +ABNANL2A +940 +ABNANL2A +:20:ABN AMRO BANK NV +:25:500950253 +:28:17501/1 +:60F:C090623EUR17369,99 +:61:0901010101D203,N369NONREF +:86:BEA 23.06.09/22.22 VILLA DORIA SCHOTEN,PAS590 +:61:0901010102D203,N369NONREF +:86:BEA 23.06.09/22.22 VILLA DORIA SCHOTEN,PAS590 +:61:0901010201D203,N369NONREF +:86:BEA 23.06.09/22.22 VILLA DORIA SCHOTEN,PAS590 +:61:0912310101D203,N369NONREF +:86:BEA 23.06.09/22.22 VILLA DORIA SCHOTEN,PAS590 +:62F:C090624EUR17159,49 \ No newline at end of file