<?php

namespace Modules\Customer\Entities;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Modules\Cheque\Entities\Cheque;
use Modules\Factor\Entities\Factor;

class Customer extends Model
{
    protected $guarded=['id'];
    protected $appends=['total','paid','debt'];

    public function cheques()
    {
        return $this->morphMany(Cheque::class, 'exporterable');
    }

    public function factors()
    {
        return $this->hasMany(Factor::class);
    }

    public function getTotalAttribute()
    {
        return $this->factors()->sum('price');
    }

    public function getPaidAttribute()
    {
        return $this->factors()->sum('paid');
    }
    public function getDebtAttribute()
    {
        return $this->factors()->sum('debt');
    }
}
