<?php
	include'session.php';
	include'../connection.php';
	include'../functions.php';
?>
<html>
<head>
	<title>Topup Report</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:98%;
			margin:1%;
			padding:10px;
		}
		.div1 input, .div1 select{
			height:30px;
			width:180px;
			font-size:16px;
			padding:2px 7px;
			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:15px;
			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, .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>Topup Report :-</p></div>
				<div class="msg"><marquee><?php include'../msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
				<div class="div2">
					<table cellpadding="20" border="2"> 
						<tr>
							<th>Id</th>
							<th>ReqType</th>
							<th>Date<br>Time</th>
							<th>User</th>
							<th><i class="fa fa-inr"></i></th>
							<th>Bank<br>Firm</th>
							<th>Txn No.</th>
							<th>Status</th>
							<th colspan='3'>Action</th>
						</tr>
						<?PHP
							    $totalPayment=0;
	                            $quPP="SELECT Id, ReqType, Status FROM order_req WHERE Status='PENDING'";
								$rePP=mysqli_query($con,$quPP);
								$countPP=mysqli_num_rows($rePP);
								while($dataPP=mysqli_fetch_array($rePP))
								{
									if($dataPP['Status']=="REJECTED")
									{
										$color="red";
									}
									elseif($dataPP['Status']=="APPROVED")
									{
										$color="green";
									}
									else
									{
										$color="blue";
									}
									$paymentReqid=$dataPP['Id'];
                                    if($dataPP['ReqType']=="BANKING")
									{
									    $tblData="p.Id, p.BankId, p.ReqType, p.Date, p.Time, p.Userid, p.Amount, p.Mode, p.TxnNo, p.Status, u.Name, b.BankName, b.AccName";
									}
									else
									{
									   $tblData="p.Id, p.ReqType, p.Date, p.Time, p.Userid, p.Amount, p.Status, u.Name, p.TxnNO";
									}
									$IJorNb    = "LEFT JOIN bank b ON p.BankId=b.Id";
									$IJorNu    = "LEFT JOIN user u ON p.Userid=u.Userid";
									$quPayment = "SELECT $tblData FROM order_req p $IJorNb $IJorNu WHERE p.Id='$paymentReqid'";
									$rePayment = mysqli_query($con,$quPayment);
									$dataPayment=mysqli_fetch_array($rePayment);
									$amountFormatted=numFormat($dataPayment['Amount']);
									echo"<tr>";
										echo "<td>".$dataPayment['Id']."</td>";
										echo "<td>".$dataPayment['ReqType']."</td>";
										echo "<td>".$dataPayment['Date']."<br>".$dataPayment['Time']."</td>";
										echo "<td>".$dataPayment['Name']."<br>[".$dataPayment['Userid']."]</td>";
										echo "<td>".$amountFormatted."</td>";
										echo "<td>".$dataPayment['BankName']."<br>".$dataPayment['AccName']."</td>";
										echo "<td>".$dataPayment['Mode']."<br>".$dataPayment['TxnNo']."</td>";
										echo "<td><p id='$color'>".$dataPayment['Status']."</p></td>";
										if(10==strlen($dataPayment['Userid']))
										{
										    echo "<td><a style='color:green;'  href='payment_approve_mlm.php?reqId=".$dataPayment['Id']."'>Payment Approve</a></td>";
										    
										}
										else
										{
										    echo "<td><a style='color:green;' href='payment_approve2.php?reqId=".$dataPayment['Id']."&amount=".$dataPayment['Amount']."&Txnnumber=".$dataPayment['Txnnumber']."&BankId=".$dataPayment['BankId']."&reqType=".$dataPayment['reqType']."&UsrId=".$dataPayment['Userid']."' onclick='showLoader()'>Payment Approve</a></td>";
										}
										echo "<td><a style='color:red;' href='payment_reject.php?reqId=".$dataPayment['Id']."' onclick='showLoader()'>Payment Reject</a></td>";
										
									echo"</tr>";
									
								}
								if($countPP<1)
								{
								    echo "<tr><td colspan='15'><center><h3 style='color:red'>Data Not Found !</h3></center></td></tr>";
								}
								
						    
						?>
					</table>
				</div>
				<div class="div1">
				    <?php
				            if(isset($_POST['submit']))
							{
								$fdateValue = $_POST['fdate'];
								$ldateValue = $_POST['ldate'];
							}
							else
							{
							    $fdateValue = $date;
								$ldateValue = $date;
							}
							
				    ?>
				    <form method="post">
						<select name="dateType" onchange="hide()">
						    <option value="S_Date">Settled Date</option>
						    <option value="Date">Request Date</option>
						</select>
						<input type="date" name="fdate" value="<?php echo $fdateValue; ?>">
						<input type="date" name="ldate" value="<?php echo $ldateValue; ?>">
						<select name="status" id="stts">
						    <option>ALL</option>
						    <option>APPROVED</option>
						    <option>PENDING</option>
						    <option>REJECTED</option>
						</select>
						<select  name="user">
						    <option>ALL</option>
						    <?php
						        $quUsr = "SELECT * FROM user WHERE STATUS='ACTIVE' AND Access='UNBLOCK'";
						        $reUsr = mysqli_query($con,$quUsr);
						        while($dataUsr = mysqli_fetch_array($reUsr))
						        {
						            $usrId   = $dataUsr['Userid'];
						            $usrName = $dataUsr['Name'];
						            echo "<option value='".$usrId."'>".$usrName." - ".$usrId."</option>";
						        }
						    ?>
						</select>
						<input type="submit" name="submit" value="Submit"  onclick='showLoader()'>
				    </form>
				
				</div>
				<div class="div2">
					<table cellpadding="20" border="2"> 
						<tr>
							<th>Req.Id</th>
							<th>ReqType</th>
							<th>User</th>
							<th>Date Time</th>
							<th><i class="fa fa-inr"></i></th>
							<th>Discription</th>
							<th>Status</th>
							<th>Settlement</th>
						</tr>
						<?PHP
						    $quStatus = "";
						    $quUserType = "";
							if(isset($_POST['submit']))
							{
								$dateType  = $_POST['dateType'];
								$fdate     = $_POST['fdate'];
								$ldate     = $_POST['ldate'];
								$status    = $_POST['status'];
								echo $user      = $_POST['user'];
								$totalPayment=0;
								$sl=0;
								$quStatus = "";
								if($status!="ALL")
								{
								    $quStatus="AND Status='$status'";
								}
								
								if($user!="ALL")
								{
								    $quUserType="AND Userid='$user'";
								}
								
								echo $quPayment="SELECT * FROM order_req WHERE $dateType>='$fdate' AND $dateType<='$ldate' $quStatus $quUserType";
								
								$rePayment=mysqli_query($con,$quPayment);
								$countPayment=mysqli_num_rows($rePayment);
								while($dataPayment=mysqli_fetch_array($rePayment))
								{
									if($dataPayment['Status']=="REJECTED")
									{
										$color="red";
									}
									elseif($dataPayment['Status']=="APPROVED")
									{
										$color="green";
									}
									$usrName=getName($dataPayment['Userid']);
									echo"<tr>";
										echo "<td>".$dataPayment['Id']."</td>";
										echo "<td>".$dataPayment['ReqType']."</td>";
										echo "<td>".$dataPayment['Date']." ".$dataPayment['Time']."</td>";
										echo "<td>".$usrName." [".$dataPayment['Userid']."]</td>";
										echo "<td>".$dataPayment['Amount']."</td>";
										echo "<td>".$dataPayment['Paymentdate']." ".$dataPayment['Bankname']." ".$dataPayment['Mode']." ".$dataPayment['Txnnumber']." ".$dataPayment['Responsemsg']."</td>";
										echo "<td><p id='$color'>".$dataPayment['Status']."</p></td>";
										echo "<td><p>".$dataPayment['SettleDate']."</p></td>";
									echo"</tr>";
									$totalPayment=$totalPayment+$dataPayment['Amount'];
								}
								if($countPayment<1)
								{
								    echo "<tr><td colspan='10'><center><h3 style='color:red'>Data Not Found !</h3></center></td></tr>";
								}
							}
							else
							{
								$sl=0;
								$quPayment="SELECT * FROM order_req ORDER BY Id DESC LIMIT 20";
								$rePayment=mysqli_query($con,$quPayment);
								$countPayment=mysqli_num_rows($rePayment);
								while($dataPayment=mysqli_fetch_array($rePayment))
								{
									if($dataPayment['Status']=="REJECTED")
									{
										$color="red";
									}
									elseif($dataPayment['Status']=="APPROVED")
									{
										$color="green";
									}
									$usrName=getName($dataPayment['Userid']);
									echo"<tr>";
										echo "<td>".$dataPayment['Id']."</td>";
										echo "<td>".$dataPayment['ReqType']."</td>";
										echo "<td>".$dataPayment['Date']." ".$dataPayment['Time']."</td>";
										echo "<td>".$usrName." [".$dataPayment['Userid']."]</td>";
										echo "<td>".$dataPayment['Amount']."</td>";
										echo "<td>".$dataPayment['Paymentdate']." ".$dataPayment['Bankname']." ".$dataPayment['Mode']." ".$dataPayment['TxnNo']." ".$dataPayment['Responsemsg']."</td>";
										echo "<td><p id='$color'>".$dataPayment['Status']."</p></td>";
										echo "<td><p>".$dataPayment['SettleDate']."</p></td>";
									echo"</tr>";
									$totalPayment=$totalPayment+$dataPayment['Amount'];
								}
								if($countPayment<1)
								{
								    echo "<tr><td colspan='10'><center><h3 style='color:red'>Data Not Found !</h3></center></td></tr>";
								}
							}
							
							echo "<tr>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th>Total Amount</th>";
							    echo "<th>".$totalPayment."</th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							echo "</tr>";
						?>
					</table>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>