<?php
	include'session.php';
	include'../connection.php';
	include'../functions.php';
?>
<html>
<head>
	<title>Check Txn Status</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:15px;
			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:13px;
			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;
		}
		textarea{padding:5px;}
		@media(max-width:768px)
		{
			.div1{
				background:;
				width:100%;
				height:auto;
				margin:10px 0 0 0;
				padding:0;
				text-align:center;
			}.div1 input{
				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>Check Txn Status :-</p></div>
				<div class="msg"><marquee><?php include'../msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
				<form method="post">
					<div class="div1">
					    <select name="serchType">
					        <option>Order_Id</option>
					        <option>Account_No</option>
					        <option>Partner_Id</option>
					    </select>
						<input type="number" name="orderid" id="orderid" placeholder="Search....">
						<input type="submit" name="submit" value="Submit"  onclick='showLoader()'>
					</div>
				</form>
				<div class="div2">
					<table cellpadding="20" border="2"> 
						<tr><th colspan="13" style="background:black;">-: Recharge Status :-</th></tr>
						<tr><th>Order Id</th><th>User</th><th>Date Time</th><th>Mobile</th><th>Operator</th><th>Amount</th><th>Lapu No</th><th>Seller</th><th>Op.Id</th><th>Status</th><th colspan='4'>Action</th></tr>
						<?PHP
						    $flag=0;
							if(isset($_POST['submit']))
							{
								$orderid   = $_POST['orderid'];
								$serchType = $_POST['serchType'];
								if(!empty($orderid))
								{
								    $flag=1;
								    if($serchType=="Order_Id")
								    {
								        $serchType = "Id='$orderid'";
								    }
								    elseif($serchType=="Account_No")
								    {
								        $serchType = "Mobile='$orderid'";
								    }
								    elseif($serchType=="Partner_Id")
								    {
								        $serchType = "PartnerId='$orderid'";
								    }
								}
								else
								{
								    echo "<tr><td style='color:red' colspan='10'>Order Id Not Found !</td></tr>";
								}
								
							}
							elseif(!empty($_GET['rechId']))
							{
							    $orderid=$_GET['rechId'];
							    $flag=1;
							    $serchType = "Id='$orderid'";
							}
							else
							{
							    echo "<tr><td style='color:red' colspan='10'>Data Not Found !</td></tr>";
							}
							
							if($flag==1)
							{   
							    $arrayData = array();
							    $quRech    ="SELECT * FROM recharge WHERE $serchType";
								$reRech    = mysqli_query($con,$quRech);
								$countRech = mysqli_num_rows($reRech);
								if($countRech==0)
								{
								    echo "<tr><td style='color:red' colspan='10'>Data Not Found !</td></tr>";
								}
								else
								{
	    							while($dataRech = mysqli_fetch_array($reRech))
		    						{
			    					    array_push($arrayData,$dataRech['Id']);
    
	    	    						if($dataRech['Status']=="FAILED")
		    	    					{
			    	    					$color="red";
				    	    			}elseif($dataRech['Status']=="SUCCESS")
					    	    		{
						    	    		$color="green";
							    	    }
	    						    	else
		    						    {
			    						    $color="blue";
    				    				}
	    				    			$usrName=getName($dataRech['Userid']);
		    							echo"<tr>";
			    							echo "<td>".$dataRech['Id']."</td>";
				    						echo "<td>".getName($dataRech['Userid'])."<br>[ ".$dataRech['Userid']." ]</td>";
					    					echo "<td>".$dataRech['Date']."<br>".$dataRech['Time']."</td>";
						    				echo "<td>".$dataRech['Mobile']."</td>";
							    			echo "<td>".$dataRech['OpName']."</td>";
								    		echo "<td><i class='fa fa-inr'></i>".$dataRech['Amount']."</td>";
			    					    	echo "<td><a href='recharge_by_lapu.php?lapuNo=".$dataRech['Lapu']."&rechId=".$dataRech['Id']."&rechDate=".$dataRech['Date']."&OpCode=".$dataRech['OpCode']."' target='_blank'>".$dataRech['Lapu']."</a></td>";
										    echo "<td>".getLON($dataRech['Lapu'])."<br>".getLFN($dataRech['Lapu'])."</td>";
	    									echo "<td><textarea>".$dataRech['OpId']."</textarea></td>";
		    								echo "<td><p id='".$color."'>".$dataRech['Status']."</p></td>";
			    							if($dataRech['Status']!="FAILED")
				    						{
					    					    echo "<td><a href='failed_recharge.php?rechId=".$dataRech['Id']."'  style='color:red'>Failed</a></td>";
						    				}
							    			echo "<td><a href='update_recharge.php?rechId=".$dataRech['Id']."'  style='color:blue'>Update</a></td>";
								    		if($dataRech['Comp']==0)
									    	{
										        echo "<td><a href='../RegisterComplain/complain.php?rechId=".$dataRech['Id']."'>Complain</a></td>";
										    }
	    									elseif($dataRech['Comp']==1)
		    								{
			    							    echo "<td>Disputed</td>";
				    						}
					    					else
						    				{
							    			    echo "<td>Closed</td>";
								    		}
									    echo"</tr>";
								    }
								}
							}
						?>
					</table>
					
					
					<table cellpadding="20" border="2"> 
						<tr><th colspan="7" style="background:black;">-: Wallet Details :-</th></tr>
						<tr><th>E-Wallet Id</th><th>Rech Id</th><th>Date-Time</th><th>Txn Type</th><th>Op. Bal</th><th>Dt / Cr</th><th>Cl. Bal</th></tr>
						<?PHP
							if($flag==1)
							{   
							    $row = count($arrayData);
							    for($x=0; $x<$row; $x++)
							    {
							        $txnId = $arrayData[$x];
		    						$quRech2="SELECT * FROM wallet WHERE TxnId='$txnId'";
			    					if($reRech2=mysqli_query($con,$quRech2))
				    				{
					    			    while($dataRech2=mysqli_fetch_array($reRech2))
						    		    {
			    			    			echo"<tr>";
				    			    			echo "<td>".$dataRech2['Id']."</td>";
				    			    			echo "<td>".$txnId."</td>";
					    			    		echo "<td>".$dataRech2['Date']."<br>".$dataRech2['Time']."</td>";
	    						    			echo "<td>".$dataRech2['TxnType']."</td>";
		    						    		echo "<td>".$dataRech2['OpBal']."</td>";
			    						    	echo "<td><p style='color:green'>".$dataRech2['Txn']."</p></td>";
				    						    echo "<td>".$dataRech2['ClBal']."</td>";
					    				    echo"</tr>";
						    		    }
							        }
	    						    else
		    					    {
			    				        echo "<tr><td colspan='10'><center><h3 style='color:red'>Refund Data Not Found !</h3></center></td></tr>";
				    			    }
							    }
					    	}
							else
							{
							    echo "<tr><td style='color:red' colspan='10'>Data Not Found !</td></tr>";
							}
						?>
					</table>
					
					<table cellpadding="20" border="2"> 
						<tr><th colspan="7" style="background:black;">-: API Details :-</th></tr>
						<tr><th>ApiHitId</th><th>Rech Id</th><th>Date-Time</th><th>ApiName</th><th>ReqType</th><th>Discription</th></tr>
						<?PHP
							if($flag==1)
							{
							    $row = count($arrayData);
							    for($x=0; $x<$row; $x++)
							    {
							        $txnId = $arrayData[$x];
	    						    $quApi="SELECT * FROM api_hit WHERE TxnId='$txnId'";
		    						$reApi=mysqli_query($con,$quApi);
			    					while($dataApi=mysqli_fetch_array($reApi))
				    				{
				    				    $usrName="";
							            if($dataApi['Type']=="HIT")
				    				    {
				    				        $usrName = getName($dataApi['ApiName']);
				    				    }
					    				echo"<tr>";
						    				echo "<td>".$dataApi['Id']."</td>";
								    		echo "<td>".$dataApi['TxnId']."<br>".$dataApi['PartnerId']."</td>";
							    			echo "<td>".$dataApi['Date']."<br>".$dataApi['Time']."</td>";
									    	echo "<td>".$usrName."<br>".$dataApi['ApiName']."</td>";
    										echo "<td>".$dataApi['Type']."</td>";
	   									    echo "<td><textarea style='width:700px; height:100px; padding:7px;'>".$dataApi['Disc']."</textarea></td>";
	    								echo"</tr>";
		    						}
							    }
							}
							else
							{
							    echo "<tr><td style='color:red' colspan='10'>Data Not Found !</td></tr>";
							}
						?>
					</table>
					
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>