<header class="page-header">
	<h2>Importing Products For Requisition</h2>
</header>
<span id='wait' style='display:none;color:red' class='box' ><h1>Click to Save</h1></span>
<div id="maindiv">
<form method="post" action="<?=url('requisitions','import_save')?>" enctype="multipart/form-data">

<section class="panel">
			
<header class="panel-heading">
				<div class="panel-actions">
					<a href="#" class="panel-action panel-action-toggle" data-panel-toggle></a>
					<a href="#" class="panel-action panel-action-dismiss" data-panel-dismiss></a>
				</div>
				
				<h2 class="panel-title">List of Receipts</h2>
			</header>	
<div class="panel-body">

	<div class="form-group">
						<label class="col-md-3 control-label" for="">List Name</label>
						<div class="col-md-6">
							<input type="text" class="form-control" id="listname" data-toggle="tooltip" data-trigger="hover" data-original-title="Enter list name" name="listname" required>
						</div>
	</div>
	<div class="form-group">
						<label class="col-md-3 control-label" for="">Start Date</label>
						<div class="col-md-6">
							<input type="text" class="form-control datepicker2" id="startdate" data-toggle="tooltip" data-trigger="hover" data-original-title="Enter start date" name="startdate" required>
						</div>
	</div>
	<div class="form-group">
						<label class="col-md-3 control-label" for="">End Date</label>
						<div class="col-md-6">
							<input type="text" class="form-control datepicker2" id="enddate" data-toggle="tooltip" data-trigger="hover" data-original-title="Enter start date" name="enddate" required>
						</div>
	</div>
	
<table class="crm_table" >
<col width="100">
<caption>List of Products </caption>
<tr>
	<th> Product Id </th>
	<th> Tradename </th>
	<th> NHIF Charge</th>
	<th> Qty </th>
	<th> Units </th>
	<th> Pack  </th>
</tr>
<? $cnt=0;
	foreach ($prods as $p) { ?>
<tr id="row<?=++$cnt?>">
	<td>
		<input type="hidden" class="rowNumber" value="<?=$cnt?>">
		<input type="text" class="form-control prodid" name="prodid[]" value="<?=$p[0]?>" >
		
	</td>
	<td>
		<input type="text" class="form-control nhifname" name="nhifname[]" value="<?=$p[1]?>" >
		
	</td>
	<td>
		<input type="text" class="form-control nhifcharge" name="nhifcharge[]" value="<?=$p[2]?>" >
	</td>
	<td>
		<input type="text" class="form-control qty" name="qty[]" value="<?=$p[3]?>">
	</td>
	<td>
		<input type="text" class="form-control units" name="units[]" value="<?=$p[4]?>">
		
	</td>
	<td>
		<input type="text" class="form-control pack" name="pack[]" value="<?=$p[5]?>">
		
	</td>
</tr>
<? } ?>
</table>

<!--<input type="submit" value="Save" >-->
<a onclick="sendVals()" id="save" class="mb-xs mt-xs mr-xs btn btn-success">Save</a>
<span id="saveSpan"></span>
</div>
</section>
</form>
</div>

<script>
	
	function sendVals(){
		
		var listname = $("#listname").val();
		var startdate = $("#startdate").val();
		var enddate = $("#enddate").val();
		
		if (startdate != '' && enddate != '' && listname != ''){
		
		$("#save").hide();
		$("#saveSpan").html('Saving...Please wait as this may take a few minutes <img src="assets/images/preloader.gif" width="40px"/>');
		
		$('.prodid').each( function() {
			
			tr = $(this).closest('tr');
			prodid = $(tr).find('.prodid').val();
			nhifname = $(tr).find('.nhifname').val();
			nhifcharge = $(tr).find('.nhifcharge').val();
			qty = $(tr).find('.qty').val();
			units = $(tr).find('.units').val();
			pack = $(tr).find('.pack').val();
		
			
				 $.get('?module=requisitions&action=submitForm&format=json&prodid='+prodid+'&nhifname='+nhifname+'&nhifcharge='+nhifcharge+'&qty='+qty+'&units='+units+'&pack='+pack+'&listname='+listname+'&startdate='+startdate+'&enddate='+enddate,null,function(d){
					CC = JSON.parse(d);
					
					
				});
			
			
		 });
		 $(document).ajaxStop(function() {
		  window.location.href = "?module=requisitions&action=index";
		});
		
		}else{
			
				triggerError('Enter listname, start and end dates');
			}
		
		
		
	}
	
	</script>