<?php
    session_start();
    if( !isset($_SESSION['chap']) ){
        header("Location:../index.html#login-area");
        exit();
    }
    else{
        $chap = $_SESSION['chap'];
        include "../connect/db.php";
        $sql = mysqli_query($mysqli,"SELECT * FROM users WHERE email = '$chap' ");
        $row = mysqli_fetch_assoc($sql);
        if( $row['status'] == "suspended" ){
            header("Location:account.php");
            exit();
        }
        else if( $row['status'] == "terminated" ){
            header("Location:terminate.php");
            exit();
        }
    }
    



       if($row['kyc_status'] == "pending" || $row['kyc_status'] == "review" )


{
   header("Location:kyc.php");
   exit();


}
    if($row['code_level'] != "nothing"){

if($row['lock_status'] == "active" )


{
   header("Location:auth.php");
   exit();


}
else{
    
}



}
else{
    
}
    



?>
<!DOCTYPE html>
<html lang="en-US" class="js">

<head>
    <meta charset="utf-8">
    <meta name="author" content="Smart">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description"
        content="Aspire Securities is a trademark of Aspire Financial Corporation. Aspire Securities is a trade name for the corporate and investment banking services of Aspire Financial Corporation and its subsidiaries. All rights reserved. Securities and strategic advisory services are provided by Aspire Securities, Inc., member FINRA, link opens in new tab and SIPC, link opens in new tab. Lending, financial risk management, and treasury management and payment services are offered by Aspire Bank. Deposit products are offered by Aspire Bank.">
    <!-- Fav Icon  -->
    <link rel="shortcut icon" href="../images/favicon.png">
    <!-- Page Title  -->
    <title><?=$row['firstname']?> <?=$row['middlename']?> <?=$row['lastname']?> | <?= htmlspecialchars(getSetting('site_name', 'Deutsche Bank Holdings Delaware')) ?> Online banking</title>
    <!-- StyleSheets  -->
    <link rel="stylesheet" href="../scss/sweetalert.css">
    <link rel="stylesheet" href="assets/css/dashlite.css?ver=2.4.0">
    <link id="skin-default" rel="stylesheet" href="assets/css/theme.css?ver=2.4.0">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">

    <link href="../css/toastr.css" rel="stylesheet" />
</head>
<link rel="stylesheet"
    href="https://www.jqueryscript.net/demo/jQuery-International-Telephone-Input-With-Flags-Dial-Codes/build/css/intlTelInput.css">
<script type="text/javascript">
    function googleTranslateElementInit() {
        new google.translate.TranslateElement({ pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE }, 'google_translate_element');
    }
</script>
<script type="text/javascript"
    src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
    <script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=" crossorigin="anonymous"></script>
<style>
    .goog-te-gadget-simple {
        border: none;
    }

    .goog-te-gadget-simple a {
        color: #000;
    }
</style>
<style type="text/css">
    .btn-primary {
        background-color: #033d75;
    }

    .btn-secondary {
        background-color: #d13636;
    }

    .btn-secondary:hover {
        opacity: 0.6;
    }

    .btn-primary:hover {
        opacity: 0.6;
    }
</style>

