EmployeeAdvanceStatus::class, 'amount' => 'integer', 'paid_amount' => 'integer', 'due_date' => 'date:Y-m-d', 'verified_at' => 'datetime', 'paid_at' => 'datetime', ]; } public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logAll() ->logOnlyDirty() ->dontLogEmptyChanges(); } protected function formattedAmount(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format($this->amount, 0, ',', '.'), ); } protected function formattedCreatedAt(): Attribute { return Attribute::make( get: fn () => $this->created_at?->translatedFormat('l, d F Y'), ); } protected function formattedDueDate(): Attribute { return Attribute::make( get: fn () => $this->due_date?->translatedFormat('l, d F Y'), ); } protected function formattedPaidAmount(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format($this->paid_amount, 0, ',', '.'), ); } protected function formattedRemainingAmount(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format($this->amount - $this->paid_amount, 0, ',', '.'), ); } protected function statusLabel(): Attribute { return Attribute::make( get: fn () => $this->status?->label(), ); } #[Scope] protected function disbursed(Builder $query): void { $query->where('status', EmployeeAdvanceStatus::DISBURSED); } #[Scope] protected function partial(Builder $query): void { $query->where('status', EmployeeAdvanceStatus::PARTIAL); } #[Scope] protected function repaid(Builder $query): void { $query->where('status', EmployeeAdvanceStatus::REPAID); } #[Scope] protected function pending(Builder $query): void { $query->where('status', EmployeeAdvanceStatus::PENDING); } #[Scope] protected function rejected(Builder $query): void { $query->where('status', EmployeeAdvanceStatus::REJECTED); } public function cashTransaction(): BelongsTo { return $this->belongsTo(CashTransaction::class); } public function employee(): BelongsTo { return $this->belongsTo(Employee::class); } public function payments(): HasMany { return $this->hasMany(EmployeeAdvancePayment::class); } public function paidBy(): BelongsTo { return $this->belongsTo(User::class, 'paid_by_id'); } public function repaymentCashTransaction(): BelongsTo { return $this->belongsTo(CashTransaction::class, 'repayment_cash_transaction_id'); } public function verifiedBy(): BelongsTo { return $this->belongsTo(User::class, 'verified_by_id'); } }