<?php 
	$header_file=APPPATH.'views/include/header.php';
	require($header_file);
	$sidenav_file=APPPATH.'views/include/sidenav.php';
	require($sidenav_file);	?>

    <!-- BEGIN: Content-->
    <div class="app-content content">
      <div class="content-overlay"></div>
      <div class="content-wrapper">
        <div class="content-header row">
          <div class="content-header-left col-md-12 col-12 mb-2 breadcrumb-new">
            <h3 class="content-header-title mb-0 d-inline-block">Issues</h3>
            <div class="row breadcrumbs-top d-inline-block">
              <div class="breadcrumb-wrapper col-12">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="#">Home</a>
                  </li>
                  <li class="breadcrumb-item"><a href="#">Issues</a>
                  </li>
                  <li class="breadcrumb-item active">Issue Entry
                  </li>
                </ol>
              </div>
            </div>
          </div>
          
        </div>
        <div class="content-body" ><!-- Basic form layout section start -->
<section id="basic-form-layouts" >
	<div class="row justify-content-md-center">
		<div class="col-md-12">
			<div class="card">
				<div class="card-content collapse show">
					<div class="card-body">
						<form class="form" autocomplete="off" action="<?php echo site_url('Barcode/addIssue');?>" method="post">
							<div class="row justify-content-md-center">
								<div class="col-md-4 mleft">
									<div class="form-body">
										<div class="form-group">
										<?php $cur_date = date("d-m-Y");
										$cur_time = date("H:i:s");
										$branch_id = $_SESSION['branch_id'];
										$branch_name = $_SESSION['branch_name'];
										$full_name = $_SESSION['full_name']; ?>
											<label for="eventInput1">Issue Date</label>
										<!--	<input class="form-control" type="text" name="issue_date" id="issue_date" value="<?php //echo $cur_date ?>" readonly >-->
											<input class="form-control pickadate datepicker picker__input picker__input--active" type="text" name="issue_date"  id="uk_dp_1" required data-uk-datepicker="{format:'DD-MM-YYYY'}" placeholder="Issue Date">
										<input class="form-control" type="hidden" name="issue_time" id="issue_time" value="<?php echo $cur_time ?>" readonly >	
										</div>
									</div>
								</div>
								<div class="col-md-4">
									<div class="form-body">
										<div class="form-group">
											<label for="eventInput1">Outlet Name</label>
											<select name="outlet" id="outlet" class="form-control select2" required>
												<option value="">Select Outlet</option>
													<?php  foreach($outlet as $olt)
													{
												?>
													<option value="<?php echo $olt->address_id  ?>"><?php echo $olt->outlet ?></option>
												<?php
													} 
												?>
											</select>
											<input type="hidden" id="branch_id" class="form-control"  name="branch_id" value="<?php echo $branch_id;?>">
											<input type="hidden" id="branch_name" class="form-control"  name="branch_name" value="<?php echo $branch_name;?>">
											<input type="hidden" id="full_name" class="form-control"  name="full_name" value="<?php echo $full_name;?>">
											
										</div>
									</div>
								</div>
								<div class="col-md-4">
									<div class="form-body">
										<div class="form-group">
											<label for="eventInput1">Select Vehicle</label>
											<select class="form-control select2" id="vehicle_id" name="vehicle_id"  required>
        										<option value="">Select</option>
        										<?php foreach($vehicle as $row1)
        											{ 
        											?>
        											<option value="<?php echo $row1->vehicle_id; ?>"><?php echo $row1->vehicle_name; ?></option>
        											<?php	 
        											}
        										?>
        									</select>
        									<input type="hidden" class="form-control num"  name="vehicle_name" id="vehicle_name" >
											
											
										</div>
									</div>
								</div>
                                <br>
    
							</div>
							<div class="form-group row">
								<div class="col-sm-3">
									<label class="col-form-label">Sacn Count</label>
									<!--<input type="text" name="scan_count" id="scan_count" ng-model='scount' class="form-control" readonly>-->
									<input type="text" name="scan_count" id="scan_count" class="form-control" readonly>
								</div>
								<div class="col-sm-3">
								</div>
								<div class="col-sm-3">
								</div>
								<div class="col-sm-3">
									<label class="col-form-label">Scan</label>
									<input type="text" name="product_scan" id="product_scan"  ng-model='barcode' class="form-control" autofocus >
									<!--<input type="text" name="product_scan" id="product_scan" class="form-control" >
									<span id='status'></span>-->
								</div>
								
							</div>
							<div class=" table-responsive">
								<table class="table table-striped table-bordered">
									<thead>
										<tr>
											<th>Bar Code</th>
											<th>Product Name</th>
										    <th>Qty</th>
											<th>Price</th>
											<th>Tax</th>
										</tr>
									</thead>
									<tbody id="table_data">
										
									</tbody>
								</table>
							</div>
							
				<div class="">
						<div class="text_increment">
							<div>
								<div class="row">
									<div class="col-md-3">
										<div class="form-group">
											<select name="item_name[]" id="item_names" class="form-control select2" required>
												<option value="">Select Item</option>
												<?php  foreach($items as $row)
													{
												?>
													<option value="<?php echo $row->item_name ?>"><?php echo $row->item_name ?></option>
												<?php
													} 
												?>
											</select>
											<input class="" type="hidden" name="it_name[]" id="it_names" readonly />
										
											<input class="" type="hidden" name="remarks[]" id="remarks" Placeholder="Remarks"/>
											<input class="" type="hidden" name="item_id[]" id="item_ids"  readonly />
											<input class="" type="hidden" name="cat_id[]" id="cat_ids" readonly />
											<input class="" type="hidden" name="itm_id[]" id="itm_ids" readonly />
										</div>
									</div>
									
								    <div class="col-md-1">
										<div class="form-group">
											<input class="form-control" type="text" name="uom[]" id="uoms"  readonly  placeholder="UOM" />
										</div>
									</div>
									<div class="col-md-1">
										<div class="form-group">
											<input class="form-control" type="text" name="close_stock[]"  id="close_stocks" readonly placeholder="CSTK"/>
										</div>
									</div>
									<div class="col-md-1">
										<div class="form-group">
											<input class="form-control quantity" type="text"  name="quantity[]"  id="quantitys" required placeholder="QTY" />
											
										</div>
									</div>
									<div class="col-md-1">
										<div class="form-group">
											<input class="form-control" type="text" name="price[]" id="prices" placeholder="Price"  />
											
										
										</div>
									</div>
									<div class="col-md-1">
										<div class="form-group">
										
											<input class="form-control" type="text" name="ttl_price[]" id="ttl_prices" readonly />	
										
										</div>
									</div>
									<div class="col-md-1">
										<div class="form-group">
											
											<input class="form-control" type="text" name="tax[]" id="taxs" readonly />
										
										</div>
									</div>
									<div class="col-md-1">
										<div class="form-group">
											
											<input class="form-control" type="text" name="tax_amt[]" id="tax_amts" readonly />
											
										</div>
									</div>
									<div class="col-md-1">
										<div class="form-group">
											
											<input class="form-control t_amt" type="text" name="total[]" id="totals" readonly />
											
										</div>
									</div>
								</div>
							</div>	
						</div>
					</div>
                    <div class="form-group row">
						<div class="col-sm-2">
						</div>
						<div class="col-sm-8">
						</div>
						<div class="col-sm-2">
							<input type="submit" name="submit" id="submit" class="btn btn-primary btn-md btn-block waves-effect text-center m-b-20" value="Submit" onclick="return confirm('Are you sure you want to submit this form?')">
						</div>
					</div>
							<!--<div class="form-actions text-right">
								<div class="col-md-2 mleft">
								<div class="form-group">
									
									<input class="form-control" type="hidden" name="total_amt" id="total_amt" readonly placeholder="Total Amount"/>
								</div>
							</div>
								<button type="reset" class="btn btn-warning ">
									<i class="la la-close"></i> Cancel
								</button>
								<button type="submit" class="btn btn-primary" onclick="return confirm('Are you sure you want to submit this form?')" >
									<i class="la la-check-square-o"></i> Save
								</button>
							</div>-->
						</form>	

					</div>
				</div>
				<div class="col-md-1 md-fab-wrapper plus">
				    
					<a href="javascript:void(0);" class="add_button" title="Add field"><i class="la la1 la-plus-circle"></i>
					<!--<img src="<?php //echo base_url(); ?>app-assets/images/add-icon.png" class="image_logo"/>-->
					</a>
				</div>
				<br/>
			</div>
		</div>
	</div>

