<?php

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

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

 ?>
 <div class="main-content app-content">
 	<div class="container-fluid">
<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-0">
                        <div class="table-responsive">
                            <table class="table text-nowrap table-bordered" id="TableTab">
                                <thead>
                                    <tr>
                                        <th scope="col">#</th>
                                       <th scope="col">Name</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">Repayment Date</th>
                                        <th scope="col">Status</th>
                                        <!--<th scope="col">Action</th>-->
                                       
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    if($loans){
                                        $i = 1;
                                    foreach($loans as $loan){
                                        $userID = ($loan['userID']);

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

                                                    $name = $user[0]['first_name']." ".$user[0]['surname'];
                                                if($loan['status'] == 0){
                                                $status = "PENDING";
                                            }elseif($loan['status'] == 1){
                                                $status = "APPROVED";
                                            }else{
                                                $status = "DECLINED";

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

                                       /* echo '<td>
                                            <div class="btn-list"> <button class="btn btn-sm btn-icon btn-success-light rounded-circle" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Edit"><i class="ri-pencil-line lh-1 align-middle"></i></button> <button class="btn btn-sm btn-icon btn-danger-light rounded-circle" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Delete"><i class="ri-delete-bin-line lh-1 align-middle"></i></button> </div>
                                        </td>';*/
                                       
                                    echo '</tr>';

                                    $i++;
                                    
                                    }

                                }

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

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