<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
  $confirminvoice=false;
  
 $deliverydate= $purchaseorder[0]['remarks'];
  
  
  if( $deliverydate=="Approved"){
	  
	  	   $confirminvoice=true;

  }else{
	  	   $confirminvoice=false;

  }
			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'];
		 
		  $data['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];
		 
		 
	 $usertype = $data['usertype'];	
    $deletebank=$this->usermodel->populatuserpermissionsdataarray('accounting','deletebank',$userid);

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

  ?>

  
		<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"> Receive dispatched products </span>
	  
				 	  				 <a href="<?php echo base_url();?>user/viewbulkdispatch?invoice=<?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>Ordered Qty</th>
								<th> Qty Received</th>
								<th>Receive Now</th>
									<th>Bal</th>
									<th>To?</th>
								<th>From?</th>

								<th>Total</th>
								</tr>

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

			 }else{
 ?>
 
 
 						<?php
					
		$batchno = $userid.time();
                 echo form_open('user/bulkdispatchorder' , 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;?>		
 
 
 
 	<?php
 
 
 
 
 
 
 $totalcost=0;
  $finaltotal=0;
  	foreach ($viewreceivings as $row){
		
	
 $itemid=$row->	item_id;
  $myid=$row->id;
   $productid=$row->id;
		 		$recaiving= $this->usermodel->populateallarray('products', 'code',$itemid);
				
			

 


             ?>
				                    <tbody >
									
										 
										
											<tr>
			 <td><?php ; 
														
   $customer=$recaiving[0]['code'];
     $producttype=$recaiving[0]['producttype'];
   if($customer!=""){
	  
      $productname = $this->usermodel->populateallarray('products','code',$itemid);
  
?>
 <a class="btn primary editbtn" id="editbtn"data-tax_included='<?php echo  $productname[0]['tax_included'];?>' data-expdate='<?php echo  $productname[0]['expdate'];?>'data-store='<?php echo  $productname[0]['store'];?>' 	 data-orderamount='<?php echo  $productname[0]['orderamount'];?>' data-supplier='<?php echo  $productname[0]['supplier'];?>'  data-category='<?php echo  $productname[0]['category'];?>'  data-buyingprice='<?php echo  $productname[0]['buyingprice'];?>' data-sellingprice='<?php echo  $productname[0]['sellingprice'];?>'data-promoprice='<?php echo  $productname[0]['promoprice'];?>'  data-wholesaleprice='<?php echo  $productname[0]['wholesaleprice'];?>' data-code='<?php echo  $productname[0]['code'];?>' data-qty='<?php echo  $productname[0]['qty'];?>'	data-description='<?php echo  $productname[0]['description'];?>' data-name='<?php echo  $productname[0]['name'];?>'	data-reorderevel='<?php echo  $productname[0]['reorderevel'];?>'  data-id='<?php echo  $productname[0]['id'];?>' data-toggle='modal' data-target='#editProductModel'> <?php echo $productname[0]['code'] ; ?> </a>	 

<?php
	
   }else{
	    echo "No Product";  
   }

  
  ?></td>
  								
													    <td><?php ; 
$receiptdescription=$configuration[0]['receiptdescription'];
							
   if($customer!=""){
	  
     // $productname = $this->usermodel->geteproductbyid($customer);
  
     echo "<b>";
     echo$name=$productname[0]['name']; if($receiptdescription=="yes"){ echo"-".$description=$productname[0]['description'];}
	 
	 
	  echo "</b>";

	
   }else{
	    echo "No Product";  
   }

  
  ?></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="itemid" id="itemid" value="<?php echo set_value('itemid',$row->id); ?>" class="form-control" required placeholder="itemid" >
							<input type="hidden" name="myview" value="user/receivedispatch?invoice=<?php echo $finalsalesid; ?>" class="form-control" required placeholder="Enter invoiceno">
							<input type="hidden" name="view" value="user/viewbulkdispatch?invoice=<?php echo $finalsalesid; ?>" class="form-control" required placeholder="Enter invoiceno">

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

																						<input type="hidden" name="code[]" id="code" value="<?php echo set_value('code',$row->item_id); ?>" class="form-control" required placeholder="myid" >
																						<input type="hidden" name="producttype[]" id="code" value="<?php echo set_value('producttype',$producttype); ?>" class="form-control" required placeholder="producttype" >
<input type="hidden" name="stockfrom[]" id="stockfrom" value="<?php echo set_value('stockfrom',$row->stockfrom); ?>" class="form-control" required placeholder="producttype" >
<input type="hidden" name="stockto[]" id="stockto" value="<?php echo set_value('stockto',$row->stockto); ?>" class="form-control" required placeholder="producttype" >

											
	
																		  		<input type="text" readonly name="qty" id="qty" value="<?php echo set_value('qty',$row->total); ?>" class="form-control" required placeholder="Qty" >
					
	
									
											
											
											
											
											
											
											
											
											
</td>














													<td>
													
													
													

	 								<input type="text" name="received" readonly id="received" value="<?php echo set_value('total',$row->qty); ?>" class="form-control" required placeholder="buying price" >



													
													</td>
													<td>
																										
														<?php


	if(($confirminvoice)) {
		 $balance=(($row->total) -($row->qty)) ;	
		  ?>
		
	<input type="text" name="total[]" id="total" value="<?php echo set_value('total',$balance); ?>" class="form-control" required placeholder="Qty Received" >
												<input type="hidden" name="buyingprice[]" id="buyingprice" value="<?php echo set_value('buyingprice',$row->buyingprice); ?>" class="form-control" required placeholder="buying price " >

	


		
	  
	 	<?php	
	  }else{

echo $row->total;
?>

												<input type="hidden" name="buyingprice[]" id="buyingprice" value="<?php echo set_value('buyingprice',$row->buyingprice); ?>" class="form-control" required placeholder="buying price " >

	 
	  
	  
	  	<?php	 
	  }


  ?>						 

													
	</td>
			<td>
		


	 	<?php	
	
	 
	  if(($confirminvoice)) {
		echo $balance=(($row->qty)-($row->total)) ;	
	  }else{

	  
	  }
	
  ?>						 



</td>	
	<td>
		



<select class="form-control" name="to[]" required>
	
	<option value=""  >---Moving products to?---</option>
	<option value="Main"   >Main Store</option>



<?php if($row->stockto=="Main"){
	?>
		<option value="Main" selected="selected"  >Main Store</option>

	<?php 
}
					 

					 $branchs= $this->usermodel->populateall('branch','id',$row->stockto);



if(is_array($branchs)) {

   foreach($branchs as $branchrows){

   //echo $courserow->coursename;
    ?>
					<option selected  value="<?=  $branchrows->id;   ?>"><?=  $branchrows->name; ?></option>



	<?php

}} else {
    echo 'No branch available.';
}
	
?>












	
	
</select>
	  
	










</td>				
			<td>
		



<?php if($row->stockfrom=="Main"){
 
	echo "Main Store";
}else{
					 

					 $branchs= $this->usermodel->populateall('branch','id',$row->stockfrom);



if(is_array($branchs)) {

   foreach($branchs as $branchrows){

   echo $branchrows->name;
   
}} else {
    echo 'No branch available.';
}
}	
?>





</td>									 
											 
											 
		 
											 
											 
											 
											 	 <td><?php 
												
												echo $totalcost=(($row->buyingprice)*($row->total)) ;
												 $finaltotal=$finaltotal+$totalcost;
												 ?></td>
				  
												  
											  
											  
											  
											  
											  
											  
											
									  
									  
							

  					

 </tr>
 <?php 
	 }?>
										

         

								<tr>
									<th colspan="3"> 
									
	<div class="form-group">
    <label for="inputdescription" class="col-sm-2 control-label">	Note/ Comment</label>
    <div class="col-sm-10">

				<textarea name="description" value="<?php echo set_value('description'); ?>"  class="form-control"  placeholder="Enter any Note/ Message regarding goods received"></textarea>
			
		<span class="text-danger"> <?php echo form_error('description'); ?>
		
		</span>
	</div>
  </div>
  Ref Number:	</b><?php echo$finalsalesid?>   :
				</th>	<th colspan="3">			
<button type="submit"  value="dispatch" name="btn_editdispatch" class="btn btn-success"> Received products in batches   </button>

								
								</th>
								<th colspan="4"><h3>Total:<?php if(isset($finaltotal)) {echo formatMoney($finaltotal, true); }?></h3>
							</th>
							
							</tr>
				 <?php echo form_close();?>	
				 
				 <?php }?>	
									</tbody>
									
									
					</table>
				</div>	
			</div>			
					
					
					
					
					
					
					
					
					
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

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

 
</div>


















