<!DOCTYPE html>
<html lang="en">
<?php include "headerLink.php";?>
<style>
.my-report-scrollbar {
position: relative;
height: 100%;
width:100%;
overflow: auto;
}
.table-report-scroll-y {
display: block;
}
</style>
<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
			
			$report_type=$_GET["report_type"];
			$_SESSION["report_type"] =  $report_type;
			
			
			
			
			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));
			}

			$selectedLocation = "";
			$selectedTenantInfo = "";
			$tenantInfo = "";
			$cutOffPayment = "";
			$tenant_status = "";
			$_SESSION["aged_date"] ="";
			//$_SESSION["projectLocation"] = "";
			$_SESSION["tenantInfo"] = "";
			$_SESSION["cutOffPayment"] = "";
			$_SESSION["tenant_status"] = "";
			//$tenant_id = $_GET["tenant_id"];
			$sqlDate = "";
			$sqlDateDeposit = "";
			//$_SESSION['projectLocation']=$_GET['projectLocation'];

			$_SESSION['statement_date']="";
			$_SESSION['statement_year']="";
			$_SESSION['statement_monthyear']="";
			$_SESSION['chooseDate']="";
			$_SESSION["statement_ChooseDate"] =  "";
			$_SESSION["statementby"] = "";
			$statementby = "";
			$statement_year = "";
			$statement_monthyear = "";
			$statement_date = "";
			$statement_ByChooseDate = "";
			$selected_cutOffPayment = "";
			$displayYear = "display:none";
			$displayMonthYear = "display:none";
			$displayDateFromTo = "display:none";
			$displayChooseDate = "display:none";
			$displayCheckBox = "display:none";
			$displayStatementOption = "display:none";

			
			//DISPLAY BEFORE SUBMIT START
			$statementby = $_GET["statementby"];
			IF($statementby != "" || $statementby != null){
				include("bill_types.php");
				if($statementby == 'statement_year'){
					$displayYear = "display:block";
					$displayMonthYear = "display:none";
					$displayDateFromTo = "display:none";
					$displayChooseDate = "display:none";
					$displayCheckBox = "display:block";
					$displayStatementOption = "display:none";
					
				
					  $sqlYear = "select YEAR(bills.issue_date) AS year from bills 
								inner join tenants on bills.tenant_id =  tenants.id 
								inner join properties on tenants.property_id = properties.id
								inner join locations on properties.location_id = locations.id
								where locations.id = ".$_SESSION["location_id"]."
								group by year having (year <= YEAR(CURDATE()) and year <> 0 ) order by year ASC";
					$runSqlYear = mysqli_query($link, $sqlYear);
					if($runSqlYear === FALSE){
						die(mysqli_error($link));
					}
					
				}
				else if($statementby == 'statement_monthyear'){
					$displayYear = "display:none";
					$displayMonthYear = "display:block";
					$displayDateFromTo = "display:none";
					$displayChooseDate = "display:none";
					$displayCheckBox = "display:block";
					$displayStatementOption = "display:none";
				}
				else if($statementby == 'statement_date'){
					$displayYear = "display:none";
					$displayMonthYear = "display:none";
					$displayDateFromTo = "display:block";
					$displayChooseDate = "display:none";
					$displayCheckBox = "display:block";
					$displayStatementOption = "display:none";
				}
				else if($statementby == 'statement_ChooseDate'){
					$displayYear = "display:none";
					$displayMonthYear = "display:none";
					$displayDateFromTo = "display:none";
					$displayChooseDate = "display:block";
					$displayCheckBox = "display:block";
					$displayStatementOption = "display:none";
				}
			}
			//END DISPLAY BEFORE SUBMIT
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			

			
			if(isset($_GET["reset"])){
				$_SESSION["dateFrom"] ="";
				$_SESSION["dateTo"] ="";
				$_SESSION['statement_date']="";
				$_SESSION['statement_year']="";
				$_SESSION['statement_monthyear']="";
				$_SESSION['chooseDate']="";
				$_SESSION["cutOffPayment"] =  "";
				$_SESSION["statement_ChooseDate"] =  "";
				$_SESSION["statementby"] = "";
				$_GET["statementby"]= "";
				$_GET["statement_year"] = "";
				$_GET["statement_monthyear"] = "";
				$_GET["statement_date"] = "";
				$_GET["statement_ByChooseDate"] = "";
				$_GET["selected_cutOffPayment"] = "";
				$_GET["dateFrom"] = "";
				$_GET["dateTo"] = "";
				$_GET["chooseDate"] = "";
				$_GET["cutOffPayment"] = "";
				$_GET["statement_ChooseDate"] = "";
				
				
				
				$_SESSION["aged_date"] ="";
				$_SESSION["projectLocation"] = "";
				$_SESSION["tenantInfo"] = "";
				$_SESSION["cutOffPayment"] = "";
				$_SESSION["cutOffPayment"] = "";
				$selectedDate = "";
				$selectedLocation = "";
				$selectedTenantInfo = "";
				$cutOffPayment = "";
				$tenant_status = "";
				 $displayYear = "display:none";
				$displayMonthYear = "display:none";
				$displayDateFromTo = "display:none";
				$displayChooseDate = "display:none";
				$displayCheckBox = "display:none";
				$statementby = "";
				$displayStatementOption = "display:none";
			}
			
			
			if(isset($_GET["searchStatement"])){
				//echo "submit!";
				$dateFrom = $_GET["dateFrom"];
				$dateTo = $_GET["dateTo"];
				$_SESSION["dateFrom"] = $dateFrom;
				$_SESSION["dateTo"] = $dateTo;
				
				$dateTo_cutOFF = date('Y-m-d', strtotime($dateTo. ' + 1 days'));	
				
				include("bill_types.php");
				
				
				$statementby = $_GET["statementby"];
				$_SESSION['statementby'] = $statementby;
				$tenant_id = $_GET["tenant_id"];
				$cond_selectedCutOffPayment = "";
				$cond_monthYear_BF = "";
				$cond_date_BF = "";
				$selected_cutOffPayment = "";
				$statement_year_cutOFF ="";
				$infoTarikhTunggakan = "";
				
				
				$selectedDate = $_GET["aged_date"];
				$selectedTenantInfo = $_GET["tenantInfo"];
				$selected_cutOffPayment = $_GET["cutOffPayment"];
				$tenant_status = $_GET["tenant_status"];
				$_SESSION["aged_date"] = $selectedDate;
				$_SESSION["tenantInfo"] = $selectedTenantInfo;
				$_SESSION["cutOffPayment"] = $selected_cutOffPayment;
				$_SESSION["tenant_status"] = $tenant_status;
				
				
				$cond = "";
				$cond_project = "";
				$cond_location = "";
				$cond_ageingDate = "";
				$cond_tenantInfo = "";
				$cond_tenantStatus = "";
				$cond_staffID = "";
				$groupBY = "";
				$ageingDateInfo ="";
				$cond_selectedCutOffPayment = "";
				$bulanTerimaan = "";
				$project_id = $_SESSION["project_id"];
				$sqlDateADV = "";
				if($statementby == 'statement_year'){
						//all payments start from 1st Jan - 31 Dec
						$displayYear = "display:block";
						$displayMonthYear = "display:none";
						$displayDateFromTo = "display:none";
						$displayChooseDate = "display:none";
						$displayCheckBox = "display:block";
						
						$statement_year = $_GET["statement_year"];
						$_SESSION['statement_year']=$statement_year;
						$selected_cutOffPayment = $_GET["cutOffPayment"];
						$_SESSION["cutOffPayment"] = $selected_cutOffPayment;
						$cutOffDate = date("Y-m-d",strtotime($statement_year . '-12-31')); //tarikh hujung tahun
						$firstYearDate =  date("Y-m-d",strtotime($statement_year . '-01-01')); //tarikh awal tahun
						$statement_year_cutOFF = date('Y-m-d', strtotime($cutOffDate. ' + 1 days'));
						IF($selected_cutOffPayment == true){
							
							$cond_selectedCutOffPayment = " and YEAR(payments.created_at) < '$statement_year_cutOFF'";
						}
						
						$year_selected = date("Y",strtotime($firstYearDate));
						$cond_monthYear_BF = " and year(bills.issue_date) < '$statement_year' ";
						$cond_date_BF = " and payments.created_at < '$firstYearDate' ";
						$sqlDate = "  YEAR(payments.created_at)  = $year_selected ";
						$sqlDateDeposit = "  YEAR(deposits.created_at)  = $year_selected ";
						$infoTarikhTunggakan = " TAHUN $statement_year";
						$sqlDateADV = " and bills.issue_date > '$cutOffDate' ";
						$sqlDatePayments = " and payments.created_at >= '$firstYearDate' and payments.created_at < '$statement_year_cutOFF' ";
				}
				else if($statementby == 'statement_monthyear'){
						//statement by bills issue_date = monthyear selected
						$displayYear = "display:none";
						$displayMonthYear = "display:block";
						$displayDateFromTo = "display:none";
						$displayChooseDate = "display:none";
						$displayCheckBox = "display:block";
						$statement_monthyear = $_GET["statement_monthyear"];
						$_SESSION['statement_monthyear']=$statement_monthyear;
						$selected_cutOffPayment = $_GET["cutOffPayment"];
						$_SESSION["cutOffPayment"] = $selected_cutOffPayment;
						$payment_monthYear = date("m/Y", strtotime($statement_monthyear));
						
						$firstDay = "";
						$lastDay = "";
						
						$firstDay = date("Y-m-01", strtotime($statement_monthyear));
						$lastDay = date("Y-m-t", strtotime($statement_monthyear));
						
						$cond_monthYear_BF = " and issue_date < '$firstDay ' ";
						$cond_date_BF = " and payments.created_at < '$firstDay' ";
						
						$cond_selectedCutOffPayment = " and payments.created_at between '$firstDay' and '$lastDay' ";
					
					$date_monthYear = date("Y-m-01",strtotime($statement_monthyear));
						$lastdate = $date_monthYear . "-01";
						$lastdate = date("Y-m-t", strtotime($lastdate));			
						$cutOffDate = $lastdate;
						
						$date_monthYearDeposit = date("M Y",strtotime($lastdate));	
						
						$sqlDate = "  bills.issue_date  = '$date_monthYear' ";
						$sqlDateDeposit = " deposits.one_month_date  = '$date_monthYearDeposit' ";
						$infoTarikhTunggakan = " BULAN $payment_monthYear ";
				}
				else if($statementby == 'statement_date' ){
						//statement by payments on selected date (dateFrom - dateTo)
						$displayYear = "display:none";
						$displayMonthYear = "display:none";
						$displayDateFromTo = "display:block";
						$displayChooseDate = "display:none";
						$displayCheckBox = "display:block";
						$statement_date = $_GET["statement_date"];
						$dateFrom = date("Y-m-d",strtotime($_GET["dateFrom"]));
						$dateTo =  date("Y-m-d",strtotime($_GET["dateTo"]));
						$_SESSION['statement_date']=$statement_date;
						$_SESSION['dateFrom']=$dateFrom;
						$_SESSION['dateTo']=$dateTo;
						$date_cutOFF = date('Y-m-d', strtotime($dateTo. ' + 1 days'));
						$dateOpening = date('Y-m-d', strtotime($dateFrom. ' - 1 days'));
						
						//]compare month year
						$monthYearFrom = date('m-Y',strtotime($dateFrom));
						$monthYearTo = date('m-Y',strtotime($dateTo));
						if($monthFrom == $monthTo){
							$bulanTerimaan = date('M Y', strtotime($dateFrom));
						}
						else{
							$bulanTerimaan = date("d/m/Y",strtotime($dateFrom)) . " SEHINGGA " . date("d/m/Y",strtotime($dateTo));
						}
						
						//compare year
						$tahunTerimaan = date('Y', strtotime($dateFrom));
						/*$yearFrom = date('Y',strtotime($dateFrom));
						$yearTo = date('Y',strtotime($dateTo));
						if($yearFrom == $yearTo){
							$tahunTerimaan = date('Y', strtotime($dateFrom));
						}
						else {
							
						}*/
						
						$firstDay = $dateFrom;
						$lastDay = $date_cutOFF;
						
						$cond_selectedCutOffPayment = " and payments.created_at between '$firstDay' and '$lastDay' ";
						$sqlDate = " (payments.created_at  >= '$dateFrom'  and payments.created_at < '$date_cutOFF') ";
						$sqlDateDeposit = " (deposits.created_at  >= '$dateFrom'  and deposits.created_at < '$date_cutOFF') ";
						$infoTarikhTunggakan = " DARI ".date("d/m/Y",strtotime($dateFrom)) . " SEHINGGA " . date("d/m/Y",strtotime($dateTo));
				}
				else if($statementby == 'statement_ChooseDate'){
						//statement by payments on selected date
						$displayYear = "display:none";
						$displayMonthYear = "display:none";
						$displayDateFromTo = "display:none";
						$displayChooseDate = "display:block";
						$displayCheckBox = "display:block";
						$chooseDate = "";
						if($_GET["statement_ChooseDate"] != "" || $_GET["statement_ChooseDate"] != null){
							$chooseDate = date("Y-m-d",strtotime($_GET["statement_ChooseDate"]));
						}
						$_SESSION['chooseDate']=$chooseDate;
						$selected_cutOffPayment = $_GET["cutOffPayment"];
						$_SESSION["cutOffPayment"] = $selected_cutOffPayment;
						$date_cutOFF = date('Y-m-d', strtotime($chooseDate));	
						
						$cond_selectedCutOffPayment = " and payments.created_at = '$date_cutOFF'";
						$sqlDate = " payments.created_at like '%$chooseDate%' ";
						$sqlDateDeposit = " deposits.created_at like '%$chooseDate%' ";
						$cutOffDate = $chooseDate;
						$infoTarikhTunggakan = " SEHINGGA ". date("d/m/Y",strtotime($chooseDate));
				}
				else if($statementby == ""){
					$cutOffDate = date('Y-m-d', strtotime($chooseDate. ' + 1 days'));
					$cond_selectedCutOffPayment = " and payments.created_at < '$cutOffDate'";
					//$sqlDate = " payments.created_at = '$cutOffDate' ";
					$infoTarikhTunggakan = " TARIKH:  " . DATE("d/m/Y");
				}
				
				
				if($report_type == "Deposit"){
					    $sqlDeposit = "select deposits.*,tenants.id as tenant_id, tenants.tenant_name, properties.unit_no  from deposits inner join 
									tenants on deposits.tenant_id = tenants.id
									inner join properties on tenants.property_id = properties.id
									inner join locations on properties.location_id = locations.id
									inner join projects on locations.project_id = projects.id 
									where locations.id =". $_SESSION['location_id'] ."
									and projects.id = $project_id
									and ($sqlDateDeposit) order by deposits.created_at ASC
									";
					$runDeposit = mysqli_query($link, $sqlDeposit);
						if($runDeposit === FALSE){
						die(mysqli_error("SQL DIE! Error for SQL: ".$sqlDeposit));
					}
				}
				else if($report_type == "Rental" || $report_type == "Water" ){
					if($statementby == "statement_year"){
						 
							  $sqlReport = "select count(tenants.id) as countTenant,  properties.unit_no, properties.id as property_id 
										 from bills
										inner join tenants on bills.tenant_id = tenants.id
										inner join properties on tenants.property_id = properties.id
										inner join locations on properties.location_id = locations.id
										inner join projects on locations.project_id = projects.id
										where bills.bill_type_id in ($bill_types_id,$bill_type_Outstanding) and locations.id = ". $_SESSION['location_id'] ."  and  YEAR(bills.issue_date) = $statement_year
										and projects.id =  $project_id  group by properties.id order by properties.id ASC";
					}
					else if($statementby == "statement_ChooseDate"){
						 $sqlReport = "select tenants.id as tenant_id
									from payments 
									inner join bills on payments.bill_id = bills.id
									inner join bill_types on bills.bill_type_id = bill_types.id
									inner join tenants on bills.tenant_id = tenants.id 
									inner join properties on tenants.property_id = properties.id
									inner join locations on properties.location_id = locations.id
									inner join projects on locations.project_id = projects.id
									inner join users on payments.created_by =  users.id
									where bills.bill_type_id in ($bill_types_id,$bill_type_Outstanding)  and locations.id = ". $_SESSION['location_id'] ." 
									and projects.id = $project_id and ($sqlDate) GROUP BY tenants.id
									
									";
					}
					else if($statementby == "statement_monthyear"){
						 $sqlReport = "select sum(payments.amount_paid) as total_amount_paid, count(payments.id) as count_payment,  tenants.id as tenant_id, tenants.tenant_name, properties.unit_no, bills.bill_amount, bills.issue_date, bills.id as bill_id
									from payments 
									inner join bills on payments.bill_id = bills.id
									inner join bill_types on bills.bill_type_id = bill_types.id
									inner join tenants on bills.tenant_id = tenants.id 
									inner join properties on tenants.property_id = properties.id
									inner join locations on properties.location_id = locations.id
									inner join projects on locations.project_id = projects.id
									inner join users on payments.created_by =  users.id
									where bills.bill_type_id in ($bill_types_id,$bill_type_Outstanding)  and locations.id = ". $_SESSION['location_id'] ."  
									and projects.id =  $project_id  and ($sqlDate) group by tenants.id order by properties.id ASC";
					}
					else if($statementby = "statement_date"){
						
						  	$sqlReport = "select count(tenants.id) as countPayment,tenants.id as tenant_id, tenants.tenant_name,  bills.bill_amount, sum(payments.amount_paid) as totalPaidByTenant,  properties.unit_no, properties.id as property_id 
										 from payments
										inner join bills on payments.bill_id = bills.id
										inner join tenants on bills.tenant_id = tenants.id 
										inner join properties on tenants.property_id = properties.id
										inner join locations on properties.location_id = locations.id
										inner join projects on locations.project_id = projects.id
										where bills.bill_type_id in ($bill_types_id,$bill_type_Outstanding)  and locations.id = ". $_SESSION['location_id'] ."  
										and projects.id =  $project_id  and ($sqlDate) group by tenants.id order by properties.id ASC";
					}
					else{
					     $sqlReport = "select payments.*, tenants.id as tenant_id, tenants.tenant_name, properties.unit_no, tenants.rental_rate, bills.issue_date,  users.name, locations.location_name,projects.project_name, bill_types.bill_type_name, bills.bill_type_id
									from payments 
									inner join bills on payments.bill_id = bills.id
									inner join bill_types on bills.bill_type_id = bill_types.id
									inner join tenants on bills.tenant_id = tenants.id 
									inner join properties on tenants.property_id = properties.id
									inner join locations on properties.location_id = locations.id
									inner join projects on locations.project_id = projects.id
									inner join users on payments.created_by =  users.id
									where bills.bill_type_id in ($bill_types_id,$bill_type_Outstanding)  and locations.id = ". $_SESSION['location_id'] ." 
									and projects.id = $project_id and ($sqlDate) order by payments.created_at ASC
									
									";
					}				
					$runReport= mysqli_query($link, $sqlReport);
					if($runReport=== FALSE){
						die(mysqli_error($link));
					}
				}
			}
			
			?>
			
            
            <!--main content upper start-->
			<?php include "main-content-upper.php"?>
            <!--main content upper end-->
			<!--main content middle start-->
						<div class="row" >
							<div class="card-body">
								<div class="row form-group">
									<!--<div class="col col-md-12">-->
									<div class="col-lg-12">
										<div class="card">
											<div class="card-header py-3">
												<h5 class="m-0 font-weight-bold text-primary">Search</h5>
											</div>
											<form action="<?php $_SERVER['PHP_SELF']; ?>" method="get" enctype="multipart/form data"  id="form_tenantStatement">
												<input type="hidden" name="projectLocation" value="<?php echo $_GET["projectLocation"]?>">
												<input type="hidden" name="menu" value="<?php echo $_GET["menu"]?>">
												<input type="hidden" name="submenu" value="<?php echo $_GET["submenu"]?>">
												<div class="card-body card-block">
													<input type="hidden" name="login" value="<?php echo $_GET["login"]?>">
													<div class="row form-group">
														<div class="col col-md-3">
															<label class=" form-control-label"><b>REPORT TYPE</b></label>
														</div>
														<div class="col col-md-9">
															<div class="form-check">
																<div class="radio">
																	<label for="radio1" class="form-check-label ">
																		<input type="radio" onChange = "change(this.value)" id="radio1" name="report_type" value="Deposit" class="form-check-input" <?php echo ($_SESSION["submenu"] == 'Deposit' || $_SESSION["report_type"] == 'Deposit' ? 'CHECKED' : '');?>> Deposit 
																	</label>
																</div>
																<div class="radio">
																	<label for="radio2" class="form-check-label ">
																		<input type="radio" onChange = "change(this.value)" id="radio2" name="report_type" value="Rental" class="form-check-input" <?php echo ($_SESSION["submenu"] == 'Rental' || $_SESSION["report_type"] == 'Rental' ? 'CHECKED' : '');?>> Rental   
																	</label>
																</div>
																<div class="radio">
																	<label for="radio3" class="form-check-label ">
																		<input type="radio" onChange = "change(this.value)" id="radio3" name="report_type" value="Water" class="form-check-input" <?php echo ($_SESSION["submenu"] == 'Water' || $_SESSION["report_type"] == 'Water' ? 'CHECKED' : '');?>> Water
																	</label>
																</div>
															</div>
														</div>
													</div>
													<div class="row form-group">
														<div class="col col-md-3">
															<label class=" form-control-label"><b>STATEMENT OPTION</b></label>
														</div>
														<div class="col col-md-9">
															<div class="form-check" >
																<?php 
																	$page = "report_all_payments.php";
																	include("statement_option.php"); 
																	?>
															</div>
														</DIV>
													</DIV>
												</div>	
												<div class="card-footer">		
													<div class="row form-group" >
														<div class="col col-md-9">
															<label for='text-input' class='form-control-label'>&nbsp;</label>
														</div>
														<div class="col col-sm-9">
															<button type="submit" name="searchStatement" onclick="submitFunc()" class="btn btn-primary btn-sm" >
																<i class="fa fa-dot-circle-o"></i> Submit
															</button>
															<button  onclick="resetFunc()"   name="resetStatement" class="btn btn-danger btn-sm">
																<i class="fa fa-ban"></i> Reset
															</button>
															 
														</div>
													</div>
												</div>
											</form>
										</div>												
									</div>
								</div>
								<div class="row form-group">
									<div class="col-lg-12" >
										<div class="card-header py-3">
											<h5 class="m-0 font-weight-bold text-primary">Showing Result</h5>
										</div>
										
										<div class="card-body card-block">
										
										<?php 
											if($report_type == "Deposit"){
												include "report_deposit.php";
											}
											else if($report_type == "Rental" || $report_type == "Water"){
												//echo "TEST 1111!!";
												include "report_rental.php";
											}
											else if($report_type == "Water"){
												include "report_water.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>
    <?PHP include "footerLink.php";?>
</body>
</html>
<!-- end document-->
<script>
function change(x){
	//document.getElementById('statementby').removeA
}
function submitFunc(){ //alert("SUBMIT BUTTON!!!");
	if(document.getElementById("statementby").value== 'statement_year'){
		
		document.getElementById("statement_year").setAttribute("required","required");
		document.getElementById("statement_monthyear").removeAttribute("required");
		document.getElementById("dateFrom").removeAttribute("required");
		document.getElementById("dateTo").removeAttribute("required");
		document.getElementById("statement_ChooseDate").removeAttribute("required");
		
		if(document.getElementById("statement_year").value =='')
			alert("Please select Year");
		else{
			//document.getElementById("statement_year").value ='';
			document.getElementById("statement_monthyear").value ='';
			document.getElementById("dateFrom").value ='';
			document.getElementById("dateTo").value ='';
			document.getElementById("statement_ChooseDate").value ='';
			document.getElementById("form_tenantStatement").submit();
		}
	}
	else if(document.getElementById("statementby").value== 'statement_monthyear'){
		
		document.getElementById("statement_year").removeAttribute("required");
		document.getElementById("statement_monthyear").setAttribute("required","required");
		document.getElementById("dateFrom").removeAttribute("required");
		document.getElementById("dateTo").removeAttribute("required");
		document.getElementById("statement_ChooseDate").removeAttribute("required");
		
		if(document.getElementById("statement_monthyear").value =='')
			alert("Please select Month/Year");
		else{
			document.getElementById("statement_year").value ='';
			//document.getElementById("statement_monthyear").value ='';
			document.getElementById("dateFrom").value ='';
			document.getElementById("dateTo").value ='';
			document.getElementById("statement_ChooseDate").value ='';
			document.getElementById("form_tenantStatement").submit();
		}
	}
	else if(document.getElementById("statementby").value== 'statement_date'){
		
		document.getElementById("statement_year").removeAttribute("required");
		document.getElementById("statement_monthyear").removeAttribute("required");
		document.getElementById("dateFrom").setAttribute("required","required");
		document.getElementById("dateTo").setAttribute("required","required");
		document.getElementById("statement_ChooseDate").removeAttribute("required");
		
		if(document.getElementById("dateFrom").value =='' || document.getElementById("dateTo").value =='')
			alert("Please choose date");
		else{
			document.getElementById("statement_year").value ='';
			document.getElementById("statement_monthyear").value ='';
			//document.getElementById("dateFrom").value ='';
			//document.getElementById("dateTo").value ='';
			document.getElementById("statement_ChooseDate").value ='';
			document.getElementById("form_tenantStatement").submit();
		}
	}
	else if(document.getElementById("statementby").value== 'statement_ChooseDate'){
		document.getElementById("statement_year").removeAttribute("required");
		document.getElementById("statement_monthyear").removeAttribute("required");
		document.getElementById("dateFrom").removeAttribute("required");
		document.getElementById("dateTo").removeAttribute("required");
		document.getElementById("statement_ChooseDate").setAttribute("required","required");
		
		if(document.getElementById("statement_ChooseDate").value =='')
			alert("Please select date");
		else{
			document.getElementById("statement_year").value ='';
			document.getElementById("statement_monthyear").value ='';
			document.getElementById("dateFrom").value ='';
			document.getElementById("dateTo").value ='';
			//document.getElementById("statement_ChooseDate").value ='';
			document.getElementById("form_tenantStatement").submit();
		}
	} 
}

	function resetFunc(){ //alert();
		var selectStatement = document.getElementById("statementby").value;
		
		document.getElementById('statement_ByYear').style.display ='none';
		document.getElementById('statement_ByMonthYear').style.display ='none';
		document.getElementById('statement_ByDate').style.display ='none';
		document.getElementById('statement_cutOff').style.display ='none';
		document.getElementById('statement_ByChooseDate').style.display ='none';
		//selectStatement.selectedIndex = 0;
		selectStatement.value = "";
		//alert(selectStatement.selectedIndex);
		//document.getElementById("statementOption").reset();
		
		
		document.getElementById("radio1").checked = false;
		document.getElementById("radio2").checked = false;
		document.getElementById("radio3").checked = false;
		document.getElementById("form_tenantStatement").reset();
	}
</script>