<?php
	include'session.php';
	include'connection.php';
	include'../Retailers/functions.php';
	include'../Admin1/insertDiff.php';
	getUBWI($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:20px;
		}
		.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);}
		
		
		
		.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';
		    
		    $totalIncome=0;
	        $rehhAmount=0;
	        $quIncome="SELECT * FROM recharge WHERE Userid='$userid' AND Rechargedate='$date' AND Status='SUCCESS'";
	        $reIncome=mysqli_query($con,$quIncome);
	        $countRech=mysqli_num_rows($reIncome);
	        while($dataIncome=mysqli_fetch_array($reIncome))
	        {
		        $totalIncome=$totalIncome+$dataIncome['RetCommAmt'];
		        $rehhAmount=$rehhAmount+$dataIncome['Amount'];
	        }
	        $totalIncome=number_format((float)$totalIncome, 2, '.', '');
	        
	        $reqAmount=0;
	        $quPayReq="SELECT * FROM paymentreq WHERE Userid='$userid' AND Date='$date' AND Status='APPROVED'";
	        $rePayReq=mysqli_query($con,$quPayReq);
	        while($dataPayReq=mysqli_fetch_array($rePayReq))
	        {
		        $reqAmount=$reqAmount+$dataPayReq['Amount'];
	        }
	        
	        $compAmount=0;
	        $quComp="SELECT * FROM complain WHERE Userid='$userid' AND Compdate='$date'";
	        $reComp=mysqli_query($con,$quComp);
	        $countComp=mysqli_num_rows($reComp);
	        while($dataComp=mysqli_fetch_array($reComp))
	        {
		        $compAmount=$compAmount+$dataComp['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><?php echo $totalIncome; ?> Income Of The Day</h3>
					</div>
					<a href="walletLedger.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-shopping-cart"></i>
					</div>
					<div class="div2">
						<h3><?php echo $reqAmount; ?> Purchase of The Day</h3>
						
					</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="display" style="background:red;">
					<div class="div1"><i class="fa fa-gavel"></i>
					</div>
					<div class="div2">
						<h3><?php echo $countComp; ?> Dispute Of The Day</h3>
						
					</div>
					<a href="complain.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="rechDiv">
				    <table cellpadding="20" border="2">
				        <tr>
				            <th>Operator</th>
				            <th>Amount</th>
				            <th><i class="fa fa-inr"></i></th>
				        </tr>
				<?php
				    $totalRech=0;
				    
				    $quRechByOp = "SELECT Companyname, SUM(AMOUNT), SUM(Debitamount) FROM `recharge` WHERE Userid='$userid' AND Rechargedate='$date' AND Status='SUCCESS' GROUP BY Companyname";
				    $reRechByOp = mysqli_query($con,$quRechByOp);
				    
				    while($dataByOp=mysqli_fetch_array($reRechByOp))
				    {
				        $debitAmount=$dataByOp[2];
				        $debitAmount=number_format((float)$debitAmount, 2, '.', '');
	        
				        echo "<tr>";
				            echo "<td>".$dataByOp[0]."</td>";
				            echo "<td>".$dataByOp[1]."</td>";
				            echo "<td>".$debitAmount."</td>";
				        echo "</tr>";
				        $totalRech=$totalRech+$dataByOp[1];
				        $totalDebitAmount=$totalDebitAmount+$dataByOp[2];
				        $totalDebitAmount=number_format((float)$totalDebitAmount, 2, '.', '');
				    }
				    echo "<tr>";
			            echo "<th>TOTAL</th>";
			            echo "<th>".$totalRech."</th>";
			            echo "<th>".$totalDebitAmount."</th>";
				    echo "</tr>";
				    
				?>
				    </table>
				</div>
				
				<div class="rechDiv">
				    <table cellpadding="20" border="2">
				        <tr>
				            <th>Order Id</th>
				            <th>Date Time</th>
				            <th>Mobile No.</th>
				            <th>Amt.</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>".$debitAmt."</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>