<?php
	include'session.php';
	include'connection.php';
	include'../Retailers/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;
		}
		
		@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">
						<input type="number" name="orderid" id="orderid" placeholder="Order Id....">
						<input type="submit" name="submit" value="Submit"  onclick='showLoader()'>
					</div>
				</form>
				<div class="div2">
					<table cellpadding="20" border="2"> 
						<tr><th colspan="12" style="background:black;">Recharge Status</th></tr>
						<tr><th>Order Id</th><th>Lapu No</th><th>Seller</th><th>Date Time</th><th>Mobile</th><th>Operator</th><th>Amount</th><th>Op.Id</th><th>Status</th><th colspan='3'>Action</th></tr>
						<?PHP
						    $flag=0;
							if(isset($_POST['submit']))
							{
								$orderid = $_POST['orderid'];
								if(!empty($orderid))
								{
								    $quPayment="SELECT * FROM recharge WHERE Id='$orderid'";
								    $flag=1;
								}
								else
								{
								    echo "<tr><td style='color:red' colspan='10'>Order Id Not Found !</td></tr>";
								}
								
							}
							elseif(!empty($_GET['rechId']))
							{
							    $orderid=$_GET['rechId'];
							    $quPayment="SELECT * FROM recharge WHERE Id='$orderid'";
							    $flag=1;
							}
							else
							{
							    echo "<tr><td style='color:red' colspan='10'>Data Not Found !</td></tr>";
							}
							
							if($flag==1)
							{
								$rePayment=mysqli_query($con,$quPayment);
								$dataPayment=mysqli_fetch_array($rePayment);
									if($dataPayment['Status']=="FAILED"){
										$color="red";
									}elseif($dataPayment['Status']=="SUCCESS"){
										$color="green";
									}else{
										$color="blue";}
									$debit_walletId=$dataPayment['Ewalletid'];
									$credit_walletId=$dataPayment['Creditewalletid'];
										
									$usrName=getName($dataPayment['Userid']);
									if(10==strlen($dataPayment['Userid']))
									{
									    $wallet="MLM_Wallet";
									}
									else
									{
									    $wallet="wallet";
									}
									echo"<tr>";
										echo "<td>".$dataPayment['Id']."</td>";
			    						echo "<td><a href='recharge_by_lapu.php?lapuNo=".$dataPayment['LapuNo']."&rechId=".$dataPayment['Id']."&rechDate=".$dataPayment['Rechargedate']."&ownOpCode=".$dataPayment['OpCode']."' target='_blank'>".$dataPayment['LapuNo']."</a></td>";
										echo "<td>".getLON($dataPayment['LapuNo'])."</td>";
										echo "<td>".$dataPayment['Rechargedate']." ".$dataPayment['Time']."</td>";
										echo "<td>".$dataPayment['Mobile']."</td>";
										echo "<td>".$dataPayment['Companyname']."</td>";
										echo "<td><i class='fa fa-inr'></i>".$dataPayment['Amount']."</td>";
										echo "<td>".$dataPayment['Operatorid']."</td>";
										echo "<td><p id='".$color."'>".$dataPayment['Status']."</p></td>";
										if($dataPayment['Status']!="FAILED")
										{
										    echo "<td><a href='failed_recharge.php?rechId=".$dataPayment['Id']."'  style='color:red'>Failed</a></td>";
										}
										echo "<td><a href='update_recharge.php?rechId=".$dataPayment['Id']."'  style='color:blue'>Update</a></td>";
										echo "<td><a href='resuccess_recharge.php?rechId=".$dataPayment['Id']."' style='color:green'>Resuccess</a></td>";
									echo"</tr>";
							}
						?>
					</table>
					
					<table cellpadding="20" border="2"> 
						<tr><th colspan="7" style="background:black;">Account Status</th></tr>
						<tr><th>E-Wallet Id</th><th>Date</th><th>Time</th><th>Txn Type</th><th>Op. Bal</th><th>Txn</th><th>Cl. Bal</th></tr>
						<?PHP
							if($flag==1)
							{
							    $quPayment1="SELECT * FROM $wallet WHERE Id='$debit_walletId'";
								$rePayment1=mysqli_query($con,$quPayment1);
								$dataPayment1=mysqli_fetch_array($rePayment1);
									echo"<tr>";
										echo "<td>".$dataPayment1['Id']."</td>";
										echo "<td>".$dataPayment1['Date']."</td>";
										echo "<td>".$dataPayment1['Time']."</td>";
										echo "<td>".$dataPayment1['TxnType']."</td>";
										echo "<td>".$dataPayment1['OpBal']."</td>";
										echo "<td><p style='color:red'>".$dataPayment1['Txn']."</p></td>";
										echo "<td>".$dataPayment1['ClBal']."</td>";
									echo"</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;">Refund Status</th></tr>
						<tr><th>E-Wallet Id</th><th>Date</th><th>Time</th><th>Txn Type</th><th>Op. Bal</th><th>Txn</th><th>Cl. Bal</th></tr>
						<?PHP
							if($flag==1)
							{
							    if(!empty($credit_walletId))
							    {
								    $quPayment2="SELECT * FROM $wallet WHERE Id='$credit_walletId'";
								    $rePayment2=mysqli_query($con,$quPayment2);
								    $dataPayment2=mysqli_fetch_array($rePayment2);
									echo"<tr>";
										echo "<td>".$dataPayment2['Id']."</td>";
										echo "<td>".$dataPayment2['Date']."</td>";
										echo "<td>".$dataPayment2['Time']."</td>";
										echo "<td>".$dataPayment2['TxnType']."</td>";
										echo "<td>".$dataPayment2['OpBal']."</td>";
										echo "<td><p style='color:green'>".$dataPayment2['Txn']."</p></td>";
										echo "<td>".$dataPayment2['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>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>