Skip to content

Commit

Permalink
add support for RCR transaction (#48)
Browse files Browse the repository at this point in the history
* add RC(R) - Credit transaction cancellation - test
* fix RC(R) - Credit transaction cancellation - parsing error
  • Loading branch information
serazoli authored Jan 11, 2023
1 parent f03730b commit fba9605
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Jejik/MT940/Parser/AbstractParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,13 @@ protected function closingBalance(string $text): ?Balance
*/
protected function transaction(array $lines): TransactionInterface
{
if (!preg_match('/(\d{6})(\d{4})?((?:C|D|RD)R?)([0-9,]{1,15})/', $lines[0], $match)) {
if (!preg_match('/(\d{6})(\d{4})?((?:C|D|RD|RC)R?)([0-9,]{1,15})/', $lines[0], $match)) {
throw new \RuntimeException(sprintf('Could not parse transaction line "%s"', $lines[0]));
}

// Parse the amount
$amount = (float)str_replace(',', '.', $match[4]);
if (in_array($match[3], array('D', 'DR'))) {
if (in_array($match[3], array('D', 'DR','RC','RCR'))) {
$amount *= -1;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/Jejik/Tests/MT940/Fixture/document/sparkasse3.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:2002010219RCR1027,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/SparkasseRcrTest.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 SparkasseRcrTest 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/sparkasse3.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 fba9605

Please sign in to comment.