mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Fixed budget charts.
This commit is contained in:
@@ -7,6 +7,7 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
@@ -273,10 +274,20 @@ class BudgetController extends Controller
|
||||
$currentEnd = Navigation::endOfPeriod($currentStart, $viewRange);
|
||||
|
||||
// get all budget limits and their repetitions.
|
||||
$reps = $repository->getAllBudgetLimitRepetitions($currentStart, $currentEnd);
|
||||
$reps = $repository->getAllBudgetLimitRepetitions($currentStart, $currentEnd, $budget);
|
||||
$budgeted = $reps->sum('amount');
|
||||
$perBudget = $repository->spentPerBudgetPerAccount(new Collection([$budget]), $accounts, $currentStart, $currentEnd);
|
||||
$spent = $perBudget->sum('spent');
|
||||
// includes null, so filter!
|
||||
$perBudget = $perBudget->filter(
|
||||
function (TransactionJournal $journal) use ($budget) {
|
||||
if (intval($journal->budget_id) === $budget->id) {
|
||||
return $journal;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
$spent = $perBudget->sum('spent');
|
||||
|
||||
$entry = [
|
||||
'date' => clone $currentStart,
|
||||
|
@@ -146,19 +146,26 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllBudgetLimitRepetitions(Carbon $start, Carbon $end): Collection
|
||||
public function getAllBudgetLimitRepetitions(Carbon $start, Carbon $end, Budget $budget = null): Collection
|
||||
{
|
||||
/** @var Collection $repetitions */
|
||||
return LimitRepetition::
|
||||
$query = LimitRepetition::
|
||||
leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
|
||||
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
||||
->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00'))
|
||||
->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00'))
|
||||
->where('budgets.user_id', $this->user->id)
|
||||
->get(['limit_repetitions.*', 'budget_limits.budget_id']);
|
||||
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
||||
->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00'))
|
||||
->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00'))
|
||||
->where('budgets.user_id', $this->user->id);
|
||||
|
||||
if (!is_null($budget)) {
|
||||
$query->where('budgets.id', $budget->id);
|
||||
}
|
||||
|
||||
$set = $query->get(['limit_repetitions.*', 'budget_limits.budget_id']);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -78,10 +78,11 @@ interface BudgetRepositoryInterface
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllBudgetLimitRepetitions(Carbon $start, Carbon $end): Collection;
|
||||
public function getAllBudgetLimitRepetitions(Carbon $start, Carbon $end, Budget $budget = null): Collection;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
|
Reference in New Issue
Block a user