<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-ui.min.js"></script>
	 <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 myitemid = $(this).data('id');
		  $("#myitemid").val(myitemid); 
		  
		  
		   
        });
		
			$(this).ready( function() {  
            $("#supplier").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/customerlookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
		    $(function() {
<!--             $(".datepicker").datepicker(); -->
<!--             $(".uniform_on").uniform() -->;
            $(".chzn-select").chosen();
   <!--          $('.textarea').wysihtml5(); -->

        });
	
		
      $(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);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });  
		
		
        </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['branchid'] = $session_data['branchid'];
	 $mybranchid = $data['branchid'];
	 
	 
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
  $deleteaction=$this->usermodel->populatuserpermissionsdataarray('products','delete',$userid);
   $updateaction=$this->usermodel->populatuserpermissionsdataarray('productlist','changeserialstatus',$userid);
  $viewbprice=$this->usermodel->populatuserpermissionsdataarray('productlist','viewbprice',$userid);




   $editserialbranch=$this->usermodel->populatuserpermissionsdataarray('productlist','changeserialstatus',$userid);

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


  ?>

  
		<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"> View Save products for printing</span>
				 <!--	 <a data-toggle='modal' data-target='#addModal' class="btn btn-default">View /Download label</a>
				 	 <a data-toggle='modal' data-target='#uploadserialModel' class="btn btn-default">Upload label </a>

	  -->
			
                 				    				 <a href="<?php echo base_url();?>user/viewproductlist" class="btn btn-primary"> Back to stocklist </a></br>
				 			 <a href="<?php echo base_url();?>user/clearlables?branchid=<?php echo $branchid;  ?>" class="btn btn-danger">Clear My lables </a></br>

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

							<div class="col-md-12">
        <?php 
		
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/savebulklabels", $attr);?>
            <div class="form-group">
				   <div class="col-md-2">
		                   Product Name: <input class="form-control" id="searchterm"  autofocus name="code" placeholder="Search for product by Serial No,name, code.." type="text" value="<?php echo set_value('searchterm'); ?>" />
	
	
                </div>
                <div class="col-md-4">
					Alternative Name:
		<select class="chzn-select" name="newproduct" style="width:100%" >
	
	<option value=""   selected="selected">---Select  product-</option>

	
	<?php 
	
$main = $this->usermodel->populateall('products','id > ',0,'companyid',$companyid);

if(is_array($main)) {

   foreach($main as $mainrow){
											// $myproducts = $this->usermodel->populateallarray('productlist','code', $childrow->code);

   //echo $courserow->coursename;
    ?>
					<option  value="<?=  $mainrow->code;   ?>"><?= $mainrow->code." ".  $mainrow->name."  ".$mainrow->sellingprice;  ?></option>



	<?php

}} else {
	

	
}





	
?>
</select>
		
                </div>
			
				
				
				
				
				
				
				
				 <div class="col-md-2">
				 
				 
		<select class="form-control"name="branch"  required id="branch" >
	
	<option value=""  >-Select branch-</option>
<option value="Main"  >-Main Store-</option>

   <?php
 //$branchid= $c->branch;

 

	     $thiscompany=$this->usermodel->populateall('branch','id',$mybranchid);



if(is_array($thiscompany)) {

   foreach($thiscompany as $thiscompanyrow){

    ?>
					<option  selected value="<?=  $thiscompanyrow->id;   ?>"><?=  $thiscompanyrow->name; ?></option>

   
    <?php

}} else {
	
}

	
 ?>
<?php 



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


if(is_array($mycompany)) {

   foreach($mycompany as $mycompanyrow){

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




	<?php

}} else {
    echo 'No Branch.';
}
	
?>

</select>		
				 
				 </div>
                <div class="col-md-2">
                    <input id="btn_lables" name="btn_savelabels" type="submit" class="btn btn-primary" value="SAVE PRODUCT" />
                    <a href="<?php echo base_url(). "user/viewbulklables"; ?>" class="btn btn-default">Refresh</a>


				</div>
				 <div class="col-md-2">
				 			 <a href="<?php echo base_url();?>user/generatebulklabels?branchid=<?php echo $branchid;  ?>" class="btn btn-primary"> Print Bulk labels </a></br>

				 
