<?php
	session_start();
	if($_SESSION['adm'])
	{
		$userid= $_SESSION['adm'];
	}
	else
	{
		header('location:../login.php');
	}
?>
<?php
	include'connection.php';
		
		$query8="select * from wallet where Userid='$userid' order by Id desc";
		$result8=mysqli_query($con,$query8);
		$data8=mysqli_fetch_array($result8);
		$currentbal= $data8['Balance'];
	
?>
<html>
<head>
<style>
body{background:#e6d9c8; background-size:cover; background-repeat:repeat; background-repeat:repeat-x; margin:0; padding:0; width:1580px;}
.head{background:; width:1580px; height:80px; margin:0px;}
#p1{font-size:34px; float:left; Margin:10 0 0 45px; color:#996420;
	font-weight:bold;}
#p2{font-size:20px; float:left; margin:28 0 0 -8px; color:#eaa040;
	font-family:Courier;}
#p3{font-size:15px; font-family:Comic Sans MS; float:left; color:#996420;
	margin-top:48px; margin-left:-153px;}
.h2{background:white; width:400px; height:70px; margin:10 200px;}

#link0{float:right; margin:10 10 0 0px; font-size:20px; text-decoration:none; color:white; background:red; padding:5px; border-radius:4px;}
 #link1{float:right; margin:10 10 0 0px; font-size:20px; text-decoration:none; color:white; background:green; padding:5px; border-radius:4px;}
#link0:hover{ padding:5px; border-radius:4px; color:black;}

