From 251e9f9ba124876d27ef668fc510c00b63f47f80 Mon Sep 17 00:00:00 2001 From: Sander Kleykens Date: Thu, 4 Apr 2019 21:08:31 +0200 Subject: [PATCH 1/2] CSV file fix for Belfius Correct the description for outgoing recurring transactions in Belfius CSV files --- app/Import/Specifics/Belfius.php | 94 +++++++++++++++++++++ config/csv.php | 2 + resources/lang/en_US/import.php | 2 + tests/Unit/Import/Specifics/BelfiusTest.php | 87 +++++++++++++++++++ 4 files changed, 185 insertions(+) create mode 100644 app/Import/Specifics/Belfius.php create mode 100644 tests/Unit/Import/Specifics/BelfiusTest.php diff --git a/app/Import/Specifics/Belfius.php b/app/Import/Specifics/Belfius.php new file mode 100644 index 0000000000..714cfb9848 --- /dev/null +++ b/app/Import/Specifics/Belfius.php @@ -0,0 +1,94 @@ + + * + * 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 . + */ +declare(strict_types=1); + +namespace FireflyIII\Import\Specifics; + +/** + * Class Belfius. + * + * Fixes Belfius CSV files to: + * - Correct descriptions for recurring transactions so doubles can be detected when the equivalent incoming + * transaction is imported. + * + */ +class Belfius implements SpecificInterface +{ + /** + * Description of this specific fix. + * + * @return string + * @codeCoverageIgnore + */ + public static function getDescription(): string + { + return 'import.specific_belfius_descr'; + } + + /** + * Name of specific fix. + * + * @return string + * @codeCoverageIgnore + */ + public static function getName(): string + { + return 'import.specific_belfius_name'; + } + + /** + * Run the fix. + * + * @param array $row + * + * @return array + * + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + */ + public function run(array $row): array + { + return Belfius::processRecurringTransactionDescription($row); + } + + /** + * Fixes the description for outgoing recurring transactions so doubles can be detected when the equivalent incoming + * transaction is imported for another bank account. + * + * @return array the row containing the new description + */ + protected static function processRecurringTransactionDescription(array $row): array + { + if (!isset($row[5]) || !isset($row[14])) { + return $row; + } + + $opposingAccountName = $row[5]; + $description = $row[14]; + + preg_match('/DOORLOPENDE OPDRACHT.*\s+' . preg_quote($opposingAccountName, '/') . '\s+(.+)\s+REF.\s*:/', $description, $matches); + + if (isset($matches[1])) { + $row[14] = $matches[1]; + } + + return $row; + } +} diff --git a/config/csv.php b/config/csv.php index 02303455ee..a265ed013d 100644 --- a/config/csv.php +++ b/config/csv.php @@ -26,6 +26,7 @@ use FireflyIII\Import\Specifics\AbnAmroDescription; use FireflyIII\Import\Specifics\IngDescription; use FireflyIII\Import\Specifics\PresidentsChoice; use FireflyIII\Import\Specifics\SnsDescription; +use FireflyIII\Import\Specifics\Belfius; return [ @@ -37,6 +38,7 @@ return [ 'AbnAmroDescription' => AbnAmroDescription::class, 'SnsDescription' => SnsDescription::class, 'PresidentsChoice' => PresidentsChoice::class, + 'Belfius' => Belfius::class ], /* diff --git a/resources/lang/en_US/import.php b/resources/lang/en_US/import.php index 3f19501654..34d9f070c0 100644 --- a/resources/lang/en_US/import.php +++ b/resources/lang/en_US/import.php @@ -207,6 +207,8 @@ return [ 'specific_rabo_descr' => 'Fixes potential problems with Rabobank files', 'specific_pres_name' => 'President\'s Choice Financial CA', 'specific_pres_descr' => 'Fixes potential problems with PC files', + 'specific_belfius_name' => 'Belfius BE', + 'specific_belfius_descr' => 'Fixes potential problems with Belfius files', // job configuration for file provider (stage: roles) 'job_config_roles_title' => 'Import setup (3/4) - Define each column\'s role', 'job_config_roles_text' => 'Each column in your CSV file contains certain data. Please indicate what kind of data the importer should expect. The option to "map" data means that you will link each entry found in the column to a value in your database. An often mapped column is the column that contains the IBAN of the opposing account. That can be easily matched to IBAN\'s present in your database already.', diff --git a/tests/Unit/Import/Specifics/BelfiusTest.php b/tests/Unit/Import/Specifics/BelfiusTest.php new file mode 100644 index 0000000000..6a26ccb44d --- /dev/null +++ b/tests/Unit/Import/Specifics/BelfiusTest.php @@ -0,0 +1,87 @@ + + * + * 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 . + */ + +declare(strict_types=1); + +namespace Tests\Unit\Import\Specifics; + + +use FireflyIII\Import\Specifics\Belfius; +use Tests\TestCase; +use Log; + +/** + * Class BelfiusTest + */ +class BelfiusTest extends TestCase +{ + /** + * + */ + public function setUp(): void + { + parent::setUp(); + Log::info(sprintf('Now in %s.', \get_class($this))); + } + + + /** + * Should return the exact same array. + * + * @covers \FireflyIII\Import\Specifics\Belfius + */ + public function testEmptyRow(): void + { + $row = [1, 2, 3, 4]; + + $parser = new Belfius; + $result = $parser->run($row); + $this->assertEquals($row, $result); + } + + /** + * Data that cannot be parsed. + * + * @covers \FireflyIII\Import\Specifics\Belfius + */ + public function testProcessUnknown(): void + { + $row = [0, 1, 2, 3, 4, 'STORE BRUSSEL n/v', 6, 7, 8, 9, 10, 11, 12, 13, 'AANKOOP BANCONTACT CONTACTLESS MET KAART NR 01234 5678 9012 3456 - FOO BAR OP 01/01 00:01 STORE BRUSSEL n/v REF. : 01234567890 VAL. 01-01']; + + $parser = new Belfius; + $result = $parser->run($row); + $this->assertEquals($row, $result); + } + + /** + * Data with recurring transaction. + * + * @covers \FireflyIII\Import\Specifics\Belfius + */ + public function testProcessRecurringTransaction(): void + { + $row = [0, 1, 2, 3, 4, 'Tom Jones', 6, 7, 8, 9, 10, 11, 12, 13, 'DOORLOPENDE OPDRACHT 12345678 NAAR BE01 1234 5678 9012 Tom Jones My Description REF. : 01234567890 VAL. 01-01']; + + $parser = new Belfius; + $result = $parser->run($row); + $this->assertEquals('My Description', $result[14]); + } +} From b3e48ede70758f159173b579b45f439d32d062eb Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 8 Apr 2019 20:40:12 +0200 Subject: [PATCH 2/2] Fix #2204 --- app/Validation/FireflyValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index 49a6d95749..bb36f45cb6 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -341,7 +341,7 @@ class FireflyValidator extends Validator // check transaction type. if ('transaction_type' === $triggerType) { - $count = TransactionType::where('type', strtolower($value))->count(); + $count = TransactionType::where('type', ucfirst($value))->count(); return 1 === $count; }