<? include "top.php"; ?>
<!DOCTYPE html>
<html>
   <head>
      <?php include('include/head.php'); 
         $stdt=$_POST['stdt'];
         $enddt=$_POST['enddt'];
         
         $hichki=$_POST['dbarea'];
               $area=md5($_POST['dbarea']);
               
               $getl=f(q("SELECT * FROM tbl_login WHERE l_uid='$area' AND l_type=2"));

               if($hichki=='0'){

                  $lname="";
               }else{

                  $lname=$getl['l_name'];
               }
         ?>
      <title>Total Payment Report from <?=$stdt?> to <?=$enddt?></title>
      <!-- <link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/jquery.dataTables.css">
      <link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/dataTables.bootstrap4.css">
      <link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/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: 13px !important;
         padding: 5px;
         }
         td{
         font-size: 11px !important;
         padding-left: 4px;
         padding-right: 4px;
         }
         table{

            width: 100%;

         }
         tr{

            width: 100%;
         }
         thead > tr > td{
            background-color: #bad5e4;

         }

      </style>
   </head>
   <body style="background-color: white; padding: 3%;"><br><center><h4>Bill Generation Report Report from <?=$stdt?> to <?=$enddt?> <?php echo $lname?></h4></center><br>
      <table class="stripe hover multiple-select-row data-table-export nowrap">
         <thead>
            <tr>
               <th class="table-plus datatable-nosort">Sl. No</th>
               <th>Bill No</th>
               <?php if($hichki=='0'){?><th>Lineman</th><?php } ?>
               <th>Customer Id</th>
               <th>Customer Name</th>
               <th>Area</th>
               <th>Phone</th>
               <th>Address</th>
               <th>Month</th>
               <th>Bill Amt</th>
               <th>Paid</th>
               <th>Due</th>
               
            </tr>
         </thead>
         <tbody>
            <?
               


               if($hichki=='0'){
                 

                     $sqlstring="SELECT * FROM `cbill` WHERE bl_dt BETWEEN '$stdt' AND '$enddt'";
                     //$paystring="SELECT SUM(a.bl_amt) as totalbl, SUM(a.bl_due) as totaldue  FROM `cbill` a WHERE a.bl_paydt BETWEEN '$stdt' AND '$enddt'";   
                 
                

                }else{

                 

                     $sqlstring="SELECT * FROM `cbill` WHERE bl_line='$hichki' AND bl_dt BETWEEN '$stdt' AND '$enddt'";
                     //$paystring="SELECT SUM(a.bl_amt) as totalbl, SUM(a.bl_due) as totaldue  FROM `cbill` a WHERE a.bl_user='$area' AND a.bl_paydt BETWEEN '$stdt' AND '$enddt'";   
                 

                 

               }
               //echo $sqlstring;
               $query=mysqli_query($con,$sqlstring);
               while($arrc=mysqli_fetch_array($query)){
                  //echo "hello";
                  //echo "SELECT * FROM `adduser` WHERE id='$arrc[bl_cid]' AND area_id='$area'";

                 

                     $getq="SELECT * FROM `adduser` WHERE id='$arrc[bl_cid]'";
                     $getl=f(q("SELECT * FROM tbl_login WHERE l_id='$arrc[bl_line]' AND l_type=2"));
                  
                  //echo $getq;
               $row=f(q($getq));
              // echo $row['id'];
               if($row['name']!=''){
                  $c++;
                  $total=floatval($total)+floatval($arrc['bl_amt']);
                  $paid=floatval($paid)+floatval($arrc['pay_amt']);
                  $dues=floatval($dues)+floatval($arrc['bl_due']);

                   $getarea=f(q("SELECT * FROM tbl_area WHERE arid='$row[area_id]'")); 
                   
               ?>



            <tr style="border-bottom: 1px solid gray;">
               <td class="table-plus" style="text-align: center;"><?=$c?></td>
               <td><?=$arrc['bl_no']?></td>
               <?php if($hichki=='0'){?><td><?php echo $getl['l_name']?></td><?php } ?>
               <td><?=$arrc['bl_cid']?></td>
               <td><?=$row['name']?></td>
               <td><?=$getarea['arname']?></td>
               <td><?=$row['phone']?></td>
               <td><?=$row['address']?></td>
               <td><?=$arrc['bl_month']?></td>
               <td><?=$arrc['pay_date']?></td>
                <td><?=$arrc['bl_amt']?></td>
               <td><?=$arrc['pay_amt']?></td>
               <td><?=$arrc['bl_due']?></td>
            </tr>
            <?} }?>	
         </tbody>
         <?php 

               $getpay=f(q($paystring));
               $totbill=$getpay['totalbl'];
               $totdue=$getpay['totaldue'];
         
         ?>
         <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><b><?php echo $total?></b></td>
                <td><b><?=$paid?></b></td>
                 <td>
                  <b><?php echo $dues?></b>
               </td>

            </tr> 
            </tfoot>
      </table><br><br><br><br>
      <?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,
         		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>

