<?php
	include'session.php';
	include'connection.php';
	include'functions.php';
?>
<html>
<head>
	<title>Recharge Report</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">
	
	<!-- Admin CSS File Link -->
	<link rel="stylesheet" href="css/style.css">
	
	<!-- User JAVA SCRIPT File Link -->
	<script type="text/javascript" src="js/script.js"></script>

	
	<!-- Font Awesome Icone -->
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
	
	<style>
		.div1{
			background:;
			width:96%;
			margin:2%;
			padding:5px 10px;
		}
		.div1 input, .div1 select{
			height:40px;
			width:180px;
			font-size:16px;
			padding:5px 10px;
			border-radius:5px;
			border:solid #6b5127 1px;
			overflow:hidden;
			margin:10px 10px 0 5px;
		}
		input[type=submit]{
			background:#6b5127;
			color:white;
			transition:1s;
			cursor:pointer;
		}
		input[type=submit]:hover{
			background:white;
			color:#6b5127;
			transition:1s;
		}
		.div2{
			background:#f7f7f7;
			width:100%;
			float:left;
			text-align:center;
			padding:0 10px 10px 10px;
			overflow-x:auto;
		}
		.div2 table{
			width:96%;
			text-align:center;
			font-size:15px;
			border-collapse:collapse;
			padding:2px 10px;
			margin:2%;
		}
		table th{
			background:#6b5127;
			color:white;
			height:40px;
			border:solid white 1px;
			padding:2px 5px;
		}
		table td{
			background:white;
			height:40px;
			border:solid black 1px;
			padding:2px 5px;
		}
		
		#account,#orderid{display:none;}
		
		@media(max-width:768px)
		{
			.div1{
				background:;
				width:100%;
				height:auto;
				margin:10px 0 0 0;
				padding:0;
				text-align:center;
			}
			.div1 input,.div1 select{
				width:90%;
				margin:10px;
			}
			.div2{
				width:100%;
				margin:10px 0 0 0;
				padding:0px;
				text-align:center;
			}
		}
		

	</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';
		?>
		<div class="content">
			<div class="head">
				<div class="title"><p>Recharge Report :-</p></div>
				<div class="msg"><marquee><?php include'msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
			    <script>
			        function searchType()
			        {
			            var searchType = document.getElementById("sarchType").value;
			            
			            if(searchType=="DATEWISE")
			            {
			                document.getElementById("date1").style.display= "inline";
			                document.getElementById("date2").style.display= "inline";
			                document.getElementById("status").style.display= "inline";
			                document.getElementById("account").style.display= "none";
			                document.getElementById("orderid").style.display= "none";
			            }
			            else if(searchType=="ACCOUNT_NO")
			            {
			                document.getElementById("date1").style.display= "none";
			                document.getElementById("date2").style.display= "none";
			                document.getElementById("status").style.display= "none";
			                document.getElementById("account").style.display= "inline";
			                document.getElementById("orderid").style.display= "none";
			            }
			            else if(searchType=="ORDER_ID")
			            {
			                document.getElementById("date1").style.display = "none";
			                document.getElementById("date2").style.display = "none";
			                document.getElementById("status").style.display = "none";
			                document.getElementById("account").style.display = "none";
			                document.getElementById("orderid").style.display = "inline";
			            }
			        }
			    </script>
				<form method="post">
					<div class="div1">
						<select name="sarchType" onchange="searchType()" id="sarchType">
						    <option>DATEWISE</option>
						    <option>ACCOUNT_NO</option>
						    <option>ORDER_ID</option>
						</select>
						<input type="date" name="fdate" id="date1" value="<?php echo $date; ?>">
						<input type="date" name="ldate" id="date2" value="<?php echo $date; ?>">
						<input type="number" name="account" id="account" placeholder="Mobile/DTH No....">
						<input type="number" name="orderid" id="orderid" placeholder="Order Id....">
						<select name="status" id="status">
						    <option>ALL</option>
						    <option>SUCCESS</option>
						    <option>FAILED</option>
						    <option>PENDING</option>
						</select>
						<input type="submit" name="submit" value="Submit"  onclick='showLoader()'>
					</div>
				</form>
				<div class="div2">
					<table cellpadding="20" border="2"> 
						<tr>
							<th>Order Id</th>
							<th>Date Time</th>
							<th>Discription</th>
							<th>Status</th>
						</tr>
						<?PHP
							if(isset($_POST['submit']))
							{
								$sarchType = $_POST['sarchType'];
								$fdate = $_POST['fdate'];
								$ldate = $_POST['ldate'];
								$status = $_POST['status'];
								$account = $_POST['account'];
								$orderid = $_POST['orderid'];
								
								$sl=0;
								if($sarchType=="DATEWISE")
								{
								    if($status=="ALL")
								    {
								        $quPayment="SELECT * FROM recharge WHERE Parentid='$userid' AND Rechargedate>='$fdate' AND Rechargedate<='$ldate'";
								    }
								    else
								    {
								        $quPayment="SELECT * FROM recharge WHERE Parentid='$userid' AND Status='$status' AND Rechargedate>='$fdate' AND Rechargedate<='$ldate'";
								    }
								}
								elseif($sarchType=="ACCOUNT_NO")
								{
								    $quPayment="SELECT * FROM recharge WHERE Mobile='$account' ORDER BY Id DESC";
								}
								elseif($sarchType=="ORDER_ID")
								{
								    $quPayment="SELECT * FROM recharge WHERE Id='$orderid'";
								}
								
								$rePayment=mysqli_query($con,$quPayment);
								while($dataPayment=mysqli_fetch_array($rePayment))
								{
									if($dataPayment['Status']=="FAILED")
									{
										$color="red";
									}
									elseif($dataPayment['Status']=="SUCCESS")
									{
										$color="green";
									}
									else
									{
										$color="blue";
									}
									$usrName=getName($dataPayment['Userid']);
									echo"<tr>";
										echo "<td>".$dataPayment['Id']."</td>";
										echo "<td>".$dataPayment['Rechargedate']." ".$dataPayment['Time']."</td>";
										echo "<td>".$usrName." ".$dataPayment['Mobile']." ".$dataPayment['Companyname']." <i class='fa fa-inr'></i>".$dataPayment['Amount']." ".$dataPayment['Operatorid']."</td>";
										echo "<td><p id='".$color."'>".$dataPayment['Status']."</p></td>";
									echo"</tr>";
								}
							}
							else
							{
								$sl=0;
								$quPayment="SELECT * FROM recharge WHERE Parentid='$userid' ORDER BY Id DESC LIMIT 10";
								$rePayment=mysqli_query($con,$quPayment);
								while($dataPayment=mysqli_fetch_array($rePayment))
								{
									if($dataPayment['Status']=="FAILED")
									{
										$color="red";
									}
									elseif($dataPayment['Status']=="SUCCESS")
									{
										$color="green";
									}
									else
									{
										$color="blue";
									}
									$usrName=getName($dataPayment['Userid']);
									echo"<tr>";
										echo "<td>".$dataPayment['Id']."</td>";
										echo "<td>".$dataPayment['Rechargedate']." ".$dataPayment['Time']."</td>";
										echo "<td>".$usrName." ".$dataPayment['Mobile']." ".$dataPayment['Companyname']." <i class='fa fa-inr'></i>".$dataPayment['Amount']." ".$dataPayment['Operatorid']."</td>";
										echo "<td><p id='".$color."'>".$dataPayment['Status']."</p></td>";
									echo"</tr>";
								}
							}
						?>
					</table>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>