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

        <script type="text/javascript">  
		
			   $(this).ready( function() {  
            $("#product").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() {  
            $("#myproduct").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); 
		  
		  
		   
        });
		
		 $(document).on("click", "#managebtnreturn", function()
        {
          var returnid = $(this).data('id');
		  $("#returnid").val(returnid); 
		  
		     var qty = $(this).data('qty');
		  $("#qty").val(qty); 
		    var serial = $(this).data('serial');
		  $("#serial").val(serial); 
		      var status = $(this).data('status');
		  $("#status").val(status); 
		  
		  
		  
		  	  
     var invoice = $(this).data('invoice');
		  $("#invoice").val(invoice); 
		  
		  
     var details = $(this).data('details');
		  $("#details").val(details); 
		  
		     var dateleased = $(this).data('dateleased');
		  $("#dateleased").val(dateleased); 
		    var duedate = $(this).data('duedate');
		  $("#duedate").val(duedate); 
		      var amount = $(this).data('amount');
		  $("#amount").val(amount); 
		       var mode = $(this).data('mode');
		  $("#mode").val(mode); 
		
		  
		  
		  
		  
		  
		  
        });
		
		
		
		
		
		
		
		
		     	   $(this).ready( function() {  
            $("#myuser").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/customerSaleslookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
		
  
		
			   $(this).ready( function() {  
            $("#incharge").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/customerSaleslookup",  
                        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">

  
		<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"> View Leases Items  </span>
	  <a data-toggle='modal' data-target='#addModal' class="btn btn-info">Add new Leased Item </a>
				 <a data-toggle='modal' data-target='#viewuserModal' class="btn btn-default">Detailed Report   </a>
					<a data-toggle='modal' data-target='#usersummaryModal' class="btn btn-default">Summary Report   </a>
					
									 <a data-toggle='modal' data-target='#viewfastslowmovingModal' class="btn btn-default">Fast/Slow Leased Item Report   </a>

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

			
	<div class="widget-content nopadding table_holder table-responsive" >				
				<?PHP
 $mydate=date("Y-m-d H:i:s");
 //     echo $this->session->flashdata('deletemsg'); 

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;
					}
					 $finalstartdate=date("Y-m-d 00:00:00");
					  $finalendate=date("Y-m-d H:i:s");

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

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	 
	 
	 	 $smsconfig = $this->usermodel->populateallarray('smsconfig','id',$companyid);
		 		$currenttime = date('H:i');

		    $mydate=date("Y-m-d H:i:s");

  	$dateString = '2020-02-05';
 
//Last date of current month.
//echo$lastDateOfMonth = date("Y-m-t", strtotime($dateString));
		  $year=date("Y");
		  $month=date("m");
		   $day=date("d");
		   
		   
		   $subtract=$day-1;
		   $add=$day+1;
		      if ($subtract<10){
			  $subtract="0".$subtract;
		   }else{
			   $subtract=$subtract; 
		   }
		$finalstartdate="";
		$finalendate="";
		  $myfromdate=$smsconfig[0]['fromdate'];
		 $mytodate=$smsconfig[0]['todate'];
		 $starttime=$smsconfig[0]['starttime'];
		 $duetime=$smsconfig[0]['duetime'];
		
	if(($myfromdate=="Current") &&($mytodate=="Current") &&  ($currenttime>=$starttime)){
	
		  $finalstartdate=$year.'-'.$month.'-'.$day.' '. $starttime.':00';
		
		 }else if(($myfromdate=="Current") &&($mytodate=="Next") &&  ($currenttime>=$starttime)){
	
		  $finalstartdate=$year.'-'.$month.'-'.$day.' '. $starttime.':00';
		
		 }
		 
		  else if(($myfromdate=="Current") &&($mytodate=="Current") && ($currenttime<$starttime)){
					  $finalstartdate=$year.'-'.$month.'-'.$day.' '. $starttime.':00';


				
		 }
		 
		 else if(($myfromdate=="Current") &&($mytodate=="Next") && ($currenttime<$starttime)){
			 if(($day=="01") || ($day=="1")){
				 
				 $currentdate=$year.'-'.$month.'-'.$day;

 $mynewfromdate = strtotime ( '-1 month' , strtotime ( $currentdate ) ) ;
$newfromdate = date ( 'Y-m-d' , $mynewfromdate );
$finalstartdate = date("Y-m-t", strtotime($newfromdate)).' '.$starttime.':00';
			 }else{
			
								  $finalstartdate=$year.'-'.$month.'-'.$subtract.' '. $starttime.':00';

			
			 }
	


		 }

	
					

		
		 
		 
		if(($mytodate=="Next") && ($currenttime>=$duetime)){
	
		  $finalendate=$year.'-'.$month.'-'.$add.' '. $duetime.':00';
				//echo $finalstartdate;
		
		 }else if(($mytodate=="Next") && ($currenttime<$duetime)){
			
		  $finalendate=$year.'-'.$month.'-'.$day.' '. $duetime.':00';
		  
				//	echo $finalstartdate;
		 }else  if(($mytodate=="Current") && ($currenttime>=$duetime)){
		 		  $finalendate=$year.'-'.$month.'-'.$add.' '. $duetime.':00';

		 }else  if(($mytodate=="Current") && ($currenttime<$duetime)){
					  $finalendate=$year.'-'.$month.'-'.$day.' '. $duetime.':00';

		  
				//	echo $finalstartdate;
		 }
		 
		 
		 
		 
		 
		 
		 
		 						$updatepaymentmode=$this->usermodel->populatuserpermissionsdataarray('sales','updatepaymentmode',$userid);

		 
	 
	    $addproductaction=$this->usermodel->populatuserpermissionsdataarray('reports','add',$userid);

	 $updateaction=$this->usermodel->populatuserpermissionsdataarray('reports','update',$userid);
  $updatebuyingpriceaction=$this->usermodel->populatuserpermissionsdataarray('reports','update',$userid);
  $deleteaction=$this->usermodel->populatuserpermissionsdataarray('reports','delete',$userid);
	 
			    $cashiersales=$this->usermodel->populatuserpermissionsdataarray('cashiersales','all',$userid);
			    $cashierreprint=$this->usermodel->populatuserpermissionsdataarray('sales','reprint',$userid);
			    $pendingmpesareports=$this->usermodel->populatuserpermissionsdataarray('cashiersales','mpesapendingreport',$userid);
				
				
	   $viewallaction=$this->usermodel->populatuserpermissionsdataarray('reports','viewall',$userid);
	   
	   
	   	   $viewdailycollections=$this->usermodel->populatuserpermissionsdataarray('cashiersales','viewdailycollections',$userid);

		   	   $adddailycollection=$this->usermodel->populatuserpermissionsdataarray('cashiersales','adddailycollection',$userid);
		   	   $clearallsales=$this->usermodel->populatuserpermissionsdataarray('cashiersales','clearallsales',$userid);
		   	   $viewtill=$this->usermodel->populatuserpermissionsdataarray('cashiersales','viewtill',$userid);
	      $selecttable=$this->usermodel->populatuserpermissionsdataarray('sales','selecttable',$userid);
		  		  	      $leaseitems=$this->usermodel->populatuserpermissionsdataarray('sales','leaseitems',$userid);

	      $viewreports=$this->usermodel->populatuserpermissionsdataarray('accomodation','viewreports',$userid);

				echo $this->session->flashdata('msg'); 
				?>
					<div class="row">
						<div class="col-md-12">
							<div class="col-md-12">
        <?php 
		$mypage=0;
		if(isset($page)) {$mypage=$page;}else{$mypage=0;}
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchforleaseditems", $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">
				   <select class="form-control"name="searchtype"  >
	
	<option value=""  >---Select way of search items---</option>

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

   <option value="Specific"  >Specific item</option>

   

</select>		
	
                </div>
                <div class="col-md-3">
                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-default" value="Search" />
                    <a href="<?php echo base_url(). "user/viewlease"; ?>" class="btn btn-default">Refresh</a>

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

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

             <thead>
         <tr>
  									<th>Ref Code </th>
							
			<th>Serial No </th>

						<th>Item Name </th>
									<th> Amount </th>

			<th> Qty </th>
			<th> Date </th>
			<th>Due Date </th>
<th>Mode </th>
													<th>From </th>
		<th> Recorded by </th>
		<th>Customer   </th>
			<th> Description </th>
			<th> Status </th>
	
				
			<th>More</th>
		


                 </tr>
             </thead>
<?php
  $ttamount=0;
    $TTQTY=0;
 if(!is_array($viewlease)) 

 {


   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 

  	foreach ($viewlease as $c): 

		 

             ?>



             <tr>
                
            <?php 
$id=$c->id;

$mycode=$c->product;
  $codedate=$this->usermodel->populateallarray('products','code',$mycode);
	
 $name=$codedate[0]['name'];
  $description=$codedate[0]['description'];

 $supplier=$codedate[0]['supplier'];
  $ttamount=  $ttamount+$c->amount;
  $TTQTY=  $TTQTY+$c->qty;
$myinvoice=$c->invoice;
$customer=$c->incharge;
$invoice_number=$c->invoice;

?>


              
  <td>
  	  	  	  	 <a  id="more" class="btn btn-default"  href="<?php echo base_url();?>user/editlease?randomitemidentifier=<?php   {echo  $invoice_number;}  ?>"><?php echo $c->invoice  ;  ?></a>

  
  				 <a  id="non-printable"  href="<?php echo base_url();?>user/printleaseditem?invoice=<?php   if(isset($myinvoice)) {echo $myinvoice; } ?>&view=user/viewlease&customer=<?php   if(isset($customer)) {echo $customer; } ?>"> Print   </a>

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

    <td><?php echo $name."-".$description ; ?></td>
		   <td><?php echo $c->amount ; ?></td>
	   <td><?php echo $c->qty ; ?></td>
	   	  <td><?php echo $c->dateleased ; ?></td>

	  
	  
	  
	  
	      <td><?php 
echo $c->duedate ;
$endate=$c->duedate;
    		  $newDate = date('Y-m-d H:i:s');

	  //$newDate = date("Y-m-d");


		//$mycurrentdate = strtotime(date($newDate));

			//$mycurrentdate = strtotime(date($newDate));



		$mycurrentdate = strtotime(date($c->duedate));


	//$mycurrentdate = strtotime(date($newDate));





$finaldate = strtotime(date($c->dateleased));
$exactdate = strtotime(date($c->duedate));

									$secs = $finaldate-$mycurrentdate;// == <seconds between the two times>
									$days = $secs / 86400;
							 $finaldays=round($days,0);

if($c->status=="Returned"){
	
	
}else{

		
			 
	
			if($finaldays <= 0){
			
			?>
			<div class="btn-success">
			<?php  echo $finaldays." Due"  ; 	?>
			</div>
			<?php
			}else if(($finaldays > 0) && ($finaldays <3)) {
		?>
			<div class="btn-warning">
			<?php  echo $finaldays." Overdue"  ; 	?>
			</div>
			<?php
			
			}else if($finaldays >=3){
			?>
			<div class="btn-danger">
			<?php  echo $finaldays." Overdue" ; 	?>
			</div>
			<?php
			}
}
			?>	
			 
			 
			 
			 
			 </td>
	  
	  
	  
	  
	  
	  
	  <td><?php echo $c->mode ; ?></td>

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

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



if(is_array($branch)) {

   foreach($branch as $branchrow){

   echo $branchrow->name;
 
 
}} else {
    echo 'Store';
}
	
?>
	
	
</td>

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

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

  ?></td>
    <td><?php
	
	$customers=$this->usermodel->geteuser($c->incharge );
	if(	$customers==false){
		
		
	 echo $c->incharge 	;

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

		}else{
					   echo $mycustomers=$customers[0]['firstname'];

		}	
	}
	
	
	; ?></td>
   <td><?php echo $c->details ; ?></td>
	  <td><?php echo $c->status ;

 echo "<br>". $c->invoice ;
	  ?></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='#deleteModal<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Delete
                                                </a>
                                                        </li>
									
									
                                        <li class="divider"></li>
                                        
													<li> 
										 <a class="btn btn-warning managebtn" id="managebtnreturn" data-invoice='<?php echo  $c->invoice;?>' data-mode='<?php echo  $c->mode;?>' data-details='<?php echo  $c->details;?>' data-dateleased='<?php echo  $c->dateleased;?>' data-duedate='<?php echo  $c->duedate;?>' data-amount='<?php echo  $c->amount;?>' 	   data-status='<?php echo  $c->status;?>' data-serial='<?php echo  $c->user;?>' data-qty='<?php echo  $c->qty;?>'	 data-id='<?php echo  $c->id;?>'    data-toggle='modal' data-target='#returnModal<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Change Status
                                                </a>
                                                        </li>                                        
                                    </ul>
											<?php
										}
										?>
                                </div>
</td>
     	
                  
             </tr>

	<?php endforeach;} ?>
<tr>
<td COLSPAN="3">
<B>TOTAL AMOUNT:
</B>
</td>
<td>
<B>
<?php echo   formatMoney($ttamount, $fractional=false)  ; ?>
</B>
</td>

<td COLSPAN="9">
<B>
<?php echo $TTQTY ; ?>
</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. "  Products damaged in the system. " ;?>    </span>

        
        </div>
	</div>

	
	<div id="deleteModal" 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('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="lease">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/viewlease">
 <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>		
	
	
	
	
	
			<div id="viewuserModal" 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">Lease Report per user</h4>
      </div>
      <div class="modal-body">
      


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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewleaseditemsbyuser' , 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="all" class="form-control"  placeholder="Enter type">

  <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" required>
	
	
	<option value=""  >---Select Branch/Counter Name--</option>
<?php
									 if( $viewallaction==true){
										 ?>
					<option value="all"  >All branches/Counters</option>
									<?php
									 }
							
	?>
	
	<?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>
	
	
				  		<input type="hidden" name="view" value="viewgroupreceiptreport" class="form-control" required placeholder="Enter sales type">

     <div class="form-group">
    <label for="inputuser" class="col-sm-2 control-label">User?</label>
    <div class="col-sm-10">
	<select class="form-control" name="user" required>
	
	<option value=""  >---Select user---</option>

						<?php
	
		
		
		 if($cashiersales==true){
			$allusers = $this->usermodel->populatealldatanoarraythree('people', 'companyid',$companyid,'status',1,'category','user');
	?>
		<option value="all" selected >-All users-</option>

	<?php

 }else{
				 			$allusers = $this->usermodel->populatealldatanoarraythree('people', 'userid',$userid,'status',1,'category','user');

 
  
 }
  ?>

	
	
	
	<?php 
				
				
	

	
if(is_array($allusers)) {

   foreach($allusers as $userrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $userrow->id;   ?>"><?=  $userrow->firstname ."- ".$userrow->surname ."(". $userrow->email.")"; ?></option>



	<?php

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

	</div>
  </div>
  
  
  
  
  
  <div class="form-group">
    <label for="inputstatus" class="col-sm-2 control-label">Product Status?</label>
    <div class="col-sm-10">
	<select class="form-control" name="status"  required>
			<option value=""></option>

		<option value=""  >---Select Product Status---</option>
						<option value="all"   selected="selected"   >--ALL-</option>

		<option value="Dispatched"      >Dispatched</option>


			<option value="Undispatched"   >Undispatched</option>


			<option value="Failed Delivery"   >Failed Delivery</option>

		<option value="Returned and Received"  >Returned and Received</option>
		<option value="Returned"  >Returned</option>


 		<option value="Delivered"  >Delivered</option>



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

	</div>
  </div>
  
  
  
  
	
	

    <label for="inputfromdate" class="col-sm-2 control-label">From Date </label>

				<div class="col-sm-5">
					<div class="form-group">

                     		  		<input type="date" name="fromdate" value="<?php echo set_value('fromdate',date("Y-m-d", strtotime($finalstartdate))); ?>" class="form-control" required placeholder="Enter start date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="frotime" value="<?php echo set_value('frotime',$starttime.":00"); ?>" class="form-control" required placeholder="Enter start time">

					</div>
				</div>
			

			
			
						    <label for="inputtodate" class="col-sm-2 control-label">To Date </label>

				<div class="col-sm-5">
					<div class="form-group">

		  		<input type="date" name="todate" value="<?php echo set_value('todate',date("Y-m-d", strtotime($finalendate))); ?>" class="form-control" required placeholder="Enter End date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="totime" value="<?php echo set_value('totime',$duetime.":00"); ?>" class="form-control" required placeholder="Enter stop time">

					</div>
				</div>
  
  
	
	
   
  <div class="form-group">
    <label for="inputgroup" class="col-sm-2 control-label"> Group Items </label>
    <div class="col-sm-10">
	<select class="form-control" name="group"  required>
		<option value=""  ></option>

	<option value=""  >--Do you want to group items on the report-</option>

	<option value="No" selected="selected" >No</option>
	<option value="Yes"  >Yes</option>



</select>
		

	</div>
  </div>


<div class="form-group">
    <label for="inputproduct" class="col-sm-2 control-label">	Product name :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" required name="product" id="myproduct" value="<?php echo set_value('product','all'); ?>" class="form-control"  placeholder="Search item by name, code,serial No etc">
		 
				
		<span class="text-danger"> <?php echo form_error('product'); ?>
		
		</span>
	</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-default"> View Leased Items  </button>

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

    

				</div>

		</div>
	    </div>
    </div>
	
	
	
	
	
	
			<div id="viewfastslowmovingModal" 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">Fast / slow  moving Lease items</h4>
      </div>
      <div class="modal-body">
      


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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewleaseditemsmovement' , 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="all" class="form-control"  placeholder="Enter type">

  <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" required>
	
	
	<option value=""  >---Select Branch/Counter Name--</option>
<?php
									 if( $viewallaction==true){
										 ?>
					<option value="all"  >All branches/Counters</option>
									<?php
									 }
							
	?>
	
	<?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="inputmovement" class="col-sm-2 control-label">Movement </label>
    <div class="col-sm-10">
	<select class="form-control" name="movement"  required>

	<option value=""  >--Select Movement type-</option>

	<option value="Slow">Slow</option>
	<option value="Fast"   selected="selected"  >Fast</option>



</select>
		

	</div>
  </div>

  

  
  <div class="form-group">
    <label for="inputstatus" class="col-sm-2 control-label">Product Status?</label>
    <div class="col-sm-10">
	<select class="form-control" name="status"  required>
			<option value=""></option>

		<option value=""  >---Select Product Status---</option>
						<option value="all"   selected="selected"   >--ALL-</option>

		<option value="Dispatched"      >Dispatched</option>


			<option value="Undispatched"   >Undispatched</option>


			<option value="Failed Delivery"   >Failed Delivery</option>

		<option value="Returned and Received"  >Returned and Received</option>
		<option value="Returned"  >Returned</option>


 		<option value="Delivered"  >Delivered</option>



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

	</div>
  </div>
  
  
  
  
	
	
  

    <label for="inputfromdate" class="col-sm-2 control-label">From Date </label>

				<div class="col-sm-5">
					<div class="form-group">

                     		  		<input type="date" name="fromdate" value="<?php echo set_value('fromdate',date("Y-m-d", strtotime($finalstartdate))); ?>" class="form-control" required placeholder="Enter start date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="frotime" value="<?php echo set_value('frotime',$starttime.":00"); ?>" class="form-control" required placeholder="Enter start time">

					</div>
				</div>
			

			
			
						    <label for="inputtodate" class="col-sm-2 control-label">To Date </label>

				<div class="col-sm-5">
					<div class="form-group">

		  		<input type="date" name="todate" value="<?php echo set_value('todate',date("Y-m-d", strtotime($finalendate))); ?>" class="form-control" required placeholder="Enter End date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="totime" value="<?php echo set_value('totime',$duetime.":00"); ?>" class="form-control" required placeholder="Enter stop time">

					</div>
				</div>
  
  
	
	
     
   
  <div class="form-group">
    <label for="inputgroup" class="col-sm-2 control-label"> Group Items </label>
    <div class="col-sm-10">
	<select class="form-control" name="group"  required>
		<option value=""  ></option>

	<option value=""  >--Do you want to group items on the report-</option>

	<option value="No">No</option>
	<option value="Yes"   selected="selected"  >Yes</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-default"> View Leased Items  </button>

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

    

				</div>

		</div>
	    </div>
    </div>
	
	
	
	
	
	
	
	
	
	
	<div id="returnModal" 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 STATUS</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to Update  this lease item? </h3>
      </div>
      <div class="modal-footer">
	  	

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

		
                 echo form_open('user/returnleaseditems' , 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="serial" name="serial" class="serial" placeholder="serial" value="">






  <div class="form-group">
    <label for="inputstatus" class="col-sm-2 control-label">Product Status?</label>
    <div class="col-sm-10">
	<select class="form-control" name="status" id="status" required>
			<option value="" selected="selected" ></option>

		<option value=""  >---Select Product Status---</option>
				
		<option value="Dispatched"   >Dispatched</option>


			<option value="Undispatched"   >Undispatched</option>


			<option value="Failed Delivery"   >Failed Delivery</option>

		<option value="Returned and Received"  >Returned and Received</option>
		<option value="Returned"  >Returned</option>


 		<option value="Delivered"  >Delivered</option>



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

	</div>
  </div>








  <div class="form-group">
    <label for="inputmode" class="col-sm-2 control-label"> Lease Type</label>
    <div class="col-sm-10">
	<select class="form-control" name="mode"  id="mode" required>
		<option value="" selected="selected" ></option>

	<option value=""  >--Select Lease Type--</option>

	<option value="Daily"  >Daily</option>
	<option value="Weekly"  >Weekly</option>
	<option value="Monthly"  >Monthly</option>
	<option value="Quaterly"  >Quaterly</option>
	<option value="Yearly"  >Yearly</option>


</select>
		

	</div>
  </div>
  	





  
  	<div class="form-group">
    <label for="inputamount" class="col-sm-2 control-label">Amount :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" id="amount" name="amount" value="<?php echo set_value('amount',0); ?>" class="form-control" required placeholder="Enter  amount charged">
		 
				
		<span class="text-danger"> <?php echo form_error('amount'); ?>
		
		</span>
	</div>
  </div>
	<div class="form-group">
    <label for="inputqty" class="col-sm-2 control-label">Quantity :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="qty"  id="qty" value="<?php echo set_value('qty'); ?>" class="form-control" required placeholder="Enter  Quantity Leased">
		 
				
		<span class="text-danger"> <?php echo form_error('qty'); ?>
		
		</span>
	</div>
  </div>
  

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

  	<div class="form-group">
    <label for="inputdateleased" class="col-sm-2 control-label">Date Leased</label>
    <div class="col-sm-10">

		  		<input type="text" name="dateleased"  id="dateleased" value="<?php echo set_value('dateleased'); ?>" class="form-control" required placeholder="Enter Date Leased ">
		 
				
		<span class="text-danger"> <?php echo form_error('dateleased'); ?>
		
		</span>
	</div>
  </div>
  
   
  
  
  
  
  
  
  
  
  
  
	<div class="form-group">
    <label for="inputdetails" class="col-sm-2 control-label">	Remarks  / Comments</label>
    <div class="col-sm-10">

				<textarea name="details" id="details" value="<?php echo set_value('details'); ?>"  class="form-control"  placeholder="Enter remarks"></textarea>
			
		<span class="text-danger"> <?php echo form_error('details'); ?>
		
		</span>
	</div>
  </div>
		

	
  
	<div class="form-group" >
    <label for="inputinvoice" class="col-sm-2 control-label">	Ref No </label>
    <div class="col-sm-10">
		

			<input type="text"  name="invoice" id="invoice" value="<?php echo set_value('invoice'); ?>" class="form-control" required placeholder="Enter invoiceno">

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




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


 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/viewlease">
 <input type="hidden" id="returnid"name="itemid" class="returnid" placeholder="returnid" 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"> Yes  </button>

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

  </div>

  </div>		
	
	
	
	
	
	
		<div id="usersummaryModal" 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">Lease Report per Customer</h4>
      </div>
      <div class="modal-body">
      


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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewleaseditemsbycustomer' , 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="all" class="form-control"  placeholder="Enter type">

  <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" required>
	
	
	<option value=""  >---Select Branch/Counter Name--</option>
<?php
									 if( $viewallaction==true){
										 ?>
					<option value="all"  >All branches/Counters</option>
									<?php
									 }
							
	?>
	
	<?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>
	
	
				  		<input type="hidden" name="view" value="viewgroupreceiptreport" class="form-control" required placeholder="Enter sales type">

     <div class="form-group">
    <label for="inputuser" class="col-sm-2 control-label">Select Customer?</label>
    <div class="col-sm-10">
			  		<input type="text" id="myuser" name="user" value="<?php echo set_value('incharge'); ?>" class="form-control" required placeholder="Enter Person incharge name">

	</div>
  </div>
  
  
  
  
  
  <div class="form-group">
    <label for="inputstatus" class="col-sm-2 control-label">Product Status?</label>
    <div class="col-sm-10">
	<select class="form-control" name="status"  required>
			<option value=""></option>

		<option value=""  >---Select Product Status---</option>
						<option value="all"   selected="selected"   >--ALL-</option>

		<option value="Dispatched"      >Dispatched</option>


			<option value="Undispatched"   >Undispatched</option>


			<option value="Failed Delivery"   >Failed Delivery</option>

		<option value="Returned and Received"  >Returned and Received</option>
		<option value="Returned"  >Returned</option>


 		<option value="Delivered"  >Delivered</option>



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

	</div>
  </div>
  
  
  

    <label for="inputfromdate" class="col-sm-2 control-label">From Date </label>

				<div class="col-sm-5">
					<div class="form-group">

                     		  		<input type="date" name="fromdate" value="<?php echo set_value('fromdate',date("Y-m-d", strtotime($finalstartdate))); ?>" class="form-control" required placeholder="Enter start date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="frotime" value="<?php echo set_value('frotime',$starttime.":00"); ?>" class="form-control" required placeholder="Enter start time">

					</div>
				</div>
			

			
			
						    <label for="inputtodate" class="col-sm-2 control-label">To Date </label>

				<div class="col-sm-5">
					<div class="form-group">

		  		<input type="date" name="todate" value="<?php echo set_value('todate',date("Y-m-d", strtotime($finalendate))); ?>" class="form-control" required placeholder="Enter End date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="totime" value="<?php echo set_value('totime',$duetime.":00"); ?>" class="form-control" required placeholder="Enter stop time">

					</div>
				</div>
  
  
  
	
	
	
     
   
  <div class="form-group">
    <label for="inputgroup" class="col-sm-2 control-label"> Group Items </label>
    <div class="col-sm-10">
	<select class="form-control" name="group"  required>
		<option value=""  ></option>

	<option value=""  >--Do you want to group items on the report-</option>

	<option value="No" selected="selected" >No</option>
	<option value="Yes"  >Yes</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-default"> View Leased Items  </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">Add new Lease </h4>
      </div>
      <div class="modal-body">
      
	  	

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


 $finalsalesid = $userid.time();
				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/addlease' , 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="action" value="insert" class="form-control" required placeholder="Enter invoiceno">

								<input type="hidden" name="mycategoryid" value="" class="form-control" required placeholder="Enter invoiceno">

  
     <div class="form-group">
    <label for="inputmethod" class="col-sm-2 control-label">Search Method?</label>
    <div class="col-sm-10">
	<select class="form-control" name="method" required>
	
	<option value=""  >---Which method do you want to search with?---</option>
	<option value="No" selected="selected" > No serial Numbers(General)</option>
	<option value="Serial"  >Search using serial Numbers</option>

	


</select>
		

	</div>
  </div>
  	


  <div class="form-group">
    <label for="inputmode" class="col-sm-2 control-label"> Lease Type</label>
    <div class="col-sm-10">
	<select class="form-control" name="mode" required>
	
	<option value=""  >--Select Lease Type--</option>

	<option value="Daily"  >Daily</option>
	<option value="Weekly"  >Weekly</option>
	<option value="Monthly"  selected="selected">Monthly</option>
	<option value="Quaterly"  >Quaterly</option>
	<option value="Yearly"  >Yearly</option>


</select>
		

	</div>
  </div>
  	




<div class="form-group" style="display:none">
    <label for="inputproduct" class="col-sm-2 control-label">	Product name :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" required name="product" id="product" value="<?php echo set_value('product',"all"); ?>" class="form-control"  placeholder="Search item by name, code,serial No etc">
		 
				
		<span class="text-danger"> <?php echo form_error('product'); ?>
		
		</span>
	</div>
  </div>
  
  
  	<div class="form-group">
    <label for="inputamount" class="col-sm-2 control-label">Amount :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="amount" value="<?php echo set_value('amount',0); ?>" class="form-control" required placeholder="Enter  amount charged">
		 
				
		<span class="text-danger"> <?php echo form_error('amount'); ?>
		
		</span>
	</div>
  </div>
<div class="form-group" style="display:none">
    <label for="inputqty" class="col-sm-2 control-label">Quantity :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="qty" value="<?php echo set_value('qty',1); ?>" class="form-control" required placeholder="Enter  Quantity Leased">
		 
				
		<span class="text-danger"> <?php echo form_error('qty'); ?>
		
		</span>
	</div>
  </div>
  
	<div class="form-group">
    <label for="inputincharge" class="col-sm-2 control-label">Customer</label>
    <div class="col-sm-10">
	
		  		<input type="text" id="incharge" name="incharge" value="<?php echo set_value('incharge'); ?>" class="form-control" required placeholder="Enter Person incharge name">
		 
				
		<span class="text-danger"> <?php echo form_error('incharge'); ?>
		
		</span>
	</div>
  </div>

  		  	<div class="form-group">
    <label for="inputduedate" class="col-sm-2 control-label">Due Date</label>
    <div class="col-sm-10">
	
		  		<input type="date" name="duedate" value="<?php echo set_value('duedate', $mydate); ?>" class="form-control" required placeholder="Enter Due Date ">
		 
				
		<span class="text-danger"> <?php echo form_error('duedate'); ?>
		
		</span>
	</div>
  </div>
  			 

  	<div class="form-group">
    <label for="inputdateleased" class="col-sm-2 control-label">Lease Date</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="dateleased" value="<?php echo set_value('dateleased', $mydate); ?>" class="form-control" required placeholder="Enter Date Leased ">
		 
				
		<span class="text-danger"> <?php echo form_error('dateleased'); ?>
		
		</span>
	</div>
  </div>
  
   
  
  
  
  
     <div class="form-group">
    <label for="inputfrom" class="col-sm-2 control-label">From?</label>
    <div class="col-sm-10">
	<select class="form-control" name="from" required>
	
	<option value=""  >---Where do you want to deduct  product from?---</option>

	
	<?php 
					 

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



if(is_array($branch)) {

   foreach($branch as $branchrow){

   //echo $courserow->coursename;
    ?>
					<option selected 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="inputinvoice" class="col-sm-2 control-label">	Ref No </label>
    <div class="col-sm-10">
		

			<input type="text"  name="invoice" value="<?php echo set_value('invoice',$finalsalesid); ?>" class="form-control" required placeholder="Enter invoiceno">

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

  
  
  
  
	<div class="form-group">
    <label for="inputdetails" class="col-sm-2 control-label">	Remarks </label>
    <div class="col-sm-10">

				<textarea name="details" value="<?php echo set_value('details'); ?>"  class="form-control"  placeholder="Enter remarks">Paid</textarea>
			
		<span class="text-danger"> <?php echo form_error('details'); ?>
		
		</span>
	</div>
  </div>
		

	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="lease" name="btn_lease" class="btn btn-primary"> Next >>> </button>

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

    

				</div>

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

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

 
</div>

	


















