diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index c6b2984728..72eaa746e5 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -335,7 +335,7 @@ class AccountController extends Controller $start = clone session('start', today(config('app.timezone'))->startOfMonth()); $end = clone session('end', today(config('app.timezone'))->endOfMonth()); $defaultSet = $repository->getAccountsByType([AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value])->pluck('id')->toArray(); - Log::debug('Default set is ', $defaultSet); + // Log::debug('Default set is ', $defaultSet); $frontpage = app('preferences')->get('frontpageAccounts', $defaultSet); $frontpageArray = !is_array($frontpage->data) ? [] : $frontpage->data; Log::debug('Frontpage preference set is ', $frontpageArray); diff --git a/app/Support/Http/Api/ExchangeRateConverter.php b/app/Support/Http/Api/ExchangeRateConverter.php index 2588794911..9c2101f23c 100644 --- a/app/Support/Http/Api/ExchangeRateConverter.php +++ b/app/Support/Http/Api/ExchangeRateConverter.php @@ -88,6 +88,10 @@ class ExchangeRateConverter return '1'; } + if($from->id === $to->id) { + Log::debug('ExchangeRateConverter: From and to are the same, return "1".'); + return '1'; + } $rate = $this->getRate($from, $to, $date); return '0' === $rate ? '1' : $rate; @@ -103,7 +107,7 @@ class ExchangeRateConverter // find in cache if (null !== $res) { - Log::debug(sprintf('ExchangeRateConverter: Return cached rate from #%d to #%d on %s.', $from->id, $to->id, $date->format('Y-m-d'))); + Log::debug(sprintf('ExchangeRateConverter: Return cached rate from %s to %s on %s.', $from->code, $to->code, $date->format('Y-m-d'))); return $res; } @@ -112,7 +116,7 @@ class ExchangeRateConverter $rate = $this->getFromDB($from->id, $to->id, $date->format('Y-m-d')); if (null !== $rate) { Cache::forever($key, $rate); - Log::debug(sprintf('ExchangeRateConverter: Return DB rate from #%d to #%d on %s.', $from->id, $to->id, $date->format('Y-m-d'))); + Log::debug(sprintf('ExchangeRateConverter: Return DB rate from %s to %s on %s.', $from->code, $to->code, $date->format('Y-m-d'))); return $rate; } @@ -122,7 +126,7 @@ class ExchangeRateConverter if (null !== $rate) { $rate = bcdiv('1', $rate); Cache::forever($key, $rate); - Log::debug(sprintf('ExchangeRateConverter: Return inverse DB rate from #%d to #%d on %s.', $from->id, $to->id, $date->format('Y-m-d'))); + Log::debug(sprintf('ExchangeRateConverter: Return inverse DB rate from %s to %s on %s.', $from->code, $to->code, $date->format('Y-m-d'))); return $rate; } @@ -133,14 +137,14 @@ class ExchangeRateConverter // combined (if present), they can be used to calculate the necessary conversion rate. if (0 === bccomp('0', $first) || 0 === bccomp('0', $second)) { - Log::warning(sprintf('$first is "%s" and $second is "%s"', $first, $second)); + Log::warning(sprintf('There is not enough information to convert %s to %s on date %d', $from->code, $to->code, $date->format('Y-m-d'))); return '1'; } $second = bcdiv('1', $second); $rate = bcmul($first, $second); - Log::debug(sprintf('ExchangeRateConverter: Return DB rate from #%d to #%d on %s.', $from->id, $to->id, $date->format('Y-m-d'))); + Log::debug(sprintf('ExchangeRateConverter: Return DB rate from %s to %s on %s.', $from->code, $to->code, $date->format('Y-m-d'))); Cache::forever($key, $rate); return $rate; @@ -154,6 +158,7 @@ class ExchangeRateConverter private function getFromDB(int $from, int $to, string $date): ?string { if ($from === $to) { + Log::debug('ExchangeRateConverter: From and to are the same, return "1".'); return '1'; } $key = sprintf('cer-%d-%d-%s', $from, $to, $date); @@ -173,7 +178,7 @@ class ExchangeRateConverter if ('' === $rate) { return null; } - Log::debug(sprintf('ExchangeRateConverter: Found !cached! rate from #%d to #%d on %s.', $from, $to, $date)); + Log::debug(sprintf('ExchangeRateConverter: Found cached rate from #%d to #%d on %s.', $from, $to, $date)); return $rate; } diff --git a/app/Support/Http/Controllers/ChartGeneration.php b/app/Support/Http/Controllers/ChartGeneration.php index 9c82e37238..18dbf80eac 100644 --- a/app/Support/Http/Controllers/ChartGeneration.php +++ b/app/Support/Http/Controllers/ChartGeneration.php @@ -58,7 +58,7 @@ trait ChartGeneration if ($cache->has()) { return $cache->get(); } - app('log')->debug('Regenerate chart.account.account-balance-chart from scratch.'); + Log::debug('Regenerate chart.account.account-balance-chart from scratch.'); $locale = app('steam')->getLocale(); /** @var GeneratorInterface $generator */ @@ -88,6 +88,7 @@ trait ChartGeneration $currentStart = clone $start; $range = Steam::finalAccountBalanceInRange($account, clone $start, clone $end, $this->convertToNative); $previous = array_values($range)[0]; + Log::debug(sprintf('Start balance for account #%d ("%s) is', $account->id, $account->name), $previous); while ($currentStart <= $end) { $format = $currentStart->format('Y-m-d'); $label = trim($currentStart->isoFormat((string) trans('config.month_and_day_js', [], $locale))); diff --git a/app/Support/Steam.php b/app/Support/Steam.php index a6211167f7..e1e1cc3a5c 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -59,8 +59,8 @@ class Steam public function finalAccountBalanceInRange(Account $account, Carbon $start, Carbon $end, bool $convertToNative): array { // expand period. - $start->subDay()->endOfDay(); // go to END of day to get the balance at the END of the day. - $end->addDay()->startOfDay(); // go to START of day to get the balance at the END of the previous day (see ahead). + $start->startOfDay(); + $end->endOfDay(); Log::debug(sprintf('finalAccountBalanceInRange(#%d, %s, %s)', $account->id, $start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s'))); // set up cache @@ -82,6 +82,7 @@ class Steam $currency = $accountCurrency ?? $nativeCurrency; Log::debug(sprintf('Currency is %s', $currency->code)); + // set start balances: $startBalance[$currency->code] ??= '0'; if ($hasCurrency) { @@ -100,10 +101,11 @@ class Steam Log::debug('Final start balance: ', $startBalance); // sums up the balance changes per day. + Log::debug(sprintf('Date >= %s and <= %s', $start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s'))); $set = $account->transactions() ->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transaction_journals.date', '>', $start->format('Y-m-d H:i:s')) - ->where('transaction_journals.date', '<', $end->format('Y-m-d H:i:s')) + ->where('transaction_journals.date', '>=', $start->format('Y-m-d H:i:s')) + ->where('transaction_journals.date', '<=', $end->format('Y-m-d H:i:s')) ->groupBy('transaction_journals.date') ->groupBy('transactions.transaction_currency_id') ->orderBy('transaction_journals.date', 'ASC')