nemiah / phpFinTS

PHP library to communicate with FinTS/HBCI servers
MIT License
130 stars 39 forks source link

added getEndBalance to "Statement" after transactions request #424

Closed nemiah closed 5 months ago

nemiah commented 6 months ago

Hi guys,

I added a new method getEndBalance to the Statement class to get the last balance of an account.

Any comments?

Philipp91 commented 5 months ago

Looks like this or one of the related changes broke lib/Tests/Fhp/Integration/DKB/GetStatementOfAccountTest.php. Why don't the tests run on PRs automatically anymore?

Philipp91 commented 5 months ago

It now gets these statements:

Fhp\Model\StatementOfAccount\StatementOfAccount Object
(
    [statements:protected] => Array
        (
            [0] => Fhp\Model\StatementOfAccount\Statement Object
                (
                    [transactions:protected] => Array
                        (
                            [0] => Fhp\Model\StatementOfAccount\Transaction Object
                                (
                                    [bookingDate:protected] => DateTime Object
                                        (
                                            [date] => 2019-09-04 00:00:00.000000
                                            [timezone_type] => 3
                                            [timezone] => UTC
                                        )
                                    [valutaDate:protected] => DateTime Object
                                        (
                                            [date] => 2019-09-03 00:00:00.000000
                                            [timezone_type] => 3
                                            [timezone] => UTC
                                        )
                                    [amount:protected] => 12
                                    [creditDebit:protected] => debit
                                    [isStorno:protected] => 
                                    [bookingCode:protected] => 177
                                    [bookingText:protected] => ONLINE-UEBERWEISUNG
                                    [description1:protected] => KREF+HKCCS12345SVWZ+32301000-P111111-33333333DATUM 02.09.2019, 22.19 UHR1.TAN 012345
                                    [description2:protected] => 
                                    [structuredDescription:protected] => Array
                                        (
                                            [KREF] => HKCCS12345
                                            [SVWZ] => 32301000-P111111-33333333 DATUM 02.09.2019, 22.19 UHR1.TAN 012345
                                        )
                                    [bankCode:protected] => DEUTDEBBXXX
                                    [accountNumber:protected] => DExx123412341234123431
                                    [name:protected] => EMPFAENGER ABCDE
                                    [booked:protected] => 1
                                    [pn:protected] => 9310
                                    [textKeyAddition:protected] => 997
                                )
                        )
                    [startBalance:protected] => 1234.56
                    [endBalance:protected] => 0
                    [creditDebit:protected] => credit
                    [date:protected] => DateTime Object
                        (
                            [date] => 2019-08-21 00:00:00.000000
                            [timezone_type] => 3
                            [timezone] => UTC
                        )
                )
            [1] => Fhp\Model\StatementOfAccount\Statement Object
                (
                    [transactions:protected] => Array
                        (
                            [0] => Fhp\Model\StatementOfAccount\Transaction Object
                                (
                                    [bookingDate:protected] => DateTime Object
                                        (
                                            [date] => 2019-09-14 00:00:00.000000
                                            [timezone_type] => 3
                                            [timezone] => UTC
                                        )
                                    [valutaDate:protected] => DateTime Object
                                        (
                                            [date] => 2019-09-13 00:00:00.000000
                                            [timezone_type] => 3
                                            [timezone] => UTC
                                        )
                                    [amount:protected] => 123.45
                                    [creditDebit:protected] => credit
                                    [isStorno:protected] => 
                                    [bookingCode:protected] => 152
                                    [bookingText:protected] => GUTSCHR. UEBERW. DAUERAUFTR
                                    [description1:protected] => SVWZ+Irgendein Käse
                                    [description2:protected] => 
                                    [structuredDescription:protected] => Array
                                        (
                                            [SVWZ] => Irgendein Käse
                                        )
                                    [bankCode:protected] => DAAEDEDD
                                    [accountNumber:protected] => DExx123412341234123417
                                    [name:protected] => Sender Name1
                                    [booked:protected] => 1
                                    [pn:protected] => 9253
                                    [textKeyAddition:protected] => 0
                                )
                        )
                    [startBalance:protected] => 0
                    [endBalance:protected] => 1222.56
                    [creditDebit:protected] => 
                    [date:protected] => DateTime Object
                        (
                            [date] => 2019-09-03 00:00:00.000000
                            [timezone_type] => 3
                            [timezone] => UTC
                        )
                )
            [2] => Fhp\Model\StatementOfAccount\Statement Object
                (
                    [transactions:protected] => Array
                        (
                        )
                    [startBalance:protected] => 0
                    [endBalance:protected] => 1345.01
                    [creditDebit:protected] => 
                    [date:protected] => DateTime Object
                        (
                            [date] => 2019-09-13 00:00:00.000000
                            [timezone_type] => 3
                            [timezone] => UTC
                        )
                )
        )
)
Philipp91 commented 5 months ago

Note how there's 3 instead of just 2 statements now. But the third statement is weirdly broken, it contains only an end balance and nothing else. Also the second statement has 1222.56 as its end balance, but that should be its start balance, and what's listed as the phantom third statement's end balance (1345.01) should be the second statement's end balance. And the first statement lacks an end balance.

So it looks like all end balances were computed correctly, but then shifted back by one statement, such that the first statement is left without an end balance and the last end balance is pushed past the end of the statement list into a phantom statement.

nemiah commented 5 months ago

I don't know why they don't run anymore. How can I run only lib/Tests/Fhp/Integration/DKB/GetStatementOfAccountTest.php? I usually don't use tests, my customers do that free of charge :blush:

Philipp91 commented 5 months ago
./vendor/bin/phpunit --filter testSimple lib/Tests/Fhp/Integration/DKB/GetStatementOfAccountTest.php

But the overall test suite runs fast enough (2s on my machine) that you can also just do composer test.

If you use an IDE, you should be able to do step by step debugging too.

nemiah commented 5 months ago

Thanks! I looked into it and I don't know why it does that with the DKB test. I've tested it with three banks of mine and it works great. But I've fixed the output and it doesn't create the phantom statement anymore. There is no endBalance for DKB though, either. #429