mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-14 16:13:54 +00:00
Various fixes for sqlite databases
This commit is contained in:
@@ -128,8 +128,8 @@ class CorrectsNativeAmounts extends Command
|
|||||||
|
|
||||||
foreach ($piggyBank->accounts as $account) {
|
foreach ($piggyBank->accounts as $account) {
|
||||||
$account->pivot->native_current_amount = null;
|
$account->pivot->native_current_amount = null;
|
||||||
if (0 !== bccomp($account->pivot->current_amount, '0')) {
|
if (0 !== bccomp((string) $account->pivot->current_amount, '0')) {
|
||||||
$account->pivot->native_current_amount = $converter->convert($piggyBank->transactionCurrency, $currency, today(), $account->pivot->current_amount);
|
$account->pivot->native_current_amount = $converter->convert($piggyBank->transactionCurrency, $currency, today(), (string) $account->pivot->current_amount);
|
||||||
}
|
}
|
||||||
$account->pivot->save();
|
$account->pivot->save();
|
||||||
}
|
}
|
||||||
|
@@ -39,8 +39,8 @@ class UpgradesTransferCurrencies extends Command
|
|||||||
use ShowsFriendlyMessages;
|
use ShowsFriendlyMessages;
|
||||||
|
|
||||||
public const string CONFIG_NAME = '480_transfer_currencies';
|
public const string CONFIG_NAME = '480_transfer_currencies';
|
||||||
protected $description = 'Updates transfer currency information.';
|
protected $description = 'Updates transfer currency information.';
|
||||||
protected $signature = 'upgrade:480-transfer-currencies {--F|force : Force the execution of this command.}';
|
protected $signature = 'upgrade:480-transfer-currencies {--F|force : Force the execution of this command.}';
|
||||||
private array $accountCurrencies;
|
private array $accountCurrencies;
|
||||||
private AccountRepositoryInterface $accountRepos;
|
private AccountRepositoryInterface $accountRepos;
|
||||||
private JournalCLIRepositoryInterface $cliRepos;
|
private JournalCLIRepositoryInterface $cliRepos;
|
||||||
@@ -68,9 +68,9 @@ class UpgradesTransferCurrencies extends Command
|
|||||||
|
|
||||||
$this->startUpdateRoutine();
|
$this->startUpdateRoutine();
|
||||||
$this->markAsExecuted();
|
$this->markAsExecuted();
|
||||||
|
if ($this->count > 0) {
|
||||||
$this->friendlyInfo(sprintf('Verified currency information of %d transfer(s).', $this->count));
|
$this->friendlyInfo(sprintf('Verified currency information of %d transfer(s).', $this->count));
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,14 +211,14 @@ class UpgradesTransferCurrencies extends Command
|
|||||||
|
|
||||||
private function getCurrency(Account $account): ?TransactionCurrency
|
private function getCurrency(Account $account): ?TransactionCurrency
|
||||||
{
|
{
|
||||||
$accountId = $account->id;
|
$accountId = $account->id;
|
||||||
if (array_key_exists($accountId, $this->accountCurrencies) && 0 === $this->accountCurrencies[$accountId]) {
|
if (array_key_exists($accountId, $this->accountCurrencies) && 0 === $this->accountCurrencies[$accountId]) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (array_key_exists($accountId, $this->accountCurrencies) && $this->accountCurrencies[$accountId] instanceof TransactionCurrency) {
|
if (array_key_exists($accountId, $this->accountCurrencies) && $this->accountCurrencies[$accountId] instanceof TransactionCurrency) {
|
||||||
return $this->accountCurrencies[$accountId];
|
return $this->accountCurrencies[$accountId];
|
||||||
}
|
}
|
||||||
$currency = $this->accountRepos->getAccountCurrency($account);
|
$currency = $this->accountRepos->getAccountCurrency($account);
|
||||||
if (null === $currency) {
|
if (null === $currency) {
|
||||||
$this->accountCurrencies[$accountId] = 0;
|
$this->accountCurrencies[$accountId] = 0;
|
||||||
|
|
||||||
@@ -290,8 +290,7 @@ class UpgradesTransferCurrencies extends Command
|
|||||||
if (null === $this->sourceTransaction->transaction_currency_id && null !== $this->sourceCurrency) {
|
if (null === $this->sourceTransaction->transaction_currency_id && null !== $this->sourceCurrency) {
|
||||||
$this->sourceTransaction
|
$this->sourceTransaction
|
||||||
->transaction_currency_id
|
->transaction_currency_id
|
||||||
= $this->sourceCurrency->id
|
= $this->sourceCurrency->id;
|
||||||
;
|
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
'Transaction #%d has no currency setting, now set to %s.',
|
'Transaction #%d has no currency setting, now set to %s.',
|
||||||
$this->sourceTransaction->id,
|
$this->sourceTransaction->id,
|
||||||
@@ -313,7 +312,7 @@ class UpgradesTransferCurrencies extends Command
|
|||||||
&& null === $this->sourceTransaction->foreign_amount
|
&& null === $this->sourceTransaction->foreign_amount
|
||||||
&& (int) $this->sourceTransaction->transaction_currency_id !== $this->sourceCurrency->id
|
&& (int) $this->sourceTransaction->transaction_currency_id !== $this->sourceCurrency->id
|
||||||
) {
|
) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.',
|
'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.',
|
||||||
$this->sourceTransaction->id,
|
$this->sourceTransaction->id,
|
||||||
$this->sourceTransaction->transaction_currency_id,
|
$this->sourceTransaction->transaction_currency_id,
|
||||||
@@ -336,8 +335,7 @@ class UpgradesTransferCurrencies extends Command
|
|||||||
if (null === $this->destinationTransaction->transaction_currency_id && null !== $this->destinationCurrency) {
|
if (null === $this->destinationTransaction->transaction_currency_id && null !== $this->destinationCurrency) {
|
||||||
$this->destinationTransaction
|
$this->destinationTransaction
|
||||||
->transaction_currency_id
|
->transaction_currency_id
|
||||||
= $this->destinationCurrency->id
|
= $this->destinationCurrency->id;
|
||||||
;
|
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
'Transaction #%d has no currency setting, now set to %s.',
|
'Transaction #%d has no currency setting, now set to %s.',
|
||||||
$this->destinationTransaction->id,
|
$this->destinationTransaction->id,
|
||||||
@@ -359,7 +357,7 @@ class UpgradesTransferCurrencies extends Command
|
|||||||
&& null === $this->destinationTransaction->foreign_amount
|
&& null === $this->destinationTransaction->foreign_amount
|
||||||
&& (int) $this->destinationTransaction->transaction_currency_id !== $this->destinationCurrency->id
|
&& (int) $this->destinationTransaction->transaction_currency_id !== $this->destinationCurrency->id
|
||||||
) {
|
) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.',
|
'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.',
|
||||||
$this->destinationTransaction->id,
|
$this->destinationTransaction->id,
|
||||||
$this->destinationTransaction->transaction_currency_id,
|
$this->destinationTransaction->transaction_currency_id,
|
||||||
@@ -382,8 +380,8 @@ class UpgradesTransferCurrencies extends Command
|
|||||||
{
|
{
|
||||||
if ($this->destinationCurrency->id === $this->sourceCurrency->id) {
|
if ($this->destinationCurrency->id === $this->sourceCurrency->id) {
|
||||||
// update both transactions to match:
|
// update both transactions to match:
|
||||||
$this->sourceTransaction->foreign_amount = null;
|
$this->sourceTransaction->foreign_amount = null;
|
||||||
$this->sourceTransaction->foreign_currency_id = null;
|
$this->sourceTransaction->foreign_currency_id = null;
|
||||||
|
|
||||||
$this->destinationTransaction->foreign_amount = null;
|
$this->destinationTransaction->foreign_amount = null;
|
||||||
$this->destinationTransaction->foreign_currency_id = null;
|
$this->destinationTransaction->foreign_currency_id = null;
|
||||||
|
@@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Handlers\Observer;
|
namespace FireflyIII\Handlers\Observer;
|
||||||
|
|
||||||
use FireflyIII\Models\BudgetLimit;
|
use FireflyIII\Models\BudgetLimit;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
@@ -56,7 +56,7 @@ class TransactionObserver
|
|||||||
|
|
||||||
public function updated(Transaction $transaction): void
|
public function updated(Transaction $transaction): void
|
||||||
{
|
{
|
||||||
Log::debug('Observe "updated" of a transaction.');
|
// Log::debug('Observe "updated" of a transaction.');
|
||||||
if (config('firefly.feature_flags.running_balance_column') && self::$recalculate) {
|
if (config('firefly.feature_flags.running_balance_column') && self::$recalculate) {
|
||||||
if (1 === bccomp($transaction->amount, '0')) {
|
if (1 === bccomp($transaction->amount, '0')) {
|
||||||
Log::debug('Trigger recalculateForJournal');
|
Log::debug('Trigger recalculateForJournal');
|
||||||
|
@@ -90,6 +90,7 @@ class EditController extends Controller
|
|||||||
$latitude = null !== $location ? $location->latitude : config('firefly.default_location.latitude');
|
$latitude = null !== $location ? $location->latitude : config('firefly.default_location.latitude');
|
||||||
$longitude = null !== $location ? $location->longitude : config('firefly.default_location.longitude');
|
$longitude = null !== $location ? $location->longitude : config('firefly.default_location.longitude');
|
||||||
$zoomLevel = null !== $location ? $location->zoom_level : config('firefly.default_location.zoom_level');
|
$zoomLevel = null !== $location ? $location->zoom_level : config('firefly.default_location.zoom_level');
|
||||||
|
$canEditCurrency = $account->piggyBanks()->count() === 0;
|
||||||
$hasLocation = null !== $location;
|
$hasLocation = null !== $location;
|
||||||
$locations = [
|
$locations = [
|
||||||
'location' => [
|
'location' => [
|
||||||
@@ -162,7 +163,7 @@ class EditController extends Controller
|
|||||||
|
|
||||||
$request->session()->flash('preFilled', $preFilled);
|
$request->session()->flash('preFilled', $preFilled);
|
||||||
|
|
||||||
return view('accounts.edit', compact('account', 'currency', 'showNetWorth', 'subTitle', 'subTitleIcon', 'locations', 'liabilityDirections', 'objectType', 'roles', 'preFilled', 'liabilityTypes', 'interestPeriods'));
|
return view('accounts.edit', compact('account', 'currency','canEditCurrency', 'showNetWorth', 'subTitle', 'subTitleIcon', 'locations', 'liabilityDirections', 'objectType', 'roles', 'preFilled', 'liabilityTypes', 'interestPeriods'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -30,6 +30,7 @@ use FireflyIII\Models\CurrencyExchangeRate;
|
|||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\UserGroup;
|
use FireflyIII\Models\UserGroup;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
|
use FireflyIII\Support\Facades\Steam;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
@@ -72,7 +73,7 @@ class ExchangeRateConverter
|
|||||||
}
|
}
|
||||||
$rate = $this->getCurrencyRate($from, $to, $date);
|
$rate = $this->getCurrencyRate($from, $to, $date);
|
||||||
|
|
||||||
return bcmul($amount, $rate);
|
return Steam::bcround(bcmul($amount, $rate), $to->decimal_places);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enabled(): bool
|
public function enabled(): bool
|
||||||
|
@@ -136,7 +136,7 @@ class PiggyBankTransformer extends AbstractTransformer
|
|||||||
$return[] = [
|
$return[] = [
|
||||||
'id' => $account->id,
|
'id' => $account->id,
|
||||||
'name' => $account->name,
|
'name' => $account->name,
|
||||||
'current_amount' => $account->pivot->current_amount,
|
'current_amount' => (string) $account->pivot->current_amount,
|
||||||
// TODO add balance, add left to save.
|
// TODO add balance, add left to save.
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@@ -1913,6 +1913,7 @@ return [
|
|||||||
'extension_date_is' => 'Extension date is {date}',
|
'extension_date_is' => 'Extension date is {date}',
|
||||||
|
|
||||||
// accounts:
|
// accounts:
|
||||||
|
'account_locked_currency' => 'The currency of this account must remain :name as long as piggy banks are linked to it.',
|
||||||
'i_am_owed_amount' => 'I am owed amount',
|
'i_am_owed_amount' => 'I am owed amount',
|
||||||
'i_owe_amount' => 'I owe amount',
|
'i_owe_amount' => 'I owe amount',
|
||||||
'inactive_account_link' => 'You have :count inactive (archived) account, which you can view on this separate page.|You have :count inactive (archived) accounts, which you can view on this separate page.',
|
'inactive_account_link' => 'You have :count inactive (archived) account, which you can view on this separate page.|You have :count inactive (archived) accounts, which you can view on this separate page.',
|
||||||
|
@@ -27,9 +27,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
{{ ExpandedForm.text('name', account.name) }}
|
{{ ExpandedForm.text('name', account.name) }}
|
||||||
{% if account.accountType.type == 'Default account' or account.accountType.type == 'Asset account' or objectType == 'liabilities' %}
|
{% if canEditCurrency and (account.accountType.type == 'Default account' or account.accountType.type == 'Asset account' or objectType == 'liabilities') %}
|
||||||
{{ CurrencyForm.currencyList('currency_id', null, {helpText:'account_default_currency'|_}) }}
|
{{ CurrencyForm.currencyList('currency_id', null, {helpText:'account_default_currency'|_}) }}
|
||||||
|
{% endif %}
|
||||||
|
{% if not canEditCurrency and (account.accountType.type == 'Default account' or account.accountType.type == 'Asset account' or objectType == 'liabilities') %}
|
||||||
|
<input type="hidden" name="currency_id" value="{{ currency.id }}"/>
|
||||||
|
{{ ExpandedForm.staticText('currency_id', trans('firefly.account_locked_currency', {name: currency.name})) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if objectType == 'liabilities' %}
|
{% if objectType == 'liabilities' %}
|
||||||
|
Reference in New Issue
Block a user