<?PHP
	include'session.php';
	include'../connection.php';
	include'../functions.php';
	
?>
<html>
<head>
	<title>Add Bank Txn</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, .div3{
			background:#f7f7f7;
			width:50%;
			height:auto;
			float:left;
			text-align:center;
			padding:10px;
		}
		.div1 table,.div3 table{
			width:94%;
			text-align:center;
			font-size:13px;
			border-collapse:collapse;
			margin:10px;
			padding:5px;
		}
		.div1 hr, div3 hr{
			margin:5px 10px;
			padding:0 10px;
		}
		table th{
			background:#6b5127;
			color:white;
			height:40px;
			border:solid white 1px;
			padding:4px 8px;
		}
		table td{
			background:white;
			height:40px;
			border:solid black 1px;
			padding:4px 8px;
		}
		.div1 hr, .div3 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:18px;
		}
		
		
		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;
		}
		.div3{width:96%; text-align:left;}
		.div3 input, .div3 select{
			width:120px;
			height:35px;
			margin:10px 5px;
			padding:2px 5px;
			border-radius:5px;
			border:1px solid #6b5127;
			font-size:13px;
		}
		@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'; ?>
		<div class="content">
			<div class="head">
				<div class="title"><p>Add Bank Txn :-</p></div>
				<div class="msg"><marquee><?php include'../msg.php'; ?></marquee></msg>
			</div><hr>
		    <?php
			    if(isset($_POST['submit']))
			    {
			        $addbal = $_POST['addbal'];
				    $Txn    = $_POST['Txn'];
				    $rmark  = $_POST['rmark'];
				    $BankId = $_POST['BankId'];
				
				    if($PayTo=="--Select Txn--" || $BankId=="--Select Bank--")
				    {
				        echo "<div class='msg-div'>
			                    <form method='post'>
				                    <h3>Invalid Selected Input !</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(empty($userid) || empty($addbal) || empty($rmark))
				    {
				        echo "<div class='msg-div'>
			                    <form method='post'>
				                    <h3>Something Empty !</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
				    {	
				        $OpBal = getBankBal($BankId);
				        if($Txn=="Credit")
				        {
				            $addRealbal=$addbal;
				            $ClBal     = $OpBal+$addbal;
				        }
				        elseif($Txn=="Debit")
				        {
				            $addRealbal=-$addbal;
				            $ClBal     = $OpBal-$addbal;
				        }
				        
				        $InsertTxn="INSERT INTO bank_wallet(BankId,Date,Time,OpBal,Txn,ClBal,TxnId,TxnType,TxnWith,Remarks)
				                VALUES ('$BankId','$date','$time','$OpBal','$addRealbal','$ClBal','4310925','Manually','$userid','$rmark')";
				        if(mysqli_query($con,$InsertTxn))
				        {
								echo "<div class='msg-div'>
							            <form method='post'>
							                <h3>Txn Added 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>";
				        }
			    	
				    }
		    	    echo "<META HTTP-EQUIV ='Refresh' Content ='5'>";
				}
			?>
			<div class="div1">
				<form method="post">
				    <input type="number" name="addbal"  Placeholder="Enter Amount..." >
				    <select name="Txn">
			            <option>--Select Txn--</option>
			            <option>Credit</option>
			            <option>Debit</option>
    		        </select>
				    <select name="BankId">
			            <option>--Select Bank--</option>
			            <?php
			                $GetBank="SELECT * FROM bank";
    			            $reGetbank=mysqli_query($con,$GetBank);
	    		            while($dataGetbank=mysqli_fetch_array($reGetbank))
		    	            {
			                    echo "<option value='".$dataGetbank['Id']."'>".$dataGetbank['BankName']." - ".$dataGetbank['AccName']."</option>"; 
		                    }
		                ?>
                    </select>
				    <input type="text" name="rmark" Placeholder="Discription..." required>
					<input type="submit" name="submit" value="Submit"  onclick='showLoader()'>
				</form>
			</div>
			<div class="div1">
				<center><h1>Bank Details</h1></center><hr>
				<table cellpadding="20" border="2">
				    <tr>
					    <th>Bank Name</th>
						<th><i class="fa fa-inr"></i></th>
					</tr>
					<?php
					    $quBank="SELECT * FROM bank WHERE Status='ACTIVE'";
		                $reBank=mysqli_query($con,$quBank);
		                while($dataBank=mysqli_fetch_array($reBank))
		                {
		                    $BankName = $dataBank['BankName'];
		                    $AccName  = $dataBank['AccName'];
		                    $BankId   = $dataBank['Id'];
		            
		                    
		                    echo "<tr>";
		                        echo "<td><a href='Bank_Account_Txn.php?BankId=".$BankId."' target='_blank'>".$BankName." -".$AccName."</a></td>";
		                        echo "<td>".floor(getBankBal($BankId))."</td>";
		                    echo "</tr>";
		                }
					?>
				</table>
			</div>
			<div class="div3">
				<center><h1>Generated Transaction</h1></center><hr>
				<form method="post">
	                <input type="date" name="fdate" value="<?php echo $date; ?>" id="inp2">
	                <input type="date" name="ldate" value="<?php echo $date; ?>" id="inp2">
				    <select name="BankName2">
			            <option>ALL</option>
			            <?php
			                $GetBank="SELECT * FROM bank";
    			            $reGetbank=mysqli_query($con,$GetBank);
	    		            while($dataGetbank=mysqli_fetch_array($reGetbank))
		    	            {
			                    echo "<option>".$dataGetbank['Bankname']."</option>"; 
		                    }
		                ?>
                    </select>
	                <input type="submit" name="submit2" value="Search" id="inp2">
				</form>
				<table cellpadding="20" border="2">
				    <tr>
					    <th>Sl.</th>
						<th>Id</th>
						<th>Date Time</th>
						<th>Bank Name</th>
						<th>Op. Bal</th>
						<th><i class="fa fa-inr"></i></th>
						<th>Cl. Bal</th>
						<th>Disc.</th>
						<th>Txn For</th>
					</tr>
					<?php
					    if(isset($_POST['submit2']))
						{
						    $fdate=$_POST['fdate'];
			                $ldate=$_POST['ldate'];
    		                $sl=0;
    		                if($bank2=="ALL")
    		                {   
                                $quGetGenrateTxn="SELECT * FROM bank_wallet WHERE TxnType='Manually' AND Date>='$fdate' AND Date<='$ldate'";
    		                }
    		                else
    		                {
    		                    $quGetGenrateTxn="SELECT * FROM bank_wallet WHERE TxnType='Manually' AND Date>='$fdate' AND Date<='$ldate' AND ='$bank2'";
    		                }
		        	        $reGetGenrateTxn=mysqli_query($con,$quGetGenrateTxn);
		        	        while($dataGetTxn=mysqli_fetch_array($reGetGenrateTxn))
						    {
							    	$sl=$sl+1;
								
								echo "<tr>";
							    	echo "<td>".$sl."</td>";
								    echo "<td>".$dataGetTxn['Id']."</td>";
								    echo "<td>".$dataGetTxn['Date']." ".$dataGetTxn['Time']."</td>";
								    echo "<td>".$dataGetTxn['OpBal']."</td>";
								    echo "<td>".$dataGetTxn['Txn']."</td>";
								    echo "<td>".$dataGetTxn['ClBal']."</td>";
								    echo "<td>".$dataGetTxn['Remarks']."</td>";
								    echo "<td>".$dataGetTxn['TxnType']."</td>";
							    echo "</tr>";
						    }
					    }
					    else
					    {
					        $sl=0;
						    $quGetTxn="SELECT * FROM bank_wallet WHERE TxnType='Manually' ORDER BY Id DESC LIMIT 10";
						    $reGetTxn=mysqli_query($con,$quGetTxn);
						    while($dataGetTxn=mysqli_fetch_array($reGetTxn))
						    {
							    $sl=$sl+1;
							    echo "<tr>";
							    	echo "<td>".$sl."</td>";
								    echo "<td>".$dataGetTxn['Id']."</td>";
								    echo "<td>".$dataGetTxn['Date']." ".$dataGetTxn['Time']."</td>";
								    echo "<td>".$dataGetTxn['OpBal']."</td>";
								    echo "<td>".$dataGetTxn['Txn']."</td>";
								    echo "<td>".$dataGetTxn['ClBal']."</td>";
								    echo "<td>".$dataGetTxn['TxnId']."</td>";
								    echo "<td>".$dataGetTxn['TxnType']."</td>";
								    echo "<td>".$dataGetTxn['Remarks']."</td>";
							    echo "</tr>";
						    }
					    }
				    ?>	
				</table>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>