Code cleanup

This commit is contained in:
James Cole
2023-10-28 15:03:33 +02:00
parent fa920fed4e
commit 0133a7c5db
77 changed files with 575 additions and 594 deletions

View File

@@ -42,36 +42,36 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class Account
*
* @property int $id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property int $user_id
* @property int $account_type_id
* @property string $name
* @property string|null $virtual_balance
* @property string|null $iban
* @property bool $active
* @property bool $encrypted
* @property int $order
* @property-read Collection|AccountMeta[] $accountMeta
* @property-read int|null $account_meta_count
* @property AccountType $accountType
* @property-read Collection|Attachment[] $attachments
* @property-read int|null $attachments_count
* @property-read string $account_number
* @property-read string $edit_name
* @property-read Collection|Location[] $locations
* @property-read int|null $locations_count
* @property-read Collection|Note[] $notes
* @property-read int|null $notes_count
* @property-read Collection|ObjectGroup[] $objectGroups
* @property-read int|null $object_groups_count
* @property-read Collection|PiggyBank[] $piggyBanks
* @property-read int|null $piggy_banks_count
* @property-read Collection|Transaction[] $transactions
* @property-read int|null $transactions_count
* @property-read User $user
* @property int $id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property int $user_id
* @property int $account_type_id
* @property string $name
* @property string|null $virtual_balance
* @property string|null $iban
* @property bool $active
* @property bool $encrypted
* @property int $order
* @property-read Collection|AccountMeta[] $accountMeta
* @property-read int|null $account_meta_count
* @property AccountType $accountType
* @property-read Collection|Attachment[] $attachments
* @property-read int|null $attachments_count
* @property-read string $account_number
* @property-read string $edit_name
* @property-read Collection|Location[] $locations
* @property-read int|null $locations_count
* @property-read Collection|Note[] $notes
* @property-read int|null $notes_count
* @property-read Collection|ObjectGroup[] $objectGroups
* @property-read int|null $object_groups_count
* @property-read Collection|PiggyBank[] $piggyBanks
* @property-read int|null $piggy_banks_count
* @property-read Collection|Transaction[] $transactions
* @property-read int|null $transactions_count
* @property-read User $user
* @method static EloquentBuilder|Account accountTypeIn($types)
* @method static EloquentBuilder|Account newModelQuery()
* @method static EloquentBuilder|Account newQuery()
@@ -91,19 +91,19 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static EloquentBuilder|Account whereVirtualBalance($value)
* @method static Builder|Account withTrashed()
* @method static Builder|Account withoutTrashed()
* @property Carbon $lastActivityDate
* @property string $startBalance
* @property string $endBalance
* @property string $difference
* @property string $interest
* @property string $interestPeriod
* @property string $accountTypeString
* @property Location $location
* @property string $liability_direction
* @property string $current_debt
* @property int|null $user_group_id
* @property Carbon $lastActivityDate
* @property string $startBalance
* @property string $endBalance
* @property string $difference
* @property string $interest
* @property string $interestPeriod
* @property string $accountTypeString
* @property Location $location
* @property string $liability_direction
* @property string $current_debt
* @property int|null $user_group_id
* @method static EloquentBuilder|Account whereUserGroupId($value)
* @property-read \FireflyIII\Models\UserGroup|null $userGroup
* @property-read UserGroup|null $userGroup
* @mixin Eloquent
*/
class Account extends Model

View File

@@ -61,7 +61,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static Builder|ObjectGroup whereTitle($value)
* @method static Builder|ObjectGroup whereUpdatedAt($value)
* @method static Builder|ObjectGroup whereUserId($value)
* @property int|null $user_group_id
* @property int|null $user_group_id
* @method static Builder|ObjectGroup whereUserGroupId($value)
* @mixin Eloquent
*/

View File

@@ -125,6 +125,14 @@ class Rule extends Model
throw new NotFoundHttpException();
}
/**
* @return BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* @return HasMany
*/
@@ -159,14 +167,6 @@ class Rule extends Model
$this->attributes['description'] = e($value);
}
/**
* @return BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* @return BelongsTo
*/

View File

