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\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
use FireflyIII\Models\LimitRepetition;
|
use FireflyIII\Models\LimitRepetition;
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
@@ -273,9 +274,19 @@ class BudgetController extends Controller
|
|||||||
$currentEnd = Navigation::endOfPeriod($currentStart, $viewRange);
|
$currentEnd = Navigation::endOfPeriod($currentStart, $viewRange);
|
||||||
|
|
||||||
// get all budget limits and their repetitions.
|
// get all budget limits and their repetitions.
|
||||||
$reps = $repository->getAllBudgetLimitRepetitions($currentStart, $currentEnd);
|
$reps = $repository->getAllBudgetLimitRepetitions($currentStart, $currentEnd, $budget);
|
||||||
$budgeted = $reps->sum('amount');
|
$budgeted = $reps->sum('amount');
|
||||||
$perBudget = $repository->spentPerBudgetPerAccount(new Collection([$budget]), $accounts, $currentStart, $currentEnd);
|
$perBudget = $repository->spentPerBudgetPerAccount(new Collection([$budget]), $accounts, $currentStart, $currentEnd);
|
||||||
|
// 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');
|
$spent = $perBudget->sum('spent');
|
||||||
|
|
||||||
$entry = [
|
$entry = [
|
||||||
|
@@ -146,19 +146,26 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
/**
|
/**
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
|
* @param Budget $budget
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getAllBudgetLimitRepetitions(Carbon $start, Carbon $end): Collection
|
public function getAllBudgetLimitRepetitions(Carbon $start, Carbon $end, Budget $budget = null): Collection
|
||||||
{
|
{
|
||||||
/** @var Collection $repetitions */
|
$query = LimitRepetition::
|
||||||
return LimitRepetition::
|
|
||||||
leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
|
leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
|
||||||
->leftJoin('budgets', 'budgets.id', '=', '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', '<=', $end->format('Y-m-d 00:00:00'))
|
||||||
->where('limit_repetitions.startdate', '>=', $start->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)
|
->where('budgets.user_id', $this->user->id);
|
||||||
->get(['limit_repetitions.*', 'budget_limits.budget_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 $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
|
* @param Budget $budget
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getAllBudgetLimitRepetitions(Carbon $start, Carbon $end): Collection;
|
public function getAllBudgetLimitRepetitions(Carbon $start, Carbon $end, Budget $budget = null): Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
|
Reference in New Issue
Block a user