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

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

		    // document.body.innerHTML = originalContents;

	}
}
	</script>
      <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 transactioncodes = $(this).data('transactioncodes');
		   $("#transactioncodes").val(transactioncodes); 
		   
		   
        });
		 $(document).on("click", "#managebtndelete2", function()
        {
          var itemid2 = $(this).data('id');
		  $("#itemid2").val(itemid2); 
		  
		    var plotno2 = $(this).data('plotno');
		   $("#plotno2").val(plotno2); 
		     
		    var houseno2 = $(this).data('houseno');
		   $("#houseno2").val(houseno2); 
		  
		   
        });
		
			 $(document).on("click", "#managebtncheckout", function()
        {
          var itemid2 = $(this).data('id');
		  $("#itemid2").val(itemid2); 
		  
		     var status = $(this).data('status');
		  $("#status").val(status); 
		     var certificateno = $(this).data('certificateno');
		  $("#certificateno").val(shares); 
		  		     var shares = $(this).data('shares');
		  $("#shares").val(shares); 
		   
        });
		
    </script> 
<style type="text/css">
  
  

    #printableArea { display: none; }
#print{  	


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


}
#alltitle{ font-size: 1em; }
	#mytitle { font-size: 1.5em; }
#sale{  	


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


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




<ul class="nav nav-tabs bordered" id="non-printable">

			
						<li  class="active">
            	<a href="#thirdtab" data-toggle="tab"><i class="entypo-plus-circled"></i>
					Receive Payment  
                    	</a></li>
						
						
						<li>
            	<a href="#payment" data-toggle="tab"><i class="entypo-menu"></i> 
					Payment history
					
					
                    	</a></li>
						
						<li>
            	<a href="#list" data-toggle="tab"><i class="entypo-menu"></i> 
					Pending invoices  for this House
					
					
                    	</a></li>
						
								<li>
            
														 <a   id="more" href="<?php echo base_url();?>admin/receivepayment?randomitemidentifier=<?php   {echo  $houseno;}  ?>&randomitemidentifier1=<?php   {echo  $plotno;}   ?>">	Refresh  </a>

				
                    	</li>
						
						
						
							<li>
            
														 <a   id="more" href="<?php echo base_url();?>admin/rentinvoice?randomitemidentifier=<?php   {echo  $houseno;}  ?>&randomitemidentifier1=<?php   {echo  $plotno;}   ?>">	New Invoice  </a>

				
                    	</li>
						
							<li>
            
														 <a   id="more" href="<?php echo base_url();?>admin/viewplot?randomitemidentifier=<?php   {echo  $plotno;}  ?>&category=<?php echo $category; ?>">Back to	Other House  </a>

				
                    	</li>
									<li>
            
														 <a   id="more" href="<?php echo base_url();?>admin/overpayment">Back to	Over payemnt  </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'); 
					
					  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;
					}
					

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

 <div class="panel panel-primary" data-collapsed="0">
 	<div class="pull-right"  id="non-printable">

<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('example')" value="print receipt!" />
</form></div>
<table id="example"  cellspacing="1" class="table table" width="100%">
             <thead>
			
			
         <tr>
    
    <th>Hs No </th>
	<th>Plot No</th>
    
	<th>Mode</th> 	
	<th>Tenant </th> 
	<th>Amount </th> 
		<th>Code </th> 
			<th>Overpayemnt </th> 
	<th>Reason </th> 
			
	<th> Payment Date </th> 
	<th> Uploaded Date </th> 
	<th> Paid By: </th> 
		<th> Added By: </th> 
 <th  id="non-printable" > Print: </th> 
	 
	 <th  id="non-printable" > Monthly: </th> 

	 <th  id="non-printable" > More: </th> 


                 </tr>
            </thead>
