<?php
	include'session.php';
	include'connection.php';
	include'../Retailers/functions.php';

?>
<html>
<head>
	<title>Pending Recharge</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">
	
	<!-- j Query Link -->
	<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
	
	<!-- 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:98%;
			height:450px;
			margin:0 1%;
			padding:10px;
			overflow:auto;
			margin:10px 0;
		}
		.div1 input, .div1 select{
			height:35px;
			width:200px;
			font-size:15px;
			padding:2px 10px;
			border-radius:5px;
			border:solid #6b5127 1px;
			margin:5px 10px;
		}
		input[type=submit]{
			background:#6b5127;
			color:white;
			cursor:pointer;
			transition:1s;
		}
		input[type=submit]:hover{
			background:white;
			color:#883333;
			border:solid #6b5127 1px;
			transition:1s;
		}
		.div2{
			background:#f7f7f7;
			width:100%;
			height:550px;
			float:left;
			text-align:center;
			padding:10px 20px;
			overflow:auto;
		}
		INPUT{padding:5px 10px; border-radius:4px;}
		.div2 table{
			width:98%;
			text-align:center;
			font-size:14px;
			border-collapse:collapse;
			padding:2px 10px;
			margin:1%;
		}
		table th{
			background:#6b5127;
			color:white;
			height:40px;
			border:solid white 1px;
			padding:2px 5px;
		}
		table td{
			background:;
			height:35px;
			border:solid black 1px;
			padding:2px 5px;
		}
		table tr:hover{background-color:gray; color:white;}
		table tr:hover a{color:white;}
		
		.deactAnchor{background:green; color:white; padding:2px 5px; border-radius:3px; cursor:pointer;}
		.deactAnchor:active{background:white; color:#E2DFDF; border-color:#E2DFDF;}
		
		#lapuList{display:none;}
		.fa-check, .fa-ban{font-size:20px;}
		.StatusP{background:blue; color:white;}
		@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>Pending Recharge :-</p></div>
				<div class="msg"><marquee><?php include'msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
				<div class="div2" id="downlinePlace">
					<script>
						function refundTxn(Arg)
						{
						    var txnRefundId = Arg;
							var xmlhttpState = new XMLHttpRequest();
							xmlhttpState.open("GET","Ajax.php?txnRefundId="+txnRefundId, false)
							xmlhttpState.send(null);
							
							if(xmlhttpState.responseText=="FAILED")
							{
							    document.getElementById(txnRefundId).style.display = "none";
							    document.getElementById(txnRefundId+"StatusP").style.backgroundColor = "red";
							    document.getElementById(txnRefundId+"StatusP").innerHTML = "FAILED";
							}
						}
					</script>
					<?php
					        if($_GET['lapuDate'])
						    {
						        $lapuDate=$_GET['lapuDate'];
						        $lapuNo=$_GET['lapuNo'];
						        echo '<form method="post"><input type="submit" name="update" value="DEACTIVE ALL"></form>';
						        if(isset($_POST['update']))
						        {
						            $UpdateQu="UPDATE recharge SET ActiveMinus='1' WHERE rechargedate='$lapuDate' AND LapuNo='$lapuNo'";
						            if(mysqli_query($con,$UpdateQu))
						            {
						                echo "UPDATED SUCCESSFULLY";
						            }
						        }
						        
						    }
						    
					?>
					
					<table cellpadding="20" border="2"> 
						<tr>
							<th>Sl.</th>
							<th>Client Name</th>
							<th>API</th>
							<th>Time</th>
							<th>Operator</th>
							<th>Mobile</th>
							<th>Amount</th>
							<th>Lapu Owner</th>
							<th>Lapu No.</th>
							<th>Order Id</th>
							<th>Status</th>
							<th>Action</th>
						</tr>
						<?php
	    					$Pdate = date("Y-m-d H:i:s");
                            $Ptime = strtotime($Pdate);
                            $Ptime = $Ptime - (60);
                            $PdatePtime = date("Y-m-d H:i:s", $Ptime);
    
	                        $UsrQu="SELECT * FROM recharge WHERE Status='PENDING' AND PTime<='$PdatePtime' ORDER BY Id DESC";
						    //$UsrQu="SELECT * FROM recharge WHERE Status='PENDING' ORDER BY Id DESC";
							$UsrResult=mysqli_query($con,$UsrQu);
							while($UsrData=mysqli_fetch_array($UsrResult))
							{
								$sl=$sl+1;
								$slDiff=0;
								$orderId=$UsrData['Id'];
								$rechDate=$UsrData['Rechargedate'];
								$lapuNo=$UsrData['LapuNo'];
								
								echo "<tr >";
									echo "<td>".$sl."</td>";
									echo "<td>".getName($UsrData['Userid'])."</td>";
									echo "<td>".$UsrData['API']."</td>";
									echo "<td>".$UsrData['Time']."</td>";
									echo "<td>".$UsrData['Companyname']."</td>";
									echo "<td>".$UsrData['Mobile']."</td>";
									echo "<td>".$UsrData['Amount']."</td>";
									echo "<td>".getLON($UsrData['LapuNo'])."</td>";
									echo "<td><a href='recharge_by_lapu.php?lapuNo=".$UsrData['LapuNo']."&rechId=".$UsrData['Id']."&rechDate=".$UsrData['Rechargedate']."' target='_blank'>".$UsrData['LapuNo']." </td>";
									echo "<td><a href='check_txn_status.php?rechId=".$UsrData['Id']."' target='_blank'>".$UsrData['Id']."</td>";
									echo "<td class='StatusP' id='".$UsrData['Id']."StatusP'>".$UsrData['Status']."</td>";
									echo "<td>";
									    if($UsrData['Status']=="PENDING")
									    {
									        echo "<button class='deactAnchor' id='".$UsrData['Id']."' onclick='refundTxn(".$UsrData['Id'].")'>Refund</button>";
									    }
								    echo "</td>";
								echo "</tr>";
							}
							
						?>
					</table>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>