Experimental fix for #2031

This commit is contained in:
James Cole 2019-01-27 21:23:18 +01:00
parent 968505ac0e
commit d905849b71
6 changed files with 98 additions and 218 deletions

View File

@ -1,7 +1,7 @@
<?php
/**
* RabobankDebitCredit.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* BankDebitCredit.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
@ -18,41 +18,40 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use Log;
/**
* Class RabobankDebitCredit.
*
* Class BankDebitCredit
*/
class RabobankDebitCredit implements ConverterInterface
class BankDebitCredit implements ConverterInterface
{
/**
* Convert D or A to integer values.
* Convert a value.
*
* @return mixed
*
* @param $value
*
* @return int
*/
public function convert($value): int
{
Log::debug('Going to convert ', ['value' => $value]);
if ('D' === $value) {
Log::debug('Return -1');
$negative = [
'D', // Old style Rabobank (NL). Short for "Debit"
'A', // New style Rabobank (NL). Short for "Af"
'Af', // ING (NL).
'Debet', // Triodos (NL)
];
if (\in_array(trim($value), $negative, true)) {
return -1;
}
// old format:
if ('A' === $value) {
Log::debug('Return -1');
return -1;
}
Log::debug('Return 1');
return 1;
}

View File

@ -1,53 +0,0 @@
<?php
/**
* INGDebitCredit.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use Log;
/**
* Class INGDebitCredit.
*/
class INGDebitCredit implements ConverterInterface
{
/**
* Convert Af or Bij to correct integer values.
*
* @param $value
*
* @return int
*/
public function convert($value): int
{
Log::debug('Going to convert ing debit credit', ['value' => $value]);
if ('Af' === $value) {
Log::debug('Return -1');
return -1;
}
Log::debug('Return 1');
return 1;
}
}

View File

@ -213,13 +213,19 @@ return [
'rabo-debit-credit' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'RabobankDebitCredit',
'converter' => 'BankDebitCredit',
'field' => 'amount-modifier',
],
'ing-debit-credit' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'INGDebitCredit',
'converter' => 'BankDebitCredit',
'field' => 'amount-modifier',
],
'generic-debit-credit' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'BankDebitCredit',
'field' => 'amount-modifier',
],
'category-id' => [

View File

@ -307,6 +307,7 @@ return [
'column_opposing-name' => 'Opposing account (name)',
'column_rabo-debit-credit' => 'Rabobank specific debit/credit indicator',
'column_ing-debit-credit' => 'ING specific debit/credit indicator',
'column_generic-debit-credit' => 'Generic bank debit/credit indicator',
'column_sepa-ct-id' => 'SEPA end-to-end Identifier',
'column_sepa-ct-op' => 'SEPA Opposing Account Identifier',
'column_sepa-db' => 'SEPA Mandate Identifier',

View File

@ -23,14 +23,16 @@ declare(strict_types=1);
namespace Tests\Unit\Import\Converter;
use FireflyIII\Import\Converter\BankDebitCredit;
use FireflyIII\Import\Converter\INGDebitCredit;
use Log;
use Tests\TestCase;
/**
* Class INGDebitCreditTest
*
* Class BankDebitCreditTest
*/
class INGDebitCreditTest extends TestCase
class BankDebitCreditTest extends TestCase
{
/**
*
@ -41,34 +43,53 @@ class INGDebitCreditTest extends TestCase
Log::info(sprintf('Now in %s.', \get_class($this)));
}
/**
* @covers \FireflyIII\Import\Converter\BankDebitCredit
*/
public function testConvertA(): void
{
$converter = new BankDebitCredit;
$result = $converter->convert('A');
$this->assertEquals(-1, $result);
}
/**
* @covers \FireflyIII\Import\Converter\INGDebitCredit
* @covers \FireflyIII\Import\Converter\BankDebitCredit
*/
public function testConvertAf(): void
{
$converter = new INGDebitCredit;
$converter = new BankDebitCredit;
$result = $converter->convert('Af');
$this->assertEquals(-1, $result);
}
/**
* @covers \FireflyIII\Import\Converter\INGDebitCredit
* @covers \FireflyIII\Import\Converter\BankDebitCredit
*/
public function testConvertAnything(): void
{
$converter = new INGDebitCredit;
$converter = new BankDebitCredit;
$result = $converter->convert('9083jkdkj');
$this->assertEquals(1, $result);
}
/**
* @covers \FireflyIII\Import\Converter\INGDebitCredit
* @covers \FireflyIII\Import\Converter\BankDebitCredit
*/
public function testConvertBij(): void
{
$converter = new INGDebitCredit;
$converter = new BankDebitCredit;
$result = $converter->convert('Bij');
$this->assertEquals(1, $result);
}
/**
* @covers \FireflyIII\Import\Converter\BankDebitCredit
*/
public function testConvertDebet(): void
{
$converter = new BankDebitCredit;
$result = $converter->convert('Debet');
$this->assertEquals(-1, $result);
}
}

View File

@ -1,94 +0,0 @@
<?php
/**
* RabobankDebitCreditTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Converter;
use FireflyIII\Import\Converter\RabobankDebitCredit;
use Log;
use Tests\TestCase;
/**
* Class RabobankDebitCredit
*/
class RabobankDebitCreditTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', \get_class($this)));
}
/**
* @covers \FireflyIII\Import\Converter\RabobankDebitCredit
*/
public function testConvertAnything(): void
{
$converter = new RabobankDebitCredit;
$result = $converter->convert('9083jkdkj');
$this->assertEquals(1, $result);
}
/**
* @covers \FireflyIII\Import\Converter\RabobankDebitCredit
*/
public function testConvertCredit(): void
{
$converter = new RabobankDebitCredit;
$result = $converter->convert('C');
$this->assertEquals(1, $result);
}
/**
* @covers \FireflyIII\Import\Converter\RabobankDebitCredit
*/
public function testConvertCreditOld(): void
{
$converter = new RabobankDebitCredit;
$result = $converter->convert('B');
$this->assertEquals(1, $result);
}
/**
* @covers \FireflyIII\Import\Converter\RabobankDebitCredit
*/
public function testConvertDebit(): void
{
$converter = new RabobankDebitCredit;
$result = $converter->convert('D');
$this->assertEquals(-1, $result);
}
/**
* @covers \FireflyIII\Import\Converter\RabobankDebitCredit
*/
public function testConvertDebitOld(): void
{
$converter = new RabobankDebitCredit;
$result = $converter->convert('A');
$this->assertEquals(-1, $result);
}
}