<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); ?>">
		<!-- Puchase detail -->		
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-user"></i> Entry 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>
		<!-- END Puchase detail -->		
		
		
		<!-- ITEM RECORD STARTS HERE-->		
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-user"></i> Entry records</h3> <em></em>
			</div>
			<div class="widget-content">
								
				
				<?php
				if(count($data['settingsentryrec']) == 0 )
				{
				?>
				<div class="row">
					<div class="col-sm-1 nopadding">
						<div class="form-group">
							<label for="multiselect1">Day</label>
							<br/>
							<input type="text" name="day[]" id="day0" class="form-control"  >
						</div>
					</div>
					<div class="col-sm-2 nopadding">
						<div class="form-group">
							<label for="multiselect1">Feed</label>
							<br/>
							<input type="text" name="feed[]" id="feed0" class="form-control"  >
						</div>
					</div>
					<div class="col-sm-2 nopadding">
						<div class="form-group">
							<label for="multiselect1">Water</label>
							<br/>
							<input type="text" name="water[]" id="water0" class="form-control" >
						</div>
					</div>
					<div class="col-sm-5 nopadding">
						<div class="form-group">
							<label for="multiselect1">Medicine</label>
							<br/>
							<input type="text" name="medicine[]" 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">Day</label>
						</div>
					</div>
					<div class="col-sm-2 nopadding">
						<div class="form-group">
							<label for="multiselect1">Feed</label>
						</div>
					</div>
					<div class="col-sm-2 nopadding">
						<div class="form-group">
							<label for="multiselect1">Water</label>
						</div>
					</div>
					<div class="col-sm-5 nopadding">
						<div class="form-group">
							<label for="multiselect1">Medicine</label>
						</div>
					</div>
					<div class="clear"></div>
				</div>
						<div id="education_fields"  class="row">
						<?php
						foreach ($data['settingsentryrec'] as $settingsentryrecs)
						{
						?>
						<div class="form-group removeclassa3"><div class="col-sm-1 nopadding"><div class="form-group"><input type="text" name="day[]" id="day0"  value="<?php echo $settingsentryrecs->fed_day; ?>" class="form-control"></div></div><div class="col-sm-2 nopadding"><div class="form-group"><input type="text" value="<?php echo $settingsentryrecs->fed_feed; ?>" name="feed[]" id="feed0" class="form-control"></div></div><div class="col-sm-2 nopadding"><div class="form-group"><input type="text"  value="<?php echo $settingsentryrecs->fed_water; ?>" name="water[]" id="water0" class="form-control"></div></div><div class="col-sm-5 nopadding"><div class="form-group"><input type="text" name="medicine[]" value="<?php echo $settingsentryrecs->fed_medicine; ?>" id="medicine0" class="form-control"></div></div><div class="col-sm-2 nopadding"><div class="form-group"><div class="input-group"><div class="input-group-btn"><button type="button" class="form-control" onclick="remove_education_fields(3);">REMOVE</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>
		<!-- ITEM RECORD ENDS HERE -->	

		<!-- 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="day[]" id="day0" class="form-control"  ></div></div><div class="col-sm-2 nopadding"><div class="form-group"><input type="text" name="feed[]" id="feed0" class="form-control"  ></div></div><div class="col-sm-2 nopadding"><div class="form-group"><input type="text" name="water[]" id="water0" class="form-control" ></div></div><div class="col-sm-5 nopadding"><div class="form-group"><input type="text" name="medicine[]" id="medicine0" class="form-control" ></div></div><div class="col-sm-2 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 +');" >REMOVE</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>