
      <script type="text/javascript">
  
			 
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		    var plotno = $(this).data('plotno');
		   $("#plotno1").val(plotno); 
		     
		    var houseno = $(this).data('houseno');
		   $("#houseno1").val(houseno); 
		   	    var type = $(this).data('type');
		   $("#type3").val(type); 
		   
		   
		       var ttamount = $(this).data('amount');
		   $("#ttamount").val(ttamount); 
		   
		   
		   
		   
        });
		
	
	$(document).on("click", "#invocebtn", function()
        {
          var phone = $(this).data('phone');
		  $("#phone1").val(phone); 
		   
		   		   
   var message = $(this).data('message');
		   $("#message1").val(message);
 
	
		  
		  
		   
        });
		


	$(document).on("click", "#receiptbtn", function()
        {
          var phone = $(this).data('phone');
		  $("#phone2").val(phone); 
		   
		   		   
   var message = $(this).data('message');
		   $("#message2").val(message);
 
	
		  
		  
		   
        });
		
	
		
    </script> 

<?PHP

				function formatMoney($number, $fractional=false) {
						if ($fractional) {
							$number = sprintf('%.2f', $number);
						}
						while (true) {
							$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
							if ($replaced != $number) {
								$number = $replaced;
							} else {
								break;
							}
						}
						return $number;
					}
						


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

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];

 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	 $salesid=$transactioncode;
	 
	 
	 $salesdetails= $this->usermodel->populateallarray('receipt','transactioncode',$salesid);
	 
						
		 	  $mycustomer=$salesdetails[0]['tenantid'];	
			  
			     $duedate = date("d/m/Y", strtotime($salesdetails[0]['exactime']));

  $Receiptno=$salesdetails[0]['id'];	
							$people=$this->usermodel->populateallarray('people','id', $mycustomer);
							  $phone=$people[0]['phone'];	
							  
							  $mytotal = formatMoney($salesdetails[0]['amount'], true); 
						$invoicelink= base_url()."printinvoicehouse?refnumber=".$salesid;

						$receiptlink= base_url()."pintreceipthouse?refnumber=".$salesid;
						$invoicemessae="Hello, this is to inform you that your invoice worth Ksh ".$mytotal." with Invoice No ".$Receiptno."   and  REF No ".$salesid." due on ".$duedate."  has been generated. Thanks for your support. Click this link to print your Digital invoice: ".$invoicelink."";
												$receiptemessage="Hello, this is to inform you that your Receipt worth Ksh ".$mytotal." with Receipt No ".$Receiptno."   and  REF No ".$salesid." has been generated.Thanks for your support. Click this link to print your Digital Receipt: ".$receiptlink."";

	 
	 
	 
	 
	 
	 
	 
	 
	 ?>



<ul class="nav nav-tabs bordered">
			<li class="active">
            	<a href="#list" data-toggle="tab"><i class="entypo-menu"></i> 
					All Invoices for this House
                    	</a></li>
			
				
						
							
							<li>
										                     <a  id="more" href="<?php echo base_url();?>admin/rentinvoice?randomitemidentifier=<?php   {echo  $randomitemidentifier;}  ?>&randomitemidentifier1=<?php   {echo  $randomitemidentifier1;}  ?>">Back to invoice  </a>

							</li>
						
						<li>
						
						
											
												
												

	 <a class="btn btn-warning invocebtn" id="invocebtn" data-phone='<?php echo  $phone;?>'   data-message='<?php echo  $invoicemessae;?>'  data-id='<?php echo  $salesid;?>' data-toggle='modal' data-target='#addinvoicesmsModal'> 	 

                                                <i class="glyphicon glyphicon-pencil"></i>
																Send invoice sms
                                                </a>
                                              										                              <a  id="more" class="btn btn-success" href="https://api.whatsapp.com/send?phone=<?php echo  $phone;?>&text=<?php echo  $invoicemessae;?>&source=&data=&app_absent="> Whatsapp Invoice </a>
       
												
												
												
												
												
									 <a class="btn btn-warning receiptbtn" id="receiptbtn" data-phone='<?php echo  $phone;?>'   data-message='<?php echo  $receiptemessage;?>'  data-id='<?php echo  $salesid;?>' data-toggle='modal' data-target='#addreceiptsmsModal'> 	 

													


                                                <i class="glyphicon glyphicon-pencil"></i>
																Send Receipt sms
                                                </a>
								
								


																		                              <a  id="more" class="btn btn-success" href="https://api.whatsapp.com/send?phone=<?php echo  $phone;?>&text=<?php echo  $receiptemessage;?>&source=&data=&app_absent="> Whatsapp Receipt </a>

						
						
						</li>
						
						
						
						
						
						
						
						
							<li>
            									 <a href="<?php echo base_url(); ?>admin/viewpallmyplots">Back Home </a>


							</li>
		</ul>
    	<!------CONTROL TABS END------>
        
		<div class="tab-content">
		<?php
					echo $this->session->flashdata('deletemsg'); 

			?>
            <!----TABLE LISTING STARTS-->
            <div class="tab-pane box active" id="list">
				
     


 <div class="panel panel-primary" data-collapsed="0">
 
 