<body class="nk-body npc-crypto bg-white has-sidebar ">
    <div class="nk-app-root">
        <!-- main @s -->
        <div class="nk-main ">
            <!-- sidebar @s -->
            <div class="nk-sidebar nk-sidebar-fixed " data-content="sidebarMenu">
                <div class="nk-sidebar-element nk-sidebar-head" style="border-bottom: solid #fe473a;">
                    <div class="nk-sidebar-brand">
                        <a href="dashboard" class="logo-link nk-sidebar-logo">
                            <img class="logo-light logo-img" src="../logo.png" srcset="../logo.png 2x" alt="logo">
                            <img class="logo-dark logo-img" src="../logo.png" srcset="../logo.png 2x" alt="logo-dark">

                        </a>
                    </div>
                    <div class="nk-menu-trigger mr-n2">
                        <a href="#" class="nk-nav-toggle nk-quick-nav-icon d-xl-none" data-target="sidebarMenu"><em
                                class="icon ni ni-arrow-left"></em></a>
                    </div>
                </div><!-- .nk-sidebar-element -->
                <?php include 'includes/sidebar.php'?>

                <!-- main header @e -->

                <div class="nk-content nk-content-fluid">
                    <div class="container-xl wide-lg">
                        <div class="nk-content-body">
                            <div class="buysell">
                                <div class="buysell-nav text-center">
                                    <ul class="nk-nav nav nav-tabs nav-tabs-s2">
                                    <li class="nav-item">
        <a class="nav-link active" href="#" id="new-loan-tab">New Loan Request</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" href="#" id="loan-history-tab">Loan History</a>
    </li>
                                    </ul>
                                </div><!-- .buysell-nav -->
                              <div   id="loanform">
                              <div class="buysell-title text-center">
                                    <h2 class="title">Apply For  <?= htmlspecialchars(getSetting('site_name', 'Deutsche Bank Holdings Delaware')) ?>  Loan</h2>
                                </div><!-- .buysell-title -->
                                <div class="buysell-block">
                                    <form action="../scripts/auth?action=loanRequest" class="buysell-form"
                                        id="loanRequest" method="post">
                                        <div class="buysell-field form-group">
                                            <div class="form-label-group">
                                                <label class="form-label">Disbursement Account:</label>
                                            </div>

                                            <div class="dropdown buysell-cc-dropdown">
                                                <a href="#" class="buysell-cc-choosen dropdown-indicator"
                                                    data-toggle="dropdown">
                                                    <div class="coin-item coin-btc">
                                                        <div class="coin-icon">
                                                            <em class="icon ni ni-wallet"></em>
                                                        </div>
                                                        <div class="coin-info">
                                                            <span class="coin-name">Checking Account (<?=currencySymbol($row['usercurrency'])?>)</span>
                                                            <span class="coin-text">Available Balance: <?=formatCurrency($row['checking_balance'], $row['usercurrency'])?></span>
                                                        </div>
                                                    </div>
                                                </a>
                                                <div class="dropdown-menu dropdown-menu-auto dropdown-menu-mxh">
                                                    <ul class="buysell-cc-list">
                                                        <li class="buysell-cc-item selected">
                                                            <a href="#" class="buysell-cc-opt" data-currency="btc">
                                                                <div class="coin-item coin-btc">
                                                                    <div class="coin-icon">
                                                                        <em class="icon ni ni-wallet"></em>
                                                                    </div>
                                                                    <div class="coin-info">
                                                                        <span class="coin-name">Checking Account
                                                                            (<?=currencySymbol($row['usercurrency'])?>)</span>
                                                                        <span class="coin-text">Available Balance: <?=formatCurrency($row['checking_balance'], $row['usercurrency'])?></span>
                                                                    </div>
                                                                </div>
                                                            </a>
                                                        </li>
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="buysell-field form-group">
                                            <div class="form-label-group">
                                                <label class="form-label" for="buysell-amount">Loan Amount</label>
                                            </div>
                                            <div class="form-control-group">
                                                <input type="number" step="any"
                                                    class="form-control form-control-lg form-control-number" id="amt"
                                                    min="150" max="150000" name="amt" placeholder="200.00" required>
                                                <div class="form-dropdown">
                                                    <div class="text"><?=currencySymbol($row['usercurrency'])?></div>
                                                </div>
                                            </div>
                                            <div class="form-note-group">
                                                <span class="buysell-min form-note-alt">Minimum:150 <?=currencySymbol($row['usercurrency'])?></span>
                                                <span class="buysell-rate form-note-alt">Maximum:150,000 <?=currencySymbol($row['usercurrency'])?></span>
                                            </div>
                                        </div><!-- .buysell-field -->
                                        <div class="row">
                                            <div class="buysell-field form-group col-lg-6">
                                                <div class="form-label-group">
                                                    <label class="form-label" for="buysell-amount">Credit
                                                        Facility</label>
                                                </div>
                                                <div class="form-control-group">
                                                    <select type="text" class="form-control form-control-lg"
                                                        id="credit_facility" name="credit_facility" required>
                                                        <option selected value="">Select Loan/Credit Facility</option>
                                                        <option value="Personal Home Loans">Personal Home Loans</option>
                                                        <option value="Joint Mortgage ">Joint Mortgage </option>
                                                        <option value="Automobile Loans ">Automobile Loans </option>
                                                        <option value="Salary loans">Salary loans</option>
                                                        <option value="Secured Overdraft">Secured Overdraft</option>
                                                        <option value="Contract Finance">Contract Finance</option>
                                                        <option value="Secured Term Loans">Secured Term Loans</option>
                                                        <option value="StartUp/Products Financing">StartUp/Products
                                                            Financing</option>
                                                        <option value="Local Purchase Orders Finance">Local Purchase
                                                            Orders Finance</option>
                                                        <option value="Operational Vehicles">Operational Vehicles
                                                        </option>
                                                        <option value="Revenue Loans and Overdraft">Revenue Loans and
                                                            Overdraft</option>
                                                        <option value="Retail TOD">Retail TOD</option>
                                                        <option value="Commercial Mortgage">Commercial Mortgage</option>
                                                        <option value="Office Equipment">Office Equipment</option>
                                                        <option value="Health Finance Product Guideline">Health Finance
                                                            Product Guideline</option>
                                                        <option value="Health Finance">Health Finance</option>
                                                    </select>
                                                </div>

                                            </div><!-- .buysell-field -->
                                            <div class="buysell-field form-group col-lg-6">
                                                <div class="form-label-group">
                                                    <label class="form-label" for="buysell-amount">Repayment
                                                        Tenure</label>
                                                </div>
                                                <div class="form-control-group">
                                                    <select type="text" class="form-control form-control-lg" id="tenure"
                                                        name="tenure" required>
                                                        <option value="" selected>Payment Tenure</option>
                                                        <option value="6">6 Months</option>
                                                        <option value="12">12 Months</option>
                                                        <option value="24">2 Years</option>
                                                        <option value="36">3 Years</option>
                                                        <option value="48">4 Years</option>
                                                        <option value="60">5 Years</option>
                                                    </select>
                                                </div>

                                            </div>
                                            <div class="buysell-field form-group col-lg-12">
                                                <div class="form-label-group">
                                                    <label class="form-label" for="buysell-amount">Purpose</label>
                                                </div>
                                                <div class="form-control-group">
                                                    <textarea type="text" class="form-control form-control-lg" cols="8"
                                                        id="purpose" name="purpose"
                                                        placeholder="Briefly exlain why you're requesting for this loan"
                                                        required></textarea>
                                                </div>

                                            </div>
                                        </div>
                                        <hr>
                                        <p class="title lead">You are requesting for an instant loan, By continueing,
                                            you have agreed and accepted the  <?= htmlspecialchars(getSetting('site_name', 'Deutsche Bank Holdings Delaware')) ?>  digital loan terms and
                                            conditions.</p>
                                        <strong class="text-center bold">Terms & Conditions</strong>
                                        <ul class="list list-sm list-checked">
                                            <li>Interest Rate: 4.3%.</li>
                                            <li>Management Fee: 3%.</li>
                                            <li>Credit Life Insurance Fee: 0.8%.</li>
                                            <li>Penal Charge: 3.5%.</li>
                                            <li>Repayment must be made according to my preffered repayment tenure.</li>
                                            <li>I waive 3-days maximum cooling off period to enable disbursement.</li>
                                            <li>I accept that  <?= htmlspecialchars(getSetting('site_name', 'Deutsche Bank Holdings Delaware')) ?>  reserved the right to decline my loan
                                                request.</li>
                                        </ul>
                                        <div id="Result"></div>
                                        <div class="buysell-field form-action">
                                            <span  class="btn btn-lg btn-block btn-primary"
                                                onclick="loanApplication()">Continue</span>
                                        </div>
                                    </form><!-- .buysell-form -->
                                </div><!-- .buysell-block -->



                              </div>








