<?php
	session_start();
	if($_SESSION['did'])
	{
		$userid= $_SESSION['did'];
	}
	else
	{
		header('location:../login.php');
	}
?>
<?php
	include'connection.php';
		
		$query8="select * from wallet where Userid='$userid' order by Id desc";
		$result8=mysqli_query($con,$query8);
		$data8=mysqli_fetch_array($result8);
		$currentbal= $data8['Balance'];
		
		$query2="select * from distributer where Userid='$userid'";
		$result2=mysqli_query($con,$query2);
		$data=mysqli_fetch_array($result2);
		$username=$data['Name'];
		$parentid=$data['Parentid'];
		$paidStatus=$data['Activation'];
?>
<html>
<title>Reward Status</title>
<head>
<style>
body{background:url('bg.jpg'); background-size:cover;
width:100%; height:700px; margin:0px;}

.head{background:; width:1350px; height:100px; margin:0px;}
#p1{font-size:34px; float:left; Margin:10 0 0 45px; color:#996420; font-weight:bold;}
#p2{font-size:20px; float:left; margin:28 0 0 -8px; color:#eaa040; font-family:Courier;}
#p3{font-size:15px; font-family:Comic Sans MS; float:left; color:#996420; margin-top:48px; margin-left:-153px;}
.h2{background:white; width:400px; height:70px; margin:10 200px;}
#link1{float:right; margin:10 30 0 0px; font-size:20px; text-decoration:none;
 color:white; background:red; padding:5px; border-radius:4px;}
 #link2{float:right; margin:10 30 0 0px; font-size:20px; background:white;color:Green; padding:5px; border-radius:4px;}
#link1:hover{ padding:5px; border-radius:4px; color:black;}
	
