Skip to content

Firefly III: a personal finances manager

🤖 Auto commit for release 'develop' on 2026-09-06

JC574b3ffea345d
diff --git a/app/Api/V1/Controllers/Insight/Income/TagController.php b/app/Api/V1/Controllers/Insight/Income/TagController.php
index 94be2ae461..df99eef909 100644
--- a/app/Api/V1/Controllers/Insight/Income/TagController.php
+++ b/app/Api/V1/Controllers/Insight/Income/TagController.php
@@ -158,10 +158,7 @@ final class TagController extends Controller
'currency_id' => (string) $foreignCurrencyId,
'currency_code' => $journal['foreign_currency_code'],
];
- $response[$foreignKey]['difference'] = bcadd(
- (string) $response[$foreignKey]['difference'],
- Steam::positive($journal['foreign_amount'])
- );
+ $response[$foreignKey]['difference'] = bcadd((string) $response[$foreignKey]['difference'], Steam::positive($journal['foreign_amount']));
$response[$foreignKey]['difference_float'] = (float) $response[$foreignKey]['difference'];
}
}
diff --git a/app/Api/V1/Controllers/Insight/Transfer/TagController.php b/app/Api/V1/Controllers/Insight/Transfer/TagController.php
index b7b85fd376..f92a7aa9f0 100644
--- a/app/Api/V1/Controllers/Insight/Transfer/TagController.php
+++ b/app/Api/V1/Controllers/Insight/Transfer/TagController.php
@@ -155,10 +155,7 @@ final class TagController extends Controller
'currency_id' => (string) $foreignCurrencyId,
'currency_code' => $journal['foreign_currency_code'],
];
- $response[$foreignKey]['difference'] = bcadd(
- (string) $response[$foreignKey]['difference'],
- Steam::positive($journal['foreign_amount'])
- );
+ $response[$foreignKey]['difference'] = bcadd((string) $response[$foreignKey]['difference'], Steam::positive($journal['foreign_amount']));
$response[$foreignKey]['difference_float'] = (float) $response[$foreignKey]['difference']; // intentional float
}
}
diff --git a/app/Http/Controllers/Budget/BudgetLimitController.php b/app/Http/Controllers/Budget/BudgetLimitController.php
index d461374baa..2edb4f5531 100644
--- a/app/Http/Controllers/Budget/BudgetLimitController.php
+++ b/app/Http/Controllers/Budget/BudgetLimitController.php
@@ -198,13 +198,7 @@ final class BudgetLimitController extends Controller
if ($request->expectsJson()) {
$array = $limit->toArray();
// add some extra metadata:
- $spentArr = $this->opsRepository->sumExpenses(
- $limit->start_date,
- $limit->end_date,
- null,
- new Collection()->push($budget),
- $currency
- );
+ $spentArr = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, null, new Collection()->push($budget), $currency);
$array['spent'] = $spentArr[$currency->id]['sum'] ?? '0';
$array['left_formatted'] = Amount::formatAnything($limit->transactionCurrency, bcadd($array['spent'], (string) $array['amount']));
$array['amount_formatted'] = Amount::formatAnything($limit->transactionCurrency, $limit['amount']);
diff --git a/app/Http/Controllers/Budget/IndexController.php b/app/Http/Controllers/Budget/IndexController.php
index d40d4432a3..215ebbd484 100644
--- a/app/Http/Controllers/Budget/IndexController.php
+++ b/app/Http/Controllers/Budget/IndexController.php
@@ -284,10 +284,7 @@ final class IndexController extends Controller
if (array_key_exists($currency->id, $spentArr) && array_key_exists('sum', $spentArr[$currency->id])) {
$array['spent'][$currency->id]['spent'] = $spentArr[$currency->id]['sum'];
- $array['spent'][$currency->id]['spent_outside'] = Steam::negative(bcsub(
- $spentInLimits[$currency->id],
- $spentArr[$currency->id]['sum']
- ));
+ $array['spent'][$currency->id]['spent_outside'] = Steam::negative(bcsub($spentInLimits[$currency->id], $spentArr[$currency->id]['sum']));
$array['spent'][$currency->id]['currency_id'] = $currency->id;
$array['spent'][$currency->id]['currency_symbol'] = $currency->symbol;
$array['spent'][$currency->id]['currency_decimal_places'] = $currency->decimal_places;
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index f4b32fe5c5..ad724137dc 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -539,13 +539,7 @@ final class BudgetController extends Controller
}
// get spent amount in this period for this currency.
- $sum = $this->opsRepository->sumExpenses(
- $currentStart,
- $currentEnd,
- $accounts,
- new Collection()->push($budget),
- $currency
- );
+ $sum = $this->opsRepository->sumExpenses($currentStart, $currentEnd, $accounts, new Collection()->push($budget), $currency);
$amount = Steam::positive($sum[$currency->id]['sum'] ?? '0');
$chartData[0]['entries'][$title] = Steam::bcround($amount, $currency->decimal_places);
diff --git a/app/Jobs/CreateAutoBudgetLimits.php b/app/Jobs/CreateAutoBudgetLimits.php
index affea656a0..476da65ac3 100644
--- a/app/Jobs/CreateAutoBudgetLimits.php
+++ b/app/Jobs/CreateAutoBudgetLimits.php
@@ -132,13 +132,7 @@ class CreateAutoBudgetLimits implements ShouldQueue
// if has one, calculate expenses and use that as a base.
$repository = app(OperationsRepositoryInterface::class);
$repository->setUser($autoBudget->budget->user);
- $spent = $repository->sumExpenses(
- $previousStart,
- $previousEnd,
- null,
- new Collection()->push($autoBudget->budget),
- $autoBudget->transactionCurrency
- );
+ $spent = $repository->sumExpenses($previousStart, $previousEnd, null, new Collection()->push($autoBudget->budget), $autoBudget->transactionCurrency);
$currencyId = $autoBudget->transaction_currency_id;
$spentAmount = $spent[$currencyId]['sum'] ?? '0';
Log::debug(sprintf('Spent in previous budget period (%s-%s) is %s', $previousStart->format('Y-m-d'), $previousEnd->format('Y-m-d'), $spentAmount));
@@ -228,13 +222,7 @@ class CreateAutoBudgetLimits implements ShouldQueue
// if has one, calculate expenses and use that as a base.
$repository = app(OperationsRepositoryInterface::class);
$repository->setUser($autoBudget->budget->user);
- $spent = $repository->sumExpenses(
- $previousStart,
- $previousEnd,
- null,
- new Collection()->push($autoBudget->budget),
- $autoBudget->transactionCurrency
- );
+ $spent = $repository->sumExpenses($previousStart, $previousEnd, null, new Collection()->push($autoBudget->budget), $autoBudget->transactionCurrency);
$currencyId = $autoBudget->transaction_currency_id;
$spentAmount = $spent[$currencyId]['sum'] ?? '0';
Log::debug(sprintf('Spent in previous budget period (%s-%s) is %s', $previousStart->format('Y-m-d'), $previousEnd->format('Y-m-d'), $spentAmount));
diff --git a/app/Services/Internal/Support/RecurringTransactionTrait.php b/app/Services/Internal/Support/RecurringTransactionTrait.php
index 802b09186c..2ea4ec7c99 100644
--- a/app/Services/Internal/Support/RecurringTransactionTrait.php
+++ b/app/Services/Internal/Support/RecurringTransactionTrait.php
@@ -338,6 +338,5 @@ trait RecurringTransactionTrait
}
$meta->value = $category->id;
$meta->save();
-
}
}
diff --git a/app/Services/Internal/Update/JournalUpdateService.php b/app/Services/Internal/Update/JournalUpdateService.php
index c3dd88822c..aea2682a4f 100644
--- a/app/Services/Internal/Update/JournalUpdateService.php
+++ b/app/Services/Internal/Update/JournalUpdateService.php
@@ -576,7 +576,6 @@ class JournalUpdateService
$this->transactionJournal->bill_id = $bill?->id;
Log::debug('Updated bill ID');
$this->transactionJournal->touch();
-
}
}
@@ -822,11 +821,13 @@ class JournalUpdateService
if (null === $this->data['longitude'] && null === $this->data['latitude'] && null === $this->data['zoom_level']) {
$this->transactionJournal->locations()->delete();
$this->transactionJournal->touch();
+
return;
}
if ('' === $this->data['longitude'] && '' === $this->data['latitude'] && null === $this->data['zoom_level']) {
$this->transactionJournal->locations()->delete();
$this->transactionJournal->touch();
+
return;
}
$location = $this->transactionJournal->locations()->first();
@@ -923,7 +924,6 @@ class JournalUpdateService
Log::debug('Will update tags.');
$tags = $this->data['tags'] ?? null;
$this->storeTags($this->transactionJournal, $tags);
-
}
}
diff --git a/app/Support/Http/Controllers/AugumentData.php b/app/Support/Http/Controllers/AugumentData.php
index a507156873..a3a940b1ba 100644
--- a/app/Support/Http/Controllers/AugumentData.php
+++ b/app/Support/Http/Controllers/AugumentData.php
@@ -222,14 +222,7 @@ trait AugumentData
$currentEnd->addMonth();
}
// primary currency amount.
- $expenses = $opsRepository->sumExpenses(
- $currentStart,
- $currentEnd,
- null,
- $budgetCollection,
- $entry->transactionCurrency,
- $this->convertToPrimary
- );
+ $expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $entry->transactionCurrency, $this->convertToPrimary);
$spent = $expenses[$currency->id]['sum'] ?? '0';
$entry->pc_spent = $spent;
diff --git a/app/Support/Http/Controllers/ChartGeneration.php b/app/Support/Http/Controllers/ChartGeneration.php
index 1a5ffc9d57..42cf732b1e 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/JsonApi/Enrichments/RecurringEnrichment.php b/app/Support/JsonApi/Enrichments/RecurringEnrichment.php
index 2428353cb0..d0c09bf027 100644
--- a/app/Support/JsonApi/Enrichments/RecurringEnrichment.php
+++ b/app/Support/JsonApi/Enrichments/RecurringEnrichment.php
@@ -354,11 +354,7 @@ class RecurringEnrichment implements EnrichmentInterface
/** @var RecurrenceRepetition $repetition */
foreach ($set as $repetition) {
- $recurrence = $this->collection->filter(
- static fn (Recurrence $item): bool => (int) $item->id === (int) $repetition->recurrence_id
- )
- ->first()
- ;
+ $recurrence = $this->collection->filter(static fn (Recurrence $item): bool => (int) $item->id === (int) $repetition->recurrence_id)->first();
$fromDate = clone ($recurrence->latest_date ?? $recurrence->first_date);
$recurrenceId = (int) $repetition->recurrence_id;
$repId = (int) $repetition->id;
diff --git a/app/Support/Steam.php b/app/Support/Steam.php
index b7dd7f20d3..a48a6642d2 100644
--- a/app/Support/Steam.php
+++ b/app/Support/Steam.php
@@ -43,6 +43,7 @@ use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Safe\Exceptions\UrlException;
use ValueError;
+
use function Safe\parse_url;
use function Safe\preg_replace;
@@ -56,13 +57,12 @@ 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,43 +70,43 @@ 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) {
// this key is overwritten right away, but I must remember it is always created.
- $currency = $currencies[$account->id];
- $return = [
+ $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';
+ $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);
@@ -120,23 +120,23 @@ class Steam
}
// 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".
- if(array_key_exists($currency->code, $sumsByCode)) {
+ if (array_key_exists($currency->code, $sumsByCode)) {
// overwrite balance, but add virtual balance to it.
$return['balance'] = bcadd($sumsByCode[$currency->code], $virtualBalance);
}
@@ -153,10 +153,9 @@ class Steam
// Log::debug(sprintf('Set pc_balance to %s', $return['pc_balance']));
}
-
if ($convertToPrimary) {
// the primary currency balance is combined with a converted virtual_balance:
- $converter = new ExchangeRateConverter();
+ $converter = new ExchangeRateConverter();
// $return['pc_balance'] = bcadd($pcVirtualBalance, $return['pc_balance']);
$sumsByCode[$primary->code] = bcadd($pcVirtualBalance, $sumsByCode[$primary->code]);
@@ -172,7 +171,7 @@ class Steam
$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;
@@ -210,10 +209,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;
@@ -355,23 +354,21 @@ 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) {
@@ -381,25 +378,26 @@ 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';
@@ -416,7 +414,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:
@@ -432,7 +430,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);
@@ -450,7 +448,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);
@@ -459,28 +457,28 @@ 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:
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);
+ $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);
+ $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)) {
@@ -491,23 +489,23 @@ class Steam
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);
+ $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, $startBalance[$primaryCurrency->code]));
}
}
if (!$hasCurrency) {
Log::debug(sprintf('[e] Also set start balance in %s', $primaryCurrency->code));
- $startBalance[$primaryCurrency->code] = (string)('' === (string)$account->virtual_balance ? '0' : $account->virtual_balance);
+ $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'))
@@ -516,50 +514,51 @@ 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);
@@ -576,26 +575,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
@@ -619,7 +618,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),
@@ -630,8 +629,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;
@@ -642,8 +641,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)) {
@@ -654,7 +653,7 @@ class Steam
return null;
}
- return Amount::getTransactionCurrencyById((int)$result->data);
+ return Amount::getTransactionCurrencyById((int) $result->data);
}
public function getHostName(string $ipAddress): string
@@ -668,11 +667,11 @@ class Steam
$hostName = $ipAddress;
}
- if ('' !== (string)$hostName && $hostName !== $ipAddress) {
+ if ('' !== (string) $hostName && $hostName !== $ipAddress) {
$host = $hostName;
}
- return (string)$host;
+ return (string) $host;
}
/**
@@ -696,18 +695,19 @@ 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;
@@ -723,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))) {
@@ -770,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 {
@@ -833,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
@@ -889,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;
@@ -908,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;
}
@@ -930,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)) {
@@ -950,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/app/Validation/RecurrenceValidation.php b/app/Validation/RecurrenceValidation.php
index 4bfe19fecc..0064977d4f 100644
--- a/app/Validation/RecurrenceValidation.php
+++ b/app/Validation/RecurrenceValidation.php
@@ -47,7 +47,7 @@ trait RecurrenceValidation
$repetitions = $data['repetitions'] ?? [];
// need at least one transaction
if (!is_countable($repetitions) || 0 === count($repetitions)) {
- $validator->errors()->add('repetitions', (string)trans('validation.at_least_one_repetition'));
+ $validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition'));
}
}
@@ -63,7 +63,7 @@ trait RecurrenceValidation
}
// need at least one transaction
if (0 === count($repetitions)) {
- $validator->errors()->add('repetitions', (string)trans('validation.at_least_one_repetition'));
+ $validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition'));
}
}
@@ -78,15 +78,15 @@ trait RecurrenceValidation
$repeatUntil = $data['repeat_until'] ?? null;
if (null !== $repetitions && null !== $repeatUntil) {
// expect a date OR count:
- $validator->errors()->add('repeat_until', (string)trans('validation.require_repeat_until'));
- $validator->errors()->add('nr_of_repetitions', (string)trans('validation.require_repeat_until'));
+ $validator->errors()->add('repeat_until', (string) trans('validation.require_repeat_until'));
+ $validator->errors()->add('nr_of_repetitions', (string) trans('validation.require_repeat_until'));
}
}
public function validateRecurringConfig(Validator $validator): void
{
$data = $validator->getData();
- $reps = array_key_exists('nr_of_repetitions', $data) ? (int)$data['nr_of_repetitions'] : null;
+ $reps = array_key_exists('nr_of_repetitions', $data) ? (int) $data['nr_of_repetitions'] : null;
$repeatUntil = array_key_exists('repeat_until', $data) ? new Carbon($data['repeat_until']) : null;
if (null === $reps && !$repeatUntil instanceof Carbon) {
@@ -106,7 +106,7 @@ trait RecurrenceValidation
$data = $validator->getData();
$repetitions = $data['repetitions'] ?? [];
if (!is_array($repetitions)) {
- $validator->errors()->add(sprintf('repetitions.%d.type', 0), (string)trans('validation.valid_recurrence_rep_type'));
+ $validator->errors()->add(sprintf('repetitions.%d.type', 0), (string) trans('validation.valid_recurrence_rep_type'));
return;
}
@@ -125,32 +125,32 @@ trait RecurrenceValidation
switch ($repetition['type'] ?? 'empty') {
default:
- $validator->errors()->add(sprintf('repetitions.%d.type', $index), (string)trans('validation.valid_recurrence_rep_type'));
+ $validator->errors()->add(sprintf('repetitions.%d.type', $index), (string) trans('validation.valid_recurrence_rep_type'));
return;
case 'daily':
- $this->validateDaily($validator, $index, (string)$repetition['moment']);
+ $this->validateDaily($validator, $index, (string) $repetition['moment']);
break;
case 'monthly':
- $this->validateMonthly($validator, $index, (int)$repetition['moment']);
+ $this->validateMonthly($validator, $index, (int) $repetition['moment']);
break;
case 'ndom':
- $this->validateNdom($validator, $index, (string)$repetition['moment']);
+ $this->validateNdom($validator, $index, (string) $repetition['moment']);
break;
case 'weekly':
- $this->validateWeekly($validator, $index, (int)$repetition['moment']);
+ $this->validateWeekly($validator, $index, (int) $repetition['moment']);
break;
case 'yearly':
- $this->validateYearly($validator, $index, (string)$repetition['moment']);
+ $this->validateYearly($validator, $index, (string) $repetition['moment']);
break;
}
@@ -164,33 +164,33 @@ trait RecurrenceValidation
*/
public function valUpdateAccountInfo(Validator $validator): void
{
- $data = $validator->getData();
+ $data = $validator->getData();
/** @var null|Recurrence $recurrence */
- $recurrence = $this->route()?->parameter('recurrence');
- $transactionType = $this->getRecurrenceType($data, $recurrence);
- $transactions = $data['transactions'] ?? [];
+ $recurrence = $this->route()?->parameter('recurrence');
+ $transactionType = $this->getRecurrenceType($data, $recurrence);
+ $transactions = $data['transactions'] ?? [];
/** @var AccountValidator $accountValidator */
$accountValidator = app(AccountValidator::class);
Log::debug(sprintf('Going to loop %d transaction(s)', count($transactions)));
foreach ($transactions as $index => $transaction) {
- $currentType = $transaction['type'] ?? $transactionType;
+ $currentType = $transaction['type'] ?? $transactionType;
$accountValidator->setTransactionType($currentType);
- $hasSource = array_key_exists('source_id', $transaction) || array_key_exists('source_name', $transaction);
- $hasDestination = array_key_exists('destination_id', $transaction) || array_key_exists('destination_name', $transaction);
+ $hasSource = array_key_exists('source_id', $transaction) || array_key_exists('source_name', $transaction);
+ $hasDestination = array_key_exists('destination_id', $transaction) || array_key_exists('destination_name', $transaction);
if (!$hasSource && !$hasDestination) {
continue;
}
- $original = $this->getOriginalRecurrenceTransaction($recurrence, $transaction);
+ $original = $this->getOriginalRecurrenceTransaction($recurrence, $transaction);
// validate source account.
- $sourceId = $hasSource ? (int)($transaction['source_id'] ?? 0) : $original?->source_id;
- $sourceName = $hasSource ? $transaction['source_name'] ?? null : null;
- $validSource = $accountValidator->validateSource(['id' => $sourceId, 'name' => $sourceName]);
+ $sourceId = $hasSource ? (int) ($transaction['source_id'] ?? 0) : $original?->source_id;
+ $sourceName = $hasSource ? $transaction['source_name'] ?? null : null;
+ $validSource = $accountValidator->validateSource(['id' => $sourceId, 'name' => $sourceName]);
// do something with result:
if (false === $validSource) {
@@ -200,7 +200,7 @@ trait RecurrenceValidation
return;
}
// validate destination account
- $destinationId = $hasDestination ? (int)($transaction['destination_id'] ?? 0) : $original?->destination_id;
+ $destinationId = $hasDestination ? (int) ($transaction['destination_id'] ?? 0) : $original?->destination_id;
$destinationName = $hasDestination ? $transaction['destination_name'] ?? null : null;
$validDestination = $accountValidator->validateDestination(['id' => $destinationId, 'name' => $destinationName]);
// do something with result:
@@ -213,29 +213,13 @@ trait RecurrenceValidation
}
}
- private function getOriginalRecurrenceTransaction(?Recurrence $recurrence, array $transaction): ?RecurrenceTransaction
- {
- if (!$recurrence instanceof Recurrence) {
- return null;
- }
- $collection = $recurrence->recurrenceTransactions;
- $id = (int)($transaction['id'] ?? 0);
- // without an ID it is only unambiguous when the recurrence has exactly one transaction.
- if (0 === $id && 1 !== $collection->count()) {
- return null;
- }
- $result = 0 === $id ? $collection->first() : $collection->firstWhere('id', $id);
-
- return $result instanceof RecurrenceTransaction ? $result : null;
- }
-
/**
* If the repetition type is daily, the moment should be empty.
*/
protected function validateDaily(Validator $validator, int $index, string $moment): void
{
if ('' !== $moment) {
- $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
+ $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
}
}
@@ -245,7 +229,7 @@ trait RecurrenceValidation
protected function validateMonthly(Validator $validator, int $index, int $dayOfMonth): void
{
if ($dayOfMonth < 1 || $dayOfMonth > 31) {
- $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
+ $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
}
}
@@ -257,19 +241,19 @@ trait RecurrenceValidation
{
$parameters = explode(',', $moment);
if (2 !== count($parameters)) {
- $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
+ $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
return;
}
- $nthDay = (int)$parameters[0];
- $dayOfWeek = (int)$parameters[1];
+ $nthDay = (int) $parameters[0];
+ $dayOfWeek = (int) $parameters[1];
if ($nthDay < 1 || $nthDay > 5) {
- $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
+ $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
return;
}
if ($dayOfWeek < 1 || $dayOfWeek > 7) {
- $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
+ $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
}
}
@@ -284,29 +268,29 @@ trait RecurrenceValidation
if (0 === $submittedTrCount) {
Log::warning('[b] User submitted no transactions.');
- $validator->errors()->add('transactions', (string)trans('validation.at_least_one_transaction'));
+ $validator->errors()->add('transactions', (string) trans('validation.at_least_one_transaction'));
return;
}
- $originalTrCount = $recurrence->recurrenceTransactions()->count();
+ $originalTrCount = $recurrence->recurrenceTransactions()->count();
if (1 === $submittedTrCount && 1 === $originalTrCount) {
- $first = $transactions[0]; // can safely assume index 0.
+ $first = $transactions[0]; // can safely assume index 0.
if (!array_key_exists('id', $first)) {
Log::debug('Single count and no ID, done.');
return; // home safe!
}
- $id = $first['id'];
- if ('' === (string)$id) {
+ $id = $first['id'];
+ if ('' === (string) $id) {
Log::debug('Single count and empty ID, done.');
return; // home safe!
}
- $integer = (int)$id;
+ $integer = (int) $id;
$secondCount = $recurrence->recurrenceTransactions()->where('recurrences_transactions.id', $integer)->count();
Log::debug(sprintf('Result of ID count: %d', $secondCount));
if (0 === $secondCount) {
- $validator->errors()->add('transactions.0.id', (string)trans('validation.id_does_not_match', ['id' => $integer]));
+ $validator->errors()->add('transactions.0.id', (string) trans('validation.id_does_not_match', ['id' => $integer]));
}
Log::debug('Single ID validation done.');
@@ -314,7 +298,7 @@ trait RecurrenceValidation
}
Log::debug('Multi ID validation.');
- $idsMandatory = false;
+ $idsMandatory = false;
if ($submittedTrCount < $originalTrCount) {
Log::debug(sprintf('User submits %d transaction, recurrence has %d transactions. All entries must have ID.', $submittedTrCount, $originalTrCount));
$idsMandatory = true;
@@ -331,19 +315,19 @@ trait RecurrenceValidation
* 2. If the user submits more transactions than already present, count the number of existing transactions. At least those must be matched. After that, submit as many as you like.
* 3. If the user submits the same number of transactions as already present, all but one must have an ID.
*/
- $unmatchedIds = 0;
+ $unmatchedIds = 0;
foreach ($transactions as $index => $transaction) {
Log::debug(sprintf('Now at %d/%d', $index + 1, $submittedTrCount));
if (!is_array($transaction)) {
Log::warning('Not an array. Give error.');
- $validator->errors()->add(sprintf('transactions.%d.id', $index), (string)trans('validation.at_least_one_transaction'));
+ $validator->errors()->add(sprintf('transactions.%d.id', $index), (string) trans('validation.at_least_one_transaction'));
return;
}
if (!array_key_exists('id', $transaction) && $idsMandatory) {
Log::warning('ID is mandatory but array has no ID.');
- $validator->errors()->add(sprintf('transactions.%d.id', $index), (string)trans('validation.need_id_to_match'));
+ $validator->errors()->add(sprintf('transactions.%d.id', $index), (string) trans('validation.need_id_to_match'));
return;
}
@@ -351,8 +335,9 @@ trait RecurrenceValidation
Log::debug('Array has ID.');
$idCount = $recurrence
->recurrenceTransactions()
- ->where('recurrences_transactions.id', (int)$transaction['id'])
- ->count();
+ ->where('recurrences_transactions.id', (int) $transaction['id'])
+ ->count()
+ ;
if (0 === $idCount) {
Log::debug('ID does not exist or no match. Count another unmatched ID.');
++$unmatchedIds;
@@ -364,11 +349,11 @@ trait RecurrenceValidation
}
}
// if too many don't match, but you haven't submitted more than already present:
- $maxUnmatched = max(1, $submittedTrCount - $originalTrCount);
+ $maxUnmatched = max(1, $submittedTrCount - $originalTrCount);
Log::debug(sprintf('Submitted: %d. Original: %d. User can submit %d unmatched transactions.', $submittedTrCount, $originalTrCount, $maxUnmatched));
if ($unmatchedIds > $maxUnmatched) {
Log::warning(sprintf('Too many unmatched transactions (%d).', $unmatchedIds));
- $validator->errors()->add('transactions.0.id', (string)trans('validation.too_many_unmatched'));
+ $validator->errors()->add('transactions.0.id', (string) trans('validation.too_many_unmatched'));
return;
}
@@ -381,7 +366,7 @@ trait RecurrenceValidation
protected function validateWeekly(Validator $validator, int $index, int $dayOfWeek): void
{
if ($dayOfWeek < 1 || $dayOfWeek > 7) {
- $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
+ $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
}
}
@@ -394,10 +379,26 @@ trait RecurrenceValidation
Carbon::createFromFormat('Y-m-d', $moment);
} catch (InvalidArgumentException $e) {
Log::debug(sprintf('Invalid argument for Carbon: %s', $e->getMessage()));
- $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
+ $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
}
}
+ private function getOriginalRecurrenceTransaction(?Recurrence $recurrence, array $transaction): ?RecurrenceTransaction
+ {
+ if (!$recurrence instanceof Recurrence) {
+ return null;
+ }
+ $collection = $recurrence->recurrenceTransactions;
+ $id = (int) ($transaction['id'] ?? 0);
+ // without an ID it is only unambiguous when the recurrence has exactly one transaction.
+ if (0 === $id && 1 !== $collection->count()) {
+ return null;
+ }
+ $result = 0 === $id ? $collection->first() : $collection->firstWhere('id', $id);
+
+ return $result instanceof RecurrenceTransaction ? $result : null;
+ }
+
/**
* Determine the transaction type to validate the submitted accounts against: the submitted type wins, then the
* type of the recurrence itself.
@@ -406,7 +407,7 @@ trait RecurrenceValidation
{
$transactionType = $data['type'] ?? 'invalid';
if ('invalid' !== $transactionType && in_array(ucfirst($transactionType), array_keys(config('firefly.transactionTypesToShort')), true)) {
- return (string)$transactionType;
+ return (string) $transactionType;
}
if (!$recurrence instanceof Recurrence) {
@@ -414,12 +415,12 @@ trait RecurrenceValidation
return 'withdrawal';
}
- $transactionType = (string)$recurrence->transactionType?->type;
+ $transactionType = (string) $recurrence->transactionType?->type;
/** @var null|RecurrenceTransaction $first */
- $first = $recurrence->recurrenceTransactions()->first();
+ $first = $recurrence->recurrenceTransactions()->first();
if (null !== $first?->transactionType) {
- $transactionType = (string)$first->transactionType->type;
+ $transactionType = (string) $first->transactionType->type;
}
if ('' === $transactionType) {
diff --git a/changelog.md b/changelog.md
index e62e159c6c..9dc2256cc0 100644
--- a/changelog.md
+++ b/changelog.md
@@ -38,7 +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
+- [Discussion 12559](https://github.com/orgs/firefly-iii/discussions/12559) (Credit Card Balance vs Available Credit) started by @SWellock
- [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
@@ -49,8 +49,8 @@ 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
+- [Issue 12692](https://github.com/firefly-iii/firefly-iii/issues/12692) (Updating accounts of a deposit recurrence via API is rejected because the validator assumes "withdrawal") reported by @Toshik1978
+- [Issue 12694](https://github.com/firefly-iii/firefly-iii/issues/12694) (Updating an amount in transaction doesn't make it discoverable in search using `updated_at_after:`) reported by @Toshik1978
- Setting an invalid language would break your account.
### Security
diff --git a/composer.lock b/composer.lock
index 93ba62d69d..876947996c 100644
--- a/composer.lock
+++ b/composer.lock
@@ -10197,16 +10197,16 @@
},
{
"name": "carthage-software/mago",
- "version": "1.47.5",
+ "version": "1.47.6",
"source": {
"type": "git",
"url": "https://github.com/carthage-software/mago.git",
- "reference": "3d6c87dccaa74b4048b90e208abe7f2832114f2e"
+ "reference": "ad48106b8d1dbf3140f3a4bd4d244a5e47c9e495"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/carthage-software/mago/zipball/3d6c87dccaa74b4048b90e208abe7f2832114f2e",
- "reference": "3d6c87dccaa74b4048b90e208abe7f2832114f2e",
+ "url": "https://api.github.com/repos/carthage-software/mago/zipball/ad48106b8d1dbf3140f3a4bd4d244a5e47c9e495",
+ "reference": "ad48106b8d1dbf3140f3a4bd4d244a5e47c9e495",
"shasum": ""
},
"require": {
@@ -10248,7 +10248,7 @@
],
"support": {
"issues": "https://github.com/carthage-software/mago/issues",
- "source": "https://github.com/carthage-software/mago/tree/1.47.5"
+ "source": "https://github.com/carthage-software/mago/tree/1.47.6"
},
"funding": [
{
@@ -10256,7 +10256,7 @@
"type": "github"
}
],
- "time": "2026-09-02T16:54:06+00:00"
+ "time": "2026-09-04T17:48:48+00:00"
},
{
"name": "cloudcreativity/json-api-testing",
diff --git a/config/firefly.php b/config/firefly.php
index 28d8a118ae..13a7e30df3 100644
--- a/config/firefly.php
+++ b/config/firefly.php
@@ -78,8 +78,8 @@ return [
'running_balance_column' => (bool)env_default_when_empty(env('USE_RUNNING_BALANCE'), true), // this is only the default value, is not used.
// see cer.php for exchange rates feature flag.
],
-'version' => 'develop/2026-09-04',
-'build_time' => 1788513491,
+'version' => 'develop/2026-09-06',
+'build_time' => 1788673381,
'api_version' => '2.1.0', // field is no longer used.
'db_version' => 28, // field is no longer used.
diff --git a/package-lock.json b/package-lock.json
index d681bbb86a..ed5d8ea9fa 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -47,21 +47,21 @@
"license": "MIT"
},
"node_modules/@full-ui/headless-calendar": {
- "version": "7.0.2",
- "resolved": "https://registry.npmjs.org/@full-ui/headless-calendar/-/headless-calendar-7.0.2.tgz",
- "integrity": "sha512-i6UlTNjBVuiBca5Sq6OoLxFqK6eaQ/v1XOLObjRkzXLuSuNn+qs9/dUvlzrbeesn7QbRH7+u7lyvlQyq8WvmGA==",
+ "version": "7.1.0",
+ "resolved": "https://registry.npmjs.org/@full-ui/headless-calendar/-/headless-calendar-7.1.0.tgz",
+ "integrity": "sha512-T54tSUik/ia9Jj4xduFHv1p98eVBgLnE33Q6qhpg+WWkqKCLBCbtVyMcTPPIOP5jjTV2MbtjrRvRt1RLSryGHA==",
"license": "MIT",
"peerDependencies": {
"temporal-polyfill": "^1.0.1"
}
},
"node_modules/@fullcalendar/core": {
- "version": "7.0.2",
- "resolved": "https://registry.npmjs.org/@fullcalendar/core/-/core-7.0.2.tgz",
- "integrity": "sha512-EkhE1wkPttp5kKNmUNLsMwl8nUuQmLdj30SPKagOEWMJUE4AHETAu/F/SbYoRq+nksm2GWPe9cQs1kbQP2H9pA==",
+ "version": "7.1.0",
+ "resolved": "https://registry.npmjs.org/@fullcalendar/core/-/core-7.1.0.tgz",
+ "integrity": "sha512-a+ABP7zQpPWpwPT8EsOdShpeOVrJyx/XYStqERd8ibld/FLi/dzpd95r7w3RIdFqFm9iUv0gdGvBshSlI/dbPw==",
"license": "MIT",
"peerDependencies": {
- "@full-ui/headless-calendar": "7.0.2",
+ "@full-ui/headless-calendar": "7.1.0",
"temporal-polyfill": "^1.0.1"
}
},
@@ -1290,14 +1290,14 @@
}
},
"node_modules/fullcalendar": {
- "version": "7.0.2",
- "resolved": "https://registry.npmjs.org/fullcalendar/-/fullcalendar-7.0.2.tgz",
- "integrity": "sha512-xqt/4CrnabOUVfu5PExyc6plbwH8QA1jAusRw6JOUfS+BmpA19W74lNLDty6EO0H+2cm/qVMza4TgQiJLHPAqQ==",
+ "version": "7.1.0",
+ "resolved": "https://registry.npmjs.org/fullcalendar/-/fullcalendar-7.1.0.tgz",
+ "integrity": "sha512-Pvr/fLrwuwfIjRygNKHJdHFJ8QGWjkAf6FFaMAi7Iv/fFftZQXV49smJE8KTgSVW/GxrqjN5t5Zw2OBTRKcnzA==",
"license": "MIT",
"dependencies": {
- "@full-ui/headless-calendar": "7.0.2",
- "@fullcalendar/core": "7.0.2",
- "preact": "^10.29.0"
+ "@full-ui/headless-calendar": "7.1.0",
+ "@fullcalendar/core": "7.1.0",
+ "preact": "^10.29.8"
},
"peerDependencies": {
"temporal-polyfill": "^1.0.1"