<?php	

	require_once 'portal_session.php';
	require_once 'portal_utilities.php';
    include 'header.php';	

	//$MemberLeases=$session->dbObject->getTenantLeases($_SESSION['session_userid']);	
    //require_once 'portal_database2024.php';
    $session = new Session();
	$LoggedInUserID = $_SESSION['session_userid'];
    $utilObject = new PortalUtilities($session->dbObject->logger, $session->dbObject);

	$MemberLeases=$session->dbObject->getTenantLeases($LoggedInUserID);	


    // ok, we have the leases.  we need to get the details and prepare them for the output items.
	$LeaseTableHeader = "<h1 class='text-center'>Your Rental Kharma Reporting History</h1>";

	$MemberUploadStatistics = $session->dbObject->getUploadStatistics($LoggedInUserID);


	$UploadTime = "<h2 class='text-center'> ";
	if ($MemberUploadStatistics['FirstUploadEver'] == null)
	{ 
		$UploadTime .= "We haven't uploaded any rental data for you yet. <br> Come back here in a few days and when we upload your rental information, you'll see it here.</h2>";
	} else {
		$UploadTime .= "We have been uploading your rental data for ";
		if ($MemberUploadStatistics['UploadingYears'] != '0') {
			if ($MemberUploadStatistics['UploadingYears'] != 1) {
				$UploadTime .= $MemberUploadStatistics['UploadingYears']. " years, ";
			} else {
				$UploadTime .= $MemberUploadStatistics['UploadingYears']. " year, ";			
			}
			if ($MemberUploadStatistics['UploadingMonths'] != 1) {
				$UploadTime .= $MemberUploadStatistics['UploadingMonths']. " months and ";
			} else {
				$UploadTime .= $MemberUploadStatistics['UploadingMonths']. " month and ";			
			}
		} else 
		{
			if ($MemberUploadStatistics['UploadingMonths'] != '0') {
				if ($MemberUploadStatistics['UploadingMonths'] != 1) {
					$UploadTime .= $MemberUploadStatistics['UploadingMonths']. " months and ";
				} else {
					$UploadTime .= $MemberUploadStatistics['UploadingMonths']. " month and";			
				}
			}
		}
		if ($MemberUploadStatistics['UploadingDays'] != 1) {
			$UploadTime .= $MemberUploadStatistics['UploadingDays']. " days.";
		} else {
			$UploadTime .= $MemberUploadStatistics['UploadingDays']. " day.";
		}

	}
	$UploadTime .= "</h2>";
	// 
	
	$LeaseTableHeader .= $UploadTime;

	if (count($MemberLeases) == 0) {
		$LeaseTableHeader .= "<h2 class='text-center'>Rental Kharma has not reported any leases for you. </h2>";
	}
	if (count($MemberLeases) == 1) {
		$LeaseTableHeader .="<h2 class='text-center'>Rental Kharma is reporting 1 lease for you: </h2>";
	} 
	if (count($MemberLeases) > 1) {
		$LeaseTableHeader .="<h2 class='text-center'>Rental Kharma is reporting ".count($MemberLeases)." leases for you: </h2>";
	} 
	
	$MonthlyUpdateSubscriptionTable = $utilObject->MembershipReportingGrid($LoggedInUserID);
    // ok, we have the leases.  we need to get the details and prepare them for the output items.
    ?>
	<style>
	.myTest { color: #008800; }
	</style>
    <div class='content'>
		<div class="mobile-content">
			<h3 class='text-center'>Membership info:</h3>
			<?php print $MonthlyUpdateSubscriptionTable; ?>
		</div>
		<div class="wide-content">                    
			<h3 class='text-center'>Membership info:</h3>
			<?php print $MonthlyUpdateSubscriptionTable; ?>
		</div>
		<?php 
		$shownHeader = 0;
		foreach ($MemberLeases as $ThisLease) { 
			if ($shownHeader == 0) {
				$LeaseTableHeader .= $utilObject->LeaseHeader($ThisLease['LeaseID']);
				$shownHeader = 1;
			} else {
				$LeaseTableHeader = $utilObject->LeaseHeader($ThisLease['LeaseID']);
			}
			//print $LeaseTableHeader;
			$MonthlyPaymentDetails = $session->dbObject->getLeasePaymentGrid($ThisLease['LeaseID']);
			
			//$session->dbObject->logger->logDebug("First lease to getLeasePaymentGrid info about is ".$ThisLease['LeaseID']);
			//$session->dbObject->logger->logDebug("MonthlyPaymentDetails results: ".print_r($MonthlyPaymentDetails,true));
		
		
		
			$LeasePaymentTable_Mobile = $utilObject->PaymentReportingGrid($ThisLease['LeaseID'], $ThisLease['USPSAddress1'], $ThisLease['USPSAddress2'],"m");       
			$LeasePaymentTable_Desktop = $utilObject->PaymentReportingGrid($ThisLease['LeaseID'], $ThisLease['USPSAddress1'], $ThisLease['USPSAddress2'],"d");       
			//print $LeasePaymentTable;
			
			
			print "<div class='mobile-content'>";
			print $LeaseTableHeader."<br>";
			print $LeasePaymentTable_Mobile;
			print "</div>";
			print "<div class='wide-content'>";
			print $LeaseTableHeader."<br>"; 
			print $LeasePaymentTable_Desktop;
			print "</div>";
			
		}
		?>
	
		

	</div>

    <?php 
//	print $utilObject->PaymentReportingGridJavascript(); 
	?>
	  <script lang='javascript'>
	
         /* When the user clicks on div, open the popup */
		 
		 
        function popupMonthInfo(_PaymentID, _LeaseID) {   
		
        	var PopupID = 'gridPopup_' + _PaymentID;
        	var ClickedMonth = document.getElementById(PopupID);
        	if (ClickedMonth.classList.contains('show')) {
        		ClickedMonth.classList.remove('show');
        	} else {
				
        		var AllMonths = document.getElementsByName('PaymentGridPopup');
        		for(var i=0; i < AllMonths.length; i++) {
        			AllMonths[i].classList.remove('show');
        		}
				
        		ClickedMonth.classList.add('show');
				
        	}
        }

			
	document.addEventListener("DOMContentLoaded", function() {
	setActive("home")
	// You can now safely manipulate elements, attach event listeners, etc.
	});
        </script>
        
<?php include "footer.php"; ?>