@@ -37,23 +37,23 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* FireflyIII\Models\TransactionCurrency
*
* @property int $id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property Carbon|null $deleted_at
* @property bool $enabled
* @property bool $userDefault
* @property bool $userEnabled
* @property string $code
* @property string $name
* @property string $symbol
* @property int $decimal_places
* @property-read Collection|BudgetLimit[] $budgetLimits
* @property-read int|null $budget_limits_count
* @property-read Collection|TransactionJournal[] $transactionJournals
* @property-read int|null $transaction_journals_count
* @property-read Collection|Transaction[] $transactions
* @property-read int|null $transactions_count
* @property int $id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property Carbon|null $deleted_at
* @property bool $enabled
* @property bool $userDefault
* @property bool $userEnabled
* @property string $code
* @property string $name
* @property string $symbol
* @property int $decimal_places
* @property-read Collection|BudgetLimit[] $budgetLimits
* @property-read int|null $budget_limits_count
* @property-read Collection|TransactionJournal[] $transactionJournals
* @property-read int|null $transaction_journals_count
* @property-read Collection|Transaction[] $transactions
* @property-read int|null $transactions_count
* @method static \Illuminate\Database\Eloquent\Builder|TransactionCurrency newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|TransactionCurrency newQuery()
* @method static Builder|TransactionCurrency onlyTrashed()
@@ -69,10 +69,10 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static \Illuminate\Database\Eloquent\Builder|TransactionCurrency whereUpdatedAt($value)
* @method static Builder|TransactionCurrency withTrashed()
* @method static Builder|TransactionCurrency withoutTrashed()
* @property-read Collection<int, \FireflyIII\Models\UserGroup> $userGroups
* @property-read int|null $user_groups_count
* @property-read Collection<int, User> $users
* @property-read int|null $users_count
* @property-read Collection<int, UserGroup> $userGroups
* @property-read int|null $user_groups_count
* @property-read Collection<int, User> $users
* @property-read int|null $users_count
* @mixin Eloquent
*/
class TransactionCurrency extends Model
@@ -115,6 +115,14 @@ class TransactionCurrency extends Model
throw new NotFoundHttpException();
}
/**
* @return HasMany
*/
public function budgetLimits(): HasMany
{
return $this->hasMany(BudgetLimit::class);
}
/**
* @param User $user
*
@@ -122,40 +130,12 @@ class TransactionCurrency extends Model
*/
public function refreshForUser(User $user)
{
$current = $user->userGroup->currencies()->where('transaction_currencies.id', $this->id)->first();
$default = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);
$current = $user->userGroup->currencies()->where('transaction_currencies.id', $this->id)->first();
$default = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);
$this->userDefault = (int)$default->id === (int)$this->id;
$this->userEnabled = null !== $current;
}
/**
* Link to users
*
* @return BelongsToMany
*/
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class)->withTimestamps()->withPivot('user_default');
}
/**
* Link to user groups
*
* @return BelongsToMany
*/
public function userGroups(): BelongsToMany
{
return $this->belongsToMany(UserGroup::class)->withTimestamps()->withPivot('group_default');
}
/**
* @return HasMany
*/
public function budgetLimits(): HasMany
{
return $this->hasMany(BudgetLimit::class);
}
/**
* @return HasMany
*/
@@ -171,4 +151,24 @@ class TransactionCurrency extends Model
{
return $this->hasMany(Transaction::class);
}
/**
* Link to user groups
*
* @return BelongsToMany
*/
public function userGroups(): BelongsToMany
{
return $this->belongsToMany(UserGroup::class)->withTimestamps()->withPivot('group_default');
}
/**
* Link to users
*
* @return BelongsToMany
*/
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class)->withTimestamps()->withPivot('user_default');
}
}

View File

