mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Move collecting journals to the collector.
This commit is contained in:
parent
aeca2ef3b2
commit
43afdb021a
@ -206,6 +206,22 @@ class JournalCollector
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $bills
|
||||||
|
*
|
||||||
|
* @return JournalCollector
|
||||||
|
*/
|
||||||
|
public function setBills(Collection $bills): JournalCollector
|
||||||
|
{
|
||||||
|
if ($bills->count() > 0) {
|
||||||
|
$billIds = $bills->pluck('id')->toArray();
|
||||||
|
$this->query->whereIn('transaction_journals.bill_id', $billIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Category $category
|
* @param Category $category
|
||||||
*
|
*
|
||||||
|
@ -14,17 +14,17 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Helpers\Report;
|
namespace FireflyIII\Helpers\Report;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DB;
|
|
||||||
use FireflyIII\Helpers\Collection\Bill as BillCollection;
|
use FireflyIII\Helpers\Collection\Bill as BillCollection;
|
||||||
use FireflyIII\Helpers\Collection\BillLine;
|
use FireflyIII\Helpers\Collection\BillLine;
|
||||||
use FireflyIII\Helpers\Collection\Category as CategoryCollection;
|
use FireflyIII\Helpers\Collection\Category as CategoryCollection;
|
||||||
use FireflyIII\Helpers\Collection\Expense;
|
use FireflyIII\Helpers\Collection\Expense;
|
||||||
use FireflyIII\Helpers\Collection\Income;
|
use FireflyIII\Helpers\Collection\Income;
|
||||||
|
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||||
use FireflyIII\Helpers\FiscalHelperInterface;
|
use FireflyIII\Helpers\FiscalHelperInterface;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\Budget;
|
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
@ -79,7 +79,9 @@ class ReportHelper implements ReportHelperInterface
|
|||||||
/** @var BillRepositoryInterface $repository */
|
/** @var BillRepositoryInterface $repository */
|
||||||
$repository = app(BillRepositoryInterface::class);
|
$repository = app(BillRepositoryInterface::class);
|
||||||
$bills = $repository->getBillsForAccounts($accounts);
|
$bills = $repository->getBillsForAccounts($accounts);
|
||||||
$journals = $repository->getAllJournalsInRange($bills, $start, $end);
|
$collector = new JournalCollector(auth()->user());
|
||||||
|
$collector->setAccounts($accounts)->setRange($start, $end)->setBills($bills);
|
||||||
|
$journals = $collector->getJournals();
|
||||||
$collection = new BillCollection;
|
$collection = new BillCollection;
|
||||||
|
|
||||||
/** @var Bill $bill */
|
/** @var Bill $bill */
|
||||||
@ -93,14 +95,14 @@ class ReportHelper implements ReportHelperInterface
|
|||||||
// is hit in period?
|
// is hit in period?
|
||||||
|
|
||||||
$entry = $journals->filter(
|
$entry = $journals->filter(
|
||||||
function (TransactionJournal $journal) use ($bill) {
|
function (Transaction $transaction) use ($bill) {
|
||||||
return $journal->bill_id === $bill->id;
|
return $transaction->bill_id === $bill->id;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$first = $entry->first();
|
$first = $entry->first();
|
||||||
if (!is_null($first)) {
|
if (!is_null($first)) {
|
||||||
$billLine->setTransactionJournalId($first->id);
|
$billLine->setTransactionJournalId($first->id);
|
||||||
$billLine->setAmount($first->journalAmount);
|
$billLine->setAmount($first->transaction_amount);
|
||||||
$billLine->setHit(true);
|
$billLine->setHit(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,41 +116,6 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
return $set;
|
return $set;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all journals connected to these bills in the given range. Amount paid
|
|
||||||
* is stored in "journalAmount" as a negative number.
|
|
||||||
*
|
|
||||||
* @param Collection $bills
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getAllJournalsInRange(Collection $bills, Carbon $start, Carbon $end): Collection
|
|
||||||
{
|
|
||||||
$ids = $bills->pluck('id')->toArray();
|
|
||||||
|
|
||||||
$set = $this->user->transactionJournals()
|
|
||||||
->leftJoin(
|
|
||||||
'transactions', function (JoinClause $join) {
|
|
||||||
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
->whereIn('bill_id', $ids)
|
|
||||||
->before($end)
|
|
||||||
->after($start)
|
|
||||||
->groupBy(['transaction_journals.bill_id', 'transaction_journals.id'])
|
|
||||||
->get(
|
|
||||||
[
|
|
||||||
'transaction_journals.bill_id',
|
|
||||||
'transaction_journals.id',
|
|
||||||
DB::raw('SUM(transactions.amount) AS journalAmount'),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
return $set;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
|
@ -57,18 +57,6 @@ interface BillRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getActiveBills(): Collection;
|
public function getActiveBills(): Collection;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all journals connected to these bills in the given range. Amount paid
|
|
||||||
* is stored in "journalAmount" as a negative number.
|
|
||||||
*
|
|
||||||
* @param Collection $bills
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getAllJournalsInRange(Collection $bills, Carbon $start, Carbon $end): Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user