"use strict";
/* eslint-disable @typescript-eslint/indent, unicorn/prefer-module */
Object.defineProperty(exports, "__esModule", { value: true });
let lotOccupancyFees = exports.lotOccupancyFees;
delete exports.lotOccupancyFees;
const lotOccupancyFeesContainerElement = document.querySelector('#container--lotOccupancyFees');
function getFeeGrandTotal() {
let feeGrandTotal = 0;
for (const lotOccupancyFee of lotOccupancyFees) {
feeGrandTotal +=
(lotOccupancyFee.feeAmount + lotOccupancyFee.taxAmount) *
lotOccupancyFee.quantity;
}
return feeGrandTotal;
}
function editLotOccupancyFeeQuantity(clickEvent) {
const feeId = Number.parseInt(clickEvent.currentTarget.closest('tr').dataset
.feeId, 10);
const fee = lotOccupancyFees.find((possibleFee) => {
return possibleFee.feeId === feeId;
});
if (fee === undefined) {
bulmaJS.alert({
title: 'Fee Not Found',
message: 'Please refresh the page',
contextualColorName: 'danger'
});
return;
}
let updateCloseModalFunction;
function doUpdateQuantity(formEvent) {
formEvent.preventDefault();
cityssm.postJSON(los.urlPrefix + '/lotOccupancies/doUpdateLotOccupancyFeeQuantity', formEvent.currentTarget, (rawResponseJSON) => {
const responseJSON = rawResponseJSON;
if (responseJSON.success) {
lotOccupancyFees = responseJSON.lotOccupancyFees;
renderLotOccupancyFees();
updateCloseModalFunction();
}
else {
bulmaJS.alert({
title: 'Error Updating Quantity',
message: 'Please try again.',
contextualColorName: 'danger'
});
}
});
}
cityssm.openHtmlModal('lotOccupancy-editFeeQuantity', {
onshow(modalElement) {
;
modalElement.querySelector('#lotOccupancyFeeQuantity--lotOccupancyId').value = lotOccupancyId;
modalElement.querySelector('#lotOccupancyFeeQuantity--feeId').value = fee.feeId.toString();
modalElement.querySelector('#lotOccupancyFeeQuantity--quantity').valueAsNumber = fee.quantity;
modalElement.querySelector('#lotOccupancyFeeQuantity--quantityUnit').textContent = fee.quantityUnit;
},
onshown(modalElement, closeModalFunction) {
var _a;
updateCloseModalFunction = closeModalFunction;
modalElement.querySelector('#lotOccupancyFeeQuantity--quantity').focus();
(_a = modalElement
.querySelector('form')) === null || _a === void 0 ? void 0 : _a.addEventListener('submit', doUpdateQuantity);
}
});
}
function deleteLotOccupancyFee(clickEvent) {
const feeId = clickEvent.currentTarget.closest('.container--lotOccupancyFee').dataset.feeId;
function doDelete() {
cityssm.postJSON(los.urlPrefix + '/lotOccupancies/doDeleteLotOccupancyFee', {
lotOccupancyId,
feeId
}, (rawResponseJSON) => {
var _a;
const responseJSON = rawResponseJSON;
if (responseJSON.success) {
lotOccupancyFees = responseJSON.lotOccupancyFees;
renderLotOccupancyFees();
}
else {
bulmaJS.alert({
title: 'Error Deleting Fee',
message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '',
contextualColorName: 'danger'
});
}
});
}
bulmaJS.confirm({
title: 'Delete Fee',
message: 'Are you sure you want to delete this fee?',
contextualColorName: 'warning',
okButton: {
text: 'Yes, Delete Fee',
callbackFunction: doDelete
}
});
}
function renderLotOccupancyFees() {
var _a, _b, _c, _d, _e, _f, _g;
if (lotOccupancyFees.length === 0) {
lotOccupancyFeesContainerElement.innerHTML = `
There are no fees associated with this record.
`;
renderLotOccupancyTransactions();
return;
}
lotOccupancyFeesContainerElement.innerHTML = `
| Fee |
Unit Cost |
× |
Quantity |
equals |
Total |
Options |
| Subtotal |
|
|
| Tax |
|
|
| Grand Total |
|
|
`;
let feeAmountTotal = 0;
let taxAmountTotal = 0;
for (const lotOccupancyFee of lotOccupancyFees) {
const tableRowElement = document.createElement('tr');
tableRowElement.className = 'container--lotOccupancyFee';
tableRowElement.dataset.feeId = lotOccupancyFee.feeId.toString();
tableRowElement.dataset.includeQuantity =
((_a = lotOccupancyFee.includeQuantity) !== null && _a !== void 0 ? _a : false) ? '1' : '0';
tableRowElement.innerHTML =
'' +
cityssm.escapeHTML((_b = lotOccupancyFee.feeName) !== null && _b !== void 0 ? _b : '') +
' ' +
'' +
cityssm.escapeHTML((_c = lotOccupancyFee.feeCategory) !== null && _c !== void 0 ? _c : '') +
'' +
' | ' +
(lotOccupancyFee.quantity === 1
? ''
: '$' +
lotOccupancyFee.feeAmount.toFixed(2) +
' | ' +
'× | ' +
'' +
lotOccupancyFee.quantity.toString() +
' | ' +
'= | ') +
'$' +
(lotOccupancyFee.feeAmount * lotOccupancyFee.quantity).toFixed(2) +
' | ' +
('' +
' ' +
(((_d = lotOccupancyFee.includeQuantity) !== null && _d !== void 0 ? _d : false)
? ''
: '') +
'' +
' ' +
' | ');
(_e = tableRowElement
.querySelector('.button--editQuantity')) === null || _e === void 0 ? void 0 : _e.addEventListener('click', editLotOccupancyFeeQuantity);
(_f = tableRowElement
.querySelector('.button--delete')) === null || _f === void 0 ? void 0 : _f.addEventListener('click', deleteLotOccupancyFee);
(_g = lotOccupancyFeesContainerElement
.querySelector('tbody')) === null || _g === void 0 ? void 0 : _g.append(tableRowElement);
feeAmountTotal += lotOccupancyFee.feeAmount * lotOccupancyFee.quantity;
taxAmountTotal += lotOccupancyFee.taxAmount * lotOccupancyFee.quantity;
}
;
lotOccupancyFeesContainerElement.querySelector('#lotOccupancyFees--feeAmountTotal').textContent = '$' + feeAmountTotal.toFixed(2);
lotOccupancyFeesContainerElement.querySelector('#lotOccupancyFees--taxAmountTotal').textContent = '$' + taxAmountTotal.toFixed(2);
lotOccupancyFeesContainerElement.querySelector('#lotOccupancyFees--grandTotal').textContent = '$' + (feeAmountTotal + taxAmountTotal).toFixed(2);
renderLotOccupancyTransactions();
}
const addFeeButtonElement = document.querySelector('#button--addFee');
addFeeButtonElement.addEventListener('click', () => {
if (los.hasUnsavedChanges()) {
bulmaJS.alert({
message: 'Please save all unsaved changes before adding fees.',
contextualColorName: 'warning'
});
return;
}
let feeCategories;
let feeFilterElement;
let feeFilterResultsElement;
function doAddFee(feeId, quantity = 1) {
cityssm.postJSON(los.urlPrefix + '/lotOccupancies/doAddLotOccupancyFee', {
lotOccupancyId,
feeId,
quantity
}, (rawResponseJSON) => {
var _a;
const responseJSON = rawResponseJSON;
if (responseJSON.success) {
lotOccupancyFees = responseJSON.lotOccupancyFees;
renderLotOccupancyFees();
filterFees();
}
else {
bulmaJS.alert({
title: 'Error Adding Fee',
message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '',
contextualColorName: 'danger'
});
}
});
}
function doSetQuantityAndAddFee(fee) {
let quantityElement;
let quantityCloseModalFunction;
function doSetQuantity(submitEvent) {
submitEvent.preventDefault();
doAddFee(fee.feeId, quantityElement.value);
quantityCloseModalFunction();
}
cityssm.openHtmlModal('lotOccupancy-setFeeQuantity', {
onshow(modalElement) {
;
modalElement.querySelector('#lotOccupancyFeeQuantity--quantityUnit').textContent = fee.quantityUnit;
},
onshown(modalElement, closeModalFunction) {
quantityCloseModalFunction = closeModalFunction;
quantityElement = modalElement.querySelector('#lotOccupancyFeeQuantity--quantity');
modalElement
.querySelector('form')
.addEventListener('submit', doSetQuantity);
}
});
}
function tryAddFee(clickEvent) {
var _a;
clickEvent.preventDefault();
const feeId = Number.parseInt(clickEvent.currentTarget.dataset.feeId, 10);
const feeCategoryId = Number.parseInt(clickEvent.currentTarget.dataset.feeCategoryId, 10);
const feeCategory = feeCategories.find((currentFeeCategory) => {
return currentFeeCategory.feeCategoryId === feeCategoryId;
});
const fee = feeCategory.fees.find((currentFee) => {
return currentFee.feeId === feeId;
});
if ((_a = fee.includeQuantity) !== null && _a !== void 0 ? _a : false) {
doSetQuantityAndAddFee(fee);
}
else {
doAddFee(feeId);
}
}
function filterFees() {
var _a, _b, _c, _d, _e, _f;
const filterStringPieces = feeFilterElement.value
.trim()
.toLowerCase()
.split(' ');
feeFilterResultsElement.innerHTML = '';
for (const feeCategory of feeCategories) {
const categoryContainerElement = document.createElement('div');
categoryContainerElement.className = 'container--feeCategory';
categoryContainerElement.dataset.feeCategoryId =
feeCategory.feeCategoryId.toString();
categoryContainerElement.innerHTML =
'' +
cityssm.escapeHTML((_a = feeCategory.feeCategory) !== null && _a !== void 0 ? _a : '') +
'
' +
'';
let hasFees = false;
for (const fee of feeCategory.fees) {
// Don't include already applied fees that limit quantity
if (lotOccupancyFeesContainerElement.querySelector(`.container--lotOccupancyFee[data-fee-id='${fee.feeId}'][data-include-quantity='0']`) !== null) {
continue;
}
let includeFee = true;
const feeSearchString = (((_b = feeCategory.feeCategory) !== null && _b !== void 0 ? _b : '') +
' ' +
((_c = fee.feeName) !== null && _c !== void 0 ? _c : '') +
' ' +
((_d = fee.feeDescription) !== null && _d !== void 0 ? _d : '')).toLowerCase();
for (const filterStringPiece of filterStringPieces) {
if (!feeSearchString.includes(filterStringPiece)) {
includeFee = false;
break;
}
}
if (!includeFee) {
continue;
}
hasFees = true;
const panelBlockElement = document.createElement('a');
panelBlockElement.className = 'panel-block is-block container--fee';
panelBlockElement.dataset.feeId = fee.feeId.toString();
panelBlockElement.dataset.feeCategoryId =
feeCategory.feeCategoryId.toString();
panelBlockElement.href = '#';
panelBlockElement.innerHTML =
'' +
cityssm.escapeHTML((_e = fee.feeName) !== null && _e !== void 0 ? _e : '') +
'
' +
'' +
cityssm
.escapeHTML((_f = fee.feeDescription) !== null && _f !== void 0 ? _f : '')
.replace(/\n/g, '
') +
'';
panelBlockElement.addEventListener('click', tryAddFee);
categoryContainerElement.querySelector('.panel').append(panelBlockElement);
}
if (hasFees) {
feeFilterResultsElement.append(categoryContainerElement);
}
}
}
cityssm.openHtmlModal('lotOccupancy-addFee', {
onshow(modalElement) {
feeFilterElement = modalElement.querySelector('#feeSelect--feeName');
feeFilterResultsElement = modalElement.querySelector('#resultsContainer--feeSelect');
cityssm.postJSON(los.urlPrefix + '/lotOccupancies/doGetFees', {
lotOccupancyId
}, (rawResponseJSON) => {
const responseJSON = rawResponseJSON;
feeCategories = responseJSON.feeCategories;
feeFilterElement.disabled = false;
feeFilterElement.addEventListener('keyup', filterFees);
feeFilterElement.focus();
filterFees();
});
},
onshown() {
bulmaJS.toggleHtmlClipped();
},
onhidden() {
renderLotOccupancyFees();
},
onremoved() {
bulmaJS.toggleHtmlClipped();
addFeeButtonElement.focus();
}
});
});
let lotOccupancyTransactions = exports.lotOccupancyTransactions;
delete exports.lotOccupancyTransactions;
const lotOccupancyTransactionsContainerElement = document.querySelector('#container--lotOccupancyTransactions');
function getTransactionGrandTotal() {
let transactionGrandTotal = 0;
for (const lotOccupancyTransaction of lotOccupancyTransactions) {
transactionGrandTotal += lotOccupancyTransaction.transactionAmount;
}
return transactionGrandTotal;
}
function deleteLotOccupancyTransaction(clickEvent) {
const transactionIndex = clickEvent.currentTarget.closest('.container--lotOccupancyTransaction').dataset.transactionIndex;
function doDelete() {
cityssm.postJSON(los.urlPrefix + '/lotOccupancies/doDeleteLotOccupancyTransaction', {
lotOccupancyId,
transactionIndex
}, (rawResponseJSON) => {
var _a;
const responseJSON = rawResponseJSON;
if (responseJSON.success) {
lotOccupancyTransactions = responseJSON.lotOccupancyTransactions;
renderLotOccupancyTransactions();
}
else {
bulmaJS.alert({
title: 'Error Deleting Transaction',
message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '',
contextualColorName: 'danger'
});
}
});
}
bulmaJS.confirm({
title: 'Delete Trasnaction',
message: 'Are you sure you want to delete this transaction?',
contextualColorName: 'warning',
okButton: {
text: 'Yes, Delete Transaction',
callbackFunction: doDelete
}
});
}
function renderLotOccupancyTransactions() {
var _a, _b, _c;
if (lotOccupancyTransactions.length === 0) {
lotOccupancyTransactionsContainerElement.innerHTML =
'' +
'
There are no transactions associated with this record.
' +
'
';
return;
}
lotOccupancyTransactionsContainerElement.innerHTML = `
| Date |
${los.escapedAliases.ExternalReceiptNumber} |
Amount |
Options |
| Transaction Total |
|
|
`;
let transactionGrandTotal = 0;
for (const lotOccupancyTransaction of lotOccupancyTransactions) {
transactionGrandTotal += lotOccupancyTransaction.transactionAmount;
const tableRowElement = document.createElement('tr');
tableRowElement.className = 'container--lotOccupancyTransaction';
tableRowElement.dataset.transactionIndex =
lotOccupancyTransaction.transactionIndex.toString();
let externalReceiptNumberHTML = '';
if (lotOccupancyTransaction.externalReceiptNumber !== '') {
externalReceiptNumberHTML = cityssm.escapeHTML((_a = lotOccupancyTransaction.externalReceiptNumber) !== null && _a !== void 0 ? _a : '');
if (los.dynamicsGPIntegrationIsEnabled) {
if (lotOccupancyTransaction.dynamicsGPDocument === undefined) {
externalReceiptNumberHTML += `
`;
}
else if (lotOccupancyTransaction.dynamicsGPDocument.documentTotal.toFixed(2) === lotOccupancyTransaction.transactionAmount.toFixed(2)) {
externalReceiptNumberHTML += `
`;
}
else {
externalReceiptNumberHTML += `
`;
}
}
externalReceiptNumberHTML += '
';
}
tableRowElement.innerHTML =
'' +
((_b = lotOccupancyTransaction.transactionDateString) !== null && _b !== void 0 ? _b : '') +
' | ' +
('' +
externalReceiptNumberHTML +
'' +
cityssm.escapeHTML((_c = lotOccupancyTransaction.transactionNote) !== null && _c !== void 0 ? _c : '') +
'' +
' | ') +
('$' +
lotOccupancyTransaction.transactionAmount.toFixed(2) +
' | ') +
('' +
'' +
' | ');
tableRowElement
.querySelector('button')
.addEventListener('click', deleteLotOccupancyTransaction);
lotOccupancyTransactionsContainerElement
.querySelector('tbody')
.append(tableRowElement);
}
;
lotOccupancyTransactionsContainerElement.querySelector('#lotOccupancyTransactions--grandTotal').textContent = '$' + transactionGrandTotal.toFixed(2);
const feeGrandTotal = getFeeGrandTotal();
if (feeGrandTotal.toFixed(2) !== transactionGrandTotal.toFixed(2)) {
lotOccupancyTransactionsContainerElement.insertAdjacentHTML('afterbegin', '' +
'
' +
'
' +
'
' +
'
$' +
(feeGrandTotal - transactionGrandTotal).toFixed(2) +
'
' +
'
' +
'
' +
'
');
}
}
const addTransactionButtonElement = document.querySelector('#button--addTransaction');
addTransactionButtonElement.addEventListener('click', () => {
let transactionAmountElement;
let externalReceiptNumberElement;
let addCloseModalFunction;
function doAddTransaction(submitEvent) {
submitEvent.preventDefault();
cityssm.postJSON(los.urlPrefix + '/lotOccupancies/doAddLotOccupancyTransaction', submitEvent.currentTarget, (rawResponseJSON) => {
var _a;
const responseJSON = rawResponseJSON;
if (responseJSON.success) {
lotOccupancyTransactions = responseJSON.lotOccupancyTransactions;
addCloseModalFunction();
renderLotOccupancyTransactions();
}
else {
bulmaJS.confirm({
title: 'Error Adding Transaction',
message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '',
contextualColorName: 'danger'
});
}
});
}
// eslint-disable-next-line @typescript-eslint/naming-convention
function dynamicsGP_refreshExternalReceiptNumberIcon() {
const externalReceiptNumber = externalReceiptNumberElement.value;
const iconElement = externalReceiptNumberElement
.closest('.control')
.querySelector('.icon');
const helpTextElement = externalReceiptNumberElement
.closest('.field')
.querySelector('.help');
if (externalReceiptNumber === '') {
helpTextElement.innerHTML = ' ';
iconElement.innerHTML = '';
return;
}
cityssm.postJSON(los.urlPrefix + '/lotOccupancies/doGetDynamicsGPDocument', {
externalReceiptNumber
}, (rawResponseJSON) => {
const responseJSON = rawResponseJSON;
if (!responseJSON.success ||
responseJSON.dynamicsGPDocument === undefined) {
helpTextElement.textContent = 'No Matching Document Found';
iconElement.innerHTML =
'';
}
else if (transactionAmountElement.valueAsNumber ===
responseJSON.dynamicsGPDocument.documentTotal) {
helpTextElement.textContent = 'Matching Document Found';
iconElement.innerHTML =
'';
}
else {
helpTextElement.textContent =
'Matching Document: $' +
responseJSON.dynamicsGPDocument.documentTotal.toFixed(2);
iconElement.innerHTML =
'';
}
});
}
cityssm.openHtmlModal('lotOccupancy-addTransaction', {
onshow(modalElement) {
los.populateAliases(modalElement);
modalElement.querySelector('#lotOccupancyTransactionAdd--lotOccupancyId').value = lotOccupancyId.toString();
const feeGrandTotal = getFeeGrandTotal();
const transactionGrandTotal = getTransactionGrandTotal();
transactionAmountElement = modalElement.querySelector('#lotOccupancyTransactionAdd--transactionAmount');
transactionAmountElement.min = (-1 * transactionGrandTotal).toFixed(2);
transactionAmountElement.max = Math.max(feeGrandTotal - transactionGrandTotal, 0).toFixed(2);
transactionAmountElement.value = Math.max(feeGrandTotal - transactionGrandTotal, 0).toFixed(2);
if (los.dynamicsGPIntegrationIsEnabled) {
externalReceiptNumberElement = modalElement.querySelector('#lotOccupancyTransactionAdd--externalReceiptNumber');
const externalReceiptNumberControlElement = externalReceiptNumberElement.closest('.control');
externalReceiptNumberControlElement.classList.add('has-icons-right');
externalReceiptNumberControlElement.insertAdjacentHTML('beforeend', '');
externalReceiptNumberControlElement.insertAdjacentHTML('afterend', '');
externalReceiptNumberElement.addEventListener('change', dynamicsGP_refreshExternalReceiptNumberIcon);
transactionAmountElement.addEventListener('change', dynamicsGP_refreshExternalReceiptNumberIcon);
dynamicsGP_refreshExternalReceiptNumberIcon();
}
},
onshown(modalElement, closeModalFunction) {
bulmaJS.toggleHtmlClipped();
transactionAmountElement.focus();
addCloseModalFunction = closeModalFunction;
modalElement
.querySelector('form')
.addEventListener('submit', doAddTransaction);
},
onremoved() {
bulmaJS.toggleHtmlClipped();
addTransactionButtonElement.focus();
}
});
});
renderLotOccupancyFees();