<?php include('session.php'); ?>
<!DOCTYPE html>

<html
  lang="en"
  class="light-style layout-navbar-fixed layout-menu-fixed"
  dir="ltr"
  data-theme="theme-default"
  data-assets-path="<?php echo $assets; ?>/assets/"
  data-template="vertical-menu-template"
>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
    />

    <title><?php echo $s0['instansi']; ?></title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="resource-type" content="document" />
    <meta http-equiv="content-type" content="text/html; charset=US-ASCII" />
    <meta http-equiv="content-language" content="en-us" />
    <meta name="author" content="CXFTEAMS" />
    <meta name="contact" content="cxfteams.sbs" />
    <meta name="copyright" content="Copyright (c) cxfteams.sbs. All Rights Reserved." />
    <meta name="robots" content="index, nofollow">

    <!-- Favicon -->
    <link rel="icon" type="image/x-icon" href="<?php echo $urlwebs; ?>/upload/favicon.png" />

    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
      href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap"
      rel="stylesheet"
    />

    <!-- Icons -->
    <link rel="stylesheet" href="<?php echo $assets; ?>/assets/vendor/fonts/fontawesome.css" />
    <link rel="stylesheet" href="<?php echo $urlweb; ?>/assets/vendor/fonts/tabler-icons.css" />
    <link rel="stylesheet" href="<?php echo $assets; ?>/assets/vendor/fonts/flag-icons.css" />

    <!-- Core CSS -->
    <link rel="stylesheet" href="<?php echo $assets; ?>/assets/vendor/css/rtl/core.css" class="template-customizer-core-css" />
    <link rel="stylesheet" href="<?php echo $assets; ?>/assets/vendor/css/rtl/theme-default.css" class="template-customizer-theme-css" />
    <link rel="stylesheet" href="<?php echo $assets; ?>/assets/css/demo.css" />

    <!-- Vendors CSS -->
    <link rel="stylesheet" href="<?php echo $assets; ?>/assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" />
    <link rel="stylesheet" href="<?php echo $assets; ?>/assets/vendor/libs/node-waves/node-waves.css" />
    <link rel="stylesheet" href="<?php echo $assets; ?>/assets/vendor/libs/typeahead-js/typeahead.css" />
    <link rel="stylesheet" href="<?php echo $assets; ?>/assets/vendor/libs/apex-charts/apex-charts.css" />
    <link rel="stylesheet" href="<?php echo $assets; ?>/assets/vendor/libs/datatables-bs5/datatables.bootstrap5.css" />
    <link rel="stylesheet" href="<?php echo $assets; ?>/assets/vendor/libs/datatables-responsive-bs5/responsive.bootstrap5.css" />
    <link rel="stylesheet" href="<?php echo $assets; ?>/assets/vendor/libs/datatables-buttons-bs5/buttons.bootstrap5.css" />

    <!-- Page CSS -->

    <!-- Helpers -->
    <script src="<?php echo $assets; ?>/assets/vendor/js/helpers.js"></script>

    <!--! Template customizer & Theme config files MUST be included after core stylesheets and helpers.js in the <head> section -->
    <!--? Template customizer: To hide customizer set displayCustomizer value false in config.js.  -->
    <!--? Config:  Mandatory theme config file contain global vars & default theme options, Set your preferred theme option in this file.  -->
    <script src="<?php echo $assets; ?>/assets/js/config.js"></script>
  </head>

  <body>
    <!-- Layout wrapper -->
    <div class="layout-wrapper layout-content-navbar">
      <div class="layout-container">
        <!-- Menu -->

        <?php include('sidebar.php'); ?>
        <!-- / Menu -->

        <!-- Layout container -->
        <div class="layout-page">
          <!-- Navbar -->

          <nav
            class="layout-navbar container-xxl navbar navbar-expand-xl navbar-detached align-items-center bg-navbar-theme"
            id="layout-navbar"
          >
            <div class="layout-menu-toggle navbar-nav align-items-xl-center me-3 me-xl-0 d-xl-none">
              <a class="nav-item nav-link px-0 me-xl-4" href="javascript:void(0)">
                <i class="ti ti-menu-2 ti-sm"></i>
              </a>
            </div>

            <div class="navbar-nav-right d-flex align-items-center" id="navbar-collapse">
              <?php include('top-menu.php'); ?>
            </div>

            <!-- Search Small Screens -->
            <div class="navbar-search-wrapper search-input-wrapper d-none">
              <input
                type="text"
                class="form-control search-input container-xxl border-0"
                placeholder="Search..."
                aria-label="Search..."
              />
              <i class="ti ti-x ti-sm search-toggler cursor-pointer"></i>
            </div>
          </nav>

          <!-- / Navbar -->

          <!-- Content wrapper -->
          <div class="content-wrapper">
            <!-- Content -->

            <div class="container-xxl flex-grow-1 container-p-y">
              <div class="row">
                <?php
                  error_reporting(0);
                  $today = date('Y-m');
                  $sql_1 = mysqli_query($conn,"SELECT SUM(total) as deposit FROM `tb_transaksi` WHERE status = 1 AND jenis = 1") or die(mysqli_error());
                  $s1 = mysqli_fetch_array($sql_1);
                  $sql_2 = mysqli_query($conn,"SELECT SUM(total) as withdraw FROM `tb_transaksi` WHERE status = 1 AND jenis = 2") or die(mysqli_error());
                  $s2 = mysqli_fetch_array($sql_2);
                  $sql_3 = mysqli_query($conn,"SELECT * FROM `tb_user` WHERE status = 1 AND level = 'user'") or die(mysqli_error());
                  $s3 = mysqli_num_rows($sql_3);
                  $sql_6 = mysqli_query($conn,"SELECT SUM(hits) as visitor FROM `tb_stat`") or die(mysqli_error());
                  $s6 = mysqli_fetch_array($sql_6);
                ?>
                <!-- Statistics -->
                <div class="col-xl-12 mb-4 col-lg-12 col-12">
                  <div class="card h-100">
                    <div class="card-header">
                    <div class="">
                      <div class="d-flex justify-content-between mb-3">
                        <h5 class="card-title mb-0">Statistics</h5>
                        <?php if($u['cuid'] == 1){ ?> 
                        <a href="<?php echo $urlweb; ?>/function/delete-alX.php" class="btn btn-danger btn-sm">RESET PANEL</a>
                        <?php } else { echo 'BLOCK'; } ?>
                      </div>
                      </div>
                    </div>
                    <?php
                            error_reporting(0);
                            if (!empty($_GET['notif'])) {
                                if ($_GET['notif'] == 1) {
                                    echo '
                                      <div class="alert alert-success alert-dismissible mb-2" role="alert">
                                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                                        <div class="alert-icon">
                                          <i class="fa fa-check"></i>
                                        </div>
                                        <div class="alert-message">
                                          <span><strong>Congrats!</strong> Panel Berhasil Di Reset!</span>
                                        </div>
                                      </div>
                                    ';
                                }
                                
                            }
                            ?>
                    <div class="card-body">
                      <div class="row gy-3">
                        <div class="col-md-3 col-6">
                          <div class="d-flex align-items-center">
                            <div class="badge rounded-pill bg-label-info me-3 p-2">
                              <i class="ti ti-users ti-sm"></i>
                            </div>
                            <div class="card-info">
                              <h5 class="mb-0"><?php echo ($s3); ?></h5>
                              <small>Total Member</small>
                            </div>
                          </div>
                        </div>
                        <div class="col-md-3 col-6">
                          <div class="d-flex align-items-center">
                            <div class="badge rounded-pill bg-label-danger me-3 p-2">
                              <i class="ti ti-shopping-cart ti-sm"></i>
                            </div>
                            <div class="card-info">
                              <h5 class="mb-0"><?php echo ($s1['deposit']); ?></h5>
                              <small>Total Deposit</small>
                            </div>
                          </div>
                        </div>
                        <div class="col-md-3 col-6">
                          <div class="d-flex align-items-center">
                            <div class="badge rounded-pill bg-label-primary me-3 p-2">
                              <i class="ti ti-chart-pie-2 ti-sm"></i>
                            </div>
                            <div class="card-info">
                              <h5 class="mb-0">Rp. <?php echo ($s2['withdraw']); ?></h5>
                              <small>Total Withdraw</small>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <!--/ Statistics -->
                <!--/ Popular Product -->

                <!-- Revenue Report -->
                <div class="col-12 col-xl-6 mb-4 col-lg-6">
                  <div class="card h-100">
                    <div class="card-header pb-0 d-flex justify-content-between mb-lg-n4">
                      <div class="card-title mb-0">
                        <h5 class="mb-0">Laporan Keuangan</h5>
                        <small class="text-muted">Penghasilan Dalam 1 Bulan</small>
                      </div>
                      <!-- </div> -->
                    </div>
                    <br>
                    <div class="card-body">
                      <div class="row">
                        <div class="col-12 col-md-4 d-flex flex-column align-self-end">
                          <div class="d-flex gap-2 align-items-center mb-2 pb-1 flex-wrap">
                            <h1 class="mb-0">Rp. <?php echo ($s1['deposit']); ?></h1>
                            <div class="badge rounded bg-label-success"></div>
                          </div>
                          <small class="text-muted"></small>
                        </div>
                      </div>
                      <br>
                      <div class="border rounded p-3 mt-2">
                        <div class="row gap-4 gap-sm-0">
                          <div class="col-6 col-sm-6">
                            <div class="d-flex gap-2 align-items-center">
                              <div class="badge rounded bg-label-primary p-1">
                                <i class="ti ti-currency-dollar ti-sm"></i>
                              </div>
                              <h6 class="mb-0">Total Deposit</h6>
                            </div>
                            <h4 class="my-2 pt-1">Rp. <?php echo ($s1['deposit']); ?></h4>
                            <div class="progress w-75" style="height: 4px">
                              <div
                                class="progress-bar"
                                role="progressbar"
                                style="width: 65%"
                                aria-valuenow="65"
                                aria-valuemin="0"
                                aria-valuemax="100"
                              ></div>
                            </div>
                          </div>
                          <div class="col-6 col-sm-6">
                            <div class="d-flex gap-2 align-items-center">
                              <div class="badge rounded bg-label-info p-1"><i class="ti ti-chart-pie-2 ti-sm"></i></div>
                              <h6 class="mb-0">Total Withdraw</h6>
                            </div>
                            <h4 class="my-2 pt-1">Rp. <?php echo ($s2['withdraw']); ?></h4>
                            <div class="progress w-75" style="height: 4px">
                              <div
                                class="progress-bar bg-warning"
                                role="progressbar"
                                style="width: 50%"
                                aria-valuenow="50"
                                aria-valuemin="0"
                                aria-valuemax="100"
                              ></div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <!--/ Revenue Report -->
                
                <!-- Popular Product -->
                <div class="col-md-12 col-xl-12 mb-4">
                  <div class="card h-100">
                    <div class="card-header d-flex justify-content-between">
                      <div class="card-title m-0 me-2">
                        <h5 class="m-0 me-2">Pembayaran Terakhir</h5>
                        <small class="text-muted">Total Deposit</small>
                      </div>
                    </div>
                    <div class="card-body">
                      <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                          <thead>
                            <tr class="bg-warning text-white">
                                <th class="text-center text-white" style="vertical-align: middle;">#</th>
                                <th class="text-center text-white" style="vertical-align: middle;">Date</th>
                                <th class="text-center text-white" style="vertical-align: middle;">Username</th>
                                <th class="text-center text-white" style="vertical-align: middle;">Payment Method</th>
                                <th class="text-center text-white" style="vertical-align: middle;">Payment From</th>
                                <th class="text-center text-white" style="vertical-align: middle;">Amount</th>
                                <th class="text-center text-white" style="vertical-align: middle;">Status</th>
                                <th class="text-center text-white" style="vertical-align: middle;">Aksi</th>
                            </tr>
                          </thead>
                          <tbody>
                            <?php
                                $sql_1 = mysqli_query($conn,"SELECT * FROM `tb_transaksi` WHERE jenis = 1 AND status = 0 ORDER BY cuid DESC LIMIT 10") or die(mysqli_error());
                                $no=0;
                                while($s1 = mysqli_fetch_array($sql_1)){
                                  $no++;
                                  $metode = $s1['metode'];
                                  $pay_from = $s1['pay_from'];
                                  $IDuser = $s1['userID'];
                                  $sql_2 = mysqli_query($conn,"SELECT * FROM `tb_user` WHERE cuid = '$IDuser'") or die(mysqli_error());
                                  $s2 = mysqli_fetch_array($sql_2);
                                  $sql_3 = mysqli_query($conn,"SELECT * FROM `tb_bank` WHERE cuid = '$metode'") or die(mysqli_error());
                                  $s3 = mysqli_fetch_array($sql_3);
                                  $sql_4 = mysqli_query($conn,"SELECT * FROM `tb_bank` WHERE cuid = '$pay_from'") or die(mysqli_error());
                                  $s4 = mysqli_fetch_array($sql_4);
                            ?>
                            <tr>
                                <td class="text-center" style="vertical-align: middle; font-size: 14px;"><?php echo $no; ?></td>
                                <td class="text-center" style="vertical-align: middle; white-space: normal; font-size: 14px;"><?php echo date('Y-m-d', strtotime($s1['date'])); ?><br><?php echo date('H:i:s', strtotime($s1['date'])); ?></td>
                                <td class="text-center" style="vertical-align: middle; white-space: normal; font-size: 14px;"><?php echo $s2['user']; ?></td>
                                <td class="text-center" style="vertical-align: middle; white-space: normal; font-size: 14px;"><?php if($s1['metode'] == 0) { echo 'By Sistem'; } else { echo $s3['akun']; } ?></td>
                                <td class="text-center" style="vertical-align: middle; white-space: normal; font-size: 14px;"><?php if($s1['pay_from'] == 0) { echo 'By Sistem'; } else { echo $s4['akun']; } ?></td>
                                <td class="text-right" style="vertical-align: middle; white-space: normal; font-size: 14px; text-align: right;"><?php echo ($s1['total']); ?></td>
                                <td class="text-center" style="vertical-align: middle; white-space: normal; font-size: 14px;">
                                  <?php
                                    if($s1['status'] == 0){
                                      echo '
                                        <span class="badge-dot">
                                          <i class="bg-warning"></i> PENDING
                                        </span>
                                      ';
                                    }
                                    else if($s1['status'] == 1){
                                      echo '
                                        <span class="badge-dot">
                                          <i class="bg-success"></i> PAID
                                        </span>
                                      ';
                                    }
                                    else {
                                      echo '
                                        <span class="badge-dot">
                                          <i class="bg-danger"></i> REJECT
                                        </span>
                                      ';
                                    }
                                  ?>
                                </td>
                                <td class="text-center" style="vertical-align: middle; white-space: nowrap; font-size: 14px;">
                                  <?php if($s1['status'] == 0){ ?>
                                  <a href="<?php echo $urlweb; ?>/function/proses_topup.php?cuid=<?php echo $s1['cuid']; ?>" class="btn btn-primary btn-sm">Proses</a>
                                  <a href="<?php echo $urlweb; ?>/function/reject_topup.php?cuid=<?php echo $s1['cuid']; ?>" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure want to Reject this Transaction?');">Reject</a>
                                  <?php } else { ?>
                                  <a href="#" class="btn btn-success btn-sm">Selesai</a>
                                  <?php } ?>
                                </td>
                            </tr>
                            <?php } ?>
                          </tbody>
                        </table>
                      </div>
                    </div>
                  </div>
                </div>
                <!--/ Popular Product -->

              </div>
            </div>
            <!-- / Content -->

            <!-- Footer -->
            <footer class="content-footer footer bg-footer-theme">
              <div class="container-xxl">
                <div
                  class="footer-container d-flex align-items-center justify-content-between py-2 flex-md-row flex-column"
                >
                  <div>
                    ©
                    <script>
                      document.write(new Date().getFullYear());
                    </script>
                    , <?php echo $s0['instansi']; ?> All Rights Reserved.
                  </div>
                </div>
              </div>
            </footer>
            <!-- / Footer -->

            <div class="content-backdrop fade"></div>
          </div>
          <!-- Content wrapper -->
        </div>
        <!-- / Layout page -->
      </div>

      <!-- Overlay -->
      <div class="layout-overlay layout-menu-toggle"></div>

      <!-- Drag Target Area To SlideIn Menu On Small Screens -->
      <div class="drag-target"></div>
    </div>
    <!-- / Layout wrapper -->

    <!-- Core JS -->
    <!-- build:js assets/vendor/js/core.js -->
    <script src="<?php echo $assets; ?>/assets/vendor/libs/jquery/jquery.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/libs/popper/popper.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/js/bootstrap.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/libs/node-waves/node-waves.js"></script>

    <script src="<?php echo $assets; ?>/assets/vendor/libs/hammer/hammer.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/libs/i18n/i18n.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/libs/typeahead-js/typeahead.js"></script>

    <script src="<?php echo $assets; ?>/assets/vendor/js/menu.js"></script>
    <!-- endbuild -->

    <!-- Vendors JS -->
    <script src="<?php echo $assets; ?>/assets/vendor/libs/apex-charts/apexcharts.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/libs/datatables/jquery.dataTables.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/libs/datatables-bs5/datatables-bootstrap5.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/libs/datatables-responsive/datatables.responsive.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/libs/datatables-responsive-bs5/responsive.bootstrap5.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/libs/datatables-buttons/datatables-buttons.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/libs/datatables-buttons-bs5/buttons.bootstrap5.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/libs/datatables-buttons/buttons.html5.js"></script>
    <script src="<?php echo $assets; ?>/assets/vendor/libs/datatables-buttons/buttons.print.js"></script>

    <!-- Main JS -->
    <script src="<?php echo $assets; ?>/assets/js/main.js"></script>
    <script src="<?php echo $assets; ?>/assets/js/dashboards-analytics.js"></script>
    <script>
    $(document).ready(function() {
      //Default data table
      $('#default-datatable').DataTable();
    });
  </script>
  </body>
</html>