<?php

	
		
	
	 $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'];	
				echo $this->session->flashdata('msg'); 
 
		if(validation_errors()):
		 endif;
 if(!is_array($payment)) 

 {



  
    }else {
?>
    
             <?php 
  
  	foreach ($payment as $c): 

		 

             ?>



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


?>

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



$paymentsectionbyid= $this->usermodel->populateall('glaccounts','number',$c->paymentmode);
					


if(is_array($paymentsectionbyid)) {

   foreach($paymentsectionbyid as $paymentsectionbyidrow){

  echo $paymentsectionbyidrow->accountname ; 
    

}} else {
	
	 $paymentsectionbyid = $this->accomodationmodel->getpaymentsectionid($c->paymentmode);
								


if(is_array($paymentsectionbyid)) {

   foreach($paymentsectionbyid as $paymentsectionbyidrow){

  echo $paymentsectionbyidrow->name ; 
    

}} else {
    echo 'No mode';
}

	
   
}








 






?></td> 
					

              
				 				         <td><?php 
					
   $tenantid=$c->tenantid;
				    $tenants = $this->accomodationmodel->gettenantbyid($tenantid);
 if(is_array($tenants)) {
   foreach($tenants as $tenantsrow){

    $names=$tenantsrow->lastname. " ".$tenantsrow->firstname ; 
   
   ?>
   
                     <a class="btn btn-warning" id="non-printable" target="_blank"  id="more" href="<?php echo base_url();?>admin/edittenant?randomitemidentifier=<?php   {echo  $tenantid;}  ?>"><?php   {echo  $names;}  ?>  </a>

   
   <span id="printableArea">
<?php
echo $names;
?>

   </span>
   <?php
    

}
    } else {
    echo 'No tenant.';
}
?>
				 
				 
		</td>
				
				       <td><?php echo formatMoney($c->amount,true) ; ?></td>
					      <td><?php echo $c->paymentcode ; ?></td>
					      <td><?php echo $c->overpayment ; ?></td>
					   <td><?php echo $c->paymentstatus ; ?></td> 
					         <td><?php echo $c->exactime; ?></td>
                     <td><?php echo $c->createdat; ?></td>
					     <td><?php echo 
						 
						 
						 $c->paidby; ?></td> 
						 
						 
						 

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

$mycustomer=$this->usermodel->populateallarray('people','id', $customer);
			echo$myname=$mycustomer[0]['firstname'];

 ?></td>
						 
						 
						 
						 
						 
				
         						<td  id="non-printable" >
						<?php
						
						$typs=$c->paymentstatus ;
						if ($typs=="receipt"){
							?>
			 <a class="btn btn-primary"  target="_blank" id="more" href="<?php echo base_url();?>admin/housereceiptbynorent?randomitemidentifier=<?php   {echo  $c->id;}  ?>&plotno=<?php   {echo  $c->plotno;}  ?>&houseno=<?php   {echo  $c->houseno;}  ?>&nyumbaid=<?php   {echo  $c->tenantid;} ?>">Print  </a>

						
						

				
						
						<?php
						}
						?>
				
				</td>
				
							<td  id="non-printable" >
						<?php
						
						$typs=$c->paymentstatus ;
						if ($typs=="receipt"){
							?>

						
						
				                     <a class="btn btn-primary" target="_blank"  id="more" href="<?php echo base_url();?>admin/allhousereceiptbynorent?randomitemidentifier1=<?php   {echo  $c->id;}  ?>&plotno=<?php   {echo  $c->plotno;}  ?>&houseno=<?php   {echo  $c->houseno;} ?>&nyumbaid=<?php   {echo  $c->tenantid;} ?>">Print (Month)  </a>

				
						
						<?php
						}
						?>
				
				</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  id="more" class="btn btn-info" href="<?php echo base_url();?>admin/rentreceiptdetails?transactioncode=<?php echo $c->transactioncode ;  ?>"> View Utilities Paid  </a>

                                        </li>
                                              <li class="divider"></li>
										<?php
										if($usertype=="admin"){
											
											?>
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete2"	 data-amount='<?php echo  $c->amount;?>'	 data-id='<?php echo  $c->id;?>'   data-plotno='<?php echo  $c->plotno;?>'  data-toggle='modal' data-target='#deleteModal<?php  $c->id; ?>'>	 


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

             <?php endforeach; ?>

              <?php }?>
			  


        </table>


</div>

</div>
	
<div class="tab-pane box" id="list" style="margin:0">
				
     


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

    <th>House No </th>
	<th>Plot Name</th>
    
	<th>Type</th> 	
	<th>Tenant </th> 
	<th>Amount </th> 
	<th>Paid </th> 
	<th>Balance </th> 
		<th> Description</th> 
	
	<th> Invoice Date </th> 
	<th>Due Date</th> 
		<th>More</th> 
  <!---<th>Delete</th> -->
	 




                 </tr>
             </thead>
<?php

	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'];	
		if(validation_errors()):
		 endif;
 if(!is_array($invoice)) 

 {



   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='12'>";
    
       echo '<div class="alert alert-warning text-center">There is no invoice found by now from system..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  
   $totalbalance= 0;
  $totalinvoice=0;
    $totalpaid=0;
  	foreach ($invoice as $c): 
	 $confirm= $this->accomodationmodel->confirmrentpayments($c->companyid,$c->transactioncode);
$amount=$confirm[0]["amount"];
$paid=$confirm[0]["paid"];
$balance=$c->amount-$paid;
$totalpaid=$totalpaid+$paid;
		   $totalinvoice= $totalinvoice+$c->amount ;
   $totalbalance=  $totalinvoice-$totalpaid;


		 

             ?>



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


?>
    <td><?php echo $c->id ; ?></td> 
             <td><?php echo $c->houseno ; ?></td> 
				<td><?php echo $c->plotno ; ?></td> 
<td><?php echo $c->paymentstatus ; ?></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;
}
				 
				 
				 
				 
				 
				 ?></td>
					   			    <td><?php echo formatMoney($c->amount,true) ; ?></td>
										   			       <td><?php echo formatMoney($paid,true) ; ?></td>
														       <td><?php echo formatMoney($balance,true) ; ?></td>

					   <td><?php echo $c->description ; ?></td> 
					      
                     <td><?php echo $c->createdat; ?></td>
					     <td><?php echo $c->exactime; ?></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>
									
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                 
										
										<li>
												 						<a  id="more" class="btn btn-info" href="<?php echo base_url();?>admin/rentinvoicedetails?transactioncode=<?php echo $c->transactioncode ;  ?>"> View Utilities Invoiced  </a>

                                        </li>
                                              <li class="divider"></li>
										<?php
										if($usertype=="admin"){
											
											?>
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete"	 data-houseno='<?php echo  $c->houseno;?>'	 data-id='<?php echo  $c->id;?>'   data-plotno='<?php echo  $c->plotno;?>' data-transactioncodes='<?php echo  $c->transactioncode;?>'  data-toggle='modal' data-target='#myModal2<?php  $c->id; ?>'>	 


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

             <?php endforeach; ?>

              <?php }?>
	   <tfoot>
<th>
    <td colspan="4">Total invoice</td> 
 					   				 

	 <td ><b><?php 
	if(isset($totalinvoice)) {echo formatMoney($totalinvoice,true) ; }
	 ?> </b></td > 
	     <td>TT Balance</td> 
	 <td colspan="5"><b><?php 
	if(isset($totalbalance)) {echo  formatMoney($totalbalance,true) ;}
	 ?> </b></td > 
		 
		 

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



</div>

</div>
		<!----CREATION FORM STARTS---->
		
   <div id="myModal2" 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 Invoice  </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="view" value="invoice">
 <input type="hidden" id="transactioncodes"  name="transactioncode" class="transactioncodes" placeholder="transactioncodes" value="">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/invoice?randomitemidentifier=">
  <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" 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"> Delete  </button>

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

  </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">Cancel Payment</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to Cancel  this Payment? </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="receipt">

 
 
  <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/receivepayment?randomitemidentifier=">
  <input type="hidden" id="view2"name="view2" class="view2" placeholder="view" value="&randomitemidentifier1=">
 
 
 
 
 
 
 <input type="hidden" id="houseno2"name="houseno" class="houseno" placeholder="houseno" value=""><br>

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

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

  </div>

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



		
<div class="row">
	<div class="col-md-12">
		<div class="panel panel-primary" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" >
            		<i class="entypo-plus-circled"></i>
			RECEIVE PAYMENTYS
            	</div>
            </div>
			<div class="panel-body">





				<?PHP
				 if (isset($_GET['myoriginalamount'])){

        $paymentid=$_GET['paymentid'];
      $originalamount=$_GET['myoriginalamount'];
    }else if(isset($originalamount)) {
	    $paymentid=$paymentid;
		$originalamount= $originalamount;
	}
				
				$customerpaymentdetails="";
				
				echo $this->session->flashdata('msg'); 
		 $date = Date('Y-m-d') ;
		 	 $year = Date('Y') ;
		  $month = Date('m') ;
		  
		  
		  
		  if($tenantid !=""){
			                  echo form_open('verifyinvoice' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
 
			  
		  }else{
			  
						                  echo form_open('admin/viewpallmyplots' , 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="inputoriginalamount" class="col-sm-2 control-label">Paid Amount</label>
    <div class="col-sm-7">
					<input type="hidden" name="paymentid" value="<?php if(isset($paymentid)) {echo   $paymentid; }?> " id="paymentid" class="form-control"  placeholder="Enter paymentid">

				<input type="text" name="originalamount" value="<?php if(isset($originalamount)) {echo   $originalamount; }?> " id="originalamount" class="form-control" required placeholder="Enter amount">
        <span class="text-danger"><?php echo form_error('originalamount'); ?></span>
	</div>
  </div>
  


  <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Payment Mode</label>
    <div class="col-sm-7">
				    	
						
						
			
			  	<select name="paymentmode"  required class="form-control" >
<option value="" >---Select Payment Mode---</option>

<?php 
//		

		if(isset($paymentmode)) {   
			 

					 $allmethods= $this->usermodel->populateall('glaccounts','number',$paymentmode);



if(is_array($allmethods)) {

   foreach($allmethods as $methodsrows){

  // echo $leavetyperow->name;
  ?>

  			 								<option selected="selected" value="<?php echo $methodsrows->number;   ?>"><?php echo $methodsrows->accountname;   ?></option>

 <?php
}} else {
    echo 'No type';
}
			 
			 
			
			 

			  }









	

//$nation = $this->nationmodel->populatenation();


if(is_array($methode)) {

   foreach($methode as $methoderow){

    ?>
	    <option value="<?php echo set_value('mode',$methoderow->number); ?> "><?=$methoderow->accountname?></option>

   
    <?php

}} else {
    echo 'There is no other  payment mode for this house.... PLease add charges first.';
}
			  
?>
	</select>
				

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



 
 <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Paid By</label>
    <div class="col-sm-7">
       	<input type="hidden" name="tenantid" value="<?php echo set_value('tenantid',$tenant[0]['tenantid']); ?>" id="idno" class="form-control" required placeholder="Enter Name">
 
		
		<?php 
		$tenantid=$tenant[0]['tenantid'];
		$tenantsdetails = $this->accomodationmodel->gettenantbyid($tenantid);
								
 

if(is_array($tenantsdetails)) {

   foreach($tenantsdetails as $tenantsdetailsrow){

	$customerpaymentdetails = "Payment for Hs No.".$houseno." and Plot No.".$plotno;

    $names=$tenantsdetailsrow->lastname. " ".$tenantsdetailsrow->firstname ; 
    ?>

	<input type="text" name="mytenantid" value="<?php echo set_value('tenantid',$names); ?>" id="idno" class="form-control" required placeholder="Enter Name">

	<?php

}} else {
	
	$customerpaymentdetails="Payment received";
	
	
	
    		$this->session->set_flashdata('msg1','<div class="alert alert-danger text-center">Oops! Error. No tenant yet allocated.. Please allocate the room first for you to invoice it </div>');
	echo $this->session->flashdata('msg1');
}
				 
		
	?>	
		
		<span class="text-danger"><?php echo form_error('tenantid'); ?></span>
	</div>
  </div>
  
  
					
  <div class="form-group">

    <label for="inputhouseno" class="col-sm-2 control-label">House Number</label>
    <div class="col-sm-7">
			  		<input type="text" readonly name="houseno" value="<?php  echo $houseno ; ?>"id="invoiceno" class="form-control" required placeholder="Enter invoice number">
  		<input type="hidden" name="action" value="<?php echo set_value('action','insert'); ?>"id="action" class="form-control" required >


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

    <label for="inputplotno" class="col-sm-2 control-label">Plot Number</label>
    <div class="col-sm-7">
	<input type="text" name="plotno" readonly value="<?php  echo $plotno  ; ?>"id="plotno" class="form-control" required placeholder="Enter invoice number">
				<input type="hidden" name="paymentcode" value="<?php echo set_value('paymentcode'); ?>" id="idno" class="form-control"  placeholder="Enter paymentcode">


     <span class="text-danger"><?php echo form_error('plotno'); ?></span>
   </div>
  </div>
  <div class="form-group">
    <label for="inputvat" class="col-sm-2 control-label">VAT</label>
    <div class="col-sm-7">
				<input type="number" readonly name="vat" value="<?php echo set_value('vat',$houserent[0]['vat']); ?>" id="vat" class="form-control"  placeholder="Enter vat">
        <span class="text-danger"><?php echo form_error('vat'); ?></span>
	</div>
  </div>	 
  
  
  
  
    <div class="form-group">
    <label for="inputcommission" class="col-sm-2 control-label">Commission</label>
    <div class="col-sm-7">
				<input type="number" readonly name="commission" value="<?php echo set_value('commission',$houserent[0]['commission']); ?>" id="commission" class="form-control"  placeholder="Enter commission">
        <span class="text-danger"><?php echo form_error('commission'); ?></span>
	</div>
  </div>	 
  
     <div class="form-group">
    <label for="inputpaymentcode" class="col-sm-2 control-label">Payment Code</label>
    <div class="col-sm-7">
				<input type="text" name="paymentcode" value="<?php if(isset($paymentcode)) {echo   $paymentcode; }?>" id="paymentcode" class="form-control"  placeholder="Enter paymentcode">
        <span class="text-danger"><?php echo form_error('paymentcode'); ?></span>
	</div>
  </div>
		  
		 
   <div class="form-group">
    <label for="inputphone3" class="col-sm-2 control-label">Description </label>
    <div class="col-sm-7">
	<textarea name="description" id="ttt" rows="5" placeholder="add Description" class="form-control"><?php if(isset($description)) {echo   $description; }else { echo $customerpaymentdetails; }?>   </textarea>
    <span class="text-danger"><?php echo form_error('description'); ?></span>
   </div>
  </div>
    
    <div class="form-group">
    <div class="col-sm-offset-2 col-sm-7">
     
	       <button type="submit" name="btn_processpayment" value="process" class="btn btn-primary">Process Payment</button>

    </div>
  </div>
        

  





<table cellpadding="0" cellspacing="0" border="0" class="table  table" id="example1" style="border-color:#CCCCCC; width:100%;"  >


<?php 

if(is_array($myinvoice)) {
	?>
	<tr>

<th>#</th>  
<th>Invoice?</th>  
<th>Invoiced Date?</th>   
<th>Due Date?</th>   

    <th>Amount?</th>    
 
 <th>Payment date</th>  
<th>Amount to pay </th>  

  </tr>
	<?php
$finaltotal=$originalamount;
 $myfinaltotal=0;
  $myfinaltotal2=-1;
  $mypayment=0;
    $finalbalnce=0;
	 $mybalnce=0;
   foreach($myinvoice as $invoicerows){



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

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

?>


  	<tr>

<input type="hidden" readonly name="invoiceid[]" value="<?php echo set_value('invoiceid',$invoicerows->id); ?>" id="type" class="form-control" required placeholder="Enter invoiceid">
	
	
		<td>
<?php echo $myfinaltotal2+2; ?>
					 

	
</td>
<td>
			 <input type="hidden" readonly name="type[]" value="<?php echo set_value('invoiceid',$invoicerows->type); ?>" id="type" class="form-control" required placeholder="Enter type">
		 
<?php echo $chargename; ?>
	
</td>
	<td>
					 <input type="date" readonly name="createdat[]" value="<?php echo set_value('createdat',$invoicerows->createdat); ?>" id="createdat" class="form-control"  placeholder=" createdat">

	
</td>
	<td>
	
						 <input type="date" readonly name="duedate[]" value="<?php echo set_value('duedate',$invoicerows->duedate); ?>" id="duedate" class="form-control"  placeholder=" duedate">

	</td>
	  
	  
	  
	  
				 <td>
				 <input type="text" readonly name="amount[]" value="<?php echo set_value('amount',$invoicerows->amount); ?>" id="amount" class="form-control" required placeholder="Enter invoiceid">

				 
    </td>
  
     <td>
   				<input type="text" name="createdat" value="<?php echo set_value('createdat',$date); ?>" id="idno" class="form-control"  placeholder="Enter Start Date">

   </td>
    
 <td>
 <?php

 
 $amount=$invoicerows->amount;
  $paid=$invoicerows->paid;
  $invoiced=$amount-$paid;

	  $myfinaltotal=$myfinaltotal+$invoiced;
	 
	  
$balance=$originalamount-$myfinaltotal;


$mybalnce=$originalamount-$myfinaltotal;

  if($myfinaltotal2==-1){
  if($originalamount<$invoiced){

///echo 0;


		
		$mypayment= $originalamount;
	}else {
		
		
		$mypayment= $invoiced;
		
		
	}
  }else{
	  
	 $finalbalnce=$balance- -$invoiced;
	  
	   
	 
		   
		    if($finalbalnce>=$invoiced){
		   	$mypayment= $invoiced;
			}else if(($finalbalnce<=$invoiced) && ($finalbalnce>0)){
	   	$mypayment= $finalbalnce;
		 
			}else if(($finalbalnce<=$invoiced) && ($finalbalnce<0)){
	 	$mypayment= "0"; 
		 
			}else{
				
				$mypayment= "0"; 	
			}
	
		   
	 
	 
	  	
	  
	  
  }
	
	
	 //$balance=$originalamount-$invoiced;



 
 
 
 
 
?>

<input type="text"  name="payment[]" value="<?php echo set_value('payment',$mypayment); ?>" id="type" class="form-control" required placeholder="Enter invoiceid">


 
<?php

$myfinaltotal2=$myfinaltotal2+1;
}
if($mybalnce>0){
	
echo "<b>Over payment :".$mybalnce."</b>";

}else{
	echo "<b>Balance :".$mybalnce."</b>";

	
}
?>

<input type="hidden"  name="overpayment" value="<?php echo set_value('mybalnce',$mybalnce); ?>" id="type" class="form-control" required placeholder="Enter overpayment">
</td>
</tr>

<tr>
<td colspan="7">

  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-7">
     
	       <button type="submit" name="btn_postpayment" value="postpayment" class="btn btn-primary">Save Bulk Payment for this house</button>

    </div>
  </div>
 

</td>

</tr>



<?php


} else {
}


?>

	<?php echo form_close();?>

</table>
		  

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








	
			         <div id="Checkout" 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">Post Shares</h4>
      </div>
      <div class="modal-body">
        <h4>Are you sure you want to post Shares to this member Account? </h4>
    
    
	  	

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

		   $closedatedate=date("Y-m-d 10:01:01");
                 echo form_open('admin/updatadvancepayment' , 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"  value="advancepayment">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/viewalltenant">
 <input type="hidden" id="itemid2"name="itemid"  value=""><br>

   <div class="form-group">
    <label for="inputshares" class="col-sm-2 control-label">Total shares</label>
    <div class="col-sm-10">
				<input type="text" name="shares"  readonly value="<?php echo set_value('shares'); ?>" id="shares" class="form-control"  placeholder="Enter total shares">
        <span class="text-danger"><?php echo form_error('shares'); ?></span>
	</div>
  </div>
  
  <div class="form-group">
    <label for="inputcertificateno" class="col-sm-2 control-label">Certificate</label>
    <div class="col-sm-10">
				<input type="text" name="certificateno" readonly value="<?php echo set_value('certificateno'); ?>" id="certificateno" class="form-control" required placeholder="Enter certificateno">
        <span class="text-danger"><?php echo form_error('certificateno'); ?></span>
	</div>
  </div>
     <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Date Posted</label>
    <div class="col-sm-10">
				<input type="text" name="amount" value="<?php echo set_value('amount',$closedatedate); ?>" id="idno" class="form-control" required placeholder="Enter amount">
        <span class="text-danger"><?php echo form_error('amount'); ?></span>
	</div>
  </div>
  <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">No of Shares</label>
    <div class="col-sm-10">
				<input type="text" name="amount" value="<?php echo set_value('amount'); ?>" id="idno" class="form-control" required placeholder="Enter No of shares">
        <span class="text-danger"><?php echo form_error('amount'); ?></span>
	</div>
  </div>
  

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

				<textarea name="description" value="<?php echo set_value('description'); ?>"  class="form-control"  placeholder="Enter remarks"></textarea>
			
		<span class="text-danger"> <?php echo form_error('description'); ?>
		
		</span>
	</div>
  </div>
  
  	  <div class="form-group">
						<label for="field-2" class="col-sm-2 control-label">Status</label>
		                    <div class="col-sm-10">
		                        <select name="status" id="status" class="form-control" >

			                         <option value="active">active</option>
									   	 <option value="inactive">inactive</option>

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

			                </div>
	</div>	
		
   </div>
   <div class="modal-footer">
 
 		   		  	         <button type="submit" name="updateadvance" value="advance" class="btn btn-success"> Yes(Post payment)  </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 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>




			