<?php
    $sql = "SELECT * FROM user
    WHERE ref_code='$ref_code'
    AND status='1'";
    $result = $mysqli->query($sql);
	if ($result->num_rows > 0)
	{
		$row = $result ->fetch_assoc();
		$sponsor_code = $row['sponsor_code'];
	    $ref_code = $row['ref_code'];
        $nick_name = $row['nick_name'];
	    $name = $row['name'];
        $last_name = $row['last_name'];
	    $level = $row['level'];
        $package_type = $row['package_type'];
        $created_date = date('d-m-Y', strtotime($row['created_date']));
	}

    $data_total_package = 
    "SELECT SUM(order_full_total) As num 
    FROM woocommerce_order_info
    WHERE status = '1'";    
    $result_total_package = $mysqli->query($data_total_package);
	if ($result_total_package ->num_rows > 0)
	{
		$row_total_package = $result_total_package ->fetch_assoc();
		$full_total_package = number_format($row_total_package['num'],2);
	}

    $data_total_package_paid = 
    "SELECT SUM(amount) As num 
    FROM package_payment
    WHERE status = '1'";    
    $result_total_package_paid = $mysqli->query($data_total_package_paid);
	if ($result_total_package_paid ->num_rows > 0)
	{
		$row_total_package_paid = $result_total_package_paid ->fetch_assoc();
		$full_total_package_paid = number_format($row_total_package_paid['num'],2);
	}


    $data_total_commission = 
    "SELECT SUM(in_transactions) As num 
    from transactions
    WHERE type_of_transaction In ('In')  
    AND type_of_process Like 'bonus_sponso%' OR  type_of_process Like 'hibah_unilevel_level_%'
    AND in_transactions != '0'
    AND status = '1'";    
    $result_total_commission = $mysqli->query($data_total_commission);
	if ($result_total_commission ->num_rows > 0)
	{
		$row_total_commission = $result_total_commission ->fetch_assoc();
		$full_total_commission = number_format($row_total_commission['num'],2);
	}

    $data_total_downline = 
    "SELECT Count(id) As num 
    FROM user
    WHERE level = '2'
    AND status = '1'
    AND activation_status = '1' "; 
    $result_total_downline = $mysqli->query($data_total_downline);
	if ($result_total_downline ->num_rows > 0)
	{
		$row_total_downline = $result_total_downline ->fetch_assoc();
		$total_downline = $row_total_downline['num'];
	}

    $data_wallet = 
    "SELECT SUM(cash_wallet) As num 
    FROM wallet";    
    $result_wallet = $mysqli->query($data_wallet);
	if ($result_wallet ->num_rows > 0)
	{
		$row_wallet = $result_wallet ->fetch_assoc();
		$cash_wallet = number_format($row_wallet['num'],2);
	}

    $data_total_withdraw = 
    "SELECT SUM(amount) As num 
    FROM withdraw_transaction  
    WHERE type_of_transaction = 'CW'
    AND tac_verify_status = '1'
    AND payment_status != '' ";    
    $result_total_withdraw = $mysqli->query($data_total_withdraw);
	if ($result_total_withdraw ->num_rows > 0)
	{
		$row_total_withdraw = $result_total_withdraw ->fetch_assoc();
		$full_total_withdraw = number_format($row_total_withdraw['num'],2);
	}
?>


<div class="row">
    <div class="col-lg-12">
        <div class="card ">
            <img class="card-img" height="400" src="../Assets/images/banner.jpg" alt="Card image">
            <div class="card-img-overlay social-profile-first">
                <div style="background-color: rgba(212,175,55,0.65); display: inline-block; margin-top: 100px; padding: 25px 35px; border-radius: 6px;">
                    <img src="../Assets/images/personal.png" class="img-circle" width="100">
                    <h4 class="card-title text-white"><?php echo $name; ?> <?php echo $last_name; ?> </h4>
                    <h5 class="text-white"><b>Username: <?php echo $nick_name; ?></b></h5> 
                    <h5 class="text-white"><b>Member ID: <?php echo $ref_code; ?></b></h5>               
                    <h5 class="text-white"><b>Registration Date: <?php echo $created_date; ?></b></h5>
                </div>
            </div>          
        </div>
    </div>

    <div class="col-md-4">
        <div style="background-color: rgba(212,175,55,0.65)" class="card text-white">
            <div class="card-body">
                <h5 class="card-title">TOTAL PACKAGE SOLD</h5>
                <div class="col-12  m-t-30">
                    <h3 class="text-white"><i class="icon-graph"></i> USD <?php echo $full_total_package; ?> </h3>
                </div>
            </div>
        </div>
    </div>

    <div class="col-md-4">
        <div style="background-color: rgba(212,175,55,0.65)" class="card text-white">
            <div class="card-body">
                <h5 class="card-title">TOTAL PACKAGE PAID</h5>
                <div class="col-12  m-t-30">
                    <h3 class="text-white"><i class="icon-graph"></i> USD <?php echo $full_total_package_paid; ?> </h3>
                </div>
            </div>
        </div>
    </div>
    
    <div class="col-md-4">
        <div style="background-color: rgba(212,175,55,0.65)" class="card text-white">
            <div class="card-body">
                <h5 class="card-title">TOTAL MEMBERS</h5>
                <div class="col-12  m-t-30">
                    <h3 class="text-white"><i class="icon-user"></i> <?php echo $total_downline; ?></h3>
                </div>
            </div>
        </div>
    </div>

    <div class="col-md-4">
        <div style="background-color: rgba(212,175,55,0.65)" class="card text-white">
            <div class="card-body">
                <h5 class="card-title">TOTAL COMMISSION</h5>
                <div class="col-12  m-t-30">
                    <h3 class="text-white"><i class="icon-wallet"></i> USD <?php echo $full_total_commission; ?></h3>
                </div>
            </div>
        </div>
    </div>

    <div class="col-md-4">
        <div style="background-color: rgba(212,175,55,0.65)" class="card text-white">
            <div class="card-body">
                <h5 class="card-title">TOTAL E-WALLET</h5>
                <div class="col-12  m-t-30">
                    <h3 class="text-white"><i class="icon-wallet"></i> USD <?php echo $cash_wallet; ?></h3>
                </div>
            </div>
        </div>
    </div>

    <div class="col-md-4">
        <div style="background-color: rgba(212,175,55,0.65)" class="card text-white">
            <div class="card-body">
                <h5 class="card-title">TOTAL WITHDRAW</h5>
                <div class="col-12  m-t-30">
                    <h3 class="text-white"><i class="icon-wallet"></i> USD <?php echo $full_total_withdraw; ?></h3>
                </div>
            </div>
        </div>
    </div>

    
    <br>
</div>

<script>
function myFunction() {
  var copyText = document.getElementById("myInput");
  copyText.SELECT();
  copyText.setSELECTionRange(0, 99999)
  document.execCommAND("copy");
  alert("Copied the text: " + copyText.value);
}
</script>

