<?php include('session.php'); 
require_once 'dompdf/autoload.inc.php'; 
use Dompdf\Dompdf; 
$data='<html>
  <head>
	<title>ECIMS ADMIN | COMPLAINT SUMMARY</title>
	</head><body>
	<div style="width:80%;padding: 5px 5px 5px 0;MARGIN:0 AUTO;">
                      <h1 style="font-size:50px;color:#0142e4;"><center>Complaint Summary Register</center></h1>
                      <table border="1" width="100%"  style="border-collapse:collapse" cellpadding="5px">
                        <thead>
                          <tr>
                            <th style="text-align:center" rowspan="2">SR. No.</th>
                            <th style="text-align:center" rowspan="2">Date</th>
                            <th style="text-align:center" colspan="4">Complaints Received</th>
                            <th style="text-align:center" colspan="4">Complaints Attended</th>
                            <th style="text-align:center" colspan="4">Complaints Un-Attended</th>
                            <th style="text-align:center" rowspan="2">% <br> Attended</th>
                            <th style="text-align:center" rowspan="2">Remarks</th>
                          </tr>
                          <tr>
                            <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>
                          </tr>
                        </thead>
                        <tbody>';
                        $start_time = strtotime($_GET['fromdate']);
                        $end_time = strtotime($_GET['todate']);$COUNT=0;
                        for($i=$start_time; $i<=$end_time; $i+=86400){
                            $dateeee = date('d/m/Y', $i);
                            $dateeee1 = date('d M-Y', $i);
                            $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;
                            $data .= '<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>';
                           } } 
                         $data .= '</tbody>
                      </table>
                      </div>
  </body>
</html>';
//echo '<pre>'; print_r($data); die;
// Instantiate and use the dompdf class 
$dompdf = new Dompdf();
// Load HTML content 
$dompdf->loadHtml($data); 
$customPaper = array(0,0,983,775);$dompdf->setPaper($customPaper); 
// (Optional) Setup the paper size and orientation 
//$dompdf->setPaper('legal','landscape'); 

 
// Render the HTML as PDF 
$dompdf->render(); 
 
// Output the generated PDF to Browser 
$dompdf->stream('COMPLAINT SUMMARY');