Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix issue with budgets.
James Cole144bc29eb325
diff --git a/app/Http/Controllers/Budget/IndexController.php b/app/Http/Controllers/Budget/IndexController.phpindex 69d4e2dc4d..2a51d1588b 100644--- a/app/Http/Controllers/Budget/IndexController.php+++ b/app/Http/Controllers/Budget/IndexController.php@@ -236,6 +236,7 @@ class IndexController extends Controller$repository->setBudgetOrder($budget, $index + 1);}}+ app('preferences')->mark();return response()->json(['OK']);}diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.phpindex 07fdebbc86..36ba46b896 100644--- a/app/Repositories/Budget/BudgetRepository.php+++ b/app/Repositories/Budget/BudgetRepository.php@@ -189,7 +189,7 @@ class BudgetRepository implements BudgetRepositoryInterface{/** @var Collection $set */$set = $this->user->budgets()->where('active', 1)- ->orderBy('order', 'ASC')+ ->orderBy('order', 'DESC')->orderBy('name', 'ASC')->get();diff --git a/app/Support/Amount.php b/app/Support/Amount.phpindex 0d8a905742..c5b69fbdbf 100644--- a/app/Support/Amount.php+++ b/app/Support/Amount.php@@ -25,11 +25,9 @@ namespace FireflyIII\Support;use Crypt;use FireflyIII\Models\TransactionCurrency;use FireflyIII\User;-use Illuminate\Contracts\Auth\Authenticatable;use Illuminate\Contracts\Encryption\DecryptException;use Illuminate\Support\Collection;use Log;-use Preferences as Prefs;/*** Class Amount.@@ -204,7 +202,7 @@ class Amountif ($cache->has()) {return $cache->get(); // @codeCoverageIgnore}- $currencyPreference = Prefs::get('currencyPreference', config('firefly.default_currency', 'EUR'));+ $currencyPreference = app('preferences')->get('currencyPreference', config('firefly.default_currency', 'EUR'));$currency = TransactionCurrency::where('code', $currencyPreference->data)->first();if ($currency) {@@ -230,7 +228,7 @@ class Amountif ($cache->has()) {return $cache->get(); // @codeCoverageIgnore}- $currencyPreference = Prefs::get('currencyPreference', config('firefly.default_currency', 'EUR'));+ $currencyPreference = app('preferences')->get('currencyPreference', config('firefly.default_currency', 'EUR'));$currency = TransactionCurrency::where('code', $currencyPreference->data)->first();$cache->store($currency->symbol);@@ -252,6 +250,18 @@ class Amountreturn $this->getDefaultCurrencyByUser($user);}+ /**+ * @return \FireflyIII\Models\TransactionCurrency+ */+ public function getSystemCurrency(): TransactionCurrency+ {+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }++ return TransactionCurrency::where('code', 'EUR')->first();+ }+/*** @param User $user*@@ -268,17 +278,18 @@ class Amountif ($cache->has()) {return $cache->get(); // @codeCoverageIgnore}- $currencyPreference = Prefs::getForUser($user, 'currencyPreference', config('firefly.default_currency', 'EUR'));+ $currencyPreference = app('preferences')->getForUser($user, 'currencyPreference', config('firefly.default_currency', 'EUR'));+ $currencyPrefStr = $currencyPreference ? $currencyPreference->data : 'EUR';// at this point the currency preference could be encrypted, if coming from an old version.Log::debug('Going to try to decrypt users currency preference.');- $currencyCode = $this->tryDecrypt((string)$currencyPreference->data);+ $currencyCode = $this->tryDecrypt((string) $currencyPrefStr);// could still be json encoded:if (strlen($currencyCode) > 3) {- $currencyCode = json_decode($currencyCode, true) ?? 'EUR';+ $currencyCode = json_decode($currencyCode, true, 512, JSON_THROW_ON_ERROR) ?? 'EUR';}-+ /** @var TransactionCurrency $currency */$currency = TransactionCurrency::where('code', $currencyCode)->first();if (null === $currency) {// get EUR