<? include "top.php"; ?>
<!DOCTYPE html>
<html>
   <head>
      <?php include('include/head.php'); 
         $stdt=$_POST['stdt'];
            $enddt=$_POST['enddt'];
            $customer=$_POST['customer'];
            $area_id=$_POST['area_id'];
            $getarea=f(q("SELECT * FROM tbl_area WHERE arid='$area_id'"));
            $areaname=$getarea['arname'];
         ?>
      <title>Area Wise Report for <?=$areaname?> from <?=$stdt?> and <?=$enddt?></title>
      <link rel="stylesheet" type="text/css" href="src/plugins/datatables/media/css/jquery.dataTables.css">
      <link rel="stylesheet" type="text/css" href="src/plugins/datatables/media/css/dataTables.bootstrap4.css">
      <link rel="stylesheet" type="text/css" href="src/plugins/datatables/media/css/responsive.dataTables.css">
      <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
      <style type="text/css">
         th{
         font-size: 12px !important;
         }
         td{
         font-size: 10px !important;
         }
      </style>
   </head>
   <body>
      <table class="stripe hover multiple-select-row data-table-export nowrap">
         <thead>
            <tr>
               <th class="table-plus datatable-nosort">Sl. No</th>
                <th>Customer Name</th>
                <th>Acno</th>
               <? if($customer=='1'){ ?>
                  <th>VC NO</th>
                  <th>STB NO</th>
               <? }else{?>
                  <th>IP</th>
                  <th>userid</th>
               <? } ?>
               <th>Email</th>
               <th>Phone</th>
               <th>Address</th>
               <th>Total(in Rs.)</th>
               <th>Paid(in Rs.)</th>
               <th>Due(in Rs.)</th>
            </tr>
         </thead>
         <tbody>
            <?
           // echo "SELECT * FROM `adduser` WHERE is_cable='1' AND area_id='$area_id'";
               $sql=mysqli_query($con,"SELECT * FROM `adduser` WHERE is_cable='1' AND area_id='$area_id'");
               while($row=mysqli_fetch_array($sql)){$c++;
               $query=mysqli_query($con,"SELECT * FROM `cbill` WHERE bl_cid=$row[id] AND bl_stdt BETWEEN '$stdt' AND '$enddt'");
               while($arrc=mysqli_fetch_array($query)){

                  $total=floatval($total)+floatval($arrc['bl_amt']);
                  $paid=floatval($paid)+floatval($arrc['bl_payamt']);
                  $dues=floatval($dues)+floatval($arrc['bl_due']);
               ?>
            <tr>
               <td class="table-plus"><?=$c?></td>
               <td><?=$row['name']?></td>
               <td><?=$row['custid']?></td>
               <td><?=$row['vc']?></td>
               <td><?=$row['stb']?></td>
               <td><?=$row['email']?></td>
               <td><?=$row['phone']?></td>
               <td><?=$row['address']?></td>
               <td><?=$arrc['bl_amt']?></td>
               <td><?=$arrc['bl_payamt']?></td>
               <td><?=$arrc['bl_due']?></td>
            </tr>
            <?}}?>
            <tfoot>
            <tr>
               <td class="table-plus"></td>
               <td></td>
               <td></td>
                <td></td>
                 <td></td>
               <td></td>
               <td></td>
               <td><b>Total</b></td>
               <td><?=$total?></td>
                <td><?=$paid?></td>
                 <td><?=$dues?></td>

            </tr> 
            </tfoot>
         </tbody>
      </table>
      <?php include('include/script.php'); ?>
      <script src="src/plugins/datatables/media/js/jquery.dataTables.min.js"></script>
      <script src="src/plugins/datatables/media/js/dataTables.bootstrap4.js"></script>
      <script src="src/plugins/datatables/media/js/dataTables.responsive.js"></script>
      <script src="src/plugins/datatables/media/js/responsive.bootstrap4.js"></script>
      <!-- buttons for Export datatable -->
      <script src="src/plugins/datatables/media/js/button/dataTables.buttons.js"></script>
      <script src="src/plugins/datatables/media/js/button/buttons.bootstrap4.js"></script>
      <script src="src/plugins/datatables/media/js/button/buttons.print.js"></script>
      <script src="src/plugins/datatables/media/js/button/buttons.html5.js"></script>
      <script src="src/plugins/datatables/media/js/button/buttons.flash.js"></script>
      <script src="src/plugins/datatables/media/js/button/pdfmake.min.js"></script>
      <script src="src/plugins/datatables/media/js/button/vfs_fonts.js"></script>
      <script>
         $('document').ready(function(){
            $('.data-table').DataTable({
               scrollCollapse: true,
               autoWidth: false,
               responsive: true,
               columnDefs: [{
                  targets: "datatable-nosort",
                  orderable: false,
               }],
               "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
               "language": {
                  "info": "_START_-_END_ of _TOTAL_ entries",
                  searchPlaceholder: "Search"
               },
            });
            $('.data-table-export').DataTable({
               scrollCollapse: true,
               autoWidth: false,
				responsive: true,
				paging: false,
				lengthchange: false,
				searching: false,
				ordering: false,
               columnDefs: [{
                  targets: "datatable-nosort",
                  orderable: false,
               }],
               "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
               "language": {
                  "info": "_START_-_END_ of _TOTAL_ entries",
                  searchPlaceholder: "Search"
               },
               dom: 'Bfrtip',
               buttons: [
               'copy', 'csv', 'pdf', 'print'
               ]
            });
            var table = $('.select-row').DataTable();
            $('.select-row tbody').on('click', 'tr', function () {
               if ($(this).hasClass('selected')) {
                  $(this).removeClass('selected');
               }
               else {
                  table.$('tr.selected').removeClass('selected');
                  $(this).addClass('selected');
               }
            });
            var multipletable = $('.multiple-select-row').DataTable();
            $('.multiple-select-row tbody').on('click', 'tr', function () {
               $(this).toggleClass('selected');
            });
         });
      </script>
      <script type="text/javascript"></script>
   </body>
</html>