@@ -41,50 +41,50 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* FireflyIII\Models\TransactionJournal
*
* @property int $id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property Carbon|null $deleted_at
* @property int $user_id
* @property int $transaction_type_id
* @property int|null $transaction_group_id
* @property int|null $bill_id
* @property int|null $transaction_currency_id
* @property string $description
* @property Carbon $date
* @property Carbon|null $interest_date
* @property Carbon|null $book_date
* @property Carbon|null $process_date
* @property int $order
* @property int $tag_count
* @property string $transaction_type_type
* @property bool $encrypted
* @property bool $completed
* @property-read Collection|Attachment[] $attachments
* @property-read int|null $attachments_count
* @property-read Bill|null $bill
* @property-read Collection|Budget[] $budgets
* @property-read int|null $budgets_count
* @property-read Collection|Category[] $categories
* @property-read int|null $categories_count
* @property-read Collection|TransactionJournalLink[] $destJournalLinks
* @property-read int|null $dest_journal_links_count
* @property-read Collection|Note[] $notes
* @property-read int|null $notes_count
* @property-read Collection|PiggyBankEvent[] $piggyBankEvents
* @property-read int|null $piggy_bank_events_count
* @property-read Collection|TransactionJournalLink[] $sourceJournalLinks
* @property-read int|null $source_journal_links_count
* @property-read Collection|Tag[] $tags
* @property-read int|null $tags_count
* @property-read TransactionCurrency|null $transactionCurrency
* @property-read TransactionGroup|null $transactionGroup
* @property-read Collection|TransactionJournalMeta[] $transactionJournalMeta
* @property-read int|null $transaction_journal_meta_count
* @property-read TransactionType $transactionType
* @property-read Collection|Transaction[] $transactions
* @property-read int|null $transactions_count
* @property-read User $user
* @property int $id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property Carbon|null $deleted_at
* @property int $user_id
* @property int $transaction_type_id
* @property int|null $transaction_group_id
* @property int|null $bill_id
* @property int|null $transaction_currency_id
* @property string $description
* @property Carbon $date
* @property Carbon|null $interest_date
* @property Carbon|null $book_date
* @property Carbon|null $process_date
* @property int $order
* @property int $tag_count
* @property string $transaction_type_type
* @property bool $encrypted
* @property bool $completed
* @property-read Collection|Attachment[] $attachments
* @property-read int|null $attachments_count
* @property-read Bill|null $bill
* @property-read Collection|Budget[] $budgets
* @property-read int|null $budgets_count
* @property-read Collection|Category[] $categories
* @property-read int|null $categories_count
* @property-read Collection|TransactionJournalLink[] $destJournalLinks
* @property-read int|null $dest_journal_links_count
* @property-read Collection|Note[] $notes
* @property-read int|null $notes_count
* @property-read Collection|PiggyBankEvent[] $piggyBankEvents
* @property-read int|null $piggy_bank_events_count
* @property-read Collection|TransactionJournalLink[] $sourceJournalLinks
* @property-read int|null $source_journal_links_count
* @property-read Collection|Tag[] $tags
* @property-read int|null $tags_count
* @property-read TransactionCurrency|null $transactionCurrency
* @property-read TransactionGroup|null $transactionGroup
* @property-read Collection|TransactionJournalMeta[] $transactionJournalMeta
* @property-read int|null $transaction_journal_meta_count
* @property-read TransactionType $transactionType
* @property-read Collection|Transaction[] $transactions
* @property-read int|null $transactions_count
* @property-read User $user
* @method static EloquentBuilder|TransactionJournal after(Carbon $date)
* @method static EloquentBuilder|TransactionJournal before(Carbon $date)
* @method static EloquentBuilder|TransactionJournal newModelQuery()
@@ -112,13 +112,13 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static EloquentBuilder|TransactionJournal whereUserId($value)
* @method static \Illuminate\Database\Query\Builder|TransactionJournal withTrashed()
* @method static \Illuminate\Database\Query\Builder|TransactionJournal withoutTrashed()
* @property-read Collection|Location[] $locations
* @property-read int|null $locations_count
* @property int $the_count
* @property int|null $user_group_id
* @property-read Collection|Location[] $locations
* @property-read int|null $locations_count
* @property int $the_count
* @property int|null $user_group_id
* @method static EloquentBuilder|TransactionJournal whereUserGroupId($value)
* @property-read Collection<int, \FireflyIII\Models\AuditLogEntry> $auditLogEntries
* @property-read int|null $audit_log_entries_count
* @property-read Collection<int, AuditLogEntry> $auditLogEntries
* @property-read int|null $audit_log_entries_count
* @mixin Eloquent
*/
class TransactionJournal extends Model

View File

