<?php
session_start();
@$userKey = $_SESSION['loginKey'];

if($userKey == "")
{
    echo "<script>window.open('login.php','_self')</script>";
}


include "control/activity.php";
$dd = new activity();


$table = "userdetails";
$condition = " where userKey='$userKey'";
$getuserdetails = $dd->single($table,$condition);
$memid = $getuserdetails['memId'];



$table = "admin_calculation";
$condition = null;
$getAdminDetails = $dd->single($table,$condition);

?>


<!DOCTYPE html>
<html lang="en" translate="no">
<head>
    <meta charset="UTF-8">
    <link rel="icon" type="image/svg+xml" href="./images/h5setting_20230808033047vpbk.ico">
    <meta name="google" content="notranslate">
    <meta name="robots" content="noindex,nofollow">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title><?= $getAdminDetails['title']; ?></title>
    <link rel="stylesheet" href="css/slick.css" />
    <link rel="stylesheet" href="css/modules.css" />
    <link rel="stylesheet" href="css/style.css" />
    <script src="js/jquery.min.js" type="text/javascript"></script>
    <script src="js/slick.min.js" type="text/javascript"></script>
    <script src="js/main.js" type="text/javascript"></script>
</head>
<body>
    <div id="app">
        <div class="dailySignIn__container">
            
            <div class="navbar">
                <div class="navbar-fixed" style="background: linear-gradient(90deg, rgb(206, 2, 4) 0%, rgb(242, 64, 58) 100%);">
                    <div class="navbar__content">
                    <div data-v-905dfe8c="" class="navbar__content-left" onclick="clicktoBack()"><div data-v-905dfe8c="" class="backIcon"></div></div>
                        <div class="navbar__content-center">
                            <div data-v-905dfe8c="" class="navbar__content-title">Invitation bonus</div>
                        </div>
                        <div data-v-905dfe8c="" class="navbar__content-right"></div>
                    </div>
                </div>
            </div>

            <!-- bonus header -->
            <div class="bonus-header">
                <div data-v-59976d00="" class="title left">Invite friends and deposit</div>
                <div data-v-59976d00="" class="tip left">Both parties can receive rewards</div>
                <div data-v-59976d00="" class="tip left">Invite friends to register and recharge to receive rewards</div>
                <div data-v-59976d00="" class="tip left">activity date</div>
                <div data-v-59976d00="" class="time left">2000-01-01 - 2099-01-01</div>
                <div class="nav">
                    <div data-v-59976d00="" class="rule">Invitation reward rules</div>
                    <div data-v-59976d00="" class="record">Invitation record</div>
                </div>
            </div>

            <!-- bonus-container -->
            <div class="bonus-container">
                
                <?php
                    $table = "userdetails";
                    $condition = " where refral_from='$memid'";
                    $totalDirect = $dd->fetch_multi($table,$condition);
                    foreach($totalDirect as $key)
                    {
                        if($key->tdeposit >=500)
                        {
                            $tdone++;
                        }
                    }
                
                   $table = "invitation_bonus";
                   $condition = null;
                   $getFullDetails = $dd->fetch_multi($table,$condition);
                   foreach($getFullDetails as $key){
                       $i++;
                ?>
                
                
                <div class="bonus-items">
                    <div class="head">
                        <div class="left">
                            Bonus <div data-v-59976d00=""><?= $i; ?></div>
                        </div>
                        <div data-v-59976d00="" class="right">₹<?= $key->bonus; ?></div>
                    </div>
                    <div class="detail">
                        <div data-v-59976d00="" class="text">Number of invitees</div>
                        <div data-v-59976d00="" class="people"><?= $key->number_refral; ?></div>
                    </div>
                    <div class="detail">
                        <div data-v-59976d00="" class="text">Recharge per people</div>
                        <div data-v-59976d00="" class="num">₹<?= $key->number_recharge; ?></div>
                    </div>
                    <div data-v-59976d00="" class="line"></div>
                    <div class="task">
                        <div class="task_iner">
                            <div data-v-59976d00="" class="peopleval"><?= $key->number_refral; ?> / <?= count($totalDirect); ?></div>
                            <div data-v-59976d00="" class="text">Number of invitees</div>
                        </div>
                        <div class="task_iner">
                            <div data-v-59976d00="" class="rechargeval"><?= $key->number_recharge; ?> / <?= $tdone; ?></div>
                            <div data-v-59976d00="" class="text">Deposit number</div>
                        </div>
                    </div>
                    <div data-v-59976d00="" onclick='claimNowThisAmount("<?= $key->number_refral; ?>","<?= $tdone; ?>","<?= $key->bonus; ?>")' class="btn <?php if($key->number_refral <= $tdone){ echo 'btn-success'; } ?>"><?php if($key->number_refral <= $tdone){ echo "Claim Now"; }else{ echo "Unfinish"; }; ?></div>
                </div>
                
                <?php } ?>
                
                
                
            </div>

        

        </div>
    </div>
    <?php include "footer.php"; ?>
</body>
<script>

 function claimNowThisAmount(a,b,c)
 {
     if(a <= b)
     {
         
        const xhttp = new XMLHttpRequest();
        xhttp.onload = function() {
        var demo_show = this.responseText;
        console.log(demo_show);
        const myArr = JSON.parse(demo_show);
        if(myArr.status == "success")
        {
            alert(myArr.remark);
        }
        else{
            alert(myArr.remark);
        }
        }
        xhttp.open("GET", "claim_refral_benifits_incentive.php?amnt="+c);
        xhttp.send();
         
         
         
     }else{
         alert('Not compleate');
     }
 }




 function clicktoBack()
  {
    window.open('index.php','_self');
  }
  </script>
</html>