Code cleanup

This commit is contained in:
James Cole
2021-03-21 09:15:40 +01:00
parent da1751940e
commit 206845575c
317 changed files with 7418 additions and 7362 deletions

View File

@@ -37,13 +37,13 @@ use Illuminate\Support\Collection;
*/
class FrontpageChartGenerator
{
private User $user;
private Carbon $start;
private Carbon $end;
private BudgetRepositoryInterface $budgetRepository;
private BudgetLimitRepositoryInterface $blRepository;
protected OperationsRepositoryInterface $opsRepository;
private BudgetLimitRepositoryInterface $blRepository;
private BudgetRepositoryInterface $budgetRepository;
private Carbon $end;
private string $monthAndDayFormat;
private Carbon $start;
private User $user;
/**
* FrontpageChartGenerator constructor.
@@ -79,38 +79,6 @@ class FrontpageChartGenerator
return $data;
}
/**
* A basic setter for the user. Also updates the repositories with the right user.
*
* @param User $user
*/
public function setUser(User $user): void
{
$this->user = $user;
$this->budgetRepository->setUser($user);
$this->blRepository->setUser($user);
$this->opsRepository->setUser($user);
$locale = app('steam')->getLocale();
$this->monthAndDayFormat = (string)trans('config.month_and_day', [], $locale);
}
/**
* @param Carbon $start
*/
public function setStart(Carbon $start): void
{
$this->start = $start;
}
/**
* @param Carbon $end
*/
public function setEnd(Carbon $end): void
{
$this->end = $end;
}
/**
* 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.
@@ -238,5 +206,37 @@ 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->user = $user;
$this->budgetRepository->setUser($user);
$this->blRepository->setUser($user);
$this->opsRepository->setUser($user);
$locale = app('steam')->getLocale();
$this->monthAndDayFormat = (string)trans('config.month_and_day', [], $locale);
}
}

View File

@@ -99,6 +99,29 @@ 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]));
$tempData = [];
foreach ($spent as $currency) {
$this->addCurrency($currency);
$tempData[] = [
'name' => $category->name,
'sum' => $currency['sum'],
'sum_float' => round((float)$currency['sum'], $currency['currency_decimal_places']),
'currency_id' => (int)$currency['currency_id'],
];
}
return $tempData;
}
/**
* @param array $currency
*/
@@ -115,29 +138,6 @@ class FrontpageChartGenerator
];
}
/**
* @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]));
$tempData = [];
foreach ($spent as $currency) {
$this->addCurrency($currency);
$tempData[] = [
'name' => $category->name,
'sum' => $currency['sum'],
'sum_float' => round((float) $currency['sum'], $currency['currency_decimal_places']),
'currency_id' => (int)$currency['currency_id'],
];
}
return $tempData;
}
/**
* @param Collection $accounts
*
@@ -152,7 +152,7 @@ class FrontpageChartGenerator
$tempData[] = [
'name' => trans('firefly.no_category'),
'sum' => $currency['sum'],
'sum_float' => round((float) $currency['sum'], $currency['currency_decimal_places'] ?? 2),
'sum_float' => round((float)$currency['sum'], $currency['currency_decimal_places'] ?? 2),
'currency_id' => (int)$currency['currency_id'],
];
}

View File

@@ -27,10 +27,8 @@ use Carbon\Carbon;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
/**
* Class WholePeriodChartGenerator
@@ -109,8 +107,8 @@ class WholePeriodChartGenerator
$earnedInfoKey = sprintf('earned-in-%s', $code);
$spentAmount = $spent[$key][$currencyId]['sum'] ?? '0';
$earnedAmount = $earned[$key][$currencyId]['sum'] ?? '0';
$chartData[$spentInfoKey]['entries'][$label] = round((float) $spentAmount, $currency['currency_decimal_places']);
$chartData[$earnedInfoKey]['entries'][$label] = round((float) $earnedAmount, $currency['currency_decimal_places']);
$chartData[$spentInfoKey]['entries'][$label] = round((float)$spentAmount, $currency['currency_decimal_places']);
$chartData[$earnedInfoKey]['entries'][$label] = round((float)$earnedAmount, $currency['currency_decimal_places']);
}
$current = app('navigation')->addPeriod($current, $step, 0);
}