diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index 7000f133bd..1c88094adc 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -405,7 +405,7 @@ class BudgetController extends Controller return response()->json($cache->get()); // @codeCoverageIgnore } $periods = app('navigation')->listOfPeriods($start, $end); - $entries = $this->repository->getBudgetPeriodReport(new Collection([$budget]), $accounts, $start, $end); // get the expenses + $entries = $this->opsRepository->getBudgetPeriodReport(new Collection([$budget]), $accounts, $start, $end); // get the expenses $budgeted = $this->getBudgetedInPeriod($budget, $start, $end); // join them into one set of data: diff --git a/app/Http/Controllers/Report/BudgetController.php b/app/Http/Controllers/Report/BudgetController.php index 38aa085ebd..825883d785 100644 --- a/app/Http/Controllers/Report/BudgetController.php +++ b/app/Http/Controllers/Report/BudgetController.php @@ -26,6 +26,7 @@ use Carbon\Carbon; use FireflyIII\Helpers\Report\BudgetReportHelperInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; +use FireflyIII\Repositories\Budget\OperationsRepositoryInterface; use FireflyIII\Support\CacheProperties; use FireflyIII\Support\Http\Controllers\BasicDataSupport; use Illuminate\Support\Collection; @@ -98,8 +99,13 @@ class BudgetController extends Controller // generate budget report right here. /** @var BudgetRepositoryInterface $repository */ $repository = app(BudgetRepositoryInterface::class); + + /** @var OperationsRepositoryInterface $opsRepository */ + $opsRepository= app(OperationsRepositoryInterface::class); + + $budgets = $repository->getBudgets(); - $data = $repository->getBudgetPeriodReport($budgets, $accounts, $start, $end); + $data = $opsRepository->getBudgetPeriodReport($budgets, $accounts, $start, $end); $noBudget = $repository->getNoBudgetPeriodReport($accounts, $start, $end); // append report data for "no budget" $data = array_merge($data, $noBudget); $report = $this->filterPeriodReport($data); diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 5828d259e4..8908bdfedd 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -206,57 +206,6 @@ class BudgetRepository implements BudgetRepositoryInterface return $set; } - /** - * This method is being used to generate the budget overview in the year/multi-year report. Its used - * in both the year/multi-year budget overview AND in the accompanying chart. - * - * @param Collection $budgets - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end - * - * @return array - */ - public function getBudgetPeriodReport(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): array - { - $carbonFormat = Navigation::preferredCarbonFormat($start, $end); - $data = []; - - - // get all transactions: - /** @var GroupCollectorInterface $collector */ - $collector = app(GroupCollectorInterface::class); - $collector->setAccounts($accounts)->setRange($start, $end); - $collector->setBudgets($budgets); - $journals = $collector->getExtractedJournals(); - - // loop transactions: - /** @var array $journal */ - foreach ($journals as $journal) { - // prep data array for currency: - $budgetId = (int)$journal['budget_id']; - $budgetName = $journal['budget_name']; - $currencyId = (int)$journal['currency_id']; - $key = sprintf('%d-%d', $budgetId, $currencyId); - - $data[$key] = $data[$key] ?? [ - 'id' => $budgetId, - 'name' => sprintf('%s (%s)', $budgetName, $journal['currency_name']), - 'sum' => '0', - 'currency_id' => $currencyId, - 'currency_code' => $journal['currency_code'], - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - 'entries' => [], - ]; - $date = $journal['date']->format($carbonFormat); - $data[$key]['entries'][$date] = bcadd($data[$budgetId]['entries'][$date] ?? '0', $journal['amount']); - } - - return $data; - } - /** * @return Collection */ diff --git a/app/Repositories/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.php index dc23f42d0e..ebbf27e04d 100644 --- a/app/Repositories/Budget/BudgetRepositoryInterface.php +++ b/app/Repositories/Budget/BudgetRepositoryInterface.php @@ -88,17 +88,6 @@ interface BudgetRepositoryInterface */ public function getActiveBudgets(): Collection; - /** - * @param Collection $budgets - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end - * - * @return array - * @deprecated - */ - public function getBudgetPeriodReport(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): array; - /** * @return Collection */ @@ -113,7 +102,6 @@ interface BudgetRepositoryInterface */ public function getByIds(array $budgetIds): Collection; - /** * @return Collection */ diff --git a/app/Repositories/Budget/OperationsRepository.php b/app/Repositories/Budget/OperationsRepository.php index 639f38e2ee..b811203819 100644 --- a/app/Repositories/Budget/OperationsRepository.php +++ b/app/Repositories/Budget/OperationsRepository.php @@ -132,6 +132,58 @@ class OperationsRepository implements OperationsRepositoryInterface return $return; } + /** + * This method is being used to generate the budget overview in the year/multi-year report. Its used + * in both the year/multi-year budget overview AND in the accompanying chart. + * + * @param Collection $budgets + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end + * + * @return array + * @deprecated + */ + public function getBudgetPeriodReport(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): array + { + $carbonFormat = app('navigation')->preferredCarbonFormat($start, $end); + $data = []; + + + // get all transactions: + /** @var GroupCollectorInterface $collector */ + $collector = app(GroupCollectorInterface::class); + $collector->setAccounts($accounts)->setRange($start, $end); + $collector->setBudgets($budgets); + $journals = $collector->getExtractedJournals(); + + // loop transactions: + /** @var array $journal */ + foreach ($journals as $journal) { + // prep data array for currency: + $budgetId = (int)$journal['budget_id']; + $budgetName = $journal['budget_name']; + $currencyId = (int)$journal['currency_id']; + $key = sprintf('%d-%d', $budgetId, $currencyId); + + $data[$key] = $data[$key] ?? [ + 'id' => $budgetId, + 'name' => sprintf('%s (%s)', $budgetName, $journal['currency_name']), + 'sum' => '0', + 'currency_id' => $currencyId, + 'currency_code' => $journal['currency_code'], + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + 'entries' => [], + ]; + $date = $journal['date']->format($carbonFormat); + $data[$key]['entries'][$date] = bcadd($data[$budgetId]['entries'][$date] ?? '0', $journal['amount']); + } + + return $data; + } + /** * @param User $user */ diff --git a/app/Repositories/Budget/OperationsRepositoryInterface.php b/app/Repositories/Budget/OperationsRepositoryInterface.php index f4e4fc2356..246a1a78ad 100644 --- a/app/Repositories/Budget/OperationsRepositoryInterface.php +++ b/app/Repositories/Budget/OperationsRepositoryInterface.php @@ -56,6 +56,17 @@ interface OperationsRepositoryInterface */ public function collectBudgetInformation(Collection $budgets, Carbon $start, Carbon $end): array; + /** + * @param Collection $budgets + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end + * + * @return array + * @deprecated + */ + public function getBudgetPeriodReport(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): array; + /** * @param User $user */