<?php
namespace App;

use Illuminate\Database\Eloquent\Model;

class ParentMaster extends Model
{

    protected $table = 'parent_master';
    
    protected $fillable = [
        'name','code'
    ];

    public $timestamps = false;

    public function totalQty($pro_id,$from_date,$to_date,$customer_id,$location)
    {

        $mode_id =  ModeDetail::where('mode_name','=','CREDIT')->first();

        $total_qty = MaterialRequisition::join('mr_products','mr_products.material_requisition_id','=','material_requisition.id') 	
							->where('material_requisition.request_date','>=',$from_date)
                           	->where('material_requisition.request_date','<=',$to_date)
                           	->where('material_requisition.customer_id','=',$customer_id)
                           	->where('material_requisition.mode_details_id','=',$mode_id->id)
                           	->where('material_requisition.location_id','=',$location)
                           	->where('mr_products.product_id','=',$pro_id)
                           	->sum('mr_products.qty');

         return $total_qty;
    }
}

?>