<div class="PurchaseprintBill">
	<div class="content">	
	<div class="main-content">	
	
	<form id="frmPurchase" name="frmPurchase" data-parsley-validate novalidate method="POST">
		<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
		<input type="hidden" name="itemid" id="itemid" value="<?php echo e($data['entryitemdet']->itm_id); ?>">

		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-user"></i> Performance settings</h3>
			</div>
			<div class="widget-content">
				<table id="user" class="table table-bordered table-striped">
					<tbody>
						<tr>
							<th>Item Name</th>
							<td><?php echo e($data['entryitemdet']->itm_name); ?></td>
						</tr>
						<tr>
							<th>Item Code</th>
							<td><?php echo e($data['entryitemdet']->itm_code); ?></td>
						</tr>
					</tbody>
				</table>
			</div>	
		</div>	
		
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-user"></i> Standard Performance parameter</h3> <em></em>
			</div>
			<div class="widget-content">
			
				<?php
				if(count($data['performancesettingsrec']) == 0 )
				{
				?>
				<div class="row">
					<div class="col-sm-1 nopadding">
						<div class="form-group">
							<label for="multiselect1">Age in Days</label>
							<br/>
							<input type="text" name="ageindays[]" id="day0" class="form-control"  >
						</div>
					</div>
					<div class="col-sm-1 nopadding">
						<div class="form-group">
							<label for="multiselect1">Weight Per bird</label>
							<br/>
							<input type="text" name="weightperbird[]" id="feed0" class="form-control"  >
						</div>
					</div>
					<div class="col-sm-1 nopadding">
						<div class="form-group">
							<label for="multiselect1">Feed Consumption</label>
							<br/>
							<input type="text" name="feedconsumption[]" id="water0" class="form-control" >
						</div>
					</div>
					<div class="col-sm-2 nopadding">
						<div class="form-group">
							<label for="multiselect1">Cum Feed Consumption 1000 birds in kg</label>
							<br/>
							<input type="text" name="cumfeedconsumption[]" id="medicine0" class="form-control" >
						</div>
					</div>
					<div class="col-sm-2 nopadding">
						<div class="form-group">
							<label for="multiselect1">water consumption	(Summer)</label>
							<br/>
							<input type="text" name="summerwaterconsumption[]" id="medicine0" class="form-control" >
						</div>
					</div>
					<div class="col-sm-2 nopadding">
						<div class="form-group">
							<label for="multiselect1">water consumption	(Winter)</label>
							<br/>
							<input type="text" name="winterwaterconsumption[]" id="medicine0" class="form-control" >
						</div>
					</div>
					<div class="col-sm-1 nopadding">
						<div class="form-group">
							<label for="multiselect1">For 1000 birds</label>
							<br/>
							<input type="text" name="for1000birds[]" id="medicine0" class="form-control" >
						</div>
					</div>
					<div class="col-sm-1 nopadding">
						<div class="form-group">
							<label for="multiselect1">FCR<br>&nbsp;</label>
							<br/>
							<input type="text" name="fcr[]" id="medicine0" class="form-control" >
						</div>
					</div>
					<div class="clear"></div>
				</div>				
				<div id="education_fields"  class="row"></div>
				<?php
				}
				else
				{
				?>
					<div class="row">
					<div class="col-sm-1 nopadding">
						<div class="form-group">
							<label for="multiselect1">Age in Days</label>
						</div>
					</div>
					<div class="col-sm-1 nopadding">
						<div class="form-group">
							<label for="multiselect1">Weight Per bird</label>
						</div>
					</div>
					<div class="col-sm-1 nopadding">
						<div class="form-group">
							<label for="multiselect1">Feed Consumption</label>
						</div>
					</div>
					<div class="col-sm-2 nopadding">
						<div class="form-group">
							<label for="multiselect1">Cum Feed Consumption 1000 birds in kg</label>
						</div>
					</div>
					<div class="col-sm-2 nopadding">
						<div class="form-group">
							<label for="multiselect1">water consumption	(Summer)</label>
						</div>
					</div>
					<div class="col-sm-2 nopadding">
						<div class="form-group">
							<label for="multiselect1">water consumption	(Winter)</label>
						</div>
					</div>
					<div class="col-sm-1 nopadding">
						<div class="form-group">
							<label for="multiselect1">For 1000 birds</label>
						</div>
					</div>
					<div class="col-sm-1 nopadding">
						<div class="form-group">
							<label for="multiselect1">FCR<br>&nbsp;</label>
						</div>
					</div>
					<div class="clear"></div>
				</div>
						<div id="education_fields"  class="row">
						<?php
						foreach ($data['performancesettingsrec'] as $settingsentryrecs)
						{
						?>						
						<div class="form-group removeclassa3"><div class="col-sm-1 nopadding"><div class="form-group"><input type="text" name="ageindays[]" id="day0" class="form-control" value="<?php echo $settingsentryrecs->std_day; ?>"  ></div></div><div class="col-sm-1 nopadding"><div class="form-group"><input type="text" name="weightperbird[]" id="feed0" class="form-control"  value="<?php echo $settingsentryrecs->std_weight_per_bird; ?>" ></div></div><div class="col-sm-1 nopadding"><div class="form-group"><input type="text" name="feedconsumption[]" id="water0" class="form-control"  value="<?php echo $settingsentryrecs->std_feed_consumption; ?>"></div></div><div class="col-sm-2 nopadding"><div class="form-group"><input type="text" name="cumfeedconsumption[]" id="medicine0" class="form-control"  value="<?php echo $settingsentryrecs->std_cum_feedconsumption1000birdsinkg; ?>" ></div></div><div class="col-sm-2 nopadding"><div class="form-group"><input type="text" name="summerwaterconsumption[]" id="medicine0" class="form-control"  value="<?php echo $settingsentryrecs->std_summer_waterconsumption; ?>" ></div></div><div class="col-sm-2 nopadding"><div class="form-group"><input type="text" name="winterwaterconsumption[]" id="medicine0" class="form-control"  value="<?php echo $settingsentryrecs->std_winter_waterconsumption; ?>" ></div></div><div class="col-sm-1 nopadding"><div class="form-group"><input type="text" name="for1000birds[]" id="medicine0" class="form-control"  value="<?php echo $settingsentryrecs->std_for1000birds; ?>" ></div></div><div class="col-sm-1 nopadding"><div class="form-group"><input type="text" name="fcr[]" id="medicine0" class="form-control"  value="<?php echo $settingsentryrecs->std_fcr; ?>" ></div></div><div class="clear"></div><div class="col-sm-1 nopadding"><div class="form-group"><div class="input-group"><div class="input-group-btn"><button type="button" class="form-control" onclick="remove_education_fields('+ room +');" >X</button></div></div></div></div><div class="clear"></div></div>
						<?php
						}
						?>
						</div>
				<?php
				}
				?>
				
				
				<div class="row">
					<div class="col-sm-3 nopadding">
						<div class="form-group">
							<div class="input-group">
								
								<div class="input-group-btn">
									
									<button type="button"  value="Add" class="form-control" onclick="education_fields();" >ADD</button>
									
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!-- Puchase detail -->		
		<div class="widget widget-table">
					<div class="col-md-12">
						<div class="form-group"><br>
							<center><button  class="btn btn-primary btngenerateentry">Click Here to update</button></center>
						</div>
					</div>	
		</div>
		<!-- END Puchase detail -->	
		</form>
	</div>
