<?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-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;}
 #srchby{margin-left:20px; font-family:calibri; font-size:22px;}
 .date{background:; margin:10 0 0 20px;}
 .rechreport{width:1560px; 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 300px; 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;}
#t1{ width:1560px; text-align:center; border-collapse:collapse; border-color:black; margin-left:20px;}
#t1 th{font-family:calibri; background:#94928f; color:white; font-size:17px;}
#t1 td{font-family:calibri; font-size:15px;}
#t1 tr:nth-child(odd){background:#f6f0e8;}
#t1 tr:nth-child(even){background:white; }
#tda a{text-decoration:none; font-size:18px; 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;}

 .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
	        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");
			
	    ?>
	    <form method="post">
		From Date : <input type="date" name="fdate" value="<?php echo $date; ?>" id="inp">
		To Date : <input type="date" name="ldate" value="<?php echo $date; ?>" id="inp">
		Parent Id : <input type="number" name="user"  id="inp">
		<select name="stats" id="inp">
		    <option>ALL</option>
		    <option>SUCCESS</option>
		    <option>FAILED</option>
		    <option>FAILED</option>
		    <option>PENDING</option>
		</select>
		<input type="submit" name="submit" id="inp">
		</form>
	</div>
	<div class="rechreport">
		<p>Recharge History</p>
	</div>
	
	<table border="1" cellpadding="5" id="t1">
		<tr>
			<th>Date | Time</th>
			<th>Agent Name</th>
			<th>Distributer Name</th>
			<th>Balance</th>
			<th>Company Name</th>
			<th>Mobile No.</th>
			<th>Amount</th>
			<th>API</th>
			<th>Lapu No.</th>
			<th>API Balance</th>
			<th>API Diff</th>
			<th>Operator Id</th>
			<th>#</th>
			<th>Recharge Id</th>
			<th>Status</th>
			<th>Diff. Value</th>
			<th>#</th>
		</tr>
		<?php
			include'connection.php';
	    	$ParentId=$_GET['ParentId'];
			$ToatlRechAmount=0;
			if(isset($_POST['submit']))
			{
			    $fdate=$_POST['fdate'];
			    $ldate=$_POST['ldate'];
			    $Parent=$_POST['user'];
			    $stats=$_POST['stats'];
			    if($stats=="ALL")
			    {
			       $queryGetRechByLapuByDate="select * from recharge where Rechargedate>='$fdate' and Rechargedate<='$ldate' and Parentid='$Parent'"; 
			    }
			    else
			    {
			        $queryGetRechByLapuByDate="select * from recharge where Rechargedate>='$fdate' and Rechargedate<='$ldate' and Status='$stats' and Parentid='$Parent'";
			    }
			    
			    if(empty($Parent))
			    {
			        $Parent=$ParentId;
			    }
			    
			    $resultGetRechByLapuByDate=mysqli_query($con,$queryGetRechByLapuByDate);
			    $sl=0;
			    $TotalRechAmount=0;
			    while($dataByDate=mysqli_fetch_array($resultGetRechByLapuByDate))
			    {
			        $sl=$sl+1;
			        $TotalRechAmount=$TotalRechAmount+$dataByDate['Amount'];
			        $quGetName1="select * from retailer where Userid='".$dataByDate['Userid']."'";
			         $reGetName1=mysqli_query($con,$quGetName1);
			         $dataGetName1=mysqli_fetch_array($reGetName1);
    			    if($dataByDate['Status']=="SUCCESS")
    			    {
    			        $color="green";
    			    }
    			    elseif($dataByDate['Status']=="FAILED")
    			    {
    			        $color="red";
    			    }
    			    else
    			    {
    			        $color="blue";
    			    }
			    
			    	echo "<tr>";
    					echo "<td>".$dataByDate['Rechargedate']." | ".$dataByDate['Time']."</td>";
    					echo "<td id='tda'><a href='User_profile.php?id=".$dataGetName1['Userid']."' target='_blank'>".$dataGetName1['Name']."</a></td>";
    					echo "<td>".$dataByDate['Agentname']."</td>";
    					echo "<td>".$dataByDate['Balance']."</td>";
    					echo "<td>".$dataByDate['Companyname']."</td>";
    					echo "<td>".$dataByDate['Mobile']."</td>";
    					echo "<td>".$dataByDate['Amount']."</td>";
    					echo "<td>".$dataByDate['API']."</td>";
    					echo "<td>".$dataByDate['LapuNo']."</td>";
    					echo "<td>".$dataByDate['ApiBal']."</td>";
    					echo "<td>".$dataByDate['Diff']."</td>";
    					echo "<td>".$dataByDate['Operatorid']."</td>";
    					echo "<td>".$row['AdminOpId']."</td>";
    					echo "<td><a id='rechId' href='check_status.php?id=".$dataByDate['Id']."' target='_blank'>".$dataByDate['Id']."</a></td>";
    					echo "<td><p id='$color'>".$dataByDate['Status']."</p></td>";
    					echo "<td>".floor($dataByDate['AdminDiffValue'])."</td>";
    					if($dataByDate['ReHit']=="1" && $dataByDate['Status']=="PENDING")
    					{   
    					    echo "<td><a href='re_hit.php?id=".$dataByDate['Id']."' target='_blank'>Re-Hit</a></td>";
    					}
    					else
    					{
    					    echo "<td></td>";
    					}
    				echo "</tr>";
				echo "</tr>";
			    }
			   ?>
		<tr>
			<th>Date From</th>
			<th>Date To</th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th>Total Amount</th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
		</tr>
			   <?php
			   echo "<tr>";
    					echo "<td>".$fdate."</td>";
    					echo "<td>".$ldate."</td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td>".$TotalRechAmount."</td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
				echo "</tr>";
			}
			else
			{
			    date_default_timezone_set("asia/Kolkata");
			    $datetime= Date("Y-m-d - h:i:s A");
			    $time= Date("h:i:s A");
			    $fdate= Date("Y-m-d");
			    $ldate= Date("Y-m-d");
			   
			    $sl=0;
			    $TotalRechAmount=0;
    			$query="select * from recharge where Parentid='$ParentId' and Rechargedate='$date' order by Id desc";
    			$result=mysqli_query($con,$query);
    			while($row=mysqli_fetch_array($result))
    			{
    			    $sl=$sl+1;
    			    $quGetName="select * from retailer where Userid='".$row['Userid']."'";
    			    $reGetName=mysqli_query($con,$quGetName);
    			    $dataGetName=mysqli_fetch_array($reGetName);
    			    if($row['Status']=="SUCCESS")
    			    {
    			        $color="green";
    			    }
    			    elseif($row['Status']=="FAILED")
    			    {
    			        $color="red";
    			    }
    			    else
    			    {
    			        $color="blue";
    			    }
    				echo "<tr>";
    					echo "<td>".$row['Rechargedate']." | ".$row['Time']."</td>";
    					echo "<td id='tda'><a href='User_profile.php?id=".$dataGetName['Userid']."' target='_blank'>".$dataGetName['Name']."</a></td>";
    					echo "<td>".$row['Agentname']."</td>";
    					echo "<td>".$row['Balance']."</td>";
    					echo "<td>".$row['Companyname']."</td>";
    					echo "<td>".$row['Mobile']."</td>";
    					echo "<td>".$row['Amount']."</td>";
    					echo "<td>".$row['API']."</td>";
    					echo "<td>".$row['LapuNo']."</td>";
    					echo "<td>".$row['ApiBal']."</td>";
    					echo "<td>".floor($row['Diff'])."</td>";
    					echo "<td>".$row['Operatorid']."</td>";
    					echo "<td>".$row['AdminOpId']."</td>";
    					echo "<td><a id='rechId' href='check_status.php?id=".$row['Id']."' target='_blank'>".$row['Id']."</a></td>";
    					echo "<td><p id='$color'>".$row['Status']."</p></td>";
    					echo "<td>".floor($row['AdminDiffValue'])."</td>";
    					if($row['ReHit']=="1" && $row['Status']=="PENDING")
    					{   
    					    echo "<td><a href='re_hit.php?id=".$row['Id']."' target='_blank'>Re-Hit</a></td>";
    					}
    					else
    					{
    					    echo "<td></td>";
    					}
    				echo "</tr>";
    				$TotalRechAmount=$TotalRechAmount+$row['Amount'];
    			}
    	       ?>
    	       
		<tr>
			<th>Date</th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th>Total Amount</th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
		</tr>
			   <?php
			   echo "<tr>";
    					echo "<td>".$date."</td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td>".$TotalRechAmount."</td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
    					echo "<td></td>";
				echo "</tr>";
			}
		?>
	</table>
	<div class="foot">
		<p>Copyright &copy; 2018 Long Life Product Pvt. Ltd.</p>
	</div>
</body>
</html>