<?php
	include'session.php';
	include'../connection.php';
	include'../functions.php';
?>
<html>
<head>
	<title>Complain 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>Complain 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">
						<?PHP
								$sl=0;
								$data1 = "c.Id, c.Date, c.Time, c.Userid, c.TxnId, c.PartnerId, c.UserMsg, c.Status,";
								$data2 = "r.Mobile, r.Amount, r.Api, r.Lapu, r.OpId, r.Status, r.Date, r.OpName,";
								$data3 = "s.Name,";
								$data4 = "f.FirmName";
								
								$LJcNr  = "LEFT JOIN recharge AS r ON c.TxnId=r.Id";
								$LJcNsl = "LEFT JOIN seller_lapu AS l ON r.Lapu=l.LapuNo";
								$LJcNs  = "LEFT JOIN Seller AS s ON l.SellerId=s.Id";
								$LJcNsf = "LEFT JOIN seller_firm AS f ON l.FirmId=f.Id";
								
								$quComplain="SELECT $data1 $data2 $data3 $data4 FROM complain AS c $LJcNr $LJcNsl $LJcNs $LJcNsf WHERE c.Status='SUBMIT'";
								$reComplain=mysqli_query($con,$quComplain);
								$countComplain=mysqli_num_rows($reComplain);
								while($dataComplain=mysqli_fetch_array($reComplain))
								{
								    
								    $sl         = $sl+1;
									$compId     = $dataComplain[0];
									$Date       = $dataComplain[1];
									$Time       = $dataComplain[2];
									$Userid     = $dataComplain[3];
									$TxnId      = $dataComplain[4];
									$PartnerId  = $dataComplain[5];
									$UserMsg    = $dataComplain[6];
									$Status     = $dataComplain[7];
									
									$RechMobile = $dataComplain[8];
									$RechAmt    = $dataComplain[9];
									$RechApi    = $dataComplain[10];
									$RechLapu   = $dataComplain[11];
									$RechOpId   = $dataComplain[12];
									$RechStatus = $dataComplain[13];
									$RechDate   = $dataComplain[14];
									$OpName     = $dataComplain[15];
									
									$S_Name     = $dataComplain[16];
									$F_Name     = $dataComplain[17];
									$usrName    = getName($Userid);
									if(empty($RechOpId))
									{
									    $RechOpId = "Op Ref Id Not Available";
									}
									    echo "<tr>
							                    <th>Sl.</th>
							                    <th>Date<br>Time</th>
							                    <th>Comp.Id</th>
							                    <th>Rech.Id</th>
							                    <th>User</th>
							                    <th colspan='2'>Action</th>
						                </tr>";
									
									
									echo"<tr>";
										echo "<td>".$sl."</td>";
										echo "<td>".$Date."<br>".$Time."</td>";
										echo "<td>".$compId."</td>";
										echo "<td><a href='check_txn_status.php?rechId=".$TxnId."' target='_blank'>".$TxnId."</a></td>";
										echo "<td>".$usrName."<br>[".$Userid."]</td>";
										echo "<td><a style='color:green;' href='complain_solved.php?compId=".$compId."'>Close Complain</a></td>";
									echo"</tr>";
									echo "<tr id='DisputeDetails'>";
									    echo "<td colspan='10'>";
									        echo "<div>";
									            if(!empty($PartnerId))
									            {
									                echo "<p>Partner Id = ".$PartnerId."</p>, ";
									            }
									            echo "<p>Mobile = ".$RechMobile.", OP = ".$OpName.", Amount = ".$RechAmt.", Api = ".$RechApi.", Status = ".$RechStatus.", OpId = ".$RechOpId."</p><br>";
									            echo "<p>Lapu = <a href='recharge_by_lapu.php?lapuNo=".$RechLapu."&rechId=".$TxnId."&rechDate=".$RechDate."&OpCode=".$OpCode."' target='_blank'>".$RechLapu."</a> Seller = ".$S_Name.", Firm = ".$F_Name."</p><br>";
									            echo "<p>User Msg =   ".$UserMsg."</p><br>";
									        echo "</div>";
									    echo "</td>";
									echo "</tr>";
								}
								if($countComplain<1)
								{
								    echo "<tr><td colspan='10'><center><h3 style='color:red'>Data Not Found !</h3></center></td></tr>";
								}
								
						?>
					</table>
				</div>
				<div class="div1">
				    <?php
				            if(isset($_POST['submit']))
							{
								$fdateValue = $_POST['fdate'];
								$ldateValue = $_POST['ldate'];
							}
							else
							{
							    $fdateValue = $date;
								$ldateValue = $date;
							}
							
				    ?>
				    <form method="post">
						<input type="date" name="fdate" value="<?php echo $fdateValue; ?>">
						<input type="date" name="ldate" value="<?php echo $ldateValue; ?>">
						<select name="status">
						    <option>ALL</option>
						    <option>Pending</option>
						    <option>Reviewed</option>
						    <option>Solved</option>
						</select>
						<input type="submit" name="submit" value="Submit"  onclick='showLoader()'>
				    </form>
				
				</div>
				<div class="div2">
					<table cellpadding="20" border="2"> 
						<tr>
							<th>Comp.Id</th>
							<th>Rech.id</th>
							<th>Date<br>Time</th>
							<th>User</th>
							<th>Response Time</th>
							<th>Disc.</th>
							<th>Status</th>
						</tr>
						<?PHP
						    $runQuery=1;
							if(isset($_POST['submit']))
							{
								$fdate  = $_POST['fdate'];
								$ldate  = $_POST['ldate'];
								$status = $_POST['status'];
								
								$sl=0;
								if($status=="ALL")
								{
								    $quComplain="SELECT * FROM complain WHERE Date>='$fdate' AND Date<='$ldate'";
								}
								else
								{
								    $quComplain="SELECT * FROM complain WHERE Status='$status' AND Date>='$fdate' AND Date<='$ldate'";
								}
							}
							else
							{
							    $quComplain="SELECT * FROM complain WHERE Status!='SUBMIT' AND Date>='$date'";
							}
							if($runQuery==1)
							{
								$reComplain=mysqli_query($con,$quComplain);
								$countComplain=mysqli_num_rows($reComplain);
								while($dataComplain=mysqli_fetch_array($reComplain))
								{
									if($dataComplain['Status']=="Solved")
									{
										$color="green";
									}
									else
									{
										$color="blue";
									}
									$usrName=getName($dataComplain['Userid']);
									echo"<tr>";
										echo "<td>".$dataComplain['Id']."</td>";
										echo "<td>".$dataComplain['TxnId']."</td>";
										echo "<td>".$dataComplain['Date']."<br>".$dataComplain['Time']."</td>";
										echo "<td>".$usrName."<br>[".$dataComplain['Userid']."]</td>";
										echo "<td>".$dataComplain['R_Date']."<br>".$dataComplain['R_Time']."</td>";
										echo "<td>".$dataComplain['UserMsg']."<br><br>".$dataComplain['RespoMsg']."</td>";
										echo "<td><p id='$color'>".$dataComplain['Status']."</p></td>";
									echo"</tr>";
								}
								if($countComplain<1)
								{
								    echo "<tr><td colspan='10'><center><h3 style='color:red'>Data Not Found !</h3></center></td></tr>";
								}
							}
						?>
					</table>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>