<script type="text/javascript">
function editProperty(property_id,projectLocation) {
	//window.location="Up_tenant_detail.php?name=?name="+name+"&tenant_id="+tenant_id;
	window.open("edit_propertyrecord.php?property_id="+property_id+"&projectLocation="+projectLocation,'_blank');
}
function addNewFireInsurance(property_id) {
	//window.location="Up_tenant_detail.php?name=?name="+name+"&tenant_id="+tenant_id;
	window.open("addNewFireInsurance.php?property_id="+property_id,'_blank');
}
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','height=600,width=700,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>

<!DOCTYPE html>
<html lang="en">
<?php
 include "headerLink.php";
 
// Initialize the session
//session_start();
//include('function_bgcolorSS_byrLepas7hb.php');
require_once "config.php";
$projectLocation = $_POST["projectLocation"];
$property_id = $_POST["property_id"];

if($property_id == "" || $property_id == null)
	$property_id = $_GET["property_id"];

if($_SESSION["projectLocation"] != "")
	$projectLocation = $_SESSION["projectLocation"];
else{
	$_SESSION["projectLocation"] = $projectLocation;
}

include "splitLocationName_project.php";
//$submit = $_GET["Submit"];

 $sql_properties = "select properties_unit.unit_no as childUnitNo, properties_unit.unit_status as childUnitStatus ,properties.*, locations.location_desc, r_rental_program.rental_desc 
					from properties_unit 
					inner join properties on properties_unit.property_id = properties.id
					inner join locations on properties.location_id = locations.location_id 
					inner join r_rental_program on locations.rental_id_program = r_rental_program.id_rental_progrm 
					WHERE properties.id = " . $property_id;
$sql_insuran_kebakaran = "select * from insuran_kebakaran where property_id = " . $property_id;
$sql_cukai_pintu = "select * from cukai_pintu where property_id = " . $property_id;
$sql_cukai_tanahpetak = "select * from cukai_tanahpetak where property_id = " . $property_id;
$sql_iwk = "select * from iwk where property_id = " . $property_id;
$sql_mntnfee_snkgfund = "select * from mntnfee_snkgfund where property_id = " . $property_id;
$sql_nilai_pasaran = "select * from nilai_pasaran where property_id = " . $property_id;

$runsql_properties = mysqli_query($link, $sql_properties);
if($runsql_properties === FALSE){
	echo "Error: " . $sql_properties . "<br>" . mysqli_error($link);
}

$runsql_insuran_kebakaran = mysqli_query($link, $sql_insuran_kebakaran);
if($runsql_insuran_kebakaran === FALSE){
	echo "Error: " . $sql_insuran_kebakaran . "<br>" . mysqli_error($link);
}

$runsql_cukai_pintu = mysqli_query($link, $sql_cukai_pintu);
if($runsql_cukai_pintu === FALSE){
	echo "Error: " . $sql_cukai_pintu . "<br>" . mysqli_error($link);
}
$runsql_cukai_tanahpetak = mysqli_query($link, $sql_cukai_tanahpetak);
if($runsql_cukai_tanahpetak === FALSE){
	echo "Error: " . $sql_cukai_tanahpetak . "<br>" . mysqli_error($link);
}
$runsql_iwk = mysqli_query($link, $sql_iwk);
if($runsql_iwk === FALSE){
	echo "Error: " . $sql_iwk . "<br>" . mysqli_error($link);
}
$runsql_mntnfee_snkgfund = mysqli_query($link, $sql_mntnfee_snkgfund);
if($runsql_mntnfee_snkgfund === FALSE){
	echo "Error: " . $sql_mntnfee_snkgfund . "<br>" . mysqli_error($link);
}
$runsql_nilai_pasaran = mysqli_query($link, $sql_nilai_pasaran);
if($runsql_nilai_pasaran === FALSE){
	echo "Error: " . $sql_nilai_pasaran . "<br>" . mysqli_error($link);
}
$resultsql_properties = mysqli_fetch_assoc($runsql_properties);
	if($property_id == "" || $property_id == null){
		$property_id = $resultsql_properties["id"];
	}
