Compare commits

..

14 Commits

Author SHA1 Message Date
github-actions[bot]
44fc00299c Merge pull request #10742 from firefly-iii/release-1754883400
🤖 Automatically merge the PR into the develop branch.
2025-08-11 05:36:47 +02:00
JC5
774fc4281c 🤖 Auto commit for release 'develop' on 2025-08-11 2025-08-11 05:36:40 +02:00
github-actions[bot]
c47955c069 Merge pull request #10741 from firefly-iii/release-1754821000
🤖 Automatically merge the PR into the develop branch.
2025-08-10 12:16:47 +02:00
JC5
e7569644f7 🤖 Auto commit for release 'develop' on 2025-08-10 2025-08-10 12:16:41 +02:00
James Cole
c567474043 Optimize balance collection. 2025-08-10 12:12:30 +02:00
github-actions[bot]
9f394e92fe Merge pull request #10740 from firefly-iii/release-1754804137
🤖 Automatically merge the PR into the develop branch.
2025-08-10 07:35:46 +02:00
JC5
66befc7e44 🤖 Auto commit for release 'develop' on 2025-08-10 2025-08-10 07:35:37 +02:00
James Cole
c3a28fc698 Fix three years ago. 2025-08-10 07:31:10 +02:00
github-actions[bot]
ef317d5b3c Merge pull request #10739 from firefly-iii/release-1754802161
🤖 Automatically merge the PR into the develop branch.
2025-08-10 07:02:58 +02:00
JC5
152301f9ee 🤖 Auto commit for release 'develop' on 2025-08-10 2025-08-10 07:02:41 +02:00
James Cole
645e9ba1f7 Go back 3 years max. 2025-08-10 06:58:06 +02:00
James Cole
56487c3a33 Fix equation. 2025-08-10 06:54:04 +02:00
James Cole
b8062a915c Fix equation. 2025-08-10 06:53:21 +02:00
James Cole
5780c9512a Optimize convert all balances. 2025-08-10 06:53:08 +02:00
9 changed files with 89 additions and 65 deletions

View File

@@ -118,6 +118,13 @@ class ShowController extends Controller
$chartUrl = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
$firstTransaction = $this->repository->oldestJournalDate($account) ?? $start;
// go back max 3 years.
$threeYearsAgo = clone $start;
$threeYearsAgo->startOfYear()->subYears(3);
if ($firstTransaction->lt($threeYearsAgo)) {
$firstTransaction = clone $threeYearsAgo;
}
Log::debug('Start period overview');
$timer = Timer::getInstance();
$timer->start('period-overview');

View File

