Fix issue with budgets.

This commit is contained in:
James Cole 2020-03-31 07:03:37 +02:00
parent 2c0d8b9cb3
commit 144bc29eb3
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 21 additions and 9 deletions

View File

@ -236,6 +236,7 @@ class IndexController extends Controller
$repository->setBudgetOrder($budget, $index + 1); $repository->setBudgetOrder($budget, $index + 1);
} }
} }
app('preferences')->mark();
return response()->json(['OK']); return response()->json(['OK']);
} }

View File

@ -189,7 +189,7 @@ class BudgetRepository implements BudgetRepositoryInterface
{ {
/** @var Collection $set */ /** @var Collection $set */
$set = $this->user->budgets()->where('active', 1) $set = $this->user->budgets()->where('active', 1)
->orderBy('order', 'ASC') ->orderBy('order', 'DESC')
->orderBy('name', 'ASC') ->orderBy('name', 'ASC')
->get(); ->get();

View File

@ -25,11 +25,9 @@ namespace FireflyIII\Support;
use Crypt; use Crypt;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Preferences as Prefs;
/** /**
* Class Amount. * Class Amount.
@ -204,7 +202,7 @@ class Amount
if ($cache->has()) { if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore 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(); $currency = TransactionCurrency::where('code', $currencyPreference->data)->first();
if ($currency) { if ($currency) {
@ -230,7 +228,7 @@ class Amount
if ($cache->has()) { if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore 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(); $currency = TransactionCurrency::where('code', $currencyPreference->data)->first();
$cache->store($currency->symbol); $cache->store($currency->symbol);
@ -252,6 +250,18 @@ class Amount
return $this->getDefaultCurrencyByUser($user); return $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 * @param User $user
* *
@ -268,17 +278,18 @@ class Amount
if ($cache->has()) { if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore 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. // 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.'); 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: // could still be json encoded:
if (strlen($currencyCode) > 3) { 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(); $currency = TransactionCurrency::where('code', $currencyCode)->first();
if (null === $currency) { if (null === $currency) {
// get EUR // get EUR