From 1f27891367592588babe995aa305b49f507647fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Wed, 22 May 2024 19:56:17 +0300 Subject: [PATCH 1/2] new engine is added for Wise --- README.md | 1 + src/Parser/Banking/Mt940/Engine.php | 1 + src/Parser/Banking/Mt940/Engine/Wise.php | 108 +++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 src/Parser/Banking/Mt940/Engine/Wise.php diff --git a/README.md b/README.md index 01b0d51..5b71631 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Currently the following engines are included: - KBS ([here](./src/Parser/Banking/Mt940/Engine/Kbs.php)) - ZETB ([here](./src/Parser/Banking/Mt940/Engine/Zetb.php)) - KONTIST ([here](./src/Parser/Banking/Mt940/Engine/Kontist.php)) +- WISE ([here](./src/Parser/Banking/Mt940/Engine/Wise.php)) - a default `UNKNOWN`-engine ([here](./src/Parser/Banking/Mt940/Engine/Unknown.php)) ### Custom engines diff --git a/src/Parser/Banking/Mt940/Engine.php b/src/Parser/Banking/Mt940/Engine.php index c1405f1..00265d8 100644 --- a/src/Parser/Banking/Mt940/Engine.php +++ b/src/Parser/Banking/Mt940/Engine.php @@ -32,6 +32,7 @@ abstract class Engine 1100 => Engine\Kbs::class, 1200 => Engine\Zetb::class, 1300 => Engine\Kontist::class, + 1400 => Engine\Wise::class, ]; /** diff --git a/src/Parser/Banking/Mt940/Engine/Wise.php b/src/Parser/Banking/Mt940/Engine/Wise.php new file mode 100644 index 0000000..58b09e7 --- /dev/null +++ b/src/Parser/Banking/Mt940/Engine/Wise.php @@ -0,0 +1,108 @@ +getCurrentStatementData(), $results) + && !empty($results[1]) + ) { + return $this->sanitizeAccount($results[1]); + } + + // SEPA / IBAN + if (preg_match('/:25:([A-Z0-9]{8}[\d\.]+)*/', $this->getCurrentStatementData(), $results) + && !empty($results[1]) + ) { + return $this->sanitizeAccount($results[1]); + } + + return 'WISE'; + } + + + /** + * uses the 61 field to determine amount/value of the transaction. + * + * @return float + */ + protected function parseTransactionPrice() + { + $results = []; + if (preg_match('/^:61:.*?[CD]([\d,\.]+)F/i', $this->getCurrentTransactionData(), $results) + && !empty($results[1]) + ) { + return $this->sanitizePrice($results[1]); + } + + return 0; + } + + /** + * uses the 61 field to get the bank specific transaction code. + * + * @return string + */ + protected function parseTransactionCode() + { + $results = []; + if (preg_match('/^:61:.*?F(.{3}).*/', $this->getCurrentTransactionData(), $results) + && !empty($results[1]) + ) { + return trim($results[1]); + } + return ''; + } + + /** + * @TODO WIP get this into the transaction somehow.. (possibly as a decorator over the transactions?) + * @return int + */ + protected function parseTransactionType() + { + static $map = [ + 'FEX' => Type::BANK_TRANSFER, + 'CHG' => Type::BANK_COSTS, + 'MSC' => Type::BANK_INTEREST, + 'TRF' => Type::UNKNOWN, + ]; + + $code = $this->parseTransactionCode(); + if (array_key_exists($code, $map)) { + return $map[$code]; + } + throw new \RuntimeException("Don't know code $code for this bank"); + } + + /** + * + * {@inheritdoc} + * @see \Kingsquare\Parser\Banking\Mt940\Engine::isApplicable() + */ + public static function isApplicable($string) + { + $firstline = strtok($string, "\r\n\t"); + + return strpos($firstline, 'F01TRWIGB2LAXXX0000000000') !== false; + } +} From dc9b2e8470ebcb2d2fc1d255dfde2d82ec96bc71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Thu, 23 May 2024 11:46:43 +0300 Subject: [PATCH 2/2] Missing use `TYPE` class and wrong TYPE --- src/Parser/Banking/Mt940/Engine/Wise.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Parser/Banking/Mt940/Engine/Wise.php b/src/Parser/Banking/Mt940/Engine/Wise.php index 58b09e7..5b3785b 100644 --- a/src/Parser/Banking/Mt940/Engine/Wise.php +++ b/src/Parser/Banking/Mt940/Engine/Wise.php @@ -2,6 +2,7 @@ namespace Kingsquare\Parser\Banking\Mt940\Engine; +use Kingsquare\Banking\Transaction\Type; use Kingsquare\Parser\Banking\Mt940\Engine; class Wise extends Engine @@ -81,10 +82,10 @@ protected function parseTransactionCode() protected function parseTransactionType() { static $map = [ - 'FEX' => Type::BANK_TRANSFER, 'CHG' => Type::BANK_COSTS, 'MSC' => Type::BANK_INTEREST, - 'TRF' => Type::UNKNOWN, + 'TRF' => Type::TRANSFER, + 'FEX' => Type::UNKNOWN, ]; $code = $this->parseTransactionCode();