Skip to content

Commit

Permalink
support for rdr segment (#35)
Browse files Browse the repository at this point in the history
corrected transaction for rdr segment updated UPGRADE.md
  • Loading branch information
twitnic authored Sep 23, 2020
1 parent 1cdfa06 commit 9ff10dc
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 1 deletion.
14 changes: 14 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

This document list backwards-incompatible changes only.

## 0.5
### 0.5.4
* added support for RDR fields in transactions.
* added test for oldenburgischelandesbank

### 0.5.3
* typo fix

### 0.5.2
* correct the check if 28C is null or is zero

### 0.5.1
* corrected getIBAN and getBIC

## 0.3 to 0.4

* Upgraded from Php 5.X to minimum Php 7.1
Expand Down
2 changes: 1 addition & 1 deletion lib/Jejik/MT940/Parser/AbstractParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ protected function closingBalance(string $text): ?Balance
*/
protected function transaction(array $lines): TransactionInterface
{
if (!preg_match('/(\d{6})(\d{4})?((?:C|D)R?)([0-9,]{1,15})/', $lines[0], $match)) {
if (!preg_match('/(\d{6})(\d{4})?((?:C|D|RD)R?)([0-9,]{1,15})/', $lines[0], $match)) {
throw new \RuntimeException(sprintf('Could not parse transaction line "%s"', $lines[0]));
}

Expand Down
9 changes: 9 additions & 0 deletions tests/Jejik/Tests/MT940/Fixture/document/sparkasse2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:20:STARTUMSE
:25:DE11222220220222220200
:28C:00000/001
:60F:C200219EUR931052,29
:61:2002010219RDR1027,25N068NONREF
:86:899?00STORNO?109392?20STORNO RECHNUNGSABSCHLUSS?21PER 01.02.2
020?3050652124?31900932005?32GEBÜHREN MANUELL GG UST-FRE?33I
:62F:C200219EUR931304,50
-
94 changes: 94 additions & 0 deletions tests/Jejik/Tests/MT940/Parser/SparkasseRdrTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Jejik\MT940 library and tests the RDR Field in sepa
* file.
*
* Copyright (c) 2020 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\Sparkasse
*
* @author Dominic Richter <[email protected]>
*/
class SparkasseRdrTest extends TestCase
{
public $statements = [];

/**
* @throws \Jejik\MT940\Exception\NoParserFoundException
*/
public function setUp(): void
{
$reader = new Reader();
$reader->addParser('Sparkasse', \Jejik\MT940\Parser\Sparkasse::class);
$this->statements = $reader->getStatements(file_get_contents(__DIR__ . '/../Fixture/document/sparkasse2.txt'));
}

public function testStatement()
{
$this->assertCount(1, $this->statements, 'Assert counting statements.');
$statement = $this->statements[0];

$this->assertEquals('00000/001', $statement->getNumber());
$this->assertEquals('DE11222220220222220200', $statement->getAccount()->getNumber());
}

public function testBalance()
{
$balance = $this->statements[0]->getOpeningBalance();
$this->assertInstanceOf(\Jejik\MT940\Balance::class, $balance);
$this->assertEquals('2020-02-19 00:00:00', $balance->getDate()->format('Y-m-d H:i:s'));
$this->assertEquals('EUR', $balance->getCurrency());
$this->assertEquals(931052.29, $balance->getAmount());
}

public function testTransaction()
{
$transactions = $this->statements[0]->getTransactions();

$this->assertCount(1, $transactions);
$this->assertNotNull($transactions[0]->getContraAccount());

$this->assertEquals(1027.25, $transactions[0]->getAmount());
$expectedDescription = "899?00STORNO?109392?20STORNO RECHNUNGSABSCHLUSS?21PER 01.02.2\r\n020?3050652124?31900932005?32GEBÜHREN MANUELL GG UST-FRE?33I";
$this->assertEquals($expectedDescription, $transactions[0]->getDescription());
$this->assertEquals('2020-02-01 00:00:00', $transactions[0]->getValueDate()->format('Y-m-d H:i:s'), 'Assert Value Date');
$this->assertEquals('2020-02-19 00:00:00', $transactions[0]->getBookDate()->format('Y-m-d H:i:s'), 'Assert Book Date');

$this->assertNull($transactions[0]->getCode());
$this->assertNull($transactions[0]->getRef());
$this->assertNull($transactions[0]->getBankRef());

$this->assertEquals('899', $transactions[0]->getGVC());
$this->assertEquals('STORNO', $transactions[0]->getTxText());
$this->assertEquals('9392', $transactions[0]->getPrimanota());
$this->assertNull($transactions[0]->getExtCode());

$this->assertNull($transactions[0]->getEref());

$this->assertEquals('50652124', $transactions[0]->getBIC());
$this->assertEquals('900932005', $transactions[0]->getIBAN());
$this->assertEquals('GEBÜHREN MANUELL GG UST-FREI', $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('900932005', $transactions[0]->getContraAccount()->getNumber());
$this->assertNull($transactions[0]->getContraAccount()->getName());
}
}

0 comments on commit 9ff10dc

Please sign in to comment.