<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>


	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/viewproductlist";
		alert(" printing...........");
    }else {

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

		    // document.body.innerHTML = originalContents;

	}
}






  $(this).ready( function() {  
            $("#searchterm").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/branchlookup", 
					// 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);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });  
		






	</script>

         <script type="text/javascript">
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
			 
											
		
				  $(document).on("click", "#editbtn", function()
        {
          var mycategoryid = $(this).data('id');
		  $("#mycategoryid").val(mycategoryid); 
		      var code = $(this).data('code');
		   $("#code").val(code);
		      var name = $(this).data('name');
		   $("#name").val(name);
  var sold = $(this).data('sold');
		   $("#sold").val(sold); 
		    var open = $(this).data('open');
		   $("#open").val(open); 
		    var added = $(this).data('added');
		   $("#added").val(added); 
		    var total = $(this).data('total');
		   $("#total").val(total); 
		    var balance = $(this).data('balance');
		   $("#balance").val(balance); 
		    var price = $(this).data('price');
		   $("#price").val(price); 
		    var totalamount = $(this).data('totalamount');
		   $("#totalamount").val(totalamount); 
		   
		
		     var unsold = $(this).data('unsold');
		   $("#unsold").val(unsold); 
		    var returned = $(this).data('returned');
		   $("#returned").val(returned); 
		   
		   var closedate = $(this).data('closedate');
		   $("#closedate").val(closedate); 
		  
		   
        });
		
				  $(document).on("click", "#closestock", function()
        {
          var mycategoryid = $(this).data('id');
		  $("#mycategoryid1").val(mycategoryid); 
		      var code = $(this).data('code');
		   $("#code1").val(code);
		      var name = $(this).data('name');
		   $("#name1").val(name);
  
		    var open = $(this).data('open');
		   $("#open1").val(open); 
		 
		
		    var balance = $(this).data('balance');
		   $("#balance1").val(balance); 
		    var price = $(this).data('price');
		   $("#price1").val(price); 
		 
		   
		
		   var closedate = $(this).data('closedate');
		   $("#closedate1").val(closedate); 
		  
		   
        });
		
		
    </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="row">
  
   	

   	<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>
                        <a  id="more"  class="btn btn-default" href="<?php echo base_url();?>user/viewproductlist">Back to Stocklist   </a>
		  <a  id="more"  class="btn btn-default" href="<?php echo base_url();?>user/viewopeningstock">Refresh </a>
 	 <a data-toggle='modal' data-target='#opentockModal' class="btn btn-default">Open stock </a>
		 	 	  	 <a data-toggle='modal' data-target='#closesingtockModal' class="btn btn-default">Enter Closing stock </a>

	  	 <a data-toggle='modal' data-target='#closestockModal' class="btn btn-default">Close stock </a>


	  	 <a data-toggle='modal' data-target='#downloadModal' class="btn btn-default">Download Report </a>
		 						 <a data-toggle='modal' data-target='#IncomingModal' class="btn btn-default">Open/Closing Report</a>

                        <a  id="more"  class="btn btn-default" href="<?php echo base_url();?>user/viewtocktaking">View Stock taking    </a>


								 <a data-toggle='modal' data-target='#openlinkModal' class="btn btn-primary">Automatic Open & close stock link </a>

				 		 	<div class="pull-right"  >

<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-default"  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['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	
	 $updatestock=$this->usermodel->populatuserpermissionsdataarray('productlist','updatestock',$userid);
	 				echo $this->session->flashdata('deletemsg'); 

				echo $this->session->flashdata('msg'); 
								?>	
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
	<div class="col-md-12">
					 <center> <b>Opening/Closing stockshit</b></center><br>

        <?php 
		
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchallopenclosestock", $attr);?>
            <div class="form-group">
			
                <div class="col-md-3">
                    <input class="form-control" 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-1">
<select class="form-control" name="daterange"  id="daterange" required>
	
	

									
					<option value="all"  >-All</option>
									<option value="Specific"  selected>--Specific-</option>


	
	
</select>
					</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-1">
<select class="form-control" name="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select Branch/Counter to Open--</option>

									
								

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


							


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-2">
                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-default" value="Search" />
                    <a href="<?php echo base_url(). "user/viewopeningstock"; ?>" class="btn btn-default">Refresh</a>
                </div>
				 
            </div>
        <?php echo form_close(); ?>

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

             <thead>
         <tr>
     <th>Code</th>
     <th>Item Name</th>
	

	 <th>Open</th>
		   <th>Added</th> 
		   <th>Total</th> 
		   	<th>Sold</th>
		   <th>Cl.Stock </th>
	




<th>Price </th>

<th>Total </br>Amount</th>
<th>Profit</th>

<th>Branch</th>
<th>Staff</th>
<th>Open Date</th>
<th>Close Date</th>
<th>Shift</th>

<th>Update</th>
			  </tr>
             </thead>
<?php
 
 




 if(!is_array($viewproducts)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='12'>";
    
       echo '<div class="alert alert-warning text-center">There no records found..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  
  $totalsales=0;
   	$myproductname="";
  	foreach ($viewproducts as $c): 

		


             ?>



             <tr>
                
            <?php 
$id=$c->id;
$myaty="0";
$myaty=$c->open ;
$totalsales=$totalsales+$c->totalamount;

?>

              
  <td><?php echo $c->code ; ?></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'];

		$myproductname=$name;

   }else{
	   		$myproductname="No name";

	    echo "No Product";  
   }
  
	?>
	</td>

    
	
  <td><?php echo $c->open ; ?></td>
          <td><?php echo $c->added ; ?></td> 
		  
      <td><?php echo $c->total; ?></td>  
	   <td><?php echo $c->sold; ?></td>  
	  			  <td><?php echo $c->balance; ?></td>  

  
 
  <td><?php echo $c->price; ?></td>  
  <td><?php echo $c->totalamount; ?></td>    
			  <td><?php echo $c->totalamount; ?></td> 									 
			  <td><?php
$mybranch = $this->usermodel->populateallarray('branch','id',$c->branchid);
echo$branchname=$mybranch[0]['name'];

if($mybranch ==false){
	echo "Main";
}

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

					  
				  }
				
		 $myuser=$this->usermodel->geteuser($c->userid);
		echo $myname=$myuser[0]['firstname'];
				  ?></td>  						
						
		
				  <td><?php echo $c->startdate; ?>  </td>
				  
				  				  <td><?php echo $c->closedate; ?>  </td>
				  				  <td><?php echo $c->shift; ?>  </td>

						
				  <td>
				  
				  <?php
										if($usertype=="admin"){
											
											?>
				  
				  
				   <a class="btn btn-default editbtn" id="editbtn"  data-closedate='<?php echo  $c->startdate ;?>'  data-unsold='<?php echo  $c->closedate ;?>'data-returned='<?php echo  $c->returned ;?>' data-code='<?php echo  $c->code ;?>' data-name='<?php echo  $myproductname;?>' data-balance='<?php echo  $c->balance;?>'  data-totalamount='<?php echo  $c->totalamount;?>' data-total='<?php echo  $c->total;?>'  data-price='<?php echo  $c->price;?>'  data-sold='<?php echo  $c->sold;?>'   data-open='<?php echo  $c->open;?>' data-added='<?php echo  $c->added;?>'  data-id='<?php echo  $c->id;?>' data-toggle='modal' data-target='#editProductModel'> 	 

                                                <i class="glyphicon glyphicon-pencil"></i>
																Update
                                                </a>
										<?php
										}											
											?>
											
											
										<br>	
											
											
											
											
											
											   <a class="btn btn-default closestock" id="closestock"  data-closedate='<?php echo  $c->startdate ;?>'  data-unsold='<?php echo  $c->closedate ;?>'data-returned='<?php echo  $c->returned ;?>' data-code='<?php echo  $c->code ;?>' data-name='<?php echo  $myproductname;?>' data-balance='<?php echo  $c->balance;?>'  data-totalamount='<?php echo  $c->totalamount;?>' data-total='<?php echo  $c->total;?>'  data-price='<?php echo  $c->price;?>'  data-sold='<?php echo  $c->sold;?>'   data-open='<?php echo  $c->open;?>' data-added='<?php echo  $c->added;?>'  data-id='<?php echo  $c->id;?>' data-toggle='modal' data-target='#closeProductModel'> 	 

                                                <i class="glyphicon glyphicon-pencil"></i>
																Update closing stock
                                                </a>
				  </td> 											 
									 
												 
											   
			
	 
		 
		 	
			</tr>

	<?php endforeach;} ?>

      
		

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

							
</tr>

        </table>
			  <div class="col-md-12 text-center">    <?php echo $links; ?>
					   		<span style="color:red; font-size:20px"><?php  echo $total_rows. "  Records in the system. " ;?>    </span>

        
        </div>	
	</div>

		
	
	
	
	
	
		
	
	
