Skip to content

Firefly III: a personal finances manager

Refactor to remove deprecated methods.

James Coled2689311877a
diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.php
index d0b1729589..aba9652544 100644
--- a/app/Helpers/Collector/GroupCollector.php
+++ b/app/Helpers/Collector/GroupCollector.php
@@ -196,24 +196,6 @@ class GroupCollector implements GroupCollectorInterface
return new LengthAwarePaginator($set, $this->total, $this->limit, $this->page);
}
- /**
- * Return the sum of all journals.
- * TODO ignores the currency.
- *
- * @return string
- */
- public function getSum(): string
- {
- $journals = $this->getExtractedJournals();
- $sum = '0';
- /** @var array $journal */
- foreach ($journals as $journal) {
- $amount = (string) $journal['amount'];
- $sum = bcadd($sum, $amount);
- }
-
- return $sum;
- }
/**
* Limit results to a specific currency, either foreign or normal one.
diff --git a/app/Helpers/Collector/GroupCollectorInterface.php b/app/Helpers/Collector/GroupCollectorInterface.php
index 97e8029457..3897f9ab44 100644
--- a/app/Helpers/Collector/GroupCollectorInterface.php
+++ b/app/Helpers/Collector/GroupCollectorInterface.php
@@ -105,13 +105,6 @@ interface GroupCollectorInterface
*/
public function getPaginatedGroups(): LengthAwarePaginator;
- /**
- * Return the sum of all journals.
- *
- * @return string
- */
- public function getSum(): string;
-
/**
* Define which accounts can be part of the source and destination transactions.
*
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index 47afba58a3..69e1c1431d 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -171,14 +171,17 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
if ($cache->has()) {
- return response()->json($cache->get()); // @codeCoverageIgnore
+ return response()->json($cache->get()); // @codeCoverageIgnore
}
$locale = app('steam')->getLocale();
$entries = [];
$amount = $budgetLimit->amount;
$budgetCollection = new Collection([$budget]);
+ $currency = $budgetLimit->transactionCurrency;
while ($start <= $end) {
- $spent = $this->opsRepository->spentInPeriod($budgetCollection, new Collection, $start, $start);
+ $current = clone $start;
+ $expenses = $this->opsRepository->sumExpenses($current, $current, null, $budgetCollection, $currency);
+ $spent = $expenses[(int)$currency->id]['sum'] ?? '0';
$amount = bcadd($amount, $spent);
$format = $start->formatLocalized((string)trans('config.month_and_day', [], $locale));
$entries[$format] = $amount;
diff --git a/app/Repositories/Budget/OperationsRepository.php b/app/Repositories/Budget/OperationsRepository.php
index 7828faa6d1..150bcca996 100644
--- a/app/Repositories/Budget/OperationsRepository.php
+++ b/app/Repositories/Budget/OperationsRepository.php
@@ -74,53 +74,6 @@ class OperationsRepository implements OperationsRepositoryInterface
return $avg;
}
- /**
- * This method collects various info on budgets, used on the budget page and on the index.
- *
- * @param Collection $budgets
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return array
- * @deprecated
- *
- */
- public function collectBudgetInformation(Collection $budgets, Carbon $start, Carbon $end): array
- {
- // get account information
- /** @var AccountRepositoryInterface $accountRepository */
- $accountRepository = app(AccountRepositoryInterface::class);
- $accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
- $defaultCurrency = app('amount')->getDefaultCurrency();
- $return = [];
- /** @var Budget $budget */
- foreach ($budgets as $budget) {
- $budgetId = $budget->id;
- $return[$budgetId] = [
- 'spent' => $this->spentInPeriod(new Collection([$budget]), $accounts, $start, $end),
- 'budgeted' => '0',
- ];
- $budgetLimits = $this->getBudgetLimits($budget, $start, $end);
- $otherLimits = new Collection;
-
- // get all the budget limits relevant between start and end and examine them:
- /** @var BudgetLimit $limit */
- foreach ($budgetLimits as $limit) {
- if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)
- ) {
- $return[$budgetId]['currentLimit'] = $limit;
- $return[$budgetId]['budgeted'] = round($limit->amount, $defaultCurrency->decimal_places);
- continue;
- }
- // otherwise it's just one of the many relevant repetitions:
- $otherLimits->push($limit);
- }
- $return[$budgetId]['otherLimits'] = $otherLimits;
- }
-
- 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.
@@ -260,30 +213,6 @@ class OperationsRepository implements OperationsRepositoryInterface
$this->user = $user;
}
- /**
- * @param Collection $budgets
- * @param Collection $accounts
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return string
- * @deprecated
- */
- public function spentInPeriod(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): string
- {
- /** @var GroupCollectorInterface $collector */
- $collector = app(GroupCollectorInterface::class);
-
- $collector->setUser($this->user);
- $collector->setRange($start, $end)->setBudgets($budgets)->withBudgetInformation();
-
- if ($accounts->count() > 0) {
- $collector->setAccounts($accounts);
- }
-
- return $collector->getSum();
- }
-
/** @noinspection MoreThanThreeArgumentsInspection */
/**
@@ -360,7 +289,8 @@ class OperationsRepository implements OperationsRepositoryInterface
): array
{
Log::debug(sprintf('Now in %s', __METHOD__));
-
+ $start->startOfDay();
+ $end->endOfDay();
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL]);
diff --git a/app/Repositories/Budget/OperationsRepositoryInterface.php b/app/Repositories/Budget/OperationsRepositoryInterface.php
index 458a640d48..4723743664 100644
--- a/app/Repositories/Budget/OperationsRepositoryInterface.php
+++ b/app/Repositories/Budget/OperationsRepositoryInterface.php
@@ -44,17 +44,6 @@ interface OperationsRepositoryInterface
*/
public function budgetedPerDay(Budget $budget): string;
- /**
- * This method collects various info on budgets, used on the budget page and on the index.
- *
- * @param Collection $budgets
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return array
- * @deprecated
- */
- public function collectBudgetInformation(Collection $budgets, Carbon $start, Carbon $end): array;
/**
* @param Collection $budgets
@@ -72,17 +61,6 @@ interface OperationsRepositoryInterface
*/
public function setUser(User $user): void;
- /**
- * @param Collection $budgets
- * @param Collection $accounts
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return string
- * @deprecated
- */
- public function spentInPeriod(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): string;
-
/**
* Return multi-currency spent information.
*
diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php
index 9a4bea8c89..ceb605c5c5 100644
--- a/app/Repositories/Tag/TagRepository.php
+++ b/app/Repositories/Tag/TagRepository.php
@@ -80,24 +80,6 @@ class TagRepository implements TagRepositoryInterface
}
}
- /**
- * @param Tag $tag
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return string
- */
- public function earnedInPeriod(Tag $tag, Carbon $start, Carbon $end): string
- {
- /** @var GroupCollectorInterface $collector */
- $collector = app(GroupCollectorInterface::class);
-
- $collector->setUser($this->user);
- $collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setTag($tag);
-
- return $collector->getSum();
- }
-
/**
* @param Tag $tag
* @param Carbon $start
@@ -297,24 +279,6 @@ class TagRepository implements TagRepositoryInterface
$this->user = $user;
}
- /**
- * @param Tag $tag
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return string
- */
- public function spentInPeriod(Tag $tag, Carbon $start, Carbon $end): string
- {
- /** @var GroupCollectorInterface $collector */
- $collector = app(GroupCollectorInterface::class);
-
- $collector->setUser($this->user);
- $collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setTag($tag);
-
- return $collector->getSum();
- }
-
/**
* @param array $data
*
diff --git a/app/Repositories/Tag/TagRepositoryInterface.php b/app/Repositories/Tag/TagRepositoryInterface.php
index 309b06be5d..caedad9b8f 100644
--- a/app/Repositories/Tag/TagRepositoryInterface.php
+++ b/app/Repositories/Tag/TagRepositoryInterface.php
@@ -60,15 +60,6 @@ interface TagRepositoryInterface
*/
public function destroyAll(): void;
- /**
- * @param Tag $tag
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return string
- */
- public function earnedInPeriod(Tag $tag, Carbon $start, Carbon $end): string;
-
/**
* @param Tag $tag
* @param Carbon $start
@@ -176,15 +167,6 @@ interface TagRepositoryInterface
*/
public function setUser(User $user);
- /**
- * @param Tag $tag
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return string
- */
- public function spentInPeriod(Tag $tag, Carbon $start, Carbon $end): string;
-
/**
* This method stores a tag.
*