?>
<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
			
			
			?>
			
            
            <div class="main-content"  >
                <div class="section__content section__content--p30" >
                    <div class="container-fluid" >
                        <!-- menu show on page after selected - start -->
                        <?php include "selectedMenuSubMenu.php"?> 
						<!-- menu show on page after selected - end -->
						<div class="row" >
                            <div class="col-lg-12">
									<div class="card">
										<div class="card-header bg-dark">
											<div class="sufee-alert alert with-close alert-success alert-dismissible fade show">
												<center>
												<span class="badge badge-pill badge-success">Save Success</span>
												You successfully read this important alert.
												<button type="button" class="close" data-dismiss="alert" aria-label="Close">
													<span aria-hidden="true">&times;</span>
												</button>
												</center>
											</div>
											<h3 class="text-center title-2"><strong class="card-title text-light">View Properties -  Info</strong></h3>
										</div>
										<div class="row">
											<div class="col-md-6">
												<div class="card">
													<div class="card-header">
														<strong class="card-title">Properties Info</strong>
													</div>
													<div class="card-body">
														<div class="row">
															<div class="col-6">
																<label class="control-label mb-1">Project</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo strtoupper($resultsql_properties["rental_desc"])?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																<label class="control-label mb-1">Location</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo strtoupper($resultsql_properties["location_desc"])?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																<label class="control-label mb-1">Property Type:</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo strtoupper($resultsql_properties["property_type"])?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																<label class="control-label mb-1">Parent's Unit No:</label>
																
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo strtoupper($resultsql_properties["unit_no"])?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																<label class="control-label mb-1">Child's Unit No:</label>
															</div>
															<?php
																//list out all childUnitID (table: properties_unit)
																$sqlChildUnit = "select unit_no as childUnitNo from properties_unit where property_id = $property_id";
																$runChildUnit = mysqli_query($link, $sqlChildUnit);
																$countChildUnit = mysqli_num_rows($runChildUnit);
																if($countChildUnit == 1){
																	$resultChildUnit = mysqli_fetch_assoc($runChildUnit);
															?>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo strtoupper($resultChildUnit['childUnitNo'])?></label>
															</div>
														</div>
																<?php } 
																else if($countChildUnit > 1){
																	$bil_unit = 1;
																	while($resultChildUnit = mysqli_fetch_array($runChildUnit)){
																		if($bil_unit == 1){
																?>
																	<div class="col-6">
																		<label  class="control-label mb-1"><?php  echo strtoupper($resultChildUnit['childUnitNo'])?></label>
																	</div>
																</div>
																		<?php } // end if bil_unit = 1
																		
																		else if($bil_unit > 1){?>
																	<div class="row">
																		<div class="col-6">
																			<label class="control-label mb-1">&nbsp;</label>
																		</div>
																		<div class="col-6">
																			<label  class="control-label mb-1"><?php  echo strtoupper($resultChildUnit['childUnitNo'])?></label>
																		</div>
																	</div>
																<?php 
																		} //end else if ($bil_unit > 1)
																			$bil_unit++;
																	} //end while
																} // end else if ?>
														<div class="row">
															<div class="col-6">
																<label class="control-label mb-1">Block:</label>
																
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo strtoupper($resultsql_properties['block'])?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																<label class="control-label mb-1">Address:</label>
															</div>
															<?php 
																$address = "";
																if($resultsql_properties['line1'] != "")
																	$address.= $resultsql_properties['line1'];
																if($resultsql_properties['line2'] != "")
																	$address.= ", " .$resultsql_properties['line2'];
																if($resultsql_properties['postcode'] != "")
																	$address.= ", " .$resultsql_properties['postcode'];
																if($resultsql_properties['city'] != "")
																	$address.= ", " .$resultsql_properties['city'];
																if($resultsql_properties['state'] != "")
																	$address.= ", " .$resultsql_properties['state'];
															
															
															?>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo ucwords($address)?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																<label class="control-label mb-1">Kedudukan Lot:</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo ucwords($resultsql_properties['kedudukan_lot'])?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																<label class="control-label mb-1">Jenis Pemilikan:</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo ucwords($resultsql_properties['jenis_pemilikan'])?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																<label class="control-label mb-1">No. Hak Milik:</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo strtoupper($resultsql_properties['no_hakmilik'])?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																<label class="control-label mb-1">No. Lot:</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo strtoupper($resultsql_properties['no_lot'])?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																	<label class="control-label mb-1">Mukim:</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo ucwords($resultsql_properties['mukim'])?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																	<label class="control-label mb-1">Daerah:</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo ucwords($resultsql_properties['daerah'])?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																	<label class="control-label mb-1">Pegangan:</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo ucwords($resultsql_properties['pegangan'])?></label>
																<div id="leaseholdClick" style='<?php echo ($resultsql_properties['pegangan'] == 'leasehold' ? 'display:block' : 'display:none')?>'>
																	<table style="border-collapse: collapse;border: 1px solid black;" id="dataLeasehold">
																		<tr  style="border: 1px solid black;">
																			<th style="border: 1px solid black;">Tempoh Pajakan</th>
																			<th style="border: 1px solid black;">Tarikh Luput Pajakan</th>
																		</tr>
																		<tr>
																			<td><?php echo $resultsql_properties['tempoh_pajakan']?> tahun</td>
																			<td><?php echo date("d/m/Y",strtotime($resultsql_properties['tarikh_luput_pajakan']))?></td>
																		</tr>
																	</table>
																</div>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																	<label class="control-label mb-1">Tarikh Perjanjian Jual Beli:</label>
															</div>
															<div class="col-6">
															<?php 
																$date_jualbeli = "";
																$tarikh_perjanjian_jualbeli = $resultsql_properties['tarikh_perjanjian_jualbeli'];
																
																$needle   = '1970-01-01';

																if (strpos($tarikh_perjanjian_jualbeli, $needle) !== false) {
																	echo $date_jualbeli;
																}
																else{
																?>
																	<label  class="control-label mb-1"><?php  echo date("d/m/Y",strtotime($resultsql_properties['tarikh_perjanjian_jualbeli']))?></label>
																<?php
																}
															?>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																	<label class="control-label mb-1">Luas Tanah (kp):</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo $resultsql_properties['luas_tanah_kp']?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																	<label class="control-label mb-1">Luas Lantai/Bangunan (kp):</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo $resultsql_properties['luas_lantai_kp']?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																	<label class="control-label mb-1">Harga Belian (RM):</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo number_format($resultsql_properties['harga_belian'],2, '.', ',');?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																	<label class="control-label mb-1">Status Pindah Milik :</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo ucwords($resultsql_properties['status_pindahmilik'])?></label>
															</div>
														</div>
														<div class="row">
															<div class="col-6">
																	<label class="control-label mb-1">Catatan :</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo ucfirst($resultsql_properties['catatan'])?></label>
															</div>
														</div>
														<div class="row" style="<?php echo ($resultsql_properties['catatan_tambahan'] == '' ? 'display:none' : 'display:block')?>">
															<div class="col-6">
																	<label class="control-label mb-1">Catatan Tambahan:</label>
															</div>
															<div class="col-6">
																<label  class="control-label mb-1"><?php  echo ucfirst($resultsql_properties['catatan_tambahan'])?></label>
															</div>
														</div>
													</div>			
												</div>
											</div>
										
											<div class="col-md-6">
												<div class="card">
													<div class="card-header">
														<strong class="card-title">Properties Additional Info</strong>
													</div>
													<div class="card-body">
														<div class="row">
															<div class="col-6">
																 <!-- DATA TABLE -->
																<h3 class="title-5 m-b-35">Fire Insurances</h3>
																<div class="table-responsive table-responsive-data2">
																	<table class="table table-data2">
																		<thead>
																			<tr>
																				<th rowspan="2">#</th>
																				<th rowspan="2"> Policy Year</th>
																				<th rowspan="2">Policy No.</th>
																				<th colspan="2" >Cover Period</th>
																				<th rowspan="2">Total Cover (RM)</th>
																				<th rowspan="2">Type Of Used</th>
																				<th rowspan="2">Policy Attachment</th>
																				<th rowspan="2">Action</th>
																			</tr>
																			<tr colspan="3" >
																				<th>Start</th>
																				<th>End</th>
																			</tr>
																		</thead>
																		<tbody>
																		<?php 
							
																		$no = 1;
																		while($resultsql_insuran_kebakaran = mysqli_fetch_array($runsql_insuran_kebakaran)){
																			$insuran_kebakaran_ID = $resultsql_insuran_kebakaran["id"];
																	?>
																		<input type="hidden" name="insuran_kebakaran_ID[]" value="<?php echo $insuran_kebakaran_ID;?>">
																			<tr>
																				<td><?php echo $no;?></td>
																				<td><?php echo $resultsql_insuran_kebakaran['policy_year'];?></td>
																				<td><?php echo $resultsql_insuran_kebakaran['policy_no'];?></td>
																				<td><?php echo date("d/m/Y",strtotime($resultsql_insuran_kebakaran['policy_start_cover']));?></td>
																				<td><?php echo date("d/m/Y",strtotime($resultsql_insuran_kebakaran['policy_end_cover']));?></td>
																				<td><?php echo $resultsql_insuran_kebakaran['policy_total_cover'];?></td>
																				<td><?php echo $resultsql_insuran_kebakaran['policy_type_of_used'];?></td>
																				<td><a href='Uploads/FileProperties/<?php echo $resultsql_insuran_kebakaran['policy_file_attachment']?>' target='_blank'>Download</a></td>
																				<td>
																					<a href="JavaScript:newPopup('editFireInsurance.php?policy_id=<?php echo $resultsql_insuran_kebakaran["id"]?>')"><img src="img/edit.png" width="15" height="15" title="Edit" border="0"/></a> 
																					| 
																					<a href="deleteAllocation.php?insuran_kebakaran_ID=<?php echo $insuran_kebakaran_ID?>" onclick="alert('Are You Sure Want To Delete This Row?')"><img src="img/delete.png" width="15" height="15" title="Delete" border="0"/></a></td>
																				
																			</tr>
																		<?php } ?>
																		</tbody>
																	</table>
																</div>
															</div>
														</div>
													</div>
												</div>
											</div>
										</div>
										</div>
									</div>	
									
								</div>
							</div>
							
							<?php //} ?>
                        </div>
                        
                        
                        
                    </div>
					<?PHP include "footer.php";?>
                </div>
            </div>
            <!-- END MAIN CONTENT-->
            <!-- END PAGE CONTAINER-->
        </div>
		
    </div>
    <?PHP include "footerLink.php";?>
