mschindler83/fints-hbci-php

bookingDate is off by one year in some cases

i124q2n8 opened this issue · 0 comments

The bookingDate can be off by one year if the valuta date (month part) is earlier than the booking date.

The error is located in MT940.php:126

$year = substr($transaction, 0, 2);
$valutaDate = $this->getDate($year . substr($transaction, 2, 4));

$bookingDate = substr($transaction, 6, 4);
if (preg_match('/^\d{4}$/', $bookingDate)) {
	// if valuta date is earlier than booking date, then it must be in the new year.
	$year = substr($transaction, 2, 2) < substr($transaction, 6, 2) ? --$year : $year;
	$bookingDate = $this->getDate($year . $bookingDate);
}

The relevant input data to reproduce the error looks like this.

:61:1604300502DR100,00N032NONREF
:86:106?00AUSZAHLUNG?109200?20SVWZ+2016-04-30T06.07.39 Ka?21rte1 

The assumption that the valuta date cant be earlier than the booking date is wrong. (See comment above)
An easy way would be to calculate both dates (same year and previous year) and take the date with the least difference to the valuta date.

I don't know whether this solution has some other drawbacks.