<div id="loan-history"  style="display: none;">
                    <div class="card card-preview ">
                        <div class="card-inner p-0" style="overflow-x:auto;">
                            <table class="datatable-init table" style="width:100%;min-width:700px;">
                                <thead>
                                    <tr>
                                        <th>Credit Facility </th>
                                        <th>Purpose</th>
                                        <th>Tenure</th>
                                        <th>Amount</th>
                                        <th>Date </th>
                                        <th>Status</th>
                                    </tr>
                                </thead>
                                <tbody>

                                <?php
                   
                   
                   $crabs = mysqli_query($mysqli,"SELECT * FROM loan WHERE user = '$chap' ORDER  BY id DESC ");
                   $brows = mysqli_num_rows($crabs);

                  
                   if( $brows == 0 ){
                     
                   }
                   else{
                       $i = 1;
                       while($xrow = mysqli_fetch_assoc($crabs)){
                        if($xrow['status'] == "Completed"){

                            $text ="success";
                            
                                                    }
                                                    else if($xrow['status'] == "Pending"){
                            
                                                        $text ="warning";
                                                        
                                                                                }
                                                    else{
                                                        $text ="danger";
                            
                                                    }



                         
                           echo'
                           <tr>
                           <td>'.$xrow['credit_facility'].'</td>
                           <td>'.$xrow['purpose'].'</td>
                           <td>'.$xrow['tenure'].'</td>
                           <td><b>'.currencySymbol($row['usercurrency']).'</b>'.$xrow['amt'].'</td>
                           <td>'.$xrow['date'].'</td>
                           <td><strong class="text-'.$text.'">'.$xrow['status'].'</strong></td>
                       </tr>

                               
            
                                  '
                           ;
                           $i++ ;
                         
                       }                                                    
                   }
            
               
               
               
               ?>          





























                                  
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>

