Skip to content

Firefly III: a personal finances manager

More exact search for available budgets. #7853

James Colef67ff98d7850
diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php
index 53a6cc23b8..f6cc57bfa1 100644
--- a/app/Http/Controllers/Json/BoxController.php
+++ b/app/Http/Controllers/Json/BoxController.php
@@ -82,7 +82,7 @@ class BoxController extends Controller
$currency = app('amount')->getDefaultCurrency();
app('log')->debug(sprintf('Default currency is %s', $currency->code));
- $availableBudgets = $abRepository->getAvailableBudgetsByDate($start, $end);
+ $availableBudgets = $abRepository->getAvailableBudgetsByExactDate($start, $end);
app('log')->debug(sprintf('Found %d available budget(s)', $availableBudgets->count()));
$availableBudgets = $availableBudgets->filter(
static function (AvailableBudget $availableBudget) use ($currency) {
diff --git a/app/Repositories/Budget/AvailableBudgetRepository.php b/app/Repositories/Budget/AvailableBudgetRepository.php
index bc551c37d4..86ef18f8c4 100644
--- a/app/Repositories/Budget/AvailableBudgetRepository.php
+++ b/app/Repositories/Budget/AvailableBudgetRepository.php
@@ -200,6 +200,23 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
return $query->get();
}
+ /**
+ * Returns all available budget objects.
+ *
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ *
+ */
+ public function getAvailableBudgetsByExactDate(Carbon $start, Carbon $end): Collection
+ {
+ return $this->user->availableBudgets()
+ ->where('start_date', '=', $start->format('Y-m-d'))
+ ->where('end_date', '=', $end->format('Y-m-d'))
+ ->get();
+ }
+
/**
* @inheritDoc
*/
diff --git a/app/Repositories/Budget/AvailableBudgetRepositoryInterface.php b/app/Repositories/Budget/AvailableBudgetRepositoryInterface.php
index dcc0be4e7c..fd2c004e6e 100644
--- a/app/Repositories/Budget/AvailableBudgetRepositoryInterface.php
+++ b/app/Repositories/Budget/AvailableBudgetRepositoryInterface.php
@@ -116,6 +116,14 @@ interface AvailableBudgetRepositoryInterface
*/
public function getAvailableBudgetsByDate(?Carbon $start, ?Carbon $end): Collection;
+ /**
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function getAvailableBudgetsByExactDate(Carbon $start, Carbon $end): Collection;
+
/**
* Get by transaction currency and date. Should always result in one entry or NULL.
*