@@ -118,7 +118,7 @@ class AccountController extends Controller
Log::debug(sprintf('expenseAccounts: accountsBalancesOptimized("%s")', $end->format('Y-m-d H:i:s')));
$startBalances = Steam::accountsBalancesOptimized($accounts, $start, $this->primaryCurrency, $this->convertToPrimary);
$endBalances = Steam::accountsBalancesOptimized($accounts, $end, $this->primaryCurrency, $this->convertToPrimary);
Log::debug('Done collecting balances');
// loop the accounts, then check for balance and currency info.
foreach ($accounts as $account) {
// Log::debug(sprintf('[a] Now in account #%d ("%s")', $account->id, $account->name));

View File

@@ -345,7 +345,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
private function getLastPaidDate(array $paidData): ?Carbon
{
Log::debug('getLastPaidDate()');
// Log::debug('getLastPaidDate()');
$return = null;
foreach ($paidData as $entry) {
if (null !== $return) {
@@ -354,15 +354,15 @@ class SubscriptionEnrichment implements EnrichmentInterface
if ($current->gt($return)) {
$return = clone $current;
}
Log::debug(sprintf('Last paid date is: %s', $return->format('Y-m-d')));
Log::debug(sprintf('[a] Last paid date is: %s', $return->format('Y-m-d')));
}
if (null === $return) {
/** @var Carbon $return */
$return = $entry['date_object'];
Log::debug(sprintf('Last paid date is: %s', $return->format('Y-m-d')));
Log::debug(sprintf('[b] Last paid date is: %s', $return->format('Y-m-d')));
}
}
Log::debug(sprintf('Last paid date is: "%s"', $return?->format('Y-m-d')));
Log::debug(sprintf('[c] Last paid date is: "%s"', $return?->format('Y-m-d')));
return $return;
}

View File

@@ -32,6 +32,7 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
use FireflyIII\Support\Singleton\PreferencesSingleton;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
@@ -321,45 +322,54 @@ class Steam
public function accountsBalancesOptimized(Collection $accounts, Carbon $date, ?TransactionCurrency $primary = null, ?bool $convertToPrimary = null): array
{
Log::debug(sprintf('accountsBalancesOptimized: Called with date/time "%s"', $date->toIso8601String()));
$result = [];
Log::debug(sprintf('accountsBalancesOptimized: Called for %d account(s) with date/time "%s"', $accounts->count(), $date->toIso8601String()));
$result = [];
$convertToPrimary ??= Amount::convertToPrimary();
$primary ??= Amount::getPrimaryCurrency();
$currencies = $this->getCurrencies($accounts);
$currencies = $this->getCurrencies($accounts);
// balance(s) in all currencies for ALL accounts.
$array = Transaction::whereIn('account_id', $accounts->pluck('id')->toArray())
$arrayOfSums = Transaction::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', '<=', $date->format('Y-m-d H:i:s'))
->get(['transactions.account_id', 'transaction_currencies.code', 'transactions.amount'])->toArray()
->groupBy(['transactions.account_id', 'transaction_currencies.code'])
->get(['transactions.account_id', 'transaction_currencies.code', DB::raw('SUM(transactions.amount) as sum_of_amount')])->toArray()
;
/** @var Account $account */
foreach ($accounts as $account) {
// filter array back to this account:
$filtered = array_filter($array, function ($item) use ($account) {
return (int)$item['account_id'] === $account->id;
});
$currency = $currencies[$account->id];
// this array is PER account, so we wait a bit before we change code here.
$return = [
'pc_balance' => '0',
'balance' => '0', // this key is overwritten right away, but I must remember it is always created.
];
$currency = $currencies[$account->id];
// second array
$accountSum = array_filter($arrayOfSums, function ($entry) use ($account) {
return $entry['account_id'] === $account->id;
});
if (0 === count($accountSum)) {
$result[$account->id] = $return;
continue;
}
$accountSum = array_values($accountSum)[0];
$sumsByCode = [
$accountSum['code'] => $accountSum['sum_of_amount'],
];
// balance(s) in all currencies.
$others = $this->groupAndSumTransactions($filtered, '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';
$return['balance'] = $sumsByCode[$currency->code] ?? '0';
if (!$convertToPrimary) {
unset($return['pc_balance']);
// Log::debug(sprintf('Set balance to %s, unset pc_balance', $return['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) {
$return['pc_balance'] = $this->convertAllBalances($others, $primary, $date); // todo sum all and convert.
$return['pc_balance'] = $this->convertAllBalances($sumsByCode, $primary, $date);
// Log::debug(sprintf('Set pc_balance to %s', $return['pc_balance']));
}
@@ -378,7 +388,7 @@ class Steam
$return['balance'] = bcadd($return['balance'], $virtualBalance);
// Log::debug(sprintf('Virtual balance makes the (primary currency) total %s', $return['balance']));
}
$final = array_merge($return, $others);
$final = array_merge($return, $sumsByCode);
$result[$account->id] = $final;
// Log::debug('Final balance is', $final);
}
@@ -508,14 +518,22 @@ class Steam
{
$total = '0';
$converter = new ExchangeRateConverter();
$singleton = PreferencesSingleton::getInstance();
foreach ($others as $key => $amount) {
$currency = TransactionCurrency::where('code', $key)->first();
$preference = $singleton->getPreference($key);
$currency = $preference ?? TransactionCurrency::where('code', $key)->first();
if (null === $currency) {
continue;
}
$current = $converter->convert($currency, $primary, $date, $amount);
Log::debug(sprintf('Convert %s %s to %s %s', $currency->code, $amount, $primary->code, $current));
$total = bcadd($current, $total);
if (null === $preference) {
$singleton->setPreference($key, $currency);
}
$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($current, $total);
}
return $total;

51
composer.lock generated
View File

@@ -586,33 +586,32 @@
},
{
"name": "doctrine/inflector",
"version": "2.0.10",
"version": "2.1.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/inflector.git",
"reference": "5817d0659c5b50c9b950feb9af7b9668e2c436bc"
"reference": "6d6c96277ea252fc1304627204c3d5e6e15faa3b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/inflector/zipball/5817d0659c5b50c9b950feb9af7b9668e2c436bc",
"reference": "5817d0659c5b50c9b950feb9af7b9668e2c436bc",
"url": "https://api.github.com/repos/doctrine/inflector/zipball/6d6c96277ea252fc1304627204c3d5e6e15faa3b",
"reference": "6d6c96277ea252fc1304627204c3d5e6e15faa3b",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0"
},
"require-dev": {
"doctrine/coding-standard": "^11.0",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-strict-rules": "^1.3",
"phpunit/phpunit": "^8.5 || ^9.5",
"vimeo/psalm": "^4.25 || ^5.4"
"doctrine/coding-standard": "^12.0 || ^13.0",
"phpstan/phpstan": "^1.12 || ^2.0",
"phpstan/phpstan-phpunit": "^1.4 || ^2.0",
"phpstan/phpstan-strict-rules": "^1.6 || ^2.0",
"phpunit/phpunit": "^8.5 || ^12.2"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Inflector\\": "lib/Doctrine/Inflector"
"Doctrine\\Inflector\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -657,7 +656,7 @@
],
"support": {
"issues": "https://github.com/doctrine/inflector/issues",
"source": "https://github.com/doctrine/inflector/tree/2.0.10"
"source": "https://github.com/doctrine/inflector/tree/2.1.0"
},
"funding": [
{
@@ -673,7 +672,7 @@
"type": "tidelift"
}
],
"time": "2024-02-18T20:23:39+00:00"
"time": "2025-08-10T19:31:58+00:00"
},
{
"name": "doctrine/lexer",
@@ -11618,16 +11617,16 @@
},
{
"name": "phpunit/phpunit",
"version": "12.3.1",
"version": "12.3.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "5fd1b6e8ab560e0c62600591d438d22a8d978d68"
"reference": "ac6952c92e8a66ee5698cf81f421120ff64c8d0f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/5fd1b6e8ab560e0c62600591d438d22a8d978d68",
"reference": "5fd1b6e8ab560e0c62600591d438d22a8d978d68",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ac6952c92e8a66ee5698cf81f421120ff64c8d0f",
"reference": "ac6952c92e8a66ee5698cf81f421120ff64c8d0f",
"shasum": ""
},
"require": {
@@ -11647,7 +11646,7 @@
"phpunit/php-text-template": "^5.0.0",
"phpunit/php-timer": "^8.0.0",
"sebastian/cli-parser": "^4.0.0",
"sebastian/comparator": "^7.1.0",
"sebastian/comparator": "^7.1.1",
"sebastian/diff": "^7.0.0",
"sebastian/environment": "^8.0.2",
"sebastian/exporter": "^7.0.0",
@@ -11695,7 +11694,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/12.3.1"
"source": "https://github.com/sebastianbergmann/phpunit/tree/12.3.2"
},
"funding": [
{
@@ -11719,7 +11718,7 @@
"type": "tidelift"
}
],
"time": "2025-08-09T07:12:41+00:00"
"time": "2025-08-10T08:36:39+00:00"
},
{
"name": "rector/rector",
@@ -11840,16 +11839,16 @@
},
{
"name": "sebastian/comparator",
"version": "7.1.0",
"version": "7.1.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "03d905327dccc0851c9a08d6a979dfc683826b6f"
"reference": "1a7c2bce03a13a457ed3c975dfd331b3b4b133aa"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/03d905327dccc0851c9a08d6a979dfc683826b6f",
"reference": "03d905327dccc0851c9a08d6a979dfc683826b6f",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1a7c2bce03a13a457ed3c975dfd331b3b4b133aa",
"reference": "1a7c2bce03a13a457ed3c975dfd331b3b4b133aa",
"shasum": ""
},
"require": {
@@ -11908,7 +11907,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/comparator/issues",
"security": "https://github.com/sebastianbergmann/comparator/security/policy",
"source": "https://github.com/sebastianbergmann/comparator/tree/7.1.0"
"source": "https://github.com/sebastianbergmann/comparator/tree/7.1.2"
},
"funding": [
{
@@ -11928,7 +11927,7 @@
"type": "tidelift"
}
],
"time": "2025-06-17T07:41:58+00:00"
"time": "2025-08-10T08:50:08+00:00"
},
{
"name": "sebastian/complexity",

View File

@@ -78,8 +78,8 @@ return [
'running_balance_column' => env('USE_RUNNING_BALANCE', false),
// see cer.php for exchange rates feature flag.
],
'version' => 'develop/2025-08-10',
'build_time' => 1754800876,
'version' => 'develop/2025-08-11',
'build_time' => 1754883282,
'api_version' => '2.1.0', // field is no longer used.
'db_version' => 26,

12
package-lock.json generated
View File

@@ -4486,9 +4486,9 @@
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001733",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001733.tgz",
"integrity": "sha512-e4QKw/O2Kavj2VQTKZWrwzkt3IxOmIlU6ajRb6LP64LHpBo1J67k2Hi4Vu/TgJWsNtynurfS0uK3MaUTCPfu5Q==",
"version": "1.0.30001734",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001734.tgz",
"integrity": "sha512-uhE1Ye5vgqju6OI71HTQqcBCZrvHugk0MjLak7Q+HfoBgoq5Bi+5YnwjP4fjDgrtYr/l8MVRBvzz9dPD4KyK0A==",
"dev": true,
"funding": [
{
@@ -7052,9 +7052,9 @@
}
},
"node_modules/i18next": {
"version": "25.3.2",
"resolved": "https://registry.npmjs.org/i18next/-/i18next-25.3.2.tgz",
"integrity": "sha512-JSnbZDxRVbphc5jiptxr3o2zocy5dEqpVm9qCGdJwRNO+9saUJS0/u4LnM/13C23fUEWxAylPqKU/NpMV/IjqA==",
"version": "25.3.4",
"resolved": "https://registry.npmjs.org/i18next/-/i18next-25.3.4.tgz",
"integrity": "sha512-AHklEYFLiRRxW1Cb6zE9lfnEtYvsydRC8nRS3RSKGX3zCqZ8nLZwMaUsrb80YuccPNv2RNokDL8LkTNnp+6mDw==",
"funding": [
{
"type": "individual",

View File

@@ -4,7 +4,7 @@
"administrations_index_menu": "Administraciones financieras",
"expires_at": "Expira el",
"temp_administrations_introduction": "Firefly III will soon get the ability to manage multiple financial administrations. Right now, you only have the one. You can set the title of this administration and its primary currency. This replaces the previous setting where you would set your \"default currency\". This setting is now tied to the financial administration and can be different per administration.",
"administration_currency_form_help": "It may take a long time for the page to load if you change the primary currency because transaction may need to be converted to your (new) primary currency.",
"administration_currency_form_help": "Puede tomar m\u00e1s tiempo para que la p\u00e1gina se cargue si cambia la moneda principal, porque puede que la transacci\u00f3n necesite ser convertida a su (nueva) moneda principal.",
"administrations_page_edit_sub_title_js": "Editar administraci\u00f3n financiera \"{title}\"",
"table": "Mesa",
"welcome_back": "\u00bfQu\u00e9 est\u00e1 pasando?",
@@ -154,7 +154,7 @@
"url": "URL",
"active": "Activo",
"interest_date": "Fecha de inter\u00e9s",
"administration_currency": "Primary currency",
"administration_currency": "Moneda Principal",
"title": "T\u00edtulo",
"date": "Fecha",
"book_date": "Fecha de registro",
@@ -174,7 +174,7 @@
"list": {
"title": "T\u00edtulo",
"active": "\u00bfEst\u00e1 Activo?",
"primary_currency": "Primary currency",
"primary_currency": "Moneda principal",
"trigger": "Disparador",
"response": "Respuesta",
"delivery": "Entrega",

View File

@@ -3,8 +3,8 @@
"administrations_page_title": "Administrations financi\u00e8res",
"administrations_index_menu": "Administrations financi\u00e8res",
"expires_at": "Expire le",
"temp_administrations_introduction": "Firefly III will soon get the ability to manage multiple financial administrations. Right now, you only have the one. You can set the title of this administration and its primary currency. This replaces the previous setting where you would set your \"default currency\". This setting is now tied to the financial administration and can be different per administration.",
"administration_currency_form_help": "It may take a long time for the page to load if you change the primary currency because transaction may need to be converted to your (new) primary currency.",
"temp_administrations_introduction": "Firefly III aura bient\u00f4t la possibilit\u00e9 de g\u00e9rer plusieurs administrations financi\u00e8res. Pour le moment, vous n'en avez qu'une. Vous pouvez d\u00e9finir le titre de cette administration et de sa devise principale. Cela remplace le param\u00e8tre pr\u00e9c\u00e9dent o\u00f9 vous d\u00e9finissiez votre \"devise par d\u00e9faut\". Ce param\u00e8tre est d\u00e9sormais li\u00e9 \u00e0 l'administration financi\u00e8re et peut \u00eatre diff\u00e9rent par administration.",
"administration_currency_form_help": "La page peut mettre longtemps \u00e0 charger si vous modifiez la devise principale, car des op\u00e9rations peuvent n\u00e9cessiter une conversion vers votre (nouvelle) devise principale.",
"administrations_page_edit_sub_title_js": "Modifier l'administration financi\u00e8re \"{title}\"",
"table": "Tableau",
"welcome_back": "Quoi de neuf ?",
@@ -154,7 +154,7 @@
"url": "Liens",
"active": "Actif",
"interest_date": "Date de valeur (int\u00e9r\u00eats)",
"administration_currency": "Primary currency",
"administration_currency": "Devise principale",
"title": "Titre",
"date": "Date",
"book_date": "Date d'enregistrement",
@@ -174,7 +174,7 @@
"list": {
"title": "Titre",
"active": "Actif ?",
"primary_currency": "Primary currency",
"primary_currency": "Devise principale",
"trigger": "D\u00e9clencheur",
"response": "R\u00e9ponse",
"delivery": "Distribution",