@@ -39,13 +39,13 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class UserGroup
*
* @property int $id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property string|null $deleted_at
* @property string $title
* @property-read Collection|GroupMembership[] $groupMemberships
* @property-read int|null $group_memberships_count
* @property int $id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property string|null $deleted_at
* @property string $title
* @property-read Collection|GroupMembership[] $groupMemberships
* @property-read int|null $group_memberships_count
* @method static Builder|UserGroup newModelQuery()
* @method static Builder|UserGroup newQuery()
* @method static Builder|UserGroup query()
@@ -54,40 +54,40 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static Builder|UserGroup whereId($value)
* @method static Builder|UserGroup whereTitle($value)
* @method static Builder|UserGroup whereUpdatedAt($value)
* @property-read Collection<int, Account> $accounts
* @property-read int|null $accounts_count
* @property-read Collection<int, AvailableBudget> $availableBudgets
* @property-read int|null $available_budgets_count
* @property-read Collection<int, Bill> $bills
* @property-read int|null $bills_count
* @property-read Collection<int, Budget> $budgets
* @property-read int|null $budgets_count
* @property-read Collection<int, PiggyBank> $piggyBanks
* @property-read int|null $piggy_banks_count
* @property-read Collection<int, TransactionJournal> $transactionJournals
* @property-read int|null $transaction_journals_count
* @property-read Collection<int, \FireflyIII\Models\Attachment> $attachments
* @property-read int|null $attachments_count
* @property-read Collection<int, \FireflyIII\Models\Category> $categories
* @property-read int|null $categories_count
* @property-read Collection<int, \FireflyIII\Models\CurrencyExchangeRate> $currencyExchangeRates
* @property-read int|null $currency_exchange_rates_count
* @property-read Collection<int, \FireflyIII\Models\ObjectGroup> $objectGroups
* @property-read int|null $object_groups_count
* @property-read Collection<int, \FireflyIII\Models\Recurrence> $recurrences
* @property-read int|null $recurrences_count
* @property-read Collection<int, \FireflyIII\Models\RuleGroup> $ruleGroups
* @property-read int|null $rule_groups_count
* @property-read Collection<int, \FireflyIII\Models\Rule> $rules
* @property-read int|null $rules_count
* @property-read Collection<int, \FireflyIII\Models\Tag> $tags
* @property-read int|null $tags_count
* @property-read Collection<int, \FireflyIII\Models\TransactionGroup> $transactionGroups
* @property-read int|null $transaction_groups_count
* @property-read Collection<int, \FireflyIII\Models\Webhook> $webhooks
* @property-read int|null $webhooks_count
* @property-read Collection<int, \FireflyIII\Models\TransactionCurrency> $currencies
* @property-read int|null $currencies_count
* @property-read Collection<int, Account> $accounts
* @property-read int|null $accounts_count
* @property-read Collection<int, AvailableBudget> $availableBudgets
* @property-read int|null $available_budgets_count
* @property-read Collection<int, Bill> $bills
* @property-read int|null $bills_count
* @property-read Collection<int, Budget> $budgets
* @property-read int|null $budgets_count
* @property-read Collection<int, PiggyBank> $piggyBanks
* @property-read int|null $piggy_banks_count
* @property-read Collection<int, TransactionJournal> $transactionJournals
* @property-read int|null $transaction_journals_count
* @property-read Collection<int, Attachment> $attachments
* @property-read int|null $attachments_count
* @property-read Collection<int, Category> $categories
* @property-read int|null $categories_count
* @property-read Collection<int, CurrencyExchangeRate> $currencyExchangeRates
* @property-read int|null $currency_exchange_rates_count
* @property-read Collection<int, ObjectGroup> $objectGroups
* @property-read int|null $object_groups_count
* @property-read Collection<int, Recurrence> $recurrences
* @property-read int|null $recurrences_count
* @property-read Collection<int, RuleGroup> $ruleGroups
* @property-read int|null $rule_groups_count
* @property-read Collection<int, Rule> $rules
* @property-read int|null $rules_count
* @property-read Collection<int, Tag> $tags
* @property-read int|null $tags_count
* @property-read Collection<int, TransactionGroup> $transactionGroups
* @property-read int|null $transaction_groups_count
* @property-read Collection<int, Webhook> $webhooks
* @property-read int|null $webhooks_count
* @property-read Collection<int, TransactionCurrency> $currencies
* @property-read int|null $currencies_count
* @mixin Eloquent
*/
class UserGroup extends Model
@@ -132,16 +132,6 @@ class UserGroup extends Model
return $this->hasMany(Account::class);
}
/**
* Link to currencies
*
* @return BelongsToMany
*/
public function currencies(): BelongsToMany
{
return $this->belongsToMany(TransactionCurrency::class)->withTimestamps()->withPivot('group_default');
}
/**
* Link to attachments.
*
@@ -192,6 +182,16 @@ class UserGroup extends Model
return $this->hasMany(Category::class);
}
/**
* Link to currencies
*
* @return BelongsToMany
*/
public function currencies(): BelongsToMany
{
return $this->belongsToMany(TransactionCurrency::class)->withTimestamps()->withPivot('group_default');
}
/**
* Link to exchange rates.
*