Skip to content

Commit

Permalink
corrected reading of fields 30, 31, 32 and 33 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
twitnic authored Jul 8, 2021
1 parent 9309715 commit b9e0f9f
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Jejik/MT940/Parser/AbstractParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
-
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Jejik\MT940 library
*
* Copyright (c) 2021 Powercloud GmbH <[email protected]>
* 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 <[email protected]>
*/
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());
}
}

0 comments on commit b9e0f9f

Please sign in to comment.