diff --git a/app/Import/Configuration/BunqConfigurator.php b/app/Import/Configuration/BunqConfigurator.php deleted file mode 100644 index a115f8e933..0000000000 --- a/app/Import/Configuration/BunqConfigurator.php +++ /dev/null @@ -1,214 +0,0 @@ -. - */ -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.php deleted file mode 100644 index a1e961b0ec..0000000000 --- a/app/Import/Configuration/ConfiguratorInterface.php +++ /dev/null @@ -1,80 +0,0 @@ -. - */ -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.php index 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.php index 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.php index 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 SpectreJobConfigurationInterface public 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 SpectreJobConfigurationInterface Log::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.php index 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 the configuration file for this job. This will make future imports way easier.', 'share_config_file' => 'If you have imported data from a public bank, you should share your configuration file 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.twig index f5b4afba79..566837af83 100644 --- a/resources/views/import/bunq/choose-accounts.twig +++ b/resources/views/import/bunq/choose-accounts.twig @@ -7,6 +7,26 @@
+ +
+
+
+

{{ trans('import.job_config_bunq_apply_rules') }}

+
+
+
+
+

+ {{ trans('import.job_config_bunq_apply_rules_text') }} +

+ {{ ExpandedForm.checkbox('apply_rules', 1, true) }} +
+
+ +
+
+
+
diff --git a/resources/views/import/spectre/accounts.twig b/resources/views/import/spectre/accounts.twig index c6c0eedf82..4fbf0ba248 100644 --- a/resources/views/import/spectre/accounts.twig +++ b/resources/views/import/spectre/accounts.twig @@ -7,6 +7,26 @@
+ +
+
+
+

{{ trans('import.job_config_spectre_apply_rules') }}

+
+
+
+
+

+ {{ trans('import.job_config_spectre_apply_rules_text') }} +

+ {{ ExpandedForm.checkbox('apply_rules', 1, true) }} +
+
+ +
+
+
+