Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BTRL - Banca Transilvania Romania #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/Parser/Banking/Mt940/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ abstract class Engine
800 => Engine\Bunq::class,
900 => Engine\Penta::class,
1000 => Engine\Asn::class,
1100 => Engine\Kbs::class,
1200 => Engine\Zetb::class,
1300 => Engine\Kontist::class,
1100 => Engine\Btrl::class,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kbs, Zetb and Kontist should not be deleted.

];

/**
Expand Down Expand Up @@ -594,7 +592,7 @@ protected function sanitizeTimestamp($string, $inFormat = 'ymd')
$date = \DateTime::createFromFormat($inFormat, $string);
$date->setTime(0, 0);
if ($date !== false) {
return (int) $date->format('U');
return (int)$date->format('U');
}

return 0;
Expand All @@ -617,7 +615,7 @@ protected function sanitizeDescription($string)
*/
protected function sanitizeDebitCredit($string)
{
$debitOrCredit = strtoupper(substr((string) $string, 0, 1));
$debitOrCredit = strtoupper(substr((string)$string, 0, 1));
if ($debitOrCredit !== Transaction::DEBIT && $debitOrCredit !== Transaction::CREDIT) {
trigger_error('wrong value for debit/credit (' . $string . ')', E_USER_ERROR);
$debitOrCredit = '';
Expand All @@ -635,6 +633,6 @@ protected function sanitizePrice($string)
{
$floatPrice = ltrim(str_replace(',', '.', strip_tags(trim($string))), '0');

return (float) $floatPrice;
return (float)$floatPrice;
}
}
48 changes: 48 additions & 0 deletions src/Parser/Banking/Mt940/Engine/Btrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Kingsquare\Parser\Banking\Mt940\Engine;

use Kingsquare\Parser\Banking\Mt940\Engine;

class Btrl extends Engine
{
/**
*
* {@inheritdoc}
* @see \Kingsquare\Parser\Banking\Mt940\Engine::parseStatementBank()
*/
protected function parseStatementBank()
{
return 'BTRL';
}

/**
* uses the 61 field to determine amount/value of the transaction.
*
* @return float
*/
protected function parseTransactionPrice()
{
$results = [];
if (preg_match('/^:61:.*?[CD]([\d,\.]+)[NSF]/i', $this->getCurrentTransactionData(), $results)
&& !empty($results[1])
) {
return $this->sanitizePrice($results[1]);
}

return 0;
}


/**
*
* {@inheritdoc}
* @see \Kingsquare\Parser\Banking\Mt940\Engine::isApplicable()
*/
public static function isApplicable($string)
{
$firstline = strtok($string, "\r\n\t");

return strpos($firstline, 'BTRL') !== false;
}
}
26 changes: 4 additions & 22 deletions test/Parser/Banking/Mt940/Engine/Abn/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
/**
*
*/
class ParseTest extends \PHPUnit_Framework_TestCase
class ParseTest extends \PHPUnit\Framework\TestCase
{
/**
* @var Abn
*/
private $engine;

protected function setUp()
protected function setUp(): void
{
$this->engine = new Abn();
$this->engine->loadString(file_get_contents(__DIR__.'/sample'));
}

public function testParseStatementBank()
public function testParseStatementBank():void
{
$method = new \ReflectionMethod($this->engine, 'parseStatementBank');
$method->setAccessible(true);
$this->assertEquals('ABN', $method->invoke($this->engine));
}

public function testParsesAllFoundStatements()
public function testParsesAllFoundStatements():void
{
$statements = $this->engine->parse();

Expand Down Expand Up @@ -78,22 +78,4 @@ public function testIssue48()
$this->assertEquals('15-12-2016', $transactions[1]->getValueTimestamp('d-m-Y'));
$this->assertEquals('15-12-2016', $transactions[1]->getEntryTimestamp('d-m-Y'));
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test methods should not be deleted.

public function testParseTransactionDebitCredit()
{
$statements = $this->engine->parse();
$transactions = reset($statements)->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals('D', $firstTransaction->getDebitCredit());
}

public function testParseTransactionPrice()
{
$statements = $this->engine->parse();
$transactions = reset($statements)->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals(7.5, $firstTransaction->getPrice());
}
}
18 changes: 0 additions & 18 deletions test/Parser/Banking/Mt940/Engine/Asn/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,4 @@ public function testParseTransactionEntryTimestamp()
$lastTransaction = end($transactions);
$this->assertEquals('02-01-2020', $lastTransaction->getEntryTimestamp('d-m-Y'));
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test methods should not be deleted.

public function testParseTransactionDebitCredit()
{
$statements = $this->engine->parse();
$transactions = reset($statements)->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals('D', $firstTransaction->getDebitCredit());
}

public function testParseTransactionPrice()
{
$statements = $this->engine->parse();
$transactions = reset($statements)->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals(2000, $firstTransaction->getPrice());
}
}
39 changes: 39 additions & 0 deletions test/Parser/Banking/Mt940/Engine/Btrl/ParseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Kingsquare\Parser\Banking\Mt940\Engine\Btrl;

use Kingsquare\Parser\Banking\Mt940\Engine\Btrl;

/**
*
*/
class ParseTest extends \PHPUnit\Framework\TestCase
{
/**
* @var Btrl
*/
private $engine;

protected function setUp(): void
{
$this->engine = new Btrl();
$this->engine->loadString(file_get_contents(__DIR__.'/sample'));
}

public function testParseStatementBank():void
{
$method = new \ReflectionMethod($this->engine, 'parseStatementBank');
$method->setAccessible(true);
$this->assertEquals('BTRL', $method->invoke($this->engine));
}

public function testParseTransactionPrice(): void
{
$statements = $this->engine->parse();
$this->assertCount(1, $statements);
$transactions = $statements[0]->getTransactions();

$this->assertEquals('980.42', $transactions[0]->getPrice());
}

}
16 changes: 16 additions & 0 deletions test/Parser/Banking/Mt940/Engine/Btrl/sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{1:F01BTRLRO22AXXX1111111111}{2:I940BTRLRO22XXXXN}{3:{108:005MSOG2109700AI}}{4:
:20:005RONCRT0072583603
:25:RO21BTRLRONCRT0072583603
:28C:00004/00001
:60F:C210406RON0,
:61:2104060406C980,42FTRFNONREF//005z001210960373
:86:Card 5487-6174 ID005696ER 04/04/21 Ora 22:44:12 RRN 005481058051
ECOMM 551 Plata factura DV - 20666 - 723121
Data entry carduri REF. 005z001210960373
:61:2104060406C418,37FTRFNONREF//005z001210960481
:86:Card 5299-2132 ID005696ER 05/04/21 Ora 08:14:25 RRN 005481324613
:86:transf in ct.crt
Transfer intern - canal electronic REF. 405ECIT210960154
:62F:C210406RON0,
:64:C210406RON0,00
-}
18 changes: 0 additions & 18 deletions test/Parser/Banking/Mt940/Engine/Bunq/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,4 @@ public function testParseTransactionEntryTimestamp()
$lastTransaction = end($transactions);
$this->assertEquals('24-05-2019', $lastTransaction->getEntryTimestamp('d-m-Y'));
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test methods should not be deleted.

public function testParseTransactionDebitCredit()
{
$statements = $this->engine->parse();
$transactions = reset($statements)->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals('C', $firstTransaction->getDebitCredit());
}

public function testParseTransactionPrice()
{
$statements = $this->engine->parse();
$transactions = reset($statements)->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals(2, $firstTransaction->getPrice());
}
}
18 changes: 0 additions & 18 deletions test/Parser/Banking/Mt940/Engine/Ing/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,4 @@ public function testParseTransactionEntryTimestamp()
$lastTransaction = end($transactions);
$this->assertEquals('2010-07-21', $lastTransaction->getEntryTimestamp('Y-m-d'));
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test methods should not be deleted.

