Skip to content

Firefly III: a personal finances manager

Fix https://github.com/orgs/firefly-iii/discussions/12559

James Colea2d612732881
diff --git a/app/Services/Internal/Support/RecurringTransactionTrait.php b/app/Services/Internal/Support/RecurringTransactionTrait.php
index 2ea4ec7c99..802b09186c 100644
--- a/app/Services/Internal/Support/RecurringTransactionTrait.php
+++ b/app/Services/Internal/Support/RecurringTransactionTrait.php
@@ -338,5 +338,6 @@ trait RecurringTransactionTrait
}
$meta->value = $category->id;
$meta->save();
+
}
}
diff --git a/app/Services/Internal/Update/RecurrenceUpdateService.php b/app/Services/Internal/Update/RecurrenceUpdateService.php
index d37701640d..d1406cd2b1 100644
--- a/app/Services/Internal/Update/RecurrenceUpdateService.php
+++ b/app/Services/Internal/Update/RecurrenceUpdateService.php
@@ -220,14 +220,17 @@ class RecurrenceUpdateService
if (array_key_exists($field, $submitted)) {
$transaction->{$column} = $submitted[$field];
$transaction->save();
+ $recurrence->touch();
}
}
// update meta data
if (array_key_exists('budget_id', $submitted)) {
$this->setBudget($transaction, (int) $submitted['budget_id']);
+ $recurrence->touch();
}
if (array_key_exists('bill_id', $submitted)) {
$this->setBill($transaction, (int) $submitted['bill_id']);
+ $recurrence->touch();
}
// reset category if name is set but empty:
// can be removed when v1 is retired.
@@ -240,19 +243,23 @@ class RecurrenceUpdateService
if (array_key_exists('category_id', $submitted)) {
Log::debug(sprintf('Category ID is submitted, set category to be %d.', (int) $submitted['category_id']));
$this->setCategory($transaction, (int) $submitted['category_id']);
+ $recurrence->touch();
}
if (array_key_exists('tags', $submitted) && is_array($submitted['tags'])) {
$this->updateTags($transaction, $submitted['tags']);
+ $recurrence->touch();
}
if (array_key_exists('piggy_bank_id', $submitted)) {
$this->updatePiggyBank($transaction, (int) $submitted['piggy_bank_id']);
+ $recurrence->touch();
}
if (array_key_exists('type', $submitted)) {
$type = TransactionType::query()->where('type', ucfirst($submitted['type']))->first();
if (null !== $type) {
$transaction->transaction_type_id = $type->id;
$transaction->save();
+ $recurrence->touch();
}
}
}
@@ -272,6 +279,7 @@ class RecurrenceUpdateService
Log::debug('Delete existing repetitions and create new ones.');
$this->deleteRepetitions($recurrence);
$this->createRepetitions($recurrence, $repetitions);
+ $recurrence->touch();
return;
}
@@ -287,6 +295,7 @@ class RecurrenceUpdateService
if (array_key_exists($field, $current)) {
$match->{$column} = $current[$field];
$match->save();
+ $recurrence->touch();
}
}
}
diff --git a/app/Support/Http/Controllers/ChartGeneration.php b/app/Support/Http/Controllers/ChartGeneration.php
index 42cf732b1e..1a5ffc9d57 100644
--- a/app/Support/Http/Controllers/ChartGeneration.php
+++ b/app/Support/Http/Controllers/ChartGeneration.php
@@ -57,7 +57,7 @@ trait ChartGeneration
$cache->addProperty($accounts);
$cache->addProperty($convertToPrimary);
if ($cache->has()) {
- return $cache->get();
+ return $cache->get();
}
Log::debug('Regenerate chart.account.account-balance-chart from scratch.');
$locale = Steam::getLocale();
diff --git a/app/Support/Steam.php b/app/Support/Steam.php
index 2ec70d6535..7c551ccc07 100644
--- a/app/Support/Steam.php
+++ b/app/Support/Steam.php
@@ -43,7 +43,6 @@ use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Safe\Exceptions\UrlException;
use ValueError;
-
use function Safe\parse_url;
use function Safe\preg_replace;
@@ -57,12 +56,13 @@ class Steam
* properly gets the balance of a range.
*/
public function accountsBalancesInRange(
- Collection $accounts,
- Carbon $start,
- Carbon $end,
+ Collection $accounts,
+ Carbon $start,
+ Carbon $end,
?TransactionCurrency $primary = null,
- ?bool $convertToPrimary = null
- ): array {
+ ?bool $convertToPrimary = null
+ ): array
+ {
return [
$this->accountsBalancesOptimized($accounts, $start, $primary, $convertToPrimary, inclusive: false),
$this->accountsBalancesOptimized($accounts, $end, $primary, $convertToPrimary),
@@ -70,54 +70,76 @@ class Steam
}
public function accountsBalancesOptimized(
- Collection $accounts,
- Carbon $date,
+ Collection $accounts,
+ Carbon $date,
?TransactionCurrency $primary = null,
- ?bool $convertToPrimary = null,
- bool $inclusive = true
- ): array {
+ ?bool $convertToPrimary = null,
+ bool $inclusive = true
+ ): array
+ {
// Log::debug(sprintf('accountsBalancesOptimized: Called for %d account(s) with date/time "%s" (inclusive: %s)', $accounts->count(), $date->toIso8601String(), var_export($inclusive, true)));
- $result = [];
+ $result = [];
$convertToPrimary ??= Amount::convertToPrimary();
$primary ??= Amount::getPrimaryCurrency();
- $currencies = $this->getCurrencies($accounts);
+ $currencies = $this->getCurrencies($accounts);
// balance(s) in all currencies for ALL accounts.
$arrayOfSums = Transaction::query()
- ->whereIn('account_id', $accounts->pluck('id')->toArray())
- ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
- ->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transactions.transaction_currency_id')
- ->where('transaction_journals.date', $inclusive ? '<=' : '<', $date->format('Y-m-d H:i:s'))
- ->whereNull('transaction_journals.deleted_at')
- ->groupBy(['transactions.account_id', 'transaction_currencies.code'])
- ->get(['transactions.account_id', 'transaction_currencies.code', DB::raw('SUM(transactions.amount) as sum_of_amount')])
- ->toArray()
- ;
+ ->whereIn('account_id', $accounts->pluck('id')->toArray())
+ ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
+ ->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transactions.transaction_currency_id')
+ ->where('transaction_journals.date', $inclusive ? '<=' : '<', $date->format('Y-m-d H:i:s'))
+ ->whereNull('transaction_journals.deleted_at')
+ ->groupBy(['transactions.account_id', 'transaction_currencies.code'])
+ ->get(['transactions.account_id', 'transaction_currencies.code', DB::raw('SUM(transactions.amount) as sum_of_amount')])
+ ->toArray();
// Log::debug('Array of sums: ', $arrayOfSums);
/** @var Account $account */
foreach ($accounts as $account) {
- $return = ['pc_balance' => '0', 'balance' => '0']; // this key is overwritten right away, but I must remember it is always created.
- $currency = $currencies[$account->id];
+ // this key is overwritten right away, but I must remember it is always created.
+ $currency = $currencies[$account->id];
+ $return = [
+ 'pc_balance' => '0',
+ 'balance' => '0',
+ ];
+ // FIRST, add virtual balance to this.
+ $virtualBalance = (string)('' === (string)$account->virtual_balance ? '0' : $account->virtual_balance);
+ $pcVirtualBalance = '0';
+ if (!$convertToPrimary) {
+ $return['balance'] = bcadd($return['balance'], $virtualBalance);
+ Log::debug(sprintf('ADD virtual balance (%s) to "balance"', $virtualBalance), $return);
+ }
+ if ($convertToPrimary) {
+ // the primary currency balance is combined with a converted virtual_balance:
+ $converter = new ExchangeRateConverter();
+ $pcVirtualBalance = $converter->convert($currency, $primary, $date, $virtualBalance);
+ Log::debug(sprintf('ADD converted virtual balance (%s) to "pc_balance"', $pcVirtualBalance));
+ $return['pc_balance'] = bcadd($pcVirtualBalance, $return['pc_balance']);
+ }
// second array
- $accountSums = array_filter($arrayOfSums, static fn (array $entry): bool => $entry['account_id'] === $account->id);
+ $accountSums = array_filter($arrayOfSums, static fn(array $entry): bool => $entry['account_id'] === $account->id);
if (0 === count($accountSums)) {
+ Log::debug('No sums in transactions, so return whatever we have now.', $return);
$result[$account->id] = $return;
continue;
}
- $sumsByCode = [];
+ $sumsByCode = [];
foreach ($accountSums as $accountSum) {
// $accountSum = array_values($accountSum)[0];
- $sumOfAmount = (string) $accountSum['sum_of_amount'];
+ $sumOfAmount = (string)$accountSum['sum_of_amount'];
$sumOfAmount = $this->floatalize('' === $sumOfAmount ? '0' : $sumOfAmount);
$sumsByCode[$accountSum['code']] = $sumOfAmount;
}
// Log::debug('All balances are (joined)', $others);
// if there is no request to convert, take this as "balance" and "pc_balance".
- $return['balance'] = $sumsByCode[$currency->code] ?? '0';
+ if(array_key_exists($currency->code, $sumsByCode)) {
+ // overwrite balance, but add virtual balance to it.
+ $return['balance'] = bcadd($sumsByCode[$currency->code], $virtualBalance);
+ }
if (!$convertToPrimary) {
unset($return['pc_balance']);
@@ -131,27 +153,26 @@ class Steam
// Log::debug(sprintf('Set pc_balance to %s', $return['pc_balance']));
}
- // either way, the balance is always combined with the virtual balance:
- $virtualBalance = (string) ('' === (string) $account->virtual_balance ? '0' : $account->virtual_balance);
if ($convertToPrimary) {
// the primary currency balance is combined with a converted virtual_balance:
- $converter = new ExchangeRateConverter();
- $pcVirtualBalance = $converter->convert($currency, $primary, $date, $virtualBalance);
- $return['pc_balance'] = bcadd($pcVirtualBalance, $return['pc_balance']);
+ $converter = new ExchangeRateConverter();
+ // $return['pc_balance'] = bcadd($pcVirtualBalance, $return['pc_balance']);
+ $sumsByCode[$primary->code] = bcadd($pcVirtualBalance, $sumsByCode[$primary->code]);
- // Log::debug(sprintf('Primary virtual balance makes the primary total %s', $return['pc_balance']));
+ Log::debug(sprintf('Primary virtual balance (%s) makes the primary total %s', $pcVirtualBalance, $sumsByCode[$primary->code]));
}
if (!$convertToPrimary) {
// if not, also increase the balance + primary balance for consistency.
- $return['balance'] = bcadd($return['balance'], $virtualBalance);
+ // $return['balance'] = bcadd($return['balance'], $virtualBalance);
+ $sumsByCode[$currency->code] = bcadd($virtualBalance, $sumsByCode[$currency->code]);
- // Log::debug(sprintf('Virtual balance makes the (primary currency) total %s', $return['balance']));
+ Log::debug(sprintf('Virtual balance (%s) makes the (primary currency) total %s', $virtualBalance, $sumsByCode[$currency->code]));
}
$final = array_merge($return, $sumsByCode);
$result[$account->id] = $final;
- // Log::debug(sprintf('Final balance for account #%d is', $account->id), $final);
+ Log::debug(sprintf('Final balance for account #%d is', $account->id), $final);
}
return $result;
@@ -189,10 +210,10 @@ class Steam
// Log::debug(sprintf('Trying bcround("%s",%d)', $number, $precision));
if (str_contains($number, '.')) {
if ('-' !== $number[0]) {
- return bcadd($number, '0.'.str_repeat('0', $precision).'5', $precision);
+ return bcadd($number, '0.' . str_repeat('0', $precision) . '5', $precision);
}
- return bcsub($number, '0.'.str_repeat('0', $precision).'5', $precision);
+ return bcsub($number, '0.' . str_repeat('0', $precision) . '5', $precision);
}
return $number;
@@ -334,21 +355,23 @@ class Steam
"balance": balance in the account's currency OR user's primary currency if the account has no currency
--> "pc_balance": balance in the user's primary currency, with all amounts converted to the primary currency.
"EUR": balance in EUR (or whatever currencies the account has balance in)
- TXT)]
+ TXT
+ )]
public function finalAccountBalance(
- Account $account,
- Carbon $date,
+ Account $account,
+ Carbon $date,
?TransactionCurrency $primary = null,
- ?bool $convertToPrimary = null,
- bool $inclusive = true
- ): array {
- $cache = new CacheProperties();
+ ?bool $convertToPrimary = null,
+ bool $inclusive = true
+ ): array
+ {
+ $cache = new CacheProperties();
$cache->addProperty($account->id);
$cache->addProperty($date);
if ($cache->has()) {
Log::debug(sprintf('CACHED finalAccountBalance(#%d, %s, inclusive:%s)', $account->id, $date->format('Y-m-d H:i:s'), var_export($inclusive, true)));
- // return $cache->get();
+ return $cache->get();
}
Log::debug(sprintf('finalAccountBalance(#%d, %s)', $account->id, $date->format('Y-m-d H:i:s')));
if (null === $convertToPrimary) {
@@ -358,26 +381,25 @@ class Steam
$primary = Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
}
// account balance thing.
- $currencyPresent = property_exists($account, 'meta') && array_key_exists('currency', $account->meta) && null !== $account->meta['currency'];
+ $currencyPresent = property_exists($account, 'meta') && array_key_exists('currency', $account->meta) && null !== $account->meta['currency'];
if ($currencyPresent) {
$accountCurrency = $account->meta['currency'];
}
if (!$currencyPresent) {
$accountCurrency = $this->getAccountCurrency($account);
}
- $hasCurrency = null !== $accountCurrency;
- $currency = $hasCurrency ? $accountCurrency : $primary;
- $return = ['pc_balance' => '0', 'balance' => '0']; // this key is overwritten right away, but I must remember it is always created.
+ $hasCurrency = null !== $accountCurrency;
+ $currency = $hasCurrency ? $accountCurrency : $primary;
+ $return = ['pc_balance' => '0', 'balance' => '0']; // this key is overwritten right away, but I must remember it is always created.
// balance(s) in all currencies.
- $array = $account
+ $array = $account
->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transactions.transaction_currency_id')
->where('transaction_journals.date', $inclusive ? '<=' : '<', $date->format('Y-m-d H:i:s'))
->get(['transaction_currencies.code', 'transactions.amount'])
- ->toArray()
- ;
- $others = $this->groupAndSumTransactions($array, 'code', 'amount');
+ ->toArray();
+ $others = $this->groupAndSumTransactions($array, 'code', 'amount');
Log::debug('All balances are (joined)', $others);
// if there is no request to convert, take this as "balance" and "pc_balance".
$return['balance'] = $others[$currency->code] ?? '0';
@@ -394,7 +416,7 @@ class Steam
}
// either way, the balance is always combined with the virtual balance:
- $virtualBalance = (string) ('' === (string) $account->virtual_balance ? '0' : $account->virtual_balance);
+ $virtualBalance = (string)('' === (string)$account->virtual_balance ? '0' : $account->virtual_balance);
if ($convertToPrimary) {
// the primary currency balance is combined with a converted virtual_balance:
@@ -410,7 +432,7 @@ class Steam
// Log::debug(sprintf('Virtual balance makes the (primary currency) total %s', $return['balance']));
}
- $final = array_merge($return, $others);
+ $final = array_merge($return, $others);
Log::debug('Final balance is', $final);
$cache->store($final);
@@ -428,7 +450,7 @@ class Steam
Log::debug(sprintf('called 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
- $cache = new CacheProperties();
+ $cache = new CacheProperties();
$cache->addProperty($account->id);
$cache->addProperty('final-balance-in-range');
$cache->addProperty($start);
@@ -437,37 +459,55 @@ class Steam
if ($cache->has()) {
Log::debug('Return cached finalAccountBalanceInRange');
- return $cache->get();
+ return $cache->get();
}
- $balances = [];
- $formatted = $start->format('Y-m-d');
+ $balances = [];
+ $formatted = $start->format('Y-m-d');
Log::debug('Get first balance to start.');
// 2025-10-08 replaced finalAccountBalance with accountsBalancesOptimized:
- $primaryCurrency = Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
- $startBalance = $this->accountsBalancesOptimized(new Collection()->push($account), $start, $primaryCurrency, $convertToPrimary, false)[$account->id];
- $accountCurrency = $this->getAccountCurrency($account);
- $hasCurrency = $accountCurrency instanceof TransactionCurrency;
- $currency = $accountCurrency ?? $primaryCurrency;
+ $primaryCurrency = Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
+ $startBalance = $this->accountsBalancesOptimized(new Collection()->push($account), $start, $primaryCurrency, $convertToPrimary, false)[$account->id];
+ $accountCurrency = $this->getAccountCurrency($account);
+ $hasCurrency = $accountCurrency instanceof TransactionCurrency;
+ $currency = $accountCurrency ?? $primaryCurrency;
Log::debug(sprintf('Currency is %s', $currency->code));
// set start balances:
- $startBalance[$currency->code] ??= '0';
- if ($hasCurrency) {
- $startBalance[$accountCurrency->code] ??= '0';
+ if (!array_key_exists($currency->code, $startBalance)) {
+ // set first balance to 0 or the virtual balance of the account.
+ $startBalance[$currency->code] = (string)('' === (string)$account->virtual_balance ? '0' : $account->virtual_balance);
+ Log::debug(sprintf('[a] Start balance in %s is %s', $currency->code, $startBalance[$currency->code]));
+ }
+ if ($hasCurrency && !array_key_exists($accountCurrency->code, $startBalance)) {
+ $startBalance[$currency->code] = (string)('' === (string)$account->virtual_balance ? '0' : $account->virtual_balance);
+ Log::debug(sprintf('[b] Start balance in %s is %s', $currency->code, $startBalance[$currency->code]));
+ }
+ if ($hasCurrency && !array_key_exists($primaryCurrency->code, $startBalance)) {
+ if ($accountCurrency->id !== $primaryCurrency->id && $convertToPrimary) {
+ $converter = new ExchangeRateConverter();
+ $converted = $converter->convert($accountCurrency, $primaryCurrency, $start, $startBalance[$accountCurrency->code]);
+ $startBalance[$primaryCurrency->code] = $converted;
+ Log::debug(sprintf('[c] Also set start balance in %s to %s', $primaryCurrency->code, $converted));
+ }
+ if ($accountCurrency->id !== $primaryCurrency->id && !$convertToPrimary) {
+ $startBalance[$primaryCurrency->code] = (string)('' === (string)$account->virtual_balance ? '0' : $account->virtual_balance);
+ Log::debug(sprintf('[d] Also set start balance in %s to %s', $primaryCurrency->code, $converted));
+ }
}
+
if (!$hasCurrency) {
- Log::debug(sprintf('Also set start balance in %s', $primaryCurrency->code));
- $startBalance[$primaryCurrency->code] ??= '0';
+ Log::debug(sprintf('[e] Also set start balance in %s', $primaryCurrency->code));
+ $startBalance[$primaryCurrency->code] = (string)('' === (string)$account->virtual_balance ? '0' : $account->virtual_balance);
}
- $currencies = [$currency->id => $currency, $primaryCurrency->id => $primaryCurrency];
+ $currencies = [$currency->id => $currency, $primaryCurrency->id => $primaryCurrency];
$balances[$formatted] = $startBalance;
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
+ $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'))
@@ -476,51 +516,50 @@ class Steam
->groupBy('transactions.transaction_currency_id')
->orderBy('transaction_journals.date', 'ASC')
->whereNull('transaction_journals.deleted_at')
- ->get(['transaction_journals.date', 'transactions.transaction_currency_id', DB::raw('SUM(transactions.amount) AS sum_of_day')])
- ;
+ ->get(['transaction_journals.date', 'transactions.transaction_currency_id', DB::raw('SUM(transactions.amount) AS sum_of_day')]);
- $currentBalance = $startBalance;
- $converter = new ExchangeRateConverter();
+ $currentBalance = $startBalance;
+ $converter = new ExchangeRateConverter();
/** @var Transaction $entry */
foreach ($set as $entry) {
// get date object
- $carbon = new Carbon($entry->date, $entry->date_tz);
- $carbonKey = $carbon->format('Y-m-d');
+ $carbon = new Carbon($entry->date, $entry->date_tz);
+ $carbonKey = $carbon->format('Y-m-d');
// make sure sum is a string:
- $sumOfDay = (string) ($entry->sum_of_day ?? '0');
+ $sumOfDay = (string)($entry->sum_of_day ?? '0');
// #10426 make sure sum is not in scientific notation.
- $sumOfDay = $this->floatalize($sumOfDay);
+ $sumOfDay = $this->floatalize($sumOfDay);
// find currency of this entry, does not have to exist.
$currencies[$entry->transaction_currency_id] ??= Amount::getTransactionCurrencyById($entry->transaction_currency_id);
// make sure this $entry has its own $entryCurrency
/** @var TransactionCurrency $entryCurrency */
- $entryCurrency = $currencies[$entry->transaction_currency_id];
+ $entryCurrency = $currencies[$entry->transaction_currency_id];
Log::debug(sprintf('Processing transaction(s) on moment %s', $carbon->format('Y-m-d H:i:s')));
// add amount to current balance in currency code.
- $currentBalance[$entryCurrency->code] ??= '0';
- $currentBalance[$entryCurrency->code] = bcadd($sumOfDay, (string) $currentBalance[$entryCurrency->code]);
+ $currentBalance[$entryCurrency->code] ??= '0';
+ $currentBalance[$entryCurrency->code] = bcadd($sumOfDay, (string)$currentBalance[$entryCurrency->code]);
// if not requested to convert to primary currency, add the amount to "balance", do nothing else.
if (!$convertToPrimary) {
- $currentBalance['balance'] = bcadd((string) $currentBalance['balance'], $sumOfDay);
+ $currentBalance['balance'] = bcadd((string)$currentBalance['balance'], $sumOfDay);
}
// if convert to primary currency add the converted amount to "pc_balance".
// if there is a request to convert, convert to "pc_balance" and use "balance" for whichever amount is in the primary currency.
if ($convertToPrimary) {
$pcSumOfDay = $converter->convert($entryCurrency, $primaryCurrency, $carbon, $sumOfDay);
- $currentBalance['pc_balance'] = bcadd((string) ($currentBalance['pc_balance'] ?? '0'), $pcSumOfDay);
+ $currentBalance['pc_balance'] = bcadd((string)($currentBalance['pc_balance'] ?? '0'), $pcSumOfDay);
// if it's the same currency as the entry, also add to balance (see other code).
if ($currency->id === $entryCurrency->id) {
- $currentBalance['balance'] = bcadd((string) $currentBalance['balance'], $sumOfDay);
+ $currentBalance['balance'] = bcadd((string)$currentBalance['balance'], $sumOfDay);
}
}
// add to final array.
- $balances[$carbonKey] = $currentBalance;
+ $balances[$carbonKey] = $currentBalance;
Log::debug(sprintf('Updated entry [%s]', $carbonKey), $currentBalance);
}
$cache->store($balances);
@@ -537,26 +576,26 @@ class Steam
*/
public function floatalize(string $value): string
{
- $value = strtoupper($value);
+ $value = strtoupper($value);
if (!str_contains($value, 'E')) {
return $value;
}
Log::debug(sprintf('Floatalizing %s', $value));
- $number = substr($value, 0, (int) strpos($value, 'E'));
+ $number = substr($value, 0, (int)strpos($value, 'E'));
if (str_contains($number, '.')) {
- $post = strlen(substr($number, (int) strpos($number, '.') + 1));
- $mantis = substr($value, (int) strpos($value, 'E') + 1);
+ $post = strlen(substr($number, (int)strpos($number, '.') + 1));
+ $mantis = substr($value, (int)strpos($value, 'E') + 1);
if ($mantis < 0) {
- $post += abs((int) $mantis);
+ $post += abs((int)$mantis);
}
// TODO careless float could break financial math.
- return number_format((float) $value, $post, '.', '');
+ return number_format((float)$value, $post, '.', '');
}
// TODO careless float could break financial math.
- return number_format((float) $value, 0, '.', '');
+ return number_format((float)$value, 0, '.', '');
}
public function formatAmountByCode(string $amount, string $code, ?bool $coloured = null): string
@@ -580,7 +619,7 @@ class Steam
public function formatAmountBySymbol(string $amount, ?string $symbol = null, ?int $decimalPlaces = null, ?bool $coloured = null): string
{
if (null === $symbol) {
- $message = sprintf(
+ $message = sprintf(
'formatAmountBySymbol("%s", %s, %d, %s) was called without a symbol. Please browse to /flush to clear your cache.',
$amount,
var_export($symbol, true),
@@ -591,8 +630,8 @@ class Steam
$currency = Amount::getPrimaryCurrency();
}
if (null !== $symbol) {
- $decimalPlaces ??= 2;
- $coloured ??= true;
+ $decimalPlaces ??= 2;
+ $coloured ??= true;
$currency = new TransactionCurrency();
$currency->symbol = $symbol;
$currency->decimal_places = $decimalPlaces;
@@ -603,8 +642,8 @@ class Steam
public function getAccountCurrency(Account $account): ?TransactionCurrency
{
- $type = $account->accountType->type;
- $list = config('firefly.valid_currency_account_types');
+ $type = $account->accountType->type;
+ $list = config('firefly.valid_currency_account_types');
// return null if not in this list.
if (!in_array($type, $list, true)) {
@@ -615,7 +654,7 @@ class Steam
return null;
}
- return Amount::getTransactionCurrencyById((int) $result->data);
+ return Amount::getTransactionCurrencyById((int)$result->data);
}
public function getHostName(string $ipAddress): string
@@ -629,11 +668,11 @@ class Steam
$hostName = $ipAddress;
}
- if ('' !== (string) $hostName && $hostName !== $ipAddress) {
+ if ('' !== (string)$hostName && $hostName !== $ipAddress) {
$host = $hostName;
}
- return (string) $host;
+ return (string)$host;
}
/**
@@ -657,19 +696,18 @@ class Steam
{
$list = [];
- $set = auth()
+ $set = auth()
->user()
->transactions()
->whereIn('transactions.account_id', $accounts)
->groupBy(['transactions.account_id', 'transaction_journals.user_id'])
- ->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) AS max_date')])
- ;
+ ->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) AS max_date')]);
/** @var Transaction $entry */
foreach ($set as $entry) {
- $date = new Carbon($entry->max_date, config('app.timezone'));
+ $date = new Carbon($entry->max_date, config('app.timezone'));
$date->setTimezone(config('app.timezone'));
- $list[(int) $entry->account_id] = $date;
+ $list[(int)$entry->account_id] = $date;
}
return $list;
@@ -685,14 +723,14 @@ class Steam
if (null !== $cached) {
return $cached;
}
- $locale = Preferences::get('locale', config('firefly.default_locale', 'equal'))->data;
+ $locale = Preferences::get('locale', config('firefly.default_locale', 'equal'))->data;
if (is_array($locale)) {
$locale = 'equal';
}
if ('equal' === $locale) {
$locale = $this->getLanguage();
}
- $locale = (string) $locale;
+ $locale = (string)$locale;
// Check for Windows to replace the locale correctly.
if ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) {
@@ -732,7 +770,7 @@ class Steam
public function getSafeUrl(string $unknownUrl, string $safeUrl): string
{
// Log::debug(sprintf('getSafeUrl(%s, %s)', $unknownUrl, $safeUrl));
- $returnUrl = $safeUrl;
+ $returnUrl = $safeUrl;
// die('in get safe url');
try {
@@ -795,24 +833,24 @@ class Steam
// has a K in it, remove the K and multiply by 1024.
$bytes = bcmul(rtrim($string, 'k'), '1024');
- return (int) $bytes;
+ return (int)$bytes;
}
if (false !== stripos($string, 'm')) {
// has a M in it, remove the M and multiply by 1048576.
$bytes = bcmul(rtrim($string, 'm'), '1048576');
- return (int) $bytes;
+ return (int)$bytes;
}
if (false !== stripos($string, 'g')) {
// has a G in it, remove the G and multiply by (1024)^3.
$bytes = bcmul(rtrim($string, 'g'), '1073741824');
- return (int) $bytes;
+ return (int)$bytes;
}
- return (int) $string;
+ return (int)$string;
}
public function positive(string $amount): string
@@ -851,12 +889,12 @@ class Steam
if (null === $preference) {
$singleton->setPreference($key, $currency);
}
- $current = $amount;
+ $current = $amount;
if ($currency->id !== $primary->id) {
$current = $converter->convert($currency, $primary, $date, $amount);
Log::debug(sprintf('Convert %s %s to %s %s', $currency->code, $amount, $primary->code, $current));
}
- $total = bcadd((string) $current, $total);
+ $total = bcadd((string)$current, $total);
}
return $total;
@@ -870,18 +908,18 @@ class Steam
$primary = Amount::getPrimaryCurrency();
$currencies[$primary->id] = $primary;
- $ids = $accounts->pluck('id')->toArray();
- $result = AccountMeta::query()->whereIn('account_id', $ids)->where('name', 'currency_id')->get();
+ $ids = $accounts->pluck('id')->toArray();
+ $result = AccountMeta::query()->whereIn('account_id', $ids)->where('name', 'currency_id')->get();
/** @var AccountMeta $item */
foreach ($result as $item) {
- $integer = (int) $item->data;
+ $integer = (int)$item->data;
if (0 !== $integer) {
- $accountPreferences[(int) $item->account_id] = $integer;
+ $accountPreferences[(int)$item->account_id] = $integer;
}
}
// collect those currencies, skip primary because we already have it.
- $set = TransactionCurrency::query()->whereIn('id', $accountPreferences)->where('id', '!=', $primary->id)->get();
+ $set = TransactionCurrency::query()->whereIn('id', $accountPreferences)->where('id', '!=', $primary->id)->get();
foreach ($set as $item) {
$currencies[$item->id] = $item;
}
@@ -892,7 +930,7 @@ class Steam
$currencyPresent = property_exists($account, 'meta') && array_key_exists('currency', $account->meta) && null !== $account->meta['currency'];
if ($currencyPresent) {
$currencyId = $account->meta['currency']->id;
- $currencies[$currencyId] ??= $account->meta['currency'];
+ $currencies[$currencyId] ??= $account->meta['currency'];
$accountCurrencies[$accountId] = $account->meta['currency'];
}
if (!$currencyPresent && !array_key_exists($accountId, $accountPreferences)) {
@@ -912,7 +950,7 @@ class Steam
foreach ($array as $item) {
$groupKey = $item[$group] ?? 'unknown';
- $return[$groupKey] = bcadd($return[$groupKey] ?? '0', (string) $item[$field]);
+ $return[$groupKey] = bcadd($return[$groupKey] ?? '0', (string)$item[$field]);
}
return $return;
diff --git a/changelog.md b/changelog.md
index 2c8099a3b8..e62e159c6c 100644
--- a/changelog.md
+++ b/changelog.md
@@ -38,6 +38,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- [Issue 12455](https://github.com/firefly-iii/firefly-iii/issues/12455) (native_amount conversion uses now() instead of transaction date) reported by @tarzan77cz
- [Issue 12468](https://github.com/firefly-iii/firefly-iii/issues/12468) (Weekly subscription not accounted to be paid if there were already a payment on that month) reported by @brunofontes
- [Issue 12500](https://github.com/firefly-iii/firefly-iii/issues/12500) (Subscriptions widget show incorrect numbers.) reported by @wascarreyes01
+- #12559
- [Issue 12577](https://github.com/firefly-iii/firefly-iii/issues/12577) (API: /accounts endpoint never returns credit_card_type / monthly_payment_date (missing from AccountEnrichment allowlist)) reported by @chigia001
- [Issue 12578](https://github.com/firefly-iii/firefly-iii/issues/12578) (API PUT/POST /accounts stores monthly_payment_date in a format incompatible with the web UI's date input) reported by @chigia001
- [Discussion 12583](https://github.com/orgs/firefly-iii/discussions/12583) (How to search for non-foreign currency transactions) started by @skogsvik
@@ -48,6 +49,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- [PR 12642](https://github.com/firefly-iii/firefly-iii/pull/12642) (Fix [Issue 12639](https://github.com/firefly-iii/firefly-iii/issues/12639) (Test rules endpoint always returns no results unless optional accounts argument is passed) reported by @grgar: match accounts arg of rule trigger & test) reported by @grgar
- [Issue 12662](https://github.com/firefly-iii/firefly-iii/issues/12662) (A Search for Tags returns more page groups than required) reported by @PAS-BC
- [Issue 12687](https://github.com/firefly-iii/firefly-iii/issues/12687) (Changing budgeted amount in a budget deletes notes.) reported by @rdesbo
+- #12692
- #12694
- Setting an invalid language would break your account.