mschindler83/fints-hbci-php

When customer have more than one account in the bank, data from first account is rewriting with data from second

mcprotector opened this issue · 14 comments

When customer have more than one account in the bank and construction for getting accounts information is
$accounts = $fints->getSEPAAccounts();
foreach ($accounts as $account) {
then data from first account is rewriting with data from second.

Issue is in a string (lib/Fhp/FinTS.php)
$masterArray += $r->getStatementOfAccountArray();
For correct work must be
$masterArray = array_merge($masterArray,$r->getStatementOfAccountArray());

Could you submit a pull request for codes changes?

MrCrankHank, I don't known how to do it. +) Can you help me?

There is a lot of documentation out there, e.g.:

https://gist.github.com/Chaser324/ce0505fbed06b947d962

Hi @mcprotector,

I don't get the problem here.
What has traversing over the accounts to do with fetching the bank statements?
Nethertheless when calling getStatementOfAccount() the $masterArray will get newly initiated on each call to this method. So it can not mix up with data from another account.

Maybe you can again explain in greater detail what the issue exactly is? Would be very good!

But still,... your suggestion to change += to array_merge is somehow valid. :)
I just don't see the issue.

Hello, Markus!

Maybe the problem is not because we have two accounts in one Bank. This relation i can't to confirm.
But this
$masterArray += $r->getStatementOfAccountArray();
rewrite masterArray elements by keys.
If i get in the first step
$r->getStatementOfAccountArray();
as
array(0 => 0, 1 => 1, 2 => 2),
and in the second step as
array(0 => 10, 1 => 11),
in result i get
array(0 => 10, 1 => 11, 2 => 2).
And two elements from first step is lost. In my case it happened.
Problem was happened with Cronbank, two accounts and access by one pint/tan.
Array-Operatoren

Okay thanks. Now I understand :)

PR #33 is mergend with master

I have found one more problem. +)
Transactions of a day may be splited to pages. Every page is as new array with dates as keys (e.g. 2017-01-10). When used += or array_merge, same day is replaced with new day array. New correct code is

foreach ($responses as $r) {
            $statementOfAccount = $r->getStatementOfAccountArray();
            foreach ($statementOfAccount as $day=>$info){
                if(isset($masterArray[$day])){
                    $masterArray[$day]['transactions'] = array_merge($masterArray[$day]['transactions'],$info['transactions']);
                } else {
                    $masterArray[$day] = $info;
                }
            }
        } 

I was trying to use array_merge_recursive. No result.

I see. Yes, array_merge_recursive will not help here.
I've a solution. I will create a PR for this.
@mcprotector maybe you can then test again with the new PR and tell me if it works.

@mcprotector
Can you please check if it works with this branch?

I'll try to check as soon as the time. Some files in my copy of fints-hbci-php is changed for getting additional data (not errors or troubles). I must replace my copy with your new commit. It takes time. +))

I'm pretty sure that the PR fixed the issue.
Closing.