<STYLE type="text/css">

/* Styles go here */

.page-header, .page-header-space {
  height: 50px;
}

.page-footer, .page-footer-space {
  height: 20px;

}

.page-footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  border-top: 1px solid black; /* for demo */
  background: yellow; /* for demo */
}

.page-header {
  position: fixed;
  top: 0mm;
  width: 100%;
  /*border-bottom: 1px solid black;*/ /* for demo */
 /*background: yellow;*/ /* for demo */
}

.page {
  page-break-before: always;
}

.watermark{
	background-repeat: repeat;
	background-image: url("img/phssbwatermark.png");
}

@page {
  margin: 10mm
  
}

@media print {
   thead {display: table-header-group;} 
   tfoot {display: table-footer-group;}
   
   button {display: none;}
   
   body {
	margin: 0;
	/*background-repeat: repeat;
	background-image: url("img/phssbwatermark.png");*/
   }
   
}

hr.line {
  border-top: 1px dashed red;
}
}
</STYLE>


<?php 

// Initialize the session
session_start();
error_reporting(0);
// Initialize the session
//session_start();
//include('function_bgcolorSS_byrLepas7hb.php');
require_once "config.php";
function dateDifference($start_date, $end_date)
{
    // calulating the difference in timestamps 
    $diff = strtotime($start_date) - strtotime($end_date);
     
    // 1 day = 24 hours 
    // 24 * 60 * 60 = 86400 seconds
    return ceil(abs($diff / 86400));
}



$tenant_id = $_GET["tenant_id"];
//GET TENANT INFO
include ("queryTenant.php");

$resultTenant = mysqli_fetch_assoc($runTenant);
$tenant_id = $resultTenant["id"];
$tenant_name = $resultTenant["tenant_name"];
$tenant_ic = $resultTenant["ic_no"];
$company_name = $resultTenant["company"];
$company_ssm = $resultTenant["ssm_no"];
$unit_no = $resultTenant["unit_no"];
$location = $resultTenant["location_name"];
$tenant_telNo = $resultTenant["phone"];
$tenant_phoneNo = $resultTenant["mobile"];
$start_rent = $resultTenant["start_date"];
$end_rent = $resultTenant["end_date"];
$tenant_status = $resultTenant["status"];
$project_name = $resultTenant["project_name"];
$mailing_address = $resultTenant["mailing_address"];
$gender = $resultTenant["gender"];
$marital_status = $resultTenant["marital_status"];
$tenant_dob = $resultTenant["tenant_dob"];
$tenant_nationality = $resultTenant["tenant_nationality"];
$tenant_religion = $resultTenant["tenant_religion"];
$tenant_email = $resultTenant["tenant_email"];

//GET RENTAL RATE FROM TENANT ID
 $sqlTenantRentalRate = "select * from tenant_rental_rate where tenant_id = $tenant_id";
$runTenantRentalRate = mysqli_query($link, $sqlTenantRentalRate);
if($runTenantRentalRate === FALSE){
	die(mysqli_error($link));
}



$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);
//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);
?>

