diff --git a/app/Http/Controllers/Bill/CreateController.php b/app/Http/Controllers/Bill/CreateController.php index 401ead7c6d..23f3cf5e06 100644 --- a/app/Http/Controllers/Bill/CreateController.php +++ b/app/Http/Controllers/Bill/CreateController.php @@ -77,7 +77,6 @@ class CreateController extends Controller $periods[$current] = (string) trans('firefly.repeat_freq_'.$current); } $subTitle = (string) trans('firefly.create_new_bill'); - $primaryCurrency = $this->primaryCurrency; // put previous url in session if not redirect from store (not "create another"). if (true !== session('bills.create.fromStore')) { @@ -85,7 +84,7 @@ class CreateController extends Controller } $request->session()->forget('bills.create.fromStore'); - return view('bills.create', compact('periods', 'subTitle', 'primaryCurrency')); + return view('bills.create', compact('periods', 'subTitle')); } /** diff --git a/app/Http/Controllers/Bill/EditController.php b/app/Http/Controllers/Bill/EditController.php index de520dfc7f..e9515ef071 100644 --- a/app/Http/Controllers/Bill/EditController.php +++ b/app/Http/Controllers/Bill/EditController.php @@ -88,7 +88,6 @@ class EditController extends Controller $bill->amount_min = app('steam')->bcround($bill->amount_min, $bill->transactionCurrency->decimal_places); $bill->amount_max = app('steam')->bcround($bill->amount_max, $bill->transactionCurrency->decimal_places); $rules = $this->repository->getRulesForBill($bill); - $primaryCurrency = $this->primaryCurrency; // code to handle active-checkboxes $hasOldInput = null !== $request->old('_token'); @@ -105,7 +104,7 @@ class EditController extends Controller $request->session()->flash('preFilled', $preFilled); $request->session()->forget('bills.edit.fromUpdate'); - return view('bills.edit', compact('subTitle', 'periods', 'rules', 'bill', 'primaryCurrency', 'preFilled')); + return view('bills.edit', compact('subTitle', 'periods', 'rules', 'bill', 'preFilled')); } /** diff --git a/app/Http/Controllers/Recurring/CreateController.php b/app/Http/Controllers/Recurring/CreateController.php index f2b5bd599c..c7a776465b 100644 --- a/app/Http/Controllers/Recurring/CreateController.php +++ b/app/Http/Controllers/Recurring/CreateController.php @@ -84,7 +84,6 @@ class CreateController extends Controller { $budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets()); $bills = app('expandedform')->makeSelectListWithEmpty($this->billRepository->getActiveBills()); - $primaryCurrency = $this->primaryCurrency; $tomorrow = today(config('app.timezone')); $oldRepetitionType = $request->old('repetition_type'); $tomorrow->addDay(); @@ -116,7 +115,7 @@ class CreateController extends Controller return view( 'recurring.create', - compact('tomorrow', 'oldRepetitionType', 'bills', 'weekendResponses', 'preFilled', 'repetitionEnds', 'primaryCurrency', 'budgets') + compact('tomorrow', 'oldRepetitionType', 'bills', 'weekendResponses', 'preFilled', 'repetitionEnds', 'budgets') ); } @@ -129,7 +128,6 @@ class CreateController extends Controller { $budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets()); $bills = app('expandedform')->makeSelectListWithEmpty($this->billRepository->getActiveBills()); - $primaryCurrency = $this->primaryCurrency; $tomorrow = today(config('app.timezone')); $oldRepetitionType = $request->old('repetition_type'); $tomorrow->addDay(); @@ -208,10 +206,7 @@ class CreateController extends Controller } $request->session()->flash('preFilled', $preFilled); - return view( - 'recurring.create', - compact('tomorrow', 'oldRepetitionType', 'bills', 'weekendResponses', 'preFilled', 'repetitionEnds', 'primaryCurrency', 'budgets') - ); + return view('recurring.create', compact('tomorrow', 'oldRepetitionType', 'bills', 'weekendResponses', 'preFilled', 'repetitionEnds', 'budgets')); } /** diff --git a/app/Http/Controllers/Transaction/CreateController.php b/app/Http/Controllers/Transaction/CreateController.php index d8e6092837..519ff3d538 100644 --- a/app/Http/Controllers/Transaction/CreateController.php +++ b/app/Http/Controllers/Transaction/CreateController.php @@ -117,7 +117,6 @@ class CreateController extends Controller $optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data; $allowedOpposingTypes = config('firefly.allowed_opposing_types'); $accountToTypes = config('firefly.account_to_transaction'); - $primaryCurrency = $this->primaryCurrency; $previousUrl = $this->rememberPreviousUrl('transactions.create.url'); $parts = parse_url((string) $previousUrl); $search = sprintf('?%s', $parts['query'] ?? ''); @@ -145,26 +144,6 @@ class CreateController extends Controller session()->put('preFilled', $preFilled); - return view( - 'transactions.create', - compact( - 'subTitleIcon', - 'cash', - 'longitude', - 'latitude', - 'zoomLevel', - 'objectType', - 'optionalDateFields', - 'subTitle', - 'primaryCurrency', - 'previousUrl', - 'optionalFields', - 'preFilled', - 'allowedOpposingTypes', - 'accountToTypes', - 'sourceId', - 'destinationId' - ) - ); + return view('transactions.create', compact('subTitleIcon', 'cash', 'longitude', 'latitude', 'zoomLevel', 'objectType', 'optionalDateFields', 'subTitle', 'previousUrl', 'optionalFields', 'preFilled', 'allowedOpposingTypes', 'accountToTypes', 'sourceId', 'destinationId')); } } diff --git a/app/Http/Controllers/Transaction/EditController.php b/app/Http/Controllers/Transaction/EditController.php index 507cc0cc34..5b30ec7a9f 100644 --- a/app/Http/Controllers/Transaction/EditController.php +++ b/app/Http/Controllers/Transaction/EditController.php @@ -84,7 +84,6 @@ class EditController extends Controller $title = $transactionGroup->transactionJournals()->count() > 1 ? $transactionGroup->title : $transactionGroup->transactionJournals()->first()->description; $subTitle = (string) trans('firefly.edit_transaction_title', ['description' => $title]); $subTitleIcon = 'fa-plus'; - $primaryCurrency = $this->primaryCurrency; $cash = $repository->getCashAccount(); $previousUrl = $this->rememberPreviousUrl('transactions.edit.url'); $parts = parse_url((string) $previousUrl); @@ -114,26 +113,7 @@ class EditController extends Controller $latitude = config('firefly.default_location.latitude'); $zoomLevel = config('firefly.default_location.zoom_level'); - return view( - 'transactions.edit', - compact( - 'cash', - 'allowedSourceDests', - 'expectedSourceTypes', - 'optionalDateFields', - 'longitude', - 'latitude', - 'zoomLevel', - 'optionalFields', - 'subTitle', - 'subTitleIcon', - 'transactionGroup', - 'allowedOpposingTypes', - 'accountToTypes', - 'primaryCurrency', - 'previousUrl' - ) - ); + return view('transactions.edit', compact('cash', 'allowedSourceDests', 'expectedSourceTypes', 'optionalDateFields', 'longitude', 'latitude', 'zoomLevel', 'optionalFields', 'subTitle', 'subTitleIcon', 'transactionGroup', 'allowedOpposingTypes', 'accountToTypes', 'previousUrl')); } public function unreconcile(TransactionJournal $journal): JsonResponse diff --git a/app/Support/Amount.php b/app/Support/Amount.php index c0c40ac390..b192b5d035 100644 --- a/app/Support/Amount.php +++ b/app/Support/Amount.php @@ -176,7 +176,7 @@ class Amount public function getSystemCurrency(): TransactionCurrency { - return TransactionCurrency::where('code', 'EUR')->first(); + return TransactionCurrency::whereNull('deleted_at')->where('code', 'EUR')->first(); } /** diff --git a/app/Support/Twig/AmountFormat.php b/app/Support/Twig/AmountFormat.php index 3a014e8003..a88836cbb4 100644 --- a/app/Support/Twig/AmountFormat.php +++ b/app/Support/Twig/AmountFormat.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Support\Twig; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account as AccountModel; use FireflyIII\Models\TransactionCurrency; use FireflyIII\Repositories\Account\AccountRepositoryInterface; @@ -52,9 +53,9 @@ class AmountFormat extends AbstractExtension return new TwigFilter( 'formatAmount', static function (string $string): string { - $currency = app('amount')->getPrimaryCurrency(); + $currency = Amount::getPrimaryCurrency(); - return app('amount')->formatAnything($currency, $string, true); + return Amount::formatAnything($currency, $string, true); }, ['is_safe' => ['html']] ); @@ -65,9 +66,9 @@ class AmountFormat extends AbstractExtension return new TwigFilter( 'formatAmountPlain', static function (string $string): string { - $currency = app('amount')->getPrimaryCurrency(); + $currency = Amount::getPrimaryCurrency(); - return app('amount')->formatAnything($currency, $string, false); + return Amount::formatAnything($currency, $string, false); }, ['is_safe' => ['html']] ); @@ -98,9 +99,9 @@ class AmountFormat extends AbstractExtension /** @var AccountRepositoryInterface $accountRepos */ $accountRepos = app(AccountRepositoryInterface::class); - $currency = $accountRepos->getAccountCurrency($account) ?? app('amount')->getPrimaryCurrency(); + $currency = $accountRepos->getAccountCurrency($account) ?? Amount::getPrimaryCurrency(); - return app('amount')->formatAnything($currency, $amount, $coloured); + return Amount::formatAnything($currency, $amount, $coloured); }, ['is_safe' => ['html']] ); @@ -113,14 +114,21 @@ class AmountFormat extends AbstractExtension { return new TwigFunction( 'formatAmountBySymbol', - static function (string $amount, string $symbol, ?int $decimalPlaces = null, ?bool $coloured = null): string { + static function (string $amount, ?string $symbol, ?int $decimalPlaces = null, ?bool $coloured = null): string { + + if(null === $symbol) { + $message = sprintf('formatAmountBySymbol("%s", "%s", %d, %s) was called without a symbol. Please browse to /flush to clear your cache.', $amount,$symbol, $decimalPlaces, var_export($coloured, true)); + Log::error($message); + throw new FireflyException($message); + } + $decimalPlaces ??= 2; $coloured ??= true; $currency = new TransactionCurrency(); $currency->symbol = $symbol; $currency->decimal_places = $decimalPlaces; - return app('amount')->formatAnything($currency, $amount, $coloured); + return Amount::formatAnything($currency, $amount, $coloured); }, ['is_safe' => ['html']] ); @@ -136,7 +144,7 @@ class AmountFormat extends AbstractExtension static function (TransactionCurrency $currency, string $amount, ?bool $coloured = null): string { $coloured ??= true; - return app('amount')->formatAnything($currency, $amount, $coloured); + return Amount::formatAnything($currency, $amount, $coloured); }, ['is_safe' => ['html']] ); @@ -161,7 +169,7 @@ class AmountFormat extends AbstractExtension Log::error(sprintf('Fallback currency is "%s".', $currency->code)); } - return app('amount')->formatAnything($currency, $amount, $coloured); + return Amount::formatAnything($currency, $amount, $coloured); }, ['is_safe' => ['html']] );