Smaller notes

This commit is contained in:
James Cole 2024-01-04 11:41:03 +01:00
parent 72a2d417af
commit c32044a8eb
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
15 changed files with 73 additions and 69 deletions

View File

@ -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',
];
}

View File

@ -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',
];
}

View File

@ -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()],

View File

@ -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',

View File

@ -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);

View File

@ -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',
];
}
}

View File

@ -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'))),

View File

@ -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',
];
}
}

View File

@ -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',
];
}

View File

@ -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',
];
}

View File

@ -64,7 +64,7 @@ class CategoryFormRequest extends FormRequest
// fixed
return [
'name' => $nameRule,
'notes' => 'between:1,65536|nullable',
'notes' => 'min:1|max:32768|nullable',
];
}
}

View File

@ -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',
];
}
}

View File

@ -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',
];
}
}

View File

@ -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',

View File

@ -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);