This code makes sure the budget report also includes split expenses.

This commit is contained in:
James Cole
2016-11-26 07:09:02 +01:00
parent 8860378757
commit 28f655dba1
5 changed files with 128 additions and 30 deletions

View File

@@ -154,7 +154,7 @@ class JournalCollector implements JournalCollectorInterface
* @return LengthAwarePaginator
* @throws FireflyException
*/
public function getPaginatedJournals():LengthAwarePaginator
public function getPaginatedJournals(): LengthAwarePaginator
{
if ($this->run === true) {
throw new FireflyException('Cannot getPaginatedJournals after run in JournalCollector.');
@@ -244,6 +244,29 @@ class JournalCollector implements JournalCollectorInterface
return $this;
}
/**
* @param Collection $budgets
*
* @return JournalCollectorInterface
*/
public function setBudgets(Collection $budgets): JournalCollectorInterface
{
$budgetIds = $budgets->pluck('id')->toArray();
if (count($budgetIds) === 0) {
return $this;
}
$this->joinBudgetTables();
$this->query->where(
function (EloquentBuilder $q) use ($budgetIds) {
$q->whereIn('budget_transaction.budget_id', $budgetIds);
$q->orWhereIn('budget_transaction_journal.budget_id', $budgetIds);
}
);
return $this;
}
/**
* @param Collection $categories
*
@@ -259,10 +282,8 @@ class JournalCollector implements JournalCollectorInterface
$this->query->where(
function (EloquentBuilder $q) use ($categoryIds) {
if (count($categoryIds) > 0) {
$q->whereIn('category_transaction.category_id', $categoryIds);
$q->orWhereIn('category_transaction_journal.category_id', $categoryIds);
}
$q->whereIn('category_transaction.category_id', $categoryIds);
$q->orWhereIn('category_transaction_journal.category_id', $categoryIds);
}
);

View File

@@ -74,6 +74,14 @@ interface JournalCollectorInterface
*/
public function setBudget(Budget $budget): JournalCollectorInterface;
/**
* @param Collection $budgets
*
* @return JournalCollectorInterface
*/
public function setBudgets(Collection $budgets): JournalCollectorInterface;
/**
* @param Collection $categories
*