<?php include("security.php"); ?>
<?php require_once('../setup.php'); ?>
<!DOCTYPE html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title><?= $main_capital_name; ?></title>
  <!-- plugins:css -->
  <link rel="stylesheet" href="vendors/feather/feather.css">
  <link rel="stylesheet" href="vendors/ti-icons/css/themify-icons.css">
  <link rel="stylesheet" href="vendors/css/vendor.bundle.base.css">
  <!-- endinject -->
  <!-- Plugin css for this page -->
  <link rel="stylesheet" href="vendors/datatables.net-bs4/dataTables.bootstrap4.css">
  <link rel="stylesheet" href="vendors/ti-icons/css/themify-icons.css">
  <link rel="stylesheet" type="text/css" href="js/select.dataTables.min.css">
  <link rel="stylesheet" href="vendors/mdi/css/materialdesignicons.min.css">
  <!-- End plugin css for this page -->
  <!-- inject:css -->
  <link rel="stylesheet" href="css/vertical-layout-light/style.css">
  <!-- endinject -->
  <link rel="shortcut icon" href="../assets/images/logo.png" />
</head>

<body>
  <div class="container-scroller">
    <!-- partial:partials/_navbar.html -->
    <?php include('topbar.php'); ?>
    <!-- partial -->
    <div class="container-fluid page-body-wrapper">
      <!-- partial:partials/_sidebar.html -->
      <?php include('nav.php'); ?>
      <!-- partial -->
      <div class="main-panel">
        <div class="content-wrapper">
          <div class="row">
            <div class="col-md-12 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">
                  <p class="card-title"><i class="mdi mdi-library-books menu-icon"></i> Recent Transactions</p>
                  <div class="row">
                    <div class="col-12">
                      <div class="table-responsive">
                        <table class="table table-striped table-hover" style="width:100%">
                          <thead>
                            <tr>
                              <th>&nbsp;</th>
                              <th>Acc Name</th>
                              <th>Amount</th>
                              <th>Bank Name</th>
                              <th>Date</th>
                              <th>Type</th>
                              <th>Status</th>
                              <th></th>
                              <th></th>
                            </tr>
                          </thead>
                          <tbody>
                            <?php
                            require_once("conn.php");
                            $query = mysqli_query($dbconfig, ("SELECT * FROM transactions WHERE user_id= '$dbid' ORDER BY id DESC"));
                            if (mysqli_num_rows($query) > 0) {
                              while ($row = $query->fetch_assoc()) {

                                //Status Function
                                if ($row['status'] == 'pending') {
                                  $new_status = '<span style="color: orange;">' . $row['status'] . '</span>';
                                } elseif ($row['status'] == 'approved') {
                                  $new_status = '<span style="color: green;">' . $row['status'] . '</span>';
                                } elseif ($row['status'] == 'canceled') {
                                  $new_status = '<span style="color: red;">' . $row['status'] . '</span>';
                                }

                                //Type Function
                                if ($row['type'] == 'Credit') {
                                  $new_type = '<span style="color: green;">' . $row['type'] . '</span>';
                                } elseif ($row['type'] == 'Debit') {
                                  $new_type = '<span style="color: red;">' . $row['type'] . '</span>';
                                }

                                //Link
                                if ($row['tag'] == 'same') {
                                  $new_link = 'verify-transfer?i=' . base64_encode($row['transaction_id']);
                                } else {
                                  $new_link = 'verify-wire-transfer?i=' . base64_encode($row['transaction_id']);
                                }

                                //Button
                                if ($row['status'] == 'pending') {
                                  $new_button = '<a href="' . $new_link . '"><button class="btn btn-sm btn-warning">Continue</button></a>';
                                } else {
                                  $new_button = '';
                                }
                                echo '
                                <tr>
                                  <td><i class="mdi mdi-arrow-right menu-icon"></i></td>
                                  <td>' . $row['account_name'] . '</td>
                                  <td>'.$dbcurrency.'' . number_format($row['amount'], 2) . '</td>
                                  <td>' . $row['bank'] . '</td>
                                  <td>' . $row['date'] . '</td>
                                  <td>' . $new_type . '</td>
                                  <td style=" text-transform: capitalize;">' . $new_status . '</td>
                                  <td><a href="view-transaction?i=' . base64_encode($row['transaction_id']) . '"><button class="btn btn-sm btn-primary">View Transaction</button></a></td>
                                  <td>' . $new_button . '</td>
                                </tr>';
                              }
                            } else {
                              echo '
                                <tr>
                                  <td align="center" colspan="9">
                                    <h3 class="font-weight-bold"> No Recent Transactions</h3>
                                  </td>
                                </tr>';
                            }
                            ?>
                          </tbody>
                        </table>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- content-wrapper ends -->
    </div>
    <!-- main-panel ends -->
  </div>
  <!-- page-body-wrapper ends -->
  </div>
  <!-- container-scroller -->

  <!-- plugins:js -->
  <script src="vendors/js/vendor.bundle.base.js"></script>
  <!-- endinject -->
  <!-- Plugin js for this page -->
  <script src="vendors/chart.js/Chart.min.js"></script>
  <script src="vendors/datatables.net/jquery.dataTables.js"></script>
  <script src="vendors/datatables.net-bs4/dataTables.bootstrap4.js"></script>
  <script src="js/dataTables.select.min.js"></script>

  <!-- End plugin js for this page -->
  <!-- inject:js -->
  <script src="js/off-canvas.js"></script>
  <script src="js/hoverable-collapse.js"></script>
  <script src="js/template.js"></script>
  <script src="js/settings.js"></script>
  <script src="js/todolist.js"></script>
  <!-- endinject -->
  <!-- Custom js for this page-->
  <script src="js/dashboard.js"></script>
  <script src="js/Chart.roundedBarCharts.js"></script>
  <!-- End custom js for this page-->
  <?php include('../chat.php'); ?>
</body>

</html>
