Skip to content

Firefly III: a personal finances manager

Clean up commands.

James Cole0a089efcac59
diff --git a/app/Api/V1/Controllers/Controller.php b/app/Api/V1/Controllers/Controller.php
index 50f0f6786a..862fa08867 100644
--- a/app/Api/V1/Controllers/Controller.php
+++ b/app/Api/V1/Controllers/Controller.php
@@ -28,6 +28,8 @@ use Carbon\Carbon;
use Carbon\Exceptions\InvalidDateException;
use Carbon\Exceptions\InvalidFormatException;
use FireflyIII\Models\Preference;
+use FireflyIII\Support\Facades\Amount;
+use FireflyIII\Support\Facades\Steam;
use FireflyIII\User;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
@@ -68,8 +70,8 @@ abstract class Controller extends BaseController
function ($request, $next) {
$this->parameters = $this->getParameters();
if (auth()->check()) {
- $language = app('steam')->getLanguage();
- $this->convertToNative = app('preferences')->get('convert_to_native', false)->data;
+ $language = Steam::getLanguage();
+ $this->convertToNative = Amount::convertToNative();
app()->setLocale($language);
}
diff --git a/app/Api/V1/Controllers/Summary/BasicController.php b/app/Api/V1/Controllers/Summary/BasicController.php
index cce6a7dc4a..9dcb45b576 100644
--- a/app/Api/V1/Controllers/Summary/BasicController.php
+++ b/app/Api/V1/Controllers/Summary/BasicController.php
@@ -123,8 +123,8 @@ class BasicController extends Controller
private function getBalanceInformation(Carbon $start, Carbon $end): array
{
// some config settings
- $convertToNative = app('preferences')->get('convert_to_native', false)->data;
- $default = app('amount')->getDefaultCurrency();
+ $convertToNative = Amount::convertToNative();
+ $default = Amount::getDefaultCurrency();
// prep some arrays:
$incomes = [];
$expenses = [];
diff --git a/app/Console/Commands/Correction/CorrectsNativeAmounts.php b/app/Console/Commands/Correction/CorrectsNativeAmounts.php
index 04b896b7bf..bf5d7e98ec 100644
--- a/app/Console/Commands/Correction/CorrectsNativeAmounts.php
+++ b/app/Console/Commands/Correction/CorrectsNativeAmounts.php
@@ -59,6 +59,10 @@ class CorrectsNativeAmounts extends Command
*/
public function handle(): int
{
+ if(!config('cer.enabled')) {
+ $this->friendlyInfo('This command will not run because currency exchange rates are disabled.');
+ return 0;
+ }
Log::debug('Will update all native amounts. This may take some time.');
$this->friendlyWarning('Recalculating native amounts for all objects. This may take some time!');
diff --git a/app/Console/Commands/Upgrade/AddsTransactionIdentifiers.php b/app/Console/Commands/Upgrade/AddsTransactionIdentifiers.php
index f425abe9f9..281078dee2 100644
--- a/app/Console/Commands/Upgrade/AddsTransactionIdentifiers.php
+++ b/app/Console/Commands/Upgrade/AddsTransactionIdentifiers.php
@@ -76,9 +76,6 @@ class AddsTransactionIdentifiers extends Command
$this->updateJournalIdentifiers($journal);
}
- if (0 === $this->count) {
- $this->friendlyPositive('All split journal transaction identifiers are OK.');
- }
if (0 !== $this->count) {
$this->friendlyInfo(sprintf('Fixed %d split journal transaction identifier(s).', $this->count));
}
diff --git a/app/Console/Commands/Upgrade/RemovesDatabaseDecryption.php b/app/Console/Commands/Upgrade/RemovesDatabaseDecryption.php
index a8eab8c9a7..29f12ff34a 100644
--- a/app/Console/Commands/Upgrade/RemovesDatabaseDecryption.php
+++ b/app/Console/Commands/Upgrade/RemovesDatabaseDecryption.php
@@ -70,7 +70,6 @@ class RemovesDatabaseDecryption extends Command
private function decryptTable(string $table, array $fields): void
{
if ($this->isDecrypted($table)) {
- $this->friendlyInfo(sprintf('No decryption required for table "%s".', $table));
return;
}
diff --git a/app/Console/Commands/Upgrade/UpgradesAccountCurrencies.php b/app/Console/Commands/Upgrade/UpgradesAccountCurrencies.php
index d4f6495c46..89ef7e5b9b 100644
--- a/app/Console/Commands/Upgrade/UpgradesAccountCurrencies.php
+++ b/app/Console/Commands/Upgrade/UpgradesAccountCurrencies.php
@@ -62,9 +62,6 @@ class UpgradesAccountCurrencies extends Command
}
$this->updateAccountCurrencies();
- if (0 === $this->count) {
- $this->friendlyPositive('All account currencies are OK.');
- }
if (0 !== $this->count) {
$this->friendlyInfo(sprintf('Corrected %d account(s).', $this->count));
}
diff --git a/app/Console/Commands/Upgrade/UpgradesAccountMetaData.php b/app/Console/Commands/Upgrade/UpgradesAccountMetaData.php
index 8ccbfd63de..d181e41e22 100644
--- a/app/Console/Commands/Upgrade/UpgradesAccountMetaData.php
+++ b/app/Console/Commands/Upgrade/UpgradesAccountMetaData.php
@@ -73,9 +73,6 @@ class UpgradesAccountMetaData extends Command
$this->markAsExecuted();
- if (0 === $count) {
- $this->friendlyPositive('All account meta is OK.');
- }
if (0 !== $count) {
$this->friendlyInfo(sprintf('Renamed %d account meta entries (entry).', $count));
}
diff --git a/app/Console/Commands/Upgrade/UpgradesAttachments.php b/app/Console/Commands/Upgrade/UpgradesAttachments.php
index 93f4e628b7..c3e0d32eb9 100644
--- a/app/Console/Commands/Upgrade/UpgradesAttachments.php
+++ b/app/Console/Commands/Upgrade/UpgradesAttachments.php
@@ -79,9 +79,6 @@ class UpgradesAttachments extends Command
++$count;
}
}
- if (0 === $count) {
- $this->friendlyPositive('All attachments are OK.');
- }
if (0 !== $count) {
$this->friendlyInfo(sprintf('Updated %d attachment(s).', $count));
}
diff --git a/app/Console/Commands/Upgrade/UpgradesBillsToRules.php b/app/Console/Commands/Upgrade/UpgradesBillsToRules.php
index de70c8e761..1e2398c2be 100644
--- a/app/Console/Commands/Upgrade/UpgradesBillsToRules.php
+++ b/app/Console/Commands/Upgrade/UpgradesBillsToRules.php
@@ -73,9 +73,6 @@ class UpgradesBillsToRules extends Command
$this->migrateUser($user);
}
- if (0 === $this->count) {
- $this->friendlyPositive('All bills are OK.');
- }
if (0 !== $this->count) {
$this->friendlyInfo(sprintf('Verified and fixed %d bill(s).', $this->count));
}
diff --git a/app/Console/Commands/Upgrade/UpgradesBudgetLimits.php b/app/Console/Commands/Upgrade/UpgradesBudgetLimits.php
index 98b4020d78..c94fe0d7dd 100644
--- a/app/Console/Commands/Upgrade/UpgradesBudgetLimits.php
+++ b/app/Console/Commands/Upgrade/UpgradesBudgetLimits.php
@@ -77,9 +77,6 @@ class UpgradesBudgetLimits extends Command
}
}
}
- if (0 === $count) {
- $this->friendlyPositive('All budget limits are OK.');
- }
$this->markAsExecuted();
return 0;
diff --git a/app/Console/Commands/Upgrade/UpgradesCreditCardLiabilities.php b/app/Console/Commands/Upgrade/UpgradesCreditCardLiabilities.php
index 33c8acfa90..f8db7c06a9 100644
--- a/app/Console/Commands/Upgrade/UpgradesCreditCardLiabilities.php
+++ b/app/Console/Commands/Upgrade/UpgradesCreditCardLiabilities.php
@@ -55,7 +55,6 @@ class UpgradesCreditCardLiabilities extends Command
$ccType = AccountType::where('type', AccountType::CREDITCARD)->first();
$debtType = AccountType::where('type', AccountType::DEBT)->first();
if (null === $ccType || null === $debtType) {
- $this->friendlyPositive('No incorrectly stored credit card liabilities.');
$this->markAsExecuted();
return 0;
@@ -73,9 +72,6 @@ class UpgradesCreditCardLiabilities extends Command
'Credit card liability types are no longer supported and have been converted to generic debts. See: https://bit.ly/FF3-credit-cards'
);
}
- if (0 === $accounts->count()) {
- $this->friendlyPositive('No incorrectly stored credit card liabilities.');
- }
$this->markAsExecuted();
return 0;
diff --git a/app/Console/Commands/Upgrade/UpgradesDatabase.php b/app/Console/Commands/Upgrade/UpgradesDatabase.php
index fb24640cbc..b09c15f657 100644
--- a/app/Console/Commands/Upgrade/UpgradesDatabase.php
+++ b/app/Console/Commands/Upgrade/UpgradesDatabase.php
@@ -57,7 +57,6 @@ class UpgradesDatabase extends Command
'upgrade:480-account-meta',
'upgrade:481-recurrence-meta',
'upgrade:500-tag-locations',
- 'upgrade:550-recurrence-type',
'upgrade:560-liabilities',
'upgrade:600-liabilities',
'upgrade:550-budget-limit-periods',
diff --git a/app/Console/Commands/Upgrade/UpgradesJournalMetaData.php b/app/Console/Commands/Upgrade/UpgradesJournalMetaData.php
index 325de12feb..e6145dc023 100644
--- a/app/Console/Commands/Upgrade/UpgradesJournalMetaData.php
+++ b/app/Console/Commands/Upgrade/UpgradesJournalMetaData.php
@@ -68,7 +68,7 @@ class UpgradesJournalMetaData extends Command
private function isMigrated(): bool
{
- $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
+ $configVar = app('fireflyconfig')->get(UpgradesToGroups::CONFIG_NAME, false);
return (bool) $configVar->data;
}
diff --git a/app/Console/Commands/Upgrade/UpgradesJournalNotes.php b/app/Console/Commands/Upgrade/UpgradesJournalNotes.php
index e638b4144b..788cf1f6c1 100644
--- a/app/Console/Commands/Upgrade/UpgradesJournalNotes.php
+++ b/app/Console/Commands/Upgrade/UpgradesJournalNotes.php
@@ -72,9 +72,6 @@ class UpgradesJournalNotes extends Command
++$count;
}
- if (0 === $count) {
- $this->friendlyPositive('No notes to migrate.');
- }
if (0 !== $count) {
$this->friendlyInfo(sprintf('Migrated %d note(s).', $count));
}
diff --git a/app/Console/Commands/Upgrade/UpgradesRecurrenceMetaData.php b/app/Console/Commands/Upgrade/UpgradesRecurrenceMetaData.php
index 2f64a2bdd2..d20f763945 100644
--- a/app/Console/Commands/Upgrade/UpgradesRecurrenceMetaData.php
+++ b/app/Console/Commands/Upgrade/UpgradesRecurrenceMetaData.php
@@ -52,9 +52,6 @@ class UpgradesRecurrenceMetaData extends Command
}
$count = $this->migrateMetaData();
- if (0 === $count) {
- $this->friendlyPositive('No recurrence meta data migrated.');
- }
if ($count > 0) {
$this->friendlyInfo(sprintf('Migrated %d meta data entries', $count));
}
diff --git a/app/Console/Commands/Upgrade/UpgradesRecurrenceType.php b/app/Console/Commands/Upgrade/UpgradesRecurrenceType.php
deleted file mode 100644
index c03376af23..0000000000
--- a/app/Console/Commands/Upgrade/UpgradesRecurrenceType.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-
-/*
- * MigrateRecurrenceType.php
- * Copyright (c) 2021 [email protected]
- *
- * This file is part of Firefly III (https://github.com/firefly-iii).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-declare(strict_types=1);
-
-namespace FireflyIII\Console\Commands\Upgrade;
-
-use FireflyIII\Console\Commands\ShowsFriendlyMessages;
-use Illuminate\Console\Command;
-
-class UpgradesRecurrenceType extends Command
-{
- use ShowsFriendlyMessages;
-
- public const string CONFIG_NAME = '550_migrate_recurrence_type';
-
- protected $description = 'Migrate transaction type of recurring transaction.';
-
- protected $signature = 'upgrade:550-recurrence-type {--F|force : Force the execution of this command.}';
-
- /**
- * Execute the console command.
- */
- public function handle(): int
- {
- if ($this->isExecuted() && true !== $this->option('force')) {
- $this->friendlyInfo('This command has already been executed.');
-
- return 0;
- }
- $this->friendlyWarning('This command has been disabled.');
- $this->markAsExecuted();
-
- return 0;
- }
-
- private function isExecuted(): bool
- {
- $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
-
- return (bool) $configVar?->data;
- }
-
- private function markAsExecuted(): void
- {
- app('fireflyconfig')->set(self::CONFIG_NAME, true);
- }
-}
diff --git a/app/Console/Commands/Upgrade/UpgradesToGroups.php b/app/Console/Commands/Upgrade/UpgradesToGroups.php
index c0c7cf3e10..bf3113f788 100644
--- a/app/Console/Commands/Upgrade/UpgradesToGroups.php
+++ b/app/Console/Commands/Upgrade/UpgradesToGroups.php
@@ -72,9 +72,6 @@ class UpgradesToGroups extends Command
if (0 !== $this->count) {
$this->friendlyInfo(sprintf('Migrated %d transaction journal(s).', $this->count));
}
- if (0 === $this->count) {
- $this->friendlyPositive('No journals to migrate to groups.');
- }
$this->markAsMigrated();
return 0;
@@ -363,9 +360,6 @@ class UpgradesToGroups extends Command
$this->giveGroup($array);
}
}
- if (0 === $total) {
- $this->friendlyPositive('No need to convert transaction journals.');
- }
}
private function giveGroup(array $array): void
diff --git a/app/Console/Commands/Upgrade/UpgradesTransferCurrencies.php b/app/Console/Commands/Upgrade/UpgradesTransferCurrencies.php
index a51ec5a95c..5fe4d06696 100644
--- a/app/Console/Commands/Upgrade/UpgradesTransferCurrencies.php
+++ b/app/Console/Commands/Upgrade/UpgradesTransferCurrencies.php
@@ -69,12 +69,6 @@ class UpgradesTransferCurrencies extends Command
$this->startUpdateRoutine();
$this->markAsExecuted();
- if (0 === $this->count) {
- $this->friendlyPositive('All transfers have correct currency information.');
-
- return 0;
- }
-
$this->friendlyInfo(sprintf('Verified currency information of %d transfer(s).', $this->count));
return 0;
diff --git a/app/Handlers/Observer/AccountObserver.php b/app/Handlers/Observer/AccountObserver.php
index a319fc79f5..e321b102e6 100644
--- a/app/Handlers/Observer/AccountObserver.php
+++ b/app/Handlers/Observer/AccountObserver.php
@@ -27,6 +27,7 @@ namespace FireflyIII\Handlers\Observer;
use FireflyIII\Models\Account;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\UserGroups\Account\AccountRepositoryInterface;
+use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
use Illuminate\Support\Facades\Log;
@@ -43,6 +44,9 @@ class AccountObserver
private function updateNativeAmount(Account $account): void
{
+ if(!Amount::convertToNative($account->user)) {
+ return;
+ }
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
$repository = app(AccountRepositoryInterface::class);
$currency = $repository->getAccountCurrency($account);
diff --git a/app/Handlers/Observer/AutoBudgetObserver.php b/app/Handlers/Observer/AutoBudgetObserver.php
index 9193bc06a9..e4a911653f 100644
--- a/app/Handlers/Observer/AutoBudgetObserver.php
+++ b/app/Handlers/Observer/AutoBudgetObserver.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Observer;
use FireflyIII\Models\AutoBudget;
+use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
use Illuminate\Support\Facades\Log;
@@ -44,6 +45,9 @@ class AutoBudgetObserver
private function updateNativeAmount(AutoBudget $autoBudget): void
{
+ if(!Amount::convertToNative($autoBudget->budget->user)) {
+ return;
+ }
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($autoBudget->budget->user->userGroup);
$autoBudget->native_amount = null;
if ($autoBudget->transactionCurrency->id !== $userCurrency->id) {
diff --git a/app/Handlers/Observer/AvailableBudgetObserver.php b/app/Handlers/Observer/AvailableBudgetObserver.php
index e7102aa6c5..d5d03fe31c 100644
--- a/app/Handlers/Observer/AvailableBudgetObserver.php
+++ b/app/Handlers/Observer/AvailableBudgetObserver.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Observer;
use FireflyIII\Models\AvailableBudget;
+use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
use Illuminate\Support\Facades\Log;
@@ -44,6 +45,9 @@ class AvailableBudgetObserver
private function updateNativeAmount(AvailableBudget $availableBudget): void
{
+ if(!Amount::convertToNative($availableBudget->user)) {
+ return;
+ }
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($availableBudget->user->userGroup);
$availableBudget->native_amount = null;
if ($availableBudget->transactionCurrency->id !== $userCurrency->id) {
diff --git a/app/Handlers/Observer/BillObserver.php b/app/Handlers/Observer/BillObserver.php
index 5bcba3cfcf..262ed250bc 100644
--- a/app/Handlers/Observer/BillObserver.php
+++ b/app/Handlers/Observer/BillObserver.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Observer;
use FireflyIII\Models\Bill;
+use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
use Illuminate\Support\Facades\Log;
@@ -55,6 +56,9 @@ class BillObserver
private function updateNativeAmount(Bill $bill): void
{
+ if(!Amount::convertToNative($bill->user)) {
+ return;
+ }
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($bill->user->userGroup);
$bill->native_amount_min = null;
$bill->native_amount_max = null;
diff --git a/app/Handlers/Observer/BudgetLimitObserver.php b/app/Handlers/Observer/BudgetLimitObserver.php
index ec3f49a209..e9e0cf5337 100644
--- a/app/Handlers/Observer/BudgetLimitObserver.php
+++ b/app/Handlers/Observer/BudgetLimitObserver.php
@@ -44,6 +44,9 @@ class BudgetLimitObserver
private function updateNativeAmount(BudgetLimit $budgetLimit): void
{
+ if(!Amount::convertToNative($budgetLimit->budget->user)) {
+ return;
+ }
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($budgetLimit->budget->user->userGroup);
$budgetLimit->native_amount = null;
if ($budgetLimit->transactionCurrency->id !== $userCurrency->id) {
diff --git a/app/Handlers/Observer/PiggyBankEventObserver.php b/app/Handlers/Observer/PiggyBankEventObserver.php
index 6afcf69f82..7ed4b2fae3 100644
--- a/app/Handlers/Observer/PiggyBankEventObserver.php
+++ b/app/Handlers/Observer/PiggyBankEventObserver.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Observer;
use FireflyIII\Models\PiggyBankEvent;
+use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
use Illuminate\Support\Facades\Log;
@@ -44,6 +45,9 @@ class PiggyBankEventObserver
private function updateNativeAmount(PiggyBankEvent $event): void
{
+ if(!Amount::convertToNative($event->piggyBank->accounts()->first()->user)) {
+ return;
+ }
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($event->piggyBank->accounts()->first()->user->userGroup);
$event->native_amount = null;
if ($event->piggyBank->transactionCurrency->id !== $userCurrency->id) {
diff --git a/app/Handlers/Observer/PiggyBankObserver.php b/app/Handlers/Observer/PiggyBankObserver.php
index b66d5d7bd0..cd8acc327d 100644
--- a/app/Handlers/Observer/PiggyBankObserver.php
+++ b/app/Handlers/Observer/PiggyBankObserver.php
@@ -78,6 +78,7 @@ class PiggyBankObserver
if ($piggyBank->transactionCurrency->id !== $userCurrency->id) {
$converter = new ExchangeRateConverter();
$converter->setIgnoreSettings(true);
+ $converter->setUserGroup($group);
$piggyBank->native_target_amount = $converter->convert($piggyBank->transactionCurrency, $userCurrency, today(), $piggyBank->target_amount);
}
$piggyBank->saveQuietly();
diff --git a/app/Handlers/Observer/TransactionObserver.php b/app/Handlers/Observer/TransactionObserver.php
index 8c79d83ac5..d4d79548da 100644
--- a/app/Handlers/Observer/TransactionObserver.php
+++ b/app/Handlers/Observer/TransactionObserver.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Observer;
use FireflyIII\Models\Transaction;
+use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
use FireflyIII\Support\Models\AccountBalanceCalculator;
use Illuminate\Support\Facades\Log;
@@ -67,6 +68,9 @@ class TransactionObserver
private function updateNativeAmount(Transaction $transaction): void
{
+ if(!Amount::convertToNative($transaction->transactionJournal->user)) {
+ return;
+ }
$userCurrency = app('amount')->getDefaultCurrencyByUserGroup($transaction->transactionJournal->user->userGroup);
$transaction->native_amount = null;
$transaction->native_foreign_amount = null;
diff --git a/app/Helpers/Report/NetWorth.php b/app/Helpers/Report/NetWorth.php
index 9b70e4b713..85bb500406 100644
--- a/app/Helpers/Report/NetWorth.php
+++ b/app/Helpers/Report/NetWorth.php
@@ -66,7 +66,7 @@ class NetWorth implements NetWorthInterface
public function byAccounts(Collection $accounts, Carbon $date): array
{
// start in the past, end in the future? use $date
- $convertToNative = app('preferences')->get('convert_to_native', false)->data;
+ $convertToNative = Amount::convertToNative();
$ids = implode(',', $accounts->pluck('id')->toArray());
$cache = new CacheProperties();
$cache->addProperty($date);
diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php
index 7853d56457..1dcdbe3be8 100644
--- a/app/Http/Controllers/Controller.php
+++ b/app/Http/Controllers/Controller.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use FireflyIII\Models\TransactionCurrency;
+use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Facades\Steam;
use FireflyIII\Support\Http\Controllers\RequestInformation;
use FireflyIII\Support\Http\Controllers\UserNavigation;
@@ -121,7 +122,7 @@ abstract class Controller extends BaseController
$language = Steam::getLanguage();
$locale = Steam::getLocale();
$darkMode = app('preferences')->get('darkMode', 'browser')->data;
- $this->convertToNative =app('preferences')->get('convert_to_native', false)->data;
+ $this->convertToNative =Amount::convertToNative();
$page = $this->getPageName();
$shownDemo = $this->hasSeenDemo();
View::share('language', $language);
diff --git a/app/Http/Controllers/ExchangeRates/IndexController.php b/app/Http/Controllers/ExchangeRates/IndexController.php
index 793a8466db..880ed1ffd1 100644
--- a/app/Http/Controllers/ExchangeRates/IndexController.php
+++ b/app/Http/Controllers/ExchangeRates/IndexController.php
@@ -27,6 +27,7 @@ namespace FireflyIII\Http\Controllers\ExchangeRates;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionCurrency;
use Illuminate\View\View;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class IndexController extends Controller
{
@@ -46,6 +47,9 @@ class IndexController extends Controller
return $next($request);
}
);
+ if(!config('cer.enabled')) {
+ throw new NotFoundHttpException();
+ }
}
public function index(): View
diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php
index 955f8f1f16..5015776d3f 100644
--- a/app/Repositories/Bill/BillRepository.php
+++ b/app/Repositories/Bill/BillRepository.php
@@ -527,7 +527,7 @@ class BillRepository implements BillRepositoryInterface
Log::debug(sprintf('sumPaidInRange from %s to %s', $start->toW3cString(), $end->toW3cString()));
$bills = $this->getActiveBills();
$return = [];
- $convertToNative = app('preferences')->getForUser($this->user, 'convert_to_native', false)->data;
+ $convertToNative = Amount::convertToNative($this->user);
$default = app('amount')->getDefaultCurrency();
/** @var Bill $bill */
@@ -572,7 +572,7 @@ class BillRepository implements BillRepositoryInterface
app('log')->debug(sprintf('Now in sumUnpaidInRange("%s", "%s")', $start->format('Y-m-d'), $end->format('Y-m-d')));
$bills = $this->getActiveBills();
$return = [];
- $convertToNative = app('preferences')->getForUser($this->user, 'convert_to_native', false)->data;
+ $convertToNative = Amount::convertToNative($this->user);
$default = app('amount')->getDefaultCurrency();
/** @var Bill $bill */
diff --git a/app/Repositories/Budget/AvailableBudgetRepository.php b/app/Repositories/Budget/AvailableBudgetRepository.php
index ff14595d01..becbf2a079 100644
--- a/app/Repositories/Budget/AvailableBudgetRepository.php
+++ b/app/Repositories/Budget/AvailableBudgetRepository.php
@@ -27,6 +27,7 @@ namespace FireflyIII\Repositories\Budget;
use Carbon\Carbon;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Models\TransactionCurrency;
+use FireflyIII\Support\Facades\Amount;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Builder;
@@ -134,8 +135,8 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
;
// use native amount if necessary?
- $convertToNative = app('preferences')->getForUser($this->user, 'convert_to_native', false)->data;
- $default = app('amount')->getDefaultCurrency();
+ $convertToNative = Amount::convertToNative($this->user);
+ $default = Amount::getDefaultCurrency();
/** @var AvailableBudget $availableBudget */
foreach ($availableBudgets as $availableBudget) {
diff --git a/app/Repositories/Budget/OperationsRepository.php b/app/Repositories/Budget/OperationsRepository.php
index e222fa5f10..fe695fa062 100644
--- a/app/Repositories/Budget/OperationsRepository.php
+++ b/app/Repositories/Budget/OperationsRepository.php
@@ -223,8 +223,8 @@ class OperationsRepository implements OperationsRepositoryInterface
$selection = new Collection();
// default currency information for native stuff.
- $convertToNative = app('preferences')->get('convert_to_native', false)->data;
- $default = app('amount')->getDefaultCurrency();
+ $convertToNative = Amount::convertToNative($this->user);
+ $default = Amount::getDefaultCurrency();
/** @var Account $account */
foreach ($subset as $account) {
diff --git a/app/Repositories/Category/NoCategoryRepository.php b/app/Repositories/Category/NoCategoryRepository.php
index 9b6fca8aec..18a7b2a783 100644
--- a/app/Repositories/Category/NoCategoryRepository.php
+++ b/app/Repositories/Category/NoCategoryRepository.php
@@ -154,8 +154,8 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
$journals = $collector->getExtractedJournals();
$array = [];
// default currency information for native stuff.
- $convertToNative = app('preferences')->get('convert_to_native', false)->data;
- $default = app('amount')->getDefaultCurrency();
+ $convertToNative = Amount::convertToNative($this->user);;
+ $default = Amount::getDefaultCurrency();
foreach ($journals as $journal) {
// Almost the same as in \FireflyIII\Repositories\Budget\OperationsRepository::sumExpenses
diff --git a/app/Repositories/Category/OperationsRepository.php b/app/Repositories/Category/OperationsRepository.php
index bca0e084e0..598214e8b7 100644
--- a/app/Repositories/Category/OperationsRepository.php
+++ b/app/Repositories/Category/OperationsRepository.php
@@ -331,8 +331,8 @@ class OperationsRepository implements OperationsRepositoryInterface
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
// default currency information for native stuff.
- $convertToNative = app('preferences')->get('convert_to_native', false)->data;
- $default = app('amount')->getDefaultCurrency();
+ $convertToNative = Amount::convertToNative($this->user);;
+ $default = Amount::getDefaultCurrency();
if (null !== $accounts && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
@@ -411,8 +411,8 @@ class OperationsRepository implements OperationsRepositoryInterface
}
$collector->setCategories($categories);
$journals = $collector->getExtractedJournals();
- $convertToNative = app('preferences')->get('convert_to_native', false)->data;
- $default = app('amount')->getDefaultCurrency();
+ $convertToNative = Amount::convertToNative($this->user);;
+ $default = Amount::getDefaultCurrency();
$array = [];
foreach ($journals as $journal) {
diff --git a/app/Support/Amount.php b/app/Support/Amount.php
index 2bfc6fb070..33ddc22b93 100644
--- a/app/Support/Amount.php
+++ b/app/Support/Amount.php
@@ -30,7 +30,6 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\Log;
/**
* Class Amount.
@@ -54,13 +53,13 @@ class Amount
*/
public function getAmountFromJournal(array $journal): string
{
- $convertToNative = app('preferences')->get('convert_to_native', false)->data;
- $currency = app('amount')->getDefaultCurrency();
+ $convertToNative = $this->convertToNative();
+ $currency = $this->getDefaultCurrency();
$field = $convertToNative && $currency->id !== $journal['currency_id'] ? 'native_amount' : 'amount';
$amount = $journal[$field] ?? '0';
// Log::debug(sprintf('Field is %s, amount is %s', $field, $amount));
// fallback, the transaction has a foreign amount in $currency.
- if ($convertToNative && null !== $journal['foreign_amount'] && $currency->id === (int)$journal['foreign_currency_id']) {
+ if ($convertToNative && null !== $journal['foreign_amount'] && $currency->id === (int) $journal['foreign_currency_id']) {
$amount = $journal['foreign_amount'];
// Log::debug(sprintf('Overruled, amount is now %s', $amount));
}
@@ -68,22 +67,30 @@ class Amount
return $amount;
}
+ public function convertToNative(?User $user = null): bool
+ {
+ if (null === $user) {
+ return \FireflyIII\Support\Facades\Preferences::get('convert_to_native', false)->data && config('cer.enabled');
+ }
+ return \FireflyIII\Support\Facades\Preferences::getForUser($user, 'convert_to_native', false)->data && config('cer.enabled');
+ }
+
/**
* Experimental function to see if we can quickly and quietly get the amount from a journal.
* This depends on the user's default currency and the wish to have it converted.
*/
public function getAmountFromJournalObject(TransactionJournal $journal): string
{
- $convertToNative = app('preferences')->get('convert_to_native', false)->data;
- $currency = app('amount')->getDefaultCurrency();
- $field = $convertToNative && $currency->id !== $journal->transaction_currency_id ? 'native_amount' : 'amount';
+ $convertToNative = $this->convertToNative();
+ $currency = $this->getDefaultCurrency();
+ $field = $convertToNative && $currency->id !== $journal->transaction_currency_id ? 'native_amount' : 'amount';
/** @var null|Transaction $sourceTransaction */
$sourceTransaction = $journal->transactions()->where('amount', '<', 0)->first();
if (null === $sourceTransaction) {
return '0';
}
- $amount = $sourceTransaction->{$field};
+ $amount = $sourceTransaction->{$field} ?? '0';
if ((int) $sourceTransaction->foreign_currency_id === $currency->id) {
// use foreign amount instead!
$amount = (string) $sourceTransaction->foreign_amount; // hard coded to be foreign amount.
@@ -102,15 +109,15 @@ class Amount
*/
public function formatFlat(string $symbol, int $decimalPlaces, string $amount, ?bool $coloured = null): string
{
- $locale = app('steam')->getLocale();
- $rounded = app('steam')->bcround($amount, $decimalPlaces);
+ $locale = app('steam')->getLocale();
+ $rounded = app('steam')->bcround($amount, $decimalPlaces);
$coloured ??= true;
- $fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
+ $fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
$fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $symbol);
$fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $decimalPlaces);
$fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimalPlaces);
- $result = (string) $fmt->format((float) $rounded); // intentional float
+ $result = (string) $fmt->format((float) $rounded); // intentional float
if (true === $coloured) {
if (1 === bccomp($rounded, '0')) {
@@ -156,7 +163,7 @@ class Amount
public function getDefaultCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency
{
- $cache = new CacheProperties();
+ $cache = new CacheProperties();
$cache->addProperty('getDefaultCurrencyByGroup');
$cache->addProperty($userGroup->id);
if ($cache->has()) {
@@ -219,20 +226,20 @@ class Amount
private function getLocaleInfo(): array
{
// get config from preference, not from translation:
- $locale = app('steam')->getLocale();
- $array = app('steam')->getLocaleArray($locale);
+ $locale = app('steam')->getLocale();
+ $array = app('steam')->getLocaleArray($locale);
setlocale(LC_MONETARY, $array);
- $info = localeconv();
+ $info = localeconv();
// correct variables
- $info['n_cs_precedes'] = $this->getLocaleField($info, 'n_cs_precedes');
- $info['p_cs_precedes'] = $this->getLocaleField($info, 'p_cs_precedes');
+ $info['n_cs_precedes'] = $this->getLocaleField($info, 'n_cs_precedes');
+ $info['p_cs_precedes'] = $this->getLocaleField($info, 'p_cs_precedes');
- $info['n_sep_by_space'] = $this->getLocaleField($info, 'n_sep_by_space');
- $info['p_sep_by_space'] = $this->getLocaleField($info, 'p_sep_by_space');
+ $info['n_sep_by_space'] = $this->getLocaleField($info, 'n_sep_by_space');
+ $info['p_sep_by_space'] = $this->getLocaleField($info, 'p_sep_by_space');
- $fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
+ $fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
$info['mon_decimal_point'] = $fmt->getSymbol(\NumberFormatter::MONETARY_SEPARATOR_SYMBOL);
$info['mon_thousands_sep'] = $fmt->getSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL);
@@ -255,7 +262,7 @@ class Amount
public static function getAmountJsConfig(bool $sepBySpace, int $signPosn, string $sign, bool $csPrecedes): string
{
// negative first:
- $space = ' ';
+ $space = ' ';
// require space between symbol and amount?
if (false === $sepBySpace) {
@@ -264,11 +271,11 @@ class Amount
// there are five possible positions for the "+" or "-" sign (if it is even used)
// pos_a and pos_e could be the ( and ) symbol.
- $posA = ''; // before everything
- $posB = ''; // before currency symbol
- $posC = ''; // after currency symbol
- $posD = ''; // before amount
- $posE = ''; // after everything
+ $posA = ''; // before everything
+ $posB = ''; // before currency symbol
+ $posC = ''; // after currency symbol
+ $posD = ''; // before amount
+ $posE = ''; // after everything
// format would be (currency before amount)
// AB%sC_D%vE
@@ -310,11 +317,11 @@ class Amount
}
// default is amount before currency
- $format = $posA.$posD.'%v'.$space.$posB.'%s'.$posC.$posE;
+ $format = $posA . $posD . '%v' . $space . $posB . '%s' . $posC . $posE;
if ($csPrecedes) {
// alternative is currency before amount
- $format = $posA.$posB.'%s'.$posC.$space.$posD.'%v'.$posE;
+ $format = $posA . $posB . '%s' . $posC . $space . $posD . '%v' . $posE;
}
return $format;
diff --git a/app/Support/Http/Controllers/ChartGeneration.php b/app/Support/Http/Controllers/ChartGeneration.php
index 572f0b6044..e1c9aea6ca 100644
--- a/app/Support/Http/Controllers/ChartGeneration.php
+++ b/app/Support/Http/Controllers/ChartGeneration.php
@@ -30,6 +30,7 @@ use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\CacheProperties;
+use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Facades\Steam;
use Illuminate\Support\Collection;
@@ -46,7 +47,7 @@ trait ChartGeneration
protected function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array // chart helper method.
{
// chart properties for cache:
- $convertToNative = app('preferences')->get('convert_to_native', false)->data;
+ $convertToNative = Amount::convertToNative();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
diff --git a/app/Support/Steam.php b/app/Support/Steam.php
index 1aa9f73bf7..d0734e1896 100644
--- a/app/Support/Steam.php
+++ b/app/Support/Steam.php
@@ -310,8 +310,8 @@ class Steam
public function finalAccountBalance(Account $account, Carbon $date): array
{
Log::debug(sprintf('Now in finalAccountBalance(#%d, "%s", "%s")', $account->id, $account->name, $date->format('Y-m-d H:i:s')));
- $native = app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
- $convertToNative = app('preferences')->getForUser($account->user, 'convert_to_native', false)->data;
+ $native = \FireflyIII\Support\Facades\Amount::getDefaultCurrencyByUserGroup($account->user->userGroup);
+ $convertToNative = \FireflyIII\Support\Facades\Amount::convertToNative($account->user);
$accountCurrency = $this->getAccountCurrency($account);
$hasCurrency = null !== $accountCurrency;
$currency = $hasCurrency ? $accountCurrency : $native;
diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php
index 09e1e3118f..18b3d5bac7 100644
--- a/app/Support/Twig/General.php
+++ b/app/Support/Twig/General.php
@@ -70,7 +70,7 @@ class General extends AbstractExtension
$info = Steam::finalAccountBalance($account, $date);
$currency = Steam::getAccountCurrency($account);
$default = Amount::getDefaultCurrency();
- $convertToNative = app('preferences')->get('convert_to_native', false)->data;
+ $convertToNative = Amount::convertToNative();
$useNative = $convertToNative && $default->id !== $currency->id;
$strings = [];
foreach ($info as $key => $balance) {
diff --git a/resources/views/partials/menu-sidebar.twig b/resources/views/partials/menu-sidebar.twig
index 52f3024148..32fff07238 100644
--- a/resources/views/partials/menu-sidebar.twig
+++ b/resources/views/partials/menu-sidebar.twig
@@ -219,12 +219,14 @@
<span>{{ 'currencies'|_ }}</span>
</a>
</li>
+ {% if config('cer.enabled') %}
<li class="{{ activeRoutePartial('exchange-rates') }}">
<a class="{{ activeRoutePartial('exchange-rates') }}" href="{{ route('exchange-rates.index') }}">
<span class="fa fa-angle-right fa-fw"></span>
<span>{{ 'menu_exchange_rates_index'|_ }}</span>
</a>
</li>
+ {% endif %}
{% if hasRole('owner') %}
<li class="{{ activeRoutePartial('admin') }}">
<a class="{{ activeRoutePartial('admin') }}" href="{{ route('admin.index') }}">
diff --git a/resources/views/preferences/index.twig b/resources/views/preferences/index.twig
index e8f16f4c32..d5b5b26907 100644
--- a/resources/views/preferences/index.twig
+++ b/resources/views/preferences/index.twig
@@ -100,7 +100,8 @@
{{ ExpandedForm.date('fiscalYearStart',fiscalYearStart,{ 'label' : 'pref_fiscal_year_start_label'|_ }) }}
</div>
- {# conversion back to natiev #}
+ {# conversion back to native #}
+ {% if config('cer.enabled') %}
<div class="preferences-box">
<h3>{{ 'pref_convert_to_native'|_ }}</h3>
<p class="text-info">
@@ -108,6 +109,7 @@
</p>
{{ ExpandedForm.checkbox('convertToNative','1',convertToNative,{ 'label' : 'pref_convert_native_help'|_ }) }}
</div>
+ {% endif %}
</div>
{# general settings column B #}