Various fixes and cleanup

This commit is contained in:
James Cole
2023-01-29 15:29:42 +01:00
parent 1cbb644d65
commit 413a4f3d9c
276 changed files with 3119 additions and 2894 deletions

View File

@@ -73,12 +73,12 @@ class NetWorth implements NetWorthInterface
$cache->addProperty('net-worth-by-currency');
$cache->addProperty(implode(',', $accounts->pluck('id')->toArray()));
if ($cache->has()) {
// return $cache->get();
return $cache->get();
}
$netWorth = [];
$result = [];
Log::debug(sprintf('Now in getNetWorthByCurrency(%s)', $date->format('Y-m-d')));
// Log::debug(sprintf('Now in getNetWorthByCurrency(%s)', $date->format('Y-m-d')));
// get default currency
$default = app('amount')->getDefaultCurrencyByUser($this->user);
@@ -89,16 +89,16 @@ class NetWorth implements NetWorthInterface
// get the preferred currency for this account
/** @var Account $account */
foreach ($accounts as $account) {
Log::debug(sprintf('Now at account #%d: "%s"', $account->id, $account->name));
// Log::debug(sprintf('Now at account #%d: "%s"', $account->id, $account->name));
$currencyId = (int)$this->accountRepository->getMetaValue($account, 'currency_id');
$currencyId = 0 === $currencyId ? $default->id : $currencyId;
Log::debug(sprintf('Currency ID is #%d', $currencyId));
// Log::debug(sprintf('Currency ID is #%d', $currencyId));
// balance in array:
$balance = $balances[$account->id] ?? '0';
Log::debug(sprintf('Balance for %s is %s', $date->format('Y-m-d'), $balance));
//Log::debug(sprintf('Balance for %s is %s', $date->format('Y-m-d'), $balance));
// always subtract virtual balance.
$virtualBalance = (string)$account->virtual_balance;
@@ -106,14 +106,14 @@ class NetWorth implements NetWorthInterface
$balance = bcsub($balance, $virtualBalance);
}
Log::debug(sprintf('Balance corrected to %s because of virtual balance (%s)', $balance, $virtualBalance));
// Log::debug(sprintf('Balance corrected to %s because of virtual balance (%s)', $balance, $virtualBalance));
if (!array_key_exists($currencyId, $netWorth)) {
$netWorth[$currencyId] = '0';
}
$netWorth[$currencyId] = bcadd($balance, $netWorth[$currencyId]);
Log::debug(sprintf('Total net worth for currency #%d is %s', $currencyId, $netWorth[$currencyId]));
// Log::debug(sprintf('Total net worth for currency #%d is %s', $currencyId, $netWorth[$currencyId]));
}
ksort($netWorth);

View File

@@ -90,7 +90,7 @@ trait ConvertsDataTypes
if (null === $string) {
return null;
}
if('' === $string) {
if ('' === $string) {
return '';
}
$search = [
@@ -154,7 +154,7 @@ trait ConvertsDataTypes
if (null === $string) {
return null;
}
if('' === $string) {
if ('' === $string) {
return '';
}
return trim($string);

View File

@@ -368,9 +368,10 @@ class User extends Authenticatable
* @return int
* @throws FireflyException
*/
public function getAdministrationId(): int {
public function getAdministrationId(): int
{
$groupId = (int)$this->user_group_id;
if(0 === $groupId) {
if (0 === $groupId) {
throw new FireflyException('User has no administration ID.');
}
return $groupId;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
/*
* ValidatesAdministrationAccess.php
* Copyright (c) 2023 james@firefly-iii.org

View File

@@ -46,7 +46,7 @@ trait CurrencyValidation
$transactions = $this->getTransactionsArray($validator);
foreach ($transactions as $index => $transaction) {
if(!is_array($transaction)) {
if (!is_array($transaction)) {
continue;
}
// if foreign amount is present, then the currency must be as well.