Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Bunq and Spectre will ask to apply rules.
James Colea1d99c1954e7
diff --git a/app/Import/Configuration/BunqConfigurator.php b/app/Import/Configuration/BunqConfigurator.phpdeleted file mode 100644index a115f8e933..0000000000--- a/app/Import/Configuration/BunqConfigurator.php+++ /dev/null@@ -1,214 +0,0 @@-<?php-/**- * BunqConfigurator.php- * Copyright (c) 2018 [email protected]- *- * 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\Configuration;--use FireflyIII\Exceptions\FireflyException;-use FireflyIII\Models\ImportJob;-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;-use FireflyIII\Support\Import\Configuration\Bunq\HaveAccounts;-use Log;--/**- * @deprecated- * @codeCoverageIgnore- * Class BunqConfigurator.- */-class BunqConfigurator implements ConfiguratorInterface-{- /** @var ImportJob */- private $job;-- /** @var ImportJobRepositoryInterface */- private $repository;-- /** @var string */- private $warning = '';-- /**- * ConfiguratorInterface constructor.- */- public function __construct()- {- }-- /**- * Store any data from the $data array into the job.- *- * @param array $data- *- * @return bool- *- * @throws FireflyException- */- public function configureJob(array $data): bool- {- if (null === $this->job) {- throw new FireflyException('Cannot call configureJob() without a job.');- }- $stage = $this->getConfig()['stage'] ?? 'initial';- Log::debug(sprintf('in getNextData(), for stage "%s".', $stage));-- switch ($stage) {- case 'have-accounts':- /** @var HaveAccounts $class */- $class = app(HaveAccounts::class);- $class->setJob($this->job);- $class->storeConfiguration($data);-- // update job for next step and set to "configured".- $config = $this->getConfig();- $config['stage'] = 'have-account-mapping';- $this->repository->setConfiguration($this->job, $config);-- return true;- default:- throw new FireflyException(sprintf('Cannot store configuration when job is in state "%s"', $stage));- break;- }- }-- /**- * Return the data required for the next step in the job configuration.- *- * @return array- *- * @throws FireflyException- */- public function getNextData(): array- {- if (null === $this->job) {- throw new FireflyException('Cannot call configureJob() without a job.');- }- $config = $this->getConfig();- $stage = $config['stage'] ?? 'initial';-- Log::debug(sprintf('in getNextData(), for stage "%s".', $stage));-- switch ($stage) {- case 'have-accounts':- /** @var HaveAccounts $class */- $class = app(HaveAccounts::class);- $class->setJob($this->job);-- return $class->getData();- default:- return [];- }- }-- /**- * @return string- *- * @throws FireflyException- */- public function getNextView(): string- {- if (null === $this->job) {- throw new FireflyException('Cannot call configureJob() without a job.');- }- $stage = $this->getConfig()['stage'] ?? 'initial';-- Log::debug(sprintf('getNextView: in getNextView(), for stage "%s".', $stage));- switch ($stage) {- case 'have-accounts':- return 'import.bunq.accounts';- default:- return '';- }- }-- /**- * Return possible warning to user.- *- * @return string- */- public function getWarningMessage(): string- {- return $this->warning;- }-- /**- * @return bool- *- * @throws FireflyException- */- public function isJobConfigured(): bool- {- if (null === $this->job) {- throw new FireflyException('Cannot call configureJob() without a job.');- }- $stage = $this->getConfig()['stage'] ?? 'initial';-- Log::debug(sprintf('in isJobConfigured(), for stage "%s".', $stage));- switch ($stage) {- case 'have-accounts':- Log::debug('isJobConfigured returns false');-- return false;- default:- Log::debug('isJobConfigured returns true');-- return true;- }- }-- /**- * @param ImportJob $job- */- public function setJob(ImportJob $job): void- {- // make repository- $this->repository = app(ImportJobRepositoryInterface::class);- $this->repository->setUser($job->user);-- // set default config:- $defaultConfig = [- 'is-redirected' => false,- 'stage' => 'initial',- 'auto-start' => true,- 'apply-rules' => true,- ];- $currentConfig = $this->repository->getConfiguration($job);- $finalConfig = array_merge($defaultConfig, $currentConfig);-- // set default extended status:- $extendedStatus = $this->repository->getExtendedStatus($job);- $extendedStatus['steps'] = 8;-- // save to job:- $job = $this->repository->setConfiguration($job, $finalConfig);- $job = $this->repository->setExtendedStatus($job, $extendedStatus);- $this->job = $job;-- }-- /**- * Shorthand method.- *- * @return array- */- private function getConfig(): array- {- return $this->repository->getConfiguration($this->job);- }-}diff --git a/app/Import/Configuration/ConfiguratorInterface.php b/app/Import/Configuration/ConfiguratorInterface.phpdeleted file mode 100644index a1e961b0ec..0000000000--- a/app/Import/Configuration/ConfiguratorInterface.php+++ /dev/null@@ -1,80 +0,0 @@-<?php-/**- * ConfiguratorInterface.php- * Copyright (c) 2017 [email protected]- *- * 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\Configuration;--use FireflyIII\Models\ImportJob;--/**- * @deprecated- * @codeCoverageIgnore- * Interface ConfiguratorInterface.- */-interface ConfiguratorInterface-{- /**- * ConfiguratorInterface constructor.- */- public function __construct();-- /**- * Store any data from the $data array into the job.- *- * @param array $data- *- * @return bool- */- public function configureJob(array $data): bool;-- /**- * Return the data required for the next step in the job configuration.- *- * @return array- */- public function getNextData(): array;-- /**- * Returns the view of the next step in the job configuration.- *- * @return string- */- public function getNextView(): string;-- /**- * Return possible warning to user.- *- * @return string- */- public function getWarningMessage(): string;-- /**- * Returns true when the initial configuration for this job is complete.- *- * @return bool- */- public function isJobConfigured(): bool;-- /**- * @param ImportJob $job- */- public function setJob(ImportJob $job);-}diff --git a/app/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandler.php b/app/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandler.phpindex 247a7a2916..ff8764cb52 100644--- a/app/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandler.php+++ b/app/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandler.php@@ -76,10 +76,11 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface*/public function configureJob(array $data): MessageBag{- $config = $this->repository->getConfiguration($this->importJob);- $accounts = $config['accounts'] ?? [];- $mapping = $data['account_mapping'] ?? [];- $final = [];+ $config = $this->repository->getConfiguration($this->importJob);+ $accounts = $config['accounts'] ?? [];+ $mapping = $data['account_mapping'] ?? [];+ $applyRules = (int)$data['apply_rules'] === 1;+ $final = [];if (\count($accounts) === 0) {throw new FireflyException('No bunq accounts found. Import cannot continue.'); // @codeCoverageIgnore}@@ -98,7 +99,8 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface$accountId = $this->validLocalAccount($localId);$final[$bunqId] = $accountId;}- $config['mapping'] = $final;+ $config['mapping'] = $final;+ $config['apply-rules'] = $applyRules;$this->repository->setConfiguration($this->importJob, $config);return new MessageBag;diff --git a/app/Support/Import/JobConfiguration/Bunq/NewBunqJobHandler.php b/app/Support/Import/JobConfiguration/Bunq/NewBunqJobHandler.phpindex 2f3f208c93..e83d4247b5 100644--- a/app/Support/Import/JobConfiguration/Bunq/NewBunqJobHandler.php+++ b/app/Support/Import/JobConfiguration/Bunq/NewBunqJobHandler.php@@ -45,11 +45,6 @@ class NewBunqJobHandler implements BunqJobConfigurationInterface*/public function configurationComplete(): bool{- // simply set the job configuration "apply-rules" to true.- $config = $this->repository->getConfiguration($this->importJob);- $config['apply-rules'] = true;- $this->repository->setConfiguration($this->importJob, $config);-return true;}diff --git a/app/Support/Import/JobConfiguration/Spectre/ChooseAccountsHandler.php b/app/Support/Import/JobConfiguration/Spectre/ChooseAccountsHandler.phpindex ee85ebfb8d..9797acd428 100644--- a/app/Support/Import/JobConfiguration/Spectre/ChooseAccountsHandler.php+++ b/app/Support/Import/JobConfiguration/Spectre/ChooseAccountsHandler.php@@ -83,9 +83,10 @@ class ChooseAccountsHandler implements SpectreJobConfigurationInterfacepublic function configureJob(array $data): MessageBag{Log::debug('Now in ChooseAccountsHandler::configureJob()', $data);- $config = $this->importJob->configuration;- $mapping = $data['account_mapping'] ?? [];- $final = [];+ $config = $this->importJob->configuration;+ $mapping = $data['account_mapping'] ?? [];+ $final = [];+ $applyRules = (int)$data['apply_rules'] === 1;foreach ($mapping as $spectreId => $localId) {// validate each$spectreId = $this->validSpectreAccount((int)$spectreId);@@ -96,7 +97,7 @@ class ChooseAccountsHandler implements SpectreJobConfigurationInterfaceLog::debug('Final mapping is:', $final);$messages = new MessageBag;$config['account_mapping'] = $final;-+ $config['apply-rules'] = $applyRules;$this->repository->setConfiguration($this->importJob, $config);if ($final === [0 => 0] || \count($final) === 0) {$messages->add('count', trans('import.spectre_no_mapping'));diff --git a/resources/lang/en_US/import.php b/resources/lang/en_US/import.phpindex feb4f58645..824704689e 100644--- a/resources/lang/en_US/import.php+++ b/resources/lang/en_US/import.php@@ -127,13 +127,16 @@ return ['spectre_no_mapping' => 'It seems you have not selected any accounts to import from.','imported_from_account' => 'Imported from ":account"','spectre_account_with_number' => 'Account :number',+ 'job_config_spectre_apply_rules' => 'Apply rules',+ 'job_config_spectre_apply_rules_text' => 'By default, your rules will be applied to the transactions created during this import routine. If you do not want this to happen, deselect this checkbox.',// job configuration for bunq:'job_config_bunq_accounts_title' => 'bunq accounts','job_config_bunq_accounts_text' => 'These are the accounts associated with your bunq account. Please select the accounts from which you want to import, and in which account the transactions must be imported.','bunq_no_mapping' => 'It seems you have not selected any accounts.','should_download_config' => 'You should download <a href=":route">the configuration file</a> for this job. This will make future imports way easier.','share_config_file' => 'If you have imported data from a public bank, you should <a href="https://github.com/firefly-iii/import-configurations/wiki">share your configuration file</a> so it will be easy for other users to import their data. Sharing your configuration file will not expose your financial details.',-+ 'job_config_bunq_apply_rules' => 'Apply rules',+ 'job_config_bunq_apply_rules_text' => 'By default, your rules will be applied to the transactions created during this import routine. If you do not want this to happen, deselect this checkbox.',// keys from "extra" array:'spectre_extra_key_iban' => 'IBAN','spectre_extra_key_swift' => 'SWIFT',diff --git a/resources/views/import/bunq/choose-accounts.twig b/resources/views/import/bunq/choose-accounts.twigindex f5b4afba79..566837af83 100644--- a/resources/views/import/bunq/choose-accounts.twig+++ b/resources/views/import/bunq/choose-accounts.twig@@ -7,6 +7,26 @@<div class="row"><form class="form-horizontal" action="{{ route('import.job.configuration.post',[importJob.key]) }}" method="post"><input type="hidden" name="_token" value="{{ csrf_token() }}"/>++ <div class="col-lg-12 col-md-12 col-sm-12">+ <div class="box box-default">+ <div class="box-header with-border">+ <h3 class="box-title">{{ trans('import.job_config_bunq_apply_rules') }}</h3>+ </div>+ <div class="box-body">+ <div class="row">+ <div class="col-lg-6">+ <p>+ {{ trans('import.job_config_bunq_apply_rules_text') }}+ </p>+ {{ ExpandedForm.checkbox('apply_rules', 1, true) }}+ </div>+ </div>++ </div>+ </div>+ </div>+<div class="col-lg-12 col-md-12 col-sm-12"><div class="box box-default"><div class="box-header with-border">diff --git a/resources/views/import/spectre/accounts.twig b/resources/views/import/spectre/accounts.twigindex c6c0eedf82..4fbf0ba248 100644--- a/resources/views/import/spectre/accounts.twig+++ b/resources/views/import/spectre/accounts.twig@@ -7,6 +7,26 @@<div class="row"><form class="form-horizontal" action="{{ route('import.job.configuration.post',[importJob.key]) }}" method="post"><input type="hidden" name="_token" value="{{ csrf_token() }}"/>++ <div class="col-lg-12 col-md-12 col-sm-12">+ <div class="box box-default">+ <div class="box-header with-border">+ <h3 class="box-title">{{ trans('import.job_config_spectre_apply_rules') }}</h3>+ </div>+ <div class="box-body">+ <div class="row">+ <div class="col-lg-6">+ <p>+ {{ trans('import.job_config_spectre_apply_rules_text') }}+ </p>+ {{ ExpandedForm.checkbox('apply_rules', 1, true) }}+ </div>+ </div>++ </div>+ </div>+ </div>+<div class="col-lg-12 col-md-12 col-sm-12"><div class="box box-default"><div class="box-header with-border">