Skip to content

Commit

Permalink
Merge pull request #67 from fruitl00p/ing-entry-date
Browse files Browse the repository at this point in the history
Ing entry date
  • Loading branch information
fruitl00p authored Jul 3, 2019
2 parents 2ba9fd7 + ef26784 commit d7cdbc0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
Binary file modified spec/ing.pdf
Binary file not shown.
24 changes: 24 additions & 0 deletions src/Parser/Banking/Mt940/Engine/Ing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
16 changes: 16 additions & 0 deletions test/Parser/Banking/Mt940/Engine/Ing/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
3 changes: 3 additions & 0 deletions test/Parser/Banking/Mt940/Engine/Ing/sample
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d7cdbc0

Please sign in to comment.