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

@@ -78,12 +78,12 @@ class ExchangeRateConverter
private function getRate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): string
{
// first attempt:
$rate = $this->getFromDB((int)$from->id, (int)$to->id, $date->format('Y-m-d'));
$rate = $this->getFromDB($from->id, $to->id, $date->format('Y-m-d'));
if (null !== $rate) {
return $rate;
}
// no result. perhaps the other way around?
$rate = $this->getFromDB((int)$to->id, (int)$from->id, $date->format('Y-m-d'));
$rate = $this->getFromDB($to->id, $from->id, $date->format('Y-m-d'));
if (null !== $rate) {
return bcdiv('1', $rate);
}
@@ -151,16 +151,16 @@ class ExchangeRateConverter
private function getEuroRate(TransactionCurrency $currency, Carbon $date): string
{
$euroId = $this->getEuroId();
if ($euroId === (int)$currency->id) {
if ($euroId === $currency->id) {
return '1';
}
$rate = $this->getFromDB((int)$currency->id, $euroId, $date->format('Y-m-d'));
$rate = $this->getFromDB($currency->id, $euroId, $date->format('Y-m-d'));
if (null !== $rate) {
// app('log')->debug(sprintf('Rate for %s to EUR is %s.', $currency->code, $rate));
return $rate;
}
$rate = $this->getFromDB($euroId, (int)$currency->id, $date->format('Y-m-d'));
$rate = $this->getFromDB($euroId, $currency->id, $date->format('Y-m-d'));
if (null !== $rate) {
return bcdiv('1', $rate);
// app('log')->debug(sprintf('Inverted rate for %s to EUR is %s.', $currency->code, $rate));
@@ -194,7 +194,7 @@ class ExchangeRateConverter
if (null === $euro) {
throw new FireflyException('Cannot find EUR in system, cannot do currency conversion.');
}
$cache->store((int)$euro->id);
return (int)$euro->id;
$cache->store($euro->id);
return $euro->id;
}
}

View File

@@ -220,7 +220,7 @@ trait AugumentData
$currentStart = clone $entry->start_date;
$currentEnd = clone $entry->end_date;
$expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $currency);
$spent = $expenses[(int)$currency->id]['sum'] ?? '0';
$spent = $expenses[$currency->id]['sum'] ?? '0';
$entry->spent = $spent;
$limits->push($entry);