<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 type="text/javascript">
   $(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);
                            }  
                        },  
                    });  
                },  
                     
            });  
        }); 
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		
		
    </script>   
	<script>
	function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

    // document.body.innerHTML = printContents.fontsize(12);
     window.print();

	 if( window.print()) {
         window.location.href = "../user/viewtocktaking";
		alert(" printing...........");
    }else {

	
		      return      window.location.href = "../user/viewtocktaking";

		    // document.body.innerHTML = originalContents;

	}
}

 
	</script>
  <style type="text/css">
  
  

    #printable { display: none; }
#print{  	


    background-repeat: no-repeat;
	font-size;20px;
  
    width:100%; 


}

#sale{  	


    background-repeat: no-repeat;
  
    width:100px; height:50px;


}
    @media print
    {
    	#non-printable { display: none; }
    	#printableArea { display: block; font-size:16; width:100%; }
    }
    </style>
   	

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

  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading" id="non-printable">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
				 <span class="pull-right"> VIEW STOCK TAKING REPORT</span>
                        <a  id="more"  class="btn btn-primary" href="<?php echo base_url();?>user/viewtocktaking">Back to stock taking  List </a>
		


				 		 	<div class="pull-right"  >

<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('sortable_table')" value="print receipt!" />
</form></div>
            	</div>
            </div>
			<div class="panel-body">

			
	<div class="widget-content nopadding table_holder table-responsive" >				
				<?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;
					}
 $session_data = $this->session->userdata('logged_in');

   		
$mydate=date('Y-m-d');
$mytime=date('H:i:s');
 	 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	
	
	 				echo $this->session->flashdata('deletemsg'); 
	 				echo $this->session->flashdata('postedtime'); 

				echo $this->session->flashdata('msg'); 
								?>	
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
	<div class="col-md-12" id="non-printable">
        <?php 
		
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchallstocktakingserial", $attr);?>
            <div class="form-group">
			
                <div class="col-md-3">
                    <input class="form-control" autofocus id="searchterm" name="searchterm" placeholder="Search for product by name, code,description.." type="text" value="<?php echo set_value('searchterm'); ?>" />
                </div>
				
				
				    <div class="col-md-2">
		  		<input type="text" name="startdate" value="<?php echo set_value('startdate',$mydate); ?>" class="form-control" required placeholder="Enter from date?">

					</div>
				
				
				
				  <div class="col-md-2">
		  		<input type="text" name="closedate" value="<?php echo set_value('closedate',$mydate); ?>" class="form-control" required placeholder="Enter to date?">

					</div>
					  <div class="col-md-2">
<select class="form-control" name="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select Branch/Counter to Open--</option>

									
					<option value="Main"  >Main Store</option>
								

	
	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
					</div>
				
				
				
				
				
                <div class="col-md-3">
                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-success" value="Record" />
                    <a href="<?php echo base_url(). "user/viewtocktaking"; ?>" class="btn btn-primary">Refresh</a>
                </div>
				 
            </div>
        <?php echo form_close(); ?>

        </div>	
									
									
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
			 <?php
			 
			   if (!isset($configuration[0]['businessname'])){
			   }else{
				   ?>
			 <tr>
								
								<td colspan="12" ><center  >
								
						
									

										<?php $bussinessname=$configuration[0]['businessname']; if(isset($bussinessname)) {echo   $bussinessname; }
										
									
										
										?>
												<span id="mytitle"><b> STOCK TAKEN ON <?PHP echo $startdate ?></b>		
								
								<br>Name---------------------------Date--------------------------Signature---------------------</span>

								</center></td>
								
								
							</tr>
							 <?php
			   }
				   ?>
         <tr>
     <th>Code</th>
	      <th>Serial</th>

     <th>Product Name</th>
	
	     <th>Category</th>

		   <th>Qty</th> 
	
<th>Branch</th>
<th>Start Date</th>
<th>Close Date </th>
<th>Staff</th>
<th>Status</th>

<th>More</th>


			  </tr>
             </thead>
