<?php include('session.php'); ?>
<!DOCTYPE html>
<html lang="en">
  <head>
	<title>ECIMS ADMIN | COMPLAINTS SUMMARY REGISTER</title>
    <?php include('includes/head.php'); ?>
    <style>
        th,td { text-align:center; }
        input, select {height:32px;}
    </style>
  </head>
  <body>
    <div class="container-scroller">
      <div class="horizontal-menu">
        <?php include('includes/header.php'); ?>
      </div>
      <div class="container-fluid page-body-wrapper">
        <div class="main-panel">
          <div class="content-wrapper">
            <div class="card grid-margin">
              <div class="card-body">
                <div class="row">
                  <div class="col-12">
                    <form class="forms-sample grid-margin" method="POST" id="Filterform">
                        <div class="row">
                          <div class="col-lg-4">
                            <label for="Complno">From Date</label>
                            <input type="DATE" class="form-control" required value="<?php if(isset($_POST['fromdate'])) {  if($_POST['fromdate'] != '') {echo $_POST['fromdate'];} } ?>" name="fromdate">
                          </div>
                          <div class="col-lg-4">
                            <label for="Complno">To Date</label>
                            <input type="DATE" class="form-control" required value="<?php if(isset($_POST['todate'])) {  if($_POST['todate'] != '') {echo $_POST['todate'];} } ?>" name="todate">
                          </div>
                          <div class="col-lg-4 pt-3">
                          <button type="submit" name="submit" class="btn btn-sm btn-primary me-2">SUBMIT</button>
                          <button class="btn btn-sm btn-light" type="button" id="resetbtn">RESET</button>
                          </div>
                        </div>
                    </form>
                    <?php if(isset($_POST['submit'])) { ?>
                    <hr>
                      <?php if($_SESSION['admintype'] == 'admin') { ?>
                        <a class="btn btn-success" href="register-complaint.php?fromdate=<?php echo $_POST['fromdate'] ?>&todate=<?php echo $_POST['todate'] ?>">Download PDF</a>
                        <?php } else { ?> 
                        <a class="btn btn-success" href="registerComplaint.php?fromdate=<?php echo $_POST['fromdate'] ?>&todate=<?php echo $_POST['todate'] ?>">Download PDF</a>
                        <?php } ?>
                        <a class="btn btn-warning dataExport" data-type="excel">Export Excel</a>
                    <h1 style="font-size:50px;color:#0142e4;"><center>Complaints Summary Register</center></h1>
                      <table class="table" id="dataTable">
                        <thead>
                          <tr>
                            <th style="text-align:center">SR. No.</th>
                            <th style="text-align:center">Date</th>
                            <th style="text-align:center"></th>
                            <th style="text-align:center"></th>
                            <th style="text-align:center">Complaints Received</th>
                            <th style="text-align:center"></th>
                            <th style="text-align:center"></th>
                            <th style="text-align:center"></th>
                            <th style="text-align:center">Complaints Attended</th>
                            <th style="text-align:center"></th>
                            <th style="text-align:center"></th>
                            <th style="text-align:center"></th>
                            <th style="text-align:center">Complaints Un-Attended</th>
                            <th style="text-align:center"></th>
                            <th style="text-align:center">% <br> Attended</th>
                            <th style="text-align:center">Remarks</th>
                          </tr>
                          <tr>
                            <th style="text-align:center"></th>
                            <th style="text-align:center"></th>
                            <th style="text-align:center">I</th>
                            <th style="text-align:center">II</th>
                            <th style="text-align:center">III</th>
                            <th style="text-align:center">TOTAL</th>
                            <th style="text-align:center">I</th>
                            <th style="text-align:center">II</th>
                            <th style="text-align:center">III</th>
                            <th style="text-align:center">TOTAL</th>
                            <th style="text-align:center">I</th>
                            <th style="text-align:center">II</th>
                            <th style="text-align:center">III</th>
                            <th style="text-align:center">TOTAL</th>
                            <th style="text-align:center"></th>
                            <th style="text-align:center"></th>
                          </tr>
                        </thead>
                        <tbody>
                            <?php
                        $start_time = strtotime($_POST['fromdate']);
                        $end_time = strtotime($_POST['todate']);$COUNT=0;
                        for($i=$start_time; $i<=$end_time; $i+=86400){
                            $dateeee = date('d/m/Y', $i);
                            $dateeee1 = date('d M-Y', $i);
                            if($_SESSION['admintype'] == 'admin') {
                            $countcomp = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."'")->num_rows; 
                            if($countcomp > 0) { $COUNT++;
                            $comprec1 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '1')")->num_rows; 
                            $comprec2 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '2')")->num_rows; 
                            $comprec3 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '3')")->num_rows; 
                            $comprecT = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."'")->num_rows; 
                            $compattend1 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND c_status='2' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '1')")->num_rows; 
                            $compattend2 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND c_status='2' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '2')")->num_rows; 
                            $compattend3 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND c_status='2' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '3')")->num_rows; 
                            $compattendT = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND c_status='2'")->num_rows; 
                            $compunatt1 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND c_status='0' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '1')")->num_rows; 
                            $compunatt2 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND c_status='0' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '2')")->num_rows; 
                            $compunatt3 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND c_status='0' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '3')")->num_rows; 
                            $compunattT = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND c_status='0'")->num_rows; 
                            $perattn = $compattendT * 100 / $comprecT;
                           
                            $users_complaint = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."'")->fetch_assoc(); 
                            echo '<tr>
                                <td style="text-align:center">'.$COUNT.'</td>
                                <td style="text-align:center">'.$dateeee1.'</td>
                                <td style="text-align:center">'.$comprec1.'</td>
                                <td style="text-align:center">'.$comprec2.'</td>
                                <td style="text-align:center">'.$comprec3.'</td>
                                <td style="text-align:center">'.$comprecT.'</td>
                                <td style="text-align:center">'.$compattend1.'</td>
                                <td style="text-align:center">'.$compattend2.'</td>
                                <td style="text-align:center">'.$compattend3.'</td>
                                <td style="text-align:center">'.$compattendT.'</td>
                                <td style="text-align:center">'.$compunatt1.'</td>
                                <td style="text-align:center">'.$compunatt2.'</td>
                                <td style="text-align:center">'.$compunatt3.'</td>
                                <td style="text-align:center">'.$compunattT.'</td>
                                <td style="text-align:center">'.number_format($perattn,2).'%</td>
                                <td style="text-align:center"></td>
                              </tr>';
                           } else {} } else {
                           $countcomp = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND department='".$_SESSION['admin']."'")->num_rows; 
                            if($countcomp > 0) {$COUNT++;
                            $comprec1 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND department='".$_SESSION['admin']."' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '1')")->num_rows; 
                            $comprec2 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND department='".$_SESSION['admin']."' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '2')")->num_rows; 
                            $comprec3 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND department='".$_SESSION['admin']."' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '3')")->num_rows; 
                            $comprecT = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND department='".$_SESSION['admin']."'")->num_rows; 
                            $compattend1 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND department='".$_SESSION['admin']."' AND c_status='2' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '1')")->num_rows; 
                            $compattend2 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND department='".$_SESSION['admin']."' AND c_status='2' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '2')")->num_rows; 
                            $compattend3 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND department='".$_SESSION['admin']."' AND c_status='2' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '3')")->num_rows; 
                            $compattendT = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND department='".$_SESSION['admin']."' AND c_status='2'")->num_rows; 
                            $compunatt1 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND department='".$_SESSION['admin']."' AND c_status='0' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '1')")->num_rows; 
                            $compunatt2 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND department='".$_SESSION['admin']."' AND c_status='0' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '2')")->num_rows; 
                            $compunatt3 = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND department='".$_SESSION['admin']."' AND c_status='0' AND c_list IN (SELECT cid FROM complaint_list WHERE priority = '3')")->num_rows; 
                            $compunattT = $conn->query("SELECT * FROM users_complaint WHERE date='".$dateeee."' AND department='".$_SESSION['admin']."' AND c_status='0'")->num_rows; 
                            echo '<tr>
                                <td style="text-align:center">'.$COUNT.'</td>
                                <td style="text-align:center">'.$dateeee1.'</td>
                                <td style="text-align:center">'.$comprec1.'</td>
                                <td style="text-align:center">'.$comprec2.'</td>
                                <td style="text-align:center">'.$comprec3.'</td>
                                <td style="text-align:center">'.$comprecT.'</td>
                                <td style="text-align:center">'.$compattend1.'</td>
                                <td style="text-align:center">'.$compattend2.'</td>
                                <td style="text-align:center">'.$compattend3.'</td>
                                <td style="text-align:center">'.$compattendT.'</td>
                                <td style="text-align:center">'.$compunatt1.'</td>
                                <td style="text-align:center">'.$compunatt2.'</td>
                                <td style="text-align:center">'.$compunatt3.'</td>
                                <td style="text-align:center">'.$compunattT.'</td>
                                <td style="text-align:center">'.number_format($perattn,2).'%</td>
                                <td style="text-align:center"></td>
                              </tr>';
                           }
                           }}  ?>
                         </tbody>
                      </table>
                    <?php } ?>
                  </div>
                </div>
              </div>
            </div>
          </div>
		  <?php include('includes/footer.php'); ?>
        </div>
      </div>
    </div>
    </div>
    <?php include('includes/foot.php'); ?>
    <script src="assets/js/tableExport.js"></script>
    <script type="text/javascript" src="assets/js/jquery.base64.js"></script>
    <script src="assets/js/export.js"></script>
    <script>
    $( document ).ready(function() {
        $('#resetbtn').click(function(){
            $('#Filterform')[0].reset();
            $('input[type="date"]').val('');
      });
    });
    $(document).ready(function() {
	$(".dataExport").click(function() {
		var exportType = $(this).data('type');		
		$('#dataTable').tableExport({
			type : exportType,			
			escape : 'false',
			ignoreColumn: []
		});		
	});
});
    </script>
  </body>
</html>