mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-04 05:06:37 +00:00
First set of code for #956
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user