<?php
ob_start();
include('../include/db_conx.php');
isset($_SESSION['admin_login']);
if (!isset($_SESSION['admin_login'])) {
    header("location: auth-login.php");
    exit();
} else {
    include('../include/admin_head.php');

    include('../include/admin_action/info.php');

    $tradeDelete = $_GET['tradeDelete'];
    if ($tradeDelete == 'true') {
        $msg = 'Record Deleted Successfully';
        $link = 'loan_list.php?userID=' . $user_id;
        swal_success($msg, $link);
    }
    $approveLoan = $_GET['approveLoan'];
    if ($approveLoan == 'true') {
        $msg = ' Successfully Approved Loan';
        $link = 'loan_list.php?userID=' . $user_id;
        swal_success($msg, $link);
    }
?>



    <body>

        <!-- <body data-layout="horizontal"> -->

        <!-- Begin page -->
        <div id="layout-wrapper">

            <?php include('../include/admin_header.php'); ?>

            <!-- ========== Left Sidebar Start ========== -->

            <!-- Left Sidebar End -->
            <?php include('../include/admin_sidebar.php'); ?>



            <!-- ============================================================== -->
            <!-- Start right Content here -->
            <!-- ============================================================== -->
            <div class="main-content">

                <div class="page-content">
                    <div class="container-fluid">

                        <!-- start page title -->
                        <div class="row">
                            <div class="col-12">
                                <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                                    <h4 class="mb-sm-0 font-size-18">Loan Histories </h4>

                                    <div class="page-title-right">
                                        <ol class="breadcrumb m-0">
                                            <li class="breadcrumb-item"><a href="javascript: void(0);">Clients</a></li>
                                            <li class="breadcrumb-item active">Loan History</li>
                                        </ol>
                                    </div>

                                </div>
                            </div>
                        </div>
                        <!-- end page title -->





                        <div class="row">
                            <div class="col-lg-12">
                                <div class="card">
                                    <div class="card-body">
                                        <div class="row">
                                            <div class="col-sm order-2 order-sm-1">
                                                <div class="d-flex align-items-start mt-3 mt-sm-0">

                                                    <div class="flex-grow-1">
                                                        <div>
                                                            <h5 class="font-size-16 mb-1"><?php echo $first_name . ' ' . $last_name ?> </h5>
                                                            <p class="text-muted font-size-13">Billing Name</p>


                                                            <div class="d-flex flex-wrap align-items-start gap-2 gap-lg-3 text-muted font-size-13">
                                                                <div> <i class="fas fa-envelope "></i> <?php echo $email ?></div>
                                                                <div><i class=" fas fa-key "></i> Password: <?php echo $password ?></div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-sm-auto order-1 order-sm-2">
                                                <div class="d-flex align-items-start justify-content-end gap-2">
                                                    <a href='client_dashboard.php?userID=<?php echo $user_id ?>'>
                                                        <button type="button" class="btn btn-primary"><i class="me-1"></i> <i class="fas fa-chevron-left "></i> Return to details </button>
                                                    </a>

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

                                        <ul class="nav nav-tabs-custom card-header-tabs border-top mt-4" id="pills-tab" role="tablist">
                                            <li class="nav-item">
                                                <a class="nav-link px-3 active" data-bs-toggle="tab" href="#overview" role="tab">Loan History Section</a>
                                            </li>

                                        </ul>
                                    </div>
                                    <!-- end card body -->
                                </div>
                                <!-- end card -->
                            </div>
                            <!-- end col -->
                        </div>
                        <!-- end row -->

                        <div class="row">
                            <div class="col-12">
                                <div class="card">
                                    <div class="card-header">
                                        <h4 class="card-title">Deposit History</h4>
                                        <p class="card-title-desc">Below are all the list of all the Loan transactions carried our for the client selected. You can delete them if they appears invalid
                                        </p>
                                    </div>
                                    <div class="card-body">
                                        <table id="datatable-buttons" class="table table-bordered dt-responsive nowrap w-100">
                                            <thead>
                                                <tr>
                                                    <th style="display:none!important;">ID</th>
                                                    <th> Name</th>
                                                    <th>Amount </th>
                                                    <th>Reason </th>
                                                    <th>Type</th>
                                                    <th> Duration</th>
                                                    <th>Date Created </th>
                                                    <th>Status </th>
                                                    <th>Image Upload </th>
                                                    <th> Edit</th>
                                                    <th> Action</th>
                                                </tr>
                                            </thead>


                                            <tbody>
                                                <?php
                                                $sql_get_meta = "SELECT * FROM loan WHERE user_id = '$user_id' ";
                                                $query_get_meta = $db_conx->query($sql_get_meta);
                                                while ($row_meta = mysqli_fetch_assoc($query_get_meta)) {

                                                    $i_id = $row_meta['id'];
                                                    $name = $row_meta['name'];
                                                    $loan_amount = $row_meta['loan_amount'];
                                                    $reason = $row_meta['reason'];
                                                    $type = $row_meta['type'];
                                                    $tenure = $row_meta['tenure'];
                                                    $loan_date = $row_meta['loan_date'];
                                                    $loan_status = $row_meta['loan_status'];
                                                    $means_of_identification = $row_meta['means_of_identification'];
                                                    $photo = $row_meta['photo'];
                                                ?>
                                                    <tr role="row" class="odd">
                                                        <td class="sorting_1" style='display:none;'><?php echo $i_id ?></td>

                                                        <td><?php echo $name ?></td>

                                                        <td><?= $currency ?><?php echo number_format($loan_amount, 2) ?></td>
                                                        <td><?php echo $reason ?></td>
                                                        <td><?php echo $type ?></td>
                                                        <td><?php echo $tenure ?></td>
                                                        <td><?php echo $loan_date ?></td>
                                                        <td><?php if ($loan_status == 0) {
                                                                echo 'Pending';
                                                            } else {
                                                                echo 'Approved';
                                                            }
                                                            ?></td>
                                                        <td>
                                                            <a href='view_loan_img.php?docID=<?php echo $photo ?>&userID=<?php echo $user_id ?>'>
                                                                <img src="../../user/loan_id/<?php echo $photo ?>" alt="" class="rounded-circle avatar-sm d-block m-auto">
                                                            </a>

                                                        </td>
                                                        <td>
                                                            <?php
                                                            if ($loan_status == 0) {
                                                            ?>
                                                                <a class='text-primary' href='../include/admin_action/approve_loan.php?userID=<?php echo $user_id ?>&loanID=<?php echo $i_id ?>&amt=<?= $loan_amount ?>'>
                                                                    <button type="button" class="btn btn-success">Approve</button>
                                                                </a>
                                                            <?php } else {

                                                            ?>
                                                                <a class='text-primary ' href='#'>
                                                                    <button type="button" class="btn btn-success" style='cursor:not-allowed'>Approve</button>
                                                                </a>
                                                            <?php   } ?>
                                                        </td>

                                                        <td>
                                                            <a class='text-danger' href='../include/admin_action/delete_loan.php?userID=<?php echo $user_id ?>&deleteID=<?php echo $i_id ?>&docID=<?= $photo ?>'>
                                                                <i class="fas fa-trash-alt"></i> Delete
                                                            </a>
                                                        </td>

                                                    </tr>

                                                <?php
                                                }
                                                ?>

                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <!-- end cardaa -->
                            </div> <!-- end col -->
                        </div> <!-- end row -->


                    </div> <!-- container-fluid -->
                </div>
                <!-- End Page-content -->


                <?php include('../include/admin_footer.php'); ?>
            </div>
            <!-- end main content-->

        </div>
        <!-- END layout-wrapper -->




        <!-- Right bar overlay-->
        <div class="rightbar-overlay"></div>

        <script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
        <script src="assets/libs/metismenu/metisMenu.min.js"></script>
        <script src="assets/libs/simplebar/simplebar.min.js"></script>
        <script src="assets/libs/node-waves/waves.min.js"></script>
        <script src="assets/libs/feather-icons/feather.min.js"></script>
        <!-- pace js -->
        <script src="assets/libs/pace-js/pace.min.js"></script>

        <!-- flatpickr js -->
        <script src="assets/libs/flatpickr/flatpickr.min.js"></script>

        <!-- Required datatable js -->
        <script src="assets/libs/datatables.net/js/jquery.dataTables.min.js"></script>
        <script src="assets/libs/datatables.net-bs4/js/dataTables.bootstrap4.min.js"></script>



        <!-- Responsive examples -->
        <script src="assets/libs/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
        <script src="assets/libs/datatables.net-responsive-bs4/js/responsive.bootstrap4.min.js"></script>

        <!-- init js -->
        <script src="assets/js/pages/invoices-list.init.js"></script>

        <script src="assets/js/app.js"></script>
        <!-- <script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=" crossorigin="anonymous"></script> -->

        <script>
            $(document).ready(function() {
                $("#datatable").DataTable(), $("#datatable-buttons").DataTable({
                    lengthChange: !1,
                    buttons: ["copy", "excel", "pdf", "colvis"]
                }).buttons().container().appendTo("#datatable-buttons_wrapper .col-md-6:eq(0)"), $(".dataTables_length select").addClass("form-select form-select-sm")
            });
        </script>


    </body>


    </html>

<?php  }
ob_end_flush();

?>