Compare commits

..

6 Commits

Author SHA1 Message Date
github-actions
295feedd77 Auto commit for release 'develop' on 2025-02-12 2025-02-12 10:50:48 +01:00
James Cole
d3b2748c8f Ok this fix for #9797 goes out to @nebster9k who is delightfully stubborn and absolutely correct. 2025-02-12 06:38:21 +01:00
James Cole
1b4655fd70 Fix #9821 2025-02-12 06:06:28 +01:00
Sander Dorigo
05f67ef584 Fix #9810 2025-02-11 16:27:18 +01:00
Sander Dorigo
04ab7ba07d qMerge branch 'develop' of https://github.com/firefly-iii/firefly-iii into develop 2025-02-11 16:10:48 +01:00
Sander Dorigo
5806323970 Add some notes 2025-02-11 16:10:16 +01:00
13 changed files with 101 additions and 45 deletions

View File

@@ -93,6 +93,7 @@ class AccountController extends Controller
$currency = $this->repository->getAccountCurrency($account) ?? $this->nativeCurrency;
$useCurrency = $currency;
if (in_array($account->accountType->type, $this->balanceTypes, true)) {
// this one is correct.
Log::debug(sprintf('accounts: Call finalAccountBalance with date/time "%s"', $date->toIso8601String()));
$balance = Steam::finalAccountBalance($account, $date);
$key = $this->convertToNative && $currency->id !== $this->nativeCurrency->id ? 'native_balance' : 'balance';

View File

@@ -136,6 +136,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
;
$journals = $collector->getExtractedJournals();
$journals = array_reverse($journals, true);
// this call is correct.
Log::debug(sprintf('getAuditReport: Call finalAccountBalance with date/time "%s"', $date->toIso8601String()));
$dayBeforeBalance = Steam::finalAccountBalance($account, $date);
$startBalance = $dayBeforeBalance['balance'];
@@ -171,6 +172,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
$journals[$index]['invoice_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'invoice_date');
}
$locale = app('steam')->getLocale();
// call is correct.
Log::debug(sprintf('getAuditReport end: Call finalAccountBalance with date/time "%s"', $this->end->toIso8601String()));
return [

View File

@@ -115,6 +115,7 @@ class ReconcileController extends Controller
$startDate = clone $start;
$startDate->subDay()->endOfDay(); // this is correct, subday endofday ends at 23:59:59
// both are validated and are correct.
Log::debug(sprintf('reconcile: Call finalAccountBalance with date/time "%s"', $startDate->toIso8601String()));
Log::debug(sprintf('reconcile2: Call finalAccountBalance with date/time "%s"', $end->toIso8601String()));
$startBalance = Steam::bcround(Steam::finalAccountBalance($account, $startDate)['balance'], $currency->decimal_places);

View File

@@ -136,6 +136,7 @@ class ShowController extends Controller
$groups->setPath(route('accounts.show', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]));
$showAll = false;
// correct
Log::debug(sprintf('show: Call finalAccountBalance with date/time "%s"', $end->toIso8601String()));
$balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency);
@@ -202,6 +203,7 @@ class ShowController extends Controller
$groups->setPath(route('accounts.show.all', [$account->id]));
$chartUrl = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
$showAll = true;
// correct
Log::debug(sprintf('showAll: Call finalAccountBalance with date/time "%s"', $end->toIso8601String()));
$balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency);

View File

