Skip to content

Commit

Permalink
Merge pull request #50 from fruitl00p/ABN-transaction-year-fix
Browse files Browse the repository at this point in the history
Transaction date year fix ABN
  • Loading branch information
fruitl00p committed Mar 27, 2017
2 parents 380a6c0 + e2fe580 commit a8d4ee4
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Parser/Banking/Mt940/Engine/Abn.php
Expand Up @@ -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;
Expand Down
36 changes: 36 additions & 0 deletions test/Parser/Banking/Mt940/Engine/Abn/ParseTest.php
Expand Up @@ -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'));
}
}
18 changes: 18 additions & 0 deletions 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
-
16 changes: 16 additions & 0 deletions 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

0 comments on commit a8d4ee4

Please sign in to comment.