<?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'];
$withdraw = $_GET['withdraw'];
$type_wallet = "gold_wallet";
      
$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 = $result_wallet ->fetch_assoc();
	$e_wallet = $row_wallet['cash_wallet'];
    $product_wallet = $row_wallet['product_wallet'];
}


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

$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();
	$name = $row_user['name'];
    $last_name = $row_user['last_name'];
    $phone_number = $row_user['phone_number'];
    $address = $row_user['address'];
    $address_2 = $row_user['address_2'];
    $state = $row_user['state'];
    $area = $row_user['area'];
    $postcode = $row_user['postcode'];
    $country = $row_user['country'];
    $ic_front = $row_user['ic_front'];
    $ic_back = $row_user['ic_back'];
}

$sql_curr_rate = "SELECT *
			     FROM currency_rate_setting
			     Where status='1'
			     order by id Asc";
$result_curr_rate = $mysqli->query($sql_curr_rate);
if ($result_curr_rate ->num_rows > 0)
{
	$deposit_rm = $row_curr_rate['deposit_rm'];
    $withdrawal_rm = $row_curr_rate['withdrawal_rm'];
    $withdraw_fees_usd = $row_curr_rate['withdraw_fees_usd'];
    $withdraw_fees_usdt_percent = $row_curr_rate['withdraw_fees_usdt_percent'];
}
?>
        
<!-- 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 -->
<!-- ============================================================== -->

<?php

$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'];
    $deposit_rm_individual = $record['deposit_rm'];

    $sql_curr_rate = "SELECT *
				      FROM currency_rate_setting
				      Where status='1'
				      order by id Asc";
    $result_curr_rate = $mysqli->query($sql_curr_rate);
	if ($result_curr_rate->num_rows > 0)
	{
		$row_curr_rate = $result_curr_rate ->fetch_assoc();
		$deposit_rm = $row_curr_rate['deposit_rm'];
        $withdrawal_rm = $row_curr_rate['withdrawal_rm'];
        $withdraw_fees_usd = $row_curr_rate['withdraw_fees_usd'];
	}
    
	if ($deposit_rm_individual == '0')
	{
		$deposit_rm = $deposit_rm;
	}
	else
	{
		$deposit_rm = $deposit_rm_individual;
	}
?> 

<div class="row">
<div class="col-lg-12">
    <div class="card">
        <div class="card-body">
            <form method="post" action="../Controller/Database_sql.php" onsubmit="return confirm('Do you want to proceed?');" enctype="multipart/form-data">
                <div class="form-body">

                    <h3 class="card-title">Fund To <?php echo $walletname; ?>: $<?php echo number_format($wallet,2); ?></h3> 
                    <hr>
                    <div class="row p-t-20">

                         <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label">Way Of Fund</label>
                                <br>
                                <select class="form-control" name="deposit_way" id="deposit_way" onchange="myCalculation()" required>
                                    <option value="">Please Select Way Of Fund</option>
                                    <option value="FPX">FPX Or Credit Card</option>
                                    <!--option value="Upload_Receipt">Upload Bank In Receipt</option-->  
                                    <!--option value="PayPal">PayPal</option-->  
                                    <!--option value="USDT">Transfer To MyUHM USDT Wallet</option--> 
                                </select>
                            </div>
                        </div>
                        
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label">Amount To Fund(RM)</label>
                                <input type="number" step="0.01" class="form-control" id="amount_rm" name="amount_rm" onkeyup="myCalculation()" required>
                            </div>
                        </div>

                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label">Amount Need To Fund($)</label>
                                <input type="number" step="0.01" class="form-control" id="amount" name="amount" onkeyup="myCalculation()" readonly>
                            </div>
                        </div>

                        <div id="Payment_Reference_Div" class="col-md-6">
                            <div class="form-group">
                                <label class="control-label">Payment Reference</label>
                                <input type="text" class="form-control" id="payment_reference" name="payment_reference"><br>
                                <font color="red">Important Notice.<br>
                                Transfer Using Instant Transfer ONLY.<br>
                                Please Type Your User ID or Name at Payment Reference, Do Not Type Forex or Investment.</font>
                            </div>
                        </div>

                        <div id="Upload_Receipt_div" class="col-md-6">
                            <div class="form-group">
                                <label class="control-label">Upload Receipt</label>
                                <input type="file" class="form-control" id="receipt_upload" name="receipt_upload">
                                <br>
                                <font color="red">Please Transfer to this Bank Acc No : MAYBANK | MYFOX MARKET TRADING | 512080562339</font>
                            </div>
                        </div>

                        <!--div id="TRX_REF_div" class="col-md-6">
                            <div class="form-group">
                                <label class="control-label">TRX REF / HASH TRX</label>
                                <input type="text" class="form-control" id="trx_ref" name="trx_ref"><br>
                                <font color="red">Please Transfer to this USDT Wallet Address <b>TRC20 ONLY</b>: TT7MuRjCaoCMqAVmtejj6GvuboimxEniTA and keyin TRX REF</font>
                            </div>
                        </div-->

                        <div id="withdraw_fees_div" class="col-md-6">
                            <div class="form-group">
                                <label class="control-label">Fees(<?php echo $withdraw_fees_usdt_percent; ?>%)</label>
                                <input type="text" class="form-control" id="deposit_fees" readonly>
                                <input type="hidden" class="form-control" id="deposit_fees_usdt_percent" name="deposit_fees_usdt_percent" onkeyup="myCalculation()" value="<?php echo $withdraw_fees_usdt_percent; ?>">
                            </div>
                        </div>

                        <div id="total_deposit_need_to_transfer_div" class="col-md-6">
                            <div class="form-group">
                                <label class="control-label">Total Amount Need To Transfer (USDT)</label>
                                <input type="text" class="form-control" id="total_deposit_need_to_transfer" name="total_deposit_need_to_transfer" readonly>                            
                            </div>
                        </div>
         
                    </div>
                    <br>
                    Fund will be processed as soon as possible. If you do not receive the fund after one hour, please contact live chat.<br><br>
                    <input type="hidden" class="form-control" id="deposit_rm" name="deposit_rm" onkeyup="myCalculation()" value="<?php echo $deposit_rm; ?>">
                    <input type="hidden" class="form-control"  name="id" value="<?php echo $id; ?>">
                    <input type="hidden" class="form-control"  name="ref_code" value="<?php echo $ref_code; ?>">

                </div>
                <div class="form-actions">               
                    <button name="deposit" class="btn btn-success"><i class="fa fa-check"></i> Submit</button>      
                </div>
            </form>
        </div>
    </div>                     
