<?php
	include'session.php';
	include'connection.php';
	include'../Retailers/functions.php';
?>
<html>
<head>
	<title>Recharge By User</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:0 2%;
			padding:5px 10px;
		}
		.div1 input, .div1 select{
			height:40px;
			max-width:160px;
			font-size:14px;
			padding:5px;
			border-radius:5px;
			border:solid #6b5127 1px;
			overflow:hidden;
			margin:10px 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%;
			height:450px;
			float:left;
			text-align:center;
			padding:5px;
			overflow:auto;
		}
		.div2 table{
			width:98%;
			text-align:center;
			font-size:13px;
			border-collapse:collapse;
			padding:2px 5px;
			margin:1%;
		}
        .div2 table tr:nth-child(odd){background:#f6f0e8;}
        .div2 table tr:nth-child(even){background:white; }
		table th{
			background:#6b5127;
			color:white;
			height:35px;
			border:solid white 1px;
			padding:2px 5px;
		}
		table td{
			height:30px;
			border:solid black 1px;
			padding:2px 5px;
		}
		
		#inpNum{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" id="contentDiv">
			<div class="head">
				<div class="title"><i class="fa fa-bars" onclick="hideMenu()" style="float:left; margin:10px;"></i><p>Recharge By Lapu :-</p></div>
				<div class="msg"><marquee><?php include'msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
			    <script>
			        function hideMenu()
			        {
			            if(document.getElementById("navHide").style.display!="none")
			            {
			                document.getElementById("navHide").style.display = "none";
			                document.getElementById("contentDiv").style.width = "100%";
			            }
			            else
			            {
			                document.getElementById("navHide").style.display = "inline";
			                document.getElementById("contentDiv").style.width = "82%";
			            }
			        }
			        
			        
			        function diffType()
			        {
			            var DiffType = document.getElementById("Diff").value;
			            
			            if(DiffType=="ALL")
			            {
			                document.getElementById("status").style.display= "inline";
			                document.getElementById("inpNum").style.display= "none";
			            }
			            else
			            {
			                document.getElementById("status").style.display= "none";
			                document.getElementById("inpNum").style.display= "inline";
			            }
			        }
			    </script>
			    <?php
			        $uid=$_GET['uid'];
			        $orderId=$_GET['rechId'];
			        $rechDate=$_GET['rechDate'];
			        
			        if(isset($_POST['submit']))
			        {
			            $fDateValue=$_POST['fdate'];
			            $lDateValue=$_POST['ldate'];
						$seller = $_POST['seller'];
			        }
			        else
			        {
			            $fDateValue=$date;
			            $lDateValue=$date;
			        }
			    ?>
				<form method="post">
					<div class="div1">
						<input type="date" name="fdate" id="date1" value="<?php echo $fDateValue; ?>">
						<input type="date" name="ldate" id="date2" value="<?php echo $lDateValue; ?>">
		                <select name="op">
		                    <option>ALL</option>
		                    <?php
		                        $quOp="SELECT * FROM operator";
		                        $reOp=mysqli_query($con,$quOp);
		                        while($dataOp=mysqli_fetch_array($reOp))
		                        {
		                            echo "<option>".$dataOp['Operator']."</option>";
		                        }
		                    ?>
		                </select>
		                <input style="width:70px" type="number" name="DiffAmt" id="inpNum" value="100">
						<select name="status" id="status">
						    <option>SUCCESS</option>
						    <option>FAILED</option>
						    <option>PENDING</option>
						    <option>ALL</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>Name</th>
							<th>Bal.</th>
							<th>Operator</th>
							<th>Mobile</th>
							<th>Amt.</th>
							<th>RO</th>
							<th>%</th>
							<th>API</th>
							<th>NO</th>
							<th>L.Owner</th>
							<th>Lapu No.</th>
							<th>Api Bal</th>
							<th>Api Diff</th>
							<th>Op. Id</th>
							<th>#</th>
							<th>Status</th>
							<th>CB</th>
							<th>RS</th>
							<th>@</th>
						</tr>
						<?PHP
							if(isset($_POST['submit']))
							{
								$fdate = $_POST['fdate'];
								$ldate = $_POST['ldate'];
								$op = $_POST['op'];
								$status = $_POST['status'];
								
								$sl=0;
								
								    if($op=="ALL")
								    {
								        if($status=="ALL")
								        {
								            $quPayment="SELECT * FROM recharge WHERE Userid='$uid' AND  Rechargedate>='$fdate' AND Rechargedate<='$ldate' ORDER BY Id DESC";
								        }
								        else
								        {
								            $quPayment="SELECT * FROM recharge WHERE Userid='$uid' AND Status='$status' AND Rechargedate>='$fdate' AND Rechargedate<='$ldate' ORDER BY Id DESC";
								        }
								    }
								    else
								    {
							            if($status=="ALL")
								        {
								            $quPayment="SELECT * FROM recharge WHERE Userid='$uid' AND  Rechargedate>='$fdate' AND Rechargedate<='$ldate' AND Companyname='$op' ORDER BY Id DESC";
								        }
								        else
								        {
								            $quPayment="SELECT * FROM recharge WHERE Userid='$uid' AND Status='$status' AND Rechargedate>='$fdate' AND Rechargedate<='$ldate' AND Companyname='$op' ORDER BY Id DESC";
								        }
								    }
								    
								$rePayment=mysqli_query($con,$quPayment);
								$totalRound500=0;
								$totalDiff=0;
								$totalRound1000=0;
								$total_rOffer=0;
								$total_amount=0;
								while($dataPayment=mysqli_fetch_array($rePayment))
								{
									if($dataPayment['Status']=="FAILED")
									{
										$color="red";
									}
									elseif($dataPayment['Status']=="SUCCESS")
									{
										$color="green";
									}
									else
									{
										$color="blue";
									}
									
									if($dataPayment['Id']==$orderId)
									{
									    $background="background:#F2BBBF";
									}
									else
									{
									    $background="";
									}
									    $usrName=getName($dataPayment['Userid']);
									    echo"<tr style='".$background."'>";
										    echo "<td><a href='check_txn_status.php?rechId=".$dataPayment['Id']."' target='_blank'>".$dataPayment['Id']."</a></td>";
    										echo "<td>".$dataPayment['Rechargedate']." ".$dataPayment['Time']."</td>";
	    									echo "<td>".$usrName."</td>";
		    								echo "<td>".floor($dataPayment['Balance'])."</td>";
						    				echo "<td>".$dataPayment['Companyname']."</td>";
							    			echo "<td>".$dataPayment['Mobile']."</td>";
								    		echo "<td>".$dataPayment['Amount']."</td>";
									    	echo "<td>".getRA($dataPayment['R_Offer'])."</td>";
    										echo "<td>".$dataPayment['RoffPerce']."</td>";
    										echo "<td>".$dataPayment['API']."</td>";
	    									echo "<td>".$dataPayment['API_NO']."</td>";
		    								echo "<td>".getLON($dataPayment['LapuNo'])."</td>";
			    							echo "<td>".$dataPayment['LapuNo']."</td>";
				    						echo "<td>".$dataPayment['ApiBal']."</td>";
					    					echo "<td>".getRA($dataPayment['Diff'])."</td>";
						    				echo "<td>".$dataPayment['Operatorid']."</td>";
							    			echo "<td>".$dataPayment['Responsetxt']."</td>";
								    		echo "<td><p id='".$color."'>".$dataPayment['Status']."</p></td>";
									    	echo "<td>";
										    if($dataPayment['CallBack']==0)
    										{
	    									    echo "<i class='fa fa-times'></i>";
		    								}
			    							else
				    						{
					    					    echo "<i class='fa fa-check'></i>";
						    				}
							    			echo "</td>";
								    		echo "<td>".$dataPayment['Roaming']."</td>";
									    	echo "<td>".$dataPayment['ReHit']."</td>";
									    echo"</tr>";
									    $total_amount=$total_amount+$dataPayment['Amount'];
									    $total_rOffer=$total_rOffer+$dataPayment['R_Offer'];
								}
							}
							else
							{
							    if(empty($rechDate))
							    {
							        $quPayment="SELECT * FROM recharge WHERE Userid='$uid' ORDER BY Id DESC LIMIT 20";
							    }
							    else
							    {
							        $quPayment="SELECT * FROM recharge WHERE Userid='$uid' AND Rechargedate='$rechDate' AND Status='SUCCESS' ORDER BY Id DESC";
							    }
								$sl=0;
								 
								$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";
									}
									
									if($dataPayment['Id']==$orderId)
									{
									    $background="background:#F2BBBF";
									}
									else
									{
									    $background="";
									}
									$usrName=getName($dataPayment['Userid']);
									if($dataPayment['ApiBal']>1000 || $dataPayment['ApiBal']==0)
									{
									    $colorBal="green";
									}
									else
									{
									    $colorBal="red";
									}
									if($dataPayment['Id']==$orderId)
									{
									    $background="background:#F2BBBF";
									}
									else
									{
									    $background="";
									}
									echo"<tr style='".$background."'>";
										echo "<td><a href='check_txn_status.php?rechId=".$dataPayment['Id']."' target='_blank'>".$dataPayment['Id']."</a></td>";
										echo "<td>".$dataPayment['Rechargedate']." ".$dataPayment['Time']."</td>";
										echo "<td>".$usrName."</td>";
										echo "<td>".floor($dataPayment['Balance'])."</td>";
										echo "<td>".$dataPayment['Companyname']."</td>";
										echo "<td>".$dataPayment['Mobile']."</td>";
										echo "<td>".$dataPayment['Amount']."</td>";
										echo "<td>".getRA($dataPayment['R_Offer'])."</td>";
										echo "<td>".$dataPayment['RoffPerce']."</td>";
										echo "<td>".$dataPayment['API']."</td>";
										echo "<td>".$dataPayment['API_NO']."</td>";
										echo "<td>".getLON($dataPayment['LapuNo'])."</td>";
										echo "<td>".$dataPayment['LapuNo']."</td>";
										echo "<td style='color:".$colorBal."; font-size:13px'><b>".floor($dataPayment['ApiBal'])."</b></td>";
										echo "<td>".getRA($dataPayment['Diff'])."</td>";
										echo "<td>".$dataPayment['Operatorid']."</td>";
										echo "<td>".$dataPayment['Responsetxt']."</td>";
										echo "<td><p id='".$color."'>".$dataPayment['Status']."</p></td>";
										echo "<td>";
										if($dataPayment['CallBack']==0)
										{
										    echo "<i class='fa fa-times'></i>";
										}
										else
										{
										    echo "<i class='fa fa-check'></i>";
										}
										echo "</td>";
										echo "<td>".$dataPayment['Roaming']."</td>";
										echo "<td>".$dataPayment['ReHit']."</td>";
									echo"</tr>";
									$total_amount=$total_amount+$dataPayment['Amount'];
									$total_rOffer=$total_rOffer+$dataPayment['R_Offer'];
								}
							}
							
							echo "<tr>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th>".$total_amount."</th>";
							    echo "<th>".$total_rOffer."</th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th>".$totalRound500."</th>";
							    echo "<th>".$totalDiff."</th>";
							    echo "<th>".$totalRound1000."</th>";
							    echo "<th></th>";
							    echo "<th></th>";
							echo "</tr>";
						?>
					</table>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>