</div>
</div>
<!-- /main -->
<script>
	$('.clickme').click(function(e)
	{
		e.preventDefault();
		$('#sideMenu').load($(this).attr('href'));
	});	
	//###Coding to create new row for items starts here
	var room = 0;
	function education_fields() 
	{
		room++;
		var objTo = document.getElementById('education_fields');
		var divtest = document.createElement("div");
		divtest.setAttribute("class", "form-group removeclassa"+room);
		var rdiv = 'removeclass'+room;
		divtest.innerHTML = '<div class="col-sm-1 nopadding"><div class="form-group"><input type="text" name="ageindays[]" id="day0" class="form-control"  ></div></div><div class="col-sm-1 nopadding"><div class="form-group"><input type="text" name="weightperbird[]" id="feed0" class="form-control"  ></div></div><div class="col-sm-1 nopadding"><div class="form-group"><input type="text" name="feedconsumption[]" id="water0" class="form-control" ></div></div><div class="col-sm-2 nopadding"><div class="form-group"><input type="text" name="cumfeedconsumption[]" id="medicine0" class="form-control" ></div></div><div class="col-sm-2 nopadding"><div class="form-group"><input type="text" name="summerwaterconsumption[]" id="medicine0" class="form-control" ></div></div><div class="col-sm-2 nopadding"><div class="form-group"><input type="text" name="winterwaterconsumption[]" id="medicine0" class="form-control" ></div></div><div class="col-sm-1 nopadding"><div class="form-group"><input type="text" name="for1000birds[]" id="medicine0" class="form-control" ></div></div><div class="col-sm-1 nopadding"><div class="form-group"><input type="text" name="fcr[]" id="medicine0" class="form-control" ></div></div><div class="clear"></div><div class="col-sm-1 nopadding"><div class="form-group"><div class="input-group"><div class="input-group-btn"><button type="button" class="form-control" onclick="remove_education_fields('+ room +');" >X</button></div></div></div></div><div class="clear"></div>';		
		objTo.appendChild(divtest)
		$('#num').val(room);
		ijk=$('#num').val(room);
	}
	//###Coding to create new row for items ends here
	//###Coding to remove row of items starts here
	function remove_education_fields(rid) 
	{
		$('.removeclassa'+rid).remove();
		findTotal();
	}
	//###Coding to remove row of items ends here
	//### Entry submission code starts here
	flag=0;
	$('.btngenerateentry').click(function(e)
	{
		e.preventDefault();
		var _token = $("input[name='_token']").val();
		var itemid = $("#itemid").val();						   
		
		arrdays = [];
		arrfeeds = [];
		arrwaters = [];
		arrmedicines = [];
		var entryday= document.getElementsByName("day[]");
		var entryfeed= document.getElementsByName("feed[]");
		var entrywater= document.getElementsByName("water[]");
		var entrymedicine= document.getElementsByName("medicine[]");
		for (index = 0; index < entryday.length; ++index) 
		{
			arrdays[index] = entryday[index].value;
			arrfeeds[index] = entryfeed[index].value;
			arrwaters[index] = entrywater[index].value;
			arrmedicines[index] = entrymedicine[index].value;
		}
		
		$.ajax({
			url: "entryrecordsubmit",
			type:'POST',
			dataType: 'json',
			data: {_token:_token,itemid:itemid,arrdays:arrdays,arrfeeds:arrfeeds,arrwaters:arrwaters, arrmedicines:arrmedicines},
			success: function(data)
			{
				if(data.status == 1)
				{
					alert("Entry record updated successfully..");
				}
				else
				{
					alert("Failed to Generate update record..");
				}
			}
		});
	});
	//### Entry submission code ends here
</script>