<?php
session_start();
$key = md5(date("Y-m-d").":".$_SERVER['REMOTE_ADDR']);
if (isset($_SESSION['aW1iZXN0cmEuY29tLm15']) <> $key) {
    header("location:".$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME']); // cara baru !
} else {
    include "_header2.php";
    include "_navtop.php";
    include "_navside.php";
    include "_functions.php";
    require "conn.php";

    $cwallet = sumWall("masuk", "cwallet") - sumWall("keluar", "cwallet");   

    
    $result = mysqli_query($con, "SELECT * FROM ahli WHERE id='".$_SESSION['aidi']."'");
    $rows = mysqli_fetch_array($result);        
    
?>
        <div id="page-wrapper" >
            <div id="page-inner">
                <div class="row">
                    <div class="col-md-12">
                     <h2>Bonus</h2>                          
                    </div>
                </div>
            <hr />
<?
if ($_SESSION['username'] <> "admin") {
?>
                <div class="row">

                    <div class="col-md-6 col-sm-6 col-xs-6">
                        <div class="panel panel-back noti-box">
                            <span class="icon-box bg-color-green set-icon">
                                <i class="fa fa-usd"></i>
                            </span>
                        <div class="text-box" >
                            <p class="main-text"><?= number_format($cwallet,2) ?> MYR</p>
                            <p class="text-muted">Balance</p>
                        </div>
                </div>
             </div>


            </div>
                 <!-- /. ROW  -->
                <hr />
<? } ?>
            <div class="row">
                <div class="col-md-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                             Bonus History
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Date</th>
                                            <th>Description</th>
                                            <th>Ref</th>
                                            <th>Debit</th>
                                            <th>Credit</th>
                                        </tr>
                                    </thead>
                                    <tbody>
<?
$c = 1;    
     $sql = "SELECT tarikh, keterangan, rujukan, keluar, masuk FROM cwallet_carwash WHERE userid ='".$_SESSION['aidi']."' ORDER BY tarikh DESC";
  //  $sql = "SELECT tarikh, keterangan, rujukan, keluar, masuk   FROM cwallet 
  //                                                              INNER JOIN cwallet_accessories  ON cwallet.userid = cwallet_accessories.userid
  //                                                              INNER JOIN cwallet_carwash      ON cwallet.userid = cwallet_carwash.userid
  //                                                              INNER JOIN cwallet_cash         ON cwallet.userid = cwallet_cash.userid
  //                                                              INNER JOIN cwallet_travel       ON cwallet.userid = cwallet_travel.userid
  //                                                              INNER JOIN cwallet_insurance    ON cwallet.userid = cwallet_insurance.userid
  //                                                              WHERE userid ='".$_SESSION['aidi']."' ORDER BY tarikh DESC";
echo $sql;
    $result = mysqli_query($con, $sql);

    while ($row = mysqli_fetch_array($result)) {
?>
                                        <tr class="even">
                                            <td><?= $c++ ?>
                                            <td><?= $row[0] ?></td>
                                            <td><?= $row[1] ?></td>
                                            <td><?= $row[2] ?></td>
                                            <td class="right"><?= $row[3]?></td>
                                            <td class="right"><?= $row[4] ?></td>
                                        </tr>
 <? } ?>
                                    </tbody>
                                </table>
                            </div>
                            
                        </div>
                    </div>
                    <!--End Advanced Tables -->
                </div>
            </div>          
    </div>
             <!-- /. PAGE INNER  -->
            </div>
<?
    include "_footer2.php";
}
?>