@@ -424,8 +424,8 @@ class AccountController extends Controller
{
$start->startOfDay();
$end->endOfDay();
// TODO not sure if these date ranges will work as expected.
Log::debug(sprintf('Now in period("%s", "%s")', $start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s')));
$chartData = [];
$cache = new CacheProperties();
$cache->addProperty('chart.account.period');
$cache->addProperty($start);
@@ -454,7 +454,6 @@ class AccountController extends Controller
$range = Steam::filterAccountBalances($range, $account, $this->convertToNative, $accountCurrency);
// temp, get end balance.
Log::debug('temp get end balance');
Log::debug(sprintf('period: Call finalAccountBalance with date/time "%s"', $end->toIso8601String()));
Steam::finalAccountBalance($account, $end);
Log::debug('END temp get end balance done');
@@ -508,7 +507,7 @@ class AccountController extends Controller
$chartData = [];
foreach ($return as $key => $info) {
if (3 === strlen($key)) {
if ('balance' !== $key && 'native_balance' !== $key) {
// assume it's a currency:
$setCurrency = $this->currencyRepository->findByCode($key);
$info['currency_symbol'] = $setCurrency->symbol;

View File

@@ -195,6 +195,7 @@ class ReconcileController extends Controller
$startDate->subDay();
$currency = $this->accountRepos->getAccountCurrency($account) ?? $this->defaultCurrency;
// correct
Log::debug(sprintf('transactions: Call finalAccountBalance with date/time "%s"', $startDate->toIso8601String()));
Log::debug(sprintf('transactions2: Call finalAccountBalance with date/time "%s"', $end->toIso8601String()));
$startBalance = Steam::bcround(Steam::finalAccountBalance($account, $startDate)['balance'], $currency->decimal_places);

View File

@@ -214,7 +214,6 @@ class OperationsRepository implements OperationsRepositoryInterface
Log::debug(sprintf('Start of %s.', __METHOD__));
// this collector excludes all transfers TO liabilities (which are also withdrawals)
// because those expenses only become expenses once they move from the liability to the friend.
// 2024-12-24 disable the exclusion for now.
$repository = app(AccountRepositoryInterface::class);
@@ -245,7 +244,7 @@ class OperationsRepository implements OperationsRepositoryInterface
}
if (null !== $currency) {
Log::debug(sprintf('Limit to currency %s', $currency->code));
$collector->setNormalCurrency($currency);
$collector->setCurrency($currency);
}
$collector->setBudgets($budgets);
$journals = $collector->getExtractedJournals();

View File

@@ -51,6 +51,7 @@ class TransactionSummarizer
public function groupByCurrencyId(array $journals, string $method = 'negative'): array
{
Log::debug(sprintf('Now in groupByCurrencyId(array, "%s")', $method));
$array = [];
foreach ($journals as $journal) {
$field = 'amount';
@@ -61,6 +62,10 @@ class TransactionSummarizer
$currencySymbol = $journal['currency_symbol'];
$currencyCode = $journal['currency_code'];
$currencyDecimalPlaces = $journal['currency_decimal_places'];
// prepare foreign currency info:
$foreignCurrencyId = 0;
if ($this->convertToNative) {
// if convert to native, use the native amount yes or no?
$useNative = $this->default->id !== (int) $journal['currency_id'];
@@ -85,8 +90,18 @@ class TransactionSummarizer
}
}
if (!$this->convertToNative) {
// default to the normal amount, but also
Log::debug(sprintf('Journal #%d also includes foreign amount (foreign is %s)', $journal['transaction_journal_id'], $journal['foreign_currency_code']));
// use foreign amount?
$foreignCurrencyId = (int) $journal['foreign_currency_id'];
if (0 !== $foreignCurrencyId) {
$foreignCurrencyName = $journal['foreign_currency_name'];
$foreignCurrencySymbol = $journal['foreign_currency_symbol'];
$foreignCurrencyCode = $journal['foreign_currency_code'];
$foreignCurrencyDecimalPlaces = $journal['foreign_currency_decimal_places'];
}
}
// first process normal amount
$amount = (string) ($journal[$field] ?? '0');
$array[$currencyId] ??= [
'sum' => '0',
@@ -96,12 +111,34 @@ class TransactionSummarizer
'currency_code' => $currencyCode,
'currency_decimal_places' => $currencyDecimalPlaces,
];
if ('positive' === $method) {
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->positive($amount));
}
if ('negative' === $method) {
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($amount));
}
// then process foreign amount, if it exists.
if (0 !== $foreignCurrencyId) {
$amount = (string) ($journal['foreign_amount'] ?? '0');
$array[$foreignCurrencyId] ??= [
'sum' => '0',
'currency_id' => $foreignCurrencyId,
'currency_name' => $foreignCurrencyName,
'currency_symbol' => $foreignCurrencySymbol,
'currency_code' => $foreignCurrencyCode,
'currency_decimal_places' => $foreignCurrencyDecimalPlaces,
];
if ('positive' === $method) {
$array[$foreignCurrencyId]['sum'] = bcadd($array[$foreignCurrencyId]['sum'], app('steam')->positive($amount));
}
if ('negative' === $method) {
$array[$foreignCurrencyId]['sum'] = bcadd($array[$foreignCurrencyId]['sum'], app('steam')->negative($amount));
}
}
// $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->{$method}($amount));
// Log::debug(sprintf('Journal #%d adds amount %s %s', $journal['transaction_journal_id'], $currencyCode, $amount));
}

View File

@@ -76,8 +76,15 @@ class Steam
$balances = [];
$formatted = $start->format('Y-m-d');
Log::debug(sprintf('finalAccountBalanceInRange: Call finalAccountBalance with date/time "%s"', $start->toIso8601String()));
$startBalance = $this->finalAccountBalance($account, $start);
/*
* To make sure the start balance is correct, we need to get the balance at the exact end of the previous day.
* Since we just did "startOfDay" we can do subDay()->endOfDay() to get the correct moment.
* THAT will be the start balance.
*/
$request = clone $start;
$request->subDay()->endOfDay();
Log::debug(sprintf('finalAccountBalanceInRange: Call finalAccountBalance with date/time "%s"', $request->toIso8601String()));
$startBalance = $this->finalAccountBalance($account, $request);
$nativeCurrency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup);
$accountCurrency = $this->getAccountCurrency($account);
$hasCurrency = null !== $accountCurrency;
@@ -141,6 +148,8 @@ class Steam
$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, $currentBalance[$entryCurrency->code]);
@@ -149,9 +158,14 @@ class Steam
$currentBalance['balance'] = bcadd($currentBalance['balance'], $sumOfDay);
}
// if convert to native add the converted amount to "native_balance".
// if there is a request to convert, convert to "native_balance" and use "balance" for whichever amount is in the native currency.
if ($convertToNative) {
$nativeSumOfDay = $converter->convert($entryCurrency, $nativeCurrency, $carbon, $sumOfDay);
$currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $nativeSumOfDay);
if ($currency->id === $entryCurrency->id) {
$currentBalance['balance'] = bcadd($currentBalance['balance'], $sumOfDay);
}
}
// just set it.
$balances[$carbonKey] = $currentBalance;
@@ -361,8 +375,8 @@ class Steam
$defaultCurrency = app('amount')->getNativeCurrency();
if ($convertToNative) {
if ($defaultCurrency->id === $currency?->id) {
Log::debug(sprintf('Unset "native_balance" and [%s] for account #%d', $defaultCurrency->code, $account->id));
unset($set['native_balance'], $set[$defaultCurrency->code]);
Log::debug(sprintf('Unset [%s] for account #%d (no longer unset "native_balance")', $defaultCurrency->code, $account->id));
unset($set[$defaultCurrency->code]);
}
// todo rethink this logic.
if (null !== $currency && $defaultCurrency->id !== $currency->id) {

View File

@@ -54,7 +54,7 @@ class PiggyBankEventTransformer extends AbstractTransformer
public function transform(PiggyBankEvent $event): array
{
// get account linked to piggy bank
$account = $event->piggyBank->account;
$account = $event->piggyBank->accounts()->first();
// set up repositories.
$this->repository->setUser($account->user);

54
composer.lock generated
View File

@@ -1874,16 +1874,16 @@
},
{
"name": "laravel/framework",
"version": "v11.41.3",
"version": "v11.42.0",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
"reference": "3ef433d5865f30a19b6b1be247586068399b59cc"
"reference": "006375ba67e830e87daa7b52ab65163ba3508d26"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/3ef433d5865f30a19b6b1be247586068399b59cc",
"reference": "3ef433d5865f30a19b6b1be247586068399b59cc",
"url": "https://api.github.com/repos/laravel/framework/zipball/006375ba67e830e87daa7b52ab65163ba3508d26",
"reference": "006375ba67e830e87daa7b52ab65163ba3508d26",
"shasum": ""
},
"require": {
@@ -1991,11 +1991,11 @@
"league/flysystem-read-only": "^3.25.1",
"league/flysystem-sftp-v3": "^3.25.1",
"mockery/mockery": "^1.6.10",
"orchestra/testbench-core": "^9.6",
"orchestra/testbench-core": "^9.9.4",
"pda/pheanstalk": "^5.0.6",
"php-http/discovery": "^1.15",
"phpstan/phpstan": "^1.11.5",
"phpunit/phpunit": "^10.5.35|^11.3.6",
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^10.5.35|^11.3.6|^12.0.1",
"predis/predis": "^2.3",
"resend/resend-php": "^0.10.0",
"symfony/cache": "^7.0.3",
@@ -2027,7 +2027,7 @@
"mockery/mockery": "Required to use mocking (^1.6).",
"pda/pheanstalk": "Required to use the beanstalk queue driver (^5.0).",
"php-http/discovery": "Required to use PSR-7 bridging features (^1.15).",
"phpunit/phpunit": "Required to use assertions and run tests (^10.5|^11.0).",
"phpunit/phpunit": "Required to use assertions and run tests (^10.5.35|^11.3.6|^12.0.1).",
"predis/predis": "Required to use the predis connector (^2.3).",
"psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).",
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^6.0|^7.0).",
@@ -2085,7 +2085,7 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"time": "2025-01-30T13:25:22+00:00"
"time": "2025-02-11T17:17:56+00:00"
},
{
"name": "laravel/passport",
@@ -2165,16 +2165,16 @@
},
{
"name": "laravel/prompts",
"version": "v0.3.4",
"version": "v0.3.5",
"source": {
"type": "git",
"url": "https://github.com/laravel/prompts.git",
"reference": "abeaa2ba4294247d5409490d1ca1bc6248087011"
"reference": "57b8f7efe40333cdb925700891c7d7465325d3b1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/prompts/zipball/abeaa2ba4294247d5409490d1ca1bc6248087011",
"reference": "abeaa2ba4294247d5409490d1ca1bc6248087011",
"url": "https://api.github.com/repos/laravel/prompts/zipball/57b8f7efe40333cdb925700891c7d7465325d3b1",
"reference": "57b8f7efe40333cdb925700891c7d7465325d3b1",
"shasum": ""
},
"require": {
@@ -2218,9 +2218,9 @@
"description": "Add beautiful and user-friendly forms to your command-line applications.",
"support": {
"issues": "https://github.com/laravel/prompts/issues",
"source": "https://github.com/laravel/prompts/tree/v0.3.4"
"source": "https://github.com/laravel/prompts/tree/v0.3.5"
},
"time": "2025-01-24T15:41:01+00:00"
"time": "2025-02-11T13:34:40+00:00"
},
{
"name": "laravel/sanctum",
@@ -2288,16 +2288,16 @@
},
{
"name": "laravel/serializable-closure",
"version": "v2.0.2",
"version": "v2.0.3",
"source": {
"type": "git",
"url": "https://github.com/laravel/serializable-closure.git",
"reference": "2e1a362527783bcab6c316aad51bf36c5513ae44"
"reference": "f379c13663245f7aa4512a7869f62eb14095f23f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/2e1a362527783bcab6c316aad51bf36c5513ae44",
"reference": "2e1a362527783bcab6c316aad51bf36c5513ae44",
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/f379c13663245f7aa4512a7869f62eb14095f23f",
"reference": "f379c13663245f7aa4512a7869f62eb14095f23f",
"shasum": ""
},
"require": {
@@ -2345,7 +2345,7 @@
"issues": "https://github.com/laravel/serializable-closure/issues",
"source": "https://github.com/laravel/serializable-closure"
},
"time": "2025-01-24T15:42:37+00:00"
"time": "2025-02-11T15:03:05+00:00"
},
{
"name": "laravel/slack-notification-channel",
@@ -3703,16 +3703,16 @@
},
{
"name": "nesbot/carbon",
"version": "3.8.4",
"version": "3.8.5",
"source": {
"type": "git",
"url": "https://github.com/CarbonPHP/carbon.git",
"reference": "129700ed449b1f02d70272d2ac802357c8c30c58"
"reference": "b1a53a27898639579a67de42e8ced5d5386aa9a4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/CarbonPHP/carbon/zipball/129700ed449b1f02d70272d2ac802357c8c30c58",
"reference": "129700ed449b1f02d70272d2ac802357c8c30c58",
"url": "https://api.github.com/repos/CarbonPHP/carbon/zipball/b1a53a27898639579a67de42e8ced5d5386aa9a4",
"reference": "b1a53a27898639579a67de42e8ced5d5386aa9a4",
"shasum": ""
},
"require": {
@@ -3788,8 +3788,8 @@
],
"support": {
"docs": "https://carbon.nesbot.com/docs",
"issues": "https://github.com/briannesbitt/Carbon/issues",
"source": "https://github.com/briannesbitt/Carbon"
"issues": "https://github.com/CarbonPHP/carbon/issues",
"source": "https://github.com/CarbonPHP/carbon"
},
"funding": [
{
@@ -3805,7 +3805,7 @@
"type": "tidelift"
}
],
"time": "2024-12-27T09:25:35+00:00"
"time": "2025-02-11T16:28:45+00:00"
},
{
"name": "nette/schema",

View File

@@ -81,7 +81,7 @@ return [
'running_balance_column' => env('USE_RUNNING_BALANCE', false),
// see cer.php for exchange rates feature flag.
],
'version' => 'develop/2025-02-11',
'version' => 'develop/2025-02-12',
'api_version' => '2.1.0', // field is no longer used.
'db_version' => 25,

12
package-lock.json generated
View File

@@ -4180,9 +4180,9 @@
"license": "MIT"
},
"node_modules/bootstrap5-autocomplete": {
"version": "1.1.35",
"resolved": "https://registry.npmjs.org/bootstrap5-autocomplete/-/bootstrap5-autocomplete-1.1.35.tgz",
"integrity": "sha512-vZAOef3lGrpGGnnIKTJlqiqv6wsx0Wr31/mc010mJmHF1eXJd28jzfGn7ol8eOI/7FiDcm3wd/1VTWku40vLbQ==",
"version": "1.1.36",
"resolved": "https://registry.npmjs.org/bootstrap5-autocomplete/-/bootstrap5-autocomplete-1.1.36.tgz",
"integrity": "sha512-fZpklymmrwAls3n6YDMua2msnBB4pwmJgJgqMayHLfnvvc2dhKWwp/qu0pGJI99S8TwC+ZDjYtEsfl+4/FEZhg==",
"license": "MIT"
},
"node_modules/bootstrap5-tags": {
@@ -10893,9 +10893,9 @@
}
},
"node_modules/terser": {
"version": "5.38.1",
"resolved": "https://registry.npmjs.org/terser/-/terser-5.38.1.tgz",
"integrity": "sha512-GWANVlPM/ZfYzuPHjq0nxT+EbOEDDN3Jwhwdg1D8TU8oSkktp8w64Uq4auuGLxFSoNTRDncTq2hQHX1Ld9KHkA==",
"version": "5.38.2",
"resolved": "https://registry.npmjs.org/terser/-/terser-5.38.2.tgz",
"integrity": "sha512-w8CXxxbFA5zfNsR/i8HZq5bvn18AK0O9jj7hyo1YqkovLxEFa0uP0LCVGZRqiRaKRFxXhELBp8SteeAjEnfeJg==",
"dev": true,
"license": "BSD-2-Clause",
"dependencies": {