<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">
	
 <link href="<?php echo base_url(); ?>assets/select/chosen.min.css" rel="stylesheet" media="screen">
	
		   
		   		   <script src="<?php echo base_url(); ?>assets/select/chosen.jquery.min.js"></script>


 

<script type="text/javascript">
  
	 $(document).on("click", "#managebtndelete", function()
        {
          var itemid2 = $(this).data('id');
		  $("#itemid2").val(itemid2); 
		  
		  
		   
        });
				    $(function() {
<!--             $(".datepicker").datepicker(); -->
<!--             $(".uniform_on").uniform() -->;
            $(".chzn-select").chosen();
   <!--          $('.textarea').wysihtml5(); -->

        });
	
		
		
		
		 $(this).ready( function() {  
            $("#newproduct").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/productlistlookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });  
		

		
		
		
      $(this).ready( function() {  
            $("#searchterm").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/productlookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });  
		
		
		
		
		
		
		
		  $(this).ready( function() {  
            $("#toproduct").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/productlookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });  
		
		
		
		
    </script>   
 
 <div class="row">
  
   	

   	<div class="col-md-12">
	
	  <?php
  echo $this->session->flashdata('deletemsg'); 
   echo $this->session->flashdata('msg'); 

				echo $this->session->flashdata('updatemsg'); 
   $session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
	 $data['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];
	 
	 
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
  
    $deleteincoming=$this->usermodel->populatuserpermissionsdataarray('incomingstock','delete',$userid);

   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;
					}	
 $mtype=$type;

  ?>
										
		
  
		<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-right"> Move/distribute/break products</span>	
	  	  				 <a href="<?php echo base_url();?>user/viewproducts" class="btn btn-default"> Back to Products</a>
          				 <a href="<?php echo base_url();?>user/viewbulkdispatch" class="btn btn-default"> View previous bulk  dispatch </a>
	 <a  id="more" class="btn btn-info" href="<?php echo base_url();?>user/printgrn?invoice=<?php     if(isset($invoice)) {echo $invoice; } ?>&type=dispatched">  
								

                                                <i class="glyphicon glyphicon-pencil"></i>
																Print GRN
                                                </a>
									<center> <h3>   BULK DISPATCH</H3>		</center>		

				
            	</div>
            </div>
			<div class="panel-body">

							
	<div class="widget-content nopadding table_holder table-responsive" >				
	
								 <?php if(!isset($configuration[0]['businessname'])) {

				 
				 ?>
			
				

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Transfer/Move/Distribute stock</h4>
      </div>
      <div class="modal-body">
      
	  	

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

  
 


if($category=="BulkReceiving"){
					                 echo form_open('user/addbulkproductsreceiving' , array('class' => 'form-inline form-groups-bordered validate', 'enctype' => 'multipart/form-data'));

}else{
	
				                 echo form_open('user/addbulkprojecttransfer' , array('class' => 'form-inline 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="type" value="product"id="type" class="form-control" required placeholder="Enter type">
				
<input type="hidden" name="frombranch" value="<?php echo$frombranch;?>" id="frombranch" class="form-control" required placeholder="Enter type">
		 		  		<input readonly type="hidden" name="invoice" required value="<?php echo set_value('invoice',$invoice); ?>" class="form-control"  placeholder="Enter invoice or Receip tnumber">
		 		  		<input readonly type="hidden" name="status" required value="<?php echo set_value('status',$status); ?>" class="form-control"  placeholder="Enter status ">
		 		  		<input readonly type="hidden" name="category" required value="<?php echo set_value('category',$category); ?>" class="form-control"  placeholder="Enter category ">
	<input type="hidden" readonly  name="salestype" value="<?php echo set_value('salestype',$salestype); ?>"id="total3" class="form-control" required placeholder="Enter retail or wholesale here">
				<input type="hidden" name="view" value="user/bulkdispatch?invoice=<?php echo$invoice;?>&type=<?php echo$type;?> &frombranch=<?php echo$frombranch;?>&tobranch=<?php echo$tobranch;?>&status=<?php echo$status;?>&category=<?php echo$category;?>&salestype=<?php echo$salestype;?>        "id="view" class="form-control" required placeholder="Enter view">

		<input type="hidden" name="productid" value=""id="productid1" class="form-control" required placeholder="Enter productid">
		<input type="hidden" name="page" value=""id="page" class="form-control" required placeholder="Enter bookid">
<input type="hidden" name="mytype" value="shop"id="mytype" class="form-control" required placeholder="Enter type">




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

  














  <div class="form-group">
    <label for="inputcode" class="col-sm-2 control-label"> Product name</label>
    <div class="col-sm-4">
	

		                    <input class="form-control" id="searchterm"  autofocus name="code" placeholder="Search for product by name, code,description.." type="text" value="<?php echo set_value('code'); ?>" />

		
	
		
		
		
		
	</div>
  </div>
    <?php

  if($mtype=="Movement"){
  ?>
	  
		<div class="form-group">
    <label for="inputtoproduct" class="col-sm-2 control-label"> To which Product?</label>
    <div class="col-sm-4">
	

				                    <input class="form-control" id="toproduct"  autofocus name="toproduct" placeholder="Search for product by name, code,description.." type="text" value="<?php echo set_value('toproduct'); ?>" />

		
	
		
		
		
		
	</div>
  </div>
<?php
  }
  ?>
  	<div class="form-group">
    <label for="inputtotal" class="col-sm-2 control-label">	Total qty </label>
    <div class="col-sm-4">
	    <?php

  if($mtype=="Movement"){
  ?>
 		  		<input type="text"   name="total" value="<?php echo set_value('total',0); ?>"id="total3" class="form-control" required placeholder="Enter total/Factor">

    <?php
  }else{
	  ?>  
	  		<input type="text"   name="total" value="<?php echo set_value('total',1); ?>"id="total3" class="form-control" required placeholder="Enter total/Factor">

  <?php	  
  }
	  ?> 	 
				
		<span class="text-danger"><?php echo form_error('total'); ?>
		
		</span>
	</div>
  </div>
  
  
  
     <?php

  if($mtype=="Transfer"){
  ?>
	  
	<div class="form-group" STYLE="display:none"">
    <label for="inpubuyingprice" class="col-sm-3 control-label">Get AVG 

	
	</label>
    <div class="col-sm-3">
	
		 	<select class="form-contro1" name="compare" required>
	
	<option value="Yes"  >Yes</option>
	<option value="No" selected="selected"  >No</option>

	

</select>



	</div>
  </div>
  
    <?php

  }
  
 // echo"----". $frombranch;
  ?>
   
	</div>
	<div class="col-md-12">
	
  



<div class="form-group">
    <label for="inputbranch" class="col-sm-3 control-label">	Branch </label>

    <div class="col-sm-3">
	<select class="form-control" name="from"   required >


	
	<?php 

			
			if($frombranch=="Main"){
				?>
			 	<option value="Main" selected="selected" >Main Store</option>

				<?php
				
			}else{
					 $branch= $this->usermodel->populateall('branch','id',$frombranch);



if(is_array($branch)) {

   foreach($branch as $branchrow){

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



	<?php

}} else {
    echo 'No branch available.';
}
	
	}
	?>
				 	<option value="Main"  >Main Store</option>

	<?php

					 $branch= $this->usermodel->populateall('branch','companyid',$companyid);



if(is_array($branch)) {

   foreach($branch as $branchrow){

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



	<?php

}} else {
    echo 'No branch available.';
}
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('from'); ?>

	</div>
  </div>



   
	  <div class="form-group">
 <div class="col-sm-4">
   To?
	

	 
	
			  		<input type="text" readonly  name="category" value="<?php echo set_value('category',$category); ?>"id="total3" class="form-control" required placeholder="Enter category">



		
	</div>
	</div>
	
	
		
				  		<input type="hidden" readonly  name="tobranch" value="<?php echo set_value('tobranch',$tobranch); ?>"id="total3" class="form-control"  placeholder="Enter branch">

	
		

  
  	<div class="form-group">
   
	
		  		<input type="text" readonly  name="type" value="<?php echo set_value('type',$type); ?>"id="total3" class="form-control" required placeholder="Enter type">
		         <button type="submit"  value="stock" name="btn_movestockinbulk" class="btn btn-info"> Post Now  </button>

  </div>

  	</div>









	
  
  
  
  
  

  
  
  					<?php echo form_close();?>
			
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	 </div>
	 			<?php
								 
				 }
							?>
		

  

  						
	<div class="widget-content nopadding table_holder table-responsive" >				
	
									
									
				<table class="tablesorter table table-bordered  table-hover" id="printableArea">			

             <thead>
			 <?php if(isset($configuration[0]['businessname'])) {

				 
				 ?>
			   <tr>
								
								<td colspan="16" ><center  >
								
						
									

										<?php

										$bussinessname=$configuration[0]['businessname']; if(isset($bussinessname)) {echo   $bussinessname; }
										
									
			
										
										?>
												<span id="mytitle"></br><b> Stock movement report between   <?PHP echo $finalfromdate ?> and <?PHP echo $finaltodate ?></b>		
								
								<br>Name----------------------Date--------------------Signature----------------</span>

								</center></td>
								
								
							</tr>
							<?php
								 
				 }
							?>
         <tr>
       <th>Invoice /P.O No</th>
	        <th>Code</th>

     <th>Name</th>
	       <th>Added</th>
		   		<?php
										if($usertype=="admin"){
											
											?>
		     <th>Before</th>
		 	     <th>After</th>
		 	   
				 		 	     <th>S.Price</th>
				 		 	     <th>TT S.price</th>
								 
								  <th>B.Price</th>
				 		 	     <th>TT 	B.price</th>


		
			<?php
										}
											
											?>
	     <th>From</th>
		  <th>To</th>
		    <th>Category</th>
		 <th>Added Date</th>
		 	 <th>Supplier</th>
<th>Added by</th>
	<th>More</th>

                 </tr>
             </thead>
<?php

 if(!is_array($viewincomingstock)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='1'>";
    
       echo '<div class="alert alert-warning text-center">There no records found..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  $myqty=0;
      $totalamount=0;

  	foreach ($viewincomingstock as $c): 

		 		    $totalamount= $totalamount+($c->buyingprice*$c->total ) ;


             ?>



             <tr>
                
            <?php 
$id=$c->id;
$myqty=$myqty+$c->total;

?>
    <td><?php if($c->invoice_number !=""){
		
		echo$c->invoice_number;
	}else{
			echo"Internal";
		
	}
	; ?></td>
	
	    <td><?php 
			if($c->serial !=""){
		
		echo $c->serial."<br>:";
	}
		echo $c->item_id ;
		
		
	
		
		
		?></td>

                 <td><?php 
	$itemid=$c->item_id;
	
	$mycategory = $this->usermodel->populateall('products','code', $itemid);
	


if(is_array($mycategory)) {

   foreach($mycategory as $mycategoryrow){
		echo $mycategoryrow->name." (" .$mycategoryrow->description.")";


}} else {
    echo 'No Product .';
}
	
?>
</td>

 
    <td><?php echo $c->total ; ?></td>
			<?php
										if($usertype=="admin"){
											
											?>
	    <td><?php echo $c->item_id1 ; ?></td>
		    <td><?php echo $c->balance ; ?></td>

		
			    <td><?php echo $c->sellingprice ; ?></td>
				
							    <td><?php echo $c->sellingprice*$c->total  ; ?></td>
		<?php
										}
											
					?>
	
 <td><?php echo $c->buyingprice ; ?></td>
				
							    <td><?php echo $c->buyingprice*$c->total  ; ?></td>


		
	
	
	<td>
												 
	<?php 
					// $branch="";
					 $stockfrom=$c->stockfrom;

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



if(is_array($branchfrom)) {

   foreach($branchfrom as $branchfromrow){

   echo $branchfromrow->name;
 
 
}} else {
    echo $stockfrom;
}
	
?>
												 
	 </td>											 
			
	 <td>
												 
	<?php 
					// $branch="";
					
					 
					 
					 if($c->category=="Project"){
						 
						  $type=$c->projectid;
						 $productname = $this->usermodel->populateallarray('projects','id', $type);
	
									 
				$name=$productname[0]['name']; 
						 
						 
						 
						 
						 
						 
					 }else  if($c->category=="Customer"){
						  $type=$c->projectid;
						 $productname = $this->usermodel->populateallarray('people','id', $type);
	
									 
				$name=$productname[0]['company']. "" .$productname[0]['firstname']; 
						 
						 
					 }else{
					 $productname = $this->usermodel->populateallarray('branch','id', $c->stockto);

						 				$name=$productname[0]['name']; 

						 
					 }

					 $branchtype= $this->usermodel->populateall('branch','id',$type);


    echo $name;

	
?>
												 
	 </td>											 
			
	
	
	 <td>
												 
	<?php 
					echo$c->category;

	
?>
												 
	 </td>
	
	
	
	
	
	 <td><?php echo $c->date ; ?></td>
	 
		 
		  <td><?php 
		  
		  
		  
		  
		  
		  $allstocks = $this->usermodel->getstockbyinvoice($c->invoice_number);
						 $mysupplier=$allstocks[0]['supplier'];
if($mysupplier !=""){
$supliers=$this->usermodel->geteuser($mysupplier);

if($supliers[0]['company']!=""){
	   echo $supliers[0]['company'];
}else{
   echo $supliers[0]['firstname'];	
}

   
   
   
   
   
}else{
	
 echo "Internal ";	




}
		  
		  
		  

?>
</td>
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
	 <td><?php  $userids= $c->userid ;

$myuser=$this->usermodel->geteuser($userids);
   echo $myname=$myuser[0]['firstname'];

  ?></td>
	 	 <td> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">
                                        More <span class="caret"></span>
                                    </button>
									<?php
										if($deleteincoming==true){
											
											?>
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                      
										
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete"		 data-id='<?php echo  $c->id;?>'    data-toggle='modal' data-target='#deleteModal<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Delete
                                                </a>
                                                        </li>
									
									
                                        <li class="divider"></li>
                                        
                                        <!-- teacher DELETION LINK -->
                                        
                                    </ul>
											<?php
										}
										?>
                                </div>
</td>
		 
             </tr>

	<?php endforeach;} ?>

            
 								<tr border="1" background="green">
									<td colspan="2"><b>Total Quantity</b></td>

									<td  colspan="6"><b><?php if(isset($myqty)) {echo $myqty;   }?></b> </td>
																											<td><b><?php if(isset($totalamount)) { echo formatMoney($totalamount , true);  }?></b> </td>


	<td colspan="3"></td>								
</tr>
	
        </table>

        </div>
  
  
  
  
  
  
  
  
  






							
</div>	

	
					

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

 
</div>



















