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

<!-- Main wrapper - style you can find in pages.scss -->
<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'];
    $pins_wallet = $row_wallet['pins_wallet'];

}

if ( $type_wallet == "e_wallet")
{
    $wallet = $e_wallet;
    $walletname = "e-Wallet";
    $type_of_transaction = "CW";
    $rm_view = "$";
    $draw_id = "WD";
}
else  
if ( $type_wallet == "gold_wallet")
{
    $wallet = $gold_wallet;
    $walletname = "Gold Wallet";
    $type_of_transaction = "PW";
    $gram_view = "gram";
}
else  
if ( $type_wallet == "pins_wallet")
{
    $wallet = $pins_wallet;
    $walletname = "Capital Wallet";
    $type_of_transaction = "DW";
    $rm_view = "$";
    $draw_id = "CD";
}

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

<!-- Bread crumb and right sidebar toggle -->
<!--?php include ("../Header/breadcumb.php"); ?-->
<br><br>
<!-- End Bread crumb and right sidebar toggle -->
    
<!-- Start Page Content -->
<!-- ============================================================== -->

<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 Withdraw 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">              
                <table 
                <?php 
                if ($level == '2') 
                { 
                ?>
                id="example23" 
                <?php 
                } 
                ?>
                class="display nowrap table table-hover table-striped table-bordered"
                    cellspacing="0" width="100%">
                    <thead>                    
                        <tr>
                            <th><?php echo $draw_id; ?> ID</th>
                            <th>Type of Withdraw</th>
                            <th>Date</th>
                            <th>Member ID</th>
                            <th>Acc Holder Name</th>
                            <th>Acc No</th>
                            <th>Bank</th>
                            <th>USDT Wallet Address</th>
                            <th>Hash TRX</th>
                            <th>Amount($)</th>
                            <th>Amount(RM)</th>
                            <th>Withdraw Fees($)</th>
						    <th>Balance<font color="white">____</font></th>
                            <th>Status</th>
                            <?php 
                            if ( $type_wallet == "gold_wallet")
                            {
                            ?>
                                <th>Detail</th>
		                    <?php
                            }
                            ?>

                        </tr>
                    </thead>                                      
                    <tbody>
                        <?php
                        if ( $level == '1')
                        {
                            $q = "SELECT *
                            FROM withdraw_transaction  
                            Where tac_verify_status ='1'
                            And type_of_transaction = '$type_of_transaction'
                            And created_date >= '$from_date'
                            And created_date <= '$to_date'
                            order by id Desc ";
						}
                        else
                        {
                            $q = "SELECT *
                            FROM withdraw_transaction  
                            Where ref_code = '$ref_code'
                            And tac_verify_status ='1'
                            And type_of_transaction = '$type_of_transaction'
                            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['ref_code'];
                            $trans_code = $record['trans_code'];
                            $created_date = date('d-m-Y h:i:s a ', strtotime($record['created_date']));
                            $created_datetime = date('d-m-Y h:i:s a ', strtotime($record['created_datetime']));
						    $description = $record['description'];
							$amount = number_format($record['amount'],2);
                            $amount_MYR = number_format($record['amount_MYR'],2);
                            $balance = number_format($record['balance'],2);
							$withdraw_fees = number_format($record['withdraw_fees'],2);
                            $blockchain_address = $record['blockchain_address'];
                            $Hash_TRX = $record['Hash_TRX'];
                            $withdraw_status_1 = $record['withdraw_status'];
							$acc_holder_name = $record['acc_holder_name'];
							$acc_no = $record['acc_no'];
							$bank = $record['bank'];
                            $remark = $record['remark'];
                            $payment_status_1 = $record['payment_status'];

                            if ($blockchain_address == "")
                            {
                              $type_of_withdraw = "Withdraw To Bank Acc";
							}
                            else
                            if ($blockchain_address != "")
                            {
                               $type_of_withdraw = "Withdraw To USDT Wallet";
							}

                            if ( $withdraw_status_1 == '0')
							{
							        $withdraw_status = 'Pending' ;
							}
							else
							if ( $withdraw_status_1 == '1')
							{
							    $withdraw_status = 'Success' ;
							}
							else
							if ( $withdraw_status_1 == '')
							{
							    $withdraw_status = '' ;
							} 

                            
                            if ( $payment_status_1 == '0')
							{
							        $payment_status = 'Pending' ;
							}
							else
							if ( $payment_status_1 == '1')
							{
							    $payment_status = 'Success' ;
							}
							else
							if ( $payment_status_1 == '')
							{
							    $payment_status = '' ;
							} 
                        ?>
                        <form method="post" action="../Controller/Database_sql.php" enctype="multipart/form-data">
                        <tr>
                             <td>
                            <?php 
                            if ( $level == "1" &&  $payment_status_1 == '0')
                            {
                            ?>
                            <input type="checkbox" name="witdhraw_id[]" value="<?php echo $wd_id; ?>"> <?php echo $draw_id ;?>00<?php echo $wd_id ;?></input>
                            <?php
                            }
                            else
                            {
                            ?>
                            <?php echo $draw_id ;?>00<?php echo $wd_id ;?>
                            <?php
							}
                            ?>
                            </td>
                            <td><?php echo $type_of_withdraw ;?></td>
                            <td><?php echo $created_datetime ;?></td>
                            <td><?php echo $ref_code ;?></td>
                            <td><?php echo $acc_holder_name ;?></td>
                            <td><?php echo $acc_no ;?></td>
                            <td><?php echo $bank;?></td>
                            <td><?php echo $blockchain_address;?></td>
                            <?php
                            if ($level == '1')
                            {
                            ?>
                                <td><input type="text" class="form-control" name="Hash_TRX" value="<?php echo $Hash_TRX;?>"></td>
                            <?php
							}
                            else
                            {
                            ?>
                                <td><?php echo $Hash_TRX;?></td>
                            <?php
							}
                            ?>
                            
							<td> $ <?php echo $amount ;?> </td>
                            <td> RM <?php echo $amount_MYR ;?> </td>
                            <td> $ <?php echo $withdraw_fees ;?></td>
                            <?php if ($level == '1')
                            {
                            ?>
                               <td>$<?php echo $balance;?></td>
                            <?php
							}
                            else
                            {
                            ?>
                               <td>$<?php echo $balance;?></td>
                            <?php
							}
                            ?>
                            <td>
                            <?php 
                                if ( $payment_status_1 != "")
                                {
                                    echo $payment_status;
								}
                                else
                                {
                                    echo $withdraw_status;
								}
                            ?> 
                            </td>   
                        </tr>
                        <?php 
                        }
                        }
                        ?>
                        <button name="form_name_Approve_Withdraw_Bulk" class="btn btn-success"><i class="fa fa-check"></i> Approve Tick Withdraw</button><br><br>
                        </form>   
                    </tbody>
                </table>
                
            </div>
        </div>
    </div> 
    <?php
    }
    }
    else
    {
    echo mysql_error();
    }
    ?>		
</div>
</div>
                				
<!-- ============================================================== -->
<!-- End PAge Content -->

</div>
<!-- End Container fluid  -->
</div>
<!-- End Page wrapper  -->


<!-- Footer Start-->
<?php include ("../Footer/footer.php"); ?>
<!-- Footer End-->

</div>
<!-- End Wrapper -->
<!-- All Jquery -->
    

<!-- All Jquery Start-->
<?php include ("../Header/all_jquery.php"); ?>
<!-- All Jquery End-->

    

</body>

</html>