<body  height="100%" style="font-family:verdana;font-size:12px" onLoad="window.print();" >
<div style="vertical-align: top;">	
	<div class="page-header" style="text-align: center">
		<table>
			<tr>
				<td width="60%" style="font-size: 100%;" bgcolor="yellow"><b>PERUMAHAN DAN HARTANAH SELANGOR SDN BHD</b></td>
				<td style="font-size: 16px; " align="right" width="40%" >
					<i>DEPOSIT PAYMENT HISTORY</i>
					
				</td>
			</tr>
			<table width="100%" height="100%" style="position: absolute; top: 0; bottom: 0; left: 0; right: 0;" >
				<thead>
					<tr>
						<td>
						<!--place holder for the fixed-position header-->
						<div class="page-header-space"></div>
						</td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>
							<table valign="top" width="100%" >
								<tr>
									<td colspan="3"  rowspan="4" width="50%">
										<!--<div style="font-size: 100%;" ><b>PERUMAHAN DAN HARTANAH SELANGOR SDN BHD</b></div>-->
										<div style="font-size: 12px;" >
											Tingkat 5, Podium Utara, <br/>
											Bangunan Sultan Salahuddin Abdul Aziz Shah, <br/>
											Selangor Darul Ehsan <br/>
											Tel: 03 5524 0233 / 0253 (Pejabat)<br/>
											Fax: 03 5524 0243 <br/>
											Web: www.phssb.com <?php //echo $sqlStatement?>
										</div>
									</td>
									<td  valign="top" width="50%" align="right" STYLE="float:right">
										<table style="font-size: 12px;"  >
											<tr valign="top">
												<td colspan="3" style="font-size: 30px" align="right" >&nbsp;</i></td>
											</tr>
											<tr>
												<td  valign="top">
													Date 
												</td>
												<td>:</td>
												<td valign="top">
													<?php echo date("d/m/Y");?>
												</td>
											</tr>
											<tr>
												<td  valign="top">
													Tenant ID 
												</td>
												<td>:</td>
												<td valign="top">
													<?php echo $tenant_id;?>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
							<br/>
							<div style="border-collapse: collapse;border-bottom: 1px solid black;"  style="line-height: 3;">
								<table width="100%" style="font-size: 12px;" border='0' >
									<tr>
										<td bgcolor="#000000" colspan = "2" width="45%"><font color="white" style="font-size: 12px;"><b>TENANT INFO:</b></font> </td>
									</tr>
									<tr>
										<td>
											<table border='0'  width="100%" >
												<tr>
													<td width="55%" valign="top">
														<table style="font-size: 12px;" border='0'  width="100%">
															
															<tr>
																<td width='30%'><strong>NAME</strong></td>
																
																<td width='50%'><?php echo strtoupper($tenant_name)?></td>
															</tr>
															<tr>
																<td width='30%'><strong>IC NO.</strong></td>
																
																<td width='50%'><?php echo $tenant_ic?></td>
															</tr>
															<tr>
																<td width='30%'><strong>CONTACT NO.</strong></td>
																
																<td width='50%'><?php echo $contact_no?></td>
															</tr>
															
															<tr>
																<td width='30%'><strong>TYPE OF PROPERTY</strong></td>
																
																<td width='50%'><?php echo strtoupper($project_name)?></td>
															</tr>
															<tr>
																<td width='30%'><strong>PROPERTY LOCATION</strong></td>
																
																<td width='50%'><?php echo $unit_no . ", " .strtoupper($location)?></td>
															</tr>
														</table>
													</td>
												</tr>
											</table>
										</td>
									</tr>
									<tr>
										<td bgcolor="#000000" colspan = "2" width="45%"><font color="white" style="font-size: 12px;"><b>RENTAL RATE INFO:</b></font> </td>
									</tr>
									<tr>
										<td>
											<table border='0' style="font-size: 12px;" border='0'  width="100%">
												<tr>
													<td>#</td>
													<td>Rental Rate (RM)</td>
													<td>Start</td>
													<td>End</td>
													<td>Status</td>
												</tr>
												<?php
												$no=1;										
												while($resultTenantRentalRate = mysqli_fetch_array($runTenantRentalRate)){
													$rental_rate = $resultTenantRentalRate["rental_rate"];
													$start_date = $resultTenantRentalRate["start_date"];
													$end_date = $resultTenantRentalRate["end_date"];
													$status = $resultTenantRentalRate["status"];
													$created_at = $resultTenantRentalRate["created_at"];
													
													if($start_date == "0000-00-00 00:00:00")
														$start_date = "-";
													else
														$start_date = date("d/m/Y",strtotime($start_date));
													if($end_date == "0000-00-00 00:00:00")
														$end_date = "-";
													else
														$end_date = date("d/m/Y",strtotime($end_date));
													if($status == "enable")
														$status = "active";
													else if($status == "disable")
														$status = "deactive";
													?>
												<tr>	
													<td><?php echo $no?></td>
													<td><?php echo number_format($rental_rate,2)?></td>
													<td><?php echo $start_date?></td>
													<td><?php echo $end_date?></td>
													<td><?php echo ucfirst($status)?></td>
												</tr>
													<?php
													$no++;
												}
												
												?>
											</table>
										</td>
									</tr>
								</table>
							</div>
							<BR/>
							<div style="border-collapse: collapse;border-bottom: 1px solid black;"  style="line-height: 3;">
								<table width="100%" style="font-size: 12px;" border='0'>
									<tr>
										<td bgcolor="#000000" colspan = "2" width="45%"><font color="white" style="font-size: 12px;"><b>DEPOSIT PAYMENT RECORDS:</b</font></td>
									</tr>
									<tr>
										<td>
											
											<table class="table table-bordered table-hover table-sm" id="dataTable" width="100%" cellspacing="0" style="font-size: 12px">
												<tr style="background-color:#e3e3e3"><th colspan="8">Deposit Payment (Payment below September 2024) </th></tr>
												<tr style="background-color:#cccccc">
													<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>
												<?php if($countRowOldRecord > 0){
													$no=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"];
														$totalAllDepositPayment += $total_deposit;
														
														?>
												<tr>
													<td align="center"><?php echo $no?></td>
													<td align="center"><?php echo $receipt_no?></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>
											<br/>
											<table class="table table-bordered table-hover table-sm" id="dataTable" width="100%" cellspacing="0" style="font-size: 12px">
												<tr style="background-color:#e3e3e3"><th colspan="7">Deposit Payment (Payment on September 2024 and above) </th></tr>
												<tr  style="background-color:#cccccc">
													<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>
											<?php
											
												if($countRowNewRecord > 0){
												$no=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"><?php echo $receipt_no?></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  style="background-color:#cccccc">
													<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
												}
												?>
											</table>
											<br/>
											<table class="table table-bordered table-hover table-sm" id="dataTable" width="100%" cellspacing="0" style="font-size: 12px">
												<tr  style="background-color:#e3e3e3"><th colspan="8">Others Payment (Pelbagai)</th></tr>
												<tr  style="background-color:#cccccc">
													<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>
												<?php 
												if($countRowPaymentOthers > 0){
												$no=1;
												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"><?php echo $deposit_other_payment_no?></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  style="background-color:#cccccc">
													<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($countRowPaymentOthers == 0){
													?>
												<tr align="center"><th colspan="8">~ No Record Found ~</th></tr>	
												<?php
												}
												?>
											</table>
										</td>
									</tr>
								</table>
							</div>
						</tbody>
		<tfoot>
			<tr>
				<td>
				  <!--place holder for the fixed-position footer-->
				  <div class="page-footer-space"></div>
				</td>
			</tr>
		</tfoot>
		</table>
		</table>
	</div>
	<div class="page-footer" align="center">
		www.phssb.com
	  </div>
	<div class="watermark" align="center">
	</div>
		

	
</div>
</body>