<!-- CUSTOM COLORED TABS -->
<div class="widget">
	<div class="widget-header">
		<h3>Batch Info</h3><em>Shed: <?php echo e($data['batchrec']->shd_name); ?> | Batch No. <?php echo e($data['batchrec']->bch_batchcode); ?> || Farm item : <?php echo e($data['batchrec']->itm_name); ?> - (<?php echo e($data['batchrec']->itm_code); ?>) </em>
	</div>
	<div class="widget-content">
		<ul class="nav nav-tabs nav-tabs-custom-colored" role="tablist">
			<li class="active"><a href="#coloredBatchDetail" role="tab" data-toggle="tab"><i class="fa fa-home"></i> Batch</a></li>
			<li onclick="loadcoloredEntries(<?php echo e($data['batchrec']->bch_id); ?>)"><a href="#coloredEntries" role="tab" data-toggle="tab"><i class="fa fa-cog"></i> Entries</a></li>
			<li onclick="loadcoloredEntryRecords(<?php echo e($data['batchrec']->bch_id); ?>)"><a href="#coloredEntryRecords" role="tab" data-toggle="tab"><i class="fa fa-cog"></i> Entry Records</a></li>
			<li onclick="loadcoloredFarmSheet(<?php echo e($data['batchrec']->bch_id); ?>)"><a href="#coloredFarmSheet" role="tab" data-toggle="tab"><i class="fa fa-cog"></i> Farm Sheet</a></li>
			<li onclick="loadcoloredDailyComparison(<?php echo e($data['batchrec']->bch_id); ?>)"><a href="#coloredDailyComparison" role="tab" data-toggle="tab"><i class="fa fa-cog"></i> Daily Comparison</a></li>
			<li onclick="loadcoloredPurchase(<?php echo e($data['batchrec']->bch_id); ?>)"><a href="#coloredPurchase" role="tab" data-toggle="tab"><i class="fa fa-cog"></i> Purchase</a></li>
			<li onclick="loadcoloredSales(<?php echo e($data['batchrec']->bch_id); ?>)"><a href="#coloredSales" role="tab" data-toggle="tab"><i class="fa fa-cog"></i> Sales</a></li>
			<li onclick="loadcoloredPerformance(<?php echo e($data['batchrec']->bch_id); ?>)"><a href="#coloredPerformance" role="tab" data-toggle="tab"><i class="fa fa-cog"></i> Performance</a></li>
			<li onclick="loadcoloredpl(<?php echo e($data['batchrec']->bch_id); ?>)"><a href="#coloredpl" role="tab" data-toggle="tab"><i class="fa fa-cog"></i> Profit & Loss</a></li>
		</ul>
		<div class="tab-content">
			<div class="tab-pane fade in active" id="coloredBatchDetail">
				<p>
		<table id="user" class="table table-bordered table-striped">
			<tbody>
				<tr>
					<th>User</th>
					<td><?php echo e($data['batchrec']->usr_name); ?> - <?php echo e($data['batchrec']->usr_loginid); ?></td>
				</tr>
				<tr>
					<th>Shed Name</th>
					<td><?php echo e($data['batchrec']->shd_name); ?></td>
				</tr>
				<tr>
					<th>Farm item</th>
					<td><?php echo e($data['batchrec']->itm_name); ?> - (<?php echo e($data['batchrec']->itm_code); ?>)</td>
				</tr>
				<tr>
					<th>Batch No.</th>
					<td><?php echo e($data['batchrec']->bch_batchcode); ?></td>
				</tr>
				<tr>
					<th>Date.</th>
					<td><?php
						$dt = $data['batchrec']->bch_dttim;
						echo date('d-M-Y', strtotime($dt)); 
						?>
					</td>
				</tr>
				<tr>
					<th>Day.</th>
					<td>
						<?php
						$dt = $data['batchrec']->bch_dttim;
						echo date('l', strtotime($dt)); 
						?>
					</td>
				</tr>
				<tr>
					<th>Time.</th>
					<td>
						<?php
						$dt = $data['batchrec']->bch_dttim;
						echo date('h:i A', strtotime($dt)); 
						?>
					</td>
				</tr>
				<tr>
					<th>Strain of chicks.</th>
					<td><?php echo e($data['batchrec']->bch_strchicks); ?></td>
				</tr>
				<tr>
					<th>Hatchery.</th>
					<td><?php echo e($data['batchrec']->bch_hatchery); ?></td>
				</tr>
				<tr>
					<th>No. of Chicks.</th>
					<td><?php echo e($data['batchcountpaid']->sum('bit_qty')); ?></td>
				</tr>
				<tr>
					<th>Free Chicks.</th>
					<td><?php echo e($data['batchcountfree']->sum('bit_qty')); ?></td>
				</tr>
				<tr>
					<th>Total Chicks.</th>
					<td><?php echo e($data['batchcountpaid']->sum('bit_qty') + $data['batchcountfree']->sum('bit_qty')); ?></td>
					</tr>
				<tr>
					<th>Rate per chick.</th>
					<td>Rs. <?php echo e($data['batchcountpaid']->avg('bit_cost')); ?></td>
				</tr>
				<tr>
					<th>Amount.</th>
					<td>Rs. <?php echo e($data['batchcountpaid']->sum('bit_qty') * $data['batchcountpaid']->avg('bit_cost')); ?></td>
				</tr>
				<tr>
					<th>Cost per chick.</th>
					<td>Rs. <?php echo e(($data['batchcountpaid']->sum('bit_qty') * $data['batchcountpaid']->avg('bit_cost')) / ($data['batchcountpaid']->sum('bit_qty') + $data['batchcountfree']->sum('bit_qty'))); ?></td>
				</tr>
				<tr>
					<th>Date of hatch.</th>
					<td><?php echo e($data['batchrec']->bch_hatchdt); ?></td>
				</tr>
				<tr>
					<th>Time of dispatch from Hatchery.</th>
					<td><?php echo e($data['batchrec']->bch_disptime); ?></td>
				</tr>
				<tr>
					<th>Remarks.</th>
					<td><?php echo e($data['batchrec']->bch_remark); ?></td>
				</tr>
				<tr>
					<th>Status.</th>
					<td><?php echo e($data['batchrec']->bch_status); ?></td>
				</tr>
			</tbody>
		</table>
				</p>
			</div>
			<div class="tab-pane fade" id="coloredEntries">
				<h5>Loading..</h5>
				<p><img src="img/loading.gif" width="250px;height:250px;"></p>
			</div>
			<div class="tab-pane fade" id="coloredEntryRecords">
				<h5>Loading..</h5>
				<p><img src="img/loading.gif" width="250px;height:250px;"></p>
			</div>
			<div class="tab-pane fade" id="coloredFarmSheet">
				<h5>Loading..</h5>
				<p><img src="img/loading.gif" width="250px;height:250px;"></p>
			</div>
			<div class="tab-pane fade" id="coloredDailyComparison">
				<h5>Loading..</h5>
				<p><img src="img/loading.gif" width="250px;height:250px;"></p>
			</div>
			<div class="tab-pane fade" id="coloredPurchase">
				<h5>Loading..</h5>
				<p><img src="img/loading.gif" width="250px;height:250px;"></p>
			</div>
			<div class="tab-pane fade" id="coloredSales">
				<h5>Loading..</h5>
				<p><img src="img/loading.gif" width="250px;height:250px;"></p>
			</div>
			<div class="tab-pane fade" id="coloredPerformance">
				<h5>Loading..</h5>
				<p><img src="img/loading.gif" width="250px;height:250px;"></p>
			</div>
			<div class="tab-pane fade" id="coloredpl">
				<h5>Loading..</h5>
				<p><img src="img/loading.gif" width="250px;height:250px;"></p>
			</div>
		</div>
	</div>
