Remove references to bill scanning.

This commit is contained in:
James Cole
2018-04-14 13:00:24 +02:00
parent d8a00f4314
commit 926c03986c
13 changed files with 1 additions and 217 deletions

View File

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

View File

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

View File

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

View File

@@ -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 */

View File

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

View File

@@ -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(

View File

@@ -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

View File

@@ -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',
],
];

View File

@@ -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
*/

View File

@@ -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
*/

View File

@@ -1,47 +0,0 @@
<?php
/**
* BillScanner.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\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);
}
}
}

View File

@@ -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]);

View File

@@ -55,21 +55,6 @@
</div>
</div>
</div>
<div class="form-group">
<label for="match_bills_label" class="col-sm-4 control-label">
{{ trans('import.file_match_bills_title') }}
</label>
<div class="col-sm-8">
<div class="checkbox"><label>
{{ Form.checkbox('match_bills', '1',
job.configuration['match-bills'] == true, {'id': 'match_bills_label'}) }}
{{ trans('import.file_match_bills_description') }}
</label>
</div>
</div>
</div>
{% for type, specific in data.specifics %}
<div class="form-group">
<label for="{{ type }}_label" class="col-sm-4 control-label">