From b9e0f9fe2203a667958ac1058b5d13f11ca0e062 Mon Sep 17 00:00:00 2001 From: Dominic Richter Date: Thu, 8 Jul 2021 23:50:47 +0200 Subject: [PATCH] corrected reading of fields 30, 31, 32 and 33 (#40) --- lib/Jejik/MT940/Parser/AbstractParser.php | 2 +- ...oldenburgischelandesbankmitbindestrich.txt | 10 ++ .../OldenburgischeLandesbankWithDashTest.php | 93 +++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 tests/Jejik/Tests/MT940/Fixture/document/oldenburgischelandesbankmitbindestrich.txt create mode 100644 tests/Jejik/Tests/MT940/Parser/OldenburgischeLandesbankWithDashTest.php diff --git a/lib/Jejik/MT940/Parser/AbstractParser.php b/lib/Jejik/MT940/Parser/AbstractParser.php index 0b2919e..3f8ba25 100644 --- a/lib/Jejik/MT940/Parser/AbstractParser.php +++ b/lib/Jejik/MT940/Parser/AbstractParser.php @@ -179,7 +179,7 @@ protected function getTransactionLines($text): ?array { } $multiPurposeField = []; - $pcre = '/(?:^|\r\n)\:(?:86)\:(.+)(?:[\r\n])(?:\:(?:6[0-9]{1}[a-zA-Z]?)\:|(?:[\r\n]-))/Us'; + $pcre = '/(?:^|\r\n)\:(?:86)\:(.+)(?:[\r\n])(?:\:(?:6[0-9]{1}[a-zA-Z]?)\:|(?:[\r\n]-$))/Us'; if (preg_match_all($pcre, $text, $match)) { $multiPurposeField = $match; diff --git a/tests/Jejik/Tests/MT940/Fixture/document/oldenburgischelandesbankmitbindestrich.txt b/tests/Jejik/Tests/MT940/Fixture/document/oldenburgischelandesbankmitbindestrich.txt new file mode 100644 index 0000000..4ae50eb --- /dev/null +++ b/tests/Jejik/Tests/MT940/Fixture/document/oldenburgischelandesbankmitbindestrich.txt @@ -0,0 +1,10 @@ +:20:STARTUMS +:25:DE12345678900022805304 +:28C:1/1 +:60F:C210204EUR279998,57 +:61:2106170617C1727,00N051NONREF +:86:166?00GUTSCHRIFT?100004770?20SVWZ+Kunden-Nr. 20389020 Ve?21rtrags +-Nr. 1000620785?30ABCDEFGHIJK?31DE41292500000123456789?32Projektg +emeinschaft XXXXXX?33+ XXXXXXGmbH + Co. KG?35EWE Vertrieb GmbH +:62F:C210605EUR0,00 +- diff --git a/tests/Jejik/Tests/MT940/Parser/OldenburgischeLandesbankWithDashTest.php b/tests/Jejik/Tests/MT940/Parser/OldenburgischeLandesbankWithDashTest.php new file mode 100644 index 0000000..18e2562 --- /dev/null +++ b/tests/Jejik/Tests/MT940/Parser/OldenburgischeLandesbankWithDashTest.php @@ -0,0 +1,93 @@ + + * 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\OldenburgischeLandesbankWithDash + * + * @author Dominic Richter + */ +class OldenburgischeLandesbankWithDashTest extends TestCase +{ + public $statements = []; + + /** + * @throws \Jejik\MT940\Exception\NoParserFoundException + */ + public function setUp(): void + { + $reader = new Reader(); + $this->statements = $reader->getStatements(file_get_contents(__DIR__ . '/../Fixture/document/oldenburgischelandesbankmitbindestrich.txt')); + } + + public function testStatement() + { + $this->assertCount(1, $this->statements, 'Assert counting statements.'); + $statement = $this->statements[0]; + + $this->assertEquals('1/1', $statement->getNumber()); + $this->assertEquals('DE12345678900022805304', $statement->getAccount()->getNumber()); + } + + public function testBalance() + { + $balance = $this->statements[0]->getOpeningBalance(); + $this->assertInstanceOf(\Jejik\MT940\Balance::class, $balance); + $this->assertEquals('2021-02-04 00:00:00', $balance->getDate()->format('Y-m-d H:i:s')); + $this->assertEquals('EUR', $balance->getCurrency()); + $this->assertEquals(279998.57, $balance->getAmount()); + } + + public function testTransaction() + { + $transactions = $this->statements[0]->getTransactions(); + + $this->assertCount(1, $transactions); + + $this->assertEquals('DE41292500000123456789', $transactions[0]->getContraAccount()->getNumber()); + + $this->assertEquals(1727, $transactions[0]->getAmount()); + $expectedDescription = "166?00GUTSCHRIFT?100004770?20SVWZ+Kunden-Nr. 20389020 Ve?21rtrags\r\n-Nr. 1000620785?30ABCDEFGHIJK?31DE41292500000123456789?32Projektg\r\nemeinschaft XXXXXX?33+ XXXXXXGmbH + Co. KG?35EWE Vertrieb GmbH"; + $this->assertEquals($expectedDescription, $transactions[0]->getDescription()); + $this->assertEquals('2021-06-17 00:00:00', $transactions[0]->getValueDate()->format('Y-m-d H:i:s'), 'Assert Value Date'); + $this->assertEquals('2021-06-17 00:00:00', $transactions[0]->getBookDate()->format('Y-m-d H:i:s'), 'Assert Book Date'); + + $this->assertEquals("051", $transactions[0]->getCode()); + $this->assertEquals("NONREF", $transactions[0]->getRef()); + $this->assertNull($transactions[0]->getBankRef()); + + $this->assertEquals('166', $transactions[0]->getGVC()); + $this->assertEquals('GUTSCHRIFT', $transactions[0]->getTxText()); + $this->assertEquals('0004770', $transactions[0]->getPrimanota()); + $this->assertNull($transactions[0]->getExtCode()); + + $this->assertNull($transactions[0]->getEref()); + + $this->assertEquals('ABCDEFGHIJK', $transactions[0]->getBIC()); + $this->assertEquals('DE41292500000123456789', $transactions[0]->getIBAN()); + $this->assertEquals('Projektgemeinschaft XXXXXX+ XXXXXXGmbH + Co. KG', $transactions[0]->getAccountHolder()); + + $this->assertNull($transactions[0]->getKref()); + $this->assertNull($transactions[0]->getMref()); + $this->assertNull($transactions[0]->getCred()); + + $this->assertEquals('Kunden-Nr. 20389020 Vertrags-Nr. 1000620785', $transactions[0]->getSvwz()); + $this->assertEquals('DE41292500000123456789', $transactions[0]->getContraAccount()->getNumber()); + $this->assertNull($transactions[0]->getContraAccount()->getName()); + } +}