<?php 

    include "top.php";
    $arid=$_POST['logusers'];
    $cstat=$_POST['paytype'];
    $yrs=$_POST['yrs'];
    $mnth=$_POST['mnth'];

    if($arid==''){

        $title=" ".$mnth." , ".$yrs;
        $excelname=trim($mnth."-".$yrs);

    }else{

      //  echo "SELECT * FROM `tbl_area` WHERE arid='$arid'";

        $sqlll=f(q("SELECT * FROM `tbl_area` WHERE arid='$arid'"));
        $title="".$sqlll['arname'].", ".$mnth." , ".$yrs;
        $excelname=trim($sqlll['arname']."-".$mnth."-".$yrs);


    }
    $getcom=f(q("SELECT * FROM tbl_company WHERE c_id=5"));
    header('Pragma: anytextexeptno-cache', true);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
    header("Content-type: application/vnd.ms-excel");
    header("Content-Disposition: attachment; filename=".$excelname.".xls");
    header("Content-Transfer-Encoding: BINARY");

?>
<style>
    table{

        width:40%;
    }
    tr{

        width:100%;
    }
    td{

        border:1px solid gray;
    }
</style>
<center><h3><?php echo $getcom['c_name']?></h3><h6><?php echo $getcom['c_address']?></h6></center>
<center><h3><?php echo $title?></h3></center>

<table class="stripe hover multiple-select-row data-table-export nowrap">
         <thead>
            <tr>
               <th class="table-plus datatable-nosort">Sl. No</th>
               <th>NAME</th>
               
              
               <th  style="50px;">HNO</th>
               <th>AREA</th>
               <th>DUE</th>
               <th>CDATE</th>
               <th>MONTH</th>
               <th>REMARKS</th>
               
            </tr>
         </thead>
         <tbody>
            <?  
                if($arid==''){

                    $sqll="SELECT * FROM `adduser` WHERE is_cable='1' AND actv='1'";
                    
                   // $sql=mysqli_query($con,"SELECT * FROM `adduser` WHERE is_cable='$customer' AND actv='$paytype'");

                }else{
                    $sqll="SELECT * FROM `adduser` WHERE is_cable='1' AND actv='1' AND area_id='$arid'";
                   
                }
               // echo $sqll;
                $sql=mysqli_query($con,$sqll);

               while($row=mysqli_fetch_array($sql)){$c++;
               
					  
                        $getco=f(q("SELECT * FROM tbl_company WHERE c_id='$row[com_id]'"));
                        $coname=$getc['c_name'];
                        $getbill=f(q("SELECT * FROM cbill WHERE bl_cid='$row[id]' ORDER BY blid DESC LIMIT 1"));
                        $areaname=f(q("SELECT * FROM `tbl_area` WHERE arid='$row[area_id]'"));
               ?>
            <tr>
               <td class="table-plus"><?=$c?></td>
               <td><?=$row['name']?></td>
               <td><?php echo $row['houseno']?>-</td>
               <td><?=$areaname['arname']?></td>
               <td><?php echo $getbill['bl_amt']?></td>
               <td></td>
               <td></td>
               <td></td>
               
            </tr>
            <?} ?>	
         
         </tbody>
      </table>

      