</div>            </div>
        <?php echo form_close(); ?>

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

								
			<thead>
								<tr>
								<th>#</th>

								<th>Code</th>
								<th>Item Name</th>
											<th>Short Name</th>
									<th>S Price</th>
									<th>Branch</th>
									<th>User</th>

						
									<td>More</td>
								</tr>
								
								
								
								
							
							
	
								
								

						</thead>
						<?php
					
					
				
 if(!is_array($viewserials)) {
	  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
 
 
 
 
 
 $mycount=count($viewserials);
 $ttbprice=0;
  $ttsprice=0;
  	   $i=0;
	   
	
  	foreach ($viewserials as $c){
 											 
			  $i++;

  $ttbprice= $c->buyingprice;
  $ttsprice=  $c->sellingprice;


             ?>
			 
 						<?php
					
		//$serial = $userid.time();
                 echo form_open('user/updatelables' , 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;?>		
 
				                    <tbody >
									
										 
										
											<tr>
											 <td>
											
	 <?php
	   echo $i;
			$myinvoice=		$c->invoice;						
	   
	   ?>
	    </td> <td>
  	<input type="hidden" readonly name="code" style ="width:50px" id="code" value="<?php echo set_value('code',$c->code); ?>" class="form-control2"  placeholder="code" >
	<?php echo $c->code; ?>

	
  </td>
			 <td>
			 

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


  

  </td>
  								
				 <td>
			 

   	<input type="text" required readonly name="description" id="description" value="<?php echo set_value('description',$c->description); ?>" class="form-control"  placeholder="eneter product code" >


  

  </td>
  												    
  

												
						<td>


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

		<input type="hidden" name="mydate" id="mydate" value="<?php echo set_value('mydate',$c->createdate); ?>" class="form-control" required placeholder="entry date" >

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

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

					 <input type="hidden" name="view" value="user/viewserialnumbers" id="view" class="form-control" required placeholder="Enter view">

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






	<td>
													
													
													



												

	
	
		<select class="form-control"name="branch" id="branch" >
	
	<option value=""  >---Select branch/counter---</option>
<option value="Main"  >---Main Store---</option>

   <?php
 $branchid= $c->branch;
 if($branchid=="Main"){
	
    ?>
					<option  selected="selected" value="<?=  $branchid;   ?>">Main Store</option>

   
    <?php 
	 
	 
	 
 }else{
	 
 

	     $thiscompany=$this->usermodel->populateall('branch','id',$branchid);



if(is_array($thiscompany)) {

   foreach($thiscompany as $thiscompanyrow){

    ?>
					<option  selected="selected" value="<?=  $thiscompanyrow->id;   ?>"><?=  $thiscompanyrow->name; ?></option>

   
    <?php

}} else {
	
}

	}
 ?>


		<?php 



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


if(is_array($mycompany)) {

   foreach($mycompany as $mycompanyrow){

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




	<?php

}} else {
    echo 'No Branch.';
}
	
?>
</select>		
	
	









												
													</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-default btn-sm dropdown-toggle" data-toggle="dropdown">
                                        More <span class="caret"></span>
                                    </button>
								
                                    <ul class="dropdown-menu dropdown-default pull-right" role="menu">
                                        
                                      
													
													<?php
										 if( $deleteaction==true){
											
											?>	
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete"		 data-id='<?php echo  $c->id;?>'    data-toggle='modal' data-target='#myDelete<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Cancel
                                                </a>
                                                        </li>
									<?php
										}
										?>
											                                       <li class="divider"></li>

													<?php
				if( $editserialbranch==true)  {
											
											?>
                                        
											<li> 
<button type="submit"  value="update" name="btn_updateserials" class="btn btn-primary"> Update </button>

                                                        </li>  
<?php
										}
										?>														
                                    </ul>
											
                                </div>
</td>
       

 </tr>
 				
          <?php echo form_close();?>	

 <?php 
										 }?>
										


								
				 
				 <?php }?>	
				 
			
									</tbody>
									
									
					</table>
						 <div class="col-md-12 text-center">   <?php   if(isset($links)) {echo $links; } ?>

	<span style="color:red; font-size:20px"><?php   if(isset($total_rows)) {echo $total_rows. "   labels  in the system. " ; } ?>    </span>

        
        </div>
				</div>	
			</div>			
					
					
					
					
					
					
					
					
					
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
		
		
		
		
		
			
	<div id="uploadserialModel" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Please Upload correct foramt</h4>
		
      </div>
      <div class="modal-body">
       <a href="<?php echo base_url();?>downloads/serialno.xlsx" class="btn btn-default">Download serial No template </a>	 

	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');
		  $new_date=date("Y-m-d H:i:00");		



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/uploadoldserialnumbers' , 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="type" value="product"id="type" class="form-control" required placeholder="Enter type">
				<input type="hidden" name="view" value="user/viewserialnumbers"id="view" class="form-control" required placeholder="Enter view">
	
	
	<div class="form-group">
    <label for="inputsurname" class="col-sm-2 control-label">	CSV LIST</label>
    <div class="col-sm-10">
		
			<input type="file" name="file" width="400"  value="<?php echo set_value('file') ;?>" placeholder="Select EXCELL" class="form-control"  placeholder="Enter Surname"  >

		  		
				
		<span class="text-danger"> Upload correct format here..<?php echo form_error('file'); ?>
		
		</span>
	</div>
  </div>	
  
	  


	 <div class="form-group" style="display:none">
    <label for="inputfromdate" class="col-sm-2 control-label">qty </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="qty" id="ourqty" value="" class="form-control"  placeholder="Enter qty">
		 
				
		
		</span>
	</div>
  </div>
  
  
  <div class="form-group" style="display:none">
    <label for="inputid" class="col-sm-2 control-label">MY id</label>
    <div class="col-sm-10">
		  		<input type="text" name="id"  value="" id="ourid" class="form-control"  placeholder="Enter qty">

			
		
		</span>
	</div>
  </div><div class="form-group" style="display:none">
    <label for="inputsalesid" class="col-sm-2 control-label">salesid</label>
    <div class="col-sm-10">
		  		<input type="text" name="salesid" value="" id="oursalesid" class="form-control"  placeholder="Enter salesid">

			
		
		</span>
	</div>
  </div>
  
  
  
	 <div class="form-group" style="display:none">
    <label for="inputcode" class="col-sm-2 control-label">code </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="code" value=""   id="ourcode" class="form-control"  placeholder="Enter code">
		 
				
		
		</span>
	</div>
  </div>
  
  
  
  
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="serial" name="btn_uploadoldserials" class="btn btn-default">Upload Existing Serial No  </button>

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

    

				</div>

		</div>
	    </div>
    </div>
	
	
		
			
	
<div id="addModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

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

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewserialkreport' , 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;?>




  <div class="form-group">
    <label for="inputbranchname" class="col-sm-2 control-label">Counter</label>
    <div class="col-sm-10">
	 
		<select class="form-control"name="branchname" id="branchname" >
	
	<option value=""  >-Select branch-</option>
<option value="Main"  >-Main Store-</option>
<option value="all" selected="selected" >-All Branches-</option>


   <?php
 //$branchid= $c->branch;

 

	     $thiscompany=$this->usermodel->populateall('branch','id',$mybranchid);



if(is_array($thiscompany)) {

   foreach($thiscompany as $thiscompanyrow){

    ?>
					<option   value="<?=  $thiscompanyrow->id;   ?>"><?=  $thiscompanyrow->name; ?></option>

   
    <?php

}} else {
	
}

	
 ?>


		<?php 



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


if(is_array($mycompany)) {

   foreach($mycompany as $mycompanyrow){

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




	<?php

}} else {
    echo 'No Branch.';
}
	
?>
</select>		
		
	</div>
  </div>

  
  
  
  

  
  
  
  
    
     <div class="form-group">
    <label for="inputtype" class="col-sm-2 control-label">Action type</label>
    <div class="col-sm-10">
	<select class="form-control" name="type" required>
	<option  value=""  >---Select option--</option>
	<!--
	<option value="view" selected="selected" >I want to view stocks</option>
		<option value="viewall" selected="selected" >I want to view all counters</option>
		
		-->

<option value="download" selected="selected">I want to download Serial</option>

	
</select>
		
						<span class="text-danger"><?php echo form_error('type'); ?>

	</div>
  </div>
   

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="serial" name="btn_serialreport" class="btn btn-default"> View /Download Serial Number  </button>

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

    

				</div>

		</div>
	    </div>
    </div>	
	
	
	
	
	
	
	   
			<div id="myDelete" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Cancel</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to cancel this item? </h3>
      </div>
      <div class="modal-footer">
	  	

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

		
                 echo form_open('user/deletebyid' , array('class' => 'form-horizontal ', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
 <input type="hidden" id="table"name="table" class="table" placeholder="view" value="labels">


 <input type="hidden" name="view" value="user/viewbulklables" id="view" class="form-control" required placeholder="Enter view">

 <input type="hidden" id="myitemid" name="itemid" class="itemid" placeholder="itemid" value=""><br>
 <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
 		  	         <button type="submit" name="btn_delete" value="deletebyid" class="btn btn-danger"> Cancel Now  </button>

	<?php echo form_close();?>
      </div>
    </div>

  </div>

  </div>	



		
  

 
</div>


















