This commit is contained in:
James Cole 2016-03-12 07:44:20 +01:00
parent 4cded0bf57
commit 1aea4045a3
4 changed files with 11 additions and 7 deletions

View File

@ -97,7 +97,7 @@ class BudgetReportHelper implements BudgetReportHelperInterface
} }
// stuff outside of budgets: // stuff outside of budgets:
$noBudget = $repository->getWithoutBudgetSum($start, $end); $noBudget = $repository->getWithoutBudgetSum($accounts, $start, $end);
$budgetLine = new BudgetLine; $budgetLine = new BudgetLine;
$budgetLine->setOverspent($noBudget); $budgetLine->setOverspent($noBudget);
$budgetLine->setSpent($noBudget); $budgetLine->setSpent($noBudget);

View File

@ -200,7 +200,7 @@ class BudgetController extends Controller
$allEntries->push([$name, $left, $spent, $overspent, $amount, $expenses]); $allEntries->push([$name, $left, $spent, $overspent, $amount, $expenses]);
} }
$noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end); $noBudgetExpenses = $repository->getWithoutBudgetSum($accounts, $start, $end);
$allEntries->push([trans('firefly.noBudget'), '0', '0', $noBudgetExpenses, '0', '0']); $allEntries->push([trans('firefly.noBudget'), '0', '0', $noBudgetExpenses, '0', '0']);
$data = $this->generator->frontpage($allEntries); $data = $this->generator->frontpage($allEntries);
$cache->store($data); $cache->store($data);
@ -266,7 +266,7 @@ class BudgetController extends Controller
// this might be a good moment to collect no budget stuff. // this might be a good moment to collect no budget stuff.
if (is_null($budget->id)) { if (is_null($budget->id)) {
// get without budget sum in range: // get without budget sum in range:
$spent = $repository->getWithoutBudgetSum($currentStart, $currentEnd) * -1; $spent = $repository->getWithoutBudgetSum($accounts, $currentStart, $currentEnd) * -1;
} else { } else {
if (isset($set[$id]['entries'][$year])) { if (isset($set[$id]['entries'][$year])) {
$spent = $set[$id]['entries'][$year] * -1; $spent = $set[$id]['entries'][$year] * -1;

View File

@ -472,13 +472,15 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
} }
/** /**
* @param Carbon $start * @param Collection $accounts
* @param Carbon $end * @param Carbon $start
* @param Carbon $end
* *
* @return string * @return string
*/ */
public function getWithoutBudgetSum(Carbon $start, Carbon $end): string public function getWithoutBudgetSum(Collection $accounts, Carbon $start, Carbon $end): string
{ {
$ids = $accounts->pluck('id')->toArray();
$entry = $this->user $entry = $this->user
->transactionjournals() ->transactionjournals()
->whereNotIn( ->whereNotIn(
@ -499,6 +501,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0); $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0);
} }
) )
->whereIn('transactions.account_id', $ids)
->transactionTypes([TransactionType::WITHDRAWAL]) ->transactionTypes([TransactionType::WITHDRAWAL])
->first([DB::raw('SUM(`transactions`.`amount`) as `journalAmount`')]); ->first([DB::raw('SUM(`transactions`.`amount`) as `journalAmount`')]);
if (is_null($entry->journalAmount)) { if (is_null($entry->journalAmount)) {

View File

@ -168,12 +168,13 @@ interface BudgetRepositoryInterface
public function getWithoutBudget(Carbon $start, Carbon $end); public function getWithoutBudget(Carbon $start, Carbon $end);
/** /**
* @param Collection $accounts
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* *
* @return string * @return string
*/ */
public function getWithoutBudgetSum(Carbon $start, Carbon $end): string; public function getWithoutBudgetSum(Collection $accounts, Carbon $start, Carbon $end): string;
/** /**
* Returns an array with the following key:value pairs: * Returns an array with the following key:value pairs: