mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 01:42:19 +00:00
Auto commit for release 'branch-v6.2' on 2024-12-21
This commit is contained in:
@@ -75,7 +75,7 @@ class AccountObserver
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$currency = $repository->getAccountCurrency($account);
|
||||
if (null !== $currency && $currency->id !== $userCurrency->id && '' !== (string) $account->virtual_balance && 0 !== bccomp($account->virtual_balance, '0')) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter->setIgnoreSettings(true);
|
||||
$account->native_virtual_balance = $converter->convert($currency, $userCurrency, today(), $account->virtual_balance);
|
||||
|
||||
@@ -87,6 +87,4 @@ class AccountObserver
|
||||
$account->saveQuietly();
|
||||
Log::debug('Account native virtual balance is updated.');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* AutoBudgetObserver.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@@ -43,16 +44,14 @@ class AutoBudgetObserver
|
||||
|
||||
private function updateNativeAmount(AutoBudget $autoBudget): void
|
||||
{
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($autoBudget->budget->user->userGroup);
|
||||
$autoBudget->native_amount =null;
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($autoBudget->budget->user->userGroup);
|
||||
$autoBudget->native_amount = null;
|
||||
if ($autoBudget->transactionCurrency->id !== $userCurrency->id) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter->setIgnoreSettings(true);
|
||||
$autoBudget->native_amount = $converter->convert($autoBudget->transactionCurrency, $userCurrency, today(), $autoBudget->amount);
|
||||
}
|
||||
$autoBudget->saveQuietly();
|
||||
Log::debug('Auto budget native amount is updated.');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* AutoBudgetObserver.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@@ -23,7 +24,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\AutoBudget;
|
||||
use FireflyIII\Models\AvailableBudget;
|
||||
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -44,16 +44,14 @@ class AvailableBudgetObserver
|
||||
|
||||
private function updateNativeAmount(AvailableBudget $availableBudget): void
|
||||
{
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($availableBudget->user->userGroup);
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($availableBudget->user->userGroup);
|
||||
$availableBudget->native_amount = null;
|
||||
if ($availableBudget->transactionCurrency->id !== $userCurrency->id) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter->setIgnoreSettings(true);
|
||||
$availableBudget->native_amount = $converter->convert($availableBudget->transactionCurrency, $userCurrency, today(), $availableBudget->amount);
|
||||
}
|
||||
$availableBudget->saveQuietly();
|
||||
Log::debug('Available budget native amount is updated.');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -55,11 +55,11 @@ class BillObserver
|
||||
|
||||
private function updateNativeAmount(Bill $bill): void
|
||||
{
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($bill->user->userGroup);
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($bill->user->userGroup);
|
||||
$bill->native_amount_min = null;
|
||||
$bill->native_amount_max = null;
|
||||
if ($bill->transactionCurrency->id !== $userCurrency->id) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter->setIgnoreSettings(true);
|
||||
$bill->native_amount_min = $converter->convert($bill->transactionCurrency, $userCurrency, today(), $bill->amount_min);
|
||||
$bill->native_amount_max = $converter->convert($bill->transactionCurrency, $userCurrency, today(), $bill->amount_max);
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* BudgetLimitObserver.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@@ -43,10 +44,10 @@ class BudgetLimitObserver
|
||||
|
||||
private function updateNativeAmount(BudgetLimit $budgetLimit): void
|
||||
{
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($budgetLimit->budget->user->userGroup);
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($budgetLimit->budget->user->userGroup);
|
||||
$budgetLimit->native_amount = null;
|
||||
if ($budgetLimit->transactionCurrency->id !== $userCurrency->id) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter->setIgnoreSettings(true);
|
||||
$budgetLimit->native_amount = $converter->convert($budgetLimit->transactionCurrency, $userCurrency, today(), $budgetLimit->amount);
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* AutoBudgetObserver.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@@ -23,7 +24,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\AvailableBudget;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -44,16 +44,14 @@ class PiggyBankEventObserver
|
||||
|
||||
private function updateNativeAmount(PiggyBankEvent $event): void
|
||||
{
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($event->piggyBank->accounts()->first()->user->userGroup);
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($event->piggyBank->accounts()->first()->user->userGroup);
|
||||
$event->native_amount = null;
|
||||
if ($event->piggyBank->transactionCurrency->id !== $userCurrency->id) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter->setIgnoreSettings(true);
|
||||
$event->native_amount = $converter->convert($event->piggyBank->transactionCurrency, $userCurrency, today(), $event->amount);
|
||||
}
|
||||
$event->saveQuietly();
|
||||
Log::debug('Piggy bank event native amount is updated.');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -25,7 +25,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankRepetition;
|
||||
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -48,18 +47,19 @@ class PiggyBankObserver
|
||||
|
||||
private function updateNativeAmount(PiggyBank $piggyBank): void
|
||||
{
|
||||
$group =$piggyBank->accounts()->first()?->user->userGroup;
|
||||
if(null === $group) {
|
||||
$group = $piggyBank->accounts()->first()?->user->userGroup;
|
||||
if (null === $group) {
|
||||
Log::debug(sprintf('No account(s) yet for piggy bank #%d.', $piggyBank->id));
|
||||
|
||||
return;
|
||||
}
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($group);
|
||||
if(null === $userCurrency) {
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($group);
|
||||
if (null === $userCurrency) {
|
||||
return;
|
||||
}
|
||||
$piggyBank->native_target_amount = null;
|
||||
if ($piggyBank->transactionCurrency->id !== $userCurrency->id) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter->setIgnoreSettings(true);
|
||||
$piggyBank->native_target_amount = $converter->convert($piggyBank->transactionCurrency, $userCurrency, today(), $piggyBank->target_amount);
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@ use Illuminate\Support\Facades\Log;
|
||||
class TransactionObserver
|
||||
{
|
||||
public static bool $recalculate = true;
|
||||
|
||||
public function deleting(?Transaction $transaction): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a transaction.');
|
||||
@@ -64,19 +65,20 @@ class TransactionObserver
|
||||
$this->updateNativeAmount($transaction);
|
||||
}
|
||||
|
||||
private function updateNativeAmount(Transaction $transaction): void {
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($transaction->transactionJournal->user->userGroup);
|
||||
$transaction->native_amount = null;
|
||||
private function updateNativeAmount(Transaction $transaction): void
|
||||
{
|
||||
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($transaction->transactionJournal->user->userGroup);
|
||||
$transaction->native_amount = null;
|
||||
$transaction->native_foreign_amount = null;
|
||||
// first normal amount
|
||||
if ($transaction->transactionCurrency->id !== $userCurrency->id) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter->setIgnoreSettings(true);
|
||||
$transaction->native_amount = $converter->convert($transaction->transactionCurrency, $userCurrency, $transaction->transactionJournal->date, $transaction->amount);
|
||||
}
|
||||
// then foreign amount
|
||||
if ($transaction->foreignCurrency?->id !== $userCurrency->id && null !== $transaction->foreign_amount && null !== $transaction->foreignCurrency) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter->setIgnoreSettings(true);
|
||||
$transaction->native_foreign_amount = $converter->convert($transaction->foreignCurrency, $userCurrency, $transaction->transactionJournal->date, $transaction->foreign_amount);
|
||||
}
|
||||
|
Reference in New Issue
Block a user