<?php
	include'session.php';
	include'connection.php';
	include'../Retailers/functions.php';
?>
<html>
<head>
	<title>Payment Settle List</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:98%;
			margin:1%;
			padding:10px;
		}
		.div1 input, .div1 select{
			height:30px;
			width:180px;
			font-size:16px;
			padding:2px 7px;
			border-radius:5px;
			border:solid #6b5127 1px;
			overflow:hidden;
			margin:10px 10px 0 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%;
			float:left;
			text-align:center;
			padding:0 10px 10px 10px;
			overflow-x:auto;
		}
		.div2 table{
			width:96%;
			text-align:center;
			font-size:15px;
			border-collapse:collapse;
			padding:2px 10px;
			margin:2%;
		}
		table th{
			background:#6b5127;
			color:white;
			height:40px;
			border:solid white 1px;
			padding:2px 5px;
		}
		table td{
			background:white;
			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, .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">
			<div class="head">
				<div class="title"><p>Payment Settle List :-</p></div>
				<div class="msg"><marquee><?php include'msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
				<div class="div2">
					<table cellpadding="20" border="2"> 
						<tr>
				            <th>Sl. No.</th>
				            <th>Request Id</th>
				            <th>Req. Type</th>
				            <th>User Name</th>
				            <th>Payment Date</th>
				            <th>Amount</th>
				            <th>Remarks</th>
				            <th>Status</th>
				            <th>Action</th>
						</tr>
						<?PHP
							$sl=0;
			
			                $query="SELECT * FROM paymentreq WHERE Active=1 AND SettleStatus='PENDING' ORDER BY Id DESC";
			                $result=mysqli_query($con,$query);
	                        $RowCount=mysqli_num_rows($result);
	        
		            		if($RowCount<1)
				            {
				                echo "<tr><td colspan='12' id='tdErr'><h3 id='errMsg'>Pending Payment Request Not Found !</h3></td></tr>";
				            }
			                while($row=mysqli_fetch_array($result))
			                {
			                    $ClintId=$row['Userid'];
			                    $PayDate=$row['Paymentdate'];
			                    $Amt=$row['Amount'];
			                    $TrxnNo=$row['Txnnumber'];
			                    $RowId=$row['Id'];
				                $sl=$sl+1;
				
				                if($row['SettleStatus']=="SETTELED")
				                {
				                    $TdColor="green";
				                }
				                elseif($row['SettleStatus']=="PENDING")
				                {
				                    $TdColor="blue";
				                }
				                else
				                {
				                    $TdColor="red"; 
				                }
				                $subClintId=substr($ClintId,"0","2");
				                if($subClintId==50)
				                {
				                    $GetClintName="select * from retailer where Userid='$ClintId'";
				                }
				                elseif($subClintId==20)
				                {
				                    $GetClintName="select * from distributer where Userid='$ClintId'";
				                }
				                else
				                {
				                    $GetClintName="select * from masterdis where Userid='$ClintId'";
				                }
				
				                $reClintName=mysqli_query($con,$GetClintName);
				                $dataClintName=mysqli_fetch_array($reClintName);
				                $ClintName=$dataClintName['Name'];
				                echo "<tr>";
					                echo "<td id='mid'>".$sl."</td>";
					                echo "<td id='mid'>".$row['Id']."</td>";
					                echo "<td id='mid'>".$row['reqType']."</td>";
					                echo "<td id='mid'>".$ClintName." [".$row['Userid']."]</td>";
					                echo "<td>".$row['Paymentdate']."</td>";
					                echo "<td>".$row['Amount']."</td>";
					                echo "<td>".$row['Remarks']."</td>";
					                echo "<td ><p id='$TdColor'>".$row['SettleStatus']."</p></td>";
					                echo "<td>";
					                    if(!empty($RowId) || !empty($ClintId) || !empty($PayDate) || !empty($Amt) || !empty($TrxnNo))
					                    {
						                    echo "<a href='Payment_Settle.php?id=".$row['Id']."'>Settel</a> ";
					                    }
    					            echo"</td>";
				                echo "</tr>";
				
			                }
						?>
					</table>
				</div>
				<div class="div2">
					<table cellpadding="20" border="2"> 
						<tr>
				            <th>Sl. No.</th>
				            <th>Request Id</th>
				            <th>Req. Type</th>
				            <th>Date</th>
				            <th>Time</th>
				            <th>User Name</th>
				            <th>Amount</th>
				            <th>Response Message</th>
				            <th>Sett. Status</th>
						</tr>
						<?PHP
							$sl=0;
			
			                $query="SELECT * FROM paymentreq WHERE Active=1 AND SettleStatus!='PENDING' AND Date='$date' ORDER BY Id DESC";
			                $result=mysqli_query($con,$query);
	                        $RowCount=mysqli_num_rows($result);
	        
		            		if($RowCount<1)
				            {
				                echo "<tr><td colspan='12' id='tdErr'><h3 id='errMsg'>Todays's Payment Request History Not Found !</h3></td></tr>";
				            }
	
			                while($row=mysqli_fetch_array($result))
			                {
			                    $ClintId=$row['Userid'];
			                    $PayDate=$row['Paymentdate'];
			                    $Amt=$row['Amount'];
			                    $TrxnNo=$row['Txnnumber'];
			                    $RowId=$row['Id'];
				                $sl=$sl+1;
				                if($row['SettleStatus']=="SETTELED")
				                {
				                    $TdColor="green";
				                }
			                	elseif($row['SettleStatus']=="PENDING")
				                {
				                    $TdColor="blue";
				                }
				                else
				                {
				                    $TdColor="red"; 
				                }
				                $subClintId=substr($ClintId,"0","2");
				                if($subClintId==50)
				                {
				                    $GetClintName="select * from retailer where Userid='$ClintId'";
				                }
				                elseif($subClintId==20)
			                	{
				                    $GetClintName="select * from distributer where Userid='$ClintId'";
				                }
				                else
				                {
				                    $GetClintName="select * from masterdis where Userid='$ClintId'";
				                }
				
			                	$reClintName=mysqli_query($con,$GetClintName);
				                $dataClintName=mysqli_fetch_array($reClintName);
				                $ClintName=$dataClintName['Name'];
				                echo "<tr>";
					                echo "<td id='mid'>".$sl."</td>";
					                echo "<td id='mid'>".$row['Id']."</td>";
					                echo "<td id='mid'>".$row['reqType']."</td>";
					                echo "<td>".$row['Date']."</td>";
					                echo "<td>".$row['Time']."</td>";
					                echo "<td id='mid'>".$ClintName." [".$row['Userid']."]</td>";
					                echo "<td>".$row['Amount']."</td>";
					                echo "<td>".$row['Responsemsg']."</td>";
					                echo "<td ><p id='$TdColor'>".$row['SettleStatus']."</p></td>";
					
				                	if($row['SettleStatus']=="SETTELED")
					                {
				                        $TotalAmount=$TotalAmount+$row['Amount'];
					                }
			                }
			                echo "<tr>";
		    	                echo "<th></th>";
		    	                echo "<th></th>";
		    	                echo "<th></th>";
		    	                echo "<th></th>";
		    	                echo "<th></th>";
		    	                echo "<th>Total</th>";
		                    	echo "<th>".$TotalAmount."</th>";
		    	                echo "<th></th>";
		    	                echo "<th></th>";
			                echo "</tr>";
			
						?>
					</table>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>