<?php

include("includes/header.php"); 
include("includes/sidebar.php"); 

$loans = $db_handle->runBaseQuery("SELECT * FROM loan_application WHERE userID = $id");

 ?>
 <div class="main-content app-content">
 	<div class="container-fluid">
 	    <div class="mt-3 d-flex justify-content-between align-items-center mb-3 p-4 rounded-4 shadow-sm text-white" 
     style="background: #C81D25;">
  
  <div>
    <h5 class="fw-bold mb-1 text-light">Loan History</h5>
    <p class="mb-0 opacity-75">Review your past and active loans in one place.</p>
  </div>

  <div>
    <i class="bi bi-piggy-bank-fill" style="font-size: 2.5rem;"></i>
  </div>
</div>
<div class="row mt-3">
            <div class="col-xl-12">
                <div class="card custom-card">
                    <div class="card-header justify-content-between border-bottom-0">
                        <div class="card-title"> All Loans </div>
                        
                    </div>
                    <div class="card-body p-3">
                        <div class="table-responsive">
                            <table class="table text-nowrap table-bordered" id="TableTab">
                                <thead>
                                    <tr>
                                        <th scope="col">#</th>
                                       
                                        <th scope="col">Amount</th>
                                       <!-- <th scope="col">Payment Type</th> -->
                                        <th scope="col">Interest</th>
                                        <th scope="col">Date Applied</th>
                                        <th scope="col">Expiring Date</th>
                                        <th scope="col">Status</th>
                                       
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php

                                    
                                    if($loans){
                                        $i = 1;
                                    foreach($loans as $loan){
                                   echo "<tr>";
                                    echo '<td class="fw-medium">'.$i.'</td>';

                                      echo '<td class="fw-medium">'.$loan['amount'].'</td>';
                                        echo '<td> <span class="fw-medium">'.number_format($loan['interest']).'</span></td>';
                                       
                                        echo '<td> <span class="">'.$loan['repayment_date'].'</span> </td>';
                                        echo '<td> <span class="">'.$loan['date'].'</span> </td>';
                                        
                                        echo '<td> <span class="">Running</span> </td>';
                                       
                                    echo '</tr>';

                                    $i++;
                                    
                                    }

                                }

                                ?>
                                    
                                   
                                   
                                </tbody>
                            </table>
                        </div>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
 </div>
  <?php

include("includes/footer.php"); 
 ?>