// HTML include another HTML
function includeHTML() {
var z, i, elmnt, file, xhttp;
/*loop through a collection of all HTML elements:*/
z = document.getElementsByTagName("*");
for (i = 0; i < z.length; i++) {
elmnt = z[i];
/*search for elements with a certain attribute:*/
file = elmnt.getAttribute("w3-include-html");
if (file) {
/*make an HTTP request using the attribute value as the file name:*/
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4) {
if (this.status == 200) { elmnt.innerHTML = this.responseText; }
if (this.status == 404) { elmnt.innerHTML = "Page not found."; }
/*remove the attribute, and call this function once more:*/
elmnt.removeAttribute("w3-include-html");
includeHTML();
}
}
xhttp.open("GET", file, true);
xhttp.send();
/*exit the function:*/
return;
}
}
};
// for getting user information on each page
function getUserInfo() {
var xmlhttp1;
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("GET", baseurl + "/landlord/getuserinfo", true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
var user = document.getElementById("profile_name");
user.innerHTML = res.response;
var landlordName = document.getElementById('landlord_name');
if (landlordName) landlordName.innerText = res.response;
} else if ((this.status == 403 || this.status == 401) && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/login.html"
} else if (this.status == 500) {
var res = JSON.parse(this.responseText);
if (res.response === "403 FORBIDDEN") {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/login.html"
}
}
};
xmlhttp1.send();
}
// format Date
function formatDate(nonFormatDate) {
// checking for null condition -- error undefinded
if (nonFormatDate == null || nonFormatDate == "") {
return nonFormatDate;
} else {
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var date = nonFormatDate.split("-");
return (months[Number(date[1]) - 1] + " " + date[2] + ", " + date[0]);
}
}
// login function
function initLogin() {
var email = $("#username").val();
var pass = $("#password").val();
var xmlhttpAuth;
try {
xmlhttpAuth = new XMLHttpRequest();
} catch (e) {
try {
xmlhttpAuth = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttpAuth = new ActiveXObject(
"Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttpAuth.open("POST", baseurl + "/authentication/getGenericJWTToken", true);
xmlhttpAuth.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttpAuth.setRequestHeader('clientID', landlordClientId);
xmlhttpAuth.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "" && this.readyState == 4) {
var res = JSON.parse(this.responseText);
if (res.token != "Invalid User or Password / Or Account Locked") {
localStorage.setItem('token', res.token);
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/index.html";
} else {
$("#error_message").show();
$("#error_message").html("Invalid User or Password / Or Account Locked ");
}
}
}
xmlhttpAuth.send(JSON.stringify({
"username": email,
"password": pass
}));
}
function signout() {
window.localStorage.removeItem("token");
// window.location.reload();
}
function addClassOnToggle() {
var toggleClicked = document.body.classList.contains('toggle-sidebar');
if (toggleClicked) {
document.body.classList.remove('toggle-sidebar');
// console.log(toggleClicked)
} else {
document.body.classList.add('toggle-sidebar');
// console.log(toggleClicked)
}
}
// sending reset password mail once manager creates account for landlord
function sendResetPassMail(clientId) {
var webBaseURL = window.location.protocol + "//" + window.location.host;
var email = document.getElementById("username").value;
document.getElementById('username').innerHTML = "";
if (!email) {
document.getElementById('username_error').innerHTML = "This field is mandatory"
document.getElementById('username').focus();
return false;
}
var xmlhttp;
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp.open("POST", baseurl + "/rentalunsecured/sendresetpassmail?emailID=" + email + "&webBaseURL="
+ webBaseURL + "&clientId=" + clientId, true);
xmlhttp.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
var response = res.response;
// Getting errors on fields
var s = res.rspnsMsg;
var s = s.replace(/[{}]/g, "");
const obj = Object.fromEntries([s.split("=")])
if (obj.error == "Invalid Mail Id!!") {
var error = document.getElementById("username_error");
error.innerHTML = obj.error;
}
if (response == "ERROR SENDING RESET MAIL") {
$('#success_message').hide()
$('#error_msg').show()
$('#error_msg').html(response);
} else if (response == "PASSWORD RESET EMAIL SEND TO USER") {
$('#error_msg').hide();
$('#success_message').show()
} else if (response == "Please enter email id for which account has been created") {
$('#success_message').hide()
$('#error_msg').show()
$('#error_msg').html(response);
}
} else if ((this.status == 403 || this.status == 401) && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/forgot-password.html"
} else if (this.status == 500 && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/forgot-password.html"
}
};
xmlhttp.send();
}
function resetAccount(tokenId, userId) {
var email = document.getElementById("email").value;
var firstName = document.getElementById("firstName").value;
var lastName = document.getElementById("lastName").value;
var password = document.getElementById("password").value;
var confirmPassword = document.getElementById("confirmPassword").value;
if (!firstName) {
document.getElementById('firstname_error').innerHTML = "This field is mandatory"
document.getElementById('firstName').focus();
return false;
}
if (!lastName) {
document.getElementById('lastname_error').innerHTML = "This field is mandatory"
document.getElementById('lastName').focus();
return false;
}
if (!email) {
document.getElementById('email_error').innerHTML = "This field is mandatory"
document.getElementById('email').focus();
return false;
}
if (!password) {
document.getElementById('password_error').innerHTML = "This field is mandatory"
document.getElementById('password').focus();
return false;
}
if (!confirmPassword) {
document.getElementById('confirmpass_error').innerHTML = "This field is mandatory"
document.getElementById('confirmPassword').focus();
return false;
}
if (!password) {
document.getElementById('confirmpass_error').innerHTML = "Confirm Password does not matches password"
document.getElementById('confirmPassword').focus();
return false;
}
var xmlhttp1;
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("POST", baseurl + "/rentalunsecured/resetlandlordaccount?tokenID=" + tokenId
+ "&user_id=" + userId, true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
var response = res.response;;
// console.log(response);
if (response == "PASSWORD UPDATED SUCCESSFULLY") {
$('#error_msg').hide();
$('#success_message').show()
var submitBtn = $("#login_form_submit");
submitBtn.prop('disabled', true);
} else {
$('#success_message').hide()
$('#error_msg').show();
}
} else if ((this.status == 403 || this.status == 401) && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/error.html"
} else if (this.status == 500 && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/error.html"
}
};
xmlhttp1.send(JSON.stringify({
"emailID": email,
"firstName": firstName,
"lastName": lastName,
"password": password,
"roles": []
}));
}
function addStyleOnSideMenu(navLinkId) {
var docElement = navLinkId + " " + "a"
setTimeout(function () { $(docElement).removeClass("collapsed"); }, 100)
var ulElement = navLinkId + " ul"
setTimeout(function () { $(ulElement).addClass("show"); }, 100)
var ind = location.pathname.lastIndexOf('/');
var href = location.pathname.slice(ind + 1);
// console.log(href);
setTimeout(function () { $("#sidebar").find('a[href="' + href + '"]').addClass("active") }, 100)
}
function resetPassword(tokenId, userId) {
var password = document.getElementById("password").value;
var confirmPassword = document.getElementById("confirmPassword").value;
if (!password) {
document.getElementById('password_error').innerHTML = "This field is mandatory"
document.getElementById('password').focus();
return false;
}
if (!confirmPassword) {
document.getElementById('confirmpass_error').innerHTML = "This field is mandatory"
document.getElementById('confirmPassword').focus();
return false;
}
if (password != confirmPassword) {
document.getElementById('confirmpass_error').innerHTML = "Confirm Password does not matches password"
document.getElementById('confirmPassword').focus();
return false;
}
var xmlhttp1;
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("POST", baseurl + "/rentalunsecured/resetpassword?tokenID=" + tokenId
+ "&user_id=" + userId + "&clientId=" + landlordClientId, true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
var response = res.response;;
if (response == "PASSWORD UPDATED SUCCESSFULLY") {
$('#error_msg').hide();
$('#success_message').show()
var submitBtn = $("#login_form_submit");
submitBtn.prop('disabled', true);
} else {
$('#success_message').hide()
$('#error_msg').show();
}
} else if ((this.status == 403 || this.status == 401) && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/error.html"
} else if (this.status == 500 && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/error.html"
}
};
xmlhttp1.send(JSON.stringify({
"emailID": userId,
"password": password,
"roles": []
}));
}
function getuserprofiledetails() {
var xmlhttp1;
var firstName = document.getElementById("userFirstName");
var lastName = document.getElementById("userLastName");
var Email = document.getElementById("userEmail");
var Phone = document.getElementById("userPhone");
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("GET", baseurl + "/landlord/getuserprofiledetails", true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
if (res.rspnsCode === 1000) {
var response = JSON.parse(res['response']);
firstName.innerHTML = response['firstName'];
lastName.innerHTML = response['lastName'];
Email.innerHTML = response['emailID'];
Phone.innerHTML = response['phoneNumber'];
document.getElementById("FirstName").value = response.firstName;
document.getElementById("LastName").value = response.lastName;
document.getElementById("Email").value = response.emailID;
document.getElementById("Phone1").value = response.phoneNumber
}
} else if ((this.status == 403 || this.status == 401) && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/login.html"
} else if (this.status == 500) {
var res = JSON.parse(this.responseText);
if (res.response === "403 FORBIDDEN") {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/login.html"
}
}
};
xmlhttp1.send();
}
// this ajax is for edit profile for landlord
function editProfileLanlord() {
var xmlhttp1;
var FirstName = document.getElementById("FirstName").value;
var LastName = document.getElementById("LastName").value;
var Email = document.getElementById("Email").value;
var Phone1 = document.getElementById("Phone1").value;
document.getElementById('FirstName_error').innerHTML = "";
document.getElementById('LastName_error').innerHTML = "";
document.getElementById('Email_error').innerHTML = "";
document.getElementById('phone1_error').innerHTML = "";
if (FirstName == null || FirstName == "") {
document.getElementById('FirstName_error').innerHTML = "This field is mandatory"
document.getElementById('FirstName').focus();
return false;
}
if (LastName == null || LastName == "") {
document.getElementById('LastName_error').innerHTML = "This field is mandatory"
document.getElementById('LastName').focus();
return false;
}
if (Email == null || Email == "") {
document.getElementById('Email_error').innerHTML = "This field is mandatory"
document.getElementById('Email').focus();
return false;
}
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("POST", baseurl + "/landlord/editlandlordprofile", true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
var response = res.response;
var s = res.rspnsMsg;
var s = s.replace(/[{}]/g, "");
let pairs = s.split(', ')
let obj = pairs.reduce((obj, data) => {
let [k, v] = data.split('=')
obj[k] = v
return obj
}, {})
if (response == "EDIT PROFILE SUCCESSFULLY") {
$('#basicModal').modal("show");
$("#modal_message").html("
Your Account has been updated.
");
$("#modal_title").html("SUCCESS!! ");
}
else {
$('#basicModal').modal("show");
$("#modal_message").html("Something went wrong.
");
$("#modal_title").html("OOPs!! ");
}
} else if ((this.status == 403 || this.status == 401) && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/pages-error-404.html"
} else if (this.status == 500 && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/pages-error-404.html"
}
};
xmlhttp1.send(JSON.stringify({
"emailID": Email,
"firstName": FirstName,
"lastName": LastName,
"phoneNumber": Phone1,
"roles": []
}));
}
// this ajax is for change password
function changeLandlordPassword() {
var xmlhttp1;
var currentPassword = document.getElementById("currentPassword").value;
var newPassword = document.getElementById("newPassword").value;
var confirmPassword = document.getElementById("renewPassword").value;
document.getElementById('currentPassword_error').innerHTML = "";
document.getElementById('newPassword_error').innerHTML = "";
document.getElementById('renewPassword_error').innerHTML = "";
if (currentPassword == null || currentPassword == "") {
document.getElementById('currentPassword_error').innerHTML = "This field is mandatory"
document.getElementById('currentPassword').focus();
return false;
}
if (newPassword == null || newPassword == "") {
document.getElementById('newPassword_error').innerHTML = "This field is mandatory"
document.getElementById('newPassword').focus();
return false;
}
if (confirmPassword == null || confirmPassword == "") {
document.getElementById('renewPassword_error').innerHTML = "This field is mandatory"
document.getElementById('renewPassword').focus();
return false;
}
if (newPassword != confirmPassword) {
alert("Confirm Password not Same as New Password");
return false;
}
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("POST", baseurl + "/landlord/changelandlordpassword?currentPassword=" + currentPassword + "&newPassword=" + newPassword + "&confirmPassword=" + confirmPassword, true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
var response = res.response;
// console.log(response)
if (response == "PASSWORD CHANGED SUCCESSFULLY") {
$('#basicModal').modal("show");
$("#modal_message").html("Your password has been updated.
");
$("#modal_title").html("SUCCESS!! ");
} else {
$('#basicModal').modal("show");
$("#modal_message").html("Something went wrong.
");
$("#modal_title").html("OOPs!! ");
}
// console.log(response);
} else if ((this.status == 403 || this.status == 401) && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/login.html"
}
};
xmlhttp1.send();
}
function listLeaseDocs() {
var xmlhttp1;
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("GET", baseurl + "/landlord/listleasedocs", true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
if (res.rspnsCode === 1000) {
var response = JSON.parse(res['response']);
// console.log(response);
tableData = '';
if (response.length > 0) {
for (i = 0; i < response.length; i++) {
var propertyAddress = response[i].lease["houseNo"] + ", " + response[i].lease["streetAddress"] + ", " +
response[i].lease["city"] + ", " + response[i].lease["zip"] + ", " + response[i].lease["state"];
if (response[i].lease["leaseEndDate"] == null || response[i].lease["leaseEndDate"] == "") {
var leaseEndDate = "Not Mentioned"
} else {
var leaseEndDate = formatDateForTables(response[i].lease["leaseEndDate"])
}
tableData += '';
tableData += '' + (i + 1) + ' ';
tableData += '' + propertyAddress + ' ';
tableData += '' + ' ' + ' ';
tableData += '' + formatDateForTables(response[i].lease["leaseStartDate"]) + ' ';
tableData += '' + leaseEndDate + ' '
tableData += '' + response[i].lease["leaseTermType"] + ' '
tableData += '' + getDateInClientFormat(response[i].updateTimeStamp) + ' '
}
} else {
tableData += " No Lease Documents for now ";
}
}
document.getElementById('approvedLease').innerHTML = tableData;
}
};
xmlhttp1.send();
}
function getPropertyDetails() {
var xmlhttp1;
var properties = document.getElementById("properties");
var webBaseURL = window.location.protocol + "//" + window.location.host;
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("GET", baseurl + "/landlord/getproperties", true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
var temphtml = "";
if (res.rspnsCode === 1000) {
var response = JSON.parse(res['response']);
console.log(response);
for (var i = 0; i < response.length; i++) {
var s = JSON.parse(response[i].imageList);
var copyLink = webBaseURL + "" + "/propertydetails.html?propertyID=" + "" + response[i].propertyId;
var firstImage = s != null ? s[0].imageLink : "../admin/assets/img/img for card.jpg";
if (response[i].isPropertyRented) {
temphtml += `
$ ${response[i].propertyInfo.rentAmount}/ ${response[i].propertyInfo.rentalRate}
${response[i].propertyInfo.houseNo}
,
${response[i].propertyInfo.streetAddress}
,
${response[i].propertyInfo.city}
,
${response[i].propertyInfo.state}
-
${response[i].propertyInfo.zip}
,
${response[i].propertyInfo.country}
${response[i].propertyInfo.squareFeet} Sq Ft
${response[i].propertyInfo.bedrooms} Bedrooms
${response[i].propertyInfo.bathrooms} Bathrooms
${response[i].propertyInfo.furnishing}
${response[i].propertyInfo.carParking}
Covered
`;
} else {
temphtml += `
$ ${response[i].propertyInfo.rentAmount}/ ${response[i].propertyInfo.rentalRate}
${response[i].propertyInfo.houseNo}
,
${response[i].propertyInfo.streetAddress}
,
${response[i].propertyInfo.city}
,
${response[i].propertyInfo.state}
-
${response[i].propertyInfo.zip}
,
${response[i].propertyInfo.country}
${response[i].propertyInfo.squareFeet} Sq Ft
${response[i].propertyInfo.bedrooms} Bedrooms
${response[i].propertyInfo.bathrooms} Bathrooms
${response[i].propertyInfo.furnishing}
${response[i].propertyInfo.carParking}
Covered
`;
}
}
properties.innerHTML = temphtml;
}
} else if ((this.status == 403 || this.status == 401) && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/login.html"
} else if (this.status == 500) {
var res = JSON.parse(this.responseText);
if (res.response === "403 FORBIDDEN") {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/login.html"
}
}
};
xmlhttp1.send();
}
function getTransactionOfProperty() {
var propertyID = $('#propertyDropdown').val();
var fromDate = $('#fromDate').val();
var toDate = $('#toDate').val();
var from = $('#from').val();
var to = $('#to').val();
var xmlhttp1;
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
var path;
path = "/landlord/gettransactionbyproperty?propertyID=" + propertyID
if (from && to) {
path += "&from=" + from + "&to=" + to;
}
xmlhttp1.open("GET", baseurl + path, true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.readyState === 4) {
if (this.status === 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
if (res.rspnsCode === 1000) {
tableData = '';
var response = JSON.parse(res['response']);
console.log(response);
if (response.length > 0) {
for (i = 0; i < response.length; i++) {
var amountExp;
(response[i].transactionType == "Escrow Debit-Landlord" || response[i].transactionType == "Escrow Debit-PM") ?
(amountExp = `(${Number(response[i].amount).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')})
`) :
(amountExp = `(${Number(response[i].amount).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')})
`)
tableData += '';
tableData += '' + (i + 1) + ' ';
tableData += '' + formatDate(response[i].payDate) + ' ';
tableData += '' + ((response[i].details == '' || response[i].details == null) ? '-' : response[i].details) + ' ';
tableData += '' + response[i].name + ' ';
tableData += '' + ((response[i].account == '' || response[i].account == null) ? '-' : (response[i].account)) + ' ';
tableData += '' + response[i].transactionType + ' ';
tableData += '' + amountExp + ' ';
}
} else {
tableData = " No transactions for now "
}
}
document.getElementById('transaction_table').innerHTML = tableData;
}
}
};
xmlhttp1.send();
}
function getPropertyList() {
var xmlhttp1;
var properties = document.getElementById("propertyDropdown");
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("GET", baseurl + "/landlord/getproperties", true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
var temphtml = "";
if (res.rspnsCode === 1000) {
var response = JSON.parse(res['response']);
console.log(response);
for (var i = 0; i < response.length; i++) {
temphtml += `${response[i].propertyInfo["houseNo"] + ", " + response[i].propertyInfo["streetAddress"] + ", " +
response[i].propertyInfo["city"] + ", " + response[i].propertyInfo["zip"] + ", " + response[i].propertyInfo["state"] + ", " + response[i].propertyInfo["country"]} `
}
properties.innerHTML = temphtml;
}
} else if ((this.status == 403 || this.status == 401) && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/login.html"
} else if (this.status == 500) {
var res = JSON.parse(this.responseText);
if (res.response === "403 FORBIDDEN") {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/login.html"
}
}
};
xmlhttp1.send();
}
function getEscrowDetails() {
var propertyID = $('#propertyDropdown').val();
var fromDate = $('#fromDate').val();
var toDate = $('#toDate').val();
var from = $('#from').val();
var to = $('#to').val();
var xmlhttp1;
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
var path;
path = "/landlord/gettransactiondetailsbyproperty?propertyID=" + propertyID
if (from && to) {
path += "&payment_date_from=" + from + "&payment_date_to=" + to;
}
xmlhttp1.open("GET", baseurl + path, true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.readyState === 4) {
if (this.status === 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
if (res.rspnsCode === 1000) {
var response = JSON.parse(res['response']);
console.log(response[0].totalEscrowCredit);
var dynamicCard = document.querySelector('.summary_card');
let totalEscrowCredit = (response[0].totalEscrowCredit);
let totalEscrowDebit = (response[0].totalEscrowDebit);
let remainingBalance = totalEscrowCredit - totalEscrowDebit;
// for (i = 0; i < response.length; i++) {
dynamicCard.innerHTML = `
Credit
$${totalEscrowCredit}
Debit
$${totalEscrowDebit}
Remaining Balance
$${remainingBalance}
`;
// }
}
// document.getElementById('transaction_table').innerHTML = tableData;
}
}
};
xmlhttp1.send();
}
function fetchLandlordFaq() {
const xhttp = new XMLHttpRequest();
xhttp.onload = function () {
let s = this.responseText;
let Answer = "";
let Question = "";
let mode = "Q";
var faqsbody = document.getElementById("faq-group-2");
let faqhtml = "";
let faqid = 0;
for (i = 0; i < s.length; i++) {
if (s.charAt(i) == "#") {
// document.getElementById("Answer").innerHTML=' '+Answer;
faqhtml += `
`;
Question = "";
mode = "Q";
} else if (s.charAt(i) == ">") {
faqhtml += `
`;
Answer = "";
mode = "A";
} else {
if (mode == "Q") {
Question += s.charAt(i);
} else {
Answer += s.charAt(i);
}
}
}
faqhtml += `
`;
faqsbody.innerHTML = faqhtml;
};
xhttp.open("GET", "faq.md", true);
xhttp.send();
}
function formatDateForTables(nonFormatDate) {
// checking for null condition -- error undefinded
if (nonFormatDate == null || nonFormatDate == "") {
return nonFormatDate;
} else {
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var date = nonFormatDate.split("-");
var day = date[2].split(" ");
return (months[Number(date[1]) - 1] + " " + day[0] + ", " + date[0]);
}
}
function getDateInClientFormat(dValue) {
if (dValue.length > 10) {
var date = new Date(dValue + " UTC").toString().replace("/", "-");;
var finalDate = date.substring(4, 10) + ", " + date.substring(11, 15) + " " + date.substring(16, 21);
// console.log(date)
return finalDate;
} else {
if (dValue == null || dValue == "") {
return dValue;
} else {
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var date = dValue.split("-");
// console.log(date)
return (months[Number(date[1]) - 1] + " " + date[2] + ", " + date[0]);
}
}
}
function copyText(copyLink) {
var body = $(window.document.body);
var textarea = $('');
textarea.css({
position: 'fixed',
opacity: '0'
});
textarea.val(copyLink);
body.append(textarea);
textarea[0].select();
try {
var successful = document.execCommand('copy');
if (!successful)
throw successful;
else
alert(message);
} catch (err) {
window.prompt("Copy to clipboard: Ctrl+C, Enter", copyLink);
}
textarea.remove();
}
function getTransactionDetailByID(propertyID, fromDate, toDate) {
var xmlhttp;
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
var path = "/landlord/gettransactionbyproperty?propertyID=" + propertyID;
if (fromDate && toDate) {
path += "&from=" + fromDate + "&to=" + toDate;
}
xmlhttp.open("GET", baseurl + path, true);
xmlhttp.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp.onreadystatechange = function () {
if (this.readyState === 4) {
if (this.status === 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
if (res.rspnsCode === 1000) {
tableData = '';
var response = JSON.parse(res['response']);
console.log(response);
if (response.length > 0) {
for (var i = 0; i < response.length; i++) {
var amountExp = '';
tableData += '';
tableData += '' + (i + 1) + ' ';
tableData += '' + formatDate(response[i].payDate) + ' ';
tableData += '' + ((response[i].details == '' || response[i].details == null) ? '-' : response[i].details) + ' ';
tableData += '' + response[i].name + ' ';
tableData += '' + ((response[i].account == '' || response[i].account == null) ? '-' : response[i].account) + ' ';
tableData += '' + response[i].transactionType + ' ';
tableData += '' + response[i].transactionSubType + ' ';
tableData += '' + response[i].amount + ' ';
tableData += ' ';
}
} else {
tableData = "No transactions for now ";
}
}
document.getElementById('transaction_table').innerHTML = tableData;
}
}
};
xmlhttp.send();
}
function getTransactionSummary(propertyID, fromDate, toDate) {
var xmlhttp;
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
var path = "/landlord/gettransactiondetailsbyproperty?propertyID=" + propertyID;
if (fromDate && toDate) {
path += "&from=" + fromDate + "&to=" + toDate;
}
xmlhttp.open("GET", baseurl + path, true);
xmlhttp.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp.onreadystatechange = function () {
if (this.readyState === 4) {
if (this.status === 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
if (res.rspnsCode === 1000) {
var response = JSON.parse(res['response']);
var tenantBalance = response[0].tenantBalance;
var propertyLiabilities = response[0].propertyLiabilities;
var cardHTML = `
Balance:
$${tenantBalance}
Property Liabilities:
$${propertyLiabilities}
`;
document.getElementById("transaction_card").innerHTML = cardHTML;
}
}
}
};
xmlhttp.send();
}
function listLease(pageNumber) {
var pageSize = $('#pageSize').val();
var xmlhttp1;
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("GET", baseurl + "/landlord/listleases?pageNumber=" + pageNumber + "&pageSize=" + pageSize, true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.readyState === 4) {
if (this.status === 200) {
try {
var res = JSON.parse(this.responseText);
if (res.rspnsCode === 1000) {
var response = JSON.parse(res.response);
var tableData = '';
if (response.length > 0) {
for (var i = 0; i < response.length; i++) {
var leaseType = response[i].leaseType;
var link;
if (leaseType === "RESIDENTIAL") {
link = "/landlord/submitted-lease.html?leaseID=" + response[i].leaseID + "&pageName=" + leaseType;
} else {
link = "/landlord/submitted-generic-lease.html?leaseID=" + response[i].leaseID + "&pageName=" + leaseType;
}
var lease = response[i].lease || {};
var propertyAddress = lease.houseNo + ", " + lease.streetAddress + ", " +
lease.city + ", " + lease.zip + ", " + lease.state;
tableData += `
${(pageNumber - 1) * pageSize + (i + 1)}
${response[i].name}
${propertyAddress}
${getDateInClientFormat(response[i].updateTimeStamp)}
`;
}
} else {
tableData = "No Submitted Leases for now ";
}
}
} catch (error) {
console.error("Error parsing JSON response:", error);
}
}
document.getElementById('submitted-leases').innerHTML = tableData;
}
};
xmlhttp1.send();
}
function getSubmittedleaseNumber(navLinkId) {
if (navLinkId == null) {
var xmlhttp1;
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("GET", baseurl + "/landlord/listleases", true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
if (res.rspnsCode === 1000) {
var response = JSON.parse(res['response']);
// console.log(response);
}
document.getElementById('submittedLease').innerHTML = response.length;
}
};
xmlhttp1.send();
}
// else {
// return new Promise(function (resolve, reject) {
// // this should not be changed
// const type = "SubmittedLeaseType";
// var xmlhttp1;
// try {
// xmlhttp1 = new XMLHttpRequest();
// } catch (e) {
// try {
// xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
// } catch (e) {
// try {
// xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
// } catch (e) {
// alert("BROWSER BROKE");
// return false;
// }
// }
// }
// xmlhttp1.open("GET", baseurl + "/rentaladmin/getcount?type=" + type, true);
// xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
// xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
// xmlhttp1.onreadystatechange = function () {
// if (this.status == 200 && this.responseText != null && this.responseText != "") {
// var res = JSON.parse(this.responseText);
// if (res.rspnsCode === 1000) {
// var response = JSON.parse(res['response']);
// // console.log(response);
// }
// // document.getElementById('applicant_number').innerHTML = response.length;
// resolve(response);
// }
// };
// xmlhttp1.send();
// })
// }
}
function getLeaseDetailsSecured(leaseID, page, type) {
var xmlhttp1;
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("GET", baseurl + "/landlord/getlease?leaseID=" + leaseID, true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
if (res.rspnsCode === 1000) {
var response = JSON.parse(res['response']);
// console.log(type);
document.getElementById("houseNo").value = response.houseNo;
document.getElementById("streetAddress").value = response.streetAddress;
document.getElementById("zip").value = response.zip;
document.getElementById("city").value = response.city;
document.getElementById("state").value = response.state;
document.getElementById("country").value = response.country;
document.getElementById("fullName").value = response.name;
document.getElementById("mail").value = response.email;
document.getElementById("phone_no").value = response.phoneNo;
document.getElementById("principalOwner").value = response.principalOwner;
document.getElementById("rentAmount").value = response.rentAmount;
document.getElementById("rentPayDate").value = response.rentPayDate;
if (page == null) {
document.getElementById("signOfTenant").value = response.signOfTenant;
document.getElementById("submitDate").value = getDateInClientFormat(response.submitDate);
}
if (type === "RESIDENTIAL") {
document.getElementById("owner").value = response.rentTo;
document.getElementById("tenant").value = response.tenant;
document.getElementById("leaseTermType").value = response.leaseTermType;
document.getElementById("leaseStartDate").value = formatDate(response.leaseStartDate);
document.getElementById("leaseEndDate").value = formatDate(response.leaseEndDate);
if (response.leaseTermType == "Month-By-Month") {
$("#leaseEndDateBox").hide();
}
document.getElementById("percentElectricityBill").value = response.percentElectricityBill;
document.getElementById("electricityBillAmount").value = response.electricityBillAmount;
document.getElementById("percentWaterBill").value = response.percentWaterBill;
document.getElementById("waterBillAmount").value = response.waterBillAmount;
document.getElementById("percentPhoneBill").value = response.percentPhoneBill;
document.getElementById("phoneBillAmount").value = response.phoneBillAmount;
document.getElementById("percentOtherBill").value = response.percentOtherBill;
document.getElementById("otherBillAmount").value = response.otherBillAmount;
if (response.isHouseHoldRuleChecked) {
// pageUrl = "leaseaddendums/householdrules.html";
pageName = "household-rules.html";
loadAddendumsSecured(response, pageName);
}
if (response.isDepositsChecked) {
// pageUrl = "leaseaddendums/deposits.html";
pageName = "deposits.html";
loadAddendumsSecured(response, pageName);
}
if (response.isPaintDisclosureChecked) {
// pageUrl="leaseaddendums/paintdisclosure.html"
pageName = "paint-disclosure.html"
loadAddendumsSecured(response, pageName);
}
if (response.isConflictResolutionChecked) {
// pageUrl="leaseaddendums/conflictresolutions.html";
pageName = "conflict-resolutions.html"
loadAddendumsSecured(response, pageName);
}
if (response.isPrivacyChecked == true) {
// pageUrl="leaseaddendums/privacy.html";
pageName = "privacy.html";
loadAddendumsSecured(response, pageName);
// $("#privacy").load("admin/leaseaddendums/privacy.html");
}
if (response.isMegansLawChecked) {
pageName = "megans-law.html";
loadAddendumsSecured(response, pageName);
// $("#megans_law").load("leaseaddendums/meganlaw.html");
}
if (response.isOtherAgreementChecked) {
pageName = "other-agreements.html";
// pageUrl= "leaseaddendums/otheragreements.html";
loadAddendumsSecured(response, pageName);
}
}
if (type === "PAYING-GUEST") {
var leaseTermType = response.leaseTermType;
if (page == 'edit-lease') {
if (leaseTermType == "Month-to-Month") {
document.getElementById("monthtoMonthStartDate").value = (response.leaseStartDate);
} else if (leaseTermType == "Fixed-Term") {
document.getElementById("fixedTermStartDate").value = (response.leaseStartDate);
document.getElementById("fixedTermEndDate").value = (response.leaseEndDate);
} else {
document.getElementById("minObligationStartDate").value = response.leaseStartDate;
}
} else {
setInterval(function () {
$('#monthtoMonthStartDate').prop("type", "text");
$('#fixedTermStartDate').prop("type", "text");
$('#fixedTermEndDate').prop("type", "text");
$('#minObligationStartDate').prop("type", "text");
}, 1000);
if (leaseTermType == "Month-to-Month") {
setInterval(function () {
document.getElementById("monthtoMonthStartDate").value = formatDate(response.leaseStartDate);
}, 1000)
} else if (leaseTermType == "Fixed-Term") {
setInterval(function () {
document.getElementById("fixedTermStartDate").value = formatDate(response.leaseStartDate);
document.getElementById("fixedTermEndDate").value = formatDate(response.leaseEndDate);
}, 1000)
} else {
setInterval(function () {
document.getElementById("minObligationStartDate").value = formatDate(response.leaseStartDate);
}, 1000)
}
}
document.getElementById("permanentAddress").value = response.guestPermanentAddress;
if (response.leaseTermType != null && response.leaseTermType != "") {
document.querySelector(`input[name="leaseTermType"][value="${response.leaseTermType}"`).checked = true;
}
document.getElementById("monthtoMonthNoticePeriod").value = response.monthToMonthNoticePeriod;
document.getElementById("minimumObligationNoticePeriod").value = response.minimumObligationNoticePeriod;
document.getElementById("minimumObligationPeriod").value = response.minimumObligationPeriod;
document.getElementById("paymentMethod").value = response.paymentMethod;
// console.log(response.paymentMethod);
document.getElementById("fixedTermDuration").value = response.fixedTermDuration;
if (response.utilityExpenses != null && response.utilityExpenses != "") {
document.querySelector(`input[name="utilityExpenses"][value="${response.utilityExpenses}"`).checked = true;
}
}
if (type == "RESIDENTIAL-LEASE-1") {
if (page == 'edit-lease') {
document.getElementById("leaseStartDate").value = response.leaseStartDate;
document.getElementById("lastPaidDate").value = formatDateBack(response.lastPaidDate);
document.getElementById("securityDeposit").value = formatDateBack(response.securityDeposit);
document.getElementById("refundPaidDate").value = formatDateBack(response.refundPaidDate);
} else {
setInterval(function () {
$('#lastPaidDate').prop("type", "text");
$('#securityDeposit').prop("type", "text");
$('#refundPaidDate').prop("type", "text");
$('#leaseStartDate').prop("type", "text");
$('#leaseEndDate').prop("type", "text");
document.getElementById("lastPaidDate").value = response.lastPaidDate;
document.getElementById("securityDeposit").value = response.securityDeposit;
document.getElementById("refundPaidDate").value = response.refundPaidDate;
document.getElementById("leaseStartDate").value = formatDate(response.leaseStartDate);
}, 2000)
}
document.getElementById("rentTo").value = response.rentTo;
document.getElementById("tenant").value = response.tenant;
document.getElementById("leaseTermType").value = response.leaseTermType;
document.getElementById("leaseEndDate").value = formatDate(response.leaseEndDate);
if (response.leaseTermType == "Month-By-Month") {
$("#leaseEndDateBox").hide();
}
document.getElementById("percentElectricityBill").value = response.percentElectricityBill;
document.getElementById("electricityBillAmount").value = response.electricityBillAmount;
document.getElementById("percentWaterBill").value = response.percentWaterBill;
document.getElementById("waterBillAmount").value = response.waterBillAmount;
document.getElementById("percentPhoneBill").value = response.percentPhoneBill;
document.getElementById("phoneBillAmount").value = response.phoneBillAmount;
document.getElementById("percentOtherBill").value = response.percentOtherBill;
document.getElementById("otherBillAmount").value = response.otherBillAmount;
document.getElementById("cleaning").value = response.cleaning;
document.getElementById("kitchenUse").value = response.kitchenUse;
document.getElementById("overnightGuests").value = response.overnightGuests;
document.getElementById("useOfAppliances").value = response.useOfAppliances;
document.getElementById("smoking").value = response.smoking;
document.getElementById("useOfCommonAreas").value = response.useOfCommonAreas;
document.getElementById("alcoholUse").value = response.alcoholUse;
document.getElementById("telephoneUse").value = response.telephoneUse;
document.getElementById("studyingHours").value = response.studyingHours;
document.getElementById("personalItemsShared").value = response.personalItemsShared;
document.getElementById("music").value = response.music;
document.getElementById("bedroomAssignment").value = response.bedroomAssignment;
document.getElementById("pets").value = response.pets;
document.getElementById("other").value = response.other;
document.getElementById("lastPaidAmount").value = response.lastPaidAmount;
document.getElementById("securityAmount").value = response.securityAmount;
document.getElementById("refundDeposit").value = response.refundDeposit;
document.getElementById("refundDuration").value = response.refundDuration;
document.getElementById("leadBasedInput1").value = response.acknowledgedTenant1;
document.getElementById("leadBasedInput2").value = response.acknowledgedTenant2;
if (response.conflictResolution != null && response.conflictResolution != "") {
document.querySelector(`input[name="conflicResolution"][value="${response.conflictResolution}"`).checked = true;
}
document.getElementById("other_programs1").value = response.otherAgreements[0];
document.getElementById("other_programs2").value = response.otherAgreements[1];
document.getElementById("other_programs3").value = response.otherAgreements[2];
document.getElementById("other_programs4").value = response.otherAgreements[3];
document.getElementById("other_programs5").value = response.otherAgreements[4];
document.getElementById("other_programs6").value = response.otherAgreements[5];
document.getElementById("other_programs7").value = response.otherAgreements[6];
document.getElementById("other_programs8").value = response.otherAgreements[7];
document.getElementById("other_programs9").value = response.otherAgreements[8];
document.getElementById("other_programs10").value = response.otherAgreements[9];
document.getElementById("other_programs11").value = response.optionSelected;
if (response.copy != null && response.copy != "") {
document.querySelector(`input[name="other_radio"][value="${response.copy}"`).checked = true;
}
}
}
}
};
xmlhttp1.send();
}
// this is to approve submitted lease by landlord
function approveLease(leaseID) {
var principalOwnerSign = $("#property_owner_sign").val();
var agreementDay = $("#agreementDay").val();
var agreementMonth = $("#agreementMonth").val();
var agreementYear = $("#agreementYear").val();
var ip = $("#ipaddress").val();
var webBaseURL = window.location.protocol + "//" + window.location.host;
if (principalOwnerSign == null || principalOwnerSign == "") {
$("#sign_error").html("This field is required");
return false;
}
var xmlhttp1;
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("POST", baseurl + "/landlord/approvelease?leaseID=" + leaseID + "&sign=" + principalOwnerSign +
"&agreementDay=" + agreementDay + "&agreementMonth=" + agreementMonth + "&agreementYear=" + agreementYear + "&ip=" + ip +
"&webBaseURL=" + webBaseURL, true);
xmlhttp1.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "" && this.readyState == 4) {
var res = JSON.parse(this.responseText);
var res = res.response;
if (res == "SUCCESS") {
$('#basicModal').modal("show");
$("#modal_message").html("Lease Approved
");
$("#modal_title").html("SUCCESS!! ");
} else {
$('#basicModal').modal("show");
$("#modal_message").html(`${res}
`);
$("#modal_title").html("OOPS!! ");
}
// location.reload();
}
else {
var res = JSON.parse(this.responseText);
console.log(res.response);
if (res.response === "401 UNAUTHORIZED") {
$('#employee_modal_message').modal("show");
$("#modal_message_content").html("You are not authorised for this action
");
$("#employee_modal_title").html("OOPS!! ");
}
}
};
xmlhttp1.send();
}
function downloadLeasePdf(leaseID, name) {
var fileType = "lease";
var fileName = leaseID + "_lease.pdf";
var xmlhttp1;
try {
xmlhttp1 = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp1.open("POST", baseurl + "/rentalUploadDownload/secureLeaseDownloadRental?leaseID=" + leaseID
+ "&type=" + fileType, true);
xmlhttp1.responseType = 'arraybuffer';
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.status == 200 && this.readyState == 4) {
if (this.response.byteLength == 0) {
window.location.href = window.location.protocol + "//" + window.location.host + "/error.html";
} else {
var blob = new Blob([this.response], { type: "application/pdf" });
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
link.click();
}
}
};
xmlhttp1.send();
}
function getLandlordIPAddress() {
var xmlhttp;
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp.open("GET", baseurl + "/landlord/getuseripaddress", true);
xmlhttp.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
// var response = JSON.parse(res['response']);
// console.log(res.response);
document.getElementById("ipaddress").value = res.response
} else if ((this.status == 403 || this.status == 401) && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/login.html"
} else if (this.status == 500) {
var res = JSON.parse(this.responseText);
if (res.response === "403 FORBIDDEN") {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/login.html"
}
}
};
xmlhttp.send();
}
function listTransaction(year) {
var xmlhttp1;
if (window.XMLHttpRequest) {
xmlhttp1 = new XMLHttpRequest();
} else {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("Your browser does not support AJAX!");
return;
}
}
xmlhttp1.open("GET", baseurl + "/landlord/getlandlordtransaction?year=" + year, true);
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.onreadystatechange = function () {
if (this.readyState === 4) {
if (this.status === 200) {
try {
var res = JSON.parse(this.responseText); // outer JSON
if (res.rspnsCode === 1000 && res.response) {
var parsedResponse = JSON.parse(res.response); // inner JSON
console.log(parsedResponse);
var allTablesHtml = '';
let bucketCount = 0;
for (const bucketId in parsedResponse) {
bucketCount++;
const transactions = parsedResponse[bucketId];
if (!transactions.length) {
continue;
}
console.log(transactions[0].bucket_name);
let tableHtml = `
S.No
Date
Description
Debit
Credit
Running Balance
`;
transactions.forEach((txn, index) => {
const formattedDate = new Date(txn.date).toLocaleDateString();
tableHtml += `
${index + 1}
${formattedDate}
${txn.description}
${txn.debit}
${txn.credit}
${txn.running_balance}
`;
});
tableHtml += `
`;
allTablesHtml += tableHtml;
}
if (allTablesHtml === '') {
allTablesHtml = "No Transactions Available
";
}
document.getElementById('landlordTransactionsContainer').innerHTML = allTablesHtml;
} else {
console.error("Error: rspnsCode is not 1000 or response is missing");
}
} catch (err) {
console.error("Error parsing JSON:", err);
}
} else {
console.error("AJAX failed with status:", this.status);
}
}
};
xmlhttp1.send();
}
function downloadLandlordTransaction() {
var landlord_name = document.getElementById("landlord_name").innerText;
var year = document.getElementById("yearFilter").value;
if (!year) {
alert("Please select a year to download the transaction PDF.");
return;
}
var xmlhttp1;
if (window.XMLHttpRequest) {
xmlhttp1 = new XMLHttpRequest();
} else {
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("Your browser does not support AJAX!");
return;
}
}
var url = baseurl + "/landlord/downloadlandlordtransaction?year=" + year;
xmlhttp1.open("GET", url, true);
xmlhttp1.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp1.responseType = 'blob';
xmlhttp1.onreadystatechange = function () {
if (this.readyState === 4) {
console.log("Response received with status:", this.status);
if (this.status === 200) {
try {
var blob = new Blob([this.response], { type: 'application/pdf' });
var downloadUrl = URL.createObjectURL(blob);
var a = document.createElement("a");
a.href = downloadUrl;
a.download = landlord_name + "_transactions_" + year + ".pdf";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(downloadUrl);
} catch (err) {
console.error("Error while processing the download:", err);
alert("Something went wrong while generating the download.");
}
} else {
console.error("Download failed. Status:", this.status);
alert("Failed to download the file. Status code: " + this.status);
}
}
};
xmlhttp1.send();
}
function getLandlordLastUpdate() {
var xmlhttp;
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {
alert("BROWSER BROKE");
return false;
}
}
}
xmlhttp.open("GET", baseurl + "/landlord/getlastupdate", true);
xmlhttp.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
xmlhttp.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));
xmlhttp.onreadystatechange = function () {
if (this.status == 200 && this.responseText != null && this.responseText != "") {
var res = JSON.parse(this.responseText);
var response = JSON.parse(res['response']);
console.log(res.response);
const lastUpdate = res.response?.replace(/"/g, '') || "N/A";
document.getElementById("landlord_last_update").textContent = lastUpdate;
} else if ((this.status == 403 || this.status == 401) && this.readyState == 4) {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/login.html"
} else if (this.status == 500) {
var res = JSON.parse(this.responseText);
if (res.response === "403 FORBIDDEN") {
window.location.href = window.location.protocol + "//" + window.location.host + "/landlord/login.html"
}
}
};
xmlhttp.send();
}