</section>
<!-- // Basic form layout section end -->
        </div>
      </div>
    </div>
    <?php //require('include/theme_customizer.php');?>

   <?php 
  $footer_file=APPPATH.'views/include/footer.php';
	require($footer_file);
	?>
	

<script src="https://rawgit.com/kabachello/jQuery-Scanner-Detection/master/jquery.scannerdetection.js"></script>
<script>
	
/*var fetch = angular.module('pshipApp', ['angucomplete-alt']);

fetch.controller('productCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {

}]);*/
</script>

<script>
	$(document).ready(function () {
		$('#product_scan').focus();
	});
</script>
<script>
$(document).scannerDetection({
    
  //https://github.com/kabachello/jQuery-Scanner-Detection

    timeBeforeScanTest: 200, // wait for the next character for upto 200ms
    avgTimeByChar: 40, // it's not a barcode if a character takes longer than 100ms
  endChar: [13],
  //preventDefault: true, //this would prevent text appearing in the current input field as typed 
        onComplete: function(barcode, qty){
		$('#pscan').val (barcode);
 
        //var barcode=$('#product_scan').val ();;
		//$('#pscan').val (barcode);
        //alert(barcode);
		$.ajax({
			type :'POST',
			dataType:'json',
			data : { bcode : barcode },
			url : '<?php echo base_url(); ?>index.php/Barcode/lastScanned',
			success: function(data) {
				//alert(data.product_code);	
				//alert("Scanned");
				if(data.recipe_no)
				{
					var basic_p=data.qty*data.price;
					var tax_amt=((basic_p*data.tax)/100).toFixed(2);
					var total=(parseFloat(basic_p)+parseFloat(tax_amt)).toFixed(2);
					var html = '<tr id="tr_'+data.recipe_id+'">';
					html += '<td><input class="form-control" type="hidden" name="barcode[]" id="barcode'+data.recipe_id+'" value="'+data.barcode_no+'" readonly />'+data.barcode_no+'<input class="form-control" type="hidden" name="itm_id[]" id="itm_id'+data.recipe_id+'" value="'+data.recipe_no+'" readonly /></td>';
					html += '<td><input class="form-control" type="hidden" name="item_name[]" id="item_name'+data.recipe_id+'" value="'+data.rname+'" readonly /><input class="form-control" type="hidden" name="item_id[]" id="item_id'+data.recipe_id+'" value="'+data.recipe_id+'" readonly /><input class="form-control" type="hidden" name="close_stock[]" id="close_stock'+data.recipe_id+'" value="'+data.close_stock+'" readonly />'+data.rname+'</td>';
				
					html += '<td><input class="form-control" type="text" name="quantity[]" id="quantity'+data.recipe_id+'" value="'+data.qty+'"  />';
					html += '<td><input class="form-control" type="text" name="price[]" id="price'+data.recipe_id+'" value="'+data.price+'" readonly />';
					html += '<td><input class="form-control" type="text" name="tax[]" id="tax_'+data.recipe_id+'" value="'+data.tax+'" readonly /><input class="form-control" type="hidden" name="ttl_price[]" id="ttl_price'+data.recipe_id+'" value="'+basic_p+'" readonly /><input class="form-control" type="hidden" name="tax_amt[]" id="tax_amt'+data.recipe_id+'" value="'+tax_amt+'" readonly /><input class="form-control" type="hidden" name="total[]" id="total'+data.recipe_id+'" value="'+total+'" readonly /></td>';
					html += '</tr>';
					
					if(data.rep_prod == 1)
					{
						$('#tr_' + data.recipe_id).find("td").eq(0).html(data.barcode_no);
						$('#tr_' + data.recipe_id).find("td").eq(1).html(data.rname);
						
						$('#tr_' + data.recipe_id).find("td").eq(2).html('<input class="form-control" type="text" name="quantity[]" id="quantity'+data.recipe_id+'" value="'+data.qty+'"  />'); //data.qty '+data.qty+'
						$('#tr_' + data.recipe_id).find("td").eq(3).html(data.price);
						$('#tr_' + data.recipe_id).find("td").eq(3).html(data.tax);
						
						$('#scnprd_' + data.recipe_id).empty();
						
						$('#tr_' + data.recipe_id).append('<div class="scnprd" id="scnprd_'+data.recipe_id+'"><input class="form-control" type="hidden" name="itm_id[]" id="itm_id'+data.recipe_id+'" value="'+data.recipe_no+'" readonly /><input class="form-control" type="hidden" name="close_stock[]" id="close_stock'+data.recipe_id+'" value="'+data.close_stock+'" readonly /><input class="form-control" type="hidden" name="item_name[]" id="item_name'+data.recipe_id+'" value="'+data.rname+'" readonly /><input class="form-control" type="hidden" name="item_id[]" id="item_id'+data.recipe_id+'" value="'+data.recipe_id+'" readonly /><input class="form-control" type="hidden" name="quantity[]" id="quantity'+data.recipe_id+'" value="'+data.qty+'"  /><input class="form-control" type="hidden" name="price[]" id="price'+data.recipe_id+'" value="'+data.price+'" readonly /><input class="form-control" type="hidden" name="tax[]" id="tax_'+data.recipe_id+'" value="'+data.tax+'" readonly /><input class="form-control" type="hidden" name="ttl_price[]" id="ttl_price'+data.recipe_id+'" value="'+basic_p+'" readonly /><input class="form-control" type="hidden" name="tax_amt[]" id="tax_amt'+data.recipe_id+'" value="'+tax_amt+'" readonly /><input class="form-control" type="hidden" name="total[]" id="total'+data.recipe_id+'" value="'+total+'" readonly /><input class="form-control" type="hidden" name="barcode[]" id="barcode'+data.recipe_id+'" value="'+data.barcode_no+'" readonly /></div>');
						
					}
					else {
						$('#table_data').prepend(html);
					}
					$('#scan_count').val(data.scount);
				}
			}
		});
		$('#product_scan').val('');
		$('#product_scan').focus();
    } // main callback function 
});

