<?php
	include'session.php';
	include'connection.php';
	include'../Retailers/functions.php';
	
    $rehhAmount=0;
	$quIncome="SELECT * FROM recharge WHERE Userid='$userid' AND Status='SUCCESS'";
	$reIncome=mysqli_query($con,$quIncome);
	$countRech=mysqli_num_rows($reIncome);
	while($dataIncome=mysqli_fetch_array($reIncome))
	{
	     $rehhAmount=$rehhAmount+$dataIncome['Amount'];
	}
	       
	if(100<floor($rehhAmount/10000*100))
	{
	      $percentRet=100; 
	}
	else
	{
	     $percentRet=floor($rehhAmount/10000*100);
	}
	
	if(100<floor($rehhAmount/100000*100))
	{
	      $percentDis=100; 
	}
	else
	{
	     $percentDis=floor($rehhAmount/100000*100);
	}
	
	$backgroundColorRet="linear-gradient(to right, green ".$percentRet."%, red ".$percentRet."%)";
	$backgroundColorDis="linear-gradient(to right, green ".$percentDis."%, red ".$percentDis."%)";
?>
<html>
<head>
	<title>Dashboard</title>
	<!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
	<link rel="icon" href="images/logo.png" type="image/gif" sizes="16x16">
	
	<!-- User CSS File Link -->
	<link rel="stylesheet" href="css/style.css">
	
	<!-- User JAVA SCRIPT File Link -->
	<script type="text/javascript" src="js/script.js"></script>


    <!-- Custom fonts for this template-->
    <!--<link href="fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">-->
	
	<!-- Font Awesome Icone -->
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
	
	<style>
		/* Content Style Coding*/
		.data-content{
			background:#f7f7f7;
			width:100%;
			min-height:500px;
			padding:10px;
		}
		.display{
			width:200px;
			height:80px;
			border-radius:5px;
			float:left;
			margin:10px;
			box-shadow:8px 8px 8px #aaaaaa;
		}
		.display a{color:white;}
		.div1{
			background:;
			width:30%;
			height:80px;
			float:left;
			border-radius:5px 0 0 0;
			color:white;
		}
		.div1 i{
			font-size:50px;
			margin:15px 10px;
		}
		.div2{
			background:;
			width:70%;
			height:90px;
			float:left;
			text-align:right;
			color:white;
			padding:10px 10px 0 0;
			border-radius:0 5px 0 0 ;
		}
		.div2 h3,.div2 i{
			padding:2px 0px;
			font-size:17px;
		}
		.div3{
			background:gray;
			width:100%;
			height:40px;
			float:left;
			border-radius:0 0 5px 5px;
			border-top:1px solid white;
			line-height:40px;
			color:white;
		}
		.div4{
			background:;
			float:left;
			height:39px;
			margin-left:15px;
		}
		.div5{
			background:;
			float:right;
			height:39px;
			margin-right:15px;
		}
		.div5 i{
			margin-top:10px;
			font-size:19px;
		}
		.rechIcon{background:red; width:50%; height:300px; float:left; margin:10px;}
		.iconDiv{background:gray; width:96%; height:auto; float:left; margin:2%;}
		.subIconDiv{background:#3D9B34; color:white; width:70px; height:95px; float:left; margin:2%; text-align:center; position:relative; border-radius:8px;}
		#mob{font-size:80px; float:left; position:absolute; left:50%; top:0; transform:translate(-50%, 0);}
		#dth{font-size:40px; float:left; position:absolute; left:50%; top:20px; transform:translate(-50%, 0);}
		.subIconDiv P{font-size:12px; float:left; position:absolute; left:50%; bottom:5px; transform:translate(-50%, 0);}
		
		#Ret1{background: <?php echo $backgroundColorRet; ?>; }
		#dis1{background: <?php echo $backgroundColorDis; ?>; }
		#Ret1 h3, #Ret1 i{float:left; }
		#dis1 h3, #dis1 i{float:left; }
		
		
		.rechDiv{
			background:#f7f7f7;
			width:100%;
			float:left;
			text-align:center;
			padding:0 10px 10px 10px;
			overflow-x:auto;
			margin-top:10px;
		}
		.rechDiv table{
			width:100%;
			text-align:center;
			font-size:14px;
			border-collapse:collapse;
			padding:2px 10px;
		}
		table th{
			background:#6b5127;
			color:white;
			height:40px;
			border:solid white 1px;
			padding:2px 5px;
		}
		table td{
			background:white;
			height:30px;
			border:solid black 1px;
			padding:2px 5px;
		}
	</style>
	
	<link rel="stylesheet" href="css/mediaStyle.css">
</head>
<body>
	<!--Header Divison-->
	<?php
		require'header.php';
	?>
	<!--Container Division-->
	<div class="container">
		<?php 
		    include'menu.php';
		    
		    
	        
	        $totalDownline=0;
	        $totalSponsored=0;
	        $totalRetailer=0;
	        $totalDistributer=0;
	        $quDownline="SELECT * FROM MLM_Users";
	        $reDownline=mysqli_query($con,$quDownline);
	        while($dataDownline=mysqli_fetch_array($reDownline))
	        {
	            if("true"==checkChild($userid,$dataDownline['Userid']))
	            {
	                $totalDownline=$totalDownline+1;
	            }
	            if($dataDownline['SponsorId']==$userid)
	            {
	                $totalSponsored=$totalSponsored+1;
	            }
	            if($dataDownline['Id_Status']=="Distributer" || $dataDownline['Id_Status']=="Retailer")
	            {
	                $totalRetailer=$totalRetailer+1;
	            }
	            if($dataDownline['Id_Status']=="Distributer")
	            {
	                $totalDistributer=$totalDistributer+1;
	            }
	        }
	        
	        
	
		?>
		<div class="content">
			<div class="head">
				<div class="title"><p>Dashboard :-</p></div>
				<div class="msg"><marquee><?php include'msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
			    
				<a href="Recharge_Panel.php"><div class="display" id="Ret1">
					<div class="div1"><i class="fa fa-mobile"></i>
                    </div>
					<div class="div2">
						<i class="fa fa-inr"></i><h3><?php echo $rehhAmount; ?></h3><p><?php echo "($percentRet%)"; ?></p><br>
						<p>Retailer Status</p>
					</div>
				</div></a>
				
				<a href="Recharge_Panel.php"><div class="display" id="dis1">
					<div class="div1"><i class="fa fa-mobile"></i>
                    </div>
					<div class="div2">
						<i class="fa fa-inr"></i><h3><?php echo $rehhAmount; ?></h3><p><?php echo "($percentDis%)"; ?></p><br>
						<p>Distributer Status</p>
					</div>
				</div></a>
				
				<div class="display" style="background:blue">
					<div class="div1"><a href='tree_view.php'><i class="fa fa-sitemap"></i></a>
                    </div>
					<div class="div2">
						<h3><?php echo $totalDownline; ?></h3><br>
						<a href="downline.php"><p>Total Downline</p></a>
					</div>
				</div>
				
				<a href="downline.php"><div class="display" style="background:orange">
					<div class="div1"><i class="fa fa-users"></i>
                    </div>
					<div class="div2">
						<h3><?php echo $totalSponsored; ?></h3><br>
						<p>Total Sponsored</p>
					</div>
				</div></a>
				
				<a href="downline.php"><div class="display" style="background:brown">
					<div class="div1"><i class="fa fa-user-circle"></i>
                    </div>
					<div class="div2">
						<h3><?php echo $totalRetailer; ?></h3><br>
						<p>Total Retailers</p>
					</div>
				</div></a>
				
				<a href="downline.php"><div class="display" style="background:green">
					<div class="div1"><i class="fa fa-user-circle"></i>
                    </div>
					<div class="div2">
						<h3><?php echo $totalDistributer; ?></h3><br>
						<p>Total Distributers</p>
					</div>
				</div></a>
				
				<div class="rechDiv" id="rech">
				    <table cellpadding="20" border="2">
				        <tr>
				            <th>Order Id</th>
				            <th>Date Time</th>
				            <th>Mobile No.</th>
				            <th><i class="fa fa-inr"></i></th>
				            <th>Operator</th>
				            <th>Reference Id</th>
				            <th>Status</th>
				        </tr>
				        <?php
				            $quRech="SELECT * FROM recharge WHERE Userid='$userid' ORDER BY Id DESC LIMIT 10";
				            $reRech=mysqli_query($con,$quRech);
				            while($dataRech=mysqli_fetch_array($reRech))
				            {
				                if($dataRech['Status']=="SUCCESS")
				                {
				                   $color="green"; 
				                }
				                elseif($dataRech['Status']=="FAILED")
				                {
				                    $color="red";
				                }
				                else
				                {
				                    $color="blue";
				                }
				                $debitAmt=getRA($dataRech['Debitamount']);
				                echo "<tr>";
				                    echo "<td>".$dataRech['Id']."</td>";
				                    echo "<td>".$dataRech['Rechargedate']." ".$dataRech['Time']."</td>";
				                    echo "<td>".$dataRech['Mobile']."</td>";
				                    echo "<td>".$dataRech['Amount']."</td>";
				                    echo "<td>".$dataRech['Companyname']."</td>";
				                    echo "<td>".$dataRech['Operatorid']."</td>";
				                    echo "<td><p id='".$color."'>".$dataRech['Status']."</p></td>";
				                echo "</tr>";
				            }
				        ?>
				    </table>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
	<script>
		function submenu(Arg)
    {
	
	var i;
	var d = document.getElementById("submenu"+Arg);
	var a = document.getElementById("angle"+Arg);
	var nol = d.getElementsByTagName('li').length;
	var dh = (35*nol)+8;
	
	d.style.transition = "all 1s";
	a.style.transition = "all .5s";
	if(d.style.height==dh+"px")
	{
		d.style.height = "0px";
		a.style.transform = "rotate(0deg)";
	}
	else
	{
		for(i=1; 1<=10; i++)
		{
			if(i==Arg)
			{	
				d.style.height = dh+"px";
				document.getElementById("angle"+i).style.transform = "rotate(90deg)";

			}
			else
			{	
				var od = document.getElementById("submenu"+i);
				od.style.height = "0px";
				document.getElementById("angle"+i).style.transform = "rotate(0deg)";
			}
		}
	}
}
	</script>
</body>
</html>