</div>
<!-- END CUSTOM COLORED TABS -->
<script type="application/javascript">
function loadcoloredEntries(batch_id)
{
		$.ajax({
			url: 'InfoEntries',
				type: 'get',
				data:'&batch_id='+batch_id,
				success: function(data)
				{
					document.getElementById("coloredEntries").innerHTML = data;
				}
		});		
}
function loadcoloredEntryRecords(batch_id)
{
		$.ajax({
			url: 'InfoEntryRecords',
				type: 'get',
				data:'&batch_id='+batch_id,
				success: function(data)
				{
					document.getElementById("coloredEntryRecords").innerHTML = data;
				}
		});		
}  
function loadcoloredFarmSheet(batch_id)
{	
		$.ajax({
			url: 'InfoFarmSheet',
				type: 'get',
				data:'&batch_id='+batch_id,
				success: function(data)
				{
					document.getElementById("coloredFarmSheet").innerHTML = data;
				}
		});
}
function loadcoloredDailyComparison(batch_id)
{	
		$.ajax({
			url: 'InfoDailyComparison',
				type: 'get',
				data:'&batch_id='+batch_id,
				success: function(data)
				{
					document.getElementById("coloredDailyComparison").innerHTML = data;
				}
		});
}  
function loadcoloredPurchase(batch_id)
{	
		$.ajax({
			url: 'InfoPurchase',
				type: 'get',
				data:'&batch_id='+batch_id,
				success: function(data)
				{
					document.getElementById("coloredPurchase").innerHTML = data;
				}
		});
}
function loadcoloredSales(batch_id)
{	
		$.ajax({
			url: 'InfoSales',
				type: 'get',
				data:'&batch_id='+batch_id,
				success: function(data)
				{
					document.getElementById("coloredSales").innerHTML = data;
				}
		});
}  
function loadcoloredPerformance(batch_id)
{	
		$.ajax({
			url: 'InfoPerformance',
				type: 'get',
				data:'&batch_id='+batch_id,
				success: function(data)
				{
					document.getElementById("coloredPerformance").innerHTML = data;
				}
		});
}
function loadcoloredStandardPerformance(batch_id)
{	
		$.ajax({
			url: 'InfoStandardPerformance',
				type: 'get',
				data:'&batch_id='+batch_id,
				success: function(data)
				{
					document.getElementById("coloredStandardPerformance").innerHTML = data;
				}
		});
}
function loadcoloredpl(batch_id)
{	
		$.ajax({
			url: 'Infopl',
				type: 'get',
				data:'&batch_id='+batch_id,
				success: function(data)
				{
					document.getElementById("coloredpl").innerHTML = data;
				}
		});
}