/*$(document).scannerDetection({
    
  //https://github.com/kabachello/jQuery-Scanner-Detection

    timeBeforeScanTest: 200, // wait for the next character for upto 200ms
    avgTimeByChar: 40, // it's not a barcode if a character takes longer than 100ms
  endChar: [13],
  //preventDefault: true, //this would prevent text appearing in the current input field as typed 
        onComplete: function(barcode, qty){
		$('#pscan').val (barcode);*/
/*$('#product_scan').change(function() {  
            var barcode=$('#product_scan').val ();;
		//$('#pscan').val (barcode);
    //alert(barcode);
		$.ajax({
			type :'POST',
			dataType:'json',
			data : { bcode : barcode },
			url : '<?php echo base_url(); ?>index.php/Barcode/lastScanned',
			success: function(data) {
				//alert(data.product_code);	
				//alert("Scanned");
				if(data.recipe_no)
				{
					var basic_p=data.qty*data.price;
					var tax_amt=((basic_p*data.tax)/100).toFixed(2);
					var total=(parseFloat(basic_p)+parseFloat(tax_amt)).toFixed(2);
					var html = '<tr id="tr_'+data.recipe_id+'">';
					html += '<td><input class="form-control" type="hidden" name="barcode[]" id="barcode'+data.recipe_id+'" value="'+data.barcode_no+'" readonly />'+data.barcode_no+'<input class="form-control" type="hidden" name="itm_id[]" id="itm_id'+data.recipe_id+'" value="'+data.recipe_no+'" readonly /></td>';
					html += '<td><input class="form-control" type="hidden" name="item_name[]" id="item_name'+data.recipe_id+'" value="'+data.rname+'" readonly /><input class="form-control" type="hidden" name="item_id[]" id="item_id'+data.recipe_id+'" value="'+data.recipe_id+'" readonly /><input class="form-control" type="hidden" name="close_stock[]" id="close_stock'+data.recipe_id+'" value="'+data.close_stock+'" readonly />'+data.rname+'</td>';
				
					html += '<td><input class="form-control" type="text" name="quantity[]" id="quantity'+data.recipe_id+'" value="'+data.qty+'"  />';
					html += '<td><input class="form-control" type="text" name="price[]" id="price'+data.recipe_id+'" value="'+data.price+'" readonly />';
					html += '<td><input class="form-control" type="text" name="tax[]" id="tax_'+data.recipe_id+'" value="'+data.tax+'" readonly /><input class="form-control" type="hidden" name="ttl_price[]" id="ttl_price'+data.recipe_id+'" value="'+basic_p+'" readonly /><input class="form-control" type="hidden" name="tax_amt[]" id="tax_amt'+data.recipe_id+'" value="'+tax_amt+'" readonly /><input class="form-control" type="hidden" name="total[]" id="total'+data.recipe_id+'" value="'+total+'" readonly /></td>';
					html += '</tr>';
					
					if(data.rep_prod == 1)
					{
						$('#tr_' + data.recipe_id).find("td").eq(0).html(data.barcode_no);
						$('#tr_' + data.recipe_id).find("td").eq(1).html(data.rname);
						
						$('#tr_' + data.recipe_id).find("td").eq(2).html('<input class="form-control" type="text" name="quantity[]" id="quantity'+data.recipe_id+'" value="'+data.qty+'"  />'); //data.qty '+data.qty+'
						$('#tr_' + data.recipe_id).find("td").eq(3).html(data.price);
						$('#tr_' + data.recipe_id).find("td").eq(3).html(data.tax);
						
						$('#scnprd_' + data.recipe_id).empty();
						
						$('#tr_' + data.recipe_id).append('<div class="scnprd" id="scnprd_'+data.recipe_id+'"><input class="form-control" type="hidden" name="itm_id[]" id="itm_id'+data.recipe_id+'" value="'+data.recipe_no+'" readonly /><input class="form-control" type="hidden" name="close_stock[]" id="close_stock'+data.recipe_id+'" value="'+data.close_stock+'" readonly /><input class="form-control" type="hidden" name="item_name[]" id="item_name'+data.recipe_id+'" value="'+data.rname+'" readonly /><input class="form-control" type="hidden" name="item_id[]" id="item_id'+data.recipe_id+'" value="'+data.recipe_id+'" readonly /><input class="form-control" type="hidden" name="quantity[]" id="quantity'+data.recipe_id+'" value="'+data.qty+'"  /><input class="form-control" type="hidden" name="price[]" id="price'+data.recipe_id+'" value="'+data.price+'" readonly /><input class="form-control" type="hidden" name="tax[]" id="tax_'+data.recipe_id+'" value="'+data.tax+'" readonly /><input class="form-control" type="hidden" name="ttl_price[]" id="ttl_price'+data.recipe_id+'" value="'+basic_p+'" readonly /><input class="form-control" type="hidden" name="tax_amt[]" id="tax_amt'+data.recipe_id+'" value="'+tax_amt+'" readonly /><input class="form-control" type="hidden" name="total[]" id="total'+data.recipe_id+'" value="'+total+'" readonly /><input class="form-control" type="hidden" name="barcode[]" id="barcode'+data.recipe_id+'" value="'+data.barcode_no+'" readonly /></div>');
						
					}
					else {
						$('#table_data').prepend(html);
					}
					$('#scan_count').val(data.scount);
				}
			}
		});
		$('#product_scan').val('');
		$('#product_scan').focus();
    //} // main callback function 
});*/


