<script type="text/javascript">

$(document).ready( function () {
    $('#dataTable').DataTable();
} );

$(document).ready(function () {
    $('#example').DataTable();
});
</script>
<?php 
$reportTypeShow = "";
if($_SESSION["bill_types_id"] == 1){
	$reportTypeShow = "Rental";
}
if($_SESSION["bill_types_id"] == 2){
	$reportTypeShow = "Water";
}


?>
<div class="col col-md-12">
<div class="card shadow mb-4">
	<div class="card-header py-3">
		<h6 class="m-0 font-weight-bold text-primary"><?php echo $reportTypeShow; ?></h6>
	</div>
	<div class="card-body card-block">
		<div class="table-report-scroll-x my-report-scrollbar">
			<table class="table table-bordered table-hover table-sm" id="dataTable" width="70%" cellspacing="0" style="font-size: 12px">
				<tr>
					<td align="center" ><b>#</b></td>
					<td align="center" ><b>NAMA PENYEWA</b></td>
					<td align="center" ><b>UNIT</b></td>
					<td align="center" ><b>INVOICE NO</b></td>
					<td align="center" ><b>MONTH/YEAR</b></td>
					<td align="center" ><b>AMOUNT DUE (RM)</b></td>
					<td align="center" ><b>PAYMENT STATUS</b></td>
					<td align="center" ><b>DATE CREATED</b></td>
				</tr>
				<?php 
				$no=1;
				$totalAmountDue = 0.00;
				while($resultNotPaidList = mysqli_fetch_array($runNotPaidList)){
					$tenant_id = $resultNotPaidList["tenant_id"];
					$tenant_name = $resultNotPaidList["tenant_name"];
					$unit_no = $resultNotPaidList["unit_no"];
					$bill_no = $resultNotPaidList["bill_no"];
					$amount_due = $resultNotPaidList["amount_due"];
					$issue_date = $resultNotPaidList["issue_date"];
					$payment_status = $resultNotPaidList["payment_status"];
					$created_at = $resultNotPaidList["created_at"];
					$bill_id = $resultNotPaidList["bill_id"];
					
					$totalAmountDue += $amount_due;
					
				?>
				<tr>
					<td align="center"><?php echo $no; ?></td>
					<td align="left"><a href="viewTenantDashboard.php?tenant_id=<?php echo $tenant_id?>"><?php echo strtoupper($tenant_name); ?></a></td>
					<td align="center"><?php echo $unit_no; ?></td>
					<td align="center"><a href="invoice/print.php?report_type=<?php echo $report_type?>&tenant_id=<?php echo $tenant_id?>&id=<?php echo $bill_id?>"><?php echo $bill_no; ?></a></td>
					<td align="center"><?php echo date("M Y",strtotime($issue_date)); ?></td>
					<td align="right"><?php echo number_format($amount_due,2,".",","); ?></td>
					<td align="center"><?php echo $payment_status; ?></td>
					<td align="center"><?php echo date("d/m/Y",strtotime($created_at)); ?></td>
				</tr>
				
				<?php
				$no++;
				}
				
				?>
				<tr>
					<td COLSPAN=5><B>TOTAL (RM)</B></td>
					<td align="right"><B><?php echo number_format($totalAmountDue,2,".",","); ?></B></td>
				</tr>
			</table>	
		</div>
	</div>
</div>
</div>