<?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";

    $mwallet        = MsumWall("masuk", "mwallet") - MsumWall("keluar", "mwallet");
    $mwallet_masuk  = MsumWall("masuk", "mwallet");
    $limit = 100;

    if ($cwallet >= $limit) {
        $link = "request_withdraw.php";
    } else {
        $link = "#";
    }

    $result = mysqli_query($con, "SELECT SUM(amaun) FROM withdraw WHERE userid='".$_SESSION['aidi']."'");
    $withdraw = mysqli_fetch_array($result);
    
?>
        <div id="page-wrapper" >
            <div id="page-inner">
                <div class="row">
                    <div class="col-md-12">
                     <h2>eWallet</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-primary set-icon">
                                <i class="fa fa-usd"></i>
                            </span>
                        <div class="text-box" >
                            <p class="main-text"><?= number_format($mwallet,2) ?> MYR</p>
                            <p class="text-muted">Available Balance</p>
                        </div>
                        </div>
                    </div>
                    <div class="col-md-6 col-sm-6 col-xs-6">
                        <div class="panel panel-back noti-box">
                            <span class="icon-box bg-primary set-icon">
                                <i class="fa fa-gift"></i>
                            </span>
                        <div class="text-box" >
                            <p class="main-text"><?= number_format($mwallet_masuk,2) ?> MYR</p>
                            <p class="text-muted">Total Redeem</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">
                             eWallet 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>Receipt</th>
                                            <th class="text-right">Debit</th>
                                            <th class="text-right">Credit</th>
                                        </tr>
                                    </thead>
                                    <tbody>
<?
$c = 1;  


    // CASH BONUS    
        $sql = "SELECT * FROM mwallet WHERE merchant_id ='".$_SESSION['aidi']."' ORDER BY tarikh DESC";
        $result = mysqli_query($con, $sql);

        while ($row = mysqli_fetch_array($result)) {
            
            $ahli_sql       = "SELECT * FROM ahli WHERE id ='".$row[6]."' ";
            $ahli_result    = mysqli_query($con, $ahli_sql);
            $ahli           = mysqli_fetch_array($ahli_result);
?>
                                        <tr >
                                            <td><?= $c++ ?>
                                            <td><?= $row[1] ?></td>
                                            <td><?= "Total Redeem RM".$row[5]." from <span class='text-danger'>".strtoupper($ahli[1])."</span>" ?></td>
                                            <td><a style="text-decoration:none;" target="_blank" href="paymerchant.php?r=<?= $row[7] ?>"><?= $row[7] ?></a></td>
                                            <td class="text-right"><?= $row[4]?></td>
                                            <td class="text-right"><?= $row[5] ?></td>
                                        </tr>
 <?     } 
 ?> 
 
 
                                    </tbody>
                                </table>
                            </div>
                            
                        </div>
                    </div>
                    <!--End Advanced Tables -->
                </div>
            </div>        
    </div>
             <!-- /. PAGE INNER  -->
            </div>
<?
    include "_footer2.php";
}
?>
