<link href="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/ui.theme.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/autocomplete.css" rel="stylesheet">
	 <script src="<?php echo base_url(); ?>assets/autocomplete/jquery.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.min.js"></script>


 
            
        <script type="text/javascript">  
        $(this).ready( function() {  
            $("#id").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/lookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });  
		
		
			
		 $(document).on("click", "#managebtndelete", function()
        {
          var transactionid = $(this).data('id');
		  $("#transactionid").val(transactionid); 
   var myid = $(this).data('myid');
		  $("#myid").val(myid); 
		   
		   
        });
		  $(function() {
<!--             $(".datepicker").datepicker(); -->
<!--             $(".uniform_on").uniform() -->;
            $(".chzn-select").chosen();
   <!--          $('.textarea').wysihtml5(); -->

        });
        </script>
	   	
 
 <div class="row">
  
   	

   	<div class="col-md-12">

  <?php

			function formatMoney($number, $fractional=false) {
						if ($fractional) {
							$number = sprintf('%.2f', $number);
						}
						while (true) {
							$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
							if ($replaced != $number) {
								$number = $replaced;
							} else {
								break;
							}
						}
						return $number;
					}
 
				echo $this->session->flashdata('msg'); 
   $session_data = $this->session->userdata('logged_in');

      $mydate=date("Y-m-d H:i:s");
 $date = Date('Y-m-d') ;
		 	 $year = Date('Y') ;
		  $month = Date('m') ;
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
    $deletebank=$this->usermodel->populatuserpermissionsdataarray('accounting','deletebank',$userid);
    $showdefaultserials=$this->usermodel->populatuserpermissionsdataarray('purchases','showdefaultserials',$userid);

	//$session_data = $this->session->userdata('logged_in');
				$session_data = $this->session->userdata('logged_in');

			$data['id'] = $session_data['id'];
         $userid = $data['id'];
		   $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];

     echo $this->session->flashdata('productmsg');
	 
	 
	  function createRandomPassword() {

		  


	$chars = time()."956323230323205436565243523535364745744523341324158009124423232023456789453242131231425325241231235325325632521321354612142545355324535523424353454645";
					  //$chars = '2342355ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-+';

	srand((double)microtime()* time());
	$i = 0;
	$pass = '' ;
	while ($i <= 6) {

		$num = rand() % 33;

		$tmp = substr($chars, $num, 1);

		$pass = $pass . $tmp;

		$i++;

	}
	return $pass;
}
	 
	 
	 
	 
	 
	 
	 

  ?>

  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
				 <span class="pull-center"> Create new serials </span>
	  
				 	  				 <a href="<?php echo base_url();?>user/viewreceivedproducts?randomitemidentifier=<?php echo $finalsalesid; ?>" class="btn btn-info"> Back </a>

				 
            	</div>
            </div>
			<div class="panel-body">
								
								
								
														<table id="register" class="table table-bordered " width="100%" >

								
			<thead>
								<tr>

								<th>Code</th>
								<th>Item Name</th>
									<th>B Price</th>
									<th>S Price</th>

								<th> Qty </th>

								<th>Main Serial</th>
								<th>Other serial</th>
								</tr>

						</thead>
						<?php
					
					
					$i=0;
					$counter=$myqty;
 if($counter < 1) {
	  echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='5'>";
    echo"There is no data found..";
    echo "</td>";
   echo "</tr>";

			 }else{

	 	$serial = createRandomPassword();

 	
					
		//$serial = $userid.time();
                 echo form_open('user/bulkproductsreceivings' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>		
		<input type="hidden" name="finalid" id="myid" value="<?php echo set_value('myid',$myid); ?>" class="form-control" required placeholder="myid" >

 		<input type="hidden" name="myqty" id="myqty" value="<?php echo set_value('myqty',$myqty); ?>" class="form-control" required placeholder="myqty" >
	<input type="hidden" name="invoice"  value="<?php echo set_value('invoice',$finalsalesid); ?>" class="form-control" required placeholder="invoice" >

 
 	<?php
 
 
 
 
 
 
 $ttbprice=0;
  $ttsprice=0;
		while ($i < $counter) {
	   $i++;

			

  $ttbprice= $ttbprice+$recaiving[0]['buyingprice'];
  $ttsprice= $ttsprice+$recaiving[0]['sellingprice'];


             ?>
				                    <tbody >
									
										 
										
											<tr>
											 <td>
  	<input type="text" readonly name="code[]" id="code" value="<?php echo set_value('code',$mycode); ?>" class="form-control"  placeholder="code" >
  </td>
			 <td><?php ; 
														

   if($mycode!=""){
	  
      $productname = $this->usermodel->populateallarray('products','code',$mycode);
  
?>

   	<input type="text" required readonly name="name[]" id="name" value="<?php echo set_value('name',$productname[0]['name']); ?>" class="form-control"  placeholder="enter product code" >

<?php
	
   }else{
	   ?>
	      	<input type="text" required readonly name="name[]" id="name" value="<?php echo set_value('name'); ?>" class="form-control"  placeholder="enter product code" >

	   
<?php
   }

  
  ?>
  	      	<input type="hidden" required readonly name="description[]" id="description" value="<?php echo set_value('description',$productname[0]['description']); ?>" class="form-control"  placeholder="enter product code" >

  </td>
  								
													    
  
  <td>
  	<input type="text"  name="buyingprice[]" id="buyingprice" value="<?php echo set_value('buyingprice',$recaiving[0]['buyingprice']); ?>" class="form-control"  placeholder="buying price" >
  </td>
												
						<td>
												<input type="hidden" name="finalsalesid[]" id="finalsalesid" value="<?php echo set_value('finalsalesid',$finalsalesid); ?>" class="form-control" required placeholder="finalsalesid" >
			<input type="hidden" name="view" value="user/viewreceivedproducts?randomitemidentifier=<?php echo $finalsalesid; ?>" class="form-control" required placeholder="Enter invoiceno">

			<input type="hidden" name="mainview" value="user/viewreceivedproducts?randomitemidentifier=<?php echo $finalsalesid; ?>" class="form-control" required placeholder="Enter invoiceno">
<input type="hidden" name="mainview2" value="user/viewserials?randomitemidentifier=<?php echo $finalsalesid; ?>&mycode=<?php echo $mycode; ?>&myqty=<?php echo $myqty; ?>&myid=<?php echo $myid; ?>status=create" class="form-control" required placeholder="Enter invoiceno">

		<input type="hidden" name="myid[]" id="myid" value="<?php echo set_value('myid',$myid); ?>" class="form-control" required placeholder="myid" >
		<input type="hidden" name="branch[]" id="branch" value="<?php echo set_value('branch',$recaiving[0]['type']); ?>" class="form-control" required placeholder="branch" >

		<input type="hidden" name="mydate[]" id="mydate" value="<?php echo set_value('mydate',$recaiving[0]['date']); ?>" class="form-control" required placeholder="entry date" >
		<input type="hidden" name="status[]" id="status" value="<?php echo set_value('status',"new"); ?>" class="form-control"  placeholder="status" >
			<input type="hidden" name="id[]" id="id" value="<?php echo set_value('id'); ?>" class="form-control" required placeholder="id" >

<input type="hidden" name="batchno[]" id="batchno" value="<?php echo set_value('batchno',1); ?>" class="form-control" required placeholder="batch" >

	
					
	
									
											
											
											
						  	<input type="text"  name="sellingprice[]" id="sellingprice" value="<?php echo set_value('sellingprice',$recaiving[0]['sellingprice']); ?>" class="form-control"  placeholder="sprice" >
					
											
											
											
											
											
</td>














													<td>
													
													
													


					<input type="text" readonly name="qty[]" id="qty" value="<?php echo set_value('qty',"1"); ?>" class="form-control" required placeholder="Qty" >

													
													</td>
			
			<td>
		
		 <?php

 if( $showdefaultserials==true){
 ?>
		<input type="text"  name="serial[]" id="serial" value="<?php echo set_value('serial',$serial+$i); ?>" class="form-control" required placeholder="serial" >


 
<?php	
}else{
	?>
		<input type="text"  name="serial[]" id="serial" value="<?php echo set_value('serial'); ?>" class="form-control" required placeholder="serial" >

	
<?php		
}
  ?>

		
</td>	
<td>
		

		
		
			<input type="text" name="otherserial[]" id="otherserial" value="<?php echo set_value('otherserial'); ?>" class="form-control"  placeholder="other serial" >


		
</td>		


		

 </tr>
 <?php 
	 }?>
										

         

								<tr>
									<th> 
	
	
  Ref Number:	</b><?php echo$finalsalesid?>   :
				</th>	
				
				
				<th>	
				
					</th>
					<th>
								<h4>Total B.PRICE: <?php if(isset($ttbprice)) {echo formatMoney($ttbprice, true); }?></H4>
							</th>
								<th>
								<h4>Total S.PRICE:   <?php if(isset($ttsprice)) {echo formatMoney($ttsprice, true); }?></H4>
							</th>
				
				
				
				
				
				<th colspan="3">			
<button type="submit"  value="bulkinsert" name="btn_bulkproductsreceiving" class="btn btn-primary"> Receive these products in bulk  </button>

								
								</th>
							
							
							</tr>
				 <?php echo form_close();?>	
				 
				 <?php }?>	
									</tbody>
									
									
					</table>
				</div>	
			</div>			
					
					
					
					
					
					
					
					
					
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    
			
			
		</div>
	    </div>
		
  

 
</div>


















