<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Employee extends Model
{
    protected $guarded = [];

    // Tambahkan relasi jabatan
    public function position() {
        return $this->belongsTo(Position::class);
    }

    public function branch() {
        return $this->belongsTo(Branch::class);
    }

    public function user() {
        return $this->belongsTo(User::class);
    }

    public function salary() {
        return $this->hasOne(EmployeeSalary::class);
    }

    public function activeLoans() {
        return $this->hasMany(EmployeeLoan::class)->where('status', 'active')->where('remaining_balance', '>', 0);
    }

    public function allowances()
    {
        return $this->hasMany(EmployeeAllowance::class)->where('is_active', true);
    }

   public function attendances()
    {
        return $this->hasMany(Attendance::class);
    }
}