public function testParseTransactionDebitCredit()
{
$statements = $this->engine->parse();
$transactions = reset($statements)->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals('C', $firstTransaction->getDebitCredit());
}

public function testParseTransactionPrice()
{
$statements = $this->engine->parse();
$transactions = reset($statements)->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals(25.03, $firstTransaction->getPrice());
}
}
18 changes: 0 additions & 18 deletions test/Parser/Banking/Mt940/Engine/Knab/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,4 @@ public function testEndPrice() {
$price_f = $statements[0]->getEndPrice();
$this->assertSame(13057.49 , $price_f);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test methods should not be deleted.

public function testParseTransactionDebitCredit()
{
$statements = $this->engine->parse();
$transactions = reset($statements)->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals('D', $firstTransaction->getDebitCredit());
}

public function testParseTransactionPrice()
{
$statements = $this->engine->parse();
$transactions = reset($statements)->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals(15, $firstTransaction->getPrice());
}
}
18 changes: 0 additions & 18 deletions test/Parser/Banking/Mt940/Engine/Penta/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,4 @@ public function testParseTransactionEntryTimestamp()
$lastTransaction = end($transactions);
$this->assertEquals('30-09-2020', $lastTransaction->getEntryTimestamp('d-m-Y'));
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test methods should not be deleted.

public function testParseTransactionDebitCredit()
{
$statements = $this->engine->parse();
$transactions = reset($statements)->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals('D', $firstTransaction->getDebitCredit());
}

public function testParseTransactionPrice()
{
$statements = $this->engine->parse();
$transactions = reset($statements)->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals(20, $firstTransaction->getPrice());
}
}
18 changes: 0 additions & 18 deletions test/Parser/Banking/Mt940/Engine/Rabo/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,4 @@ public function testHandlingOfPREF() {
$statements = $this->engine->parse();
$this->assertSame('PmtInfId-20151208-987', $statements[0]->getTransactions()[1]->getDescription());
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test methods should not be deleted.

public function testParseTransactionDebitCredit()
{
$statements = $this->engine->parse();
$transactions = $statements[5]->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals('C', $firstTransaction->getDebitCredit());
}

public function testParseTransactionPrice()
{
$statements = $this->engine->parse();
$transactions = $statements[5]->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals(500, $firstTransaction->getPrice());
}
}
9 changes: 0 additions & 9 deletions test/Parser/Banking/Mt940/Engine/Spk/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,4 @@ public function testParsesAllFoundStatements()
$this->assertEquals('18-02-2010', $last->getStartTimestamp('d-m-Y'));
$this->assertEquals('18-02-2010', $last->getEndTimestamp('d-m-Y'));
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test methods should not be deleted.

public function testParseTransactionDebitCredit()
{
$statements = $this->engine->parse();
$transactions = reset($statements)->getTransactions();
$firstTransaction = reset($transactions);

$this->assertEquals('C', $firstTransaction->getDebitCredit());
}
}