var room = 0;
//Add entry Row
function addentryinforow() 
{
	room++;
	var objTo = document.getElementById('entryrows');
	var divtest = document.createElement("div");
	divtest.setAttribute("class", "form-group removeclassa"+room);
	var rdiv = 'removeclassbatch'+room;
	divtest.innerHTML = '<div class="col-sm-3 nopadding"><div class="form-group"><input type="text" name="slno[]" id="slno[]" class="form-control"><small class="text-danger" id="errstatus"></small></div></div><div class="col-sm-3 nopadding"><div class="form-group"><input type="text" name="nobirds[]" id="nobirds[]" class="form-control"  ><small class="text-danger" id="errstatus"></small></div></div><div class="col-sm-3 nopadding"><div class="form-group"><input type="text" name="totweight[]" id="totweight[]" class="form-control" ><small class="text-danger" id="errstatus"></small></div></div><div class="clear"></div><div class="col-sm-3 nopadding"><div class="form-group"><div class="input-group"> <div class="input-group-btn"><button type="button" class="form-control" onclick="deleteentryinforow('+ room +');" >REMOVE</button></div></div></div></div><div class="clear"></div>';		
	objTo.appendChild(divtest)
	$('#num').val(room);
	ijk=$('#num').val(room);
}
//Delete entry Row
function deleteentryinforow(rid)
{
	$('.removeclassa'+rid).remove();
}

//### submission entry code starts here
function funentrysubmission()
	{
		var _token = $("input[name='_token']").val();
		var batchid = $("input[name='batchid']").val();
		var entrydate = $("input[name='entrydate']").val();
		var mortality = $("input[name='mortality']").val();
		var feed = $("input[name='feed']").val();
		var water = $("input[name='water']").val();
		var medvac = $("input[name='medvac']").val();
		var temperature = $("input[name='temperature']").val();
		var humidity = $("input[name='humidity']").val();
		var fed_id = $("input[name='fed_id']").val();		
		var observation = $("#observation").val();
		var suggestion = $("#suggestion").val();

		//itemname[] itemcost[] itemquantity[] itemtotal[]		
		arrslno = [];
		arrnobirds = [];
		arrtotweight = [];
		var slno= document.getElementsByName("slno[]");
		var nobirds= document.getElementsByName("nobirds[]");
		var totweight= document.getElementsByName("totweight[]");
		for (index = 0; index < slno.length; ++index) {
			arrslno[index] = slno[index].value;
			arrnobirds[index] = nobirds[index].value;
			arrtotweight[index] = totweight[index].value;
		}
		$.ajax({		
			url: "InfoEntriesInsert",
			type:'POST',
			dataType: 'json',
			//cache : false,
			//processData: false,
			data: {_token:_token,abatchid:batchid, aentrydate:entrydate, amortality:mortality, afeed:feed, awater:water,amedvac:medvac,atemperature:temperature,ahumidity:humidity,aobservation:observation,asuggestion:suggestion,aarrslno:arrslno,aarrnobirds:arrnobirds,aarrtotweight:arrtotweight,afed_id:fed_id},
			success: function(data)
			{
				if(data.status == "Success")
				{
					alert("Entry record inserted successfully..");
					//BillPrint(data.bil_id);
					//$('#sideMenu').load('PurchaseprintBill');
					//BillPrint(Billno)
				}
				else
				{
					alert("Failed to Generate Purchase Bill..");
					//printErrorMsg(data.message)
				}
			}
		});
		
	}
//### submission entry code ends here
</script>
<script>
//Show info entry on Entryrecords
function loadentryrec(batch_id,entryid)
{
		$.ajax({
			url: 'InfoEntriesedit',
				type: 'get',
				data:'&batch_id='+batch_id,
				success: function(data)
				{
					document.getElementById("coloredEntryRecords").innerHTML = data;
				}
		});	
}
//Show info entry on Entryrecords ends here
</script>
