<?php include 'includes/config.php';

if (!isset($_SESSION['useradmin'])) 
{
  echo '<script>alert("Please Login First");window.location = "index.php";</script>';
}
$usertype = $_SESSION['useradmin'];
?>
    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="utf-8" />
        <title>Dashboard</title>

        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="shortcut icon" href="adminassets/images/favicon.ico">

        <!-- Bootstrap Css -->
        <link href="adminassets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
        <!-- Icons Css -->
        <link href="adminassets/css/icons.min.css" rel="stylesheet" type="text/css" />

        <link href="adminassets/libs/datatables.net-bs4/css/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css" />
        <link href="adminassets/libs/datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css" />
        <link href="adminassets/libs/datatables.net-responsive-bs4/css/responsive.bootstrap4.min.css" rel="stylesheet" type="text/css" />
        <link href="adminassets/libs/select2/css/select2.min.css" rel="stylesheet" type="text/css" />
        <!-- App Css-->
        <link href="adminassets/css/app.min.css?v=2" id="app-style" rel="stylesheet" type="text/css" />

        <link href="adminassets/css/custom.css?v=11" rel="stylesheet" type="text/css" />

    </head>

    <body data-sidebar="dark">

        <div id="layout-wrapper">
            
            <?php include 'includes/header.php';  ?>

            <div class="main-content">
                <div class="page-content">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-12">
                                <div class="page-title-box d-flex align-items-center justify-content-between">
                                    <h4 class="mb-0 font-size-18">Dashboard</h4>

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

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

                        <div class="row">
                            <div class="col-xl-4">
                                <div class="card overflow-hidden">
                                    <div class="bg-soft-primary">
                                        <div class="row">
                                            <div class="col-7">
                                                <div class="text-primary p-3">
                                                    <h5 class="text-primary">Welcome Back !</h5>
                                                    <p>Admin Dashboard</p>
                                                </div>
                                            </div>
                                            <div class="col-5 align-self-end">
                                                <img src="adminassets/images/profile-img.png" alt="" class="img-fluid">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="card-body pt-0 dboard_pro_mht">
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <div class="avatar-md profile-user-wid mb-4">
                                                    <img src="adminassets/images/users/avatar-1.jpg" alt="" class="img-thumbnail rounded-circle">
                                                </div>
                                                <h5 class="font-size-15 text-truncate">
                                                     </h5>
                                                <p class="text-muted mb-0 text-truncate">Admin</p>
                                            </div>

                                            <div class="col-sm-8">
                                                <div class="pt-4">
                                                    <div class="row">
                                                        <div class="col-6">
                                                            <a href="un-approved-users-list.php">
                                                                <?php
                                                                    $tmsql = "SELECT COUNT(member_id) as idc FROM member WHERE status='Pending'";
                                                                    $tmqry = mysqli_query($conn, $tmsql);
                                                                    $tmrow = mysqli_fetch_assoc($tmqry);
                                                                    $tmnum = $tmrow['idc'] ?: '0';
                                                                    ?>
                                                                <h5 class="font-size-15"><?php echo $tmnum; ?></h5>
                                                                <p class="text-muted mb-0">Unapproved Users</p>
                                                            </a>
                                                        </div>
                                                        <div class="col-6">
                                                            <a href="user-management.php">
                                                                  <?php
                                                                        $tsql = "SELECT COUNT(member_id) as idc FROM member WHERE status = 'Active' ";
                                                                        $tqry = mysqli_query($conn, $tsql);
                                                                        $trow = mysqli_fetch_assoc($tqry);
                                                                        $tnum = $trow['idc'] ?: '0';
                                                                        ?>
                                                                <h5 class="font-size-15"><?php echo $tnum; ?></h5>
                                                                <p class="text-muted mb-0">Approved Users</p>
                                                            </a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="card">
                                    <div class="card-body">
                                        <h4 class="card-title mb-4">Market Bid Details</h4>
                                        <div class="row">
                                            <div class="col-sm-12"> 
                                                <form name="getMarketBidFrm" method="post">
                                                    <div class="form-group">
                                                        <label>Date</label>
                                                        <input class="form-control" type="date" name="start_date1" id="start_date1" placeholder="Enter Start Date">
                                                    </div>

                                                    <div class="form-group">
                                                        <label class="text-muted">Game Name</label>
                                                        <div class="input-group"> 
                                                            <select id="game_name" name="game_name" class="form-control getMarketBid">
                                                                <option value='all'>Select Games</option>
                                                                <?php
                                                                    $getsql = "SELECT * FROM market WHERE active_status != 'Removed' ";
                                                                    $getqry = mysqli_query($conn, $getsql);
                                                                    $i = 1;
                                                                    if (mysqli_num_rows($getqry) > 0) {
                                                                        while ($row = mysqli_fetch_assoc($getqry)) {
                                                                    ?>
                                                                    <option value="<?php echo $row['market_id']; ?>"><?php echo $row['market_name']; ?></option>
                                                                <?php } } ?>
                                                            </select>
                                                        </div>
                                                    </div> 

                                                    <div class="form-group" style="text-align: right; margin-top: 20px;">
                                                        <button type="button" id="getsubmit" class="btn btn-success">Submit</button>
                                                    </div>
                                                </form>
                                                 <?php
                                                    $amsql = "SELECT SUM(betting_amount) as idc FROM betting WHERE DATE(betting_date) = Date('$date')";
                                                    $amqry = mysqli_query($conn, $amsql);
                                                    $amrow = mysqli_fetch_assoc($amqry);
                                                    $amnum = $amrow['idc'] ?: '0';
                                                    ?>
                                                <h3 id="bid_amt"></h3>
                                                <p class="text-muted">Total Bid Amount</p>

                                                <div class="row" id="tabledata">
                                                    <div class="col-md-12">
                                                        <div class="bid_history_box bhb_bid_amt" style="border: 1px dotted black;padding: 2px; margin:5px;">
                                                            <div class="row" style="align-items: baseline; padding:5px;">
                                                                <div class="col-md-6">    
                                                                 <h5 class="text-muted font-weight-medium" style="font-size: 13px;">Total Bid Amount</h5>
                                                                </div>
                                                                <div class="col-md-3"> <h5 style="font-size: 12px;" id="total_bid_amt"><i class="bx bx-rupee"></i><?php echo $amnum;?></h5>
                                                                </div>
                                                                <div class="col-md-3 text-sm-right"> 
                                                                 <button type="button" class="btn btn-primary waves-light btn-xs showbettbl" id="winner_btn">View</button>
                                                                 </div>
                                                            </div>
                                                        </div>
                                                        <?php
                                                            // $amsql = "SELECT SUM(betting_amount) as idc FROM betting WHERE DATE(betting_date) LIKE '%$date%'";
                                                            $amsql = "SELECT * , SUM(transaction_amount) as amt , COUNT(w_transaction_id) as cont FROM `wallet_transaction` WHERE transaction_type='WinningBat' AND Date(transaction_update_date)=Date('$date')";
                                                            $amqry = mysqli_query($conn, $amsql);
                                                            $amrow = mysqli_fetch_assoc($amqry);
                                                            $amnum1 = $amrow['amt'] ?: '0';
                                                            ?>
                                                        <div class="bid_history_box bhb_win_amt" style="border: 1px dotted black;padding: 2px; margin:5px;">
                                                            <div class="row" style="align-items: baseline; padding:5px;">
                                                                <div class="col-md-6">   
                                                                    <h5 class="text-muted font-weight-medium" style="font-size: 13px;">Total Win Amount</h5>
                                                                </div>
                                                                <div class="col-md-3"> <h5 class="mb-0" style="font-size: 13px;" id="total_win_amt"><i class="bx bx-rupee"></i><?php echo $amnum1;?></h5>
                                                                </div>
                                                                <div class="col-md-3 text-sm-right">
                                                                    <button type="button" class="btn btn-primary waves-light btn-xs showwidtbl"  id="winner_btn">View</button>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <?php 
                                                        $ttl = $amnum - $amnum1;
                                                        
                                                        if ($ttl > 0) {
                                                        	$color = "green";
                                                        }elseif($ttl == 0){
                                                        	$color = "#556ee6";
                                                        }else{
                                                        	$color = "red";
                                                        }
                                                        
                                                        ?>
                                                            <div class="bid_history_area">
                                                                <div class="bid_history_box bhb_profit_amt" id="mensales" style="border: 2px solid green;padding: 2px; margin:5px;">
                                                                    <div class="row" style="align-items: baseline; padding:5px;background:<?php echo $color;?>;">
                                                                        <div class="col-md-6">
                                                                            <h5 class="text-muted font-weight-medium" id="profit_loss" style="font-size: 13px;">Total Profit Amount</h5>
                                                                        </div>
                                                                        <div class="col-md-3"><h5 class="mb-0" style="font-size: 13px;" id="total_profit_amt"><i class="bx bx-rupee"></i> <?php echo $ttl ;?> </h5>
                                                                        </div>
                                                                        <div class="col-md-3"></div>
                                                                    </div>
                                                                </div>
                                                            </div> 
                                                    </div>
                                                </div>
                                            </div>

                                        </div>

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

                            <div class="col-xl-8">
                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="card mini-stats-wid">
                                            <a href="user-management.php">
                                                <div class="card-body">
                                                    <div class="media">
                                                        <div class="media-body">
                                                            <p class="text-muted font-weight-medium">Users</p>
                                                            <?php
                                                            $tmsql = "SELECT COUNT(member_id) as idc FROM member";
                                                            $tmqry = mysqli_query($conn, $tmsql);
                                                            $tmrow = mysqli_fetch_assoc($tmqry);
                                                            $tmnum = $tmrow['idc'] ?: '0';
                                                            ?>
                                                            <h4 class="mb-0"><?php echo $tmnum; ?></h4>
                                                        </div>

                                                        <div class="mini-stat-icon avatar-sm rounded-circle bg-primary align-self-center">
                                                            <span class="avatar-title">
                                                <i class="bx bx-user font-size-24"></i>
                                            </span>
                                                        </div>
                                                    </div>
                                                </div>
                                            </a>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="card mini-stats-wid">
                                            <a href="game-name.php">
                                                <div class="card-body">
                                                    <div class="media">
                                                        <div class="media-body">
                                                            <p class="text-muted font-weight-medium">Games</p>
                                                            <?php
                                                                $mksql = "SELECT COUNT(market_id) as mki FROM market WHERE active_status != 'Removed' ";
                                                                $mkqry = mysqli_query($conn, $mksql);
                                                                $mkrow = mysqli_fetch_assoc($mkqry);
                                                                $mknum = $mkrow['mki'] ?: '0';
                                                                ?>
                                                            <h4 class="mb-0"><?php echo $mknum; ?></h4>
                                                        </div>

                                                        <div class="avatar-sm rounded-circle bg-primary align-self-center mini-stat-icon">
                                                            <span class="avatar-title rounded-circle bg-primary">
                                                <i class="bx bx-archive-in font-size-24"></i>
                                            </span>
                                                        </div>
                                                    </div>
                                                </div>
                                            </a>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="card mini-stats-wid">
                                            <div class="card-body">
                                                <div class="media">
                                                    <div class="media-body">
                                                        <p class="text-muted font-weight-medium">Starline Bid Amount</p>
                                                        <?php
                                                            $tmsql = "SELECT SUM(transaction_amount) as idc FROM wallet_transaction WHERE DATE(transaction_update_date) LIKE '%$date%' AND game_name='StarLine' AND transaction_type = 'StarLineBat'";
                                                            $tmqry = mysqli_query($conn, $tmsql);
                                                            $tmrow = mysqli_fetch_assoc($tmqry);
                                                            $tmnum = $tmrow['idc'] ?: '0';
                                                            ?>
                                                        <h4 class="mb-0"><?php echo $tmnum; ?></h4>
                                                    </div>

                                                    <div class="avatar-sm rounded-circle bg-primary align-self-center mini-stat-icon">
                                                        <span class="avatar-title rounded-circle bg-primary">
                                                <i class="bx bx-purchase-tag-alt font-size-24"></i>
                                            </span>
                                                    </div>

                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="card">
                                    <div class="card-body">
                                        <h4 class="card-title mb-4">Total Bids On Single Ank Of Date <?php echo $date?></h4>
                                        <form method="post">
                                            <div class="row">
                                                <div class="form-group col-md-5">
                                                    <label>Game Name</label>
                                                    <select id="game_id" name="game_id" class="form-control">
                                                    <option value=''>-Select Game Name-</option>
                                                    <option value="All">All</option>
                                            <?php

                                          $getsql = "SELECT * FROM market WHERE active_status != 'Removed' ";
                                          $getqry = mysqli_query($conn, $getsql);
                                          $i = 1;
                                          if (mysqli_num_rows($getqry) > 0) {
                                             while ($row = mysqli_fetch_assoc($getqry)) {
                                        ?>
                                            <option value="<?php echo $row['market_id']; ?>"><?php echo $row['market_name']; ?></option>
                                            <?php }}?>
                                                    </select>
                                                </div>
                                                <div class="form-group col-md-5">
                                                    <label>Market Time</label>
                                                    <select id="market_open" name="market_open" class="form-control">
                                            <option value=''>-Select Market Time-</option>
                                                <option value="Open">Open Market</option>
                                                <option value="Close">Close Market</option>
                                                
                                        </select>
                                                </div>
                                                <div class="form-group col-md-2">
                                                    <label>&nbsp;</label>
                                                    <button type="button" class="btn btn-primary btn-block" name="getbet" id="getbet">Get</button>
                                                </div>

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

                                <div class="row">
                                    <div class="col-md-12">
                                        <div id="search">
                                            <div class="row-2_5 tot_bit_boxs">
                                                <div class="col-md-2_5">
                                                    <div class="card border card_0">
                                                        <div class="card-header bg-transparent card_0">
                                                            <h5 class="my-0 text-primary emmmt">Total Bids <span id="bid0" class="emmmt">0</span></h5>
                                                        </div>
                                                        <div class="card-body">
                                                            <h2 id="total0"  class="emmmt">0</h2>
                                                            <h5 class="card-title mt-0 ">Total Bid Amount</h5>

                                                        </div>
                                                        <div class="card-footer-ank">Ank <span>0</span></div>
                                                    </div>
                                                </div>
                                                <div class="col-md-2_5">
                                                    <div class="card border card_1">
                                                        <div class="card-header bg-transparent card_1">
                                                            <h5 class="my-0 text-primary">Total Bids <span id="bid1" class="emmmt">0</span></h5>
                                                        </div>
                                                        <div class="card-body">
                                                            <h2 id="total1" class="emmmt">0</h2>
                                                            <h5 class="card-title mt-0 ">Total Bid Amount</h5>

                                                        </div>
                                                        <div class="card-footer-ank">Ank <span>1</span></div>
                                                    </div>
                                                </div>
                                                <div class="col-md-2_5">
                                                    <div class="card border card_2">
                                                        <div class="card-header bg-transparent card_2">
                                                            <h5 class="my-0 text-primary">Total Bids <span id="bid2" class="emmmt">0</span></h5>
                                                        </div>
                                                        <div class="card-body">
                                                            <h2 id="total2" class="emmmt">0</h2>
                                                            <h5 class="card-title mt-0 ">Total Bid Amount</h5>

                                                        </div>
                                                        <div class="card-footer-ank">Ank <span>2</span></div>
                                                    </div>
                                                </div>
                                                <div class="col-md-2_5">
                                                    <div class="card border card_3">
                                                        <div class="card-header bg-transparent card_3">
                                                            <h5 class="my-0 text-primary">Total Bids <span id="bid3" class="emmmt">0</span></h5>
                                                        </div>
                                                        <div class="card-body">
                                                            <h2 id="total3" class="emmmt">0</h2>
                                                            <h5 class="card-title mt-0 ">Total Bid Amount</h5>

                                                        </div>
                                                        <div class="card-footer-ank">Ank <span>3</span></div>
                                                    </div>
                                                </div>
                                                <div class="col-md-2_5">
                                                    <div class="card border card_4">
                                                        <div class="card-header bg-transparent card_4">
                                                            <h5 class="my-0 text-primary">Total Bids <span id="bid4" class="emmmt">0</span></h5>
                                                        </div>
                                                        <div class="card-body">
                                                            <h2 id="total4" class="emmmt">0</h2>
                                                            <h5 class="card-title mt-0 ">Total Bid Amount</h5>

                                                        </div>
                                                        <div class="card-footer-ank">Ank <span>4</span></div>
                                                    </div>
                                                </div>
                                                <div class="col-md-2_5">
                                                    <div class="card border card_5">
                                                        <div class="card-header bg-transparent card_5">
                                                            <h5 class="my-0 text-primary">Total Bids <span id="bid5" class="emmmt">0</span></h5>
                                                        </div>
                                                        <div class="card-body">
                                                            <h2 id="total5" class="emmmt">0</h2>
                                                            <h5 class="card-title mt-0 ">Total Bid Amount</h5>

                                                        </div>
                                                        <div class="card-footer-ank">Ank <span>5</span></div>
                                                    </div>
                                                </div>
                                                <div class="col-md-2_5">
                                                    <div class="card border card_6">
                                                        <div class="card-header bg-transparent card_6">
                                                            <h5 class="my-0 text-primary">Total Bids <span id="bid6" class="emmmt">0</span></h5>
                                                        </div>
                                                        <div class="card-body">
                                                            <h2 id="total6" class="emmmt">0</h2>
                                                            <h5 class="card-title mt-0 ">Total Bid Amount</h5>

                                                        </div>
                                                        <div class="card-footer-ank">Ank <span>6</span></div>
                                                    </div>
                                                </div>
                                                <div class="col-md-2_5">
                                                    <div class="card border card_7">
                                                        <div class="card-header bg-transparent card_7">
                                                            <h5 class="my-0 text-primary">Total Bids <span id="bid7" class="emmmt">0</span></h5>
                                                        </div>
                                                        <div class="card-body">
                                                            <h2 id="total7" class="emmmt">0</h2>
                                                            <h5 class="card-title mt-0 ">Total Bid Amount</h5>

                                                        </div>
                                                        <div class="card-footer-ank">Ank <span>7</span></div>
                                                    </div>
                                                </div>
                                                <div class="col-md-2_5">
                                                    <div class="card border card_8">
                                                        <div class="card-header bg-transparent card_8">
                                                            <h5 class="my-0 text-primary">Total Bids <span id="bid8" class="emmmt">0</span></h5>
                                                        </div>
                                                        <div class="card-body">
                                                            <h2 id="total8" class="emmmt">0</h2>
                                                            <h5 class="card-title mt-0 ">Total Bid Amount</h5>

                                                        </div>
                                                        <div class="card-footer-ank">Ank <span>8</span></div>
                                                    </div>
                                                </div>
                                                <div class="col-md-2_5">
                                                    <div class="card border card_9">
                                                        <div class="card-header bg-transparent card_9">
                                                            <h5 class="my-0 text-primary">Total Bids <span id="bid9" class="emmmt">0</span></h5>
                                                        </div>
                                                        <div class="card-body">
                                                            <h2 id="total9" class="emmmt">0</h2>
                                                            <h5 class="card-title mt-0 ">Total Bid Amount</h5>

                                                        </div>
                                                        <div class="card-footer-ank">Ank <span>9</span></div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="card">
                                    <div class="card-body">
                                        <h4 class="card-title mb-4">Profit Loss Report <span>On Date <?=$date?></span></h4>
                                        <hr>
                                        <form method="post">
                                            <div class="row">
                                                <!--<div class="form-group col-md-12">-->
                                                <!--    <input type="radio" id="age1" name="age">-->
                                                <!--    <label for="age1" style="font-size: 13px;">Report By Date</label>-->
                                                <!--    <input type="radio" id="age2" name="age">-->
                                                <!--    <label for="age2" style="font-size: 13px;">Report By Date Range</label>-->
                                                <!--</div>-->
                                                <div class="form-group col-md-12">
                                                    <div class="table-responsive">
                                                        <table class="table table-responsive-md table-bordered" id="viewCompAllotTbl" style="width: 100%;">
                                                            <thead>
                                                                <tr>
                                                                    <th><strong>Deposit</strong></th>
                                                                    <th><strong>Withdraw</strong></th>
                                                                    <th><strong>Total</strong></th>
                                                                    <th><strong>Result</strong></th>
                                                                </tr>
                                                            </thead>
                                                            <tbody >
                                                                <tr style="background: #a2a2a23b;">
                                                                    <td id="total_dep"><strong>-</strong></td>
                                                                    <td id="total_wid"><strong>-</strong></td>
                                                                    <td id="total_amt"><strong>--</strong></td>
                                                                    <td id="trns"><strong><a href="javascript:void(0);" style="width: 100%;"></a></strong></td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                    <!-- <label>Game Name</label>
                                                    <select id="game_id" name="game_id" class="form-control">
                                                        <option value="">-Select Game Name-</option>
                                                        <option value="All">All</option>
                                                        <option value="1">Milan Morning</option>
                                                        <option value="4">Time Bazar</option>
                                                        <option value="5">Madhur Day</option>
                                                        <option value="7">Supreme Day</option>
                                                        <option value="8">Rajdhani Day</option>
                                                        <option value="9">Kalyan</option>
                                                        <option value="10">Sridevi Night </option>
                                                        <option value="11">Madhur Night </option>
                                                        <option value="13">Milan Night </option>
                                                        <option value="14">Kalyan Night </option>
                                                        <option value="15">Rajdhani Night </option>
                                                        <option value="16">Main Bazar</option>
                                                        <option value="17">test</option>
                                                        <option value="21">GAZIYABAD</option>
                                                        <option value="76">Delhi Jodi</option>
                                                        <option value="77">Abhishek Jodi</option>
                                                        <option value="78">wsdesfgc</option>
                                                    </select> -->
                                                </div>  
                                            </div>
                                        </form>
                                    </div>
                                </div> 
                            </div>


                        </div>

                    </div>
                    
                    <div class="row" id="bettbl" style="display: none;">

                        <div class="col-sm-12">
                            <div class="card">
                                <div class="card-body">
                                    <h4 class="card-title">Bet History</h4>
                                    <div class="dt-ext table-responsive demo-gallery">
                                        <table class="table table-striped table-bordered " id="tbbid">
                                            <thead>
                                                <tr>
                                                    <th>#</th>
                                                    <th>Game Name</th>
                                                    <th>Game Type</th>
                                                    <th>Session</th>
                                                    <th>Digits</th>
                                                    <th>Points</th>
                                                    <th>User Name</th>
                                                    <th>Date</th>
                                                    <!-- <th>Action</th> -->
                                                </tr>
                                            </thead>
                                            <tbody>
                                        <?php

                                          $getsql = "SELECT * FROM `betting` as bt LEFT JOIN market mk ON bt.b_market_id = mk.market_id LEFT JOIN game gm ON bt.b_game_id = gm.game_id LEFT JOIN member mem ON bt.b_member_id = mem.member_id WHERE bt.betting_status = 'Active' AND date(betting_date) = date('$date') ORDER BY bt.betting_id DESC ";
                                          $getqry = mysqli_query($conn, $getsql);
                                          $i = 1;
                                          if (mysqli_num_rows($getqry) > 0) {
                                             while ($row = mysqli_fetch_assoc($getqry)) {
                                        ?>
                                        <tr>
                                            <td><?php echo $i; ?></td>
                                            <td><?php echo $row['market_name']; ?></td>
                                            <td><?php echo $row['game_name']; ?></td>
                                            <td><?php echo $row['betting_time_type']; ?></td>
                                            <td><?php echo $row['betting_number'] .' - '. $row['betting_number_second']; ?></td>
                                            <td><?php echo $row['betting_amount']; ?></td>
                                            <td><?php echo $row['member_name'] .' - '. $row['member_mobile']; ?></td>
                                            <td><?php echo $row['betting_date'] .' '. $row['betting_time']; ?></td>
                                        </tr>
                                    <?php
                                    $i++;
                                                 
                                             }}else {
                                        echo " <tr>
                                            <td colspan='5' style='text-align:center;'>No Winner Found</td>
                                        </tr> ";
                                    }

                                ?>
                                    </tbody>
                                        </table>
                                    </div>
                                    <div id="msg"></div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row" id="widtbl" style="display: none;">

                        <div class="col-sm-12">
                            <div class="card">
                                <div class="card-body">
                                    <h4 class="card-title">Winning History</h4>
                                    <div class="dt-ext table-responsive demo-gallery">
                                        <table class="table table-striped table-bordered " id="tbwin">
                                            <thead>
                                                <tr>
                                                    <th>#</th>
                                                    <th>Tx Id</th>
                                                    <th>Member Name</th>
                                                    <th>Member No</th>
                                                    <th>Game Name</th>
                                                    <th>Bet Number</th>
                                                    <th>Game Type</th>
                                                    <th>Amount</th>
                                                    <!-- <th>Action</th> -->
                                                </tr>
                                            </thead>
                                            <tbody>
                                        <?php

                                          $getsql = "SELECT * FROM wallet_transaction wt LEFT JOIN member mem ON wt.member_id = mem.member_id WHERE date(transaction_update_date) = date('$date') AND transaction_type='WinningBat' ORDER BY w_transaction_id DESC ";
                                          $getqry = mysqli_query($conn, $getsql);
                                          $i = 1;
                                          if (mysqli_num_rows($getqry) > 0) {
                                             while ($row = mysqli_fetch_assoc($getqry)) {
                                        ?>
                                        <tr>
                                            <td><?php echo $i; ?></td>
                                            <td><?php echo $row['transaction_id']; ?></td>
                                            <td><?php echo $row['member_name']; ?></td>
                                            <td><?php echo $row['member_mobile']; ?></td>
                                            <td><?php echo $row['market_name'] .' - '. $row['game_name']; ?></td>
                                            <td><?php echo $row['bat_number']; ?></td>
                                            <td><?php echo $row['bet_type']; ?></td>
                                            <td><?php echo $row['transaction_amount']; ?></td>
                                        </tr>
                                    <?php
                                    $i++;
                                                 
                                             }}else {
                                        echo " <tr>
                                            <td colspan='5' style='text-align:center;'>No bet Found</td>
                                        </tr> ";
                                    }

                                ?>
                                    </tbody>
                                        </table>
                                    </div>
                                    <div id="msg"></div>
                                </div>
                            </div>
                        </div>
                    </div>


                    <div class="row">

                        <div class="col-sm-12">
                            <div class="card">
                                <div class="card-body">
                                    <h4 class="card-title">Fund Request Auto Deposit History</h4>
                                    <div class="dt-ext table-responsive demo-gallery">
                                        <table class="table table-striped table-bordered " id="autoFundRequestList">
                                            <thead>
                                                <tr>
                                                    <th>#</th>
                                                    <th>User Name</th>
                                                    <th>Amount</th>
                                                    <th>Txn Id</th>
                                                    <th>Date</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                        <?php

                                          $getsql = "SELECT * FROM wallet_transaction wt INNER JOIN member m ON wt.member_id = m.member_id  WHERE wt.transaction_type = 'AddAmt' || wt.transaction_type = 'Add' AND transaction_update_date ='$date' ORDER BY wt.w_transaction_id DESC LIMIT 0 ,10";
                                          $getqry = mysqli_query($conn, $getsql);
                                          $i = 1;
                                          if (mysqli_num_rows($getqry) > 0) {
                                             while ($row = mysqli_fetch_assoc($getqry)) {
                                        ?>
                                        <tr>
                                            <td><?php echo $i; ?></td>
                                            <td><?php echo $row['member_name'] .' - '. $row['member_mobile']; ?></td>
                                            <td><?php echo $row['transaction_amount']; ?></td>
                                            <td><?php echo $row['transaction_id']; ?></td>
                                            <td><?php echo $row['transaction_update_date']; ?></td>
                                        </tr>
                                    <?php
                                    $i++;
                                                 
                                             }}else {
                                        echo " <tr>
                                            <td colspan='5' style='text-align:center;'>No New Request</td>
                                        </tr> ";
                                    }

                                ?>
                                    </tbody>
                                        </table>
                                    </div>
                                    <div id="msg"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <footer class="footer">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-sm-6">
                        <script>
                            document.write(new Date().getFullYear())
                        </script> ©Matka.
                    </div>
                    <div class="col-sm-6">
                        <div class="text-sm-right d-none d-sm-block">

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


        <input type="hidden" id="base_url" value="">
        <input type="hidden" id="admin" value="">

        <div id="snackbar"></div>
        <div id="snackbar-info"></div>
        <div id="snackbar-error"></div>
        <div id="snackbar-success"></div>


        <script src="adminassets/libs/jquery/jquery.min.js"></script>
        <script src="adminassets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
        <script src="adminassets/libs/metismenu/metisMenu.min.js"></script>
        <script src="adminassets/libs/simplebar/simplebar.min.js"></script>
        <script src="adminassets/libs/node-waves/waves.min.js"></script>
        <script src="adminassets/libs/select2/js/select2.min.js"></script>
        <script src="adminassets/js/pages/form-advanced.init.js"></script>
        <!-- Required datatable js -->
        <script src="adminassets/libs/datatables.net/js/jquery.dataTables.min.js"></script>
        <script src="adminassets/libs/datatables.net-bs4/js/dataTables.bootstrap4.min.js"></script>
        <!-- Buttons examples -->
        <script src="adminassets/libs/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
        <script src="adminassets/libs/datatables.net-buttons-bs4/js/buttons.bootstrap4.min.js"></script>
        <!--<script src="adminassets/libs/jszip/jszip.min.js"></script>-->
        <!--<script src="adminassets/libs/pdfmake/build/pdfmake.min.js"></script>-->
        <script src="adminassets/libs/pdfmake/build/vfs_fonts.js"></script>
        <script src="adminassets/libs/datatables.net-buttons/js/buttons.html5.min.js"></script>
        <script src="adminassets/libs/datatables.net-buttons/js/buttons.print.min.js"></script>
        <script src="adminassets/libs/datatables.net-buttons/js/buttons.colVis.min.js"></script>

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

        <!-- Datatable init js -->
        <script src="adminassets/js/pages/datatables.init.js"></script>
        <!-- App js -->
        <script src="adminassets/js/app.js"></script>
        <!-- <script src="adminassets/js/customjs.js?v=9051"></script> -->

        <script type="text/javascript">
            $(document).ready(function() {
                $('#autoFundRequestList').DataTable();
            });
        </script>
        
        <script type="text/javascript">
            $(document).ready(function() {
                $('#tbbid').DataTable();
            });
        </script>


        <script type="text/javascript">
            $(document).ready(function() {
                $('#tbwin').DataTable();
            });
        </script>

        
        <script type="text/javascript">
              $(document).ready(function() {
                // Approve Request
                // $(document).on('click', '#getbet', function() {
                    $('#getbet').on('click', function () {
                  var game_id = document.getElementById('game_id').value
                  var market_open = document.getElementById('market_open').value
                  var zero = 0;
                  
                  for (var i = 0; i < 10; i++) {
                         var n = 'total'+i;
                         var m = 'bid'+i;
                         document.getElementById(n).innerHTML = zero;
                         document.getElementById(m).innerHTML = zero;
                }
                
        
                //   alert(game_id + ' ' + market_open )
        
                  $.ajax({
                    url: 'apiz/singlenumber_bet.php',
                    type: 'POST',
                    data: {
                      'game_id': game_id,
                      'market_open': market_open,
                    },
                    success: function(response) {
                        var res = JSON.parse(response);
                        // console.log(JSON.parse(response))
                        var list = res.list;
                        if (list != 'No Bet') {

                            var num = null;
                        
                        for (var i = list.length - 1; i >= 0; i--) {
                            var num = list[i].number
                            var amount = ''
                            var numcount = list[i].betnum
                            if (num == 0) {
                                var amount = list[i].amount;
                                document.getElementById("total0" ).innerHTML = amount;
                                document.getElementById("bid0" ).innerHTML = numcount;
                            }
                            if (num == 1) {
                                var amount = list[i].amount;
                                document.getElementById("total1" ).innerHTML = amount;
                                document.getElementById("bid1" ).innerHTML = numcount;
                            }
                            if (num == 2) {
                                var amount = list[i].amount;
                                document.getElementById("total2" ).innerHTML = amount;
                                document.getElementById("bid2" ).innerHTML = numcount;
                            }
                            if (num == 3) {
                                var amount = list[i].amount;
                                document.getElementById("total3" ).innerHTML = amount;
                                document.getElementById("bid3" ).innerHTML = numcount;
                            }
                            if (num == 4) {
                                var amount = list[i].amount;
                                document.getElementById("total4" ).innerHTML = amount;
                                document.getElementById("bid4" ).innerHTML = numcount;
                            }
                            if (num == 5) {
                                var amount = list[i].amount;
                                document.getElementById("total5" ).innerHTML = amount;
                                document.getElementById("bid5" ).innerHTML = numcount;
                            }
                            if (num == 6) {
                                var amount = list[i].amount;
                                document.getElementById("total6" ).innerHTML = amount;
                                document.getElementById("bid6" ).innerHTML = numcount;
                            }
                            if (num == 7) {
                                var amount = list[i].amount;
                                document.getElementById("total7" ).innerHTML = amount;
                                document.getElementById("bid7" ).innerHTML = numcount;
                            }
                            if (num == 8) {
                                var amount = list[i].amount;
                                document.getElementById("total8" ).innerHTML = amount;
                                document.getElementById("bid8" ).innerHTML = numcount;
                            }
                            if (num == 9) {
                                var amount = list[i].amount;
                                document.getElementById("total9" ).innerHTML = amount;
                                document.getElementById("bid9" ).innerHTML = numcount;
                            }
                            console.log (num + ' - ' + amount)
                        }

                        }else {
                            alert('No Ank Bet Found')
                        }
                        
                    }
                  });
                });
              });
        </script>


        <!-- Bet Hide Show -->

        <script>
            $(document).ready(function(){
                $('.showbettbl').on('click', function() {
                    document.getElementById("bettbl").style.display = 'block';
                    document.getElementById("widtbl").style.display = 'none';
                });

                $('.showwidtbl').on('click', function() {
                    document.getElementById("widtbl").style.display = 'block';
                    document.getElementById("bettbl").style.display = 'none';
                });
            }); 
        </script>

        <!-- Bet Hide Show -->

        <!-- work start is here -->
        <script>
            $(document).ready(function(){
                    $('#getsubmit').on('click', function() {
                        //var id = $('#market_id').val();
                    // setInterval(function() {
                        var id = $('#game_name').val();
                        var betdate = $('#start_date1').val();
                        $.ajax({ //create an ajax request to display.php
                            type: "POST",
                            url: "apiz/bet_live_copy.php",
                            data : {
                                id: id,
                                betdate: betdate,
                            },
                            success: function(dataResult) {
                                var data = JSON.parse(dataResult).data;
                                var betamt = data.betamt;
                                var winamt = data.winamt;
                                var totalamt = data.totalamt;
                                var bttype = data.type;

                                document.getElementById("total_bid_amt").innerHTML = betamt;
                                document.getElementById("total_win_amt").innerHTML = winamt;
                                document.getElementById("total_profit_amt").innerHTML = totalamt;
                                if(bttype == "Profit"){
                                    document.getElementById("mensales").style.background = "#556ee6";
                                }else if(bttype == "Noloss"){
                                    document.getElementById("mensales").style.background = "#0dcebc";
                                }else {
                                    document.getElementById("mensales").style.background = "#f1673e";
                                }
                            }
                        });
                    // },1000);
                });
            }); 
        </script>
        <script>
            $(document).ready(function(){
                    // $('#getsubmit').on('click', function() {
                        //var id = $('#market_id').val();
                    // setInterval(function() {
                        // var id = $('#game_name').val();
                        // var betdate = $('#start_date1').val();
                        $.ajax({ //create an ajax request to display.php
                            type: "POST",
                            url: "apiz/dailycount.php",
                            data : {
                                // id: id,
                                // betdate: betdate,
                            },
                            success: function(dataResult) {
                                var data = JSON.parse(dataResult).data;
                                var betamt = data.betamt;
                                var winamt = data.winamt;
                                var totalamt = data.totalamt;
                                var bttype = data.type;

                                document.getElementById("total_dep").innerHTML = betamt;
                                document.getElementById("total_wid").innerHTML = winamt;
                                document.getElementById("total_amt").innerHTML = totalamt;
                                if(bttype == "Profit"){
                                    document.getElementById("trns").innerHTML = bttype; 
                                    document.getElementById("trns").style.background = "#556ee6";
                                }else if(bttype == "Noloss"){
                                    document.getElementById("trns").innerHTML = bttype; 
                                    document.getElementById("trns").style.background = "#0dcebc";
                                }else {
                                    document.getElementById("trns").innerHTML = bttype; 
                                    document.getElementById("trns").style.background = "#f1673e";
                                }
                            }
                        });
                    // },1000);
                });
            // }); 
        </script>
        <!-- work end is here -->

    </body>

    </html>