<? include "top.php"; ?>
<!DOCTYPE html>
<html>
   <head>
      <?php include('include/head.php'); 
        //  $stdt=$_POST['stdt'];
        //  $enddt=$_POST['enddt'];
         $customer=1;
         $name=mysqli_real_escape_string($con,$_POST['search']);
            $custid=mysqli_real_escape_string($con,$_POST['search']);
            $curdate=date("Y-m-d");


            $stdt=$_POST['stdt'];
            $enddt=$_POST['enddt'];
            $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>Due Report Report <?=$stdt?> to <?=$enddt?> <?php echo $lname?></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 src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
      
   </head>
   <body style="background-color: white; padding: 3%;">
      <div style="width:100%;padding:10px;text-align:right;">
            <!-- <a href="due_report_excel.php" class="btn btn-primary" target="_blank">Export To Excel</a>
            <button id="print" class="btn btn-primary" onclick="printContent('printoutdiv');" >Print</button> -->

      </div>


      
      <div id="printoutdiv">
         <style type="text/css">
         th{
         font-size: 13px !important;
         padding: 5px;
         }
         td{
         font-size: 12px !important;
         }
         table{

            width: 100%;

         }
         tr{

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

         }

      </style>
         <br><center><h4>Due Report Report <?=$stdt?> to <?=$enddt?> <?php echo $lname?></h4></center><br>
      <table class="stripe hover multiple-select-row data-table-export nowrap">
         <thead>
            <tr style="background-color: #bad5e4;">
               <th class="table-plus datatable-nosort">Sl. No</th>
               <th>Customer Name</th>
               <th>A/C No</th>
               <th>Address</th>
               <? if($customer=='1'){ ?>
               <th>VC NO</th>
               <th>MSO no</th>
               <? }else{?>
               <th>IP</th>
               <th>userid</th>
               <? } ?>
               <th>Bill Date</th>
               <th>Period</th>
               <th>Start Dt</th>
               <th>End Dt</th>
               <th>Bill Amt</th>
               <th>Status</th>
               <th>Paid(in Rs.)</th>
               <th>Payment Date</th>
               <th>Due(in Rs.)</th>
            </tr>
         </thead>
         <tbody>
            <?

            if($hichki=='0'){

                $sqls="SELECT * FROM adduser";
            }else{
                $sqls="SELECT * FROM adduser WHERE line_ids='$hichki'";

            }

            $getc=mysqli_query($con,$sqls);
            while($arrcust=mysqli_fetch_array($getc)){
            
            $row=mysqli_query($con,"SELECT * FROM `cbill` WHERE bl_due>0 AND bl_cid='$arrcust[id]' AND bl_dt BETWEEN '$stdt' AND '$enddt' ORDER BY blid DESC LIMIT 1");
           

               while($arrc=mysqli_fetch_array($row)){$c++;
               
               $total=floatval($total)+floatval($arrc['bl_amt']);
               $paid=floatval($paid)+floatval($arrc['bl_payamt']);
              
                $getcust=f(q("SELECT * FROM `adduser` WHERE id='$arrc[bl_cid]'"));
				$billamt=floatval($arrc['bl_amt'])+floatval($arrc['bl_prevdue']);
            $billdisc=$arrc['bl_disc'];
				$bildue=abs(round(floatval($billamt)-(floatval($arrc['bl_payamt'])+floatval($billdisc))));
            $dues=floatval($dues)+floatval($bildue);

           




               ?>
            <tr style="border-bottom: 1px solid gray;<? if($arrc['bl_stat']==0){?>background-color: #f1d4c4;<?}?>">
               <td class="table-plus" style="text-align: center;"><?=$c?></td>
               <td><?=$arrc['bl_cname']?></td>
               <td><?=$getcust['custid']?></td>
               <td><?=$getcust['address']?></td>
             
               <td><?=$getcust['vc']?></td>
               <td><?=$getcust['msoacno']?></td>
               <td><?=$arrc['bl_dt']?></td>
               <td><?=$arrc['bl_month']?>,<?=$arrc['bl_year']?></td>
               
               <td><?=$arrc['bl_stdt']?></td>
               <td><?=$arrc['bl_expiry']?></td>
               <td><?=$billamt?></td>
               <td><? if($arrc['bl_stat']==1){?>Paid<?}else{?>Unpaid<? } ?></td>
               <td><?=$arrc['bl_payamt']?></td>
               <td><?=$arrc['bl_paydt']?></td>
               <td><?=$bildue?></td>
            </tr>
            <?} }?>	
            <!-- <tfoot>
            <tr>
               <td class="table-plus"></td>
               <td></td>
               <td></td>
               <td></td>
               <td></td>
               <td></td>
               <td></td>
               
            </tr>
         </tfoot> -->
         </tbody>
      </table><br>
      <table>
            <tr>
               <td style="width: 65%;"></td>
               <td style="text-align:right;padding-right: 15px;"><b>Total Bill</b></td>
               <td>&#8377; <?=$total?></td>
              <td></td>
            </tr>
            <tr>
               <td style="width: 65%;"></td>
               <td style="text-align:right;padding-right: 15px;"><b>Total Paid Amount</b></td>
               
               <td>&#8377; <?=$paid?></td>
               <td></td>
            </tr>
            <tr>
               <td style="width: 65%;"></td>
               <td style="text-align:right;padding-right: 15px;"><b>Total Due Amount</b></td>
               
               <td>&#8377; <?=$dues?></td>
               <td></td>
            </tr>

      </table>
      <br><br>
   </div>

   <?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>
      <script>
function printContent(el){
var restorepage = $('body').html();
var printcontent = $('#' + el).clone();
$('body').empty().html(printcontent);
window.print();
$('body').html(restorepage);
}
</script>
   </body>
</html>

