mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-14 00:04:24 +00:00
Refactor to remove deprecated methods.
This commit is contained in:
@@ -196,24 +196,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
return new LengthAwarePaginator($set, $this->total, $this->limit, $this->page);
|
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.
|
* Limit results to a specific currency, either foreign or normal one.
|
||||||
|
@@ -105,13 +105,6 @@ interface GroupCollectorInterface
|
|||||||
*/
|
*/
|
||||||
public function getPaginatedGroups(): LengthAwarePaginator;
|
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.
|
* Define which accounts can be part of the source and destination transactions.
|
||||||
*
|
*
|
||||||
|
@@ -177,8 +177,11 @@ class BudgetController extends Controller
|
|||||||
$entries = [];
|
$entries = [];
|
||||||
$amount = $budgetLimit->amount;
|
$amount = $budgetLimit->amount;
|
||||||
$budgetCollection = new Collection([$budget]);
|
$budgetCollection = new Collection([$budget]);
|
||||||
|
$currency = $budgetLimit->transactionCurrency;
|
||||||
while ($start <= $end) {
|
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);
|
$amount = bcadd($amount, $spent);
|
||||||
$format = $start->formatLocalized((string)trans('config.month_and_day', [], $locale));
|
$format = $start->formatLocalized((string)trans('config.month_and_day', [], $locale));
|
||||||
$entries[$format] = $amount;
|
$entries[$format] = $amount;
|
||||||
|
@@ -74,53 +74,6 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
return $avg;
|
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
|
* 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.
|
* in both the year/multi-year budget overview AND in the accompanying chart.
|
||||||
@@ -260,30 +213,6 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
$this->user = $user;
|
$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 */
|
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -360,7 +289,8 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
): array
|
): array
|
||||||
{
|
{
|
||||||
Log::debug(sprintf('Now in %s', __METHOD__));
|
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||||
|
$start->startOfDay();
|
||||||
|
$end->endOfDay();
|
||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL]);
|
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL]);
|
||||||
|
@@ -44,17 +44,6 @@ interface OperationsRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function budgetedPerDay(Budget $budget): string;
|
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
|
* @param Collection $budgets
|
||||||
@@ -72,17 +61,6 @@ interface OperationsRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function setUser(User $user): void;
|
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.
|
* Return multi-currency spent information.
|
||||||
*
|
*
|
||||||
|
@@ -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 Tag $tag
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
@@ -297,24 +279,6 @@ class TagRepository implements TagRepositoryInterface
|
|||||||
$this->user = $user;
|
$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
|
* @param array $data
|
||||||
*
|
*
|
||||||
|
@@ -60,15 +60,6 @@ interface TagRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function destroyAll(): void;
|
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 Tag $tag
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
@@ -176,15 +167,6 @@ interface TagRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function setUser(User $user);
|
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.
|
* This method stores a tag.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user