mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 09:22:33 +00:00
Auto commit for release 'develop' on 2025-02-04
This commit is contained in:
@@ -97,95 +97,96 @@ class Steam
|
|||||||
|
|
||||||
|
|
||||||
// sums up the balance changes per day, for foreign, native and normal amounts.
|
// sums up the balance changes per day, for foreign, native and normal amounts.
|
||||||
$set = $account->transactions()
|
$set = $account->transactions()
|
||||||
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d H:i:s'))
|
->where('transaction_journals.date', '>=', $start->format('Y-m-d H:i:s'))
|
||||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d H:i:s'))
|
->where('transaction_journals.date', '<=', $end->format('Y-m-d H:i:s'))
|
||||||
->groupBy('transaction_journals.date')
|
->groupBy('transaction_journals.date')
|
||||||
->groupBy('transactions.transaction_currency_id')
|
->groupBy('transactions.transaction_currency_id')
|
||||||
->orderBy('transaction_journals.date', 'ASC')
|
->orderBy('transaction_journals.date', 'ASC')
|
||||||
->whereNull('transaction_journals.deleted_at')
|
->whereNull('transaction_journals.deleted_at')
|
||||||
->get(
|
->get(
|
||||||
[ // @phpstan-ignore-line
|
[ // @phpstan-ignore-line
|
||||||
'transaction_journals.date',
|
'transaction_journals.date',
|
||||||
'transactions.transaction_currency_id',
|
'transactions.transaction_currency_id',
|
||||||
DB::raw('SUM(transactions.amount) AS sum_of_day'),
|
DB::raw('SUM(transactions.amount) AS sum_of_day'),
|
||||||
]
|
]
|
||||||
);
|
)
|
||||||
|
;
|
||||||
|
|
||||||
$currentBalance = $startBalance;
|
$currentBalance = $startBalance;
|
||||||
$converter = new ExchangeRateConverter();
|
$converter = new ExchangeRateConverter();
|
||||||
|
|
||||||
|
|
||||||
/** @var Transaction $entry */
|
/** @var Transaction $entry */
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
// normal, native and foreign amount
|
// normal, native and foreign amount
|
||||||
$carbon = new Carbon($entry->date, $entry->date_tz);
|
$carbon = new Carbon($entry->date, $entry->date_tz);
|
||||||
$sumOfDay = (string) (null === $entry->sum_of_day ? '0' : $entry->sum_of_day);
|
$sumOfDay = (string) (null === $entry->sum_of_day ? '0' : $entry->sum_of_day);
|
||||||
|
|
||||||
// find currency of this entry.
|
// find currency of this entry.
|
||||||
$currencies[$entry->transaction_currency_id] ??= TransactionCurrency::find($entry->transaction_currency_id);
|
$currencies[$entry->transaction_currency_id] ??= TransactionCurrency::find($entry->transaction_currency_id);
|
||||||
|
|
||||||
/** @var TransactionCurrency $entryCurrency */
|
/** @var TransactionCurrency $entryCurrency */
|
||||||
$entryCurrency = $currencies[$entry->transaction_currency_id];
|
$entryCurrency = $currencies[$entry->transaction_currency_id];
|
||||||
|
|
||||||
Log::debug(sprintf('Processing transaction(s) on date %s', $carbon->format('Y-m-d H:i:s')));
|
Log::debug(sprintf('Processing transaction(s) on date %s', $carbon->format('Y-m-d H:i:s')));
|
||||||
$currentBalance[$entryCurrency->code] ??= '0';
|
$currentBalance[$entryCurrency->code] ??= '0';
|
||||||
$currentBalance[$entryCurrency->code] = bcadd($sumOfDay, $currentBalance[$entryCurrency->code]);
|
$currentBalance[$entryCurrency->code] = bcadd($sumOfDay, $currentBalance[$entryCurrency->code]);
|
||||||
|
|
||||||
// if not convert to native, add the amount to "balance" and "native_balance" alike:
|
// if not convert to native, add the amount to "balance" and "native_balance" alike:
|
||||||
if(!$convertToNative) {
|
if (!$convertToNative) {
|
||||||
$currentBalance['balance'] = bcadd($currentBalance['balance'], $sumOfDay);
|
$currentBalance['balance'] = bcadd($currentBalance['balance'], $sumOfDay);
|
||||||
$currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $sumOfDay);
|
$currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $sumOfDay);
|
||||||
}
|
}
|
||||||
// if convert to native add the converted amount to native balance.
|
// if convert to native add the converted amount to native balance.
|
||||||
if($convertToNative) {
|
if ($convertToNative) {
|
||||||
$nativeSumOfDay = $converter->convert($entryCurrency, $defaultCurrency, $carbon, $sumOfDay);
|
$nativeSumOfDay = $converter->convert($entryCurrency, $defaultCurrency, $carbon, $sumOfDay);
|
||||||
$currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $nativeSumOfDay);
|
$currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $nativeSumOfDay);
|
||||||
// only add to "balance" if it has the correct currency code (the same as "native")
|
// only add to "balance" if it has the correct currency code (the same as "native")
|
||||||
if($defaultCurrency->code === $entryCurrency->code) {
|
if ($defaultCurrency->code === $entryCurrency->code) {
|
||||||
$currentBalance['balance'] = bcadd($currentBalance['balance'], $sumOfDay);
|
$currentBalance['balance'] = bcadd($currentBalance['balance'], $sumOfDay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // if convert to native, if NOT convert to native.
|
// // if convert to native, if NOT convert to native.
|
||||||
// if ($convertToNative) {
|
// if ($convertToNative) {
|
||||||
// // convert for this day to native
|
// // convert for this day to native
|
||||||
// $currentNative = '0'; // TODO
|
// $currentNative = '0'; // TODO
|
||||||
// //$currentBalance['native_balance']
|
// //$currentBalance['native_balance']
|
||||||
//
|
//
|
||||||
//// Log::debug(sprintf('Amount is %s %s, foreign amount is %s, native amount is %s', $entryCurrency->code, $this->bcround($modified, 2), $this->bcround($foreignModified, 2), $this->bcround($nativeModified, 2)));
|
// // Log::debug(sprintf('Amount is %s %s, foreign amount is %s, native amount is %s', $entryCurrency->code, $this->bcround($modified, 2), $this->bcround($foreignModified, 2), $this->bcround($nativeModified, 2)));
|
||||||
//// // if the currency is the default currency add to native balance + currency balance
|
// // // if the currency is the default currency add to native balance + currency balance
|
||||||
//// if ($entry->transaction_currency_id === $defaultCurrency->id) {
|
// // if ($entry->transaction_currency_id === $defaultCurrency->id) {
|
||||||
//// Log::debug('Add amount to native.');
|
// // Log::debug('Add amount to native.');
|
||||||
//// $currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $modified);
|
// // $currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $modified);
|
||||||
//// }
|
// // }
|
||||||
////
|
// //
|
||||||
//// // add to native balance.
|
// // // add to native balance.
|
||||||
//// if ($entry->foreign_currency_id !== $defaultCurrency->id) {
|
// // if ($entry->foreign_currency_id !== $defaultCurrency->id) {
|
||||||
//// // this check is not necessary, because if the foreign currency is the same as the default currency, the native amount is zero.
|
// // // this check is not necessary, because if the foreign currency is the same as the default currency, the native amount is zero.
|
||||||
//// // so adding this would mean nothing.
|
// // // so adding this would mean nothing.
|
||||||
//// $currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $nativeModified);
|
// // $currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $nativeModified);
|
||||||
//// }
|
// // }
|
||||||
//// if ($entry->foreign_currency_id === $defaultCurrency->id) {
|
// // if ($entry->foreign_currency_id === $defaultCurrency->id) {
|
||||||
//// $currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $foreignModified);
|
// // $currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $foreignModified);
|
||||||
//// }
|
// // }
|
||||||
//// // add to balance if is the same.
|
// // // add to balance if is the same.
|
||||||
//// if ($entry->transaction_currency_id === $accountCurrency?->id) {
|
// // if ($entry->transaction_currency_id === $accountCurrency?->id) {
|
||||||
//// $currentBalance['balance'] = bcadd($currentBalance['balance'], $modified);
|
// // $currentBalance['balance'] = bcadd($currentBalance['balance'], $modified);
|
||||||
//// }
|
// // }
|
||||||
//// // add currency balance
|
// // // add currency balance
|
||||||
//// $currentBalance[$entryCurrency->code] = bcadd($currentBalance[$entryCurrency->code] ?? '0', $modified);
|
// // $currentBalance[$entryCurrency->code] = bcadd($currentBalance[$entryCurrency->code] ?? '0', $modified);
|
||||||
// }
|
// }
|
||||||
// if (!$convertToNative) {
|
// if (!$convertToNative) {
|
||||||
// Log::debug(sprintf('Amount is %s %s, foreign amount is %s, native amount is %s', $entryCurrency->code, $modified, $foreignModified, $nativeModified));
|
// Log::debug(sprintf('Amount is %s %s, foreign amount is %s, native amount is %s', $entryCurrency->code, $modified, $foreignModified, $nativeModified));
|
||||||
// // add to balance, as expected.
|
// // add to balance, as expected.
|
||||||
// $currentBalance['balance'] = bcadd($currentBalance['balance'] ?? '0', $modified);
|
// $currentBalance['balance'] = bcadd($currentBalance['balance'] ?? '0', $modified);
|
||||||
// // add to GBP, as expected.
|
// // add to GBP, as expected.
|
||||||
// $currentBalance[$entryCurrency->code] = bcadd($currentBalance[$entryCurrency->code] ?? '0', $modified);
|
// $currentBalance[$entryCurrency->code] = bcadd($currentBalance[$entryCurrency->code] ?? '0', $modified);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
$balances[$carbon->format('Y-m-d')] = $currentBalance;
|
$balances[$carbon->format('Y-m-d')] = $currentBalance;
|
||||||
Log::debug('Updated entry', $currentBalance);
|
Log::debug('Updated entry', $currentBalance);
|
||||||
}
|
}
|
||||||
$cache->store($balances);
|
$cache->store($balances);
|
||||||
@@ -314,7 +315,7 @@ class Steam
|
|||||||
*/
|
*/
|
||||||
public function finalAccountBalance(Account $account, Carbon $date): array
|
public function finalAccountBalance(Account $account, Carbon $date): array
|
||||||
{
|
{
|
||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
$cache->addProperty($account->id);
|
$cache->addProperty($account->id);
|
||||||
$cache->addProperty($date);
|
$cache->addProperty($date);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
@@ -323,27 +324,27 @@ class Steam
|
|||||||
|
|
||||||
Log::debug(sprintf('Now in finalAccountBalance(#%d, "%s", "%s")', $account->id, $account->name, $date->format('Y-m-d H:i:s')));
|
Log::debug(sprintf('Now in finalAccountBalance(#%d, "%s", "%s")', $account->id, $account->name, $date->format('Y-m-d H:i:s')));
|
||||||
|
|
||||||
$native = Amount::getNativeCurrencyByUserGroup($account->user->userGroup);
|
$native = Amount::getNativeCurrencyByUserGroup($account->user->userGroup);
|
||||||
$convertToNative = Amount::convertToNative($account->user);
|
$convertToNative = Amount::convertToNative($account->user);
|
||||||
$accountCurrency = $this->getAccountCurrency($account);
|
$accountCurrency = $this->getAccountCurrency($account);
|
||||||
$hasCurrency = null !== $accountCurrency;
|
$hasCurrency = null !== $accountCurrency;
|
||||||
$currency = $hasCurrency ? $accountCurrency : $native;
|
$currency = $hasCurrency ? $accountCurrency : $native;
|
||||||
$return = [
|
$return = [
|
||||||
//'balance' => '0',
|
// 'balance' => '0',
|
||||||
'native_balance' => '0',
|
'native_balance' => '0',
|
||||||
];
|
];
|
||||||
// balance(s) in other (all) currencies.
|
// balance(s) in other (all) currencies.
|
||||||
$array = $account->transactions()
|
$array = $account->transactions()
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||||
->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transactions.transaction_currency_id')
|
->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transactions.transaction_currency_id')
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d H:i:s'))
|
->where('transaction_journals.date', '<=', $date->format('Y-m-d H:i:s'))
|
||||||
->get(['transaction_currencies.code', 'transactions.amount'])->toArray()
|
->get(['transaction_currencies.code', 'transactions.amount'])->toArray()
|
||||||
;
|
;
|
||||||
$others = $this->groupAndSumTransactions($array, 'code', 'amount');
|
$others = $this->groupAndSumTransactions($array, 'code', 'amount');
|
||||||
Log::debug('All balances are (joined)', $others);
|
Log::debug('All balances are (joined)', $others);
|
||||||
// if there is no request to convert, take this as "balance" and "native_balance".
|
// if there is no request to convert, take this as "balance" and "native_balance".
|
||||||
if (!$convertToNative) {
|
if (!$convertToNative) {
|
||||||
//$return['balance'] = $others[$currency->code] ?? '0';
|
// $return['balance'] = $others[$currency->code] ?? '0';
|
||||||
$return['native_balance'] = $others[$currency->code] ?? '0';
|
$return['native_balance'] = $others[$currency->code] ?? '0';
|
||||||
Log::debug(sprintf('Set balance + native_balance to %s', $return['native_balance']));
|
Log::debug(sprintf('Set balance + native_balance to %s', $return['native_balance']));
|
||||||
}
|
}
|
||||||
@@ -355,9 +356,9 @@ class Steam
|
|||||||
}
|
}
|
||||||
|
|
||||||
// either way, the balance is always combined with the virtual balance:
|
// 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);
|
||||||
//$return['balance'] = bcadd($return['balance'], $virtualBalance);
|
// $return['balance'] = bcadd($return['balance'], $virtualBalance);
|
||||||
//Log::debug(sprintf('Virtual balance makes the total %s', $return['balance']));
|
// Log::debug(sprintf('Virtual balance makes the total %s', $return['balance']));
|
||||||
|
|
||||||
if ($convertToNative) {
|
if ($convertToNative) {
|
||||||
// the native balance is combined with a converted virtual_balance:
|
// the native balance is combined with a converted virtual_balance:
|
||||||
@@ -384,7 +385,7 @@ class Steam
|
|||||||
// $return['native_balance'] = $sum;
|
// $return['native_balance'] = $sum;
|
||||||
// unset($return['balance']);
|
// unset($return['balance']);
|
||||||
// }
|
// }
|
||||||
$final = array_merge($return, $others);
|
$final = array_merge($return, $others);
|
||||||
// // Log::debug('Return is', $final);
|
// // Log::debug('Return is', $final);
|
||||||
|
|
||||||
$cache->store($final);
|
$cache->store($final);
|
||||||
|
12
changelog.md
12
changelog.md
@@ -7,12 +7,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- #9713
|
- [Issue 9713](https://github.com/firefly-iii/firefly-iii/issues/9713) (Many decimal points in amounts) reported by @memo-567
|
||||||
- #9736
|
- [Issue 9736](https://github.com/firefly-iii/firefly-iii/issues/9736) (Wrong `finalAccountBalance` result) reported by @gthbusrr
|
||||||
- #9745
|
- [Issue 9745](https://github.com/firefly-iii/firefly-iii/issues/9745) (Type mismatch in period overview) reported by @electrofloat
|
||||||
- #9747
|
- [Issue 9747](https://github.com/firefly-iii/firefly-iii/issues/9747) (Data entry issues with exchange rates) reported by @Azmodeszer
|
||||||
- #9751
|
- [Issue 9751](https://github.com/firefly-iii/firefly-iii/issues/9751) (Net worth changes since 6.2 update) reported by @ahmaddxb
|
||||||
- #9762
|
- [Issue 9762](https://github.com/firefly-iii/firefly-iii/issues/9762) (Piggy bank show: start/target date not displayed) reported by @Simeam
|
||||||
|
|
||||||
## 6.2.2 - 2025-02-02
|
## 6.2.2 - 2025-02-02
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user