<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\FyearMaster;

class GrantEntry extends Model
{
    use SoftDeletes;

    protected $table = 'grant_entries';
    protected $primaryKey = 'GrTrn_Id';

    protected $fillable = [
        'FY_Id',
        'Dpt_Id',
        'GT_Id',
        'Bh_Id',
        'Amount',
        'Date',
        'Status',
        'GE_HOD',     // ✅ ADD
        'Remarks'     // ✅ ADD
    ];

    protected $casts = [
        'Date' => 'date',
        'Amount' => 'decimal:2'
    ];

    public function hod()
    {
        return $this->belongsTo(UserMaster::class, 'GE_HOD', 'Usr_Id');
    }

    // ✅ Relationships

    public function financialYear()
    {
        return $this->belongsTo(FYearMaster::class, 'FY_Id', 'FY_Id');
    }

    public function department()
    {
        return $this->belongsTo(Department::class, 'Dpt_Id', 'Dpt_id');
    }

    public function grantType()
    {
        return $this->belongsTo(GrantTypeMaster::class, 'GT_Id', 'GT_Id');
    }

    public function budgetHead()
    {
        return $this->belongsTo(BudgetHead::class, 'Bh_Id', 'Bh_Id');
    }

    public function action()
    {
        return $this->belongsTo(ActionMaster::class, 'Status', 'Act_Id');
    }
}
