mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Code cleanup.
This commit is contained in:
@@ -78,15 +78,33 @@ class FrontpageChartGenerator
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function setEnd(Carbon $end): void
|
||||
{
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
public function setStart(Carbon $start): void
|
||||
{
|
||||
$this->start = $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic setter for the user. Also updates the repositories with the right user.
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->budgetRepository->setUser($user);
|
||||
$this->blRepository->setUser($user);
|
||||
$this->opsRepository->setUser($user);
|
||||
|
||||
$locale = app('steam')->getLocale();
|
||||
$this->monthAndDayFormat = (string)trans('config.month_and_day_js', [], $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* For each budget, gets all budget limits for the current time range.
|
||||
* When no limits are present, the time range is used to collect information on money spent.
|
||||
* If limits are present, each limit is processed individually.
|
||||
*
|
||||
* @param array $data
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function processBudget(array $data, Budget $budget): array
|
||||
{
|
||||
@@ -104,15 +122,11 @@ class FrontpageChartGenerator
|
||||
/**
|
||||
* When no limits are present, the expenses of the whole period are collected and grouped.
|
||||
* This is grouped per currency. Because there is no limit set, "left to spend" and "overspent" are empty.
|
||||
*
|
||||
* @param array $data
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function noBudgetLimits(array $data, Budget $budget): array
|
||||
{
|
||||
$spent = $this->opsRepository->sumExpenses($this->start, $this->end, null, new Collection([$budget]));
|
||||
|
||||
/** @var array $entry */
|
||||
foreach ($spent as $entry) {
|
||||
$title = sprintf('%s (%s)', $budget->name, $entry['currency_name']);
|
||||
@@ -126,12 +140,6 @@ class FrontpageChartGenerator
|
||||
|
||||
/**
|
||||
* If a budget has budget limit, each limit is processed individually.
|
||||
*
|
||||
* @param array $data
|
||||
* @param Budget $budget
|
||||
* @param Collection $limits
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function budgetLimits(array $data, Budget $budget, Collection $limits): array
|
||||
{
|
||||
@@ -146,16 +154,11 @@ class FrontpageChartGenerator
|
||||
/**
|
||||
* For each limit, the expenses from the time range of the limit are collected. Each row from the result is
|
||||
* processed individually.
|
||||
*
|
||||
* @param array $data
|
||||
* @param Budget $budget
|
||||
* @param BudgetLimit $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function processLimit(array $data, Budget $budget, BudgetLimit $limit): array
|
||||
{
|
||||
$spent = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, null, new Collection([$budget]), $limit->transactionCurrency);
|
||||
|
||||
/** @var array $entry */
|
||||
foreach ($spent as $entry) {
|
||||
// only spent the entry where the entry's currency matches the budget limit's currency
|
||||
@@ -172,13 +175,6 @@ class FrontpageChartGenerator
|
||||
*
|
||||
* Each one is added to the $data array. If the limit's date range is different from the global $start and $end
|
||||
* dates, for example when a limit only partially falls into this month, the title is expanded to clarify.
|
||||
*
|
||||
* @param array $data
|
||||
* @param Budget $budget
|
||||
* @param BudgetLimit $limit
|
||||
* @param array $entry
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function processRow(array $data, Budget $budget, BudgetLimit $limit, array $entry): array
|
||||
{
|
||||
@@ -200,35 +196,4 @@ class FrontpageChartGenerator
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $end
|
||||
*/
|
||||
public function setEnd(Carbon $end): void
|
||||
{
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
*/
|
||||
public function setStart(Carbon $start): void
|
||||
{
|
||||
$this->start = $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic setter for the user. Also updates the repositories with the right user.
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->budgetRepository->setUser($user);
|
||||
$this->blRepository->setUser($user);
|
||||
$this->opsRepository->setUser($user);
|
||||
|
||||
$locale = app('steam')->getLocale();
|
||||
$this->monthAndDayFormat = (string)trans('config.month_and_day_js', [], $locale);
|
||||
}
|
||||
}
|
||||
|
@@ -51,9 +51,6 @@ class FrontpageChartGenerator
|
||||
|
||||
/**
|
||||
* FrontpageChartGenerator constructor.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*/
|
||||
public function __construct(Carbon $start, Carbon $end)
|
||||
{
|
||||
@@ -66,9 +63,6 @@ class FrontpageChartGenerator
|
||||
$this->noCatRepos = app(NoCategoryRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function generate(): array
|
||||
{
|
||||
$categories = $this->repository->getCategories();
|
||||
@@ -78,6 +72,7 @@ class FrontpageChartGenerator
|
||||
|
||||
// get expenses + income per category:
|
||||
$collection = [];
|
||||
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
// get expenses
|
||||
@@ -98,12 +93,6 @@ class FrontpageChartGenerator
|
||||
return $this->insertValues($currencyData, $tempData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function collectExpenses(Category $category, Collection $accounts): array
|
||||
{
|
||||
$spent = $this->opsRepos->sumExpenses($this->start, $this->end, $accounts, new Collection([$category]));
|
||||
@@ -121,9 +110,6 @@ class FrontpageChartGenerator
|
||||
return $tempData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $currency
|
||||
*/
|
||||
private function addCurrency(array $currency): void
|
||||
{
|
||||
$currencyId = (int)$currency['currency_id'];
|
||||
@@ -137,11 +123,6 @@ class FrontpageChartGenerator
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function collectNoCatExpenses(Collection $accounts): array
|
||||
{
|
||||
$noCatExp = $this->noCatRepos->sumExpenses($this->start, $this->end, $accounts);
|
||||
@@ -159,15 +140,11 @@ class FrontpageChartGenerator
|
||||
return $tempData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function createCurrencyGroups(array $data): array
|
||||
{
|
||||
$return = [];
|
||||
$names = $this->expandNames($data);
|
||||
|
||||
/**
|
||||
* @var array $currency
|
||||
*/
|
||||
@@ -184,12 +161,6 @@ class FrontpageChartGenerator
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $currencyData
|
||||
* @param array $monetaryData
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function insertValues(array $currencyData, array $monetaryData): array
|
||||
{
|
||||
/** @var array $array */
|
||||
|
@@ -35,13 +35,6 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
class WholePeriodChartGenerator
|
||||
{
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function generate(Category $category, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$collection = new Collection([$category]);
|
||||
@@ -116,11 +109,6 @@ class WholePeriodChartGenerator
|
||||
|
||||
/**
|
||||
* TODO this method is duplicated
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function calculateStep(Carbon $start, Carbon $end): string
|
||||
{
|
||||
@@ -142,10 +130,6 @@ class WholePeriodChartGenerator
|
||||
/**
|
||||
* Loop array of spent/earned info, and extract which currencies are present.
|
||||
* Key is the currency ID.
|
||||
*
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function extractCurrencies(array $array): array
|
||||
{
|
||||
|
Reference in New Issue
Block a user