<?php
	include'session.php';
	include'../connection.php';
	include'../functions.php';
?>
<html>
<head>
	<title>U Turn 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>U Turn 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 AjaxName     = "Ajax12";
						    var orderId      = Arg;
							var xmlhttpState = new XMLHttpRequest();
							xmlhttpState.open("GET","Ajax.php?AjaxName="+AjaxName+"&orderId="+orderId, false)
							xmlhttpState.send(null);
							if(xmlhttpState.responseText=="FAILED")
							{
							    document.getElementById(orderId).style.display = "none";
							    document.getElementById(orderId+"StatusP").style.backgroundColor = "red";
							    document.getElementById(orderId+"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 colspan='2'>Action</th>
						</tr>
						<?php
	    					$Ptime = strtotime($time);
                            $Ptime = $Ptime - (60);
                            $Ptime = date("h:i:s A", $Ptime);
                            
                            $quUturn    = "SELECT * FROM wallet, recharge WHERE TxnType='Recharge_Refund' AND wallet.TxnId=recharge.Id AND recharge.Status = 'SUCCESS'";
	                        $reUturn    = mysqli_query($con,$quUturn);
	                        $countUturn = mysqli_num_rows($reUturn);
	                        //$dataUturn  = mysqli_fetch_array($reUturn);

                            
	                        //$UsrQu="SELECT * FROM recharge WHERE Status='PENDING' AND Time<='$Ptime' ORDER BY Id DESC";
							//$UsrResult=mysqli_query($con,$UsrQu);
							while($dataUturn = mysqli_fetch_array($reUturn))
							{
								$sl=$sl+1;
								$slDiff=0;
								$orderId  = $dataUturn['recharge.Id'];
								$rechDate = $dataUturn['recharge.Date'];
								$lapuNo   = $dataUturn['recharge.Lapu'];
								
								echo "<tr >";
									echo "<td>".$sl."</td>";
									echo "<td>".getName($dataUturn['Userid'])."</td>";
									echo "<td>".$dataUturn['recharge.Api']."</td>";
									echo "<td>".$dataUturn['recharge.Time']."</td>";
									echo "<td>".$dataUturn['recharge.OpName']."</td>";
									echo "<td>".$dataUturn['recharge.Mobile']."</td>";
									echo "<td>".$dataUturn['recharge.Amount']."</td>";
									echo "<td>".getLON($dataUturn['recharge.Lapu'])."</td>";
									echo "<td><a href='recharge_by_lapu.php?lapuNo=".$dataUturn['recharge.Lapu']."&rechId=".$dataUturn['recharge.Id']."&rechDate=".$dataUturn['recharge.Date']."' target='_blank'>".$UsrData['recharge.Lapu']." </td>";
									echo "<td><a href='check_txn_status.php?rechId=".$dataUturn['recharge.Id']."' target='_blank'>".$dataUturn['recharge.Id']."</td>";
									echo "<td class='StatusP' id='".$dataUturn['recharge.Id']."StatusP'>".$dataUturn['recharge.Status']."</td>";
									echo "<td>";
									    if($UsrData['Status']=="PENDING")
									    {
									        echo "<a href='../LinkFile/updateRechByChkApi.php?order_id=".$UsrData['Id']."' >Check Status</a>";
									    }
								    echo "</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>