<?php include "headerLink.php"?>
<!DOCTYPE html>
<html lang="en">


<body class="animsition">
    <div class="page-wrapper">
        <!-- HEADER MOBILE-->
        <?php include "menuSideBar_mobile.php" ;?>
        <!-- END HEADER MOBILE-->
		
        <!-- MENU SIDEBAR-->
        <?php include "menuSideBar.php" ;?>
        <!-- END MENU SIDEBAR-->

        <!-- PAGE CONTAINER-->
        <div class="page-container">
            <!-- HEADER DESKTOP-->
			<?php include "headerPage.php"?>
            <!-- END HEADER DESKTOP-->
			
			
			
			<!-- MAIN CONTENT-->
			<?php
			include("tenant_payment_dashboard.php");
			
			?>
			
            
            <!--main content upper start-->
			<?php include "main-content-upper.php"?>
            <!--main content upper end-->
			<!--main content middle start-->
			<div class="row" style="font:small-caption">
				
							<div class="card-body">
								<div class="row">
									
									
									
								</div>
								<div class="row">
									<div class="col col-md-6">
										<div class="card">
											<div class="card-header">
												<h5 class="m-0 font-weight-bold text-primary">
													Personal Information  
													<button type="button" class="btn btn-sm btn-primary" style="float:right">Edit</button>
												</h5>
											</div>
											<div class="card-body card-block">
												<div class="default-tab">
													<nav>
														<div class="nav nav-tabs" id="nav-tab" role="tablist">
															<a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab" aria-controls="nav-home"
															 aria-selected="true"><b>Tenant</b> </a>
															<a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab" aria-controls="nav-profile"
															 aria-selected="false"><b>Spouse</b></a>
															<a class="nav-item nav-link" id="nav-contact-tab" data-toggle="tab" href="#nav-contact" role="tab" aria-controls="nav-contact"
															 aria-selected="false"><b>Salary</b></a>
															 <a class="nav-item nav-link" id="nav-selangorku-tab" data-toggle="tab" href="#nav-selangorku" role="tab" aria-controls="nav-selangorku"
															 aria-selected="false"><b>Info Rumah SelangorKU</b></a>
															  <a class="nav-item nav-link" id="nav-harta-tab" data-toggle="tab" href="#nav-harta" role="tab" aria-controls="nav-harta"
															 aria-selected="false"><b>Holding Property Information</b></a>
															 <a class="nav-item nav-link" id="nav-kesihatan-tab" data-toggle="tab" href="#nav-kesihatan" role="tab" aria-controls="nav-kesihatan"
															 aria-selected="false"><b>Health Info</b></a>
															 <a class="nav-item nav-link" id="nav-keluarga-tab" data-toggle="tab" href="#nav-keluarga" role="tab" aria-controls="nav-keluarga"
															 aria-selected="false"><b>Tenant's Family Members</b></a>
														</div>
													</nav>
													<div class="tab-content pl-3 pt-2" id="nav-tabContent">
														<div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
															<div class="card-body card-block">
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Name</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo strtoupper($tenant_name)?></label>
																	</div>
																</div>
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Unit No</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo $unit_no?> , <?php echo $location?></label>
																	</div>
																</div>
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Project</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo $project_name?></label>
																	</div>
																</div>
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Rental Status</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo ucfirst($tenant_status_show)?></label>
																	</div>
																</div>
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">IC NO.</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo $tenant_ic?></label>
																	</div>
																</div>
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">D.O.B</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo $tenant_dob?></label>
																	</div>
																</div>
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Age</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo $tenant_age?></label>
																	</div>
																</div>
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Gender</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo ucfirst($gender)?></label>
																	</div>
																</div>
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Marital Status</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo ucfirst($marital_status)?></label>
																	</div>
																</div>
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Religion</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo ucfirst($tenant_religion)?></label>
																	</div>
																</div>
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Nationality</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo ucfirst($tenant_nationality)?></label>
																	</div>
																</div>
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Mailing Address</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo $mailing_address?></label>
																	</div>
																</div>	
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Contact No.</label>
																	</div>
																	<?php if($tenant_telNo != "" && $tenant_phoneNo != ""){?>
																	<div class="col col-md-4">
																		<label class=" form-control-label"><?php echo $tenant_telNo?></label>
																	</div>
																	<div class="col col-md-4">
																		<label class=" form-control-label"><?php echo $tenant_phoneNo?></label>
																	</div>
																	<?php } 
																	else if($tenant_telNo != "" && $tenant_phoneNo == ""){
																	?>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo $tenant_telNo?></label>
																	</div>
																	<?php } 
																	else if($tenant_telNo == "" && $tenant_phoneNo != ""){
																	?>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo $tenant_phoneNo?></label>
																	</div>
																	<?php } ?>
																</div>
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Email</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo $tenant_email?></label>
																	</div>
																</div>	
															</div>
														</div>
														<div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">
															<div class="card-body card-block">
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Name</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo strtoupper($tenant_name)?></label>
																	</div>
																</div>
															</div>
														</div>
														<div class="tab-pane fade" id="nav-contact" role="tabpanel" aria-labelledby="nav-contact-tab">
															<div class="card-body card-block">
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Name</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo strtoupper($tenant_name)?></label>
																	</div>
																</div>
															</div>
														</div>
														<div class="tab-pane fade" id="nav-selangorku" role="tabpanel" aria-labelledby="nav-selangorku-tab">
															<div class="card-body card-block">
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Name</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo strtoupper($tenant_name)?></label>
																	</div>
																</div>
															</div>
														</div>
														<div class="tab-pane fade" id="nav-harta" role="tabpanel" aria-labelledby="nav-harta-tab">
															<div class="card-body card-block">
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Name</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo strtoupper($tenant_name)?></label>
																	</div>
																</div>
															</div>
														</div>
														<div class="tab-pane fade" id="nav-kesihatan" role="tabpanel" aria-labelledby="nav-kesihatan-tab">
															<div class="card-body card-block">
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Name</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo strtoupper($tenant_name)?></label>
																	</div>
																</div>
															</div>
														</div>
														<div class="tab-pane fade" id="nav-keluarga" role="tabpanel" aria-labelledby="nav-keluarga-tab">
															<div class="card-body card-block">
																<div class="row">
																	<div class="col col-md-3">
																		<label class=" form-control-label">Name</label>
																	</div>
																	<div class="col col-md-9">
																		<label class=" form-control-label"><?php echo strtoupper($tenant_name)?></label>
																	</div>
																</div>
															</div>
														</div>
														
													</div>
												</div>												
											</div>	
										</div>												
									</div>
									<div class="col col-md-6" >
											<div class="card">
												<div class="card-header ">
													<h5 class="m-0 font-weight-bold text-primary">
														Billing Summary
														<button type="button" class="btn btn-outline-success btn-sm" style="float:right" onclick="billPayment('<?php echo $tenant_id;?>')" >Bill Payment</button>
														<button type="button" style="float:right" onclick="viewStatement('<?php echo $username;?>','<?php echo $unit?>','<?php echo $tenant_id?>')" class="btn btn-outline-primary btn-sm">View Statement</button>
													</h5>
												</div>
												<div class="card-body card-block">
													<div class="row" valign="middle">
														<div class="col col-md-6">
															<label class=" form-control-label">Deposit</label>
															<label class=" badge badge-secondary"><?php echo $depositStatus?></label>
														</div>
														<div class="col col-md-6" >
														<?php if($deposit_button == "Re-print" || $deposit_button == ""){?>
															<a href="" onclick="reprint('<?php echo $tenant_id;?>')" style="float:right" class="href"><?php echo $totalDepositShow ?></a>
														<?php } 
															else if(strstr($deposit_button,"Pay Now") !== false){?>
															 <button type="button" style="float:right" class="btn btn-outline-danger btn-sm" onclick="Javascript:newPopup('deposit_Paynow.php?tenant_id=<?php echo $tenant_id;?>','&deposit_bill_id=<?php echo $deposit_bill_id; ?>')">
																<?php echo $deposit_button?></a>
															</button> 
														<?php } else if($deposit_button == "Create Bill"){?>
															<button type="button" style="float:right" class="btn btn-outline-danger btn-sm" onclick="Javascript:newPopup('deposit_CreateBill.php?tenant_id=<?php echo $tenant_id;?>')">
																<?php echo $deposit_button ?>
															</button> 
															
														<?php } //else if($deposit_button == "Update Bill"){
															else if(strstr($deposit_button,"Update Bill") !== false){
															?>
															<button type="button" style="float:right" class="btn btn-outline-danger btn-sm" onclick="Javascript:newPopup('deposit_UpdateBill.php?tenant_id=<?php echo $tenant_id;?>')">
																<?php echo $deposit_button ?>
															</button> 
															<button type="button" style="float:right" class="btn btn-outline-danger btn-sm" onclick="Javascript:newPopup('deposit_Paynow.php?tenant_id=<?php echo $tenant_id;?>','&deposit_bill_id=<?php echo $deposit_bill_id; ?>')">
																<?php echo $deposit_button_payNow ?></a>
															</button> 
															
														<?php } ?>
															<br>
														</div>
													</div>
													<div class="row">
														<div class="col col-md-6">
															<label class=" form-control-label">Current Rental Bill <?php echo date("M Y");?></label>
															<label class=" badge badge-secondary"><?php echo ucfirst($currentRentalPaymentStatus)?></label>
														</div>
														<div class="col col-md-6" >
															<label class=" form-control-label" style="float:right"><?php echo $bill_show?></label>
														</div>
													</div>
													<div class="row">
														<div class="col col-md-6">
															<label class=" form-control-label">Total Previous Outstanding Rental</label>
														</div>
														<div class="col col-md-6" >
															<label class=" form-control-label" style="float:right"><?php echo  $Outstanding_amount?></label>
														</div>
													</div>
													<div class="row">
														<div class="col col-md-6">
															<label class=" form-control-label">Current Water Bill <?php echo date("M Y");?></label>
														</div>
														<div class="col col-md-6" >
															<label class=" form-control-label" style="float:right">-</label>
														</div>
													</div>
													<?php //if($countRowBillOutstandingOthers > 0){ ?>
													<div class="row">
														<div class="col col-md-6">
															<label class=" form-control-label"> <?php echo $others_outstanding_sentences?></label>
														</div>
														<div class="col col-md-6" >
															<label class=" form-control-label" style="float:right"><?php echo $others_outstanding?></label>
														</div>
													</div>
													<?php //} ?>
												</div>
											</div>	
											<div class="card">
												<div class="card-header ">
													<h5 class="m-0 font-weight-bold text-primary">
														Deposit Payments History
														<button type="button" style="float:right" onclick="reprint('<?php echo $tenant_id?>')" class="btn btn-outline-primary btn-sm">PRINT RECEIPT</button>
														<button type="button" style="float:right" onclick="printSummaryDeposit('<?php echo $tenant_id?>')" class="btn btn-outline-primary btn-sm">PRINT SUMMARY</button>
													</h5>
												</div>
												<?php 
												$colspanShow_header = 8;
												$colspanShow_bottom = 5;
												
													//check table deposits (penyewa lama)
													$sqlDeposit_oldRecord = "select deposits.*, users.name from deposits inner join users on deposits.created_by = users.id
																	where deposits.tenant_id = $tenant_id "; //RETURN NULL IN ROW - SHOULD CHECK THE PROBLEM
													$runDeposit_oldRecord = mysqli_query($link, $sqlDeposit_oldRecord);
													if($runDeposit_oldRecord === FALSE){
														die(mysqli_error($link));
													}
													$countRowOldRecord = mysqli_num_rows($runDeposit_oldRecord);
												
													//check table deposit_bills (penyewa baru)
													$sqlDeposit_newRecord = "select deposit_payments.*, 
																				deposit_bills.two_month_rental_amount, deposit_bills.utility_amount, users.name
																			from deposit_payments 
																			inner join deposit_bills on deposit_payments.deposit_bill_id = deposit_bills.id 
																			inner join users on deposit_payments.created_by = users.id
																			where deposit_bills.tenant_id = $tenant_id";
													$runDeposit_newRecord = mysqli_query($link, $sqlDeposit_newRecord);
													if($runDeposit_newRecord === FALSE){
														die(mysqli_error($link));
													}
													$countRowNewRecord = mysqli_num_rows($runDeposit_newRecord);
													
													
													
													$colspanShow_header = 7;
													$colspanShow_bottom = 4;
												
													//deposit_payment_other_receipts table
													 "   sqlDepositPaymentOthers: ".$sqlDepositPaymentOthers = "select deposit_payment_other_receipts.* , users.name, deposit_bill_other_receipts.stamping_charges_amount,
																													deposit_bill_other_receipts.sst_charges_amount,deposit_bill_other_receipts.yp_charges_amount 
																													from deposit_payment_other_receipts 
																													inner join deposit_bill_other_receipts on deposit_payment_other_receipts.deposit_bill_other_id = deposit_bill_other_receipts.id 
																													inner join users on deposit_payment_other_receipts.created_by = users.id
																													where tenant_id = $tenant_id";
													$runDepositPaymentOthers = mysqli_query($link, $sqlDepositPaymentOthers);
													if($runDepositPaymentOthers === FALSE){
														die(mysqli_error($link));
													}
													$countRowPaymentOthers = mysqli_num_rows($runDepositPaymentOthers);
												//echo $sqlDeposit;
												?>
												<div class="card-body card-block">	
													<div class="table-wrapper-scroll-y my-custom-scrollbar">
														<table class="table table-bordered table-hover table-sm" id="dataTable" width="70%" cellspacing="0" style="font-size: 12px">
															<thead>
															<tr><th colspan="8">Deposit Payment (Payment below September 2024)</th></tr>
															  <tr>
																<td align="center"><b>#</b></td>
																<td align="center"><b>Receipt No.</b></td>
																<td align="center"><b>Two Months Rental(RM)</b></td>
																<td align="center"><b>Utilities(RM)</b></td>
																<td align="center"><b>Management Fee(RM)</b></td>
																<td align="center"><b>Total(RM)</b></td>
																<td align="center"><b>Date Paid</b></td>
																<td align="center"><b>Staff Incharge</b></td>
															  </tr>
															</thead>
															<tbody>
															  <?php 
																$no=1;
																$totalAllDepositPayment = 0.00;
																//$countRowDeposit =mysqli_num_rows($runDeposit);
																if($countRowOldRecord >= 1){
																 while($resultDeposit_oldRecord = mysqli_fetch_array($runDeposit_oldRecord)){
																		$deposit_id = $resultDeposit_oldRecord["id"];
																		$receipt_no = $resultDeposit_oldRecord["receipt_no"];
																		$two_month_rental = $resultDeposit_oldRecord["two_month_rental"];
																		$utilities = $resultDeposit_oldRecord["utilities"];
																		$management_fee = $resultDeposit_oldRecord["management_fee"];
																		$created_at = $resultDeposit_oldRecord["created_at"];
																		$pic = $resultDeposit_oldRecord["name"];
																		//$total_deposit = $resultDeposit_oldRecord["total_deposit"];
																		$total_deposit = $two_month_rental +  $utilities + $management_fee;
																		$totalAllDepositPayment += $total_deposit;
																	
															?>
																<tr>
																	<td align="center"><?php echo $no?></td>
																	<td align="center"><a href="print_deposit.php?deposit_id=<?php echo $deposit_id?>" target="_blank"><?php echo $receipt_no?></a></td>
																	<td align="right"><?php echo number_format($two_month_rental,2)?></td>
																	<td align="right"><?php echo number_format($utilities,2)?></td>
																	<td align="right"><?php echo number_format($management_fee,2)?></td>
																	<td align="right"><?php echo number_format($total_deposit,2)?></td>
																	<td align="center"><?php echo date("d/m/Y",strtotime($created_at))?></td>
																	<td align="center"><?php echo ucfirst($pic)?></td>
																</tr>
																<?php 
																$no++;
																} ?>
																<tr>
																	<td colspan="5"><b>TOTAL (RM)</b></td>
																	<td align="right"><b><?php echo number_format($totalAllDepositPayment,2)?></b></td>
																	<td colspan="2">&nbsp;</td>
																</tr>
																<?php } else if($countRowOldRecord == 0){
																		?>
																	<tr align="center"><th colspan="8">~ No Record Found ~</th></tr>	
																	<?php
																	}
																	?>
														</table>
														<table class="table table-bordered table-hover table-sm" id="dataTable" width="70%" cellspacing="0" style="font-size: 12px">
															<thead>
															<tr><th colspan="7">Deposit Payment (Payment on September 2024 and above)</th></tr>
															  <tr>
																<td align="center"><b>#</b></td>
																<td align="center"><b>Receipt No.</b></td>
																<td align="center"><b>Two Months Rental(RM)</b></td>
																<td align="center"><b>Utilities(RM)</b></td>
																<td align="center"><b>Total(RM)</b></td>
																<td align="center"><b>Date Paid</b></td>
																<td align="center"><b>Staff Incharge</b></td>
															  </tr>
															</thead>	
																<?php 
																$no=1;
																$totalAllDepositPayment = 0.00;
																//$countRowDeposit =mysqli_num_rows($runDeposit);
																if($countRowNewRecord >= 1){
																	while($resultDeposit_newRecord = mysqli_fetch_array($runDeposit_newRecord)){
																		$deposit_id = $resultDeposit_newRecord["id"];
																		$receipt_no = $resultDeposit_newRecord["receipt_no"];
																		$two_month_rental = $resultDeposit_newRecord["two_months_amount_paid"];
																		$utilities = $resultDeposit_newRecord["utility_amount_paid"];
																		$created_at = $resultDeposit_newRecord["created_at"];
																		$pic = $resultDeposit_newRecord["name"];
																		$total_deposit = $two_month_rental + $utilities;
																		$paymentType = "";
																		$totalAllDepositPayment += $total_deposit;
																	?>
																<tr>
																	<td align="center"><?php echo $no?></td>
																	<td align="center"><a href="print_deposit.php?depositPaymentID_print=<?php echo $deposit_id?>" target="_blank"><?php echo $receipt_no?></a></td>  
																	<td align="right"><?php echo number_format($two_month_rental,2)?></td>
																	<td align="right"><?php echo number_format($utilities,2)?></td>
																	<td align="right"><?php echo number_format($total_deposit,2)?></td>
																	<td align="center"><?php echo date("d/m/Y",strtotime($created_at))?></td>
																	<td align="center"><?php echo ucfirst($pic)?></td>
																</tr>
																
																	<?php
																	$no++;
																	} ?>
																<tr>
																	<td colspan="4"><b>TOTAL (RM)</b></td>
																	<td align="right"><b><?php echo number_format($totalAllDepositPayment,2)?></b></td>
																	<td colspan="2">&nbsp;</td>
																</tr>
																
																<?php } 
																else if($countRowNewRecord == 0){
																	?>
																<tr align="center"><th colspan="7">~ No Record Found ~</th></tr>	
																<?php
																}
																?>
																</tbody>
														</table>
														<table class="table table-bordered table-hover table-sm" id="dataTable" width="70%" cellspacing="0" style="font-size: 12px">
															<thead>
																<tr><th colspan="8">Others Payment (Pelbagai)</th></tr>
																<tr>
																	<th scope="col">#</th>
																	<th scope="col">Receipt No.</th>
																	<th scope="col">Yuran Pelbagai(RM)</th>
																	<th scope="col">SST  <?php echo $sst_percent?>(RM)</th>
																	<th scope="col">Stamping  (RM)</th>
																	<th scope="col">Total Paid (RM)</th>
																	<th scope="col">Date Paid</th>
																	<th scope="col">Staff Incharge</th>
																</tr>
															</thead>
															<tbody>
																<?php 
																$no=1;
																$countDepositPaymentOthers = mysqli_num_rows($runDepositPaymentOthers);
																$totalPaymentOthers = 0.00;
																if($countDepositPaymentOthers > 0){
																	while($resultDepositPaymentOthers = mysqli_fetch_array($runDepositPaymentOthers)){
																		$deposit_other_payment_id = $resultDepositPaymentOthers["id"];
																		$deposit_other_payment_no = $resultDepositPaymentOthers["deposit_other_payment_no"];
																		$stamping_paid = $resultDepositPaymentOthers["stamping_paid"];
																		$sst_paid = $resultDepositPaymentOthers["sst_paid"];
																		$yp_paid = $resultDepositPaymentOthers["yp_paid"];
																		$total_charges_paid = $resultDepositPaymentOthers["total_charges_paid"];
																		$created_at = $resultDepositPaymentOthers["created_at"];
																		$pic = $resultDepositPaymentOthers["name"];
																		$totalPaymentOthers += $total_charges_paid;
																		?>
																<tr>
																	<td align="center"><?php echo $no?></td>
																	<td align="center"><a href="print_deposit.php?depositPaymentOtherID_print=<?php echo $deposit_other_payment_id?>" target="_blank"><?php echo $deposit_other_payment_no?></a></td>
																	<td align="right"><?php echo number_format($yp_paid,2)?></td>
																	<td align="right"><?php echo number_format($sst_paid,2)?></td>
																	<td align="right"><?php echo number_format($stamping_paid,2)?></td>
																	<td align="right"><?php echo number_format($total_charges_paid,2)?></td>
																	<td align="center"><?php echo date("d/m/Y",strtotime($created_at))?></td>
																	<td align="center"><?php echo ucfirst($pic)?></td>
																</tr>
																		
																		<?php
																		$no++;
																	}
																	?>
																<tr>
																	<td colspan="5"><b>TOTAL (RM)</b></td>
																	<td align="right"><b><?php echo number_format($totalPaymentOthers,2)?></b></td>
																	<td colspan="2">&nbsp;</td>
																</tr>
																	
																	<?php
																}else if($countRowDeposit == 0){
																	?>
																<tr align="center"><th colspan="8">~ No Record Found ~</th></tr>	
																<?php
																}
																?>
															</tbody>
														</table>
													</div>
												</div>
											</div>
											<div class="card">
												<div class="card-header ">
													<h5 class="m-0 font-weight-bold text-primary">
														Rental Payments History
														
													</h5>
												</div>
												<div class="card-body card-block">	
													<div class="table-wrapper-scroll-y my-custom-scrollbar">
														 
														  <table class="table table-bordered table-hover table-sm" id="dataTable" width="70%" cellspacing="0" style="font-size: 12px">
															<thead>
															  <tr>
																<th scope="col">#</th>
																<th scope="col">Receipt No.</th>
																<th scope="col">Month / Year</th>
																<th scope="col">Amount(RM)</th>
																<th scope="col">Date Paid</th>
																<th scope="col">Staff Incharge</th>
																<th scope="col">Type</th>
																<th scope="col"></th>
															  </tr>
															</thead>
															<tbody>
															  <?php 
																$no=1;
																while($resultRentalHistory = mysqli_fetch_array($runRentalHistory)){
																	$payment_id = $resultRentalHistory["payment_id"];
																	$receipt_no = $resultRentalHistory["receipt_no"];
																	$issue_date = $resultRentalHistory["issue_date"];
																	$amount_paid = $resultRentalHistory["amount_paid"];
																	$created_at = $resultRentalHistory["created_at"];
																	$pic = $resultRentalHistory["name"];
																	//$payment_info = $resultRentalHistory["info"];
																	$paymentType = "";
																	$monthYear_issue_date = date("Y-m",strtotime($issue_date));
																	$monthYear_created_at = date("Y-m",strtotime($created_at));
																	if($monthYear_created_at > $monthYear_issue_date)
																		$paymentType = "Outstanding";
																	else if($monthYear_created_at == $monthYear_issue_date)
																		$paymentType = "Normal";
																	else if($monthYear_created_at < $monthYear_issue_date)
																		$paymentType = "Advanced"; 
																	
																	include("paymentRefNoInfo.php");
																	
																	
															?>
																<tr>
																	<td><?php echo $no?></td>
																	<td><?php echo $receipt_no?></td>
																	<td><?php echo date("m/Y",strtotime($issue_date))?></td>
																	<td><?php echo number_format($amount_paid,2) . " " . $paymentInfoShow ?></td>
																	<td><?php echo date("d/m/Y H:i A",strtotime($created_at))?></td>
																	<td><?php echo ucfirst($pic)?></td>
																	<td><?php echo $paymentType?></td>
																	<td><a href="printPayment.php?payment_id=<?php echo $payment_id?>" target="_blank">print</a></td>
																</tr>
																<?php 
																$no++;
																} ?>
															  
															</tbody>
														  </table>

														</div>
													</div>
											</div>
											<div class="card">
												<div class="card-header ">
													<h5 class="m-0 font-weight-bold text-primary">
														Water Payments History
														
													</h5>
												</div>
												<div class="card-body card-block">	
													<div class="table-wrapper-scroll-y my-custom-scrollbar">
														  
														   <table class="table table-bordered table-hover table-sm" id="dataTable" width="70%" cellspacing="0" style="font-size: 12px">
															<thead>
															  <tr>
																<th scope="col">#</th>
																<th scope="col">Receipt No.</th>
																<th scope="col">Month / Year</th>
																<th scope="col">Amount(RM)</th>
																<th scope="col">Date Paid</th>
																<th scope="col">Staff Incharge</th>
																<th scope="col">Type</th>
																<th scope="col"></th>
															  </tr>
															</thead>
															<tbody>
															  <?php 
																$no=1;
																while($resultWaterHistory = mysqli_fetch_array($runWaterHistory)){
																	$payment_id = $resultWaterHistory["payment_id"];
																	$receipt_no = $resultWaterHistory["receipt_no"];
																	$issue_date = $resultWaterHistory["issue_date"];
																	$amount_paid = $resultWaterHistory["amount_paid"];
																	$created_at = $resultWaterHistory["created_at"];
																	$pic = $resultWaterHistory["name"];
																	$paymentType = "";
																	 "monthYear_issue_date $receipt_no:: " . $monthYear_issue_date = date("Y-m",strtotime($issue_date));
																	 "monthYear_created_at $receipt_no:: " . $monthYear_created_at = date("Y-m",strtotime($created_at));
																	if($monthYear_created_at > $monthYear_issue_date)
																		$paymentType = "Outstanding";
																	else if($monthYear_created_at == $monthYear_issue_date)
																		$paymentType = "Normal";
																	else if($monthYear_created_at < $monthYear_issue_date)
																		$paymentType = "Advanced";
																	
																	include("paymentRefNoInfo.php");
															?>
																<tr>
																	<td><?php echo $no?></td>
																	<td><?php echo $receipt_no?></td>
																	<td><?php echo date("m/Y",strtotime($issue_date))?></td>
																	<td><?php echo number_format($amount_paid,2) . " " . $paymentInfoShow?></td>
																	<td><?php echo date("d/m/Y H:i A",strtotime($created_at))?></td>
																	<td><?php echo ucfirst($pic)?></td>
																	<td><?php echo $paymentType?></td>
																	<td><a href="printPayment.php?payment_id=<?php echo $payment_id?>" target="_blank">print</a></td>
																</tr>
																<?php 
																$no++;
																} ?>
															  
															</tbody>
														  </table>

														</div>
													</div>
											</div>
											<?php 
												$countRowOthers = mysqli_num_rows($runOthersHistory);
												if($countRowOthers > 0) {
											?>
											<div class="card">
												<div class="card-header ">
													<h5 class="m-0 font-weight-bold text-primary">
														Others Payments History
														
													</h5>
												</div>
												<div class="card-body card-block">	
													<div class="table-wrapper-scroll-y my-custom-scrollbar">
														  
														   <table class="table table-bordered table-hover table-sm" id="dataTable" widtd="70%" cellspacing="0" style="font-size: 12px">
															<thead>
															  <tr>
																<th scope="col">#</th>
																<th scope="col">Receipt No.</th>
																<th scope="col">Month / Year</th>
																<th scope="col">Amount(RM)</th>
																<th scope="col">Date Paid</th>
																<th scope="col">Staff Incharge</th>
																<th scope="col">Type</th>
																<th scope="col"></th>
															  </tr>
															</thead>
															<tbody>
															  <?php 
																$no=1;
																while($resultOthersHistory = mysqli_fetch_array($runOthersHistory)){
																	$payment_id = $resultOthersHistory["payment_id"];
																	$receipt_no = $resultOthersHistory["receipt_no"];
																	$issue_date = $resultOthersHistory["issue_date"];
																	$amount_paid = $resultOthersHistory["amount_paid"];
																	$created_at = $resultOthersHistory["created_at"];
																	$pic = $resultOthersHistory["name"];
																	$paymentType = "";
																	$monthYear_issue_date = date("Y-m",strtotime($issue_date));
																	$monthYear_created_at = date("Y-m",strtotime($created_at));
																	if($monthYear_created_at > $monthYear_issue_date)
																		$paymentType = "Outstanding";
																	else if($monthYear_created_at == $monthYear_issue_date)
																		$paymentType = "Normal";
																	else if($monthYear_created_at < $monthYear_issue_date)
																		$paymentType = "Advanced";
																	
																	include("paymentRefNoInfo.php");
																	
															?>
																<tr>
																	<td><?php echo $no?></td>
																	<td><?php echo $receipt_no?></td>
																	<td><?php echo date("m/Y",strtotime($issue_date))?></td>
																	<td><?php echo number_format($amount_paid,2) . " " . $paymentInfoShow?></td>
																	<td><?php echo date("d/m/Y H:i A",strtotime($created_at))?></td>
																	<td><?php echo ucfirst($pic)?></td>
																	<td><?php echo $paymentType?></td>
																	<td><a href="printPayment.php?payment_id=<?php echo $payment_id?>" target="_blank">print</a></td>
																</tr>
																<?php 
																$no++;
																} ?>
															  
															</tbody>
														  </table>

														</div>
													</div>
											</div>
												<?php } ?>
									</div>
								</div>
                        
							</div> 
						</DIV>
						

            <!--main content middle end-->
			<!--main content bottom start-->
				<?PHP include "main-content-bottom.php";?>
			<!--main content bottom end-->
			
            <!-- END MAIN CONTENT-->
            <!-- END PAGE CONTAINER-->
        </div>
    </div>
	<!-- modal deposit START-->
	<!-- <div class="modal fade" id="largeModal" tabindex="-1" role="dialog" aria-labelledby="largeModalLabel" aria-hidden="true" data-bs-backdrop="false">
		<div class="modal-dialog modal-lg" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<h5 class="modal-title" id="largeModalLabel">DEPOSIT BILL</h5>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<from action="depositBillController.php" method="post" name="search_form" id="contactForm" role="form">
					<div class="modal-body">
						<div class="col col-md-9">
							<label class=" form-control-label">Create <b>Deposit Bill</b> for this tenant</label>
						</div>
						<div class="col col-md-9">
							<div class="form-check">
								
								<div class="checkbox">
									<label for="checkbox1" class="form-check-label ">
										<input type="checkbox" id="checkbox1" name="checkbox_2MonthsRentalAndUtility" value="Two Months Rental + Utility" class="form-check-input" checked>Two Months Rental + Utility
									</label>
								</div>
								<div class="checkbox">
									<label for="checkbox2" class="form-check-label ">
										<input type="checkbox" id="checkbox2" name="checkbox_stampingOtherFee" value="Stamping and Others Fee" class="form-check-input" checked>Stamping and Others Fee
									</label>
								</div>
								<div class="checkbox">
									<label for="checkbox3" class="form-check-label ">
										<input type="checkbox" id="checkbox3" name="checkbox_1MonthRental" value="1st Month Rental" class="form-check-input" checked>Stamping and Others Fee
									</label>
								</div>
								<div class="checkbox">
									<label for="checkbox4" class="form-check-label ">
										<?php 
										// $sstSql = "select sst_percent from sst where sst_status = 'enable'";
										// $runSstSql = mysqli_query($link, $sstSql);
										// if($runSstSql === FALSE){
										// 	die(mysqli_error($link));
										// }
										// $resultSstSql = mysqli_fetch_array($runSstSql);		
										// $sst_percent = 	$resultSstSql["sst_percent"];

										?>
										<input type="checkbox" id="checkbox4" name="sst_percent" value="<?php echo $sst_percent?>" class="form-check-input" checked>SST Charge: <?php echo $sst_percent*100?>%
									</label>
								</div>
							</div>
						</div>
					</div>
					<div class="modal-footer">
						<input type="hidden" name="tenant_id" value="<?php echo $tenant_id; ?>" />
						<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
						<button type="submit" class="btn btn-primary" id="submit" >Confirm</button>
						<!-- <input type="submit" class="btn btn-primary"  value="Confirm"> -->
					<!-- </div>
				</from>
			</div>
		</div>
	</div> --> 
	<!-- modal deposit END-->
    <?PHP include "footerLink.php";?>
</body>
</html>
<!-- end document-->
<script>
function newPopup(url) {
	popupWindow = window.open(
	//url,'popUpWindow','height=600,width=700,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
	url,'_blank','left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
$(document).ready(function () {
  $('#dtDynamicVerticalScrollExample').DataTable({
    "scrollY": "50vh",
    "scrollCollapse": true,
  });
  $('.dataTables_length').addClass('bs-select');
});
$(document).ready(function(){	
	$("#contactForm").submit(function(event){
		submitForm();
		return false;
	});
});
function submitForm(){
	 $.ajax({
		type: "POST",
		url: "depositBillController.php",
		cache:false,
		data: $('form#contactForm').serialize(),
		success: function(response){
			$("#contact").html(response)
			$("#contact-modal").modal('hide');
		},
		error: function(){
			alert("Error");
		}
	});
}
</script>
<script type="text/javascript">
  function form_submit() {
	alert();
    document.getElementById("confirm-submit").submit();
   }    
  </script>