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

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

		    // document.body.innerHTML = originalContents;

	}
}


       
		 
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid").val(itemid); 
		  
		  
		   
        });
		








	</script>
	
	
	
	           <script type="text/javascript">
  
  
		 $(document).on("click", "#managebtncheckout", function()
        {
          var roomidentifier = $(this).data('id');
		  $("#roomidentifier").val(roomidentifier); 
		  
		    var houseno2 = $(this).data('houseno');
		  $("#houseno2").val(houseno2); 
		     var plotno2 = $(this).data('plotno');
		  $("#plotno2").val(plotno2); 
		   
		    var bedid = $(this).data('bedid');
		  $("#bedid").val(bedid); 
        });
		
	
		</script>
	
	
	
	
	
	
	
   <style type="text/css">
  
  

    #printable { display: none; }

    #myprint { display: none; }
#print{  	


    background-repeat: no-repeat;
	font-size;12px;
  
    


}


#sale{  	
background-image:url(images/add.png) ;

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


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

    }
    </style>







 <div class="row">

 

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

				 
				 	<div class="print-hide" id="non-printable"  >
<form name="print" method="post" action="">
 
 <div class="row">

 

   	<div class="col-md-6">
				 <a class="btn btn-success" href="<?php echo base_url(); ?>admin/viewalladvance">	GO BACK</a> ||

					 <a class="btn btn-info"href="<?php echo base_url(); ?>admin/searchbalance">View More reports</a><BR>

</div>
   	<div class="col-md-6">
<input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('printableArea')" value="print receipt!" />
</form></div></div>
							</div> 
     
	 
	 <?php
	 	$session_data = $this->session->userdata('logged_in');

    $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
 $data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
        
		
			 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	        		$configuration = $this->usermodel->populateallarray('smsconfig','id',$companyid);


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

    $updatehouse=$this->usermodel->populatuserpermissionsdataarray('accomodation','updatehouse',$userid);
		   $cancelpayment=$this->usermodel->populatuserpermissionsdataarray('accomodation','cancel',$userid);
	      


	 
	 ?>
	 
	 
	 


 <div class="panel panel-primary" data-collapsed="0">
 	<div class="table-responsive">
			<div id="printableArea">
			
			<table width="100%">
           
			
			<tr>
				 	
	<td colspan="2" width="100%">
	<center>
					
										<?php $bussinessname=$configuration[0]['businessname']; if(isset($bussinessname)) {echo   $bussinessname; }?>
		</center>	
		</td>

			</tr>
			<?php if(isset($fromdate)) {
			
				
				
			
			?>
		<tr>
				<td>

				<h4><b>Bookings  between <?php echo $fromdate; ?> AND <?php echo $todate; ?>.</b></h4>	</td>
					<td><h4><b>Printed on <?php echo $date = date("Y-m-d"); ?></b></h4></td>

		</tr>
			
			
				<?php 
				
				}
			
			?>
			
			
			
</table >
			
			
			
			
			
	<div class="panel panel-primary" data-collapsed="0" ID="sortable_table">
 <CENTER><B>ADVANCE PAYMENTS</B></CENTER>
<table id="example"  cellspacing="1" class="table table-bordered datatable" width="100%">
             <thead>
			 
         <tr>


 <th>Customer Name </th>
 <th>Expected paid</th> 
  <th>Paid</th> 
    <th>Balance</th>

	<th>IDNO Number</th>	
    <th>Phone Number</th>         
	<th>Start date</th> 
	<th>Due date</th> 
	<th>Description</th> 
	<th>Staff</th> 

	<th>Plotno</th> 
	<th>Hs No</th> 

	<th id="non-printable">Payments</th> 
			  <th>Status </th>
<th id="non-printable">More</th>


                 </tr>
             </thead>
<?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;
					}
					








