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

@@ -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);
}