mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fine tuning. [skip ci]
This commit is contained in:
@@ -123,7 +123,7 @@ class BudgetReportHelper implements BudgetReportHelperInterface
|
||||
$set = new Collection;
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$expenses = $repository->getExpensesPerDay($budget, $start, $end);
|
||||
$expenses = $repository->getExpensesPerDay($budget, $start, $end, $accounts);
|
||||
$total = strval($expenses->sum('dailyAmount'));
|
||||
if (bccomp($total, '0') === -1) {
|
||||
$set->push($budget);
|
||||
|
@@ -447,26 +447,32 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
||||
* Returns the expenses for this budget grouped per day, with the date
|
||||
* in "date" (a string, not a Carbon) and the amount in "dailyAmount".
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getExpensesPerDay(Budget $budget, Carbon $start, Carbon $end): Collection
|
||||
public function getExpensesPerDay(Budget $budget, Carbon $start, Carbon $end, Collection $accounts = null): Collection
|
||||
{
|
||||
$set = $this->user->budgets()
|
||||
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.budget_id', '=', 'budgets.id')
|
||||
->leftJoin('transaction_journals', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
||||
->where('budgets.id', $budget->id)
|
||||
->where('transactions.amount', '<', 0)
|
||||
->groupBy('transaction_journals.date')
|
||||
->orderBy('transaction_journals.date')
|
||||
->get(['transaction_journals.date', DB::raw('SUM(`transactions`.`amount`) as `dailyAmount`')]);
|
||||
$query = $this->user->budgets()
|
||||
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.budget_id', '=', 'budgets.id')
|
||||
->leftJoin('transaction_journals', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
||||
->where('budgets.id', $budget->id)
|
||||
->where('transactions.amount', '<', 0)
|
||||
->groupBy('transaction_journals.date')
|
||||
->orderBy('transaction_journals.date');
|
||||
if (!is_null($accounts) && $accounts->count() > 0) {
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$query->whereIn('transactions.account_id', $ids);
|
||||
}
|
||||
$set
|
||||
= $query->get(['transaction_journals.date', DB::raw('SUM(`transactions`.`amount`) as `dailyAmount`')]);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
@@ -170,13 +170,14 @@ interface BudgetRepositoryInterface
|
||||
* Returns the expenses for this budget grouped per day, with the date
|
||||
* in "date" (a string, not a Carbon) and the amount in "dailyAmount".
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getExpensesPerDay(Budget $budget, Carbon $start, Carbon $end):Collection;
|
||||
public function getExpensesPerDay(Budget $budget, Carbon $start, Carbon $end, Collection $accounts = null) : Collection;
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
|
Reference in New Issue
Block a user