First set of code for #956

This commit is contained in:
James Cole
2017-12-01 20:11:29 +01:00
parent 382c5e5760
commit 8a59380c6d
5 changed files with 125 additions and 7 deletions

View File

@@ -38,6 +38,7 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalMeta;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\TransactionRules\Processor;
use Illuminate\Database\Query\JoinClause;
@@ -49,6 +50,10 @@ use Log;
*/
trait ImportSupport
{
/** @var BillRepositoryInterface */
protected $billRepository;
/** @var Collection */
protected $bills;
/** @var int */
protected $defaultCurrencyId = 1;
/** @var ImportJob */
@@ -81,6 +86,29 @@ trait ImportSupport
return true;
}
/**
* @param TransactionJournal $journal
*
* @return bool
*/
protected function matchBills(TransactionJournal $journal): bool
{
if(!is_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;
}
/**
* @param array $parameters
*
@@ -107,6 +135,17 @@ trait ImportSupport
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
@@ -224,7 +263,7 @@ trait ImportSupport
* @param Account $account
*
* @return string
*
*x
* @throws FireflyException
*
* @see ImportSupport::getOpposingAccount()