<?php
	namespace App\Http\Controllers;
	use Illuminate\Foundation\Bus\DispatchesJobs;
	use Illuminate\Routing\Controller as BaseController;
	use Illuminate\Foundation\Validation\ValidatesRequests;
	use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
	use Illuminate\Foundation\Auth\Access\AuthorizesResources;
	use Illuminate\Http\Request;
	use DB;
	use App\Http\Model\FarmModel;
	use Validator;
	
	class EntryController extends Controller
	{
		public function __construct()
		{
			$this->Farm= new FarmModel;
		}
		public function addentry()
		{
			$data['Shed']=$this->Farm->Shed();
			return view('entry',compact('data'));
		}
		public function SubshedName(Request $request)
		{
			$data['ShedBatchID']=$request->input('shedid');
			$batchnumber=$this->Farm->SubshedName($data);
			return json_encode($batchnumber);
		}
		public function BatchEntryFarm(Request $request)
		{
			$date=date('Y-m-d');
			$todate=date('d-m-Y');
			$data['BatchNo']=$request->input('BatchNo');
			$BatchEntryFarmId=$this->Farm->BatchEntryFarm($data);
			$data['DailyHumidity']=$BatchEntryFarmId->DailyHumidity;
			$data['DailyFeed']=$BatchEntryFarmId->DailyFeed;
			$data['DailyWater']=$BatchEntryFarmId->DailyWater;
			$data['DailyTemp']=$BatchEntryFarmId->DailyTemp;
			$data['day']=$todate;
			$days = [1 => 'Monday',2 => 'Tuesday',3 => 'Wednesday',4 => 'Thursday',5 => 'Friday',6 => 'Saturday',7 => 'Sunday'];
			$data['day_number']= $days[date('N',strtotime($date))];
			return $data;			
		}
		public function AddFarmRecord(Request $request)
		{
			$data['shedName']=$request->input('shedName');
			$data['BatchNumber']=$request->input('BatchNumber');
			$data['Date1']=$request->input('Date1');
			$data['day']=$request->input('day');
			$data['Feed']=$request->input('Feed');
			$data['Water']=$request->input('Water');
			$data['Observation']=$request->input('Observation');
			$data['Suggestion']=$request->input('Suggestion');
			$data['Mortality']=$request->input('Mortality');
			$data['Feed1']=$request->input('Feed1');
			$data['Water1']=$request->input('Water1');
			$data['Med/VAC']=$request->input('Med/VAC');
			$data['Weight']=$request->input('Weight');
			$data['TEMP']=$request->input('TEMP');
			$data['Humidity']=$request->input('Humidity');
			return $AddFarm=$this->Farm->AddFarmRecord($data);
			
		}
		public function viewentry()
		{
			return view('entryView');
		}
		public function AddWeightEntry(Request $request)
		{
			$data['shedName']=$request->input('ShedName');
			$data['BatchNumber']=$request->input('BatchNumber');
			$data['batchDate']=$request->input('batchDate');
			$data['batchDay']=$request->input('batchDay');
			$data['num']=$request->input('num');
			for($i=1;$i<=$data['num'];$i++)
			{
				$data['batchSlno'.$i]=$request->input('batchSlno'.$i);
				$data['noOfBird'.$i]=$request->input('noOfBird'.$i);
				$data['ToatlWeight'.$i]=$request->input('ToatlWeight1'.$i);
			}
			return $AddFarm=$this->Farm->AddWeightEntry($data);
		}
		public function addnewbatch(Request $request)
		{
			$data['batchno']=$request->input('batchno');
			$data['compname']=$request->input('compname');
			$data['user']=$request->input('user');
			$data['StrainofChicks']=$request->input('StrainofChicks');
			$data['batchDatetim']=$request->input('batchDate') . " ". $request->input('batchTime') ;
			$data['Hatchery']=$request->input('Hatchery');
			$data['DateofHatch']=$request->input('DateofHatch');
			$data['dispatchfromHatchery']=$request->input('dispatchfromHatchery');
			$data['Remarks']=$request->input('Remarks');
			$data['status']=$request->input('status');	
			$data['itemid']=$request->input('itemname');	
			return $newbatch=$this->Farm->AddBatchrecords($data);
		}
	}
