<? include "top.php"; ?>
<!DOCTYPE html>
<html>
   <head>
      <?php include('include/head.php'); 
         $stdt=$_POST['stdt'];
         $enddt=$_POST['enddt'];
         $logusers=$_POST['custid'];
         $paytype=$_POST['paytype'];


         if($logusers=='0'){

            $comname="All Customers";
         }else{

            $getc=f(q("SELECT * FROM tbl_login WHERE user_id='$logusers'"));
            $comname=$getc['l_name'];
         }

         ?>
      <title>Payment Report for <?=$stdt?> and <?=$enddt?> for <?php echo $comname?></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: 12px !important;
         }
         td{
         font-size: 10px !important;
         border:1px solid #e2e1e1;
         }
         table{

            width: 100%;

            }
            tr{

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

            }
      </style>
   </head>
   <body style="background-color: white; padding: 3%;"><br><center><h4>Payment Report <?php if($paytype!='0'){ echo "(".$paytype.")"; }?> from <?php echo $stdt?> to <?php echo $enddt?>  for <?php echo $comname?></h4></center><br>
      <table class="stripe">
         <thead>
            <tr>
               <th class="table-plus datatable-nosort">Sl. No</th>
               
               <th>Customer Id</th>
               <th>Customer Name</th>
               <th>Phone</th>
               <th>MSO No</th>
               <th>Address</th>
               <th>Start Date</th>
               <th>End Date</th>
               <th>Bill No</th>
               <th>Current Amt</th>
               <th>Bill Amt(incl Prev Due)</th>
               <th>Paid Amt</th>
               <th>Pay Date</th>
               <!--<th>Due Amt</th>-->
            </tr>
         </thead>
         <tbody>
            <? 
            

                if($paytype=='0'){

                    $sqlq="SELECT * FROM `cbill` a,tbl_billpay b WHERE a.blid=b.pay_bill AND  a.bl_payamt>0 AND  a.bl_cid='$logusers' AND b.pay_date BETWEEN '$stdt' AND '$enddt'";

                }else{

                    $sqlq="SELECT * FROM `cbill` a,tbl_billpay b WHERE a.blid=b.pay_bill AND  b.pay_by='$paytype' AND a.bl_payamt>0 AND  a.bl_cid='$logusers' AND b.pay_date BETWEEN '$stdt' AND '$enddt'";

                }

               

            
           // echo $sqlq;
            $query=mysqli_query($con,$sqlq);
           
               
               while($arrc=mysqli_fetch_array($query)){$c++;
               $row=f(q("SELECT * FROM `adduser` WHERE id=$arrc[bl_cid]"));
               $billamt=floatval($arrc['bl_amt'])+floatval($arrc['bl_prevdue']);

               $getco=f(q("SELECT * FROM tbl_company WHERE c_id='$row[com_id]'"));
               $coname=$getc['c_name'];

               ?>
            <tr>
               <td class="table-plus"><?=$c?></td>
               
               <td><?=$row['custid']?></td>
               <td><?=$row['name']?></td>
               <td><?=$row['phone']?></td>
               <td><?=$row['msoacno']?></td>
               <td><?=$row['address']?></td>
               <td><?=$arrc['bl_stdt']?></td>
               <td><?=$arrc['bl_expiry']?></td>
               <td><?=$arrc['bl_no']?></td>
               <td><?=$arrc['bl_amt']?></td>
               <td><?php echo $billamt;?></td>
               <td><?php echo $arrc['pay_amt'];?></td>
               <td><?php echo $arrc['pay_date'];?></td>
               <!--<td><?php echo $arrc['bl_due'];?></td>-->
            </tr>
            <?}?>	
         </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,
               paging: false,
               lengthchange: false,
               searching: 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"
         		},
         	});
         	$('.data-table-export').DataTable({
         		scrollCollapse: true,
         		autoWidth: false,
         		responsive: true,
               paging: false,
				lengthchange: false,
				searching: 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>

