- Added `rejections` table to track rejection reasons and related entities. - Created `attendances` table for employee attendance records with geolocation data. - Introduced `payroll_periods`, `payrolls`, and `payroll_adjustments` tables for payroll management. - Established `leave_requests` table to manage employee leave applications. - Implemented `purchases` and `purchase_items` tables for tracking supplier purchases. - Created `media` table for file storage and management. - Added `activity_log` table for tracking system activities. - Established `orders` and `order_items` tables for managing customer orders. - Created `cuttings`, `cutting_materials`, and `cutting_results` tables for production management. - Introduced `system_configurations` table for application settings. - Added `push_subscriptions` table for managing user push notifications. - Created `homepage_configurations` table for homepage settings. - Established `product_prices` table for managing product pricing. - Added `owner_verification_requests` table for tracking ownership verification processes. - Created `notifications` table for user notifications. - Established `employee_advance_payments` table for managing advance payments to employees. - Created `retail_stock_histories` table for tracking stock changes. - Established `stok_opnames` and `stok_opname_items` tables for stock opname management. - Created `cutting_material_combinations` table for managing material combinations. - Added `restocks` and `restock_items` tables for managing stock replenishments. - Established `stock_mutations` table for tracking stock changes across various operations.
192 lines
4.8 KiB
PHP
192 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
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 Illuminate\Support\Carbon;
|
|
use Laravel\Fortify\TwoFactorAuthenticatable;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
#[Hidden(['id'])]
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|