<?PHP
	include'session.php';
	include'connection.php';
	include'functions.php';
	
?>
<html>
<head>
	<title>Add Money</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:#f7f7f7;
			width:50%;
			height:auto;
			float:left;
			text-align:center;
			padding:10px;
		}
		.div1 table{
			width:94%;
			text-align:center;
			font-size:13px;
			border-collapse:collapse;
			margin:10px;
			padding:5px;
		}
		.div1 hr{
			margin:5px;
			padding:0 10px;
		}
		table th{
			background:#6b5127;
			color:white;
			height:40px;
			border:solid white 1px;
		}
		table td{
			background:white;
			height:40px;
			border:solid black 1px;
			padding:5px;
		}
		.div1 hr{width:94%;}
		.div1 input,select, textarea{
			width:90%;
			height:45px;
			margin:5px 10px;
			padding:2px 10px;
			border-radius:5px;
			border:1px solid #6b5127;
			font-size:14px;
		}
		textarea{
			height:100px;
			padding:5px 10px;
		}
		input[type=submit]{
			background:#6b5127;
			color:white;
			font-size:30px;
			transition:1s;
		}
		input[type=submit]:hover{
			background:white;
			color:#6b5127;
			border:1px solid #6b5127;
			cursor:pointer;
			transition:1s;
		}
		
		@media(max-width:768px)
		{
			.div1{
				width:100%;
				height:auto;
			}
			.nav,.container{
				height:auto;
			}
		}
	</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';
			
			
	if(isset($_POST['submit']))
	{
		$reqType = $_POST['reqType'];
		$amount = $_POST['amount'];
		$Pdate = $_POST['date'];
		$bank = $_POST['bank'];
		$mode = $_POST['mode'];
		$txn = $_POST['txn'];
		$msg = $_POST['msg'];
		
		if($reqType=="BANKING")
		{
		    $allowAmount=50000;
		}
		else
		{
		    $allowAmount=5000;
		}
		
		if(empty($amount) || empty($Pdate) || empty($txn))
		{
		    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Fill All Fields Please !</h3><br>
				        <i class='fa fa-ban' aria-hidden='true' id='NotokIcon'></i><br><br>
				        <button type='submit' class='btnPopup'>OK</button><br><br>
			        </form>
		        </div>";
		}
		elseif($amount<2000 || $amount>$allowAmount)
		{
		    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Amount Must Be 2000 To .$allowAmount. Only !</h3><br>
				        <i class='fa fa-ban' aria-hidden='true' id='NotokIcon'></i><br><br>
				        <button type='submit' class='btnPopup'>OK</button><br><br>
			        </form>
		        </div>";
		}
		elseif($bank=="--Select Bank--")
		{
		    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Select Bank Please !</h3><br>
				        <i class='fa fa-ban' aria-hidden='true' id='NotokIcon'></i><br><br>
				        <button type='submit' class='btnPopup'>OK</button><br><br>
			        </form>
		        </div>";
		}
		elseif($mode=="--Select Mode--")
		{
		    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Select Payment Mode !</h3><br>
				        <i class='fa fa-ban' aria-hidden='true' id='NotokIcon'></i><br><br>
				        <button type='submit' class='btnPopup'>OK</button><br><br>
			        </form>
		        </div>";
		}
		else
		{	
			$quDupTxn="SELECT * FROM paymentreq WHERE Txnnumber='$txn' AND Status='PENDING' OR Txnnumber='$txn' AND Status='APPROVED'";
			$reDupTxn=mysqli_query($con,$quDupTxn);
			$countDupTxn=mysqli_num_rows($reDupTxn);
			if($countDupTxn>=1)
			{
			    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Duplicate Transaction Not Allowed !</h3><br>
				        <i class='fa fa-ban' aria-hidden='true' id='NotokIcon'></i><br><br>
				        <button type='submit' class='btnPopup'>OK</button><br><br>
			        </form>
		        </div>";
			}
			else
			{
			    $quBankName="SELECT * FROM bank WHERE Id='$bank'";
				$reBankName=mysqli_query($con,$quBankName);
				$dataBankName=mysqli_fetch_array($reBankName);
				$bankName=$dataBankName['Bankname'];
				
				$quInsertRequest="INSERT INTO paymentreq(reqType,Date,Time,Paymentdate,Userid,Amount,BankId,Bankname,Txnnumber,Mode,Remarks)
				VALUES('$reqType','$date','$time','$Pdate','$userid','$amount','$bank','$bankName','$txn','$mode','$msg')";
				if(mysqli_query($con,$quInsertRequest))
				{
					echo "<div class='msg-div'>
							<form method='post'>
							<h3>Payment Request Submited Successfully !</h3><br>
							<i class='fa fa-check-circle' aria-hidden='true' id='okIcon'></i><br><br>
							<button type='submit' class='btnPopup'>OK</button><br><br>
							</form>
						</div>";
				}
			}
		}
	}
		?>
		<div class="content">
			<div class="head">
				<div class="title"><p>Add Money :-</p></div>
				<div class="msg"><marquee><?php include'msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
				<form method="post">
					<div class="div1">
					    <center><h3 style="color:blue">Minimum Amount Limit 2000 Rs.</h3></center>
						<select name="reqType" onchange="reqTyp()" id="reqT" >
							<option>BANKING</option>
						</select>
						<input type="number" name="amount" placeholder="Minimum Amount 2000..." required>
						<input type="date" name="date" value="<?php echo $date; ?>"  required>
						<select name="bank"  required>
							<option>--Select Bank--</option>
							<?php
							    $quBank="SELECT * FROM bank WHERE Status='Active'";
							    $reBank=mysqli_query($con,$quBank);
							    while($dataBank=mysqli_fetch_array($reBank))
							    {
							        echo "<option value='".$dataBank['Id']."'>".$dataBank['Bankname']." - ".$dataBank['Accno']."</option>";
							    }
							
							?>
						</select>
						<select name="mode">
							<option>--Select Mode--</option>
							<option>IMPS</option>
							<option>NEFT</option>
							<option>RTGS</option>
						</select>
						<input type="text" name="txn" placeholder="Txn No..."  required>
						<textarea name="msg" placeholder="Type your message hear..(optional)"></textarea>
						<input type="submit" name="submit" value="Submit"  onclick='showLoader()'>
					</div>
				</form>
				<div class="div1">
					<center><h1>Recent Transaction</h1></center><hr>
					<table cellpadding="20" border="2">
						<tr>
							<th>Req.Id</th>
							<th>Date</th>
							<th><i class="fa fa-inr"></i></th>
							<th>Discription</th>
							<th>Status</th>
						</tr>
						<?php
							$quGetTxn="SELECT * FROM paymentreq WHERE Userid='$userid' ORDER BY Id DESC LIMIT 10";
							$reGetTxn=mysqli_query($con,$quGetTxn);
							while($dataGetTxn=mysqli_fetch_array($reGetTxn))
							{
								if($dataGetTxn['Status']=="PENDING")
								{
									$color="blue";
								}
								elseif($dataGetTxn['Status']=="APPROVED")
								{
									$color="green";
								}
								else
								{
									$color="red";
								}
								echo "<tr>";
									echo "<td>".$dataGetTxn['Id']."</td>";
									echo "<td>".$dataGetTxn['Date']."</td>";
									echo "<td>".$dataGetTxn['Amount']."</td>";
									echo "<td style='width:55%'>".$dataGetTxn['reqType']." ".$dataGetTxn['Mode']." ".$dataGetTxn['Txnnumber']." ".$dataGetTxn['Bankname']."</td>";
									echo "<td style='color:".$color."'>".$dataGetTxn['Status']."</td>";
								echo "</tr>";
							}
						?>
					</table>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>