<?php
	namespace App\Http\Model;
	use Illuminate\Database\Eloquent\Model;
	use DB;
	use Auth;
	class FarmItemModel extends Model
	{		
		public function QPermission($id)
	 	{
		    $QModules=DB::table('modules')->select('Mid')->where('mUrl',$id['url'])->first();
			$Mid=$QModules->Mid;
			return $Qpermission=DB::table('permission')->where('Mid',$Mid)->first();
		}
		public function itemrecordsmodel()
		{
			return $itemrecord=DB::table('itm_item')->select('itm_id','itm_name')
			->where('itm_status','Active')
			->where('itm_type','Both')
			->orWhere('itm_type','Sales')
			->get();
		}
		public function insertitemrecordsmodel($rec)
		{
			return $update=DB::table('itm_item')->where('itm_id',$rec['itemid'])->update(['itm_farmitem'=>'yes']);
		}		
		public function salesLoadviewitem()
		{
			return $itm_item=DB::table('itm_item')
			->leftjoin('cat_category','cat_category.cat_id','=','itm_item.cat_id')
			->leftjoin('unt_unit','unt_unit.unt_id','=','itm_item.unt_id')
			->where('itm_item.itm_status','Active')
			->where('itm_item.itm_type','=','Sales')
			->where('itm_item.itm_farmitem','=','yes')
			->get();
		}
		public function entrysettingsitemdetailsmodel($id)
		{
			$itm_ids = $id['itm_ids'];
			return $itemrecord=DB::table('itm_item')->select('itm_id','itm_name','itm_code')
			->where('itm_id','=',$itm_ids)
			->first();
		}
		public function settingsentrymodel($id)
		{
			$itemid = $id['itm_ids'];
			return $itm_item=DB::table('fed_masterfeed')->select('fed_day','fed_feed','fed_water','fed_medicine','fed_status')
			->where('fed_masterfeed.fed_status','Active')
			->where('fed_masterfeed.itm_id','=',$itemid)
			->get();
		}
		public function performancesettingsrecmodel($id)
		{
			$itemid = $id['itm_ids'];
			return $itm_item=DB::table('std_standardperformance')->select('std_day','std_weight_per_bird','std_feed_consumption','std_cum_feedconsumption1000birdsinkg','std_summer_waterconsumption','std_winter_waterconsumption','std_for1000birds','std_fcr','std_status')
			->where('std_standardperformance.std_status','Active')
			->where('std_standardperformance.itm_id','=',$itemid)
			->get();
		}
		public function submitentryrecordsmodel($id)
		{
			$insertdetails=0;
			$itemid = $id['itemid'];
			$arrdays = $id['arrdays'];
			$arrfeeds = $id['arrfeeds'];
			$arrwaters = $id['arrwaters'];
			$arrmedicines = $id['arrmedicines'];
			
			$itemUp=DB::table('fed_masterfeed')->where('itm_id',$itemid)
			->update(['fed_status'=>'Inactive']);
			
			for($i=0;$i<count($arrdays);$i++)
			{
				$entryrecord=DB::table('fed_masterfeed')->insertGetId(['itm_id'=>$itemid,'fed_day'=>$arrdays[$i],'fed_feed'=>$arrfeeds[$i],'fed_water'=>$arrwaters[$i],'fed_medicine'=>$arrmedicines[$i],'fed_status'=>'Active']);
			}
			$insertdetails=1;
			return $insertdetails;
		}
	}