<div id="editProductModel" 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">Update stock</h4>
      </div>
      <div class="modal-body">
      
	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/updatedailystock' , 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="mycategoryid" value=""id="mycategoryid" class="form-control" required placeholder="Enter mycategoryid">
		

	<div class="form-group">
    <label for="inputcode" class="col-sm-2 control-label">	Code </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="code" readonly value="<?php echo set_value('code'); ?>" id="code" class="form-control" required placeholder="Enter code">
		 
				
		<span class="text-danger"> <?php echo form_error('code'); ?>
		
		</span>
	</div>
  </div>










	<div class="form-group">
    <label for="inputname" class="col-sm-2 control-label">	Name </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="name" readonly value="<?php echo set_value('name'); ?>" id="name" class="form-control" required placeholder="Enter name">
		 
				
		<span class="text-danger"> <?php echo form_error('name'); ?>
		
		</span>
	</div>
  </div>		
	<div class="form-group">
    <label for="inputopen" class="col-sm-2 control-label">	opening </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="open" value="<?php echo set_value('open'); ?>" id="open" class="form-control" required placeholder="Enter opening">
		 
				
		<span class="text-danger"> <?php echo form_error('open'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  	<div class="form-group">
    <label for="inputunsold" class="col-sm-2 control-label">	Unsold  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="unsold" value="<?php echo set_value('unsold',0); ?>" id="unsold" class="form-control" required placeholder="Enter number of unsold products ">
		 
				
		<span class="text-danger"> Unsold items through system<?php echo form_error('unsold'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  <div class="form-group">
    <label for="inputreturned" class="col-sm-2 control-label">	Returned Items  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="returned" value="<?php echo set_value('returned',"0"); ?>" id="returned" class="form-control" required placeholder="Enter number of returned products ">
		 
				
		<span class="text-danger"> <?php echo form_error('returned'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  
  
  
  	<div class="form-group">
    <label for="inputadded" class="col-sm-2 control-label">	Added </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="added" value="<?php echo set_value('added',"0"); ?>" id="added" class="form-control" required placeholder="Enter added stock">
		 
				
		<span class="text-danger"> <?php echo form_error('added'); ?>
		
		</span>
	</div>
  </div>
  	<div class="form-group">
    <label for="inputtotal" class="col-sm-2 control-label">	total stock </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="total" value="<?php echo set_value('total'); ?>" id="total" class="form-control" required placeholder="Enter total stock">
		 
				
		<span class="text-danger"> <?php echo form_error('total'); ?>
		
		</span>
	</div>
  </div>

    	<div class="form-group">
    <label for="inputtotal" class="col-sm-2 control-label">	Sold stock </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="sold" value="<?php echo set_value('sold'); ?>" id="sold" class="form-control" required placeholder="Enter sold qty">
		 
				
		<span class="text-danger"> <?php echo form_error('sold'); ?>
		
		</span>
	</div>
  </div>
    	<div class="form-group">
    <label for="inputbalance" class="col-sm-2 control-label">	Closing Balance </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="balance" value="<?php echo set_value('balance'); ?>" id="balance" class="form-control" required placeholder="Enter closing balance">
		 
				
		<span class="text-danger"> <?php echo form_error('balance'); ?>
		
		</span>
	</div>
  </div>
       
   	<div class="form-group">
    <label for="inputprice" class="col-sm-2 control-label">	Selling price </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="price" value="<?php echo set_value('price'); ?>" id="price" class="form-control" required placeholder="Enter selling price ">
		 
				
		<span class="text-danger"> <?php echo form_error('price'); ?>
		
		</span>
	</div>
  </div>
   	<div class="form-group">
    <label for="inputtotalamount" class="col-sm-2 control-label">	Total sales</label>
    <div class="col-sm-10">
	
		  		<input type="text" readonly name="totalamount" value="<?php echo set_value('totalamount'); ?>" id="totalamount" class="form-control" required placeholder="Enter total amount ">
		 
				
		<span class="text-danger"> <?php echo form_error('totalamount'); ?>
		
		</span>
	</div>
  </div>
  
 	<div class="form-group">
    <label for="inputclosedate" class="col-sm-2 control-label">	Closing date </label>
    <div class="col-sm-10">
	
		  		<input type="date"  name="closedate" value="<?php echo set_value('closedate'); ?>" id="closedate" class="form-control" required placeholder="Enter close date ">
		 
				
		<span class="text-danger"> <?php echo form_error('closedate'); ?>
		
		</span>
	</div>
  </div>
  
  
		

	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="stock" name="btn_updatestock" class="btn btn-primary"> Update Opening/Closing stock   </button>

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

    

				</div>

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


	
	
	
	
<div id="closeProductModel" 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">Close stock by updating balance</h4>
      </div>
      <div class="modal-body">
      
	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/updatedailystockperitem' , 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="mycategoryid" value=""id="mycategoryid1" class="form-control" required placeholder="Enter mycategoryid">
		
    	<div class="form-group">
    <label for="inputbalance" class="col-sm-2 control-label">	Closing Balance </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="balance" autofocus value="" class="form-control" required placeholder="Enter closing balance">
		 
				
		<span class="text-danger"> <?php echo form_error('balance'); ?>
		
		</span>
	</div>
  </div>
  
	<div class="form-group">
    <label for="inputcode" class="col-sm-2 control-label">	Code </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="code" readonly value="<?php echo set_value('code'); ?>" id="code1" class="form-control" required placeholder="Enter code">
		 
				
		<span class="text-danger"> <?php echo form_error('code'); ?>
		
		</span>
	</div>
  </div>










	<div class="form-group">
    <label for="inputname" class="col-sm-2 control-label">	Name </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="name" readonly value="<?php echo set_value('name'); ?>" id="name1" class="form-control" required placeholder="Enter name">
		 
				
		<span class="text-danger"> <?php echo form_error('name'); ?>
		
		</span>
	</div>
  </div>		
  
  
    
  

  
  
  
  
  
	<div class="form-group">
    <label for="inputopen" class="col-sm-2 control-label">	opening </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="open" value="<?php echo set_value('open'); ?>" id="open1" class="form-control" required placeholder="Enter opening">
		 
				
		<span class="text-danger"> <?php echo form_error('open'); ?>
		
		</span>
	</div>
  </div>
  

       
   	<div class="form-group">
    <label for="inputprice" class="col-sm-2 control-label">	Selling price </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="price" value="<?php echo set_value('price'); ?>" id="price1" class="form-control" required placeholder="Enter selling price ">
		 
				
		<span class="text-danger"> <?php echo form_error('price'); ?>
		
		</span>
	</div>
  </div>
  
 	<div class="form-group">
    <label for="inputclosedate" class="col-sm-2 control-label">	Closing date </label>
    <div class="col-sm-10">
	
		  		<input type="text"  name="closedate" value="<?php echo set_value('closedate'); ?>" id="closedate1" class="form-control" required placeholder="Enter close date ">
		 
				
		<span class="text-danger"> <?php echo form_error('closedate'); ?>
		
		</span>
	</div>
  </div>
  
  
		

	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="stock" name="btn_updatestock" class="btn btn-primary"> Update Opening/Closing stock   </button>

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

    

				</div>

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




	
	
	
	
	
	
	
	
	
	
	
	
	
	<div id="opentockModal" 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">Open stock</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to open the stock? </h3>
      </div>
      <div class="modal-footer">
	  	

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

		
                 echo form_open('user/openbranchstock' , 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;?>


	
  <div class="form-group">
    <label for="inputbranchname" class="col-sm-2 control-label">Counter/branch</label>
    <div class="col-sm-10">
	<select class="form-control" name="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select one Branch/Counter to Open--</option>

					<option value="Main"  >-Main Store-</option>
					
										<option value="all"  >-All counters-</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>








  
  <div class="form-group">
    <label for="inputmaincategory" class="col-sm-2 control-label">	Main category?</label>
    <div class="col-sm-10">
	<select class="form-control" name="maincategory"   required>
	
	<option selected="selected" value="all"  >---All/Any Main Category--</option>

	
	<?php 

					 		$productcategory = $this->usermodel->populatealldatawhere('maincategory','name','ASC','companyid',$companyid);

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


							


if(is_array($productcategory)) {

   foreach($productcategory as $productcategoryrow){

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



	<?php

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

	</div>
  </div>

	








  <div class="form-group">
    <label for="inputfromdate" class="col-sm-2 control-label">Opening Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="startdate" value="<?php echo set_value('startdate',$mydate); ?>" class="form-control" required placeholder="Enter start date">
		 
						  		<input type="hidden" name="postedtime" value="<?php echo set_value('postedtime',$mytime); ?>" class="form-control" required placeholder="Enter start time">

		<span class="text-danger"> <?php echo form_error('fromdate'); ?>
	Time:	<?php echo $mytime; ?>

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



<div class="form-group">
    <label for="inputshift" class="col-sm-2 control-label">Shift Time?</label>
    <div class="col-sm-10">
	<select class="form-control" name="shift"  id="shift" required>
	
	
	<option value=""   >---Select shift</option>

			<option value="1"  selected="selected" >First time a day</option>
			<option value="2"  >Second time a day</option>
			<option value="3"  >Third time a day</option>
			<option value="4"  >Fourth time a day </option>
			<option value="5"  >Fifth time day</option>


</select>

		
	</div>
  </div>







 <input type="hidden" id="table"name="table" class="table" placeholder="view" value="products">

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

 <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="openstock" value="open" class="btn btn-info"> Open Now  </button>

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

  </div>

  </div>				
	
	
	
	
	
	
	
	<div id="downloadModal" 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">Download stock</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to download  the stock with this below closing date? </h3>
      </div>
      <div class="modal-footer">
	  	

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

		
                 echo form_open('user/downloadstock' , 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;?>


	
  <div class="form-group">
    <label for="inputbranchname" class="col-sm-2 control-label">Counter/branch</label>
    <div class="col-sm-10">
	<select class="form-control" name="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select Branch/Counter to Open--</option>

									
					<option value="all"  >All branches/Counters</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>
<div class="form-group">
    <label for="inputdepartment" class="col-sm-2 control-label">Department</label>
    <div class="col-sm-10">
	<select class="form-control" name="department"  id="department" required>
	
	
	<option value=""  >---Select department to Open--</option>

									
					<option value="all" selected="selected" >All departments</option>
								

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


							


if(is_array($maindepartment)) {

   foreach($maindepartment as $maindepartmentrow){

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



	<?php

}} else {
    echo 'No departmentrow counter available.';
}
	
?>
</select>

		
	</div>
  </div>
  
	
  <div class="form-group">
    <label for="inputclosedate" class="col-sm-2 control-label">Closing Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="closedate" value="<?php echo set_value('closedate',$mydate); ?>" class="form-control" required placeholder="Enter start date">
		 
						  		<input type="hidden" name="postedtime" value="<?php echo set_value('closedate',$mytime); ?>" class="form-control" required placeholder="Enter close date">

		<span class="text-danger"> <?php echo form_error('closedate'); ?>
	Time:	<?php echo $mytime; ?>

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







 <input type="hidden" id="table"name="table" class="table" placeholder="view" value="products">

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

 <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="downtock" value="download" class="btn btn-info"> Download Now  </button>

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

  </div>

  </div>				
	
	
	
	
	
	
<div id="openlinkModal" 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">Automatic Opening and closing stock links</h4>
      </div>
      <div class="modal-body">
      
	  	

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

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


				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/displaylinkwindow' , 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="inputbranch" class="col-sm-2 control-label">Branch/Counter</label>
    <div class="col-sm-10">
	<select class="form-control" name="branch"  required readonly id="branch" >

	
	
	<option value="" selected="selected" >---Select Branch/Counter to Open---</option>

		<option value="Main"  >Main Store</option>
		<option value="all"  >All Branches</option>

	<?php 
					 

					 $branch= $this->usermodel->populateall('branch','companyid',$companyid);
					//$branch  = $this->usermodel->populatealldatanoarray('branch','id', $branchid,'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">
    <label for="inputstockstatus" class="col-sm-2 control-label">Stock status</label>
    <div class="col-sm-10">
	<select class="form-control" name="stockstatus"  id="stockstatus" required>
	
	
	<option value=""  selected="selected" >---Select status</option>

									
					<option value="close"  >Close</option>
													<option value="open" >Open</option>


	
	
</select>

		
	</div>
  </div>


	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="link" name="displaywindow" class="btn btn-primary"> Open the Printing Window  </button>

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

    

				</div>

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






	
	
	
			<div id="IncomingModal" 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">Opening/Closing stock Report</h4>
      </div>
      <div class="modal-body">
      
	  	

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


				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewopenclosereport' , 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="inputstockstatus" class="col-sm-2 control-label">Stock status</label>
    <div class="col-sm-10">
	<select class="form-control" name="stockstatus"  id="stockstatus" required>
	
	
	<option value=""  >---Select status</option>

									
					<option value="Closed" selected="selected" >Closed</option>
													<option value="Open" >Open</option>


	
	
</select>

		
	</div>
  </div>
  
	
	
	
  <div class="form-group">
    <label for="inputbranchname" class="col-sm-2 control-label">Counter/branch</label>
    <div class="col-sm-10">
	<select class="form-control" name="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select Branch/Counter to Open--</option>

									
					<option value="all"  >All branches/Counters</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>
  
	<div class="form-group">
    <label for="inputdepartment" class="col-sm-2 control-label">Department</label>
    <div class="col-sm-10">
	<select class="form-control" name="department"  id="department" required>
	
	
	<option value=""  >---Select department to Open--</option>

									
					<option value="all" selected="selected" >All departments</option>
								

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


							


if(is_array($maindepartment)) {

   foreach($maindepartment as $maindepartmentrow){

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



	<?php

}} else {
    echo 'No departmentrow counter available.';
}
	
?>
</select>

		
	</div>
  </div>
  
	
	
	
  <div class="form-group">
    <label for="inputstartdate" class="col-sm-2 control-label">Open Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="startdate" value="<?php echo set_value('startdate',$mydate); ?>" class="form-control" required placeholder="Enter start date">
		 
				
		<span class="text-danger"> <?php echo form_error('startdate'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputclosedate" class="col-sm-2 control-label">	Close Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="closedate" value="<?php echo set_value('closedate',$mydate); ?>" class="form-control" required placeholder="Enter End date">
		 
				
		<span class="text-danger"> <?php echo form_error('closedate'); ?>
		
		</span>
	</div>
  </div>
  
  
   
<div class="form-group">
    <label for="inputshift" class="col-sm-2 control-label">Shift Time?</label>
    <div class="col-sm-10">
	<select class="form-control" name="shift"  id="shift" required>
	
	
	<option value=""   >---Select shift</option>

			<option value="1"  selected="selected" >First time a day</option>
			<option value="2"  >Second time a day</option>
			<option value="3"  >Third time a day</option>
			<option value="4"  >Fourth time a day </option>
			<option value="5"  >Fifth time day</option>


</select>

		
	</div>
  </div>	
	
	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="event" name="btn_addevent" class="btn btn-primary"> View  stock  </button>

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

    

				</div>

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

	
	
	
	
	<div id="closesingtockModal" 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">Update closing stock</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to enter close  the stock? </h3>
      </div>
      <div class="modal-footer">
	  	

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

		
                 echo form_open('user/enterclosingstock' , 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;?>







<div class="form-group">
    <label for="inputdepartment" class="col-sm-2 control-label">Department</label>
    <div class="col-sm-10">
	<select class="form-control" name="department"  id="department" required>
	
	
	<option value=""  >---Select department to Open--</option>

									
					<option value="all" selected="selected" >All departments</option>
								

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


							


if(is_array($maindepartment)) {

   foreach($maindepartment as $maindepartmentrow){

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



	<?php

}} else {
    echo 'No departmentrow counter available.';
}
	
?>
</select>

		
	</div>
  </div>





	
  <div class="form-group">
    <label for="inputbranchname" class="col-sm-2 control-label">Counter/ branch</label>
    <div class="col-sm-10">
	<select class="form-control" name="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select Branch/Counter to Open--</option>

									
					<option value="all"  >All branches/Counters</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>
  
   
   
   
   
    <div class="form-group">
    <label for="inputmethod" class="col-sm-2 control-label">Input Method</label>
    <div class="col-sm-10">
	<select class="form-control" name="method"  id="branchid" required>
	
	
	<option value=""  >---How do you want key in the closing stock--</option>

									
					<option selected="selected" value="bulk"  >Bulk(Both Cl.Stock and Added stock) </option>
					<option  value="bulkonly"  >Bulk(Closing stock)</option>

			

	
</select>

		
	</div>
  </div>
  
   
   
    <div class="form-group">
    <label for="inputaction" class="col-sm-2 control-label">Action</label>
    <div class="col-sm-10">
	<select class="form-control" name="action"  id="action" required>
	
	
	<option value=""  >---Do you  also want to update the physical  stock quantity--</option>
					<option value="No"  >No </option>

									<?php 
				 	 if( $updatestock==true){
										 ?>
										 <?php
									 }
									 ?>			
					
					<option selected="selected"  value="Yes"  >Yes</option>
	 
									
					
					

			

	
</select>

		
	</div>
  </div>
   
   
   
   
   

  <div class="form-group">
    <label for="inputfromdate" class="col-sm-2 control-label">Opening Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="startdate" value="<?php echo set_value('startdate',$mydate); ?>" class="form-control" required placeholder="Enter start date">
		 

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


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







 <input type="hidden" id="table"name="table" class="table" placeholder="view" value="products">

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

 <input type="hidden" id="itemid1"name="itemid" class="itemid" placeholder="itemid" value=""><br>
 <button type="button" class="btn btn-success" data-dismiss="modal">Cancel</button>
 		  	         <button type="submit" name="enterclosingstock" value="close" class="btn btn-info"> Next  </button>

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

  </div>

  </div>	
	
	

	<div id="closestockModal" 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">Close stock</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to close  the stock? </h3>
      </div>
      <div class="modal-footer">
	  	

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

		
                 echo form_open('user/closebranchstock' , 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;?>




  <div class="form-group">
    <label for="inputtype" class="col-sm-2 control-label">Closing method</label>
    <div class="col-sm-10">
	<select class="form-control" name="type"  id="type" required>
	
	
	<option value=""  >---Select method to use--</option>
								<option value="BothManual"  >Two Manual (Closing and added stock)</option>

									<option value="Manual"  >One Manual(Closing stock)</option>

										<option value="Automatic"  >All Automatic</option>

								

	
</select>

		
	</div>
  </div>














	
  <div class="form-group">
    <label for="inputbranchid" class="col-sm-2 control-label">Counter/branch</label>
    <div class="col-sm-10">
	<select class="form-control" name="branchid"  id="branchid" required>
	
	
	<option value="" selected="selected" >---Select Branch/Counter to Open--</option>

									
					<option value="Main"  >-Main Store-</option>
				<option value="all"  >-All counters-</option>
	

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


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>

		
	</div>
  </div>
  
  
  
  
  
  
  
  
  
  
  
  <div class="form-group">
    <label for="inputmaincategory" class="col-sm-2 control-label">	Main category?</label>
    <div class="col-sm-10">
	<select class="form-control" name="maincategory"   required>
	
	<option selected="selected" value="all"  >---All/Any Main Category--</option>

	
	<?php 

					 		$productcategory = $this->usermodel->populatealldatawhere('maincategory','name','ASC','companyid',$companyid);

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


							


if(is_array($productcategory)) {

   foreach($productcategory as $productcategoryrow){

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



	<?php

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

	</div>
  </div>

	
  
    <div class="form-group">
    <label for="inputclosedate" class="col-sm-2 control-label">Close Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="closedate" value="<?php echo set_value('closedate',$mydate); ?>" class="form-control" required placeholder="Enter close date">
		 
						  		<input type="hidden" name="postedtime" value="<?php echo set_value('postedtime',$mytime); ?>" class="form-control" required placeholder="Enter close time">

		<span class="text-danger"> <?php echo form_error('closedate'); ?>
	Time:	<?php echo $mytime; ?>

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

  <div class="form-group">
    <label for="inputfromdate" class="col-sm-2 control-label">Opening Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="startdate" value="<?php echo set_value('startdate',$mydate); ?>" class="form-control" required placeholder="Enter start date">
		 

		<span class="text-danger"> Enter the date in which the stock  was opened<?php echo form_error('fromdate'); ?>


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







 <input type="hidden" id="table"name="table" class="table" placeholder="view" value="products">

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

 <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="closestock" value="close" class="btn btn-info"> Close Now  </button>

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

  </div>

  </div>				
	

	

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

 
</div>


















