Various code cleanup.

This commit is contained in:
James Cole
2023-11-05 19:41:37 +01:00
parent a0564751d6
commit 1d2e95f5af
136 changed files with 1171 additions and 514 deletions

View File

@@ -81,7 +81,7 @@ class BalanceController extends Controller
/** @var TransactionCurrency $default */
$default = app('amount')->getDefaultCurrency();
$converter = new ExchangeRateConverter();
$currencies = [(int)$default->id => $default,]; // currency cache
$currencies = [$default->id => $default,]; // currency cache
$data = [];
$chartData = [];
@@ -94,7 +94,7 @@ class BalanceController extends Controller
$journals = $collector->getExtractedJournals();
// set array for default currency (even if unused later on)
$defaultCurrencyId = (int)$default->id;
$defaultCurrencyId = $default->id;
$data[$defaultCurrencyId] = [
'currency_id' => (string)$defaultCurrencyId,
'currency_symbol' => $default->symbol,
@@ -168,7 +168,7 @@ class BalanceController extends Controller
$amountConverted = bcmul($amount, $rate);
// perhaps transaction already has the foreign amount in the native currency.
if ((int)$journal['foreign_currency_id'] === (int)$default->id) {
if ((int)$journal['foreign_currency_id'] === $default->id) {
$amountConverted = $journal['foreign_amount'] ?? '0';
$amountConverted = 'earned' === $key ? app('steam')->positive($amountConverted) : app('steam')->negative($amountConverted);
}

View File

@@ -170,9 +170,8 @@ class BudgetController extends Controller
*/
private function noBudgetLimits(Budget $budget, Carbon $start, Carbon $end): array
{
$budgetId = (int)$budget->id;
$spent = $this->opsRepository->listExpenses($start, $end, null, new Collection([$budget]));
return $this->processExpenses($budgetId, $spent, $start, $end);
return $this->processExpenses($budget->id, $spent, $start, $end);
}
/**
@@ -275,11 +274,10 @@ class BudgetController extends Controller
*/
private function processLimit(Budget $budget, BudgetLimit $limit): array
{
$budgetId = (int)$budget->id;
$end = clone $limit->end_date;
$end->endOfDay();
$spent = $this->opsRepository->listExpenses($limit->start_date, $end, null, new Collection([$budget]));
$limitCurrencyId = (int)$limit->transaction_currency_id;
$limitCurrencyId = $limit->transaction_currency_id;
$limitCurrency = $limit->transactionCurrency;
$converter = new ExchangeRateConverter();
$filtered = [];
@@ -295,9 +293,9 @@ class BudgetController extends Controller
$filtered[$currencyId] = $entry;
}
}
$result = $this->processExpenses($budgetId, $filtered, $limit->start_date, $end);
$result = $this->processExpenses($budget->id, $filtered, $limit->start_date, $end);
if (1 === count($result)) {
$compare = bccomp((string)$limit->amount, app('steam')->positive($result[$limitCurrencyId]['spent']));
$compare = bccomp($limit->amount, app('steam')->positive($result[$limitCurrencyId]['spent']));
if (1 === $compare) {
// convert this amount into the native currency:
$result[$limitCurrencyId]['left'] = bcadd($limit->amount, $result[$limitCurrencyId]['spent']);

View File

@@ -104,7 +104,7 @@ class CategoryController extends Controller
$amount = app('steam')->positive($journal['amount']);
$nativeAmount = $converter->convert($default, $currency, $journal['date'], $amount);
$key = sprintf('%s-%s', $categoryName, $currency->code);
if ((int)$journal['foreign_currency_id'] === (int)$default->id) {
if ((int)$journal['foreign_currency_id'] === $default->id) {
$nativeAmount = app('steam')->positive($journal['foreign_amount']);
}
// create arrays