<?php
	include'session.php';
	include'connection.php';
	include'../Retailers/functions.php';
	include'../Admin1/insertDiff.php';
	
	getCBT($userid);
?>
<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:240px;
			height:130px;
			border-radius:5px;
			float:left;
			margin:10px;
			box-shadow:8px 8px 8px #aaaaaa;
		}
		.div1{
			background:;
			width:30%;
			height:90px;
			float:left;
			border-radius:5px 0 0 0;
			color:white;
		}
		.div1 i{
			font-size:60px;
			margin: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{
			padding:2px 0px;
			font-size:22px;
		}
		.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;
		}
		.retailerLowBal{background:; width:96%; height:auto; float:left; margin:2%; text-align:center;}
		.retailerLowBal h3{}
		.LBRtbl{float:left; text-align:center; width:100%; border-collapse:collapse; margin-top:10px;}
		.LBRtbl th{padding:2px 5px; background:#6b5127; color:white; height:40px; border:solid white 1px; border-top:solid black 1px; border-left:solid black 1px; }
		.LBRtbl td{padding:2px 5px; background:white; height:40px; border:solid black 1px;}
		.LBRtbl a{font-weight:bold; font-size:25px;}
	</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';
		    $totalIncome=0;
	        $quIncome="SELECT * FROM commwallet WHERE Userid='$userid' AND Active='0' AND Date='$date'";
	        $reIncome=mysqli_query($con,$quIncome);
	        while($dataIncome=mysqli_fetch_array($reIncome))
	        {
		        $totalIncome=$totalIncome+$dataIncome['Balance'];
	        }
	
	        $quDownline="SELECT * FROM retailer WHERE Parentid='$userid'";
	        $reDownline=mysqli_query($con,$quDownline);
	        $countDownline=mysqli_num_rows($reDownline);
	
	        $rehhAmount=0;
	        $quRechToday="SELECT * FROM recharge WHERE Parentid='$userid' AND Rechargedate='$date' AND Status='SUCCESS'";
	        $reRechToday=mysqli_query($con,$quRechToday);
	        while($dataRechToday=mysqli_fetch_array($reRechToday))
	        {
	            $rehhAmount=$rehhAmount+$dataRechToday['Amount'];
	        }
	        
	        $reqAmount=0;
	        $quReqToday="SELECT * FROM paymentreq WHERE Userid='$userid' AND Date='$date' AND Status='APPROVED'";
	        $reReqToday=mysqli_query($con,$quReqToday);
	        while($dataReqToday=mysqli_fetch_array($reReqToday))
	        {
	            $reqAmount=$reqAmount+$dataReqToday['Amount'];
	        }
		?>
		<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">
				<div class="display" style="background:orange;">
					<div class="div1"><i class="fa fa-inr"></i></div>
					<div class="div2">
						<h3>Income Of The Day</h3>
						<i class="fa fa-inr"></i> <?php echo $totalIncome; ?>
					</div>
					<a href="redeem_commission.php"><div class="div3">
						<div class="div4"><p>View List</p></div>
						<div class="div5"><i class="fa fa-arrow-circle-right"></i></div>
					</div></a>
				</div>
				<div class="display" style="background:green;">
					<div class="div1"><i class="fa fa-sitemap"></i></div>
					<div class="div2">
						<h3>Total Retailers</h3>
						<i class="fa fa-users"></i> <?php echo $countDownline; ?>
					</div>
					<a href="retailers_list.php"><div class="div3">
						<div class="div4"><p>View List</p></div>
						<div class="div5"><i class="fa fa-arrow-circle-right"></i></div>
					</div></a>
				</div>
				<div class="display" style="background:blue;">
					<div class="div1"><i class="fa fa-mobile"></i></div>
					<div class="div2">
						<h3>Recharge of The Day</h3>
						<i class="fa fa-mobile"></i> <?php echo $rehhAmount; ?>
					</div>
					<a href="recharge_report.php"><div class="div3">
						<div class="div4"><p>View List</p></div>
						<div class="div5"><i class="fa fa-arrow-circle-right"></i></div>
					</div></a>
				</div>
				<div class="display" style="background:purple;">
					<div class="div1"><i class="fa fa-shopping-cart"></i></div>
					<div class="div2">
						<h3>Purchase Of The Day</h3>
						<i class="fa fa-shopping-cart"></i> <?php echo $reqAmount; ?>
					</div>
					<a href="topup_reports.php"><div class="div3">
						<div class="div4"><p>View List</p></div>
						<div class="div5"><i class="fa fa-arrow-circle-right"></i></div>
					</div></a>
				</div>
				<div class="retailerLowBal">
				    <center><h3>Low Balance Retailers</h3></center>
				    <table class="LBRtbl" cellpadding="10" border="1px">
				        <tr>
				            <th>Userid</th>
				            <th>Name</th>
				            <th>Bal.</th>
				            <th style="border-right:solid black 1px"><i class="fa fa-inr"></i></th>
				        </tr>
				        <?php
				            $backDate=getBackDate($date,7);
				            $quLBR="SELECT * FROM retailer WHERE Parentid='$userid' AND Balance<2000 AND Lastrechdate>='$backDate' ORDER BY Balance ASC";
				            $reLBR=mysqli_query($con,$quLBR);
				            while($dataLBR=mysqli_fetch_array($reLBR))
				            {
				                $retId=$dataLBR['Userid'];
				                echo "<tr>";
				                    echo "<td>".$dataLBR['Userid']."</td>";
				                    echo "<td>".$dataLBR['Name']."</td>";
				                    if($dataLBR['Balance']<1000)
				                    {
				                        echo "<td style='color:red;'>".$dataLBR['Balance']."</td>";
				                    }
				                    else
				                    {
				                        echo "<td style='color:black;'>".$dataLBR['Balance']."</td>";
				                    }
				                    echo "<td><a href='fund_transfer.php?retId=".$retId."'><i class='fa fa-inr'></i></a></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>