</div>
</div>
<?php
}
}
?>				
<!-- ============================================================== -->
<!-- End PAge Content -->

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

<script type="text/javascript">
function myCalculation()
{
  deposit_way = document.getElementById("deposit_way").value;
  deposit_rm = document.getElementById("deposit_rm").value;
  amount_rm = document.getElementById("amount_rm").value;
  amount = document.getElementById("amount").value;
  deposit_fees_usdt_percent = document.getElementById("deposit_fees_usdt_percent").value;
  deposit_fees = Number(amount) * (Number(deposit_fees_usdt_percent)/100);
  total_deposit_need_to_transfer =  Number(amount) +  Number(deposit_fees);
  amount = Number(amount_rm)/Number(deposit_rm);

  console.log(amount);
  //console.log(deposit_fees_usdt_percent);
  //console.log(total_deposit_need_to_transfer);

  document.getElementById("deposit_fees").value = deposit_fees.toFixed(2);
  document.getElementById("deposit_fees").value = deposit_fees.toFixed(2);
  document.getElementById("total_deposit_need_to_transfer").value = total_deposit_need_to_transfer.toFixed(2);
  document.getElementById("amount").value = amount.toFixed(2);


  if ( deposit_way == "FPX")
  {
    $("#Upload_Receipt_div").hide();
    $("#Payment_Reference_Div").hide();
	//$("#TRX_REF_div").hide();
    $("#withdraw_fees_div").hide();
    $("#total_deposit_need_to_transfer_div").hide();
  }
  else
  if ( deposit_way == "Upload_Receipt")
  {
    $("#Upload_Receipt_div").show();
    $("#Payment_Reference_Div").show();
    //$("#TRX_REF_div").hide();
    $("#withdraw_fees_div").hide();
    $("#total_deposit_need_to_transfer_div").hide();

	document.getElementById("receipt_upload").required = true;
    document.getElementById("payment_reference").required = true;
  }
  /*
  else
  if ( deposit_way == "USDT")
  {
    $("#TRX_REF_div").show();
    $("#withdraw_fees_div").show();
    $("#total_deposit_need_to_transfer_div").show();
    $("#Upload_Receipt_div").hide();
    $("#Payment_Reference_Div").hide();

	document.getElementById("trx_ref").required = true;	
  }
  */
}   
</script>


<!-- 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>