.menu{background:#996420; height:40px; width:1380px; margin:0 0 0 20px; padding:0;}
.menu ul{padding:0; margin:0; position:relative; display:inline-block;}
.menu ul li{list-style:none; float:left; width:170px; line-height:40px;
	text-align:center; font-size:15px; margin:0; padding:0; color:white;}
.menu ul li ul {display:none;}
.menu ul li:hover{background:#d1994a; cursor:pointer;}
.menu ul li:hover ul {display:block; z-index:2;}
.menu ul li:hover ul li{background:#d1994a; border-top:solid white 0.1px;}
.menu ul li ul li:hover{background:#996420; color:white;}
.menu ul li ul li:hover a{ color:white;}
.menu ul li a{ text-decoration:none; color:white;}
 #a1{border:none; color:white;}
 .menu{letter-spacing:1px;}
 #bal:hover{background:#996420; cursor:text;}
 
.content{margin:0px; padding:0;}
#heading{margin:10 20px;}
#t1{width:1400px; margin:0 0 20 20px; border-collapse:collapse; font-size:22px; text-align:center; border:1px solid black; background:white;}
#t1 th{background:#d6d7dd;  height:70px;}
#t1 td{ height:100px;}
.rewardStatus{width:1400px; height:50px; background:#334455; color:white; margin:20 0 0 20px; line-height:50px; }
#rewSts{margin-left:20px;}
#rewimg{height:100px;}

#Green{background-color:#13b91f; color:white; padding:10px; border-radius:10px;}
#red{color:blue;}
#amountGreen{color:#13b91f; font-size:22px; font-weight:bold;}
#amountRed{color:red; font-size:22px;}
#trgreen{color:#13b91f; font-size:22px; font-weight:bold;}

.foot{ width:1350px; height:50px; float:left; text-align:center;}
</style>
</head>
<body>
	<div class="head">
		<p id="p1">LLP</p>
		<p id="p2">Recharge</p>
		<p id="p3">The Complete Solution</p>
		<a id="link1" href="logout.php">Log Out</a>
		<p id="link2"><?php echo"Balance : ". $currentbal;  ?></p>
	</div>
	<div class="menu">
		<ul>
			<li><a href="recharge_home.php" id="a1">Home</a></li>
			<li>Retailer
				<ul>
					<li><a href="add_new_agent.php">Add New Retailer</a></li>
					<li><a href="view_retailer.php">View Total Retailers</a></li>
					<li><a href="low_bal_retailer.php">Low Bal. Retailers</a></li>
					<li><a href="lazy_retailer.php">Lazy Retailers</a></li>
				</ul>
			</li>
			<li>Commission
				<ul>
					<li><a href="earn_commision.php">Earn Commision</a></li>
					<li><a href="withdraw_commision.php">Withdraw Comm.</a></li>
					<li><a href="reward.php">Reward Status</a></li>
					<li><a href="getReferalIncome.php">Referral Income</a></li>
				</ul>
			</li>
			<li>Reports
				<ul>
					<li><a href="recharge_history.php">Recharge History</a></li>
					<li><a href="account_reports.php">Account Reports</a></li>
					<li><a href="check_status.php">Check Status</a></li>
				</ul>
			</li>
			<li>Documents
				<ul>
					<li><a href="sms_format.php">SMS Format</a></li>
					<li><a href="complain.php">Complain</a></li>
				</ul>
			</li>
			<li>Profile
				<ul>
					<li><a href="change_profile.php">Change Profile</a></li>
					<li><a href="change_pwd.php">Change Password</a></li>
				</ul>
			</li>
			<li>Payment Request
				<ul>
					<li><a href="payment_request.php">Update Payment</a></li>
					<li><a href="bank_list.php">Bank List</a></li>
				</ul>
			</li>
		</ul>
	</div>
	<div class="content">
	    <?php
	        include'connection.php';
	        date_default_timezone_set("asia/kolkata");
	        $date=Date("Y-m-d");
	         $PrintDate=Date("d-M-Y");
	        
	         $TotalRechamount=0;
	        
		    $resultdate=date('Y-m-d', strtotime($date. ' - 10 days'));
	        $quGetPer="select * from recharge where Status='SUCCESS' and Parentid='$userid' and Rechargedate<='$date' and Rechargedate>'$resultdate'";
	        $reGetPer=mysqli_query($con,$quGetPer);
	        while($dataGetPer=mysqli_fetch_array($reGetPer))
	        {
	             $RechAmount=$dataGetPer['Amount'];
	            $TotalRechamount=$TotalRechamount+$RechAmount;
	        }
	        if($TotalRechamount>=100000)
	        {
	            $quGetReward="select * from distributer where Userid='$userid'";
	            $reGetReward=mysqli_query($con,$quGetReward);
	            $dataGetReward=mysqli_fetch_array($reGetReward);
	            $Reward1=$dataGetReward['Reward1'];
	            if(empty($Reward1) && $paidStatus=="PAID")
	            {
	                $updateReward="update distributer set Reward1='$PrintDate' where Userid='$userid'";
	                mysqli_query($con,$updateReward);
	            }
	        }
	        else
	        {
	            $amountColor1="amountRed";
	        }
	            $quGetReward="select * from distributer where Userid='$userid'";
	            $reGetReward=mysqli_query($con,$quGetReward);
	            $dataGetReward=mysqli_fetch_array($reGetReward);
	            $Reward1=$dataGetReward['Reward1'];
	        if(empty($Reward1))
	        {
	            $statusRewars1="PENDING";
	            $color1="red";
	            $Reward1="In Wait";
	        }
	        else
	        {
	            $amountColor1="amountGreen";
	            $color1="green";
	            $statusRewars1="ACHIEVED";
	            $BgColor1="trgreen";
	        }
	        
		    $resultdate2=date('Y-m-d', strtotime($date. ' - 30 days'));
	        $quGetPer2="select * from recharge where Status='SUCCESS' and Parentid='$userid' and Rechargedate<='$date' and Rechargedate>'$resultdate2'";
	        $reGetPer2=mysqli_query($con,$quGetPer2);
	        $TotalRechamount2=0;
	        while($dataGetPer2=mysqli_fetch_array($reGetPer2))
	        {
	             $RechAmount2=$dataGetPer2['Amount'];
	            $TotalRechamount2=$TotalRechamount2+$RechAmount2;
	        }
	        if($TotalRechamount2>=500000)
	        {
	            $BgColor2="Green";
	            $quGetReward="select * from distributer where Userid='$userid'";
	            $reGetReward=mysqli_query($con,$quGetReward);
	            $dataGetReward=mysqli_fetch_array($reGetReward);
	            $Reward2=$dataGetReward['Reward2'];
	            if(empty($Reward2) && $paidStatus=="PAID")
	            {
	                $updateReward="update distributer set Reward2='$PrintDate' where Userid='$userid'";
	                mysqli_query($con,$updateReward);
	            }
	        }
	        else
	        {
	            $amountColor2="amountRed";
	        }
	            $quGetReward="select * from distributer where Userid='$userid'";
	            $reGetReward=mysqli_query($con,$quGetReward);
	            $dataGetReward=mysqli_fetch_array($reGetReward);
	            $Reward2=$dataGetReward['Reward2'];
	        if(empty($Reward2))
	        {
	            $statusRewars2="PENDING";
	            $BgColor2="Default";
	            $color2="red";
	            $Reward2="In Wait";
	        }
	        else
	        {
	            $amountColor2="amountGreen";
	            $color2="green";
	            $statusRewars2="ACHIEVED";
	            $BgColor2="trgreen";
	        }
	        
	        
		    $resultdate3=date('Y-m-d', strtotime($date. ' - 60 days'));
	        $quGetPer3="select * from recharge where Status='SUCCESS' and Parentid='$userid' and Rechargedate<='$date' and Rechargedate>'$resultdate3'";
	        $reGetPer3=mysqli_query($con,$quGetPer3);
	        $TotalRechamount3=0;
	        while($dataGetPer3=mysqli_fetch_array($reGetPer3))
	        {
	             $RechAmount3=$dataGetPer3['Amount'];
	            $TotalRechamount3=$TotalRechamount3+$RechAmount3;
	        }
	        
	        if($TotalRechamount3>=2000000)
	        {
	            $quGetReward="select * from distributer where Userid='$userid'";
	            $reGetReward=mysqli_query($con,$quGetReward);
	            $dataGetReward=mysqli_fetch_array($reGetReward);
	            $Reward3=$dataGetReward['Reward3'];
	            if(empty($Reward3) && $paidStatus=="PAID")
	            {
	                $updateReward="update distributer set Reward3='$PrintDate' where Userid='$userid'";
	                mysqli_query($con,$updateReward);
	            }
	        }
	        else
	        {
	            $amountColor3="amountRed";
	        }
	            $quGetReward="select * from distributer where Userid='$userid'";
	            $reGetReward=mysqli_query($con,$quGetReward);
	            $dataGetReward=mysqli_fetch_array($reGetReward);
	            $Reward3=$dataGetReward['Reward3'];
	        if(empty($Reward3))
	        {
	            $statusRewars3="PENDING";
	            $BgColor3="Default";
	            $color3="red";
	            $Reward3="In Wait";
	        }
	        else
	        {
	            $amountColor3="amountGreen";
	            $color3="green";
	            $statusRewars3="ACHIEVED";
	            $BgColor3="trgreen";
	        }
	        
	        
		    $resultdate4=date('Y-m-d', strtotime($date. ' - 150 days'));
	        $quGetPer4="select * from recharge where Status='SUCCESS' and Parentid='$userid' and Rechargedate<='$date' and Rechargedate>'$resultdate4'";
	        $reGetPer4=mysqli_query($con,$quGetPer4);
	        $TotalRechamount4=0;
	        while($dataGetPer4=mysqli_fetch_array($reGetPer4))
	        {
	            $RechAmount4=$dataGetPer4['Amount'];
	            $TotalRechamount4=$TotalRechamount4+$RechAmount4;
	            
	        }
	        
	        if($TotalRechamount4>=9000000)
	        {
	            $quGetReward="select * from distributer where Userid='$userid'";
	            $reGetReward=mysqli_query($con,$quGetReward);
	            $dataGetReward=mysqli_fetch_array($reGetReward);
	            $Reward4=$dataGetReward['Reward4'];
	            if(empty($Reward4) && $paidStatus=="PAID")
	            {
	                $updateReward="update distributer set Reward4='$PrintDate' where Userid='$userid'";
	                mysqli_query($con,$updateReward);
	            }
	        }
	        else
	        {
	            $amountColor4="amountRed";
	        }
	            $quGetReward="select * from distributer where Userid='$userid'";
	            $reGetReward=mysqli_query($con,$quGetReward);
	            $dataGetReward=mysqli_fetch_array($reGetReward);
	            $Reward4=$dataGetReward['Reward4'];
	        if(empty($Reward4))
	        {
	            $statusRewars4="PENDING";
	            $BgColor4="Default";
	            $color4="red";
	            $Reward4="In Wait";
	        }
	        else
	        {
	            $amountColor4="amountGreen";
	            $color4="green";
	            $statusRewars4="ACHIEVED";
	            $BgColor4="trgreen";
	        }
	        
		    $resultdate5=date('Y-m-d', strtotime($date. ' - 360 days'));
	        $quGetPer5="select * from recharge where Status='SUCCESS' and Parentid='$userid' and Rechargedate<='$date' and Rechargedate>'$resultdate5'";
	        $reGetPer5=mysqli_query($con,$quGetPer5);
	        $TotalRechamount5=0;
	        while($dataGetPer5=mysqli_fetch_array($reGetPer5))
	        {
	            $RechAmount5=$dataGetPer5['Amount'];
	            $TotalRechamount5=$TotalRechamount5+$RechAmount5;
	        }
	        
	        if($TotalRechamount5>=36000000)
	        {
	            $quGetReward="select * from distributer where Userid='$userid'";
	            $reGetReward=mysqli_query($con,$quGetReward);
	            $dataGetReward=mysqli_fetch_array($reGetReward);
	            $Reward5=$dataGetReward['Reward5'];
	            if(empty($Reward5) && $paidStatus=="PAID")
	            {
	                $updateReward="update distributer set Reward5='$PrintDate' where Userid='$userid'";
	                mysqli_query($con,$updateReward);
	            }
	        }
	        else
	        {
	            $amountColor5="amountRed";
	        }
	           $quGetReward="select * from distributer where Userid='$userid'";
	            $reGetReward=mysqli_query($con,$quGetReward);
	            $dataGetReward=mysqli_fetch_array($reGetReward);
	            $Reward5=$dataGetReward['Reward5'];
	        if(empty($Reward5))
	        {
	            $statusRewars5="PENDING";
	            $BgColor5="Default";
	            $color5="red";
	            $Reward5="In Wait";
	        }
	        else
	        {
	            $amountColor5="amountGreen";
	            $color5="green";
	            $statusRewars5="ACHIEVED";
	            $BgColor5="trgreen";
	        }
	    ?>
		<h2 id="heading">Reward</h2><hr>
		<div class="rewardStatus">
			<h2 id="rewSts">Reward Status</h2>
		</div>
		<table border="1" cellpadding="10" id="t1">
			<tr>
				<th>Sl. No.</th>
				<th>Reward Name</th>
				<th>Reward Pic</th>
				<th>Achieve Period</th>
				<th>Achieve Goal</th>
				<th>Your Performance</th>
				<th>Status</th>
				<th>Achieve Date</th>
			</tr>
			<tr id="<?php echo $BgColor1; ?>">
				<td>1</td>
				<td>Dairy-Pen<br>+<br>(Certificate & ID Card)</td>
				<td><img src="Diary-Pen.jpg" id="rewimg"></img></td>
				<td>10 Days</td>
				<td>1 Lacks Recharge Amount</td>
				<td id="<?php echo $amountColor1; ?>"><?php echo $TotalRechamount; ?></td>
				<td><p id="<?php echo $color1; ?>"><?php echo $statusRewars1; ?></p></td>
				<td><?php echo $Reward1; ?></td>
			</tr>
			<tr id="<?php echo $BgColor2; ?>">
				<td>2</td>
				<td>Mobile<br> (Worth Rs. 1500)</td>
				<td><img src="KeypadMobile.jpg" id="rewimg"></img></td>
				<td>30 Days</td>
				<td>5 Lacks Recharge Amount</td>
				<td id="<?php echo $amountColor2; ?>"><?php echo $TotalRechamount2; ?></td>
				<td><p id="<?php echo $color2; ?>"><?php echo $statusRewars2; ?></p></td>
				<td><?php echo $Reward2; ?></td>
			</tr>
			<tr id="<?php echo $BgColor3; ?>">
				<td>3</td>
				<td>Smartphone<br> (Worth Rs. 10000)</td>
				<td><img src="Smartphone.jpg" id="rewimg"></img></td>
				<td>60 Days</td>
				<td>20 Lacks Recharge Amount</td>
				<td id="<?php echo $amountColor3; ?>"><?php echo $TotalRechamount3; ?></td>
				<td><p id="<?php echo $color3; ?>"><?php echo $statusRewars3; ?></p></td>
				<td><?php echo $Reward3; ?></td>
			</tr>
			<tr id="<?php echo $BgColor4; ?>">
				<td>4</td>
				<td>Bike<br> (Worth Rs. 50000)</td>
				<td><img src="Bike.jpg" id="rewimg"></img></td>
				<td>150 Days</td>
				<td>90 Lacks Recharge Amount</td>
				<td id="<?php echo $amountColor4; ?>"><?php echo $TotalRechamount4; ?></td>
				<td><p id="<?php echo $color4; ?>"><?php echo $statusRewars4; ?></p></td>
				<td><?php echo $Reward4; ?></td>
			</tr>
			<tr id="<?php echo $BgColor5; ?>">
				<td>5</td>
				<td>Car<br> (Worth Rs. 300000)</td>
				<td><img src="Car.png" id="rewimg"></img></td>
				<td>360 Days</td>
				<td>360 Lacks Recharge Amount</td>
				<td id="<?php echo $amountColor5; ?>"><?php echo $TotalRechamount5; ?></td>
				<td><p id="<?php echo $color5; ?>"><?php echo $statusRewars5; ?></p></td>
				<td><?php echo $Reward5; ?></td>
			</tr>
		</table>
	</div>
	    <center><h2 style="color:red;">-: It Is Only For Paid Distributers :-</h2></center>
<div class="footer">
		<p style="text-align:center;">Copyright &copy; 2018 -2019 Long Life Product Pvt. Ltd.</p>
</div>
</body>
</html>