From 62f4da6063e8bb7e5c650036a1a0b9cb72189eaa Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 30 Dec 2024 10:51:34 +0100 Subject: [PATCH] Update available budgets code. --- app/Handlers/Events/Model/BudgetLimitHandler.php | 1 + .../Observer/AvailableBudgetObserver.php | 2 +- .../Controllers/Account/CreateController.php | 3 +-- app/Http/Controllers/Account/EditController.php | 2 +- .../Controllers/Account/ReconcileController.php | 4 ++-- app/Http/Controllers/Account/ShowController.php | 4 ++-- app/Http/Controllers/Bill/CreateController.php | 2 +- app/Http/Controllers/Bill/EditController.php | 7 +++---- app/Http/Controllers/Budget/CreateController.php | 3 +-- app/Http/Controllers/Budget/EditController.php | 3 +-- app/Http/Controllers/Budget/IndexController.php | 12 +++++++----- app/Http/Controllers/Chart/AccountController.php | 6 ++---- app/Http/Controllers/Chart/BudgetController.php | 2 +- app/Http/Controllers/Controller.php | 2 +- app/Http/Controllers/Json/BoxController.php | 16 +++++++--------- .../Controllers/Json/ReconcileController.php | 4 ++-- app/Http/Controllers/PreferencesController.php | 7 +++++++ .../Controllers/Recurring/CreateController.php | 4 ++-- .../Transaction/ConvertController.php | 6 ++---- .../Controllers/Transaction/CreateController.php | 2 +- .../Controllers/Transaction/EditController.php | 2 +- app/Http/Middleware/Range.php | 5 +++-- app/Http/Requests/PiggyBankStoreRequest.php | 3 ++- app/Http/Requests/PiggyBankUpdateRequest.php | 3 ++- app/Models/RecurrenceRepetition.php | 8 ++++---- app/Repositories/Bill/BillRepository.php | 2 +- .../Budget/AvailableBudgetRepository.php | 9 +++++---- .../Report/Summarizer/TransactionSummarizer.php | 2 +- 28 files changed, 65 insertions(+), 61 deletions(-) diff --git a/app/Handlers/Events/Model/BudgetLimitHandler.php b/app/Handlers/Events/Model/BudgetLimitHandler.php index 6164460cdd..a0a60b60e1 100644 --- a/app/Handlers/Events/Model/BudgetLimitHandler.php +++ b/app/Handlers/Events/Model/BudgetLimitHandler.php @@ -143,6 +143,7 @@ class BudgetLimitHandler ); $availableBudget->save(); Log::debug(sprintf('ID of new AB is #%d', $availableBudget->id)); + $this->calculateAmount($availableBudget); } } diff --git a/app/Handlers/Observer/AvailableBudgetObserver.php b/app/Handlers/Observer/AvailableBudgetObserver.php index 8644bac575..ec23dd7df6 100644 --- a/app/Handlers/Observer/AvailableBudgetObserver.php +++ b/app/Handlers/Observer/AvailableBudgetObserver.php @@ -33,7 +33,7 @@ class AvailableBudgetObserver { public function created(AvailableBudget $availableBudget): void { - Log::debug('Observe "created" of an available budget.'); + // Log::debug('Observe "created" of an available budget.'); $this->updateNativeAmount($availableBudget); } diff --git a/app/Http/Controllers/Account/CreateController.php b/app/Http/Controllers/Account/CreateController.php index be9260c369..20dec447c6 100644 --- a/app/Http/Controllers/Account/CreateController.php +++ b/app/Http/Controllers/Account/CreateController.php @@ -76,7 +76,6 @@ class CreateController extends Controller */ public function create(Request $request, string $objectType) { - $defaultCurrency = app('amount')->getDefaultCurrency(); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); $subTitle = (string) trans(sprintf('firefly.make_new_%s_account', $objectType)); $roles = $this->getRoles(); @@ -106,7 +105,7 @@ class CreateController extends Controller $request->session()->flash( 'preFilled', [ - 'currency_id' => $defaultCurrency->id, + 'currency_id' => $this->defaultCurrency->id, 'include_net_worth' => $hasOldInput ? (bool) $request->old('include_net_worth') : true, ] ); diff --git a/app/Http/Controllers/Account/EditController.php b/app/Http/Controllers/Account/EditController.php index ca674eb407..a72c579179 100644 --- a/app/Http/Controllers/Account/EditController.php +++ b/app/Http/Controllers/Account/EditController.php @@ -124,7 +124,7 @@ class EditController extends Controller $openingBalanceAmount = ''; } $openingBalanceDate = $repository->getOpeningBalanceDate($account); - $currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); + $currency = $this->repository->getAccountCurrency($account) ?? $this->defaultCurrency; // include this account in net-worth charts? $includeNetWorth = $repository->getMetaValue($account, 'include_net_worth'); diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.php index 6a76227a83..ec3673c014 100644 --- a/app/Http/Controllers/Account/ReconcileController.php +++ b/app/Http/Controllers/Account/ReconcileController.php @@ -86,7 +86,7 @@ class ReconcileController extends Controller return redirect(route('accounts.index', [config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type))])); } - $currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); + $currency = $this->accountRepos->getAccountCurrency($account) ?? $this->defaultCurrency; // no start or end: $range = app('navigation')->getViewRange(false); @@ -197,7 +197,7 @@ class ReconcileController extends Controller } $reconciliation = $this->accountRepos->getReconciliation($account); - $currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); + $currency = $this->accountRepos->getAccountCurrency($account) ?? $this->defaultCurrency; $source = $reconciliation; $destination = $account; if (1 === bccomp($difference, '0')) { diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.php index 6b6caffb64..2840229849 100644 --- a/app/Http/Controllers/Account/ShowController.php +++ b/app/Http/Controllers/Account/ShowController.php @@ -101,7 +101,7 @@ class ShowController extends Controller $page = (int) $request->get('page'); $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $accountCurrency = $this->repository->getAccountCurrency($account); - $currency = $accountCurrency ?? Amount::getDefaultCurrency(); + $currency = $accountCurrency ?? $this->defaultCurrency; $fStart = $start->isoFormat($this->monthAndDayFormat); $fEnd = $end->isoFormat($this->monthAndDayFormat); $subTitle = (string) trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]); @@ -178,7 +178,7 @@ class ShowController extends Controller $subTitleIcon = config('firefly.subIconsByIdentifier.'.$account->accountType->type); $page = (int) $request->get('page'); $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; - $currency = $this->repository->getAccountCurrency($account) ?? Amount::getDefaultCurrency(); + $currency = $this->repository->getAccountCurrency($account) ?? $this->defaultCurrency; $subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]); $periods = new Collection(); diff --git a/app/Http/Controllers/Bill/CreateController.php b/app/Http/Controllers/Bill/CreateController.php index b126273230..664f7d8689 100644 --- a/app/Http/Controllers/Bill/CreateController.php +++ b/app/Http/Controllers/Bill/CreateController.php @@ -77,7 +77,7 @@ class CreateController extends Controller $periods[$current] = (string) trans('firefly.repeat_freq_'.$current); } $subTitle = (string) trans('firefly.create_new_bill'); - $defaultCurrency = app('amount')->getDefaultCurrency(); + $defaultCurrency = $this->defaultCurrency; // put previous url in session if not redirect from store (not "create another"). if (true !== session('bills.create.fromStore')) { diff --git a/app/Http/Controllers/Bill/EditController.php b/app/Http/Controllers/Bill/EditController.php index abb062e606..c3f7b24969 100644 --- a/app/Http/Controllers/Bill/EditController.php +++ b/app/Http/Controllers/Bill/EditController.php @@ -85,11 +85,10 @@ class EditController extends Controller $this->rememberPreviousUrl('bills.edit.url'); } - $currency = app('amount')->getDefaultCurrency(); - $bill->amount_min = app('steam')->bcround($bill->amount_min, $currency->decimal_places); - $bill->amount_max = app('steam')->bcround($bill->amount_max, $currency->decimal_places); + $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); - $defaultCurrency = app('amount')->getDefaultCurrency(); + $defaultCurrency = $this->defaultCurrency; // code to handle active-checkboxes $hasOldInput = null !== $request->old('_token'); diff --git a/app/Http/Controllers/Budget/CreateController.php b/app/Http/Controllers/Budget/CreateController.php index 9bdc298e8f..026b3629e4 100644 --- a/app/Http/Controllers/Budget/CreateController.php +++ b/app/Http/Controllers/Budget/CreateController.php @@ -86,11 +86,10 @@ class CreateController extends Controller 'half_year' => (string) trans('firefly.auto_budget_period_half_year'), 'yearly' => (string) trans('firefly.auto_budget_period_yearly'), ]; - $currency = app('amount')->getDefaultCurrency(); $preFilled = [ 'auto_budget_period' => $hasOldInput ? (bool) $request->old('auto_budget_period') : 'monthly', - 'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $currency->id, + 'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $this->defaultCurrency->id, ]; $request->session()->flash('preFilled', $preFilled); diff --git a/app/Http/Controllers/Budget/EditController.php b/app/Http/Controllers/Budget/EditController.php index 8729985fac..382dc3a756 100644 --- a/app/Http/Controllers/Budget/EditController.php +++ b/app/Http/Controllers/Budget/EditController.php @@ -91,10 +91,9 @@ class EditController extends Controller // code to handle active-checkboxes $hasOldInput = null !== $request->old('_token'); - $currency = app('amount')->getDefaultCurrency(); $preFilled = [ 'active' => $hasOldInput ? (bool) $request->old('active') : $budget->active, - 'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $currency->id, + 'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $this->defaultCurrency->id, ]; if (null !== $autoBudget) { $amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount; diff --git a/app/Http/Controllers/Budget/IndexController.php b/app/Http/Controllers/Budget/IndexController.php index c49cee169c..8c67680cba 100644 --- a/app/Http/Controllers/Budget/IndexController.php +++ b/app/Http/Controllers/Budget/IndexController.php @@ -42,6 +42,7 @@ use Illuminate\Contracts\View\Factory; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Log; use Illuminate\View\View; /** @@ -106,7 +107,6 @@ class IndexController extends Controller $end ??= session('end', today(config('app.timezone'))->endOfMonth()); } - $defaultCurrency = app('amount')->getDefaultCurrency(); $currencies = $this->currencyRepository->get(); $budgeted = '0'; $spent = '0'; @@ -119,14 +119,14 @@ class IndexController extends Controller // get all available budgets: $availableBudgets = $this->getAllAvailableBudgets($start, $end); // get all active budgets: - $budgets = $this->getAllBudgets($start, $end, $currencies, $defaultCurrency); + $budgets = $this->getAllBudgets($start, $end, $currencies, $this->defaultCurrency); $sums = $this->getSums($budgets); // get budgeted for default currency: if (0 === count($availableBudgets)) { - $budgeted = $this->blRepository->budgeted($start, $end, $defaultCurrency); - $spentArr = $this->opsRepository->sumExpenses($start, $end, null, null, $defaultCurrency); - $spent = $spentArr[$defaultCurrency->id]['sum'] ?? '0'; + $budgeted = $this->blRepository->budgeted($start, $end, $this->defaultCurrency); + $spentArr = $this->opsRepository->sumExpenses($start, $end, null, null, $this->defaultCurrency); + $spent = $spentArr[$this->defaultCurrency->id]['sum'] ?? '0'; unset($spentArr); } @@ -136,6 +136,7 @@ class IndexController extends Controller // get all inactive budgets, and simply list them: $inactive = $this->repository->getInactiveBudgets(); + $defaultCurrency = $this->defaultCurrency; return view( 'budgets.index', @@ -162,6 +163,7 @@ class IndexController extends Controller private function getAllAvailableBudgets(Carbon $start, Carbon $end): array { + Log::debug(sprintf('Start of getAllAvailableBudgets("%s", "%s")', $start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s'))); $converter = new ExchangeRateConverter(); // get all available budgets. $ab = $this->abRepository->get($start, $end); diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 09d5bb6ccd..bfd43804e0 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -103,7 +103,6 @@ class AccountController extends Controller $currencies = []; $chartData = []; $tempData = []; - $default = Amount::getDefaultCurrency(); // grab all accounts and names $accounts = $this->accountRepository->getAccountsByType([AccountTypeEnum::EXPENSE->value]); @@ -139,7 +138,7 @@ class AccountController extends Controller continue; } Log::debug(sprintf('Will process expense array "%s" with amount %s', $key, $endBalance)); - $searchCode = $this->convertToNative ? $default->code : $key; + $searchCode = $this->convertToNative ? $this->defaultCurrency->code : $key; Log::debug(sprintf('Search code is %s', $searchCode)); // see if there is an accompanying start amount. // grab the difference and find the currency. @@ -562,7 +561,6 @@ class AccountController extends Controller $currencies = []; $chartData = []; $tempData = []; - $default = Amount::getDefaultCurrency(); // grab all accounts and names $accounts = $this->accountRepository->getAccountsByType([AccountTypeEnum::REVENUE->value]); @@ -599,7 +597,7 @@ class AccountController extends Controller continue; } Log::debug(sprintf('Will process expense array "%s" with amount %s', $key, $endBalance)); - $searchCode = $this->convertToNative ? $default->code : $key; + $searchCode = $this->convertToNative ? $this->defaultCurrency->code : $key; Log::debug(sprintf('Search code is %s', $searchCode)); // see if there is an accompanying start amount. // grab the difference and find the currency. diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index df07bf8d10..2ae6db7a63 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -465,7 +465,7 @@ class BudgetController extends Controller $chartGenerator->setStart($start); $chartGenerator->setEnd($end); $chartGenerator->convertToNative = $this->convertToNative; - $chartGenerator->default = Amount::getDefaultCurrency(); + $chartGenerator->default = $this->defaultCurrency; $chartData = $chartGenerator->generate(); $data = $this->generator->multiSet($chartData); diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 1dcdbe3be8..237b02d55a 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -118,7 +118,7 @@ abstract class Controller extends BaseController $this->defaultCurrency =null; // get shown-intro-preference: if (auth()->check()) { - $this->defaultCurrency = app('amount')->getDefaultCurrency(); + $this->defaultCurrency = Amount::getDefaultCurrency(); $language = Steam::getLanguage(); $locale = Steam::getLocale(); $darkMode = app('preferences')->get('darkMode', 'browser')->data; diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php index d7781be69a..a20d2d8306 100644 --- a/app/Http/Controllers/Json/BoxController.php +++ b/app/Http/Controllers/Json/BoxController.php @@ -78,9 +78,7 @@ class BoxController extends Controller $incomes = []; $expenses = []; $sums = []; - $currency = app('amount')->getDefaultCurrency(); - - + $currency = $this->defaultCurrency; // collect income of user: /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); @@ -91,7 +89,7 @@ class BoxController extends Controller /** @var array $journal */ foreach ($set as $journal) { - $currencyId = $this->convertToNative ? $currency->id : (int) $journal['currency_id']; + $currencyId = $this->convertToNative && $this->defaultCurrency->id !== (int) $journal['currency_id'] ? $this->defaultCurrency->id : (int) $journal['currency_id']; $amount = Amount::getAmountFromJournal($journal); $incomes[$currencyId] ??= '0'; $incomes[$currencyId] = bcadd($incomes[$currencyId], app('steam')->positive($amount)); @@ -109,7 +107,7 @@ class BoxController extends Controller /** @var array $journal */ foreach ($set as $journal) { - $currencyId = $this->convertToNative ? $currency->id : (int) $journal['currency_id']; + $currencyId = $this->convertToNative ? $this->defaultCurrency->id : (int) $journal['currency_id']; $amount = Amount::getAmountFromJournal($journal); $expenses[$currencyId] ??= '0'; $expenses[$currencyId] = bcadd($expenses[$currencyId], $amount); @@ -126,10 +124,10 @@ class BoxController extends Controller $expenses[$currencyId] = app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false); } if (0 === count($sums)) { - $currency = app('amount')->getDefaultCurrency(); - $sums[$currency->id] = app('amount')->formatAnything($currency, '0', false); - $incomes[$currency->id] = app('amount')->formatAnything($currency, '0', false); - $expenses[$currency->id] = app('amount')->formatAnything($currency, '0', false); + $currency = $this->defaultCurrency; + $sums[$this->defaultCurrency->id] = app('amount')->formatAnything($this->defaultCurrency, '0', false); + $incomes[$this->defaultCurrency->id] = app('amount')->formatAnything($this->defaultCurrency, '0', false); + $expenses[$this->defaultCurrency->id] = app('amount')->formatAnything($this->defaultCurrency, '0', false); } $response = [ diff --git a/app/Http/Controllers/Json/ReconcileController.php b/app/Http/Controllers/Json/ReconcileController.php index e27bda139a..38c29896f3 100644 --- a/app/Http/Controllers/Json/ReconcileController.php +++ b/app/Http/Controllers/Json/ReconcileController.php @@ -73,7 +73,7 @@ class ReconcileController extends Controller { $startBalance = $request->get('startBalance'); $endBalance = $request->get('endBalance'); - $accountCurrency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); + $accountCurrency = $this->accountRepos->getAccountCurrency($account) ?? $this->defaultCurrency; $amount = '0'; $clearedAmount = '0'; @@ -193,7 +193,7 @@ class ReconcileController extends Controller $startDate->subDay(); $end->endOfDay(); - $currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); + $currency = $this->accountRepos->getAccountCurrency($account) ?? $this->defaultCurrency; $startBalance = Steam::finalAccountBalance($account, $startDate)['balance']; $endBalance = Steam::finalAccountBalance($account, $end)['balance']; diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php index 290e60ea86..811da4c325 100644 --- a/app/Http/Controllers/PreferencesController.php +++ b/app/Http/Controllers/PreferencesController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers; +use FireflyIII\Events\Preferences\UserGroupChangedDefaultCurrency; use FireflyIII\Events\Test\UserTestNotificationChannel; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Requests\PreferencesRequest; @@ -35,6 +36,7 @@ use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Routing\Redirector; +use Illuminate\Support\Facades\Log; use Illuminate\View\View; /** @@ -258,6 +260,11 @@ class PreferencesController extends Controller // convert native $convertToNative = 1 === (int) $request->get('convertToNative'); + if($convertToNative && !$this->convertToNative) { + // set to true! + Log::debug('User sets convertToNative to true.'); + event(new UserGroupChangedDefaultCurrency(auth()->user()->userGroup)); + } app('preferences')->set('convert_to_native', $convertToNative); // custom fiscal year diff --git a/app/Http/Controllers/Recurring/CreateController.php b/app/Http/Controllers/Recurring/CreateController.php index c8c91df86b..2a79a90092 100644 --- a/app/Http/Controllers/Recurring/CreateController.php +++ b/app/Http/Controllers/Recurring/CreateController.php @@ -84,7 +84,7 @@ class CreateController extends Controller { $budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets()); $bills = app('expandedform')->makeSelectListWithEmpty($this->billRepository->getActiveBills()); - $defaultCurrency = app('amount')->getDefaultCurrency(); + $defaultCurrency = $this->defaultCurrency; $tomorrow = today(config('app.timezone')); $oldRepetitionType = $request->old('repetition_type'); $tomorrow->addDay(); @@ -129,7 +129,7 @@ class CreateController extends Controller { $budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets()); $bills = app('expandedform')->makeSelectListWithEmpty($this->billRepository->getActiveBills()); - $defaultCurrency = app('amount')->getDefaultCurrency(); + $defaultCurrency = $this->defaultCurrency; $tomorrow = today(config('app.timezone')); $oldRepetitionType = $request->old('repetition_type'); $tomorrow->addDay(); diff --git a/app/Http/Controllers/Transaction/ConvertController.php b/app/Http/Controllers/Transaction/ConvertController.php index ca3700b0eb..775d714d26 100644 --- a/app/Http/Controllers/Transaction/ConvertController.php +++ b/app/Http/Controllers/Transaction/ConvertController.php @@ -217,14 +217,13 @@ class ConvertController extends Controller { // make repositories $accountList = $this->accountRepository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); - $defaultCurrency = app('amount')->getDefaultCurrency(); $grouped = []; // group accounts: /** @var Account $account */ foreach ($accountList as $account) { $balance = Steam::finalAccountBalance($account, today()->endOfDay())['balance']; - $currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency; + $currency = $this->accountRepository->getAccountCurrency($account) ?? $this->defaultCurrency; $role = 'l_'.$account->accountType->type; $key = (string) trans('firefly.opt_group_'.$role); $grouped[$key][$account->id] = $account->name.' ('.app('amount')->formatAnything($currency, $balance, false).')'; @@ -240,14 +239,13 @@ class ConvertController extends Controller { // make repositories $accountList = $this->accountRepository->getActiveAccountsByType([AccountType::ASSET]); - $defaultCurrency = app('amount')->getDefaultCurrency(); $grouped = []; // group accounts: /** @var Account $account */ foreach ($accountList as $account) { $balance = Steam::finalAccountBalance($account, today()->endOfDay())['balance']; - $currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency; + $currency = $this->accountRepository->getAccountCurrency($account) ?? $this->defaultCurrency; $role = (string) $this->accountRepository->getMetaValue($account, 'account_role'); if ('' === $role) { $role = 'no_account_type'; diff --git a/app/Http/Controllers/Transaction/CreateController.php b/app/Http/Controllers/Transaction/CreateController.php index a1b29b3877..fad87c640a 100644 --- a/app/Http/Controllers/Transaction/CreateController.php +++ b/app/Http/Controllers/Transaction/CreateController.php @@ -114,7 +114,7 @@ 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'); - $defaultCurrency = app('amount')->getDefaultCurrency(); + $defaultCurrency = $this->defaultCurrency; $previousUrl = $this->rememberPreviousUrl('transactions.create.url'); $parts = parse_url($previousUrl); $search = sprintf('?%s', $parts['query'] ?? ''); diff --git a/app/Http/Controllers/Transaction/EditController.php b/app/Http/Controllers/Transaction/EditController.php index 9f2da101d2..c638deb7c8 100644 --- a/app/Http/Controllers/Transaction/EditController.php +++ b/app/Http/Controllers/Transaction/EditController.php @@ -82,7 +82,7 @@ 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'; - $defaultCurrency = app('amount')->getDefaultCurrency(); + $defaultCurrency = $this->defaultCurrency; $cash = $repository->getCashAccount(); $previousUrl = $this->rememberPreviousUrl('transactions.edit.url'); $parts = parse_url($previousUrl); diff --git a/app/Http/Middleware/Range.php b/app/Http/Middleware/Range.php index 228b4bda88..3e0dc65f63 100644 --- a/app/Http/Middleware/Range.php +++ b/app/Http/Middleware/Range.php @@ -25,6 +25,7 @@ namespace FireflyIII\Http\Middleware; use Carbon\Carbon; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; +use FireflyIII\Support\Facades\Amount; use FireflyIII\Support\Http\Controllers\RequestInformation; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; @@ -108,7 +109,7 @@ class Range setlocale(LC_TIME, $localeArray); $moneyResult = setlocale(LC_MONETARY, $localeArray); - // send error to view, if could not set money format + // send error to view, if it could not set money format if (false === $moneyResult) { app('log')->error('Could not set locale. The following array doesnt work: ', $localeArray); app('view')->share('invalidMonetaryLocale', true); @@ -117,7 +118,7 @@ class Range // save some formats: $monthAndDayFormat = (string) trans('config.month_and_day_js', [], $locale); $dateTimeFormat = (string) trans('config.date_time_js', [], $locale); - $defaultCurrency = app('amount')->getDefaultCurrency(); + $defaultCurrency = Amount::getDefaultCurrency(); // also format for moment JS: $madMomentJS = (string) trans('config.month_and_day_moment_js', [], $locale); diff --git a/app/Http/Requests/PiggyBankStoreRequest.php b/app/Http/Requests/PiggyBankStoreRequest.php index de06a31528..5dfe510745 100644 --- a/app/Http/Requests/PiggyBankStoreRequest.php +++ b/app/Http/Requests/PiggyBankStoreRequest.php @@ -26,6 +26,7 @@ namespace FireflyIII\Http\Requests; use FireflyIII\Models\TransactionCurrency; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Rules\IsValidPositiveAmount; +use FireflyIII\Support\Facades\Amount; use FireflyIII\Support\Request\ChecksLogin; use FireflyIII\Support\Request\ConvertsDataTypes; use Illuminate\Foundation\Http\FormRequest; @@ -125,7 +126,7 @@ class PiggyBankStoreRequest extends FormRequest $currencyId = (int) ($data['transaction_currency_id'] ?? 0); $currency = TransactionCurrency::find($currencyId); if (null === $currency) { - return app('amount')->getDefaultCurrency(); + return Amount::getDefaultCurrency(); } return $currency; diff --git a/app/Http/Requests/PiggyBankUpdateRequest.php b/app/Http/Requests/PiggyBankUpdateRequest.php index 7a76ae0ca2..e3deddb188 100644 --- a/app/Http/Requests/PiggyBankUpdateRequest.php +++ b/app/Http/Requests/PiggyBankUpdateRequest.php @@ -27,6 +27,7 @@ use FireflyIII\Models\PiggyBank; use FireflyIII\Models\TransactionCurrency; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Rules\IsValidPositiveAmount; +use FireflyIII\Support\Facades\Amount; use FireflyIII\Support\Request\ChecksLogin; use FireflyIII\Support\Request\ConvertsDataTypes; use Illuminate\Foundation\Http\FormRequest; @@ -128,7 +129,7 @@ class PiggyBankUpdateRequest extends FormRequest $currencyId = (int) ($data['transaction_currency_id'] ?? 0); $currency = TransactionCurrency::find($currencyId); if (null === $currency) { - return app('amount')->getDefaultCurrency(); + return Amount::getDefaultCurrency(); } return $currency; diff --git a/app/Models/RecurrenceRepetition.php b/app/Models/RecurrenceRepetition.php index f226d184ff..0d1453a986 100644 --- a/app/Models/RecurrenceRepetition.php +++ b/app/Models/RecurrenceRepetition.php @@ -38,16 +38,16 @@ class RecurrenceRepetition extends Model use ReturnsIntegerIdTrait; use SoftDeletes; - #[\Deprecated] + #[\Deprecated] /** @deprecated */ public const int WEEKEND_DO_NOTHING = 1; - #[\Deprecated] + #[\Deprecated] /** @deprecated */ public const int WEEKEND_SKIP_CREATION = 2; - #[\Deprecated] + #[\Deprecated] /** @deprecated */ public const int WEEKEND_TO_FRIDAY = 3; - #[\Deprecated] + #[\Deprecated] /** @deprecated */ public const int WEEKEND_TO_MONDAY = 4; protected $casts diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index a92ff5af30..b0d63df1d9 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -590,7 +590,7 @@ class BillRepository implements BillRepositoryInterface if ($total > 0) { $currency = $convertToNative && $bill->transactionCurrency->id !== $default->id ? $default : $bill->transactionCurrency; - $average = bcdiv(bcadd($bill->{$maxField}, $bill->{$minField}), '2'); + $average = bcdiv(bcadd($bill->{$maxField} ?? '0', $bill->{$minField} ?? '0'), '2'); Log::debug(sprintf('Amount to pay is %s %s (%d times)', $currency->code, $average, $total)); $return[$currency->id] ??= [ 'id' => (string) $currency->id, diff --git a/app/Repositories/Budget/AvailableBudgetRepository.php b/app/Repositories/Budget/AvailableBudgetRepository.php index a1a23eb093..aac5c086c0 100644 --- a/app/Repositories/Budget/AvailableBudgetRepository.php +++ b/app/Repositories/Budget/AvailableBudgetRepository.php @@ -68,13 +68,14 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface if (null !== $start && null !== $end) { $query->where( static function (Builder $q1) use ($start, $end): void { // @phpstan-ignore-line - $q1->where('start_date', '=', $start->format('Y-m-d H:i:s')); - $q1->where('end_date', '=', $end->format('Y-m-d H:i:s')); + $q1->where('start_date', '=', $start->format('Y-m-d')); + $q1->where('end_date', '=', $end->format('Y-m-d')); } ); } - - return $query->get(['available_budgets.*']); + $result = $query->get(['available_budgets.*']); + Log::debug(sprintf('Found %d available budgets between %s and %s', $result->count(), $start->format('Y-m-d'), $end->format('Y-m-d'))); + return $result; } /** diff --git a/app/Support/Report/Summarizer/TransactionSummarizer.php b/app/Support/Report/Summarizer/TransactionSummarizer.php index 17368c53b8..e0890270a8 100644 --- a/app/Support/Report/Summarizer/TransactionSummarizer.php +++ b/app/Support/Report/Summarizer/TransactionSummarizer.php @@ -97,7 +97,7 @@ class TransactionSummarizer 'currency_decimal_places' => $currencyDecimalPlaces, ]; $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->{$method}($amount)); - Log::debug(sprintf('Journal #%d adds amount %s %s', $journal['transaction_journal_id'], $currencyCode, $amount)); + //Log::debug(sprintf('Journal #%d adds amount %s %s', $journal['transaction_journal_id'], $currencyCode, $amount)); } Log::debug('End of sumExpenses.', $array);