From 926c03986cf072b89d77c2bdac8123db02003208 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 14 Apr 2018 13:00:24 +0200 Subject: [PATCH] Remove references to bill scanning. --- .../Events/StoredJournalEventHandler.php | 15 ------ .../Events/UpdatedJournalEventHandler.php | 15 ------ app/Import/Configuration/BunqConfigurator.php | 1 - app/Import/Configuration/FileConfigurator.php | 1 - .../Configuration/SpectreConfigurator.php | 1 - app/Import/Storage/ImportStorage.php | 26 +--------- app/Import/Storage/ImportSupport.php | 40 ---------------- app/Providers/EventServiceProvider.php | 2 - app/Repositories/Bill/BillRepository.php | 46 ------------------ .../Bill/BillRepositoryInterface.php | 8 ---- app/Support/Events/BillScanner.php | 47 ------------------- .../Configuration/File/UploadConfig.php | 1 - .../views/import/file/upload-config.twig | 15 ------ 13 files changed, 1 insertion(+), 217 deletions(-) delete mode 100644 app/Support/Events/BillScanner.php diff --git a/app/Handlers/Events/StoredJournalEventHandler.php b/app/Handlers/Events/StoredJournalEventHandler.php index 6cfb5ad600..43ca29745b 100644 --- a/app/Handlers/Events/StoredJournalEventHandler.php +++ b/app/Handlers/Events/StoredJournalEventHandler.php @@ -28,7 +28,6 @@ use FireflyIII\Models\RuleGroup; use FireflyIII\Repositories\Journal\JournalRepositoryInterface as JRI; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface as PRI; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface as RGRI; -use FireflyIII\Support\Events\BillScanner; use FireflyIII\TransactionRules\Processor; /** @@ -91,18 +90,4 @@ class StoredJournalEventHandler return true; } - /** - * This method calls a special bill scanner that will check if the stored journal is part of a bill. - * - * @param StoredTransactionJournal $storedJournalEvent - * - * @return bool - */ - public function scanBills(StoredTransactionJournal $storedJournalEvent): bool - { - $journal = $storedJournalEvent->journal; - BillScanner::scan($journal); - - return true; - } } diff --git a/app/Handlers/Events/UpdatedJournalEventHandler.php b/app/Handlers/Events/UpdatedJournalEventHandler.php index 4b1ee5b3ff..ac06e95908 100644 --- a/app/Handlers/Events/UpdatedJournalEventHandler.php +++ b/app/Handlers/Events/UpdatedJournalEventHandler.php @@ -26,7 +26,6 @@ use FireflyIII\Events\UpdatedTransactionJournal; use FireflyIII\Models\Rule; use FireflyIII\Models\RuleGroup; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; -use FireflyIII\Support\Events\BillScanner; use FireflyIII\TransactionRules\Processor; /** @@ -80,18 +79,4 @@ class UpdatedJournalEventHandler return true; } - /** - * This method calls a special bill scanner that will check if the updated journal is part of a bill. - * - * @param UpdatedTransactionJournal $updatedJournalEvent - * - * @return bool - */ - public function scanBills(UpdatedTransactionJournal $updatedJournalEvent): bool - { - $journal = $updatedJournalEvent->journal; - BillScanner::scan($journal); - - return true; - } } diff --git a/app/Import/Configuration/BunqConfigurator.php b/app/Import/Configuration/BunqConfigurator.php index f1bb96fe60..6dad1ea2ad 100644 --- a/app/Import/Configuration/BunqConfigurator.php +++ b/app/Import/Configuration/BunqConfigurator.php @@ -185,7 +185,6 @@ class BunqConfigurator implements ConfiguratorInterface 'stage' => 'initial', 'auto-start' => true, 'apply-rules' => true, - 'match-bills' => false, ]; $currentConfig = $this->repository->getConfiguration($job); $finalConfig = array_merge($defaultConfig, $currentConfig); diff --git a/app/Import/Configuration/FileConfigurator.php b/app/Import/Configuration/FileConfigurator.php index 0eae8d7d07..2151e0091c 100644 --- a/app/Import/Configuration/FileConfigurator.php +++ b/app/Import/Configuration/FileConfigurator.php @@ -53,7 +53,6 @@ class FileConfigurator implements ConfiguratorInterface 'file-type' => 'csv', // assume 'has-config-file' => true, 'apply-rules' => true, - 'match-bills' => false, 'auto-start' => false, ]; /** @var ImportJob */ diff --git a/app/Import/Configuration/SpectreConfigurator.php b/app/Import/Configuration/SpectreConfigurator.php index e09f7d17fb..a0b5a41915 100644 --- a/app/Import/Configuration/SpectreConfigurator.php +++ b/app/Import/Configuration/SpectreConfigurator.php @@ -206,7 +206,6 @@ class SpectreConfigurator implements ConfiguratorInterface 'accounts-mapped' => '', 'auto-start' => true, 'apply-rules' => true, - 'match-bills' => false, ]; $currentConfig = $this->repository->getConfiguration($job); $finalConfig = array_merge($defaultConfig, $currentConfig); diff --git a/app/Import/Storage/ImportStorage.php b/app/Import/Storage/ImportStorage.php index aee0bdbc6a..0e75e0fce1 100644 --- a/app/Import/Storage/ImportStorage.php +++ b/app/Import/Storage/ImportStorage.php @@ -28,7 +28,6 @@ use FireflyIII\Factory\TransactionJournalFactory; use FireflyIII\Import\Object\ImportJournal; use FireflyIII\Models\ImportJob; use FireflyIII\Models\TransactionType; -use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Support\Collection; @@ -56,10 +55,6 @@ class ImportStorage public $errors; /** @var Collection */ public $journals; - /** @var BillRepositoryInterface */ - protected $billRepository; - /** @var Collection */ - protected $bills; /** @var int */ protected $defaultCurrencyId = 1; /** @var ImportJob */ @@ -76,8 +71,6 @@ class ImportStorage private $dateFormat = 'Ymd'; /** @var TransactionJournalFactory */ private $factory; - /** @var bool */ - private $matchBills = false; /** @var Collection */ private $objects; /** @var int */ @@ -122,20 +115,13 @@ class ImportStorage $this->job = $job; $this->transfers = $this->getTransfers(); $this->applyRules = $config['apply-rules'] ?? false; - $this->matchBills = $config['match-bills'] ?? false; if (true === $this->applyRules) { Log::debug('applyRules seems to be true, get the rules.'); $this->rules = $this->getRules(); } - if (true === $this->matchBills) { - Log::debug('matchBills seems to be true, get the bills'); - $this->bills = $this->getBills(); - $this->billRepository = app(BillRepositoryInterface::class); - $this->billRepository->setUser($job->user); - } + Log::debug(sprintf('Value of apply rules is %s', var_export($this->applyRules, true))); - Log::debug(sprintf('Value of match bills is %s', var_export($this->matchBills, true))); } /** @@ -301,16 +287,6 @@ class ImportStorage Log::info('Will NOT apply rules to this journal.'); } $this->addStep(); - - // match bills if config calls for it. - if (true === $this->matchBills) { - Log::info('Will match bills.'); - $this->matchBills($factoryJournal); - } - - if (!(true === $this->matchBills)) { - Log::info('Cannot match bills (yet), but do not have to.'); - } $this->addStep(); Log::info( diff --git a/app/Import/Storage/ImportSupport.php b/app/Import/Storage/ImportSupport.php index ddcb5fa1f6..f7544b516e 100644 --- a/app/Import/Storage/ImportSupport.php +++ b/app/Import/Storage/ImportSupport.php @@ -33,7 +33,6 @@ use FireflyIII\Models\Rule; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournalMeta; use FireflyIII\Models\TransactionType; -use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\TransactionRules\Processor; use Illuminate\Database\Query\JoinClause; @@ -45,10 +44,6 @@ use Log; */ trait ImportSupport { - /** @var BillRepositoryInterface */ - protected $billRepository; - /** @var Collection */ - protected $bills; /** @var int */ protected $defaultCurrencyId = 1; /** @var ImportJob */ @@ -84,41 +79,6 @@ trait ImportSupport return true; } - /** - * @param TransactionJournal $journal - * - * @return bool - */ - protected function matchBills(TransactionJournal $journal): bool - { - if (null !== $journal->bill_id) { - Log::debug('Journal is already linked to a bill, will not scan.'); - - return true; - } - if ($this->bills->count() > 0) { - $this->bills->each( - function (Bill $bill) use ($journal) { - Log::debug(sprintf('Going to match bill #%d to journal %d.', $bill->id, $journal->id)); - $this->billRepository->scan($bill, $journal); - } - ); - } - - return true; - } - - /** - * @return Collection - */ - private function getBills(): Collection - { - $set = Bill::where('user_id', $this->job->user->id)->where('active', 1)->where('automatch', 1)->get(['bills.*']); - Log::debug(sprintf('Found %d user bills.', $set->count())); - - return $set; - } - /** * This method finds out what the import journal's currency should be. The account itself * is favoured (and usually it stops there). If no preference is found, the journal has a say diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 14a2965912..75b5dc0921 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -76,12 +76,10 @@ class EventServiceProvider extends ServiceProvider ], // is a Transaction Journal related event. StoredTransactionJournal::class => [ - 'FireflyIII\Handlers\Events\StoredJournalEventHandler@scanBills', 'FireflyIII\Handlers\Events\StoredJournalEventHandler@processRules', ], // is a Transaction Journal related event. UpdatedTransactionJournal::class => [ - 'FireflyIII\Handlers\Events\UpdatedJournalEventHandler@scanBills', 'FireflyIII\Handlers\Events\UpdatedJournalEventHandler@processRules', ], ]; diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index 6401d05819..ddc7e0b358 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -541,52 +541,6 @@ class BillRepository implements BillRepositoryInterface return $start; } - /** - * @param Bill $bill - * @param TransactionJournal $journal - * - * @deprecated - * @return bool - */ - public function scan(Bill $bill, TransactionJournal $journal): bool - { - // Can only support withdrawals. - if (false === $journal->isWithdrawal()) { - return false; - } - - /** @var JournalRepositoryInterface $repos */ - $repos = app(JournalRepositoryInterface::class); - $repos->setUser($this->user); - - $destinationAccounts = $repos->getJournalDestinationAccounts($journal); - $sourceAccounts = $repos->getJournalDestinationAccounts($journal); - $matches = explode(',', $bill->match); - $description = strtolower($journal->description) . ' '; - $description .= strtolower(implode(' ', $destinationAccounts->pluck('name')->toArray())); - $description .= strtolower(implode(' ', $sourceAccounts->pluck('name')->toArray())); - - $wordMatch = $this->doWordMatch($matches, $description); - $amountMatch = $this->doAmountMatch($repos->getJournalTotal($journal), $bill->amount_min, $bill->amount_max); - - // when both, update! - if ($wordMatch && $amountMatch) { - $journal->bill()->associate($bill); - $journal->save(); - - return true; - } - if ($bill->id === $journal->bill_id) { - // if no match, but bill used to match, remove it: - $journal->bill_id = null; - $journal->save(); - - return true; - } - - return false; - } - /** * @param User $user */ diff --git a/app/Repositories/Bill/BillRepositoryInterface.php b/app/Repositories/Bill/BillRepositoryInterface.php index d6cea63eea..bdf1f6f29a 100644 --- a/app/Repositories/Bill/BillRepositoryInterface.php +++ b/app/Repositories/Bill/BillRepositoryInterface.php @@ -196,14 +196,6 @@ interface BillRepositoryInterface */ public function nextExpectedMatch(Bill $bill, Carbon $date): Carbon; - /** - * @param Bill $bill - * @param TransactionJournal $journal - * - * @return bool - */ - public function scan(Bill $bill, TransactionJournal $journal): bool; - /** * @param User $user */ diff --git a/app/Support/Events/BillScanner.php b/app/Support/Events/BillScanner.php deleted file mode 100644 index f07d5d71b6..0000000000 --- a/app/Support/Events/BillScanner.php +++ /dev/null @@ -1,47 +0,0 @@ -. - */ -declare(strict_types=1); - -namespace FireflyIII\Support\Events; - -use FireflyIII\Models\TransactionJournal; -use FireflyIII\Repositories\Bill\BillRepositoryInterface; - -/** - * Class BillScanner. - */ -class BillScanner -{ - /** - * @param TransactionJournal $journal - */ - public static function scan(TransactionJournal $journal) - { - /** @var BillRepositoryInterface $repository */ - $repository = app(BillRepositoryInterface::class); - $list = $journal->user->bills()->where('active', 1)->where('automatch', 1)->get(); - - /** @var \FireflyIII\Models\Bill $bill */ - foreach ($list as $bill) { - $repository->scan($bill, $journal); - } - } -} diff --git a/app/Support/Import/Configuration/File/UploadConfig.php b/app/Support/Import/Configuration/File/UploadConfig.php index 8a0d6dbc07..750e7603d8 100644 --- a/app/Support/Import/Configuration/File/UploadConfig.php +++ b/app/Support/Import/Configuration/File/UploadConfig.php @@ -123,7 +123,6 @@ class UploadConfig implements ConfigurationInterface $config['date-format'] = (string)$data['date_format']; $config['delimiter'] = 'tab' === $delimiter ? "\t" : $delimiter; $config['apply-rules'] = (int)($data['apply_rules'] ?? 0.0) === 1; - $config['match-bills'] = (int)($data['match_bills'] ?? 0.0) === 1; Log::debug('Entered import account.', ['id' => $importId]); diff --git a/resources/views/import/file/upload-config.twig b/resources/views/import/file/upload-config.twig index 68f21d5872..c7bf64435d 100644 --- a/resources/views/import/file/upload-config.twig +++ b/resources/views/import/file/upload-config.twig @@ -55,21 +55,6 @@ -
- - -
-
-
-
-
- {% for type, specific in data.specifics %}