<?php


require_once "auth.php";

$today = date('Y-m-d');

/* ======================
   TOTAL USERS + TODAY
   ====================== */
$total_user = $pdo->query(
    "SELECT COUNT(*) FROM user_data"
)->fetchColumn();

$today_user = $pdo->prepare(
    "SELECT COUNT(*) FROM user_data WHERE DATE(joined_at) = ?"
);
$today_user->execute([$today]);
$today_user = $today_user->fetchColumn();

/* ======================
   TOTAL RECHARGE + TODAY
   ====================== */
$total_recharge = $pdo->query(
    "SELECT COALESCE(SUM(amount),0) 
     FROM deposit_history 
     WHERE status='SUCCESS'"
)->fetchColumn();

$today_recharge = $pdo->prepare(
    "SELECT COALESCE(SUM(amount),0) 
     FROM deposit_history 
     WHERE status='SUCCESS' AND DATE(created_at)=?"
);
$today_recharge->execute([$today]);
$today_recharge = $today_recharge->fetchColumn();

/* ======================
   TOTAL OTP COUNT + TODAY
   ====================== */
$total_otp = $pdo->query(
    "SELECT COUNT(*) FROM otp_history WHERE status = 'RECEIVED'"
)->fetchColumn();

$today_otp_stmt = $pdo->prepare(
    "SELECT COUNT(*) 
     FROM otp_history 
     WHERE DATE(created_at) = ? 
       AND status = 'RECEIVED'"
);

$today_otp_stmt->execute([$today]);
$today_otp = $today_otp_stmt->fetchColumn();

/* ======================
   TOTAL OTP PRICE + TODAY
   ====================== */
$total_otp_price = $pdo->query(
    "SELECT COALESCE(SUM(price),0) FROM otp_history WHERE status = 'RECEIVED'"
)->fetchColumn();

$today_otp_price = $pdo->prepare(
    "SELECT COALESCE(SUM(price),0) 
     FROM otp_history WHERE DATE(created_at)=? AND status = 'RECEIVED'"
);
$today_otp_price->execute([$today]);
$today_otp_price = $today_otp_price->fetchColumn();
?>


<!DOCTYPE html>
<html lang="en">

<head>
  <title>Dashboard - @radiumsahil</title>
<?php include("include/head.php"); ?>  
</head>

<body id="page-top">
  <div id="wrapper">
    <!-- Sidebar -->
<?php include ("include/slidebar.php"); ?>
    <!-- Sidebar -->
    <div id="content-wrapper" class="d-flex flex-column">
      <div id="content">
        <!-- TopBar -->
<?php include ("include/topbar.php"); ?>              
        <!-- Topbar -->

        <!-- Container Fluid-->
        <div class="container-fluid" id="container-wrapper">
          <div class="d-sm-flex align-items-center justify-content-between mb-4">
            <h1 class="h3 mb-0 text-gray-800">Dashboard</h1>
            <ol class="breadcrumb">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item active" aria-current="page">Dashboard</li>
            </ol>
          </div>

          <div class="row mb-3">
            <!-- Earnings (Monthly) Card Example -->
            <div class="col-xl-3 col-md-6 mb-4">
              <div class="card h-100">
                <div class="card-body">
                  <div class="row align-items-center">
                    <div class="col mr-2">
                      <div class="text-xs font-weight-bold text-uppercase mb-1">Total User</div>
                      <div class="h5 mb-0 font-weight-bold text-gray-800"><?php echo $total_user;?></div>
                      <div class="mt-2 mb-0 text-muted text-xs">
                        <span class="text-success mr-2"><i class="fa fa-plus"></i> <?php echo $today_user;?></span>
                        <span>Register Today</span>
                      </div>
                    </div>
                    <div class="col-auto">
                      <i class="fas fa-user-circle fa-2x text-primary"></i>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <!-- Earnings (Annual) Card Example -->
            <div class="col-xl-3 col-md-6 mb-4">
              <div class="card h-100">
                <div class="card-body">
                  <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                      <div class="text-xs font-weight-bold text-uppercase mb-1">Total Recharge</div>
                      <div class="h5 mb-0 font-weight-bold text-gray-800">₹<?php echo $total_recharge;?></div>
                      <div class="mt-2 mb-0 text-muted text-xs">
                        <span class="text-success mr-2"><i class="fas fa-plus"></i> ₹<?php echo $today_recharge;?></span>
                        <span>Recharge Today</span>
                      </div>
                    </div>
                    <div class="col-auto">
                      <i class="fas fa-shopping-cart fa-2x text-success"></i>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <!-- New User Card Example -->
            <div class="col-xl-3 col-md-6 mb-4">
              <div class="card h-100">
                <div class="card-body">
                  <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                      <div class="text-xs font-weight-bold text-uppercase mb-1">Total Otp Sell</div>
                      <div class="h5 mb-0 mr-3 font-weight-bold text-gray-800"><?php echo $total_otp;?></div>
                      <div class="mt-2 mb-0 text-muted text-xs">
                        <span class="text-success mr-2"><i class="fas fa-plus"></i> <?php echo $today_otp;?></span>
                        <span>Today Otp Sell</span>
                      </div>
                    </div>
                    <div class="col-auto">
                      <i class="fas fa-comments fa-2x text-info"></i>
                    </div>
                  </div>
                </div>
              </div>
            </div>
               <!-- New User Card Example -->
            <div class="col-xl-3 col-md-6 mb-4">
              <div class="card h-100">
                <div class="card-body">
                  <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                      <div class="text-xs font-weight-bold text-uppercase mb-1">Total Otp Sell Amount</div>
                      <div class="h5 mb-0 mr-3 font-weight-bold text-gray-800">₹<?php echo $total_otp_price;?></div>
                      <div class="mt-2 mb-0 text-muted text-xs">
                        <span class="text-success mr-2"><i class="fas fa-plus"></i> ₹<?php echo $today_otp_price;?></span>
                        <span>Today Otp Sell Amount</span>
                      </div>
                    </div>
                    <div class="col-auto">
                      <i class="fas fa-comments-dollar fa-2x text-warning"></i>
                    </div>
                  </div>
                </div>
              </div>
            </div>
                <!-- New User Card Example -->

                </div>
                <div class="card-footer"></div>
              </div>
            </div>
            
            <!--Row-->

     <!--    <centre><div class="row">
            <div class="col-lg-12 text-center">
              <p>Any Bug Found Please Contact Me <a href="https://telegram.dog/radiumsahil"
                  class="btn btn-primary btn-sm" target="_blank"><i class="fab fa-fw fa-telegram"></i>&nbsp; Telegram</a></p>
            </div>
          </div></centre> -->

 
        </div>
        </div>

        <!---Conta        </div>
iner Fluid-->
      </div>
      <!-- Footer -->

      <!-- Footer -->
    </div>
  </div>

  <!-- Scroll to top -->
  <a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
  </a>
<?php include("include/script.php"); ?>

</body>

</html>