<?php

namespace App;

use App\Employees;
use Illuminate\Database\Eloquent\Model;

class EmployeeAdvance extends Model
{
    protected $fillable = [
        'employee_id','amount','recovered',
        'monthly_deduction','given_date','status','notes',
    ];

    protected $casts = [
        'given_date' => 'date',
    ];

    public function employee()
    {
        return $this->belongsTo(Employees::class);
    }

    /** Remaining balance */
    public function getBalanceAttribute(): float
    {
        return (float)$this->amount - (float)$this->recovered;
    }
}