mschindler83/fints-hbci-php

Parse MT940 loses data when new line ist between code-characters

Opened this issue · 3 comments

166?00GUTSCHRIFT?109251?20SVWZ+Rechnung xxx?30DEUTDEDB276?3 1DE1127xxxxx40011xxxxxx?32Testfirma GmbH

This is the description in the MT940 Class as it enters the function protected function parseDescription($descr)

As you see, after the BIC the code for accountnumber is splitted by a newline: xxxx?3[new line]1
So the parser can't parse the accountnumber and it's displayed as empty.

I've added the following to line 155 ofMT940.php

//search for newlines in codes from 10-63 and remove them foreach($prepared as $key => $value){ $keystring = (string) $key; if(strlen ($keystring) == 2){ $first = substr($keystring,0,1); $last = substr($keystring,-1,1); $descr = str_replace("$first\r\n$last", "$first$last", $descr); } }
This will remove the newlines in all codes with two digits from 10 to 63.
As I'm not a php expert, this code is working for me and i'd like know wether it is suitable!

I cannot reproduce your issue. So far, I haven't looked at your proposed fix, but I'm happy to do so once I understand the issue. Are you testing with the latest released version (1.0.4) or the code in the master branch?

I copied the current parseDescription() code from master to phpfiddle.org (here's a copy: https://gist.github.com/Philipp91/2acbff5835a0365b84dc26079d2d935e) and ran it with your example. I inserted the line break \r\n in the position you indicated (hope I got that right). I'm getting the following output:

Array
(
    [description] => Array
        (
            [SVWZ] => Rechnung xxx
        )

    [booking_text] => GUTSCHRIFT
    [primanoten_nr] => 9251
    [description_1] => SVWZ+Rechnung xxx
    [bank_code] => DEUTDEDB276
    [account_number] => DE1127xxxxx40011xxxxxx
    [name] => Testfirma GmbH
    [text_key_addition] => 
    [description_2] => 
)

In particular, the account_number is present.

What am I missing?

@Makku01 Could you try https://github.com/nemiah/phpFinTS? I just made some fixes concerning a similar problem.

@Philipp91 Please try your GIST without the charcters for the new line as in:

print_r(parseDescription("166?00GUTSCHRIFT?109251?20SVWZ+Rechnung xxx?30DEUTDEDB276?3 1DE1127xxxxx40011xxxxxx?32Testfirma GmbH"));

As you'll see, the Account Number is empty.

PS: Sorry for the delayed reply!
@ampaze I'll try it soon, Thanks!