Skip to content

Correct bank account parsing#5

Open
pionl wants to merge 10 commits into
ifm24:masterfrom
pionl:bank-account-detection
Open

Correct bank account parsing#5
pionl wants to merge 10 commits into
ifm24:masterfrom
pionl:bank-account-detection

Conversation

@pionl
Copy link
Copy Markdown

@pionl pionl commented Nov 7, 2022

I've found that bank account parsing is not working. I've used by real exports from my client.

At this moment I'm in proof of concept stage, code structure can change.


Commit d2380654fcf89722aff85f612b582de053a70a25 introduced bank number in bank account number but the format is incorrectly interpreted

This PR tries to construct it correct format if possible - real exports are needed.

  • Česká spořitelna (CZ): Need real export
  • ČSOB (CZ): Need real export
  • Fio banka (CZ): Works, uses IBAN. docs
  • GE Money Bank (CZ): Need real export
  • Komerční banka (CZ), alias KM format: Uses internal format, uses IBAN. docs
  • Raiffeisenbank (CZ): Partial support, Does not use IBAN, can't detect bank code

Comment thread Statement/Statement.php
*
* @return array{prefix: ?string, number: ?string, bankCode: ?string}
*/
public function getParsedAccountNumber(): array
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously this method was constructing $parsedAccountNumber on every transactions - this can lead to bad performance - constructing is done in setAccountNumber.

Comment thread Statement/Statement.php Outdated
Comment thread Parser/ABOParser.php
Comment thread Parser/ABOParser.php
Comment thread Tests/ABO/BankAccountParserTest.php Outdated
@MartinMystikJonas
Copy link
Copy Markdown

@pionl I will get real export from Česká spořitelna. Export allows to select internal or normal account format so I would stick with normal format in this case.

@pionl
Copy link
Copy Markdown
Author

pionl commented Nov 8, 2022

We need to just fix ABOParserTest::testParseFileObjectWithCurrency test - CSOB export should solve this.

Would be great to get other bank statements to ensure correct support. Don't know how to solve RB - potentially could be the "default" bank account (or add ability to set it as default to BankAccountParser).

@pionl
Copy link
Copy Markdown
Author

pionl commented Nov 8, 2022

Přidána podpora CREDITAS bank

Comment thread Tests/Parser/ABOParserTest.php Outdated
Comment thread Tests/Parser/ABOParserTest.php
@pionl
Copy link
Copy Markdown
Author

pionl commented Nov 8, 2022

na PHP 8.1 mě to hlásí warning:

Return type of JakubZapletal\Component\BankStatement\Statement\Statement::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/vendor/ifm24/bank-statements/Statement/Statement.php on line 332

@pionl pionl force-pushed the bank-account-detection branch from 4c20769 to c53c242 Compare November 11, 2022 14:30
@pionl pionl changed the title Draft: Correct bank account parsing Correct bank account parsing Nov 11, 2022
@pionl
Copy link
Copy Markdown
Author

pionl commented Nov 11, 2022

I've finalized all proposed changes, we are missing tests for other banks, but it should work and we have new fallbacks to customize "failures".

I've tested the changes on my import usage and now all looks well.

Comment thread ABO/BankAccountParser.php
}

// Example: 7204021470000115
$internalAccountNumber = substr($line, 3, 16);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move transformation of internal to normal format to separate utility function in ABOParser

Copy link
Copy Markdown
Author

@pionl pionl Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree. At this moment ABOParser is huge and the testability of the code is thank to it degreased. It is sensible to use the "service" class to handle bank account transformation so we can test it in detail in its own test case and ABOParser test will not care about implementation detail.

Comment thread ABO/BankAccountParser.php Outdated
Comment thread Parser/ABOParser.php

# Counter account number
$counterAccountNumber = substr($line, 19, 6) . '-' . substr($line, 25, 10);
$counterAccountNumber = $this->bankAccountParser->formatBankAccountNumber(substr($line, 19, 6), substr($line, 25, 10));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conversion from internal format should be used here too for banks that use internal format

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I've not found an example of bank account. I would add it if we have an example. Otherwise we should leave it as it is?

Comment thread ABO/BankAccountParser.php Outdated
- Move bank related const to own file: based on feedback
- expose construct properties: makes testing easier (via DI)
@pionl
Copy link
Copy Markdown
Author

pionl commented Nov 22, 2022

  • I've added minor changes based on code review
  • I've added test to real CSOB export
  • I've exposed new properties to allow "external" testing of constructed classes.

@maryo
Copy link
Copy Markdown

maryo commented Feb 15, 2023

Bank code in bank number of Česká Spořitelna export is not present. Therefore there is no way how to trigger the POSTING_CODE_MAP_ALT logic in master branch.

 const BANKS_WITH_ALT_POSTING_CODE = [
      '0300', // Česká spořitelna
];

Also the bank code is not 0300 but 0800 but it's irrelevant when it's not present in the export.
An anonymized export of Česká spořitelna

0740000001234567890John Doe            30112200000000001234+00000000005678+00000007654321+00000001234567+987654321              
0750000001234567890000000000000000000000000000000000000000001000000000000080000000000000000111222Cena za vedení účtu 01101311222

@pionl
Copy link
Copy Markdown
Author

pionl commented Feb 15, 2023

Hi @maryo , thank your for the catch, i will update the comment (CSOB is the expected name).

Also thank you for CS export. It is sad that we are unable to detect the bank :(

@maryo
Copy link
Copy Markdown

maryo commented Feb 15, 2023

I think it should be Česká spořitelna because the "alt" posting codes were previously set in
Parser/ABO/CeskaSporitelnaCZParser.php before it was refactored but not sure about posting codes of CSOB.
d238065

Also according to https://www.csas.cz/static_internet/cs/Obchodni_informace-Produkty/Prime_bankovnictvi/Spolecne/Prilohy/ABO_format.pdf

Údaj se vztahuje k údaji pod poř. č. 2 a jeho obsah je specifikován takto: „1“ – položka debet, „2“ – položka
kredit, „3“ – storno položky debet, „4“ – storno položky kredit.

BTW it is actually not a new problem caused by your MR. With your MR, you can at least pass an instance of
BankAccountParser with default string $defaultBankCode = '0000' set to 0800/0300 to trigger the logic.

In master branch there is no way. It is even not possible to override the constants with custom BANKS_WITH_ALT_POSTING_CODE as it was before because of self::BANKS_WITH_ALT_POSTING_CODE (not static::).

(I'd report it elsewhere or create a PR but the issues are closed and this PR partially solves the problem by providing the $defaultBankCode argument).

@pionl
Copy link
Copy Markdown
Author

pionl commented Feb 16, 2023

Thanks for the summary :)

I would recommend using this (if you have multiple statements from different banks). When the account number is 973789052 then 5500 bank code is added. Other bank statements contains bank code so it works for me as needed :)

 return new BankAccountParser(bankAccountNumberToBankCodeMap: [
       '973789052' => '5500',
]);

@pionl
Copy link
Copy Markdown
Author

pionl commented Apr 29, 2023

@nedvajz any chance of merging? :)

@nedvajz
Copy link
Copy Markdown

nedvajz commented May 2, 2023

@nedvajz any chance of merging? :)

Hello @pionl. As fresh co-maintainer (well, less than this) I am not able to do decision like this .. will try to reach somebody to come back to you ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants