diff --git a/lib/Jejik/MT940/Parser/GermanBank.php b/lib/Jejik/MT940/Parser/GermanBank.php index 1f0ecbc..3a2b858 100755 --- a/lib/Jejik/MT940/Parser/GermanBank.php +++ b/lib/Jejik/MT940/Parser/GermanBank.php @@ -419,7 +419,6 @@ protected function cred(array $lines): ?string return null; } - // return return preg_replace('#(\?\d{0,2})#', '', $match[1]); } @@ -432,19 +431,18 @@ protected function svwz(array $lines): ?string $svwzLine = isset($lines[1]) ? $lines[1] : null; // pattern - $pattern = 'S(?:\?2[1-9])?V(?:\?2[1-9])?W(?:\?2[1-9])?Z(?:\?2[1-9])?\+(?:\?2[1-9])?((?:[a-zA-ZöäüÖÄÜß\-/\s0-9\,\.\:]+(?:\?2[1-9])?)+)'; + $pattern = "(S(?:\?2[1-9])?V(?:\?2[1-9])?W(?:\?2[1-9])?Z(?:\?2[1-9])?\+)(?:\?(?:2[1-9]))?(?'SVWZ'.*)(?:\?30)"; // match it /** @var string $svwzLine */ - preg_match("#{$pattern}#", $this->removeNewLinesFromLine($svwzLine), $match); + preg_match("/{$pattern}/", $this->removeNewLinesFromLine($svwzLine), $match); // assure match - if (!isset($match[1])) { + if (!isset($match['SVWZ'])) { return null; } - // return - return preg_replace('#(\?2[1-9])#', '', $match[1]); + return preg_replace('/(\?2[1-9])/', '', $match['SVWZ']); } /** diff --git a/tests/Jejik/Tests/MT940/Fixture/document/K4262927_20200905-080000-952.txt b/tests/Jejik/Tests/MT940/Fixture/document/K4262927_20200905-080000-952.txt new file mode 100644 index 0000000..7ef9dd7 --- /dev/null +++ b/tests/Jejik/Tests/MT940/Fixture/document/K4262927_20200905-080000-952.txt @@ -0,0 +1,10 @@ +:20:STARTUMS TA +:25:28020050/1426292700 +:28C:172/1 +:60F:C200904EUR0, +:61:2009040904C230,00N051NONREF +:86:166?00GUTSCHRIFT?100004772?20EREF+SCP 100 / 0082002528?21SVWZ+D 8 +03020001000145464 +?221000145463 Manthey,August?30OLBODEH2XXX?31D +E59280200501422112100?32EWE VERTRIEB GmbH?35EWE VERTRIEB powerclo +ud +:65F:Dnullnull7414,3 diff --git a/tests/Jejik/Tests/MT940/Fixture/document/deutschebank.txt b/tests/Jejik/Tests/MT940/Fixture/document/deutschebank.txt index 6044fe2..b2ce98c 100644 --- a/tests/Jejik/Tests/MT940/Fixture/document/deutschebank.txt +++ b/tests/Jejik/Tests/MT940/Fixture/document/deutschebank.txt @@ -1,14 +1,14 @@ -:20:DEUTDEMMXXX -:25:20070000/0123456601 -:28C:00143/1 -:60F:C200605EUR0,00 -:61:2006080608D12,35 NRTIKREF+//2016021783252833 -/OCMT/EUR11,85//CHGS/EUR0,50/ -:86:109?00SEPA-LASTSCHR. RETOURE CORE?109075/629?20EREF+A1.200080779. -400143254?21.4961336 KREF+SEPA-DA202006?2201221740-34972000-P1 MR -EF+2?230852HW2723821 CRED+DE41EON0?240000129793 OAMT+11,85 SVWZ+? -25SONSTIGE GRUENDE ENDABRECHN?26UNG NR. 500106875 ZU VERTRA?2d40 -0143254, KUNDENNUM MER 2?2802227779?30CSDBDE71XXX?31DE50712345600 -200691329?32TESTER?33EL -:62F:C200608EUR0,00 -- +:20:DEUTDEMMXXX +:25:20070000/0123456601 +:28C:00143/1 +:60F:C200605EUR0,00 +:61:2006080608D12,35 NRTIKREF+//2016021783252833 +/OCMT/EUR11,85//CHGS/EUR0,50/ +:86:109?00SEPA-LASTSCHR. RETOURE CORE?109075/629?20EREF+A1.200080779. +400143254?21.4961336 KREF+SEPA-DA202006?2201221740-34972000-P1 MR +EF+2?230852HW2723821 CRED+DE41EON0?240000129793 OAMT+11,85 SVWZ+? +25SONSTIGE GRUENDE ENDABRECHN?26UNG NR. 500106875 ZU VERTRA?2740 +0143254, KUNDENNUM MER 2?2802227779?30CSDBDE71XXX?31DE50712345600 +200691329?32TESTER?33EL +:62F:C200608EUR0,00 +- diff --git a/tests/Jejik/Tests/MT940/Parser/DeutscheBankTest.php b/tests/Jejik/Tests/MT940/Parser/DeutscheBankTest.php index 9504b56..cdb63c8 100644 --- a/tests/Jejik/Tests/MT940/Parser/DeutscheBankTest.php +++ b/tests/Jejik/Tests/MT940/Parser/DeutscheBankTest.php @@ -65,7 +65,7 @@ public function testTransaction() $this->assertEquals(-12.35, $transactions[0]->getAmount()); $expectedDescription = "109?00SEPA-LASTSCHR. RETOURE CORE?109075/629?20EREF+A1.200080779.\r\n400143254?21.4961336 KREF+SEPA-DA202006?2201221740-34972000-P1 MR\r EF+2?230852HW2723821 CRED+DE41EON0?240000129793 OAMT+11,85 SVWZ+?\r -25SONSTIGE GRUENDE ENDABRECHN?26UNG NR. 500106875 ZU VERTRA?2d40\r +25SONSTIGE GRUENDE ENDABRECHN?26UNG NR. 500106875 ZU VERTRA?2740\r 0143254, KUNDENNUM MER 2?2802227779?30CSDBDE71XXX?31DE50712345600\r 200691329?32TESTER?33EL"; $this->assertEquals($expectedDescription, $transactions[0]->getDescription()); @@ -82,7 +82,7 @@ public function testTransaction() $this->assertNull($transactions[0]->getExtCode()); $this->assertEquals( - 'A1.200080779.400143254.4961336 KREF+SEPA-DA20200601221740-34972000-P1 MREF+20852HW2723821 CRED+DE41EON00000129793 OAMT+11,85 SVWZ+SONSTIGE GRUENDE ENDABRECHNUNG NR. 500106875 ZU VERTRA', + 'A1.200080779.400143254.4961336 KREF+SEPA-DA20200601221740-34972000-P1 MREF+20852HW2723821 CRED+DE41EON00000129793 OAMT+11,85 SVWZ+SONSTIGE GRUENDE ENDABRECHNUNG NR. 500106875 ZU VERTRA400143254, KUNDENNUM MER 202227779', $transactions[0]->getEref() ); @@ -97,7 +97,7 @@ public function testTransaction() $this->assertEquals('20852HW2723821 CRED+DE41EON00000129793 OAMT+11,85', $transactions[0]->getMref()); $this->assertEquals('DE41EON00000129793 OAMT+11,85', $transactions[0]->getCred()); - $this->assertEquals('SONSTIGE GRUENDE ENDABRECHNUNG NR. 500106875 ZU VERTRA', $transactions[0]->getSvwz()); + $this->assertEquals('SONSTIGE GRUENDE ENDABRECHNUNG NR. 500106875 ZU VERTRA400143254, KUNDENNUM MER 202227779', $transactions[0]->getSvwz()); //$this->assertEquals('DE12345678901234567890', $transactions[0]->getContraAccount()->getNumber()); //$this->assertEquals('Max Mustermann', $transactions[0]->getContraAccount()->getName()); } diff --git a/tests/Jejik/Tests/MT940/Parser/OldenburgischeLandesbankTxTest.php b/tests/Jejik/Tests/MT940/Parser/OldenburgischeLandesbankTxTest.php new file mode 100644 index 0000000..6c2b018 --- /dev/null +++ b/tests/Jejik/Tests/MT940/Parser/OldenburgischeLandesbankTxTest.php @@ -0,0 +1,96 @@ + + * 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\OldenburgischeLandesbank + * + * @author Dominic Richter + */ +class OldenburgischeLandesbankTxTest extends TestCase +{ + public $statements = []; + + /** + * @throws \Jejik\MT940\Exception\NoParserFoundException + */ + public function setUp(): void + { + $reader = new Reader(); + $reader->addParser('OldenburgischeLandesbank', \Jejik\MT940\Parser\OldenburgischeLandesbank::class); + $this->statements = $reader->getStatements(file_get_contents(__DIR__ . '/../Fixture/document/K4262927_20200905-080000-952.txt')); + } + + public function testStatement() + { + $this->assertCount(1, $this->statements, 'Assert counting statements.'); + $statement = $this->statements[0]; + + $this->assertEquals('172/1', $statement->getNumber()); + $this->assertEquals('28020050/1426292700', $statement->getAccount()->getNumber()); + } + + public function testBalance() + { + $balance = $this->statements[0]->getOpeningBalance(); + $this->assertInstanceOf(\Jejik\MT940\Balance::class, $balance); + $this->assertEquals('2020-09-04 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(1, $transactions); + + $this->assertNull($transactions[0]->getContraAccount()); + + $this->assertEquals(230, $transactions[0]->getAmount()); + $expectedDescription = "166?00GUTSCHRIFT?100004772?20EREF+SCP 100 / 0082002528?21SVWZ+D 8\r +03020001000145464 +?221000145463 Manthey,August?30OLBODEH2XXX?31D\r +E59280200501422112100?32EWE VERTRIEB GmbH?35EWE VERTRIEB powerclo\r +ud"; + $this->assertEquals($expectedDescription, $transactions[0]->getDescription()); + $this->assertEquals('2020-09-04 00:00:00', $transactions[0]->getValueDate()->format('Y-m-d H:i:s'), 'Assert Value Date'); + $this->assertEquals('2020-09-04 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->assertEquals("NONREF", $transactions[0]->getBankRef()); + + $this->assertEquals('166', $transactions[0]->getGVC()); + $this->assertEquals('GUTSCHRIFT', $transactions[0]->getTxText()); + $this->assertEquals('0004772', $transactions[0]->getPrimanota()); + $this->assertNull($transactions[0]->getExtCode()); + + $this->assertEquals('SCP 100 / 0082002528', $transactions[0]->getEref()); + + $this->assertEquals('OLBODEH2XXX', $transactions[0]->getBIC()); + $this->assertEquals('DE59280200501422112100', $transactions[0]->getIBAN()); + $this->assertEquals('EWE VERTRIEB GmbH', $transactions[0]->getAccountHolder()); + + $this->assertNull($transactions[0]->getKref()); + $this->assertNull($transactions[0]->getMref()); + $this->assertNull($transactions[0]->getCred()); + $this->assertEquals('D 803020001000145464 +1000145463 Manthey,August', $transactions[0]->getSvwz()); + //$this->assertEquals('DE12345678901234567890', $transactions[0]->getContraAccount()->getNumber()); + //$this->assertEquals('Max Mustermann', $transactions[0]->getContraAccount()->getName()); + } +}