mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-08-16 10:54:39 +00:00
Compare commits
3 Commits
9f394e92fe
...
c47955c069
Author | SHA1 | Date | |
---|---|---|---|
|
c47955c069 | ||
|
e7569644f7 | ||
|
c567474043 |
@@ -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));
|
||||
|
@@ -322,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']));
|
||||
}
|
||||
|
||||
@@ -379,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);
|
||||
}
|
||||
|
26
composer.lock
generated
26
composer.lock
generated
@@ -11618,16 +11618,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 +11647,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 +11695,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 +11719,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-08-09T07:12:41+00:00"
|
||||
"time": "2025-08-10T08:36:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "rector/rector",
|
||||
@@ -11840,16 +11840,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 +11908,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 +11928,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-06-17T07:41:58+00:00"
|
||||
"time": "2025-08-10T08:50:08+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sebastian/complexity",
|
||||
|
@@ -79,7 +79,7 @@ return [
|
||||
// see cer.php for exchange rates feature flag.
|
||||
],
|
||||
'version' => 'develop/2025-08-10',
|
||||
'build_time' => 1754804023,
|
||||
'build_time' => 1754820895,
|
||||
'api_version' => '2.1.0', // field is no longer used.
|
||||
'db_version' => 26,
|
||||
|
||||
|
@@ -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",
|
||||
|
Reference in New Issue
Block a user