Various code cleanup and fixed alignments.

This commit is contained in:
James Cole
2024-01-01 14:43:56 +01:00
parent 1368aafe5f
commit f963ac63f1
443 changed files with 3668 additions and 3672 deletions

View File

@@ -83,11 +83,11 @@ class BudgetController extends Controller
public function budget(Budget $budget): JsonResponse
{
/** @var Carbon $start */
$start = $this->repository->firstUseDate($budget) ?? session('start', today(config('app.timezone')));
$start = $this->repository->firstUseDate($budget) ?? session('start', today(config('app.timezone')));
/** @var Carbon $end */
$end = session('end', today(config('app.timezone')));
$cache = new CacheProperties();
$end = session('end', today(config('app.timezone')));
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('chart.budget.budget');
@@ -105,19 +105,19 @@ class BudgetController extends Controller
$defaultEntries = [];
while ($end >= $loopStart) {
/** @var Carbon $loopEnd */
$loopEnd = app('navigation')->endOfPeriod($loopStart, $step);
$spent = $this->opsRepository->sumExpenses($loopStart, $loopEnd, null, $collection);
$label = trim(app('navigation')->periodShow($loopStart, $step));
$loopEnd = app('navigation')->endOfPeriod($loopStart, $step);
$spent = $this->opsRepository->sumExpenses($loopStart, $loopEnd, null, $collection);
$label = trim(app('navigation')->periodShow($loopStart, $step));
foreach ($spent as $row) {
$currencyId = $row['currency_id'];
$currencyId = $row['currency_id'];
$currencies[$currencyId] ??= $row; // don't mind the field 'sum'
// also store this day's sum:
$currencies[$currencyId]['spent'][$label] = $row['sum'];
}
$defaultEntries[$label] = 0;
// set loop start to the next period:
$loopStart = clone $loopEnd;
$loopStart = clone $loopEnd;
$loopStart->addSecond();
}
// loop all currencies:
@@ -133,7 +133,7 @@ class BudgetController extends Controller
$chartData[$currencyId]['entries'][$label] = bcmul($spent, '-1');
}
}
$data = $this->generator->multiSet(array_values($chartData));
$data = $this->generator->multiSet(array_values($chartData));
$cache->store($data);
return response()->json($data);
@@ -150,9 +150,9 @@ class BudgetController extends Controller
throw new FireflyException('This budget limit is not part of this budget.');
}
$start = clone $budgetLimit->start_date;
$end = clone $budgetLimit->end_date;
$cache = new CacheProperties();
$start = clone $budgetLimit->start_date;
$end = clone $budgetLimit->end_date;
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('chart.budget.budget.limit');
@@ -162,11 +162,11 @@ class BudgetController extends Controller
if ($cache->has()) {
return response()->json($cache->get());
}
$locale = app('steam')->getLocale();
$entries = [];
$amount = $budgetLimit->amount;
$budgetCollection = new Collection([$budget]);
$currency = $budgetLimit->transactionCurrency;
$locale = app('steam')->getLocale();
$entries = [];
$amount = $budgetLimit->amount;
$budgetCollection = new Collection([$budget]);
$currency = $budgetLimit->transactionCurrency;
while ($start <= $end) {
$current = clone $start;
$expenses = $this->opsRepository->sumExpenses($current, $current, null, $budgetCollection, $currency);
@@ -177,7 +177,7 @@ class BudgetController extends Controller
$start->addDay();
}
$data = $this->generator->singleSet((string)trans('firefly.left'), $entries);
$data = $this->generator->singleSet((string)trans('firefly.left'), $entries);
// add currency symbol from budget limit:
$data['datasets'][0]['currency_symbol'] = $budgetLimit->transactionCurrency->symbol;
$data['datasets'][0]['currency_code'] = $budgetLimit->transactionCurrency->code;
@@ -198,8 +198,8 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
$cache->addProperty($budgetLimitId);
$cache->addProperty('chart.budget.expense-asset');
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
if (null !== $budgetLimit) {
$start = $budgetLimit->start_date;
@@ -214,14 +214,14 @@ class BudgetController extends Controller
}
$collector->setRange($start, $end);
$collector->setBudget($budget);
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
// group by asset account ID:
foreach ($journals as $journal) {
$key = sprintf('%d-%d', (int)$journal['source_account_id'], $journal['currency_id']);
$result[$key] ??= [
$result[$key] ??= [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'],
@@ -230,7 +230,7 @@ class BudgetController extends Controller
$result[$key]['amount'] = bcadd($journal['amount'], $result[$key]['amount']);
}
$names = $this->getAccountNames(array_keys($result));
$names = $this->getAccountNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
$assetId = (int)$parts[0];
@@ -243,7 +243,7 @@ class BudgetController extends Controller
];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
$data = $this->generator->multiCurrencyPieChart($chartData);
$cache->store($data);
return response()->json($data);
@@ -261,8 +261,8 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
$cache->addProperty($budgetLimitId);
$cache->addProperty('chart.budget.expense-category');
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
if (null !== $budgetLimit) {
$start = $budgetLimit->start_date;
$end = $budgetLimit->end_date;
@@ -276,12 +276,12 @@ class BudgetController extends Controller
}
$collector->setRange($start, $end);
$collector->setBudget($budget)->withCategoryInformation();
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
foreach ($journals as $journal) {
$key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']);
$result[$key] ??= [
$result[$key] ??= [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'],
@@ -290,7 +290,7 @@ class BudgetController extends Controller
$result[$key]['amount'] = bcadd($journal['amount'], $result[$key]['amount']);
}
$names = $this->getCategoryNames(array_keys($result));
$names = $this->getCategoryNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
$categoryId = (int)$parts[0];
@@ -301,7 +301,7 @@ class BudgetController extends Controller
'currency_code' => $info['currency_code'],
];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
$data = $this->generator->multiCurrencyPieChart($chartData);
$cache->store($data);
return response()->json($data);
@@ -319,8 +319,8 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
$cache->addProperty($budgetLimitId);
$cache->addProperty('chart.budget.expense-expense');
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
if (null !== $budgetLimit) {
$start = $budgetLimit->start_date;
$end = $budgetLimit->end_date;
@@ -334,14 +334,14 @@ class BudgetController extends Controller
}
$collector->setRange($start, $end);
$collector->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)->withAccountInformation();
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
/** @var array $journal */
foreach ($journals as $journal) {
$key = sprintf('%d-%d', $journal['destination_account_id'], $journal['currency_id']);
$result[$key] ??= [
$result[$key] ??= [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'],
@@ -350,7 +350,7 @@ class BudgetController extends Controller
$result[$key]['amount'] = bcadd($journal['amount'], $result[$key]['amount']);
}
$names = $this->getAccountNames(array_keys($result));
$names = $this->getAccountNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
$opposingId = (int)$parts[0];
@@ -363,7 +363,7 @@ class BudgetController extends Controller
];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
$data = $this->generator->multiCurrencyPieChart($chartData);
$cache->store($data);
return response()->json($data);
@@ -374,11 +374,11 @@ class BudgetController extends Controller
*/
public function frontpage(): JsonResponse
{
$start = session('start', today(config('app.timezone'))->startOfMonth());
$end = session('end', today(config('app.timezone'))->endOfMonth());
$start = session('start', today(config('app.timezone'))->startOfMonth());
$end = session('end', today(config('app.timezone'))->endOfMonth());
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('chart.budget.frontpage');
@@ -391,8 +391,8 @@ class BudgetController extends Controller
$chartGenerator->setStart($start);
$chartGenerator->setEnd($end);
$chartData = $chartGenerator->generate();
$data = $this->generator->multiSet($chartData);
$chartData = $chartGenerator->generate();
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);
@@ -408,7 +408,7 @@ class BudgetController extends Controller
public function period(Budget $budget, TransactionCurrency $currency, Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($accounts);
@@ -437,11 +437,11 @@ class BudgetController extends Controller
],
];
$currentStart = clone $start;
$currentStart = clone $start;
while ($currentStart <= $end) {
$currentStart = app('navigation')->startOfPeriod($currentStart, $preferredRange);
$title = $currentStart->isoFormat($titleFormat);
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
$currentStart = app('navigation')->startOfPeriod($currentStart, $preferredRange);
$title = $currentStart->isoFormat($titleFormat);
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
// default limit is no limit:
$chartData[0]['entries'][$title] = 0;
@@ -450,7 +450,7 @@ class BudgetController extends Controller
$chartData[1]['entries'][$title] = 0;
// get budget limit in this period for this currency.
$limit = $this->blRepository->find($budget, $currency, $currentStart, $currentEnd);
$limit = $this->blRepository->find($budget, $currency, $currentStart, $currentEnd);
if (null !== $limit) {
$chartData[1]['entries'][$title] = app('steam')->bcround($limit->amount, $currency->decimal_places);
}
@@ -460,11 +460,11 @@ class BudgetController extends Controller
$amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
$chartData[0]['entries'][$title] = app('steam')->bcround($amount, $currency->decimal_places);
$currentStart = clone $currentEnd;
$currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay();
}
$data = $this->generator->multiSet($chartData);
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);
@@ -476,7 +476,7 @@ class BudgetController extends Controller
public function periodNoBudget(TransactionCurrency $currency, Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($accounts);
@@ -500,7 +500,7 @@ class BudgetController extends Controller
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
}
$data = $this->generator->singleSet((string)trans('firefly.spent'), $chartData);
$data = $this->generator->singleSet((string)trans('firefly.spent'), $chartData);
$cache->store($data);
return response()->json($data);