<?php
	session_start();
	if($_SESSION['kbuid'])
	{
		$userid= $_SESSION['kbuid'];
	}
	else
	{
		header('location:../login.php');
	}
?>
<?php
	include'connection.php';
?>
<html>
<head>
	<title>Income Report</title>
	<!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	
	<!-- Admin CSS File Link -->
	<link rel="stylesheet" href="css/style.css">
	
	<!-- 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,.div1 button{
			height:35px;
			width:auto;
			font-size:18px;
			padding:2px 10px;
			border-radius:5px;
			border:solid green 1px;
			overflow:hidden;
			margin:10px 10px 0 10px;
		}
		input[type=submit]{
			background:green;
			color:white;
			transition:1s;
		}
		input[type=submit]:hover{
			background:white;
			color:green;
			transition:1s;
		}
		.div2{
			background:#f7f7f7;
			width:100%;
			float:left;
			text-align:center;
			padding:0 10px;
			overflow:auto;
		}
		.div2 table{
			width:100%;
			text-align:center;
			font-size:16px;
			border-collapse:collapse;
			padding:2px 10px;
		}
		table th{
			background:green;
			color:white;
			height:40px;
			border:solid white 1px;
			padding:2px 5px;
		}
		table td{
			background:white;
			color:green;
			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{
				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>Income Report :-</p></div>
				<div class="msg"><marquee>This Is Test Message</marquee></msg>
			</div><hr>
			<div class="data-content">
				<form method="post">
					<div class="div1">
				<center><h4 style="color:blue;">Redeem Amount Must Be 100 or Above !</h4></center>
						
						<input type="date" name="fdate" value="<?php echo $date; ?>">
						<input type="date" name="ldate" value="<?php echo $date; ?>">
						<select name="txnType">
							<option>All</option>
							<option>Sponser</option>
							<option>Level 1</option>
							<option>Level 2</option>
							<option>Level 3</option>
							<option>Level 4</option>
							<option>Level 5</option>
							<option>Level 6</option>
							<option>Level 7</option>
							<option>Level 8</option>
							<option>Level 9</option>
							<option>Level 10</option>
						</select>
						<select name="wallet">
							<option>Main Wallet</option>
							<option>Recharge Wallet</option>
						</select>
						<input type="submit" name="submit" value="Submit" >
					</div>
				</form>
				<div class="div2">
					<table cellpadding="20" border="2"> 
						<tr>
							<th>From</th>
							<th>To</th>
							<th>Income Type</th>
							<th>Income</th>
							<th>To Wallet</th>
							<th>Action</th>
						</tr>
						<?php
							
							if(isset($_GET['status']))
							{
								echo "<div id='msgDiv'>
								<div class='msg-div'>
									<form method='post'>
									<h3>Income Redeem Successfully !</h3><br>
									<i class='fa fa-check-circle' aria-hidden='true' id='okIcon'></i><br><br>
									<a href='income_redeem.php'>OK</a><br><br>
									</form>
								</div></div>";
							}
							if(isset($_POST['submit']))
							{
								$fdate = $_POST['fdate'];
								$ldate = $_POST['ldate'];
								$txnType = $_POST['txnType'];
								$wallet = $_POST['wallet'];
								
								if($txnType=="All"){
									$quLedger="SELECT * FROM income WHERE Userid='$userid' AND Date>='$fdate' AND Date<='$ldate' AND Status='0'";
								}else{
									$quLedger="SELECT * FROM income WHERE Userid='$userid' AND Date>='$fdate' AND Date<='$ldate' AND TxnType='$txnType' AND Status='0'";
								}
								$reLedger=mysqli_query($con,$quLedger);
								$totalTxn=0;
								while($dataLedger=mysqli_fetch_array($reLedger))
								{
									$totalTxn=$totalTxn+$dataLedger['Txn'];
								}
									echo "<tr>";
										echo "<td>".$fdate."</td>";
										echo "<td>".$ldate."</td>";
										echo "<td>".$txnType."</td>";
										echo "<td><i class='fa fa-inr'></i> ".$totalTxn."</td>";
										echo "<td>".$wallet."</td>";
										echo "<td>";
										if($totalTxn>100)
										{
											echo "<a href='redeem.php?userid=".$userid."&fdate=".$fdate."&ldate=".$ldate."&txnType=".$txnType."&wallet=".$wallet."'>Redeem Now <i class='fa fa-arrow-right'></i></a>";
										}
										echo "</td>";
									echo "</tr>";
								
							}
						?>
					</table>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>