206 lines
5.2 KiB
PHP
206 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Appends;
|
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Fortify\TwoFactorAuthenticatable;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
#[Guarded(['id'])]
|
|
#[Appends(['full_name'])]
|
|
class User extends Authenticatable
|
|
{
|
|
use HasFactory, HasRoles, Notifiable, SoftDeletes, TwoFactorAuthenticatable;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'is_active' => 'boolean',
|
|
'last_login_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'two_factor_confirmed_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
#[Scope]
|
|
protected function active(Builder $query): void
|
|
{
|
|
$query->where('is_active', true);
|
|
}
|
|
|
|
protected function name(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->userProfile?->full_name ?? '',
|
|
);
|
|
}
|
|
|
|
protected function fullName(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->userProfile?->full_name ?? '',
|
|
);
|
|
}
|
|
|
|
public function attendances(): HasMany
|
|
{
|
|
return $this->hasMany(Attendance::class);
|
|
}
|
|
|
|
public function cashAccounts(): HasMany
|
|
{
|
|
return $this->hasMany(CashAccount::class, 'created_by_id');
|
|
}
|
|
|
|
public function cashTransactions(): HasMany
|
|
{
|
|
return $this->hasMany(CashTransaction::class, 'created_by_id');
|
|
}
|
|
|
|
public function createdCuttings(): HasMany
|
|
{
|
|
return $this->hasMany(Cutting::class, 'created_by_id');
|
|
}
|
|
|
|
public function createdExpenses(): HasMany
|
|
{
|
|
return $this->hasMany(Expense::class, 'created_by_id');
|
|
}
|
|
|
|
public function createdOrders(): HasMany
|
|
{
|
|
return $this->hasMany(Order::class, 'created_by_id');
|
|
}
|
|
|
|
public function createdPayrollAdjustments(): HasMany
|
|
{
|
|
return $this->hasMany(PayrollAdjustment::class, 'created_by_id');
|
|
}
|
|
|
|
public function createdPurchases(): HasMany
|
|
{
|
|
return $this->hasMany(Purchase::class, 'created_by_id');
|
|
}
|
|
|
|
public function createdRestocks(): HasMany
|
|
{
|
|
return $this->hasMany(Restock::class, 'created_by_id');
|
|
}
|
|
|
|
public function employee(): HasOne
|
|
{
|
|
return $this->hasOne(Employee::class);
|
|
}
|
|
|
|
public function employeeAdvancesPaid(): HasMany
|
|
{
|
|
return $this->hasMany(EmployeeAdvance::class, 'paid_by_id');
|
|
}
|
|
|
|
public function employeeAdvancesVerified(): HasMany
|
|
{
|
|
return $this->hasMany(EmployeeAdvance::class, 'verified_by_id');
|
|
}
|
|
|
|
public function leaveRequestsVerified(): HasMany
|
|
{
|
|
return $this->hasMany(LeaveRequest::class, 'verified_by_id');
|
|
}
|
|
|
|
public function marketingOrders(): HasMany
|
|
{
|
|
return $this->hasMany(Order::class, 'marketing_id');
|
|
}
|
|
|
|
public function notifications(): HasMany
|
|
{
|
|
return $this->hasMany(AppNotification::class);
|
|
}
|
|
|
|
public function orderItems(): HasMany
|
|
{
|
|
return $this->hasMany(OrderItem::class);
|
|
}
|
|
|
|
public function ownerVerificationRequestsSubmitted(): HasMany
|
|
{
|
|
return $this->hasMany(OwnerVerificationRequest::class, 'submitted_by_id');
|
|
}
|
|
|
|
public function ownerVerificationRequestsVerified(): HasMany
|
|
{
|
|
return $this->hasMany(OwnerVerificationRequest::class, 'verified_by_id');
|
|
}
|
|
|
|
public function paidPayrolls(): HasMany
|
|
{
|
|
return $this->hasMany(Payroll::class, 'paid_by_id');
|
|
}
|
|
|
|
public function payrollPeriodsClosed(): HasMany
|
|
{
|
|
return $this->hasMany(PayrollPeriod::class, 'closed_by_id');
|
|
}
|
|
|
|
public function purchaseItems(): HasMany
|
|
{
|
|
return $this->hasMany(PurchaseItem::class);
|
|
}
|
|
|
|
public function pushSubscriptions(): HasMany
|
|
{
|
|
return $this->hasMany(PushSubscription::class);
|
|
}
|
|
|
|
public function rejections(): HasMany
|
|
{
|
|
return $this->hasMany(Rejection::class, 'rejected_by_id');
|
|
}
|
|
|
|
public function restockItems(): HasMany
|
|
{
|
|
return $this->hasMany(RestockItem::class);
|
|
}
|
|
|
|
public function retailStockHistories(): HasMany
|
|
{
|
|
return $this->hasMany(RetailStockHistory::class);
|
|
}
|
|
|
|
public function stockMutations(): HasMany
|
|
{
|
|
return $this->hasMany(StockMutation::class);
|
|
}
|
|
|
|
public function stokOpnamesCreated(): HasMany
|
|
{
|
|
return $this->hasMany(StokOpname::class, 'created_by_id');
|
|
}
|
|
|
|
public function stokOpnamesVerified(): HasMany
|
|
{
|
|
return $this->hasMany(StokOpname::class, 'verified_by_id');
|
|
}
|
|
|
|
public function submittedCuttings(): HasMany
|
|
{
|
|
return $this->hasMany(Cutting::class, 'submitted_by_id');
|
|
}
|
|
|
|
public function userProfile(): HasOne
|
|
{
|
|
return $this->hasOne(UserProfile::class);
|
|
}
|
|
}
|