Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Various fixes for sqlite databases
James Colef2166b97b8f6
diff --git a/app/Console/Commands/Correction/CorrectsNativeAmounts.php b/app/Console/Commands/Correction/CorrectsNativeAmounts.phpindex bf5d7e98ec..eab4e97525 100644--- a/app/Console/Commands/Correction/CorrectsNativeAmounts.php+++ b/app/Console/Commands/Correction/CorrectsNativeAmounts.php@@ -128,8 +128,8 @@ class CorrectsNativeAmounts extends Commandforeach ($piggyBank->accounts as $account) {$account->pivot->native_current_amount = null;- if (0 !== bccomp($account->pivot->current_amount, '0')) {- $account->pivot->native_current_amount = $converter->convert($piggyBank->transactionCurrency, $currency, today(), $account->pivot->current_amount);+ if (0 !== bccomp((string) $account->pivot->current_amount, '0')) {+ $account->pivot->native_current_amount = $converter->convert($piggyBank->transactionCurrency, $currency, today(), (string) $account->pivot->current_amount);}$account->pivot->save();}diff --git a/app/Console/Commands/Upgrade/UpgradesTransferCurrencies.php b/app/Console/Commands/Upgrade/UpgradesTransferCurrencies.phpindex 5fe4d06696..a58b1af8bf 100644--- a/app/Console/Commands/Upgrade/UpgradesTransferCurrencies.php+++ b/app/Console/Commands/Upgrade/UpgradesTransferCurrencies.php@@ -39,8 +39,8 @@ class UpgradesTransferCurrencies extends Commanduse ShowsFriendlyMessages;public const string CONFIG_NAME = '480_transfer_currencies';- protected $description = 'Updates transfer currency information.';- protected $signature = 'upgrade:480-transfer-currencies {--F|force : Force the execution of this command.}';+ protected $description = 'Updates transfer currency information.';+ protected $signature = 'upgrade:480-transfer-currencies {--F|force : Force the execution of this command.}';private array $accountCurrencies;private AccountRepositoryInterface $accountRepos;private JournalCLIRepositoryInterface $cliRepos;@@ -68,9 +68,9 @@ class UpgradesTransferCurrencies extends Command$this->startUpdateRoutine();$this->markAsExecuted();-- $this->friendlyInfo(sprintf('Verified currency information of %d transfer(s).', $this->count));-+ if ($this->count > 0) {+ $this->friendlyInfo(sprintf('Verified currency information of %d transfer(s).', $this->count));+ }return 0;}@@ -211,14 +211,14 @@ class UpgradesTransferCurrencies extends Commandprivate function getCurrency(Account $account): ?TransactionCurrency{- $accountId = $account->id;+ $accountId = $account->id;if (array_key_exists($accountId, $this->accountCurrencies) && 0 === $this->accountCurrencies[$accountId]) {return null;}if (array_key_exists($accountId, $this->accountCurrencies) && $this->accountCurrencies[$accountId] instanceof TransactionCurrency) {return $this->accountCurrencies[$accountId];}- $currency = $this->accountRepos->getAccountCurrency($account);+ $currency = $this->accountRepos->getAccountCurrency($account);if (null === $currency) {$this->accountCurrencies[$accountId] = 0;@@ -290,8 +290,7 @@ class UpgradesTransferCurrencies extends Commandif (null === $this->sourceTransaction->transaction_currency_id && null !== $this->sourceCurrency) {$this->sourceTransaction->transaction_currency_id- = $this->sourceCurrency->id- ;+ = $this->sourceCurrency->id;$message = sprintf('Transaction #%d has no currency setting, now set to %s.',$this->sourceTransaction->id,@@ -313,7 +312,7 @@ class UpgradesTransferCurrencies extends Command&& null === $this->sourceTransaction->foreign_amount&& (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.',$this->sourceTransaction->id,$this->sourceTransaction->transaction_currency_id,@@ -336,8 +335,7 @@ class UpgradesTransferCurrencies extends Commandif (null === $this->destinationTransaction->transaction_currency_id && null !== $this->destinationCurrency) {$this->destinationTransaction->transaction_currency_id- = $this->destinationCurrency->id- ;+ = $this->destinationCurrency->id;$message = sprintf('Transaction #%d has no currency setting, now set to %s.',$this->destinationTransaction->id,@@ -359,7 +357,7 @@ class UpgradesTransferCurrencies extends Command&& null === $this->destinationTransaction->foreign_amount&& (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.',$this->destinationTransaction->id,$this->destinationTransaction->transaction_currency_id,@@ -382,8 +380,8 @@ class UpgradesTransferCurrencies extends Command{if ($this->destinationCurrency->id === $this->sourceCurrency->id) {// update both transactions to match:- $this->sourceTransaction->foreign_amount = null;- $this->sourceTransaction->foreign_currency_id = null;+ $this->sourceTransaction->foreign_amount = null;+ $this->sourceTransaction->foreign_currency_id = null;$this->destinationTransaction->foreign_amount = null;$this->destinationTransaction->foreign_currency_id = null;diff --git a/app/Handlers/Observer/BudgetLimitObserver.php b/app/Handlers/Observer/BudgetLimitObserver.phpindex e9e0cf5337..e13bde9327 100644--- a/app/Handlers/Observer/BudgetLimitObserver.php+++ b/app/Handlers/Observer/BudgetLimitObserver.php@@ -25,6 +25,7 @@ declare(strict_types=1);namespace FireflyIII\Handlers\Observer;use FireflyIII\Models\BudgetLimit;+use FireflyIII\Support\Facades\Amount;use FireflyIII\Support\Http\Api\ExchangeRateConverter;use Illuminate\Support\Facades\Log;diff --git a/app/Handlers/Observer/TransactionObserver.php b/app/Handlers/Observer/TransactionObserver.phpindex d4d79548da..986cda6eeb 100644--- a/app/Handlers/Observer/TransactionObserver.php+++ b/app/Handlers/Observer/TransactionObserver.php@@ -56,7 +56,7 @@ class TransactionObserverpublic 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 (1 === bccomp($transaction->amount, '0')) {Log::debug('Trigger recalculateForJournal');diff --git a/app/Http/Controllers/Account/EditController.php b/app/Http/Controllers/Account/EditController.phpindex 93a1603582..8d1b772256 100644--- a/app/Http/Controllers/Account/EditController.php+++ b/app/Http/Controllers/Account/EditController.php@@ -90,6 +90,7 @@ class EditController extends Controller$latitude = null !== $location ? $location->latitude : config('firefly.default_location.latitude');$longitude = null !== $location ? $location->longitude : config('firefly.default_location.longitude');$zoomLevel = null !== $location ? $location->zoom_level : config('firefly.default_location.zoom_level');+ $canEditCurrency = $account->piggyBanks()->count() === 0;$hasLocation = null !== $location;$locations = ['location' => [@@ -162,7 +163,7 @@ class EditController extends Controller$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'));}/**diff --git a/app/Support/Http/Api/ExchangeRateConverter.php b/app/Support/Http/Api/ExchangeRateConverter.phpindex dfe9cd7753..c3d847179d 100644--- a/app/Support/Http/Api/ExchangeRateConverter.php+++ b/app/Support/Http/Api/ExchangeRateConverter.php@@ -30,6 +30,7 @@ use FireflyIII\Models\CurrencyExchangeRate;use FireflyIII\Models\TransactionCurrency;use FireflyIII\Models\UserGroup;use FireflyIII\Support\CacheProperties;+use FireflyIII\Support\Facades\Steam;use Illuminate\Support\Facades\Cache;use Illuminate\Support\Facades\Log;@@ -72,7 +73,7 @@ class ExchangeRateConverter}$rate = $this->getCurrencyRate($from, $to, $date);- return bcmul($amount, $rate);+ return Steam::bcround(bcmul($amount, $rate), $to->decimal_places);}public function enabled(): booldiff --git a/app/Transformers/PiggyBankTransformer.php b/app/Transformers/PiggyBankTransformer.phpindex 6c76f73a7b..c1cf567fa3 100644--- a/app/Transformers/PiggyBankTransformer.php+++ b/app/Transformers/PiggyBankTransformer.php@@ -136,7 +136,7 @@ class PiggyBankTransformer extends AbstractTransformer$return[] = ['id' => $account->id,'name' => $account->name,- 'current_amount' => $account->pivot->current_amount,+ 'current_amount' => (string) $account->pivot->current_amount,// TODO add balance, add left to save.];}diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.phpindex 5e5b8d5092..6921b61bb6 100644--- a/resources/lang/en_US/firefly.php+++ b/resources/lang/en_US/firefly.php@@ -1913,6 +1913,7 @@ return ['extension_date_is' => 'Extension date is {date}',// 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_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.',diff --git a/resources/views/accounts/edit.twig b/resources/views/accounts/edit.twigindex 9b9ce38834..e5cbdb0266 100644--- a/resources/views/accounts/edit.twig+++ b/resources/views/accounts/edit.twig@@ -27,9 +27,12 @@</div><div class="box-body">{{ 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'|_}) }}-+ {% 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 %}{% if objectType == 'liabilities' %}