<table id="example"  cellspacing="1" class="table" width="100%">
             <thead>
			
         <tr>
    
    <th>Hse No </th>
		    <th id="non-printable">Priority </th>

	<th>Plot No</th>
    
	<th>Type</th> 	
	<th>Tenant </th> 
	<th>Exp Amount </th> 
		<th>Paid </th> 
		<th>Copa </th> 
			<th>comm </th> 
			
			
		<th> Invoice Name</th> 
		<th> Month </th> 
		<th> Year </th> 
	<th> Invoice Date </th> 
	<th>Due Date</th> 
		<th id="non-printable">More</th> 
  <!---<th>Delete</th> -->
	 




                 </tr>
             </thead>
<?php

		if(validation_errors()):
		 endif;
 if(!is_array($invoice)) 

 {




    }else {
?>
    
             <?php 
    $totalpaid=0;
   $mydifference=0;
  $totalinvoice=0;
    $totalbalance=0;
  	foreach ($invoice as $c): 

		 

             ?>


             <tr>
                
            <?php 
		$id=$c->id;
  $totalpaid= $totalpaid+$c->paid ;
  
  $totalinvoice= $totalinvoice+$c->amount ;
    $totalbalance=  $totalinvoice-$totalpaid;

?>

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

				<td><?php echo $c->plotno ; ?></td> 
<td><?php //echo $c->paymentstatus ;



   
						   $chargename = $this->usermodel->populateallarray('charges','id', $c->type);

	echo $chargename=$chargename[0]['type'];

 ?></td> 
					

                 <td><?php  $tenantid=$c->tenantid ; 
				 
				 
				    $tenants = $this->accomodationmodel->gettenantbyid($tenantid);
								


if(is_array($tenants)) {

   foreach($tenants as $tenantsrow){

   echo $tenantsrow->lastname. "  ".$tenantsrow->firstname ; 
    

}} else {
    echo $c->tenantid;
}
				
				 $diffrence=($c->amount-$c->paid)+ $c->coparent  ;
				 if( $diffrence < $c->amount){
					 $mydifference= $diffrence;
				 }else{
					 $mydifference= 0;
 
					 
				 }
				 
				 
				 
				 ?></td>
				       <td><?php echo $c->amount ; ?></td>
					         <td><?php echo $c->paid ; ?></td>
							     <td><?php echo $c->coparent ; ?></td>
							     <td><?php echo $TTCOM=($c->commission+$c->coparentcommission) ; ?></td>
					   <td><?php echo $c->type ; ?></td> 
					          <td><?php echo $c->month ; ?></td>
							         <td><?php echo $c->year ; ?></td>
                     <td><?php echo $c->createdat; ?></td>
					     <td><?php echo $c->duedate; ?></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>
									<?php
										if($usertype=="admin"){
											
											?>
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
										 <li> 
						<a class="btn btn-info managebtn" id="managebtncoparent" data-type='<?php echo  $c->type;?>'  data-coparentvat='<?php echo  $c->coparentvat;?>'  data-coparentcommission='<?php echo  $c->coparentcommission;?>'  data-coparent='<?php echo  $c->coparent;?>' data-houseno='<?php echo  $c->houseno;?>'	 data-id='<?php echo  $c->id;?>'   data-plotno='<?php echo  $c->plotno;?>'	 data-amount='<?php echo  $mydifference;?>'   data-toggle='modal' data-target='#Coparent<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Pay through Coparent 
                                                </a>
                                                        </li>
									
                                           <li class="divider"></li>
										
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete"	data-type='<?php echo  $c->type;?>'  data-amount='<?php echo  $c->amount;?>' data-houseno='<?php echo  $c->houseno;?>'	 data-id='<?php echo  $c->id;?>'   data-plotno='<?php echo  $c->plotno;?>'  data-toggle='modal' data-target='#myModal<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Cancel Invoice
                                                </a>
                                                        </li>
									
									
                                        <li class="divider"></li>
                                        				
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtncancelpayamnt"	 data-houseno='<?php echo  $c->houseno;?>'	 data-id='<?php echo  $c->id;?>'   data-plotno='<?php echo  $c->plotno;?>'  data-toggle='modal' data-target='#myClearpaymentModal<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Cancel real payment
                                                </a>
                                                        </li>
														
														      <li class="divider"></li>
														
														  <li> 
										 <a class="btn btn-danger managebtn" id="managebtncancelpayamntcopa"	 data-houseno='<?php echo  $c->houseno;?>'	 data-id='<?php echo  $c->id;?>'   data-plotno='<?php echo  $c->plotno;?>'  data-toggle='modal' data-target='#myClearpaymentModalCopa<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Cancel Coparent payments
                                                </a>
                                                        </li>
														
														
														
														
                                        <!-- teacher DELETION LINK -->
                                        
                                    </ul>
											<?php
										}
										?>
                                </div>
							</td>
		 
            
             </tr>

             <?php endforeach; ?>

              <?php }?>
 <tfoot>
