From 8b3af4145a794f57e8b1c1348a533d30942f38ef Mon Sep 17 00:00:00 2001 From: Dominic Richter Date: Mon, 15 Feb 2021 18:34:40 +0100 Subject: [PATCH] LBBW Bank (#38) added LBBW Bank (Draft) --- UPGRADE.md | 9 ++ lib/Jejik/MT940/Parser/Lbbw.php | 79 +++++++++++++++ .../Tests/MT940/Fixture/document/lbbw.txt | 15 +++ tests/Jejik/Tests/MT940/Parser/LbbwTest.php | 98 +++++++++++++++++++ 4 files changed, 201 insertions(+) create mode 100755 lib/Jejik/MT940/Parser/Lbbw.php create mode 100644 tests/Jejik/Tests/MT940/Fixture/document/lbbw.txt create mode 100644 tests/Jejik/Tests/MT940/Parser/LbbwTest.php diff --git a/UPGRADE.md b/UPGRADE.md index 992beef..7c00bfd 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -3,6 +3,15 @@ This document list backwards-incompatible changes only. ## 0.5 +### 0.5.7 +* added first draft of LBBW Bank + +### 0.5.6 +* corrected SVWZ Regex + +### 0.5.5 +* added GermanbankTest + ### 0.5.4 * added support for RDR fields in transactions. * added test for oldenburgischelandesbank diff --git a/lib/Jejik/MT940/Parser/Lbbw.php b/lib/Jejik/MT940/Parser/Lbbw.php new file mode 100755 index 0000000..8399f39 --- /dev/null +++ b/lib/Jejik/MT940/Parser/Lbbw.php @@ -0,0 +1,79 @@ + + * Licensed under the MIT license + * + * For the full copyright and license information, please see the LICENSE + * file that was distributed with this source code. + */ + +namespace Jejik\MT940\Parser; + +/** + * Sparkasse provides a parser for Sparkasse Bank + * @package Jejik\MT940\Parser + */ +class Lbbw extends GermanBank +{ + /** + * Test if the document can be read by the parser + */ + public function accept(string $text): bool + { + $allowedUniqueIdentifiers = [ + ':20:LBBW' + ]; + + // unique identifier check + $mt940Identifier = substr($text, 0, 8); + if (in_array($mt940Identifier, $allowedUniqueIdentifiers)) { + return true; + } + + // if not check it's BLZ + return $this->isBLZAllowed($text); + } + + /** + * Get an array of allowed BLZ for this bank + */ + public function getAllowedBLZ(): array + { + return [ + ]; + } + + /** + * Get the contra account from a transaction + * + * @param array $lines The transaction text at offset 0 and the description at offset 1 + */ + protected function contraAccountNumber(array $lines): ?string + { + if (preg_match('/\?31(.*?)\?32/s', $lines[1], $match)) { + return trim(preg_replace('/\s\s+/', '', $match[1])); + } + + return null; + } + + protected function contraAccountName(array $lines): ?string + { + if (preg_match('/\?32(.*?)\?34/s', $lines[1], $match)) { + return trim(preg_replace('/\s\s+/', '', $match[1])); + } + + return null; + } + + //TODO: reformat :86: Mehrzweckfeld + protected function description(?string $description): ?string + { + return parent::description($description); // TODO: Change the autogenerated stub + } +} diff --git a/tests/Jejik/Tests/MT940/Fixture/document/lbbw.txt b/tests/Jejik/Tests/MT940/Fixture/document/lbbw.txt new file mode 100644 index 0000000..fe3cfb9 --- /dev/null +++ b/tests/Jejik/Tests/MT940/Fixture/document/lbbw.txt @@ -0,0 +1,15 @@ +:20:LBBW +:21:NONREF +:25:12345678/1324357 +:28C:1 +:60F:C210120EUR0,00 +:61:2102080208D0,01NCMZNONREF +:86:834?00KONTENPOOL?102?20BUCHUNG AUF KTO 7402050699?21BANKLEITZAHL +60050101?3060050101?3111111111 +:61:2102080208C0,01NCOLKREF+//202102040007693 +:86:171?00SEPA EINZUGSAUFTRAG?101?20KREF+SEPA-20210203175805-00?21154 +800-P1?22SVWZ+E-MOBILITY ABRECHNUNG?23NR. 28 ZU VERTRAG 9433, KUN +?24DENNUMMER 11111?30SOLADEST600?31DE59600501010007907986?32NIC R +ICHTER +:62F:C210208EUR0,00 +- diff --git a/tests/Jejik/Tests/MT940/Parser/LbbwTest.php b/tests/Jejik/Tests/MT940/Parser/LbbwTest.php new file mode 100644 index 0000000..2c45c08 --- /dev/null +++ b/tests/Jejik/Tests/MT940/Parser/LbbwTest.php @@ -0,0 +1,98 @@ + + * Licensed under the MIT license + * + * For the full copyright and license information, please see the LICENSE + * file that was distributed with this source code. + */ + +namespace Jejik\Tests\MT940\Parser; + +use Jejik\MT940\Reader; +use PHPUnit\Framework\TestCase; + +/** + * Tests for Jejik\MT940\Parser\Sparkasse + * + * @author Dominic Richter + */ +class LbbwTest extends TestCase +{ + public $statements = []; + + /** + * @throws \Jejik\MT940\Exception\NoParserFoundException + */ + public function setUp(): void + { + $reader = new Reader(); + $reader->addParser('Lbbw', \Jejik\MT940\Parser\Lbbw::class); + $this->statements = $reader->getStatements(file_get_contents(__DIR__ . '/../Fixture/document/lbbw.txt')); + } + + public function testStatement() + { + $this->assertCount(1, $this->statements, 'Assert counting statements.'); + $statement = $this->statements[0]; + + $this->assertEquals('1', $statement->getNumber()); + $this->assertEquals('12345678/1324357', $statement->getAccount()->getNumber()); + } + + public function testBalance() + { + $balance = $this->statements[0]->getOpeningBalance(); + $this->assertInstanceOf(\Jejik\MT940\Balance::class, $balance); + $this->assertEquals('2021-01-20 00:00:00', $balance->getDate()->format('Y-m-d H:i:s')); + $this->assertEquals('EUR', $balance->getCurrency()); + $this->assertEquals(0, $balance->getAmount()); + } + + public function testTransaction() + { + $transactions = $this->statements[0]->getTransactions(); + + $this->assertCount(2, $transactions); + + $this->assertNull($transactions[0]->getContraAccount()); + + $this->assertEquals(-0.01, $transactions[0]->getAmount()); + $expectedDescription = "834?00KONTENPOOL?102?20BUCHUNG AUF KTO 7402050699?21BANKLEITZAHL\r +60050101?3060050101?3111111111"; + $this->assertEquals($expectedDescription, $transactions[0]->getDescription()); + $this->assertEquals('2021-02-08 00:00:00', $transactions[0]->getValueDate()->format('Y-m-d H:i:s'), 'Assert Value Date'); + $this->assertEquals('2021-02-08 00:00:00', $transactions[0]->getBookDate()->format('Y-m-d H:i:s'), 'Assert Book Date'); + + $this->assertEquals('CMZ', $transactions[0]->getCode()); + $this->assertEquals('NONREF', $transactions[0]->getRef()); + $this->assertEquals('NONREF', $transactions[0]->getBankRef()); + + $this->assertEquals('834', $transactions[0]->getGVC()); + $this->assertEquals('KONTENPOOL', $transactions[0]->getTxText()); + $this->assertEquals('2', $transactions[0]->getPrimanota()); + $this->assertNull($transactions[0]->getExtCode()); + $this->assertNull($transactions[0]->getEref()); + $this->assertEquals('60050101', $transactions[0]->getBIC()); + $this->assertEquals('11111111', $transactions[0]->getIBAN()); + $this->assertNull($transactions[0]->getAccountHolder()); + $this->assertNull($transactions[0]->getKref()); + $this->assertNull($transactions[0]->getMref()); + $this->assertNull($transactions[0]->getCred()); + $this->assertNull($transactions[0]->getSvwz()); + + $this->assertEquals('NIC RICHTER', $transactions[1]->getAccountHolder()); + $this->assertEquals('SEPA-20210203175805-00154800-P1', $transactions[1]->getKref()); + $this->assertNull($transactions[1]->getMref()); + $this->assertNull($transactions[1]->getCred()); + $this->assertEquals( + 'E-MOBILITY ABRECHNUNGNR. 28 ZU VERTRAG 9433, KUNDENNUMMER 11111', + $transactions[1]->getSvwz() + ); + } +}