diff --git a/app/Api/V1/Requests/Models/Bill/StoreRequest.php b/app/Api/V1/Requests/Models/Bill/StoreRequest.php index a29f4106c8..110bfc6635 100644 --- a/app/Api/V1/Requests/Models/Bill/StoreRequest.php +++ b/app/Api/V1/Requests/Models/Bill/StoreRequest.php @@ -83,7 +83,7 @@ class StoreRequest extends FormRequest 'repeat_freq' => 'in:weekly,monthly,quarterly,half-year,yearly|required', 'skip' => 'between:0,31', 'active' => [new IsBoolean()], - 'notes' => 'between:1,65536', + 'notes' => 'min:1|max:32768', ]; } diff --git a/app/Api/V1/Requests/Models/Bill/UpdateRequest.php b/app/Api/V1/Requests/Models/Bill/UpdateRequest.php index f5896eff17..87ccf2cd59 100644 --- a/app/Api/V1/Requests/Models/Bill/UpdateRequest.php +++ b/app/Api/V1/Requests/Models/Bill/UpdateRequest.php @@ -86,7 +86,7 @@ class UpdateRequest extends FormRequest 'repeat_freq' => 'in:weekly,monthly,quarterly,half-year,yearly', 'skip' => 'between:0,31', 'active' => [new IsBoolean()], - 'notes' => 'between:1,65536', + 'notes' => 'min:1|max:32768', ]; } diff --git a/app/Api/V1/Requests/Models/Budget/StoreRequest.php b/app/Api/V1/Requests/Models/Budget/StoreRequest.php index 2932342ddc..3867b0352d 100644 --- a/app/Api/V1/Requests/Models/Budget/StoreRequest.php +++ b/app/Api/V1/Requests/Models/Budget/StoreRequest.php @@ -72,7 +72,7 @@ class StoreRequest extends FormRequest 'active' => [new IsBoolean()], 'currency_id' => 'exists:transaction_currencies,id', 'currency_code' => 'exists:transaction_currencies,code', - 'notes' => 'nullable|between:1,65536', + 'notes' => 'nullable|min:1|max:32768', // auto budget info 'auto_budget_type' => 'in:reset,rollover,adjusted,none', 'auto_budget_amount' => ['required_if:auto_budget_type,reset', 'required_if:auto_budget_type,rollover', 'required_if:auto_budget_type,adjusted', new IsValidPositiveAmount()], diff --git a/app/Api/V1/Requests/Models/Budget/UpdateRequest.php b/app/Api/V1/Requests/Models/Budget/UpdateRequest.php index fb520d6a16..5f495b5e87 100644 --- a/app/Api/V1/Requests/Models/Budget/UpdateRequest.php +++ b/app/Api/V1/Requests/Models/Budget/UpdateRequest.php @@ -83,7 +83,7 @@ class UpdateRequest extends FormRequest return [ 'name' => sprintf('between:1,100|uniqueObjectForUser:budgets,name,%d', $budget->id), 'active' => [new IsBoolean()], - 'notes' => 'nullable|between:1,65536', + 'notes' => 'nullable|min:1|max:32768', 'auto_budget_type' => 'in:reset,rollover,adjusted,none', 'auto_budget_currency_id' => 'exists:transaction_currencies,id', 'auto_budget_currency_code' => 'exists:transaction_currencies,code', diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php index 7fb0f3755e..7ebe7acf7b 100644 --- a/app/Http/Requests/AccountFormRequest.php +++ b/app/Http/Requests/AccountFormRequest.php @@ -116,7 +116,7 @@ class AccountFormRequest extends FormRequest 'amount_currency_id_virtual_balance' => 'exists:transaction_currencies,id', 'what' => 'in:'.$types, 'interest_period' => 'in:daily,monthly,yearly', - 'notes' => 'between:1,65536|nullable', + 'notes' => 'min:1|max:32768|nullable', ]; $rules = Location::requestRules($rules); diff --git a/app/Http/Requests/AttachmentFormRequest.php b/app/Http/Requests/AttachmentFormRequest.php index 7a51343ded..09b8919508 100644 --- a/app/Http/Requests/AttachmentFormRequest.php +++ b/app/Http/Requests/AttachmentFormRequest.php @@ -54,7 +54,7 @@ class AttachmentFormRequest extends FormRequest // fixed return [ 'title' => 'between:1,255|nullable', - 'notes' => 'between:1,65536|nullable', + 'notes' => 'min:1|max:32768|nullable', ]; } } diff --git a/app/Http/Requests/BillStoreRequest.php b/app/Http/Requests/BillStoreRequest.php index c5fa73bf98..a45e2e5446 100644 --- a/app/Http/Requests/BillStoreRequest.php +++ b/app/Http/Requests/BillStoreRequest.php @@ -69,7 +69,7 @@ class BillStoreRequest extends FormRequest 'amount_max' => ['required', new IsValidPositiveAmount()], 'transaction_currency_id' => 'required|exists:transaction_currencies,id', 'date' => 'required|date', - 'notes' => 'between:1,65536|nullable', + 'notes' => 'min:1|max:32768|nullable', 'bill_end_date' => 'nullable|date', 'extension_date' => 'nullable|date', 'repeat_freq' => sprintf('required|in:%s', implode(',', config('firefly.bill_periods'))), diff --git a/app/Http/Requests/BillUpdateRequest.php b/app/Http/Requests/BillUpdateRequest.php index 485cf0cc47..6c2907bae7 100644 --- a/app/Http/Requests/BillUpdateRequest.php +++ b/app/Http/Requests/BillUpdateRequest.php @@ -78,7 +78,7 @@ class BillUpdateRequest extends FormRequest 'repeat_freq' => sprintf('required|in:%s', implode(',', config('firefly.bill_periods'))), 'skip' => 'required|integer|gte:0|lte:31', 'active' => 'boolean', - 'notes' => 'between:1,65536|nullable', + 'notes' => 'min:1|max:32768|nullable', ]; } } diff --git a/app/Http/Requests/BudgetFormStoreRequest.php b/app/Http/Requests/BudgetFormStoreRequest.php index 5200ff8544..2b44ba1dd8 100644 --- a/app/Http/Requests/BudgetFormStoreRequest.php +++ b/app/Http/Requests/BudgetFormStoreRequest.php @@ -67,7 +67,7 @@ class BudgetFormStoreRequest extends FormRequest 'auto_budget_currency_id' => 'exists:transaction_currencies,id', 'auto_budget_amount' => ['required_if:auto_budget_type,1', 'required_if:auto_budget_type,2', new IsValidPositiveAmount()], 'auto_budget_period' => 'in:daily,weekly,monthly,quarterly,half_year,yearly', - 'notes' => 'between:1,65536|nullable', + 'notes' => 'min:1|max:32768|nullable', ]; } diff --git a/app/Http/Requests/BudgetFormUpdateRequest.php b/app/Http/Requests/BudgetFormUpdateRequest.php index 486f614fe4..0c109bf577 100644 --- a/app/Http/Requests/BudgetFormUpdateRequest.php +++ b/app/Http/Requests/BudgetFormUpdateRequest.php @@ -76,7 +76,7 @@ class BudgetFormUpdateRequest extends FormRequest 'auto_budget_currency_id' => 'exists:transaction_currencies,id', 'auto_budget_amount' => ['required_if:auto_budget_type,1', 'required_if:auto_budget_type,2|numeric', new IsValidPositiveAmount()], 'auto_budget_period' => 'in:daily,weekly,monthly,quarterly,half_year,yearly', - 'notes' => 'between:1,65536|nullable', + 'notes' => 'min:1|max:32768|nullable', ]; } diff --git a/app/Http/Requests/CategoryFormRequest.php b/app/Http/Requests/CategoryFormRequest.php index c3b1b10628..59b2f0505d 100644 --- a/app/Http/Requests/CategoryFormRequest.php +++ b/app/Http/Requests/CategoryFormRequest.php @@ -64,7 +64,7 @@ class CategoryFormRequest extends FormRequest // fixed return [ 'name' => $nameRule, - 'notes' => 'between:1,65536|nullable', + 'notes' => 'min:1|max:32768|nullable', ]; } } diff --git a/app/Http/Requests/PiggyBankStoreRequest.php b/app/Http/Requests/PiggyBankStoreRequest.php index 0892ae75bc..5140fb03a9 100644 --- a/app/Http/Requests/PiggyBankStoreRequest.php +++ b/app/Http/Requests/PiggyBankStoreRequest.php @@ -65,7 +65,7 @@ class PiggyBankStoreRequest extends FormRequest 'targetdate' => 'date|nullable', 'order' => 'integer|min:1', 'object_group' => 'min:0|max:255', - 'notes' => 'between:1,65536|nullable', + 'notes' => 'min:1|max:32768|nullable', ]; } } diff --git a/app/Http/Requests/PiggyBankUpdateRequest.php b/app/Http/Requests/PiggyBankUpdateRequest.php index 6b61cf084a..971efe3754 100644 --- a/app/Http/Requests/PiggyBankUpdateRequest.php +++ b/app/Http/Requests/PiggyBankUpdateRequest.php @@ -69,7 +69,7 @@ class PiggyBankUpdateRequest extends FormRequest 'targetdate' => 'date|nullable', 'order' => 'integer|max:65536|min:1', 'object_group' => 'min:0|max:255', - 'notes' => 'between:1,65536|nullable', + 'notes' => 'min:1|max:32768|nullable', ]; } } diff --git a/app/Http/Requests/RecurrenceFormRequest.php b/app/Http/Requests/RecurrenceFormRequest.php index c2621c16d8..217e9e63e1 100644 --- a/app/Http/Requests/RecurrenceFormRequest.php +++ b/app/Http/Requests/RecurrenceFormRequest.php @@ -160,10 +160,10 @@ class RecurrenceFormRequest extends FormRequest $rules = [ // mandatory info for recurrence. 'title' => 'required|between:1,255|uniqueObjectForUser:recurrences,title', - 'first_date' => sprintf('required|date|before:%s|after:%s',$before->format('Y-m-d'),$today->format('Y-m-d')), + 'first_date' => sprintf('required|date|before:%s|after:%s', $before->format('Y-m-d'), $today->format('Y-m-d')), 'repetition_type' => ['required', new ValidRecurrenceRepetitionValue(), new ValidRecurrenceRepetitionType(), 'between:1,20'], 'skip' => 'required|numeric|integer|gte:0|lte:31', - 'notes' => 'between:1,65536|nullable', + 'notes' => 'min:1|max:32768|nullable', // optional for recurrence: 'recurring_description' => 'between:0,65000', 'active' => 'numeric|between:0,1', diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 20233bd558..e173d47270 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -72,7 +72,8 @@ class AccountRepository implements AccountRepositoryInterface /** @var Account $account */ foreach ($accounts as $account) { $byName = $this->user->accounts()->where('name', $account->name) - ->where('id', '!=', $account->id)->first(); + ->where('id', '!=', $account->id)->first() + ; if (null !== $byName) { $result->push($account); $result->push($byName); @@ -81,7 +82,8 @@ class AccountRepository implements AccountRepositoryInterface } if (null !== $account->iban) { $byIban = $this->user->accounts()->where('iban', $account->iban) - ->where('id', '!=', $account->id)->first(); + ->where('id', '!=', $account->id)->first() + ; if (null !== $byIban) { $result->push($account); $result->push($byIban); @@ -107,7 +109,8 @@ class AccountRepository implements AccountRepositoryInterface $q1->where('account_meta.name', '=', 'account_number'); $q1->where('account_meta.data', '=', $json); } - ); + ) + ; if (0 !== count($types)) { $dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); @@ -133,7 +136,7 @@ class AccountRepository implements AccountRepositoryInterface public function findByName(string $name, array $types): ?Account { - $query = $this->user->accounts(); + $query = $this->user->accounts(); if (0 !== count($types)) { $query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); @@ -200,7 +203,7 @@ class AccountRepository implements AccountRepositoryInterface public function getAttachments(Account $account): Collection { - $set = $account->attachments()->get(); + $set = $account->attachments()->get(); /** @var \Storage $disk */ $disk = \Storage::disk('upload'); @@ -222,7 +225,7 @@ class AccountRepository implements AccountRepositoryInterface public function getCashAccount(): Account { /** @var AccountType $type */ - $type = AccountType::where('type', AccountType::CASH)->first(); + $type = AccountType::where('type', AccountType::CASH)->first(); /** @var AccountFactory $factory */ $factory = app(AccountFactory::class); @@ -231,7 +234,7 @@ class AccountRepository implements AccountRepositoryInterface return $factory->findOrCreate('Cash account', $type->type); } - public function setUser(null | Authenticatable | User $user): void + public function setUser(null|Authenticatable|User $user): void { if ($user instanceof User) { $this->user = $user; @@ -241,9 +244,10 @@ class AccountRepository implements AccountRepositoryInterface public function getCreditTransactionGroup(Account $account): ?TransactionGroup { $journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transactions.account_id', $account->id) - ->transactionTypes([TransactionType::LIABILITY_CREDIT]) - ->first(['transaction_journals.*']); + ->where('transactions.account_id', $account->id) + ->transactionTypes([TransactionType::LIABILITY_CREDIT]) + ->first(['transaction_journals.*']) + ; return $journal?->transactionGroup; } @@ -287,10 +291,11 @@ class AccountRepository implements AccountRepositoryInterface */ public function getOpeningBalanceAmount(Account $account): ?string { - $journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transactions.account_id', $account->id) - ->transactionTypes([TransactionType::OPENING_BALANCE, TransactionType::LIABILITY_CREDIT]) - ->first(['transaction_journals.*']); + $journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->where('transactions.account_id', $account->id) + ->transactionTypes([TransactionType::OPENING_BALANCE, TransactionType::LIABILITY_CREDIT]) + ->first(['transaction_journals.*']) + ; if (null === $journal) { return null; } @@ -308,9 +313,10 @@ class AccountRepository implements AccountRepositoryInterface public function getOpeningBalanceDate(Account $account): ?string { return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transactions.account_id', $account->id) - ->transactionTypes([TransactionType::OPENING_BALANCE, TransactionType::LIABILITY_CREDIT]) - ->first(['transaction_journals.*'])?->date->format('Y-m-d H:i:s'); + ->where('transactions.account_id', $account->id) + ->transactionTypes([TransactionType::OPENING_BALANCE, TransactionType::LIABILITY_CREDIT]) + ->first(['transaction_journals.*'])?->date->format('Y-m-d H:i:s') + ; } public function getOpeningBalanceGroup(Account $account): ?TransactionGroup @@ -320,19 +326,13 @@ class AccountRepository implements AccountRepositoryInterface return $journal?->transactionGroup; } - /** - * - * - * @param Account $account - * - * @return TransactionJournal|null - */ public function getOpeningBalance(Account $account): ?TransactionJournal { return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transactions.account_id', $account->id) - ->transactionTypes([TransactionType::OPENING_BALANCE]) - ->first(['transaction_journals.*']); + ->where('transactions.account_id', $account->id) + ->transactionTypes([TransactionType::OPENING_BALANCE]) + ->first(['transaction_journals.*']) + ; } public function getPiggyBanks(Account $account): Collection @@ -352,18 +352,19 @@ class AccountRepository implements AccountRepositoryInterface $name = trans('firefly.reconciliation_account_name', ['name' => $account->name, 'currency' => $currency->code]); /** @var AccountType $type */ - $type = AccountType::where('type', AccountType::RECONCILIATION)->first(); + $type = AccountType::where('type', AccountType::RECONCILIATION)->first(); /** @var null|Account $current */ - $current = $this->user->accounts()->where('account_type_id', $type->id) - ->where('name', $name) - ->first(); + $current = $this->user->accounts()->where('account_type_id', $type->id) + ->where('name', $name) + ->first() + ; if (null !== $current) { return $current; } - $data = [ + $data = [ 'account_type_id' => null, 'account_type_name' => AccountType::RECONCILIATION, 'active' => true, @@ -373,7 +374,7 @@ class AccountRepository implements AccountRepositoryInterface ]; /** @var AccountFactory $factory */ - $factory = app(AccountFactory::class); + $factory = app(AccountFactory::class); $factory->setUser($account->user); return $factory->create($data); @@ -381,8 +382,8 @@ class AccountRepository implements AccountRepositoryInterface public function getAccountCurrency(Account $account): ?TransactionCurrency { - $type = $account->accountType->type; - $list = config('firefly.valid_currency_account_types'); + $type = $account->accountType->type; + $list = config('firefly.valid_currency_account_types'); // return null if not in this list. if (!in_array($type, $list, true)) { @@ -446,7 +447,7 @@ class AccountRepository implements AccountRepositoryInterface public function maxOrder(string $type): int { - $sets = [ + $sets = [ AccountType::ASSET => [AccountType::DEFAULT, AccountType::ASSET], AccountType::EXPENSE => [AccountType::EXPENSE, AccountType::BENEFICIARY], AccountType::REVENUE => [AccountType::REVENUE], @@ -462,7 +463,7 @@ class AccountRepository implements AccountRepositoryInterface } $specials = [AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION]; - $order = (int) $this->getAccountsByType($specials)->max('order'); + $order = (int) $this->getAccountsByType($specials)->max('order'); app('log')->debug(sprintf('Return max order of "%s" set (specials!): %d', $type, $order)); return $order; @@ -511,12 +512,13 @@ class AccountRepository implements AccountRepositoryInterface { /** @var null|TransactionJournal $first */ $first = $account->transactions() - ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') - ->orderBy('transaction_journals.date', 'ASC') - ->orderBy('transaction_journals.order', 'DESC') - ->where('transaction_journals.user_id', $this->user->id) - ->orderBy('transaction_journals.id', 'ASC') - ->first(['transaction_journals.id']); + ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') + ->orderBy('transaction_journals.date', 'ASC') + ->orderBy('transaction_journals.order', 'DESC') + ->where('transaction_journals.user_id', $this->user->id) + ->orderBy('transaction_journals.id', 'ASC') + ->first(['transaction_journals.id']) + ; if (null !== $first) { return TransactionJournal::find($first->id); } @@ -555,11 +557,12 @@ class AccountRepository implements AccountRepositoryInterface public function searchAccount(string $query, array $types, int $limit): Collection { $dbQuery = $this->user->accounts() - ->where('active', true) - ->orderBy('accounts.order', 'ASC') - ->orderBy('accounts.account_type_id', 'ASC') - ->orderBy('accounts.name', 'ASC') - ->with(['accountType']); + ->where('active', true) + ->orderBy('accounts.order', 'ASC') + ->orderBy('accounts.account_type_id', 'ASC') + ->orderBy('accounts.name', 'ASC') + ->with(['accountType']) + ; if ('' !== $query) { // split query on spaces just in case: $parts = explode(' ', $query); @@ -579,12 +582,13 @@ class AccountRepository implements AccountRepositoryInterface public function searchAccountNr(string $query, array $types, int $limit): Collection { $dbQuery = $this->user->accounts()->distinct() - ->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id') - ->where('accounts.active', true) - ->orderBy('accounts.order', 'ASC') - ->orderBy('accounts.account_type_id', 'ASC') - ->orderBy('accounts.name', 'ASC') - ->with(['accountType', 'accountMeta']); + ->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id') + ->where('accounts.active', true) + ->orderBy('accounts.order', 'ASC') + ->orderBy('accounts.account_type_id', 'ASC') + ->orderBy('accounts.name', 'ASC') + ->with(['accountType', 'accountMeta']) + ; if ('' !== $query) { // split query on spaces just in case: $parts = explode(' ', $query);