<!-- DATA EXPORT -->
<div class="widget widget-table">
	<div class="widget-header">
		<h3><i class="fa fa-table"></i> Farm Sheet</h3>
	</div>
	<div class="widget-content">
	<table id="datatable-data-export" class="table table-sorting table-striped table-hover table-bordered datatable">		
				<tr>
					<th>Shed name</th>	
					<td>{{$data['batchrec']->shd_name}}</td>
					<th>Time of Hatch</th>	
					<td>{{$data['batchrec']->bch_disptime}}</td>
					<th>Sold</th>	
					<td>{{$data['farmsheetrecords']->sum('totalsold')}}</td>
					<th colspan='2'>PERFORMANCE PARAMETERS</th>						
				</tr>
				<tr>
					<th>Batch No.</th>	
					<td>{{$data['batchrec']->bch_batchcode}}</td>	
					<th>No. of Chicks</th>	
					<td>{{$data['batchcountpaid']->sum('bit_qty')}}</td>
					<th>Difference</th>	
					<td>{{$data['batchcountpaid']->sum('bit_qty') + $data['batchcountfree']->sum('bit_qty') - ($data['farmsheetrecords']->sum('feed_mortality') + $data['farmsheetrecords']->sum('totalsold'))}}</td>
					<th>Average weight</th>	
					<td>{{$data['farmsheetrecords']->sum('totalsold')/$data['farmsheetrecords']->sum('totalsold')}}</td>							
				</tr>
				<tr>
					<th>Date</th>
					<td><?php
						$dt = $data['batchrec']->bch_dttim;
						echo date('d-M-Y', strtotime($dt)); 
						?></td>		
					<th>Free Chicks</th>	
					<td>{{$data['batchcountfree']->sum('bit_qty')}}</td>
					<th>Total Weight kg</th>	
					<td>{{ $data['farmsheetrecords']->sum('totalsold') }}</td>
					<th>Livability%</th>	
					<td>{{ 100-($data['farmsheetrecords']->sum('feed_mortality') / ($data['batchcountpaid']->sum('bit_qty') + $data['batchcountfree']->sum('bit_qty'))) }}%</td>							
				</tr>
				<tr>
					<th>Time</th>
					<td><?php
						$dt = $data['batchrec']->bch_dttim;
						echo date('h:i:s', strtotime($dt)); 
						?></td>	
					<th>Total Chicks</th>	
					<td>{{$data['batchcountpaid']->sum('bit_qty') + $data['batchcountfree']->sum('bit_qty')}}</td>
					<th>Rate</th>	
					<td>{{$data['farmsheetrecords']->avg('bit_cost')}}</td>
					<th>Mortality%</th>	
					<td>{{ $data['farmsheetrecords']->sum('feed_mortality') / ($data['batchcountpaid']->sum('bit_qty') + $data['batchcountfree']->sum('bit_qty')) }}%</td>								
				</tr>
				<tr>
					<th>Day</th>
					<td><?php
						$dt = $data['batchrec']->bch_dttim;
						echo date('l', strtotime($dt)); 
						?></td>	
					<th>Rate per chick</th>	
					<td>Rs. {{$data['batchcountpaid']->avg('bit_cost')}}</td>
					<th>Amount</th>	
					<td>{{$data['farmsheetrecords']->sum('bit_cost') * $data['farmsheetrecords']->sum('totalsold') }}</td>
					<th>FCR</th>	
					<td>{{ $data['farmsheetrecords']->sum('feed_feed')/$data['farmsheetrecords']->sum('totalsold') }}</td>								
				</tr>
				<tr>
					<th>Hatchery</th>
					<td><?php
						$dt = $data['batchrec']->bch_dttim;
						echo date('d-M-Y', strtotime($dt)); 
						?></td>		
					<th>Amount</th>	
					<td>Rs. {{$data['batchcountpaid']->sum('bit_qty') * $data['batchcountpaid']->avg('bit_cost')}}</td>
					<th>Feed Cons kg</th>	
					<td>{{ $data['farmsheetrecords']->sum('feed_feed') }}</td>
					<th>Mean Age</th>	
					<td>0</td>							
				</tr>
				<tr>
					<th>Strain of Chicks</th>	
					<td>{{$data['batchrec']->bch_strchicks}}</td>
					<th>Cost Per Chick</th>	
					<td>Rs. {{ ($data['batchcountpaid']->sum('bit_qty') * $data['batchcountpaid']->avg('bit_cost')) / ($data['batchcountpaid']->sum('bit_qty') + $data['batchcountfree']->sum('bit_qty')) }}</td>
					<th>Feed in Bg</th>	
					<td>{{ $data['farmsheetrecords']->sum('feed_feed') /50 }}</td>
					<th>CFCR</th>	
					<td>{{ ((2-$data['farmsheetrecords']->sum('totalsold')/$data['farmsheetrecords']->sum('totalsold'))*0.25)+$data['farmsheetrecords']->sum('feed_feed')/$data['farmsheetrecords']->sum('totalsold') }}</td>
				</tr>
				<tr>
					<th>Remarks</th>
					<td>{{$data['batchrec']->bch_remark}}</td>	
					<th>Mortality</th>	
					<td>{{$data['farmsheetrecords']->sum('feed_mortality')}}</td>
					<th>Per kg prod cost</th>	
					<td>0</td>
					<th>BPI</th>	
					<td>0</td>								
				</tr>
				<tr>
					<th>Date of hatch</th>	
					<td>{{$data['batchrec']->bch_hatchdt}}</td>	
					<th></th>	
					<td></td>
					<th></th>	
					<td></td>
					<th>BPEF</th>	
					<td>0</td>								
				</tr>
	</table>
	
		<table id="datatable-data-export" class="table table-sorting table-striped table-hover table-bordered datatable">
			<thead>
				<tr>
					<th>Days</th>
					<th>Date</th>
					<th>OPENING</th>
					<th>MORTALITY</th>
					<th>SOLD</th>
					<th>CLOSING</th>
					<th>REMARKS</th>
					<th>Feed in Kg</th>	
					<th>Water in Ltrs</th>							
				</tr>
			</thead>
			<tbody>
			<?php 
			$totalchicks = $data['batchcountpaid']->sum('bit_qty') + $data['batchcountfree']->sum('bit_qty'); 
			$mortality=0;	
			$totalsold=0;
			$feedinkg=0;
			$waterinltr=0;
				?>
				@foreach ($data['farmsheetrecords'] as $entryrecords) 
				<tr>
					<td><?php
							$today = strtotime(date('Y-m-d',strtotime($data['batchrec']->bch_dttim)));
							$your_date = strtotime($entryrecords->feed_dt);
							$datediff = $your_date - $today;
							echo floor($datediff / (60 * 60 * 24));
				?></td>
					<td><?php echo date("d-m-Y",strtotime($entryrecords->feed_dt)); ?></td>
					<td><?php echo $totalchicks; ?></td>
					<td><?php 
					echo $entryrecords->feed_mortality; 
						$mortality= $mortality + $entryrecords->feed_mortality; 
						?></td>
					<td><?php 
						echo $entryrecords->totalsold;	
						$totalsold = $totalsold + $entryrecords->totalsold;
						?></td>
					<td><?php echo $totalchicks = $totalchicks - ($entryrecords->feed_mortality + $entryrecords->totalsold);  ?></td>
					<td><?php echo $entryrecords->feed_medical; ?></td>	
					<td><?php
						echo $entryrecords->feed_feed;
						$feedinkg=$feedinkg + $entryrecords->feed_feed;
						?></td>
					<td><?php 
						echo $entryrecords->feed_water; 
						$waterinltr = $waterinltr + $entryrecords->feed_water;
						?></td>									
				</tr>
				@endforeach
			</tbody>			
			<tfoot>
				<tr>
					<th>TOTAL</th>
					<th></th>
					<th></th>
					<th><?php echo $mortality; ?></th>
					<th><?php echo $totalsold; ?></th>
					<th></th>
					<th></th>
					<th><?php echo $feedinkg; ?></th>	
					<th><?php echo $waterinltr; ?></th>				
				</tr>
			</tfoot>
		</table>
	</div>
</div>
<!-- END DATA EXPORT -->