<?php include("../Header/Session.php"); ?>
<?php include("../Header/Connection.php"); ?>


<!DOCTYPE html>
<html lang="en">
<?php include ("../Header/head.php"); ?>
<body class="skin-default fixed-layout">

<div id="main-wrapper">    
<?php include ("../Header/header.php"); ?>
<?php include ("../Header/left_menu.php"); ?>
<?php include ("../Header/right_sidebar.php"); ?>

<?php
$type_wallet = $_GET['type_wallet'];
$status = $_GET['status'];
          
$sql_wallet = "SELECT * FROM wallet 
WHERE ref_code='$ref_code' LIMIT 1";
$result_wallet = $mysqli->query($sql_wallet);
if ($result_wallet ->num_rows > 0)
{
	$row_wallet = $result_wallet ->fetch_assoc();
	$e_wallet = $row_wallet['cash_wallet'];
    $gold_wallet = $row_wallet['product_wallet'];
}

if ( $type_wallet == "e_wallet")
{
    $wallet = $e_wallet;
    $walletname = "e-Wallet";
    $type_of_transaction = "CW";
    $rm_view = "$";
}
else  
if ( $type_wallet == "a_wallet")
{
    $wallet = $gold_wallet;
    $walletname = "Activation Wallet";
    $type_of_transaction = "PW";
    $gram_view = "gram";
}

?>
<div class="page-wrapper">
<div class="container-fluid">

<br><br>

<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-body">
                <form method="post" action="" enctype="multipart/form-data">
                    <div class="form-body">
                        <h3 class="card-title">Date Selection</h3>
                        <hr>
                        <div class="row p-t-20">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="control-label">From</label>
                                    <input type="date" class="form-control" name="from_date"  required>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="control-label">To</label>
                                    <input type="date" class="form-control" name="to_date"  required>
                                </div>
                            </div>                   
                        </div>
                    </div>
                    <div class="form-actions">
                        <button name="Date_Selection" class="btn btn-success"><i class="fa fa-check"></i> Submit</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<?php
if (isset($_POST['Date_Selection'])) 
{
    $from_date = $_POST['from_date'];
    $to_date = $_POST['to_date'];

    $from_date_display = date('d-m-Y', strtotime($_POST['from_date']));
    $to_date_display = date('d-m-Y', strtotime($_POST['to_date']));
}

date_default_timezone_set("Asia/Kuala_Lumpur");
$from_date_display = $from_date_display ?? date('d-m-Y');
$to_date_display   = $to_date_display   ?? date('d-m-Y');

if (empty($from_date)) $from_date = date('Y-m-d');
if (empty($to_date))   $to_date   = date('Y-m-d');

$ref_code = $_GET['ref_code'];
if ( $ref_code == '')
{
	$ref_code=$_SESSION['ref_code'];
}