<th>
    <td colspan="5"></td> 
 
	
	 <td colspan="9"><b>Total Balance:<?php 
	if(isset($totalbalance)) {echo  "KSHS  =" .$totalbalance; }
	 ?> </b></td > 
		 
	

 
	 
	




                 </th>
				  </tfoot>
        </table>


</div>

</div>
		<!----CREATION FORM STARTS---->
		
   <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">Cancel Utility</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to Cancel this Utility? </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="view" value="invoice">
 <input type="hidden" id="type3"name="type" class="type" placeholder="view" value="" >

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/rentinvoicedetails?transactioncode=<?php echo   $transactioncode;?>">
  <input type="hidden" id="view2"name="view2" class="view2" placeholder="view" value="&randomitemidentifier1=">
 <input type="hidden" id="houseno1"name="houseno" class="houseno" placeholder="houseno" value=""><br>
 <input type="hidden" name="transactioncode" class="transactioncode" placeholder="transactioncode" value="<?php echo   $transactioncode;?>"><br>
 <input type="hidden" id="ttamount"name="amount" class="amount" placeholder="amount" value=""><br>

 <input type="hidden" id="itemid1"name="itemid" class="itemid" placeholder="itemid" value=""><br>
          <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"> Cancel  </button>

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

  </div>

  </div>
   <div class="tab-pane box" id="thirdtab" style="padding: 5px">
			
			



		
					
		
		

 <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 invoice/receipt? </h3>
      </div>
      <div class="modal-footer">
	  	

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

		
                 echo form_open('admin/deletestudentdocuments' , 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="documentname1"name="documentname" class="form-control" placeholder="Full Name"  value="">
 <button type="button" class="btn btn-success" data-dismiss="modal">No</button>
 		  	         <button type="submit" name="btn_delete" value="deletestudentdocuments" class="btn btn-danger"> Delete  </button>

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

  </div>

  </div>






   </div>
   
   
   
   	

						<div id="addinvoicesmsModal" 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 Invoice Sms</h4>
      </div>
      <div class="modal-body">
      
	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/addsalessms' , 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="inputcontact" class="col-sm-2 control-label">	Contact </label>
    <div class="col-sm-10">
								<input type="hidden" name="view" value="user/searchinvoice?code=<?php echo $salesid ;?>" id="view" class="form-control" required placeholder="Enter view">

	
	<textarea name="contact" value="<?php echo set_value('contact'); ?>" id="phone1" class="form-control"  placeholder="Enter phone e.g  254712345678,254712345678"></textarea>

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

	

	<div class="form-group">
    <label for="inputmessage" class="col-sm-2 control-label">	Message</label>
    <div class="col-sm-10">
		
<textarea   maxlength="800" required name="message" id="message1" value="pos.robisearch.com/printinvoice?refnumber=11597205277" class="form-control" rows="3" cols="60" onFocus="countChars('textbox','char_count',0)" onKeyDown="countChars('textbox','char_count',0)" onKeyUp="countChars('textbox','char_count',0)"></textarea> <br />Characters:<span id="char_count"></span>

			
		
			
		<span class="char_count"> <?php echo form_error("message"); ?>
		
		</span>
	</div>
  </div>
		

	
	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="sms" name="btn_addsms" class="btn btn-primary"> Send SMS   </button>

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

    

				</div>

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

						<div id="addreceiptsmsModal" 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 receipt Sms</h4>
      </div>
      <div class="modal-body">
      
	  	

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

//

				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/addsalessms' , 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="inputcontact" class="col-sm-2 control-label">	Contact </label>
    <div class="col-sm-10">

									<input type="hidden" name="view" value="user/searchinvoice?code=<?php echo $salesid ;?>" id="view" class="form-control" required placeholder="Enter view">

	<textarea name="contact" value="<?php echo set_value('contact'); ?>" id="phone2" class="form-control"  placeholder="Enter phone e.g  254712345678,254712345678"></textarea>

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

	

	<div class="form-group">
    <label for="inputmessage" class="col-sm-2 control-label">	Message</label>
    <div class="col-sm-10">
		
<textarea   maxlength="800" required name="message" value="" id="message2" class="form-control" rows="3" cols="60" onFocus="countChars('textbox','char_count',0)" onKeyDown="countChars('textbox','char_count',0)" onKeyUp="countChars('textbox','char_count',0)"></textarea> <br />Characters:<span id="char_count"></span>

			
		
			
		<span class="char_count"> <?php echo form_error("message"); ?>
		
		</span>
	</div>
  </div>
		

	
	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="sms" name="btn_addsms" class="btn btn-primary"> Send SMS   </button>

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

    

				</div>

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

					
			
	
	
	
	
	
	
	
	
	
	

</div>




			