<?php

namespace App;

use App\Traits\ModelTimeFormat;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Inventory extends Model
{
    use ModelTimeFormat;
    use SoftDeletes;
    protected $fillable=[
        'id','owner_id','owner_id','type', 'start_at', 'end_at','total','processed','difference','returned','deleted_at','created_at',
    ];
    protected $appends = [
            'surplus'
    ];
    public function owner(){
        return $this->belongsTo('App\Owner','owner_id','id');
    }
    public function inventoryMissions(){
        return $this->belongsTo('App\InventoryMission','id','inventory_id');
    }

    public function getSurplusAttribute()
    {
        return $this['total'] ? $this['total']-$this['processed']:null;
    }
}
