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