diff --git a/spec/ing.pdf b/spec/ing.pdf index 11f5649..d505fda 100644 Binary files a/spec/ing.pdf and b/spec/ing.pdf differ diff --git a/src/Parser/Banking/Mt940/Engine/Ing.php b/src/Parser/Banking/Mt940/Engine/Ing.php index 326ad2e..add3d50 100644 --- a/src/Parser/Banking/Mt940/Engine/Ing.php +++ b/src/Parser/Banking/Mt940/Engine/Ing.php @@ -79,6 +79,30 @@ protected function parseTransactionAccountName() return $this->parseNameFromTransactionData($results[1]); } + /** + * Overloaded: ING uses the :61: date-part of the field for two values: + * Valuetimestamp (YYMMDD) and Entry date (book date) (MMDD). + * + * @return int + */ + protected function parseTransactionEntryTimestamp() + { + $results = []; + if (preg_match('/^:61:(\d{2})((\d{2})\d{2})((\d{2})\d{2})[C|D]/', $this->getCurrentTransactionData(), $results) + && !empty($results[1]) + ) { + + 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; + } + /** * @param $transactionData * diff --git a/test/Parser/Banking/Mt940/Engine/Ing/ParseTest.php b/test/Parser/Banking/Mt940/Engine/Ing/ParseTest.php index 5a9e860..078586e 100644 --- a/test/Parser/Banking/Mt940/Engine/Ing/ParseTest.php +++ b/test/Parser/Banking/Mt940/Engine/Ing/ParseTest.php @@ -38,4 +38,20 @@ public function testParsesAllFoundStatements() $this->assertEquals('23-07-2010', $first->getEndTimestamp('d-m-Y')); $this->assertEquals(-3.47, $first->getDeltaPrice()); } + + /** + * + */ + public function testParseTransactionEntryTimestamp() + { + $statements = $this->engine->parse(); + $transactions = reset($statements)->getTransactions(); + // the first has no entryTimestamp + $firstTransaction = reset($transactions); + $this->assertEquals(0, $firstTransaction->getEntryTimestamp()); + + // the last does have an entryTimestamp (custom edited) + $lastTransaction = end($transactions); + $this->assertEquals('2010-07-21', $lastTransaction->getEntryTimestamp('Y-m-d')); + } } diff --git a/test/Parser/Banking/Mt940/Engine/Ing/sample b/test/Parser/Banking/Mt940/Engine/Ing/sample index c6c149f..9824260 100644 --- a/test/Parser/Banking/Mt940/Engine/Ing/sample +++ b/test/Parser/Banking/Mt940/Engine/Ing/sample @@ -25,6 +25,9 @@ TMG TANGO ING Bank inzake GPKyoto :61:100722C3,68NVZ NONREF :86:0111111111 EJ46GREENP100610T1456 CLIEOP TMG GPHONGKONG AMSTERDAM +:61:1007220721C3,68NVZ NONREF +:86:0111111111 EJ46GREENP100610T1456 +CLIEOP TMG GPHONGKONG AMSTERDAM :62F:C100723EUR3,47 :86:D000004C000002D25,24C28,71 ­XXX \ No newline at end of file