$imgid = rand(100, 990000).time();
 $session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$totalamount=0;
    $totalbalance=0;
 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
 if(!is_array($advance)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='1'>";
    
       echo '<div class="alert alert-warning text-center">There is no advance found by now from system..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  

  
  	foreach ($advance as $c): 

		 

             ?>



             <tr>
                    
   <td>
            <?php 
		$tenantid=$c->tenantid;
 $id=$c->id;
 
   $totalamount=$totalamount+$c->amount;
    $totalbalance=$totalbalance+$c->balance;
 							
$mycustomer = $this->usermodel->populateallarray('people','id', $tenantid);
	 $firstname=$mycustomer[0]['firstname'];
	 $idno=$mycustomer[0]['idno'];
	 $phone=$mycustomer[0]['phone'];
	 $lastname=$mycustomer[0]['lastname'];
	 
	 
	 
echo $tenantid."- ";

			
			if($tenantid !=""){
				if($mycustomer[0]['company']!=""){
									echo$myname=$mycustomer[0]['company'];

				}else{
									echo$myname=$mycustomer[0]['firstname'];
									
									

				}
			}

	 
	 
	 
	 
	 
	 
	 
	 
	 


?>
    			
				
				
				
				
				
				
				
				
				
				
				
				

</td> 

		<td><?php  echo formatMoney($c->amount, true);?></td> 
										<td><?php echo formatMoney($c->paid, true);?></td> 
																				<td><?php echo formatMoney($c->balance, true);?></td> 











					 

			 <td><?php echo $idno ; ?></td>
					<td><?php echo $phone ; ?></td> 

            
		
                     <td><?php echo $c->startdate; ?></td>   
                                  <td><?php echo $c->closedate; ?></td>   
                                  <td><?php echo $c->description; ?></td>   
 <td>
												 
	<?php 
					// $branch="";
					 $userid=$c->userid;

					 $user= $this->usermodel->populateall('people','id',$userid);



if(is_array($user)) {

   foreach($user as $userhrow){

   echo $userhrow->surname;
 
 
}} else {
    echo 'No Name.';
}
	
?>
												 
	 </td>	
	 
	    <td><?php echo $c->plotno; ?></td>   
                                  <td><?php echo $c->houseno; ?></td>   

					          <td id="non-printable">
 <a class="btn btn-info managebtn" id="managebtncheckout"	 data-id='<?php echo  $c->id;?>'     data-status='<?php echo  $c->status;?>'  data-toggle='modal' data-target='#Checkout<?php  $c->id; ?>'>	 Receive
  </a>
   <a class="btn btn-success managebtn" id="managebtnaddpayment"	 data-id='<?php echo  $c->id;?>'     data-status='<?php echo  $c->status;?>'  data-toggle='modal' data-target='#AddPayment<?php  $c->id; ?>'>	 Add
  </a>
  	  	  	  	 <a  id="more" class=" btn-primary"  href="<?php echo base_url();?>user/printadvancereceipt?randomitemidentifier=<?php   {echo  $c->id;}  ?>&myid=<?php   {echo  $userid;}  ?>">Print  </a>

         </td>
		                   <td><?php echo $c->status; ?></td>  
		 	 <td id="non-printable"> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">
                                        More <span class="caret"></span>
                                    </button>
									
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                    
 
						<li>
 	
							   <a class="btn btn-success" id="more" href="<?php echo base_url();?>admin/viewmyadvancepayment?randomitemidentifier=<?php   {echo  $c->id;}  ?>">

						
                                                <i>View history</i>
						</a>
						</li>
 						   <li class="divider"></li>

 
 <li>
 	
			 <a class="btn btn-info managebtn" id="managebtncheckout"	 data-id='<?php echo  $c->id;?>'     data-status='<?php echo  $c->status;?>'  data-toggle='modal' data-target='#Checkout<?php  $c->id; ?>'>	 

						
                                                <i>Receive payment</i>
						</a>
						</li>
						   <li class="divider"></li>
						
						
						
												   <li class="divider"></li>

							
						<li>
 	
                     <a  class="btn btn-primary" id="more" href="<?php echo base_url();?>admin/editadvance?randomitemidentifier=<?php   {echo  $id;}  ?>">

						
                                                <i>Update</i>
						</a>
						</li>
						                                        <li class="divider"></li>

						  <?php
										if($usertype=="admin"){
											
											?>
										
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete"		 data-id='<?php echo  $c->id;?>'     data-toggle='modal' data-target='#myModal<?php  $c->id; ?>'>	 


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

          

             <?php endforeach; ?>

              <?php }?>
  	</tr>
	<tfoot>
			 <tr>
			 
			 <td>					 TOTAL AMOUNT

			 </td>

			
			
			  <td>
			  <?php echo $totalamount;  ?>
			
			 </td>
			   <td>
			  <?php echo $totalbalance;  ?>
			
			 </td>
			   <td> </td>
			   <td> </td>
			   <td> </td>
			   <td> </td>
			   <td> </td>
			   <td> </td>
			   <td> </td>
			   <td id="non-printable"> </td>
			   <td id="non-printable"> </td>

		
			 </tr>
			 	</tfoot>
        </table>

</div>











 <div id="myCheckout" 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">Customer Check Out</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to Check out this customer? </h3>
      </div>
      <div class="modal-footer">
	  	

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

		
                 echo form_open('admin/myupdatechekoutbeds' , 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="bookroom" value="bookroom">
 <input type="hidden" id="view2"name="view2" class="view2" placeholder="view2" value="">
 <input type="hidden" id="roomidentifier" name="roomidentifier" class="roomidentifier" placeholder="roomidentifier" value="">
 <input type="hidden" id="bedid" name="bedid" class="roomidentifier" placeholder="roomidentifier" value="">

 
 	<select class="form-control" name="status" required >
	<option  value=""  >--Select status-</option>

				   <option selected value="Vacant Dirty" >Vacant Dirty</option>
				<?php
					if( $usertype=="admin"){
						?>
   <option value="vacant"  >Vacant Ready</option>
  
<option value="Occupied Dirty" >Occupied Dirty </option>

   <option value="Blocked" >Blocked</option>
   <option value="Reserved" >Reserved</option>

					<?php	
					}
					
					?>
					


	
</select>
Clear Pending Balance?
 	<select class="form-control" name="balance" required>
	<option  value=""  >--Do you want to Clear any Pending tenant balance automatically?-</option>
   <option value="yes"  >Yes</option>
									  
 <option value="no"  selected="selected"  >No</option>
																 									   <option value="Pending">Pending</option>



	
</select>
 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/salesreceipts">
 <input type="hidden" id="itemid1"name="itemid" class="itemid" placeholder="itemid" value=""><br>
           <input type="hidden" id="houseno2"name="houseno" class="form-control" placeholder="houseno"  value="">

          <input type="hidden" id="plotno2"name="plotno" class="form-control" placeholder="plotno"  value="">
 		   		  	         <button type="submit" name="updatecheckout" value="checkoutbed" class="btn btn-success"> Yes  </button>

 <button type="button" class="btn btn-danger" data-dismiss="modal">No</button>


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

  </div>

  </div>
		
		















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

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

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

		
                 echo form_open('user/deleteallbyid' , 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="bookroom" value="bookroom">
 <input type="hidden" id="view2"name="view2" class="view2" placeholder="view2" value="">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/viewpallmyplots">
 <input type="hidden" id="itemid"name="itemid" class="itemid" placeholder="itemid" value=""><br>
           <input type="hidden" id="houseno"name="houseno" class="form-control" placeholder="houseno"  value="">

          <input type="hidden" id="plotno1"name="plotno" class="form-control" placeholder="plotno"  value="">
 <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>