 
<table class="table table-bordered table-hover table-sm" id="dataTable" width="70%" cellspacing="0" style="font-size: 12px">
							<thead>
								<tr>
									<td ROWSPAN="4" valign="top" align="center" ><b>#</b></td>
									<td ROWSPAN="4" valign="top" align="center" ><b>NAMA PENYEWA</b></td>
									<td ROWSPAN="4" valign="top" align="center" ><b>UNIT NO</b></td>
									<td ROWSPAN="4" valign="top" align="center" ><b>RECEIPT NO</b></td>
									<td ROWSPAN="4" valign="top" align="center" ><b>DATE PAID</b></td>
								<!--	<td ROWSPAN="4" valign="top" align="center" ><b>PAYMENT INFO</b></td>-->
									<td COLSPAN="7" valign="top" align="center" ><b>RENTAL</b></td>
									<td ROWSPAN="3" COLSPAN="2" valign="top" align="center" ><b>PAYMENT INFO</b></td>
								</tr>
								<tr>
									<td ROWSPAN="2" valign="top" align="center"><b>CURRENT MONTH</b></td>
									<td COLSPAN="4"  align="center"><b>OUTSTANDING</b></td>
									<td ROWSPAN="2" COLSPAN="2"  valign="top" align="center"><b>ADVANCE</b></td>
								</tr>
								<tr>
									<td COLSPAN="2" align="center"><b>OTHER</b></td>
									<td COLSPAN="2" align="center"><b>PHSSB</b></td>
								</tr>
								<tr>
									<td align="center"><b>RM</b></td>
									<td align="center"><b>MONTH / YEAR</b></td>
									<td align="center"><b>RM</b></td>
									<td align="center"><b>MONTH / YEAR</b></td>
									<td align="center"><b>RM</b></td>
									<td align="center"><b>MONTH / YEAR</b></td>
									<td align="center"><b>RM</b></td>
									<td align="center"><b>REF_NAME</b></td>
									<td align="center"><b>REF_DATE</b></td>
								</tr>
							</thead>
								<tr>
								</tr>
							<tbody>
							<?PHP
							$no=1;
							$totalPaymentSemasa = 0.00;
							$totalPaymentTunggakanPhssb = 0.00;
							$totalPaymentTunggakanBukanPhssb = 0.00;
							$totalPaymentAdvance = 0.00;
							while($resultRental = mysqli_fetch_array($runReport)){
								 $unit_no = $resultRental["unit_no"];
								$tenant_id = $resultRental["tenant_id"];
								$bill_amount = $resultRental["bill_amount"];
								$tenant_name = $resultRental["tenant_name"];					
								$totalPaidByTenant = $resultRental["totalPaidByTenant"];
								$bill_types_id  = $resultRental["bill_type_id"];
								$created_at  = $resultRental["created_at"];
								$issue_date  = $resultRental["issue_date"];
								$amount_paid  = $resultRental["amount_paid"];
								$receipt_no  = $resultRental["receipt_no"];
								 " :: PAYMENT ID:: " .$payment_id  = $resultRental["payment_id"];
								
								//QUERY UNTUK KELUARKAN PAYMENT 
					  
								
									
									
									$payment_semasa = "";
									$monthYearTunggakanPhssb="";
									$paymentTunggakanPhssb = "";
									$monthYearAdvancePhssb="";
									$paymentAdvancePhssb = "";
									$monthYeartunggakanBukanPHSSB = "";
									$payment_tunggakanBukanPHSSB = "";
									
									include("paymentRefNoInfo.php");
									
									if($bill_types_id == 1 || $bill_types_id == 2){ //rental and water
										//compare created_at dengan issue_date untuk letak kedudukan amount_paid dalam column yg mana
										//1. column bayaran semasa
										$monthYear_created_at = date("Y-m", strtotime($created_at));
										$monthYear_issue_date = date("Y-m", strtotime($issue_date));
										//$monthYear_dateFrom = date("Y-m",strtotime($dateFrom));
										$monthYear_dateFrom = date("Y-m",strtotime($created_at));
										//2. column bayaran tunggakan tahun sebelum 
										$year_created_at = date("Y", strtotime($created_at));
										$year_issue_date = date("Y", strtotime($issue_date));
										//$year_dateFrom = date("Y",strtotime($dateFrom));
										$year_dateFrom = date("Y",strtotime($created_at));
										
										
										if($monthYear_created_at == $monthYear_issue_date){ //semasa
											$payment_semasa = $amount_paid;
											$total_bayaranBulanSemasa += $amount_paid;
											$payment_semasa = number_format($payment_semasa,2,'.',',');
											$totalPaymentSemasa +=  $amount_paid;
										}
										else if($monthYear_dateFrom > $monthYear_issue_date){ //tunggakan
											$paymentTunggakanPhssb = $amount_paid;
											$total_bayaranTunggakanPhssb += $amount_paid;
											$paymentTunggakanPhssb = number_format($paymentTunggakanPhssb,2,'.',',');
											$monthYearTunggakanPhssb = date("M/Y",strtotime($monthYear_issue_date));
											$totalPaymentTunggakanPhssb +=  $amount_paid;
										}
										else if($monthYear_dateFrom < $monthYear_issue_date){ //advance
											$paymentAdvancePhssb = $amount_paid;
											$total_bayaranAdvancePhssb += $amount_paid;
											$paymentAdvancePhssb = number_format($paymentAdvancePhssb,2,'.',',');
											$monthYearAdvancePhssb = date("M/Y",strtotime($monthYear_issue_date));
											$totalPaymentAdvance +=  $amount_paid;
										}
									}
									else{ //tunggakan selain phssb
										$payment_tunggakanBukanPHSSB = $amount_paid;
										$total_bayaranTunggakanNotPHSSB += $amount_paid;
										$payment_tunggakanBukanPHSSB = number_format($payment_tunggakanBukanPHSSB,2,'.',',');
										$monthYeartunggakanBukanPHSSB = date("M/Y",strtotime($monthYear_issue_date));
										$totalPaymentTunggakanBukanPhssb +=  $amount_paid;
									}
									?>
								<tr>
									<td><?php echo $no?></td>
									<td rowspan="<?php echo $rowspanByPayment?>"><a href="viewTenantDashboard.php?tenant_id=<?php echo $tenant_id?>"><?php echo $tenant_name?></a></td>
									<td><?php echo $unit_no?></td>
									<td><?php echo $receipt_no?></td>
									<td><?php echo date("d/m/Y",strtotime($created_at))?></td>
								<!--	<td align="right"><?php echo $paymentInfoShow?></td>-->
									<td align="right"><?php echo $payment_semasa?></td>
									<td><?php echo $monthYeartunggakanBukanPHSSB?></td>
									<td align="right"><?php echo $payment_tunggakanBukanPHSSB?></td>
									<td><?php echo $monthYearTunggakanPhssb?></td>
									<td align="right"><?php echo $paymentTunggakanPhssb?></td>
									<td><?php echo $monthYearAdvancePhssb?></td>
									<td align="right"><?php echo $paymentAdvancePhssb?></td>
									<td><?php echo $ref_name?></td>
									<td><?php echo $ref_date?></td>
								</tr>
									<?php
									$no++;
								//}
								?>
								
								
							<?PHP }?>
							<tr>
								<td colspan="5">JUMLAH (RM)</td>
								<td  align="right"><?PHP ECHO number_format($totalPaymentSemasa,2,'.',',');?></td>
								<td >&nbsp;</td>
								<td  align="right"><?PHP ECHO number_format($totalPaymentTunggakanBukanPhssb,2,'.',',');?></td>
								<td >&nbsp;</td>
								<td align="right" ><?PHP ECHO number_format($totalPaymentTunggakanPhssb,2,'.',',');?></td>
								<td >&nbsp;</td>
								<td  align="right"><?PHP ECHO number_format($totalPaymentAdvance,2,'.',',');?></td>
								<td colspan="2">&nbsp;</td>
							</tr>
							<?PHP 
								$totalAllPayment = $totalPaymentSemasa + $totalPaymentTunggakanBukanPhssb + $totalPaymentTunggakanPhssb + $totalPaymentAdvance;
							?>
							<tr>
								<td colspan="5">JUMLAH KESELURUHAN(RM)</td>
								<td colspan="7" align="center"><?PHP ECHO number_format($totalAllPayment,2,'.',',');?></td>
							</tr>
							</tbody>
						</table>