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,42 +18,41 @@
* 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

@ -141,102 +141,108 @@ return [
'field' => 'external-id',
],
'currency-symbol' => [
'currency-symbol' => [
'mappable' => true,
'pre-process-map' => false,
'converter' => 'CurrencySymbol',
'field' => 'currency',
'mapper' => 'TransactionCurrencies',
],
'description' => [
'description' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Description',
'field' => 'description',
],
'date-transaction' => [
'date-transaction' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Date',
'field' => 'date',
],
'date-interest' => [
'date-interest' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Date',
'field' => 'date-interest',
],
'date-book' => [
'date-book' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Date',
'field' => 'date-book',
],
'date-process' => [
'date-process' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Date',
'field' => 'date-process',
],
'date-due' => [
'date-due' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Date',
'field' => 'date-due',
],
'date-payment' => [
'date-payment' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Date',
'field' => 'date-payment',
],
'date-invoice' => [
'date-invoice' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Date',
'field' => 'date-invoice',
],
'budget-id' => [
'budget-id' => [
'mappable' => true,
'pre-process-map' => false,
'converter' => 'BudgetId',
'field' => 'budget',
'mapper' => 'Budgets',
],
'budget-name' => [
'budget-name' => [
'mappable' => true,
'pre-process-map' => false,
'converter' => 'BudgetName',
'field' => 'budget',
'mapper' => 'Budgets',
],
'rabo-debit-credit' => [
'rabo-debit-credit' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'RabobankDebitCredit',
'converter' => 'BankDebitCredit',
'field' => 'amount-modifier',
],
'ing-debit-credit' => [
'ing-debit-credit' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'INGDebitCredit',
'converter' => 'BankDebitCredit',
'field' => 'amount-modifier',
],
'category-id' => [
'generic-debit-credit' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'BankDebitCredit',
'field' => 'amount-modifier',
],
'category-id' => [
'mappable' => true,
'pre-process-map' => false,
'converter' => 'CategoryId',
'field' => 'category',
'mapper' => 'Categories',
],
'category-name' => [
'category-name' => [
'mappable' => true,
'pre-process-map' => false,
'converter' => 'CategoryName',
'field' => 'category',
'mapper' => 'Categories',
],
'tags-comma' => [
'tags-comma' => [
'mappable' => false,
'pre-process-map' => true,
'pre-process-mapper' => 'TagsComma',
@ -244,7 +250,7 @@ return [
'converter' => 'TagsComma',
'mapper' => 'Tags',
],
'tags-space' => [
'tags-space' => [
'mappable' => false,
'pre-process-map' => true,
'pre-process-mapper' => 'TagsSpace',
@ -252,21 +258,21 @@ return [
'converter' => 'TagsSpace',
'mapper' => 'Tags',
],
'account-id' => [
'account-id' => [
'mappable' => true,
'pre-process-map' => false,
'field' => 'asset-account-id',
'converter' => 'AccountId',
'mapper' => 'AssetAccounts',
],
'account-name' => [
'account-name' => [
'mappable' => true,
'pre-process-map' => false,
'field' => 'asset-account-name',
'converter' => 'AssetAccountName',
'mapper' => 'AssetAccounts',
],
'account-iban' => [
'account-iban' => [
'mappable' => true,
'pre-process-map' => false,
'field' => 'asset-account-iban',
@ -274,78 +280,78 @@ return [
'mapper' => 'AssetAccountIbans',
],
'account-number' => [
'account-number' => [
'mappable' => true,
'pre-process-map' => false,
'field' => 'asset-account-number',
'converter' => 'AssetAccountNumber',
'mapper' => 'AssetAccounts',
],
'account-bic' => [
'account-bic' => [
'mappable' => false,
'pre-process-map' => false,
'field' => 'asset-account-bic',
'converter' => 'AccountBic',
],
'opposing-id' => [
'opposing-id' => [
'mappable' => true,
'pre-process-map' => false,
'field' => 'opposing-account-id',
'converter' => 'AccountId',
'mapper' => 'OpposingAccounts',
],
'opposing-bic' => [
'opposing-bic' => [
'mappable' => false,
'pre-process-map' => false,
'field' => 'opposing-account-bic',
'converter' => 'AccountBic',
],
'opposing-name' => [
'opposing-name' => [
'mappable' => true,
'pre-process-map' => false,
'field' => 'opposing-account-name',
'converter' => 'OpposingAccountName',
'mapper' => 'OpposingAccounts',
],
'opposing-iban' => [
'opposing-iban' => [
'mappable' => true,
'pre-process-map' => false,
'field' => 'opposing-account-iban',
'converter' => 'OpposingAccountIban',
'mapper' => 'OpposingAccountIbans',
],
'opposing-number' => [
'opposing-number' => [
'mappable' => true,
'pre-process-map' => false,
'field' => 'opposing-account-number',
'converter' => 'OpposingAccountNumber',
'mapper' => 'OpposingAccounts',
],
'amount' => [
'amount' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Amount',
'field' => 'amount',
],
'amount_debit' => [
'amount_debit' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'AmountDebit',
'field' => 'amount_debit',
],
'amount_credit' => [
'amount_credit' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'AmountCredit',
'field' => 'amount_credit',
],
'amount_negated' => [
'amount_negated' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'AmountNegated',
'field' => 'amount_negated',
],
'amount_foreign' => [
'amount_foreign' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Amount',
@ -353,63 +359,63 @@ return [
],
// SEPA end to end ID
'sepa-ct-id' => [
'sepa-ct-id' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Description',
'field' => 'sepa_ct_id',
],
// SEPA opposing account identifier
'sepa-ct-op' => [
'sepa-ct-op' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Description',
'field' => 'sepa_ct_op',
],
// SEPA Direct Debit Mandate Identifier
'sepa-db' => [
'sepa-db' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Description',
'field' => 'sepa_db',
],
// SEPA clearing code
'sepa-cc' => [
'sepa-cc' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Description',
'field' => 'sepa_cc',
],
// SEPA country
'sepa-country' => [
'sepa-country' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Description',
'field' => 'sepa_country',
],
// SEPA external purpose
'sepa-ep' => [
'sepa-ep' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Description',
'field' => 'sepa_ep',
],
// SEPA creditor identifier
'sepa-ci' => [
'sepa-ci' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Description',
'field' => 'sepa_ci',
],
// SEPA Batch ID
'sepa-batch-id' => [
'sepa-batch-id' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Description',
'field' => 'sepa_batch',
],
// Internal reference
'internal-reference' => [
'internal-reference' => [
'mappable' => false,
'pre-process-map' => false,
'converter' => 'Description',

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);
}
}