$q = "SELECT *
FROM user
WHERE ref_code='$ref_code'";
$result = $mysqli->query($q);
if ($result->num_rows > 0)
{
    while($record = $result -> fetch_assoc())
    {    	
        $id = $record['id'] ;
        $sponsor_code = $record['sponsor_code'] ;
        $ref_code = $record['ref_code'] ;
        $name = $record['name'];
        $email = $record['email'];
        $password = $record['password'];
        $phone_number = $record['phone_number'];
        $paid = $record['paid'];
        $address = $record['address'];
        $bank_type = $record['bank_type'];
        $acc_no = $record['acc_no'];
        $acc_holder = $record['acc_holder'];		   
?> 
<div class="row">
<div class="col-lg-12">
    <div class="card">
        <div class="card-body">
            <h4 class="card-title">List Of Funds From <?php echo $from_date_display; ?> To <?php echo $to_date_display; ?> </h4>
            <h6 class="card-subtitle">Export data to Copy, CSV, Excel, PDF & Print</h6>
            <div class="table-responsive m-t-40">
                <form method="post" action="../Controller/Database_sql.php" enctype="multipart/form-data">
                <table id="example23"
                    class="display nowrap table table-hover table-striped table-bordered"
                    cellspacing="0" width="100%">
                    <thead>
                        <tr>
                            <th>DP ID</th>
                            <th>Member Info</th>
                            <th>Type of DP</th>
                            <th>Date</th>
                            <th>Payment Reference</th>
                            <th>Receipt Attachment</th>
                            <th>Hash TRX</th>
                            <th>Amount($)</th>
                            <th>Fund Fees($)</th>
                            <th>Status</th>
                            <?php 
                            if ( $type_wallet == "gold_wallet")
                            {
                            ?>
                                <th>Detail</th>
		                    <?php
                            }
                            ?>
                            <?php 
                            if ( $level == "1")
                            {
                            ?>
                                <th>Action</th>
		                    <?php
                            }
                            ?>

                        </tr>
                    </thead>                                      
                    <tbody>
                        <?php
                        if ( $level == '1')
                        {
                            $q = "SELECT *
                            FROM transactions  
                            Where description Like 'Deposit To Activation Wallet%'
                            And status Not In ('100','9')
                            And created_date >= '$from_date'
                            And created_date <= '$to_date'
                            order by id Desc ";
						}
                        else
                        {
                            $q = "SELECT *
                            FROM transactions  
                            Where description Like 'Deposit To Activation Wallet%'
                            And user_ref_code = '$ref_code'
                            And status Not In ('100','9')
                            And created_date >= '$from_date'
                            And created_date <= '$to_date'
                            order by id Desc ";
						}

                        $result = $mysqli->query($q);
                        if ($result->num_rows > 0)
                        {
                        while($record = $result -> fetch_assoc())
                        {    							   
						    $wd_id = $record['id'];
                            $ref_code = $record['user_ref_code'];
                            $deposit_way = $record['deposit_way'];
                            $trans_code = $record['trans_code'];
                            $created_date = date('d-m-Y h:i:s a ', strtotime($record['created_date']));
						    $description = $record['description'];
                            $receipt_upload = $record['receipt_upload'];
                            $payment_reference = $record['payment_reference'];
							$amount = number_format($record['in_transactions'],2);
                            $balance = number_format($record['balance'],2);
							$fees = number_format($record['fees'],2);
                            $trx_ref = $record['trx_ref'];
                            $deposit_status_1 = $record['deposit_status'];

                            if ($deposit_way == "FPX")
                            {
                               $type_of_deposit = "FPX Or Credit Card";
							}
                            else
                            if ($deposit_way == "Upload_Receipt")
                            {
                              $type_of_deposit = "Upload Bank In Receipt";
							}
                            else
                            if ($deposit_way == "USDT")
                            {
                               $type_of_deposit = "Transfer To MyUHM USDT Wallet";
							}
                            

                            if ( $deposit_status_1 == '0')
							{
							    $deposit_status = 'Pending' ;
							}
							else
							if ( $deposit_status_1 == '1')
							{
							    $deposit_status = 'Success' ;
							}
							else
							if ( $deposit_status_1 == '')
							{
							    $deposit_status = '' ;
							} 

                            //Check user info
                            $sql_user = "SELECT *
                                         FROM user
                                         Where ref_code = '$ref_code'";
                            $result_user = $mysqli->query($sql_user);
	                        if ($result_user ->num_rows > 0)
	                        {
		                        $row_user = $result_user ->fetch_assoc();
		                        $User_ref_code = $row_user['ref_code'];
                                $User_name = $row_user['name'];
                                $User_email = $row_user['email'];
                                $User_phone_number = $row_user['phone_number'];
	                        }
                        ?>
                        <tr>
                            <td>WD00<?php echo $wd_id ;?></td>
                            <td><?php echo $User_ref_code; ?> | <?php echo $User_name; ?> | <?php echo $User_email; ?> | <?php echo $User_phone_number; ?></td>
                            <td><?php echo $type_of_deposit ;?></td>
                            <td><?php echo $created_date ;?></td>
                            <td><?php echo $payment_reference ;?>
                            <td><?php echo $receipt_upload ;?>
                            <?php if ($receipt_upload != "")
                            {
                            ?>
                            <br>
                            <a href="../Controller/uploads/<?php echo $receipt_upload; ?>" download><font color="blue">Click To Download</font></a><br>
                            <?php
							}
                            ?>
                            </td>
                            <td><?php echo $trx_ref ;?></td>
							<td> $ <?php echo $amount ;?> </td>
                            <td> $ <?php echo $fees ;?></td>
                            <td><?php echo $deposit_status; ?></td>
                            
                            <?php 
                            if ( $level == "1" &&  $deposit_status_1 == '0')
                            {
                            ?>
                                <td>
                                <a href="../Controller/Database_sql.php?form_name_Approve_Deposit=Approve_Deposit&trans_code=<?php echo $trans_code;?>&ref_code=<?php echo $ref_code;?>" 
                                onClick="javascript: return confirm('Do you want to proceed?');" class="btn btn-success"><i class="fa fa-check"></i>&nbsp; Approve Deposit</a>  

                                <a href="../Controller/Database_sql.php?form_name_Reject_Deposit=Reject_Deposit&trans_code=<?php echo $trans_code;?>&ref_code=<?php echo $ref_code;?>" 
                                onClick="javascript: return confirm('Do you want to proceed?');" class="btn btn-success"><i class="fa fa-check"></i>&nbsp; Delete Request</a>  
                                </td>
		                    <?php
                            }
                            else
                            if ( $level == "1" &&  $deposit_status_1 == '1')
                            {
                            ?>
                                 <td>
                                </td>
							<?php
                            }
                            ?>                    
                        </tr>
                        <?php 
                        }
                        }
                        ?>
                    </tbody>
                </table>
                </form>
            </div>
        </div>
    </div> 
    <?php
    }
    }
    else
    {
    echo mysql_error();
    }
    ?>		
</div>
</div>

</div>
</div>
<?php include ("../Footer/footer.php"); ?>

</div>
<?php include ("../Header/all_jquery.php"); ?>
</body>

</html>