 			
       <?php
       
       $mid = $_GET["mid"];
$sql_user_billrecord= "SELECT SUM(amount) as feepaidbalances FROM tbl_payments where payment_type = 'MD' and unique_id = '$mid'";
$result_user_billpay= mysqli_query($conn, $sql_user_billrecord);
$row_user_billpay_summary = mysqli_fetch_assoc($result_user_billpay);

$sql_user_readings1 = "SELECT sum(fee) as totalfee FROM tbl_meterdevice where account_no = '$mid' ";
$result_user_details2 = mysqli_query($conn, $sql_user_readings1);
$row_user_readings_summary = mysqli_fetch_assoc($result_user_details2);

$remainingbalance_summary = $row_user_readings_summary['totalfee'];
$billspayment_summary = $row_user_billpay_summary['feepaidbalances'];

$totalunpaidbill_wbhistory = $remainingbalance_summary - $billspayment_summary;

?>		
   <H4>Remaining Balance: <b style="color:#fd0000">&#8369;<?php echo number_format(($totalunpaidbill_wbhistory));?> </b> </h4>    
   
  
<table id="example1" class="table table-bordered table-hover">

<thead>
  <tr>
  <th width="5%">Type </th> 
 
  <th  width="10%">Paid</th>  
  <th  width="10%">MOP</th>  
                   
  <th width="10%" >Payment </th>
  <?php if (($_SESSION['username'] == 'MainAdmin')) {?>
  <th width="10%"> Action</td>
  <?php }else { ?>
                        <?php }?>>
 
</tr>
</thead>
<tbody>

<?php


// $acctno = "this. document.getElementById('id_u').value"
$result = mysqli_query($conn,"SELECT * FROM tbl_payments where unique_id = '$mid' and payment_type='MD'");
$i=1;
while($row = mysqli_fetch_array($result)) {
?>
<tr id="<?php echo $row["id"]; ?>">
                <td>
                     <?php echo $row["payment_type"]; ?>
               </td>
             
               <td>
                     <?php echo  '&#8369;'. $row["amount"]; ?>
               </td>
               <td>
                     <?php echo   $row["payment_option"]; ?>
               </td>
               <td>
                     <?php echo $row["payment_date"]; ?>
               </td>
               <?php if (($_SESSION['username'] == 'MainAdmin')) {?> <td> 
              
               <a href="#deletebillspay" class="deletebillspay btn btn-danger btn-radius" data-id="<?php echo $row["id"]; ?>" data-toggle="modal">
		 <i class="fas fa-trash-alt" data-toggle="tooltip" 
			  title="Delete"></i></a>

                  
                </td> 
                <?php }else { ?>
                        <?php }?>


</tr>
<?php
$i++;
}
?>
</tbody>
</table>
<!---END payment history RECORD -->
 