<?php
	session_start();
	if($_SESSION['adm'])
	{
		$userid= $_SESSION['adm'];
	}
	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'];
	
?>
<html>
<head>
<style>
body{background:#e6d9c8; background-image:linear-gradient(to bottom right, #e6d9c8,#996420); background-size:cover; background-repeat:repeat; background-repeat:repeat-x; margin:0; padding:0; width:1580px;}
.head{background:; width:1580px; height:80px; 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;}

#link0{float:right; margin:10 10 0 0px; font-size:20px; text-decoration:none; color:white; background:red; padding:5px; border-radius:4px;}
 #link1{float:right; margin:10 10 0 0px; font-size:20px; text-decoration:none; color:white; background:green; padding:5px; border-radius:4px;}
#link0:hover{ padding:5px; border-radius:4px; color:black;}

.menu{background:#996420; height:40px; width:1450px; margin-left:10px; padding:0; line-height:40px;}
.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;}
#AFLI{background:white; width:200px;}
#AFLI:hover{background:#f5f5f5;}
 #inp{width:200px; height:35px; padding:3 10px; font-size:20px;}
 #inp2{width:80px; height:35px; padding:3 10px; font-size:20px;}
 #srchby{margin-left:20px; font-family:calibri; font-size:22px;}
 .date{background:; margin:10 0 0 20px;}
 .rechreport{width:1160px; height:40px; background:#996420; color:white; line-height:40px; margin:0 0 0 20px;}
 .rechreport p{margin-left:20px;}
.notifi{background:#995702; width:800px; height:70px; margin:5 5 5 50px; border-radius:8px;}
.imgdiv{background:; width:60px; height:60px; float:left; margin:0 20px;}
#notifidiv{background:red; width:40px; height:40px; margin:0 0 0 30px; border-radius:50%; text-align:center; line-height:40px;
color:white; font-size:20px; z-index:4; float:left; position:absolute;}
img{width:60px; height:60px; float:left; margin:7px;}
#myInput{width:200px; height:40px; font-size:17px; margin:0 10px; border-radius:8px;}

#ROffr{background:gray; color:white; font-size:22px; }

#t1{ width:1160px; text-align:center; border-collapse:collapse; border-color:black; margin-left:20px;}
#t1 th{font-family:calibri; background:#94928f; color:white; font-size:18px;}
#t1 td{font-family:calibri; font-size:17px;}
#tda a{text-decoration:none; font-size:19px; font-family:sans-serif; color:#0b52e2;}
#rechId{text-decoration:none; background:; color:blue; font-size:18px; padding:2 5px; border-radius:4px; font-weight:bold;}
#green{background:green; color:white; font-size:18px; padding:2 5px; border-radius:4px; font-weight:bold;}
#red{background:red; color:white; font-size:18px; padding:2 5px; border-radius:4px; font-weight:bold;}
#blue{background:blue; color:white; font-size:18px; padding:2 5px; border-radius:4px; font-weight:bold;}
#lightPink{background:#f4cfd7;}
#pink{background:#f6f0e8;}
 .foot{float:left; margin:10 0 0 100px; width:1350px;}
 </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="link0" href="logout.php">Log Out</a>
		<p id="link1"><?php echo "Welcome $userid Admin";  ?></p>
    </div>
	<?php include 'menu.php'; ?>
	<div class="date">
	    <?php
	        
			include'connection.php';
			$RDate=$_GET['date'];
			
			        
			
	        date_default_timezone_set("asia/Kolkata");
			$datetime= Date("Y-m-d - h:i:s A");
			$time= Date("h:i:s A");
			$date= Date("Y-m-d");
			
			$date1=date_create($date);
		    date_sub($date1,date_interval_create_from_date_string("1 day"));
		    $resultdate=date_format($date1,"Y-m-d");
			
	    ?>
	    <table border="1" cellpadding="10" id="ROffr">
	    </table><br>
	    <form method="post">
	        <input type="date" name="fdate" value="<?php echo $resultdate; ?>" id="inp">
		    <input type="date" name="ldate" value="<?php echo $resultdate; ?>" id="inp">
		<select name="seller" id="inp">
		    <option>--SELECT SELLER--</option>
		    <?php
		        $quSeller="SELECT * FROM Seller";
		        $reSeller=mysqli_query($con,$quSeller);
		        while($dataSeller=mysqli_fetch_array($reSeller))
		        {
		            echo "<option>".$dataSeller['Name']."</option>";
		        }
		    ?>
		</select>
		<select name="stats" id="inp">
		    <option>SUCCESS</option>
		    <option>FAILED</option>
		    <option>FAILED</option>
		    <option>PENDING</option>
		    <option>ALL</option>
		</select>
		<input type="number" name="amount" id="inp2" value='10'>
		<input type="submit" name="submit" id="inp">
		</form>
	</div>
	<div class="rechreport">
		<p>Recharge History <?php if(isset($_POST['submit'])){ echo $seller=$_POST['seller'];} ?></p>
	</div>
	
	<table border="1" cellpadding="5" id="t1">
		<tr>
			<th>Sl</th>
			<th>Rech. Id</th>
			<th>Rech. Date</th>
			<th>Operator</th>
			<th>Seller</th>
			<th>Address</th>
			<th>Lapu No.</th>
			<th>Lapu Bal</th>
			<th>Last Update</th>
		</tr>
		<?php
			
			if(!empty($RDate))
			{
			    $date=$RDate;
			}
			$ToatlLapuBal=0;
			$sl=0;
			if(isset($_POST['submit']))
			{
			    $fdate=$_POST['fdate'];
			    $ldate=$_POST['ldate'];
			    $stats=$_POST['stats'];
			    $seller=$_POST['seller'];
			    $amount=$_POST['amount'];
			    
			    $quGetLapuOwner="select * from myapi where Seller='$seller' AND LastUpdate>='$fdate'";
			    $reGetLapuOwner=mysqli_query($con,$quGetLapuOwner);
			    while($dataGetLapuOwner=mysqli_fetch_array($reGetLapuOwner))
			    {   
			        $lapuNo=$dataGetLapuOwner['LapuNumber'];
			        $background="pink";
			        
			        $quLastRech="SELECT * FROM recharge WHERE Rechargedate>='$fdate' AND Rechargedate<='$ldate' AND LapuNo='$lapuNo' AND Status='SUCCESS' ORDER BY Id DESC";
			        if($reLastRech=mysqli_query($con,$quLastRech))
			        {
			            $dataLastRech=mysqli_fetch_array($reLastRech);
			            $rechId=$dataLastRech['Id'];
			            $lapuBal=$dataLastRech['ApiBal'];
			            $lapuNo=$dataLastRech['LapuNo'];
			            if($lapuBal>=$amount)
			            {
			                $sl=$sl+1;
    				        echo "<tr id='$background'>";
    					        echo "<td>".$sl."</td>";
    					        echo "<td>".$rechId."</td>";
    					        echo "<td>".$dataLastRech['Rechargedate']."</td>";
    					        echo "<td>".$dataGetLapuOwner['Operator']."</td>";
    					        echo "<td>".$dataGetLapuOwner['Seller']."</td>";
    					        echo "<td>".$dataGetLapuOwner['Address']."</td>";
    					        echo "<td>".$lapuNo."</td>";
    					        echo "<td>".$lapuBal."</td>";
    					        echo "<td>".$dataGetLapuOwner['LastUpdate']."</td>";
    				        echo "</tr>";
    				        $ToatlLapuBal=$ToatlLapuBal+$lapuBal;
			            }
			        }
    			}
			}
			   echo "<tr>";
    					echo "<th>".$ldate."</th>";
    					echo "<th></th>";
    					echo "<th></th>";
    					echo "<th></th>";
    					echo "<th></th>";
    					echo "<th></th>";
    					echo "<th></th>";
    					echo "<th>".$ToatlLapuBal."</th>";
    					echo "<th></th>";
				echo "</tr>";
			
		?>
	</table>
	<div class="foot">
		
	</div>
</body>
</html>