<?php
 
 




 if(!is_array($viewproducts)) 

 {


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

   
  	foreach ($viewproducts as $c): 
  $ttqty=$ttqty+$c->added ;




             ?>

							 
										<?php
	
                 echo form_open('user/updatestocktaking' , 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="view" value="user/viewstocktakingreporbranch?startdate=<?php if(isset($startdate)) {echo $startdate; }; ?>&branchid=<?php if(isset($branchid)) {echo $branchid; }; ?>&department=<?php if(isset($department)) {echo $department; }; ?>" class="form-control" required placeholder="Enter view">
							<input type="hidden" name="myid" value="<?php echo set_value('myid',$c->id); ?>" class="form-control" required placeholder="Enter id">

							<input type="hidden" name="branchid" value="<?php echo set_value('branchid',$c->branchid); ?>" class="form-control" required placeholder="Enter branchid">
							<input type="hidden" name="open" value="<?php echo set_value('open',$c->open); ?>" class="form-control" required placeholder="Enter qty available">
							<input type="hidden" name="code" value="<?php echo set_value('code',$c->code); ?>" class="form-control" required placeholder="Enter code">
							<input type="hidden" name="startdate" value="<?php if(isset($startdate)) {echo $startdate; }; ?>" class="form-control" required placeholder="">
							<input type="hidden" name="department" value="<?php if(isset($department)) {echo $department; }; ?>" class="form-control" required placeholder="">

             <tr>
   
              
  <td><?php echo $c->code ; ?></td>
    <td><?php echo $c->serial ; ?></td>

    <td><?php 
	 $mycode=$c->code;
	  $userid=$c->userid;
   if($mycode!=""){
	  
      $productname = $this->usermodel->geteproductbyid($mycode);
  
     echo$name=$productname[0]['name']."  ". $description=$productname[0]['description'];

	
   }else{
	    echo "No Product";  
   }
 $c->branchid;
	?>
	</td>

    <td><?php 
	
	
	if($mycode!=""){
	  
      $productname = $this->usermodel->geteproductbyid($mycode);
  
     $category=$productname[0]['category'];

	

	
	
	$mycategory = $this->usermodel->populatecategorybyowner($category);
	


if(is_array($mycategory)) {

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


}} else {
    echo 'No Category .';
}
	   }else{
	    echo "No Product";  
   }
  

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

?>
</td>
	
 
 
		  </td> 
		   <td>
		  					<input type="text" name="added" id="non-printable" value="<?php echo set_value('added',$c->added); ?>" class="form-control" required placeholder="sold adjusted qty" >

							<span id="printable"><?php echo $c->added ; ?></span>
		  </td> 
		  
		  
		  
  
 
												 
			   <td><?php
			  if($c->branchid==0){
				  echo "Main Store";
				  
			  }else{
				  
			 
								$mybranch = $this->usermodel->populateallarray('branch','id',$c->branchid);
echo$branchname=$mybranch[0]['name'];
 }
		?></td>  									 
				  <td><?php echo $c->startdate; ?></td> 											 
									 
						<td><?php echo $c->closedate; ?></td> 	

											   
			      <td><?php 
				  $myid="";
				  $updatedby=$c->updatedby;
				  if($updatedby==0){
					    $myid=$userid;
					  
				  }else{
					  $myid=$updatedby;

					  
				  }
				
		 $myuser=$this->usermodel->geteuser($myid);
			echo $myname=$myuser[0]['firstname'];
				  ?></td>  	
						<td><?php 
							$serialstatus = $this->usermodel->populateallarray('serials','serial', $c->serial);
						echo$myserialstatus=$serialstatus[0]["status"];    


						?></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($usertype=="admin"){
											
											?>
                                    <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='#myModal<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Delete
                                                </a>
                                                        </li>
									
									
                                        <li class="divider"></li>
                                        
                                     	 
                                        
                                    </ul>
											<?php
										}
										?>
                                </div>
</td>
		 
		 						
	
 <?php echo form_close();?>	
		 
		 	
			</tr>

	<?php endforeach;} ?>

             
			  
		

			  <tr border="1" background="green">
									<td colspan="2"><b>Total</b></td>
									<td colspan="2"></td>
		<td  colspan="4" style="background:#999999 ; width:100px" ><b><?php if(isset($ttqty)) {echo $ttqty;   }?></b></td>

							
</tr>

        </table>
			 	
	</div>

		
	
	
	
	
	
	
	
	
	

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

 
</div>






					<div id="myModal" 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">Delete</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to delete this item? </h3>
      </div>
      <div class="modal-footer">
	  	

     
		<?PHP
				$session_data = $this->session->userdata('adminlogged_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="serialstocktaking">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/getstocktakingbyserial?startdate=<?php echo$startdate;?>&closedate=<?php echo$closedate;?>&branchid=<?php echo$branchid;?>&companyid=<?php echo$companyid;?>">
 <input type="hidden" id="itemid1"name="itemid" class="itemid" placeholder="itemid" value=""><br>
 <button type="button" class="btn btn-success" data-dismiss="modal">No</button>
 		  	         <button type="submit" name="btn_delete" value="deletebyid" class="btn btn-danger"> Delete  </button>

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

  </div>

  </div>














