sunrise-cms/helpers/functions.lotOccupancy.js

37 lines
1.5 KiB
JavaScript

export function filterOccupantsByLotOccupantType(lotOccupancy, lotOccupantType) {
const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase();
return (lotOccupancy.lotOccupancyOccupants ?? []).filter((possibleOccupant) => {
return (possibleOccupant.lotOccupantType.toLowerCase() ===
lotOccupantTypeLowerCase);
});
}
export function getFieldValueByOccupancyTypeField(lotOccupancy, occupancyTypeField) {
const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase();
const field = (lotOccupancy.lotOccupancyFields ?? []).find((possibleField) => {
return (possibleField.occupancyTypeField.toLowerCase() ===
occupancyTypeFieldLowerCase);
});
if (field === undefined) {
return undefined;
}
return field.lotOccupancyFieldValue;
}
export function getFeesByFeeCategory(lotOccupancy, feeCategory, feeCategoryContains = false) {
const feeCategoryLowerCase = feeCategory.toLowerCase();
return (lotOccupancy.lotOccupancyFees ?? []).filter((possibleFee) => {
return feeCategoryContains
? possibleFee.feeCategory
.toLowerCase()
.includes(feeCategoryLowerCase)
: possibleFee.feeCategory.toLowerCase() ===
feeCategoryLowerCase;
});
}
export function getTransactionTotal(lotOccupancy) {
let transactionTotal = 0;
for (const transaction of lotOccupancy.lotOccupancyTransactions ?? []) {
transactionTotal += transaction.transactionAmount;
}
return transactionTotal;
}