</body>

</html>

<script type="text/javascript">

function addNewLinkAcc(){
	//alert();
	var divWrap = document.createElement('div');
	var div1 = document.createElement('div');
	var div2 = document.createElement('div');
	var div3 = document.createElement('div');
    divWrap.className = 'row form-group';
    div1.className = 'col col-md-3';
    div2.className = 'col-12 col-md-6';
    div3.className = 'col col-md-3';
	divWrap.id = 'divRow';
	div3.id = 'deleteButton';
	
	var div1_html = "<label for='text-input' class='form-control-label'>&nbsp;</label>";
	var div2_html = "<input type='text' name='child_unit_no[]'  id='child_unit_no' size='25' required='Please type childs unit no.' class='form-control' placeholder='Please type childs unit no. '>";
	var div3_html = "<span class='help-block'><a href='#' id='del' onclick='deleteRow(this)'><i class='fas fa-minus-square' ></a></i></span>";
	
	div1.innerHTML = div1_html;
	div2.innerHTML = div2_html;
	div3.innerHTML = div3_html;
	
	divWrap.append(div1,div2,div3);
	document.getElementById("input_unitNo").appendChild(divWrap);	
	
}
function deleteRow(row){ 
	
	var x = document.querySelectorAll("#deleteButton");
	
	var remove = function(){
		this.parentNode.remove();
	};

	var button = document.querySelectorAll('#del');
	for (var i = 0, len = x.length; i < len; i++) {
		x[i].addEventListener('click', remove, false);
	}


}


document.getElementById("skipParentsUnit").onclick = function() {myFunction()};

function myFunction() {
	if(document.getElementById("propertiesParentsUnit_input").disabled === true){
		document.getElementById("propertiesParentsUnit_input").removeAttribute("disabled");
		document.getElementById("propertiesParentsUnit_input").setAttribute("required","required");
	}
	else{
		document.getElementById("propertiesParentsUnit_input").setAttribute("disabled","disabled");
		document.getElementById("propertiesParentsUnit_input").removeAttribute("required");
		
	}
		
}


function leaseholdClick(){
  document.getElementById('leaseholdClick').style.display ='block';
}
function freeholdClick(){
  document.getElementById('leaseholdClick').style.display ='none';
}
function tambahCatatanClick(){
  document.getElementById('tambahCatatanClick').style.display ='block';
}
</script>
<!-- end document-->