</div>




<script>
   $(document).ready(function() {
    // Function to show the New Loan Request form
    $('#new-loan-tab').click(function(e) {
        e.preventDefault(); // Prevent the default anchor behavior
        
        // Show the loan request form and hide the loan history
        $('#loanform').show();
        $('#loan-history').hide();

        // Add active class to the New Loan Request tab
        $(this).addClass('active');
        // Remove active class from the Loan History tab
        $('#loan-history-tab').removeClass('active');
    });

    // Function to show the Loan History
    $('#loan-history-tab').click(function(e) {
        e.preventDefault(); // Prevent the default anchor behavior
        
        // Show the loan history and hide the loan request form
        $('#loan-history').show();
        $('#loanform').hide();

        // Add active class to the Loan History tab
        $(this).addClass('active');
        // Remove active class from the New Loan Request tab
        $('#new-loan-tab').removeClass('active');
    });
});


</script>










                            </div><!-- .buysell -->
                        </div>
                    </div>
                </div>

                <script src="../js/jquery.min.js"></script>
               

<script>
    /*--------------------------
Simplified sweetaalert
---------------------------- */
function toastAlert(bool1,pos,bool2,time,kind,msg){

const Toast = Swal.mixin({
  toast: bool1,
  position: pos,
  showConfirmButton: bool2,
  timer: time
});

Toast.fire({
  type: kind,
  title: msg
});
}
    /*--------------------------
Loan Application
---------------------------- */
function loanApplication(){
    let amt = $("input[name=amt]").val();
    let credit_facility = $("#credit_facility").val();
let tenure = $("#tenure").val();
let purpose = $("#purpose").val();

if (amt == "" || amt == null) { 
    toastAlert(true,"center",false,3000,"info","Please Fill Amount"); 
    return; 
}
if (credit_facility == "" || credit_facility == null) { 
    toastAlert(true,"center",false,3000,"info","Please Fill Your Credit Facility"); 
    return; 
}
if (tenure == "" || tenure == null) { 
    toastAlert(true,"center",false,3000,"info","Please Fill Your Repayment Tenure"); 
    return; 
}
if (purpose == "" || purpose == null) { 
    toastAlert(true,"center",false,3000,"info","Please Fill Your Purpose"); 
    return; 
}


      
let dataString = "credit_facility=" + credit_facility + 
                 "&tenure=" + tenure + 
                 "&purpose=" + purpose + 
                 "&amt=" + amt;
   Swal.showLoading();
    $.ajax({
      url : "../apps/user/loanapp.php",
      type : "POST",
      data : dataString, 
      success : function(data){
        let info = data.trim();
        if ( info == "success" ){
            Swal.fire({
            icon: 'success',
            title: 'Request Submitted',
            text: 'Your request has been submitted',
            showConfirmButton: false,
            timer: 2000
          })
            setTimeout(function(){window.location = "loan-history.php"} , 3200);        
        }
        else if( info == "error" ){
          toastAlert(true,"center",false,3000,"error","Sonething went wrong");
                    console.log(info);

        }
        else{
          // toastAlert(true,"center",false,3000,"error","Something went wrong, Please try again");
          console.log(info);
        }
      }
    }) 
  }
</script>


















                <div class="nk-footer nk-footer-fluid">
                    <div class="container-fluid">
                        <div class="nk-footer-wrap">
                            <div class="nk-footer-copyright"> &copy; <?php
echo date("Y");
?>  <?= htmlspecialchars(getSetting('site_name', 'Deutsche Bank Holdings Delaware')) ?>   <a href="#">All rights
                                    reserved.</a>
                            </div>
                            <div class="nk-footer-links">
                                <ul class="nav nav-sm">
                                    <li class="nav-item"><a class="nav-link" href="#">Terms</a></li>
                                    <li class="nav-item"><a class="nav-link" href="privacy">Privacy</a></li>
                                    <li class="nav-item"><a class="nav-link" href="contact">Help</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- footer @e -->
            </div>
            <!-- wrap @e -->
        </div>
        <!-- main @e -->
    </div>
    <!-- app-root @e -->
    <!-- JavaScript -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="../js/country.js"></script>
    <script src="assets/js/bundle.js?ver=2.4.0"></script>
    <script src="assets/js/scripts.js?ver=2.4.0"></script>
    <script src="assets/js/charts/chart-crypto.js?ver=2.4.0"></script>
    <script src="../js/sweetalert.js"></script>
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/custom.js"></script>
    <script src="../js/toastr.js"></script>

</body>

</html>