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

               if($hichki=='0'){

                  $lname="";
               }else{

                  $lname=$getl['l_name'];
               }

         ?>
      <title>Payment/Due Report from <?=$stdt?> to <?=$enddt?> <?php echo $lname?></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: 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>Payment/Due 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>Lineman</th>
               <th>Customer Id</th>
               <th>Customer Name</th>
               <th>Area</th>
               <th>Phone</th>
               <th>Address</th>
               <th>Mode</th>
               <th>Pay Date</th>
               <th>Total(in Rs.)</th>
               <th>Paid(in Rs.)</th>
               <th>Due(in Rs.)</th>
            </tr>
         </thead>
         <tbody>
            <?
               


               if($hichki=='0'){
                  if($paytype=='0'){

                     $sqlstring="SELECT * FROM `cbill` a, tbl_billpay b WHERE a.blid=b.pay_bill AND b.pay_date 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` a, tbl_billpay b WHERE a.blid=b.pay_bill AND a.bl_paymd='$paytype' AND b.pay_date BETWEEN '$stdt' AND '$enddt'";
                     $paystring="SELECT SUM(a.bl_amt) as totalbl, SUM(a.bl_due) as totaldue  FROM `cbill` a WHERE a.bl_paymd='$paytype' AND a.bl_paydt BETWEEN '$stdt' AND '$enddt'";   
                  }
                

                }else{

                  if($paytype=='0'){

                     $sqlstring="SELECT * FROM `cbill` a, tbl_billpay b WHERE a.blid=b.pay_bill AND a.bl_line='$area' AND  b.pay_date BETWEEN '$stdt' AND '$enddt'";
                     $paystring="SELECT SUM(a.bl_amt) as totalbl, SUM(a.bl_due) as totaldue  FROM `cbill` a WHERE a.bl_line='$area' AND a.bl_paydt BETWEEN '$stdt' AND '$enddt'";   
                  }else{

                     $sqlstring="SELECT * FROM `cbill` a, tbl_billpay b WHERE a.blid=b.pay_bill AND a.bl_paymd='$paytype' AND
                      a.bl_line='$area' AND  b.pay_date BETWEEN '$stdt' AND '$enddt'";
                      $paystring="SELECT SUM(a.bl_amt) as totalbl, SUM(a.bl_due) as totaldue FROM `cbill` a WHERE a.bl_paymd='$paytype' AND a.bl_line='$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]'";
                  
                  //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]'")); 

                   $linemanq=f(q("SELECT * FROM tbl_login WHERE l_id='$arrc[bl_line]' AND l_type=2"));

                   
               ?>



            <tr style="border-bottom: 1px solid gray;">
               <td class="table-plus" style="text-align: center;"><?=$c?></td>
               <td><?=$linemanq['l_name']?></td>
               <td><?=$row['custid']?></td>
               <td><?=$row['name']?></td>
               <td><?=$getarea['arname']?></td>
               <td><?=$row['phone']?></td>
               <td><?=$row['address']?></td>
               <td><?=$arrc['pay_by']?></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></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>

