<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class MRproduct extends Model
{
    protected $table = 'mr_products';
    
    protected $fillable = [
        'material_requisition_id','product_id','qty','unit_id','grade_id','deleted_at','price','remarks'
    ];

    public $timestamps = false;

    public function product()
    {
    	return $this->belongsTo('App\Product','product_id');
    }

    public function unit()
    {
    	return $this->belongsTo('App\UnitMeasurement','unit_id');
    }

    public function grade()
    {
    	return $this->belongsTo('App\GradeMaster','grade_id')->withDefault(['grade' => 'NOGRADE' , 'id' => 0]);
    }

    public function materialRequest()
    {
    	return $this->belongsTo('App\MaterialRequisition','material_requisition_id');
    }

    public function mrApproval()
    {
        return $this->hasmany('App\MRapprovalproduct','mr_product_id');
    }

      public function amount($id)
    {
        $total_amount = MRproduct::where('material_requisition_id','=',$id)->sum('price');
        return $total_amount;
    }
}