</script>

<script type="text/javascript">
	$(window).on('beforeunload', function () {
		//$("input[type=submit], input[type=button]").prop("disabled", "disabled");
		$("input[type=submit]").prop("disabled", "disabled");
		$("#submit").css("background-color","#dcdcdc");
	});
	$('#scform').on('keyup keypress', function(e) {
	  var keyCode = e.keyCode || e.which;
	  if (keyCode === 13) { 
		e.preventDefault();
		return false;
	  }
	});
</script> 
<script type="text/javascript">
		$(document).ready(function(){
		    
			var maxField = 100; //Input fields increment limitation
			var addButton = $('.add_button'); //Add button selector
			var wrapper = $('.text_increment'); //Input field wrapper
			var x = 1; //Initial field counter is 1
			var counter = 1;
			
			//$(addButton).click(function(){ 
			$(document).on("click",".add_button",function() {  //Once add button is clicked
				if(x < maxField){ //Check maximum number of input fields
					x++; //Increment field counter
					$(wrapper).append('<div><div class="row"><div class="col-md-3"><div class="form-group"><select name="item_name[]" id="item_names'+counter+'" class="form-control select2" required><option value="">Select Item</option><?php  foreach($items as $row) { ?><option value="<?php echo $row->item_name ?>"><?php echo $row->item_name ?></option><?php } ?></select><input class="form-control" type="hidden" name="it_name[]" id="it_names'+counter+'" readonly /><input class="" type="hidden" name="remarks[]" id="remarks'+counter+'" Placeholder="Remarks"/><input class="" type="hidden" name="item_id[]" id="item_ids'+counter+'"  readonly /><input class="" type="hidden" name="cat_id[]" id="cat_ids'+counter+'" readonly /><input class="" type="hidden" name="itm_id[]" id="itm_ids'+counter+'" readonly /></div></div><div class="col-md-1"><div class="form-group"><input class="form-control" type="text" name="uom[]" id="uoms'+counter+'"  readonly  placeholder="UOM" /></div></div><div class="col-md-1"><div class="form-group"><input class="form-control" type="text" name="close_stock[]"  id="close_stocks'+counter+'" readonly placeholder="CSTK"/></div></div><div class="col-md-1"><div class="form-group"><input class="form-control quantity" type="text"  name="quantity[]"  id="quantitys'+counter+'" required placeholder="QTY" /></div></div><div class="col-md-1"><div class="form-group"><input class="form-control" type="text" name="price[]" id="prices'+counter+'" placeholder="Price" /></div></div><div class="col-md-1"><div class="form-group"><input class="form-control" type="text" name="ttl_price[]" id="ttl_prices'+counter+'" readonly /></div></div><div class="col-md-1"><div class="form-group"><input class="form-control" type="text" name="tax[]" id="taxs'+counter+'" readonly /></div></div><div class="col-md-1"><div class="form-group"><input class="form-control" type="text" name="tax_amt[]" id="tax_amts'+counter+'" readonly /></div></div><div class="col-md-1"><div class="form-group"><input class="form-control t_amt" type="text" name="total[]" id="totals'+counter+'" readonly /></div></div><div class="col-md-1 remove_button"><a href="javascript:void(0);" class="" title="Remove field"><img src="<?php echo base_url(); ?>app-assets/images/remove-icon.png" class="image_logo"/></a></div></div></div>'); 
					
				
					//alert(counter);
					//$('#main').hide();
					$(function () {
						$(".select2").select2();
						$('#quantitys' + counter).keypress(function(e) {
							var a = [];
							var k = e.which;
							for (i = 46; i < 58; i++)
							a.push(i);
							if (!($.inArray(k,a)>=0))
							e.preventDefault();
						});
					});
					
                    
					$('#item_names' + counter).change(function(){
						var id = $(this).attr('id');
						 //alert(id);
						id_length = id.length;
						if(id_length == 11) {
							counts = id.substr(-1);
							var i_name = $('#item_names'+counts).val();
							var branch_id = $('#branch_id').val();
							$.ajax({
								type :'POST',
								dataType:'json',
								data : { iname : i_name,br_id : branch_id },
								url : '<?php echo base_url();?>index.php/Issues/get_PItemDetails',
								success: function(data) {
									//alert(data.price);
																											
									$('#uoms'+counts).val(data.uom);
									$('#item_ids'+counts).val(data.item_id);
									$('#cat_ids'+counts).val(data.category_id);
									$('#prices'+counts).val(data.item_price);
									$('#taxs'+counts).val(data.item_tax);
									$('#close_stocks'+counts).val(data.stock_item);
									$('#itm_ids'+counts).val(data.itm_id);
									
								}
							});
							//$("#item_name"+ counts).attr('disabled', 'disabled');
						}
						else{
							counts = id.substr(-2);
							var i_name = $('#item_names'+counts).val();
							var branch_id = $('#branch_id').val();
							//alert(i_name);
							//alert(brname);
							$.ajax({
								type :'POST',
								dataType:'json',
								data : { iname : i_name,br_id : branch_id },
								url : '<?php echo base_url();?>index.php/Issues/get_PItemDetails',
								success: function(data) {
									//alert(data.price);
									$('#uoms'+counts).val(data.uom);
									$('#item_ids'+counts).val(data.item_id);
									$('#cat_ids'+counts).val(data.category_id);
									$('#prices'+counts).val(data.item_price);
									$('#taxs'+counts).val(data.item_tax);
									$('#close_stocks'+counts).val(data.stock_item);
									$('#itm_ids'+counts).val(data.itm_id);
								}
							});
							//$("#item_name"+ counts).attr('disabled', 'disabled');
						}
					});
						
													
					$('#quantitys'+counter).on('keyup',function() {
						var id = $(this).attr('id');
						id_length = id.length;
						if(id_length == 10) {
							counts = id.substr(-1);
							
							var qty = $('#quantitys'+ counts).val();
							var stock = $('#close_stocks'+ counts).val();
							var price = $('#prices'+ counts).val();
							var tax = $('#taxs'+ counts).val();
							/*var result = (parseFloat(qty) * parseFloat(price)).toFixed(2);
							var tax_amt = ((parseFloat(result) * parseFloat(tax)) / 100).toFixed(2);
							var total = (parseFloat(result) + parseFloat(tax_amt)).toFixed(2);*/
							
							
							var tax1 = parseFloat(tax)/100;
                			var tax2 = tax1+1;
                			var basicamt = (parseFloat(price)/tax2).toFixed(2);
                			var taxamt2 = (parseFloat(price)-parseFloat(basicamt)).toFixed(2);
                			var taxamt=(parseFloat(qty) *parseFloat(taxamt2)).toFixed(2);
                			var basic_amount=(parseFloat(qty) *parseFloat(basicamt)).toFixed(2);
                			var basic = parseFloat(qty) * parseFloat(price);
							if(parseFloat(qty) > parseFloat(stock))
							{
								var lt = 0;
								alert("you cant enter more than the stock");
								$('#quantitys'+counts).val('');
								$('#ttl_prices'+ counts).val(lt);
								$('#tax_amts'+ counts).val(lt);
								$('#totals'+ counts).val(lt);
							}
							else
							{
								if (!isNaN(basic)) {
									$('#ttl_prices'+ counts).val(basic_amount);
									$('#tax_amts'+ counts).val(taxamt);
									$('#totals'+ counts).val(basic);
								}
								var sum = 0;
								$('.t_amt').each(function() {
									sum += Number($(this).val());
								});
								$('#total_amt').val(sum.toFixed(2));
							}
						}
						else
						{
							counts = id.substr(-2);
							
							var qty = $('#quantitys'+ counts).val();
							var stock = $('#close_stocks'+ counts).val();
							var price = $('#prices'+ counts).val();
							var tax = $('#taxs'+ counts).val();
							/*var result = (parseFloat(qty) * parseFloat(price)).toFixed(2);
							var tax_amt = ((parseFloat(result) * parseFloat(tax)) / 100).toFixed(2);
							var total = (parseFloat(result) + parseFloat(tax_amt)).toFixed(2);*/
							
							
							var tax1 = parseFloat(tax)/100;
                			var tax2 = tax1+1;
                			var basicamt = (parseFloat(price)/tax2).toFixed(2);
                			var taxamt2 = (parseFloat(price)-parseFloat(basicamt)).toFixed(2);
                			var taxamt=(parseFloat(qty) *parseFloat(taxamt2)).toFixed(2);
                			var basic_amount=(parseFloat(qty) *parseFloat(basicamt)).toFixed(2);
                			var basic = parseFloat(qty) * parseFloat(price);
							if(parseFloat(qty) > parseFloat(stock))
							{
								var lt = 0;
								alert("you cant enter more than stock");
								$('#quantitys'+counts).val('');
								$('#ttl_prices'+ counts).val(lt);
								$('#tax_amts'+ counts).val(lt);
								$('#totals'+ counts).val(lt);
							}
							else
							{
								if (!isNaN(basic)) {
									$('#ttl_prices'+ counts).val(basic_amount);
									$('#tax_amts'+ counts).val(taxamt);
									$('#totals'+ counts).val(basic);
								}
								var sum = 0;
								$('.t_amt').each(function() {
									sum += Number($(this).val());
								});
								$('#total_amt').val(sum.toFixed(2));
							}
						}
					});
					
					$('#prices'+counter).on('keyup',function() {
						var id = $(this).attr('id');
						id_length = id.length;
						if(id_length == 7) {
							counts = id.substr(-1);
							
							var qty = $('#quantitys'+ counts).val();
							var stock = $('#close_stocks'+ counts).val();
							var price = $('#prices'+ counts).val();
							var tax = $('#taxs'+ counts).val();
							/*var result = (parseFloat(qty) * parseFloat(price)).toFixed(2);
							var tax_amt = ((parseFloat(result) * parseFloat(tax)) / 100).toFixed(2);
							var total = (parseFloat(result) + parseFloat(tax_amt)).toFixed(2);*/
							
							
							var tax1 = parseFloat(tax)/100;
                			var tax2 = tax1+1;
                			var basicamt = (parseFloat(price)/tax2).toFixed(2);
                			var taxamt2 = (parseFloat(price)-parseFloat(basicamt)).toFixed(2);
                			var taxamt=(parseFloat(qty) *parseFloat(taxamt2)).toFixed(2);
                			var basic_amount=(parseFloat(qty) *parseFloat(basicamt)).toFixed(2);
                			var basic = parseFloat(qty) * parseFloat(price);
							if(parseFloat(qty) > parseFloat(stock))
							{
								var lt = 0;
								alert("you cant enter more than the stock");
								$('#quantitys'+counts).val('');
								$('#ttl_prices'+ counts).val(lt);
								$('#tax_amts'+ counts).val(lt);
								$('#totals'+ counts).val(lt);
							}
							else
							{
								if (!isNaN(basic)) {
									$('#ttl_prices'+ counts).val(basic_amount);
									$('#tax_amts'+ counts).val(taxamt);
									$('#totals'+ counts).val(basic);
								}
								var sum = 0;
								$('.t_amt').each(function() {
									sum += Number($(this).val());
								});
								$('#total_amt').val(sum.toFixed(2));
							}
						}
						else
						{
							counts = id.substr(-2);
							
							var qty = $('#quantitys'+ counts).val();
							var stock = $('#close_stocks'+ counts).val();
							var price = $('#prices'+ counts).val();
							var tax = $('#taxs'+ counts).val();
							/*var result = (parseFloat(qty) * parseFloat(price)).toFixed(2);
							var tax_amt = ((parseFloat(result) * parseFloat(tax)) / 100).toFixed(2);
							var total = (parseFloat(result) + parseFloat(tax_amt)).toFixed(2);*/
							
							
							var tax1 = parseFloat(tax)/100;
                			var tax2 = tax1+1;
                			var basicamt = (parseFloat(price)/tax2).toFixed(2);
                			var taxamt2 = (parseFloat(price)-parseFloat(basicamt)).toFixed(2);
                			var taxamt=(parseFloat(qty) *parseFloat(taxamt2)).toFixed(2);
                			var basic_amount=(parseFloat(qty) *parseFloat(basicamt)).toFixed(2);
                			var basic = parseFloat(qty) * parseFloat(price);
							if(parseFloat(qty) > parseFloat(stock))
							{
								var lt = 0;
								alert("you cant enter more than stock");
								$('#quantitys'+counts).val('');
								$('#ttl_prices'+ counts).val(lt);
								$('#tax_amts'+ counts).val(lt);
								$('#totals'+ counts).val(lt);
							}
							else
							{
								if (!isNaN(basic)) {
									$('#ttl_prices'+ counts).val(basic_amount);
									$('#tax_amts'+ counts).val(taxamt);
									$('#totals'+ counts).val(basic);
								}
								var sum = 0;
								$('.t_amt').each(function() {
									sum += Number($(this).val());
								});
								$('#total_amt').val(sum.toFixed(2));
							}
						}
					});
				}
				//alert(counter);
				counter++;
			});
			$(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
				e.preventDefault();
				$(this).parent('div').remove(); //Remove field html
				x--; //Decrement field counter
				counter--;
			});
		});
	</script>
	<script>
		$("#item_names").change(function(){
			var i_name = $('#item_names').val();
			var branch_id = $('#branch_id').val();
			//alert(i_name);
			//alert(branch_id);
			$.ajax({
				type :'POST',
				dataType:'json',
				data : { iname : i_name,br_id : branch_id },
				url : '<?php echo base_url();?>index.php/Issues/get_PItemDetails',
				success: function(data) {
					
					$('#uoms').val(data.uom);
					$('#item_ids').val(data.item_id);
					$('#cat_ids').val(data.category_id);
				    $('#prices').val(data.item_price);
					$('#taxs').val(data.item_tax);
					$('#close_stocks').val(data.stock_item);
					$('#itm_ids').val(data.itm_id);
					//$('#quantity').focus();
				}
			});
			//$("#item_name").attr('disabled', 'disabled');
		});
	</script>
	<script>
		$('#quantitys').on('keyup',function() {
			var qty = $('#quantitys').val();
			var stock = $('#close_stocks').val();
			var price = $('#prices').val();
			var tax = $('#taxs').val();
			/*var result = (parseFloat(qty) * parseFloat(price)).toFixed(2);
			var tax_amt = ((parseFloat(result) * parseFloat(tax)) / 100).toFixed(2);
			var total = (parseFloat(result) + parseFloat(tax_amt)).toFixed(2);*/
			
			
			var tax1 = parseFloat(tax)/100;
			var tax2 = tax1+1;
			var basicamt = (parseFloat(price)/tax2).toFixed(2);
			var taxamt2 = (parseFloat(price)-parseFloat(basicamt)).toFixed(2);
			var taxamt=(parseFloat(qty) *parseFloat(taxamt2)).toFixed(2);
			var basic_amount=(parseFloat(qty) *parseFloat(basicamt)).toFixed(2);
			var basic = parseFloat(qty) * parseFloat(price);
			if(parseFloat(qty) > parseFloat(stock))
			{
				var lt = 0;
				alert("you cant enter more than the stock");
				$('#quantitys').val('');
				$('#ttl_prices').val(lt);
				$('#tax_amts').val(lt);
				$('#totals').val(lt);
			}
			else
			{
				if (!isNaN(basic_amount)) {
					$('#ttl_prices').val(basic_amount);
					$('#tax_amts').val(taxamt);
					$('#totals').val(basic);
				}
				var sum = 0;
				$('.t_amt').each(function() {
					sum += Number($(this).val());
				});
				$('#total_amt').val(sum.toFixed(2));
			}
		});
		
		$('#prices').on('keyup',function() {
			var qty = $('#quantitys').val();
			var stock = $('#close_stocks').val();
			var price = $('#prices').val();
			var tax = $('#taxs').val();
			/*var result = (parseFloat(qty) * parseFloat(price)).toFixed(2);
			var tax_amt = ((parseFloat(result) * parseFloat(tax)) / 100).toFixed(2);
			var total = (parseFloat(result) + parseFloat(tax_amt)).toFixed(2);*/
			
			
			var tax1 = parseFloat(tax)/100;
			var tax2 = tax1+1;
			var basicamt = (parseFloat(price)/tax2).toFixed(2);
			var taxamt2 = (parseFloat(price)-parseFloat(basicamt)).toFixed(2);
			var taxamt=(parseFloat(qty) *parseFloat(taxamt2)).toFixed(2);
			var basic_amount=(parseFloat(qty) *parseFloat(basicamt)).toFixed(2);
			var basic = parseFloat(qty) * parseFloat(price);
			if(parseFloat(qty) > parseFloat(stock))
			{
				var lt = 0;
				alert("you cant enter more than the stock");
				$('#quantitys').val('');
				$('#ttl_prices').val(lt);
				$('#tax_amts').val(lt);
				$('#totals').val(lt);
			}
			else
			{
				if (!isNaN(basic_amount)) {
					$('#ttl_prices').val(basic_amount);
					$('#tax_amts').val(taxamt);
					$('#totals').val(basic);
				}
				var sum = 0;
				$('.t_amt').each(function() {
					sum += Number($(this).val());
				});
				$('#total_amt').val(sum.toFixed(2));
			}
		});
	</script>
	<script>
		$(window).on('beforeunload', function () {
			//$("input[type=submit], input[type=button]").prop("disabled", "disabled");
			$("input[type=submit]").prop("disabled", "disabled");
			$("#submit").css("background-color","#dcdcdc");
		});
	</script>

  </body>
  <!-- END: Body-->

<!-- Mirrored from pixinvent.com/modern-admin-clean-bootstrap-4-dashboard-html-template/html/ltr/vertical-modern-menu-template/form-layout-basic.html by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Apr 2020 09:38:02 GMT -->
</html>