.menu{background:#996420; height:40px; width:1450px; margin-left:10px; padding:0; line-height:40px;}
.menu ul{padding:0; margin:0; position:relative; display:inline-block;}
.menu ul li{list-style:none; float:left; width:170px; line-height:40px; text-align:center; font-size:15px; margin:0; padding:0; color:white;}
.menu ul li ul {display:none;}
.menu ul li:hover{background:#d1994a; cursor:pointer;}
.menu ul li:hover ul {display:block; z-index:2;}
.menu ul li:hover ul li{background:#d1994a; border-top:solid white 0.1px;}
.menu ul li ul li:hover{background:#996420; color:white;}
.menu ul li ul li:hover a{ color:white;}
.menu ul li a{ text-decoration:none; color:white;}
 #a1{border:none; color:white;}
 .menu{letter-spacing:1px;}
#AFLI{background:white; width:200px;}
#AFLI:hover{background:#f5f5f5;}
 #inp{margin:10 0 10 20px; width:200px; height:35px; padding:3 10px; font-size:20px;}
 #srchby{margin-left:20px; font-family:calibri; font-size:22px;}
 .date{background:; margin:10 0 0 20px;}
 .rechreport{width:1560px; height:40px; background:#996420; color:white; line-height:40px; margin:0 0 0 20px;}
 .rechreport p{margin-left:20px;}
.notifi{background:#995702; width:800px; height:70px; margin:5 5 5 300px; border-radius:8px;}
.imgdiv{background:; width:60px; height:60px; float:left; margin:0 20px;}
#notifidiv{background:red; width:40px; height:40px; margin:0 0 0 30px; border-radius:50%; text-align:center; line-height:40px;
color:white; font-size:20px; z-index:4; float:left; position:absolute;}
img{width:60px; height:60px; float:left; margin:7px;}
#myInput{width:200px; height:40px; font-size:17px; margin:0 10px; border-radius:8px;}
#t1{ width:1560px; text-align:center; border-collapse:collapse; border-color:black; margin-left:20px;}
#t1 th{font-family:calibri; background:#94928f; color:white; font-size:22px;}
#t1 td{background:white; font-family:calibri; font-size:20px;}
#tda a{text-decoration:none; font-size:18px; font-family:sans-serif; color:#0b52e2;}
#rechId{text-decoration:none; background:; color:blue; font-size:18px; padding:2 5px; border-radius:4px; font-weight:bold;}
#green{color:green; font-weight:bold;}
#red{color:red; font-weight:bold;}
#blue{background:blue; color:white; font-size:18px; padding:2 5px; border-radius:4px; font-weight:bold;}
#lightPink{background:#f4cfd7;}
#pink{background:#f6f0e8;}
 .foot{float:left; margin:10 0 0 100px; width:1350px;}
 </style>
</head>
<body>
	<div class="head">
		<p id="p1">LLP</p>
		<p id="p2">Recharge</p>
		<p id="p3">The Complete Solution</p>
		<a id="link0" href="logout.php">Log Out</a>
		<p id="link1"><?php echo "Welcome $userid Admin";  ?></p>
    </div>
	<?php include 'menu.php'; ?>
	<div class="date">
	    <?php
	        date_default_timezone_set("asia/Kolkata");
			$datetime= Date("Y-m-d - h:i:s A");
			$time= Date("h:i:s A");
			$date= Date("Y-m-d");
			
	    ?>
	    <form method="post">
		    <input type="date" name="fdate" value="<?php echo $date; ?>" id="inp">
		    <input type="date" name="ldate" value="<?php echo $date; ?>" id="inp">
		    <input type="submit" name="submit" id="inp">
		</form>
	</div>
	<div class="rechreport">
		<p>Recharge History</p>
	</div>
	
	<table border="1" cellpadding="5" id="t1">
		<tr>
			<th>Sl. No.</th>
			<th>Id</th>
			<th>Date | Time</th>
			<th>Bank Name</th>
			<th>Opening Bal.</th>
			<th>Txn</th>
			<th>Closing Bal.</th>
			<th>Txn Id</th>
			<th>Disc</th>
			<th>Txn For</th>
		</tr>
		<?php
			include'connection.php';
			$BankId=$_GET['BankId'];
			
			    $quBankTxn="select * from Bank_Account_Txn where Bank_Id='$BankId'";
			    $reBankTxn=mysqli_query($con,$quBankTxn);
			    $sl=0;
			    $TotalTxn=0;
			    while($dataBankTxn=mysqli_fetch_array($reBankTxn))
			    {   
    		        $TxnId=$dataBankTxn['Id'];
			        $TotalTxn=$TotalTxn+$dataBankTxn['Txn'];
    		        $OpeningBal=$TotalTxn-$dataBankTxn['Txn'];
    		        
    		        $quUpdateBal="update Bank_Account_Txn set OpeningBal='$OpeningBal', Balance='$TotalTxn' where Id='$TxnId'";
    		        mysqli_query($con,$quUpdateBal);
    			 }
			
			$ToatlRechAmount=0;
			if(isset($_POST['submit']))
			{
			    $fdate=$_POST['fdate'];
			    $ldate=$_POST['ldate'];
			    $BankName=$_POST['BankName'];
			    
			    $quBankTxnByDate="select * from Bank_Account_Txn where Bank_Id='$BankId' and Date>='$fdate' and Date<='$ldate'";
			    $reBankTxnByDate=mysqli_query($con,$quBankTxnByDate);
			    $sl=0;
			    $TotalRechAmount=0;
			    while($dataByDate=mysqli_fetch_array($reBankTxnByDate))
			    {
			        if($dataByDate['Txn']<0)
			        {
			            $color="red";
			        }
			        else
			        {
			            $color="green";
			        }
			        $sl=$sl+1;
			        $TotalRechAmount=$TotalRechAmount+$dataByDate['Txn'];
			        
        			    	echo "<tr id='$background'>";
    		        			echo "<td>".$sl."</td>";
    		        			echo "<td>".$dataByDate['Id']."</td>";
            					echo "<td>".$dataByDate['Date']." | ".$dataByDate['Time']."</td>";
    			        		echo "<td>".$dataByDate['Bank_Name']."</td>";
    			        		echo "<td>".$dataByDate['OpeningBal']."</td>";
    				        	echo "<td id='$color'>".$dataByDate['Txn']."</td>";
    					        echo "<td>".$dataByDate['Balance']."</td>";
        					    echo "<td>".$dataByDate['Txn_Id']."</td>";
            					echo "<td>".$dataByDate['Disc']."</td>";
            					echo "<td>".$dataByDate['Txn_For']."</td>";
    			    	    echo "</tr>";
    			 }
			   echo "<tr>";
    					echo "<th></th>";
    					echo "<th></th>";
    					echo "<th>".$fdate ." To ". $ldate."</th>";
    					echo "<th>Total Value</th>";
    					echo "<th></th>";
    					echo "<th>".$TotalRechAmount."</th>";
    					echo "<th></th>";
    					echo "<th></th>";
    					echo "<th></th>";
    					echo "<th></th>";
				echo "</tr>";
			 }
    		 else
    		 {
    		    $quBankTxnByDate="select * from Bank_Account_Txn where Bank_Id='$BankId' and Date='$date'";
			    $reBankTxnByDate=mysqli_query($con,$quBankTxnByDate);
			    $sl=0;
			    $TotalRechAmount=0;
			    while($dataByDate=mysqli_fetch_array($reBankTxnByDate))
			    {
			        if($dataByDate['Txn']<0)
			        {
			            $color="red";
			        }
			        else
			        {
			            $color="green";
			        }
			        $sl=$sl+1;
			        $TotalRechAmount=$TotalRechAmount+$dataByDate['Txn'];
			        
        			    	echo "<tr id='$background'>";
    		        			echo "<td>".$sl."</td>";
    		        			echo "<td>".$dataByDate['Id']."</td>";
            					echo "<td>".$dataByDate['Date']." | ".$dataByDate['Time']."</td>";
    			        		echo "<td>".$dataByDate['Bank_Name']."</td>";
    			        		echo "<td>".$dataByDate['OpeningBal']."</td>";
    				        	echo "<td id='$color'>".$dataByDate['Txn']."</td>";
    					        echo "<td>".$dataByDate['Balance']."</td>";
        					    echo "<td>".$dataByDate['Txn_Id']."</td>";
            					echo "<td>".$dataByDate['Disc']."</td>";
            					echo "<td>".$dataByDate['Txn_For']."</td>";
    			    	    echo "</tr>";
    			 }
			   echo "<tr>";
    					echo "<th></th>";
    					echo "<th></th>";
    					echo "<th>".$date."</th>";
    					echo "<th>Total Value</th>";
    					echo "<th></th>";
    					echo "<th>".$TotalRechAmount."</th>";
    					echo "<th></th>";
    					echo "<th></th>";
    					echo "<th></th>";
    					echo "<th></th>";
				echo "</tr>";
    	 
        }
        ?>
	</table>
	<div class="foot">
		<p>Copyright &copy; 2018 Long Life Product Pvt. Ltd.</p>
	</div>
</body>
</html>