diff --git a/app/Models/Budget.php b/app/Models/Budget.php index d2e421bf0b..666f367aa1 100644 --- a/app/Models/Budget.php +++ b/app/Models/Budget.php @@ -46,11 +46,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property Carbon created_at * @property Carbon updated_at * @property User $user - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at * @property \Illuminate\Support\Carbon|null $deleted_at - * @property bool $encrypted - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\BudgetLimit[] $budgetlimits * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionJournals * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Transaction[] $transactions * @method static bool|null forceDelete() diff --git a/app/Repositories/Budget/BudgetLimitRepository.php b/app/Repositories/Budget/BudgetLimitRepository.php index 6d23f66a9e..3dfdec3e40 100644 --- a/app/Repositories/Budget/BudgetLimitRepository.php +++ b/app/Repositories/Budget/BudgetLimitRepository.php @@ -69,12 +69,15 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface public function budgeted(Carbon $start, Carbon $end, TransactionCurrency $currency, ?Collection $budgets = null): string { $query = BudgetLimit - ::where('start_date', $start->format('Y-m-d 00:00:00')) - ->where('end_date', $end->format('Y-m-d 00:00:00')) - ->where('transaction_currency_id', $currency->id); + ::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') + ->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00')) + ->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00')) + ->where('budget_limits.transaction_currency_id', $currency->id) + ->where('budgets.user_id', $this->user->id); if (null !== $budgets && $budgets->count() > 0) { - $query->whereIn('budget_id', $budgets->pluck('id')->toArray()); + $query->whereIn('budget_limits.budget_id', $budgets->pluck('id')->toArray()); } + $set = $query->get(['budget_limits.*']); $result = '0'; /** @var BudgetLimit $budgetLimit */