<?php
	include'session.php';
	include'../connection.php';
	include'../functions.php';
?>
<html>
<head>
	<title>Bank Account 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{
			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;
		}
		
        .div2 table tr:hover{background:gray; color:white;}
		#inpNum, #lapuValue, #value1, #value2{display:none;}
		#analysisData{margin-left:2%;}
		#analysisData table td{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" id="contentDiv">
			<div class="head">
				<div class="title"><i class="fa fa-bars" onclick="hideMenu()" style="float:left; margin:10px;"></i><p>Bank Account Txn :-</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%";
			            }
			        }
			        
			        
			      
			    </script>
			    <?php
			        $BankId=$_GET['BankId'];
			        $fDateValue=$date;
			        $lDateValue=$date;
			        if(isset($_POST['submit']))
			        {
			            $fDateValue = $_POST['fdate'];
			            $lDateValue = $_POST['ldate'];
			            $TxnType    = $_POST['TxnType'];
			            $slType     = $_POST['slType'];
			            if($TxnType=="ALL")
			            {
			                $TxnType1 = "selected";
			            }
			            elseif($TxnType=="CREDIT")
			            {
			                $TxnType2 = "selected";
			            }
			            elseif($TxnType=="DEBIT")
			            {
			                $TxnType3 = "selected";
			            }
			            
			            if($slType=="ASC")
			            {
			                $slType1 = "selected";
			            }
			            elseif($slType=="DESC")
			            {
			                $slType2 = "selected";
			            }
			            
			        }
			    ?>
				<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="TxnType" id="Diff">
		                    <option <?php echo $TxnType1; ?>>ALL</option>
		                    <option <?php echo $TxnType2; ?>>CREDIT</option>
		                    <option <?php echo $TxnType3; ?>>DEBIT</option>
		                </select>
		                <select name="slType" id="Diff">
		                    <option <?php echo $slType2; ?> >DESC</option>
		                    <option <?php echo $slType1; ?> >ASC</option>
		                </select>
						<input type="submit" name="submit" value="Submit"  onclick='showLoader()'>
					</div>
				</form>
				<div class="div2">
					<table cellpadding="20" border="2"> 
						<tr>
							<th>Id</th>
							<th>Date Time</th>
							<th>Bank Details</th>
							<th>Op Bal</th>
							<th>Txn</th>
							<th>Cl. Bal</th>
							<th>Txn Id</th>
							<th>Txn Type</th>
							<th>Txn With</th>
							<th>Bank Ref.</th>
							<th>Remarks.</th>
						</tr>
						<?PHP
			                $sl          = 0;
			                $TotalDebit  = 0;
							$TotalCredit = 0;
							
						    $data1   = "w.Id, w.Date, w.Time, w.OpBal, w.Txn, w.ClBal, w.TxnId, w.TxnType, w.TxnWith, w.BankRefNo, w.Remarks,";
						    $data2   = "b.BankName, b.AccName";
						    $LJbwNb  = "LEFT JOIN bank AS b ON w.BankId=b.Id";
						    $where1  = "BankId='$BankId'";
						    $where2  = "";
						    $where3  = "";
						    $orderBy = "";
							if(isset($_POST['submit']))
							{
								$fdate   = $_POST['fdate'];
								$ldate   = $_POST['ldate'];
								$TxnType = $_POST['TxnType'];
								$slType  = $_POST['slType'];
								
								$BankId  = $_GET['BankId'];
								$where2  = "AND Date>='$fdate' AND Date<='$ldate'";
								if($TxnType=="CREDIT")
								{
							        $where3 = "AND Txn>0";
								}
								elseif($TxnType=="DEBIT")
								{
								    $where3 = "AND Txn<0";
								}
								
								$orderBy = "ORDER BY Id $slType";
							}
							else
							{
							    $orderBy = "ORDER BY Id DESC LIMIT 25";
							}
						    $quPayment = "SELECT $data1 $data2 FROM bank_wallet AS w $LJbwNb WHERE $where1 $where2 $where3 $orderBy";
							$rePayment = mysqli_query($con,$quPayment);
							while($dataPayment=mysqli_fetch_array($rePayment))
							{
							    $sl=$sl+1;
							    $Id        = $dataPayment[0];
							    $Date      = $dataPayment[1];
							    $Time      = $dataPayment[2];
							    $OpBal     = $dataPayment[3];
							    $Txn       = $dataPayment[4];
							    $ClBal     = $dataPayment[5];
							    $TxnId     = $dataPayment[6];
							    $TxnType   = $dataPayment[7];
							    $TxnWith   = $dataPayment[8];
							    $BankRefNo = $dataPayment[9];
							    $Remarks   = $dataPayment[10];
							    $BankName  = $dataPayment[11];
							    $AccName   = $dataPayment[12];
							    if($Txn<0)
								{
									$color = "red";
									$TotalDebit = $TotalDebit+abs($Txn);
								}
								else
								{
									$color = "green";
									$TotalCredit = $TotalCredit+$Txn;
								}
						        echo"<tr>";
								    echo "<td>".$Id."</td>";
					    			echo "<td>".$Date."<br>".$Time."</td>";
					    			echo "<td>".$BankName."<br>".$AccName."</td>";
					    			echo "<td>".$OpBal."</td>";
						    		echo "<td><p id='".$color."'>".$Txn."</p></td>";
						    		echo "<td>".$ClBal."</td>";
							    	echo "<td>".$TxnId."</td>";
							    	echo "<td>".$TxnType."</td>";
							    	echo "<td>".$TxnWith."</td>";
							    	echo "<td>".$BankRefNo."</td>";
							    	echo "<td>".$Remarks."</td>";
							    echo"</tr>";
							    
							    
								
							}
							
					        $totalTxn = $TotalCredit - $TotalDebit;
							echo "<tr>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th style='background:green; color:white'>".$TotalCredit."</th>";
							    echo "<th>".$totalTxn."</th>";
							    echo "<th style='background:red; color:white'>".$TotalDebit."</th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							    echo "<th></th>";
							echo "</tr>";
						?>
					</table>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>