diff --git a/helpers/lotOccupancyDB/getFees.js b/helpers/lotOccupancyDB/getFees.js index fccd9a79..b06dc064 100644 --- a/helpers/lotOccupancyDB/getFees.js +++ b/helpers/lotOccupancyDB/getFees.js @@ -19,18 +19,25 @@ export function getFees(feeCategoryId, additionalFilters, connectedDatabase) { sqlParameters.push(additionalFilters.lotTypeId); } const fees = database - .prepare('select f.feeId, f.feeName, f.feeDescription,' + - ' f.occupancyTypeId, o.occupancyType,' + - ' f.lotTypeId, l.lotType,' + - ' ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction,' + - ' f.taxAmount, f.taxPercentage,' + - ' f.includeQuantity, f.quantityUnit,' + - ' f.isRequired, f.orderNumber' + - ' from Fees f' + - ' left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId' + - ' left join LotTypes l on f.lotTypeId = l.lotTypeId' + - sqlWhereClause + - ' order by f.orderNumber, f.feeName') + .prepare(`select f.feeId, f.feeName, f.feeDescription, + f.occupancyTypeId, o.occupancyType, + f.lotTypeId, l.lotType, + ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction, + f.taxAmount, f.taxPercentage, + f.includeQuantity, f.quantityUnit, + f.isRequired, f.orderNumber, + ifnull(lo.lotOccupancyFeeCount, 0) as lotOccupancyFeeCount + from Fees f + left join ( + select feeId, count(lotOccupancyId) as lotOccupancyFeeCount + from LotOccupancyFees + where recordDelete_timeMillis is null + group by feeId + ) lo on f.feeId = lo.feeId + left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId + left join LotTypes l on f.lotTypeId = l.lotTypeId + ${sqlWhereClause} + order by f.orderNumber, f.feeName`) .all(sqlParameters); if (updateOrderNumbers) { let expectedOrderNumber = 0; diff --git a/helpers/lotOccupancyDB/getFees.ts b/helpers/lotOccupancyDB/getFees.ts index 76e29aca..69c33ca8 100644 --- a/helpers/lotOccupancyDB/getFees.ts +++ b/helpers/lotOccupancyDB/getFees.ts @@ -44,20 +44,27 @@ export function getFees( sqlParameters.push(additionalFilters.lotTypeId) } - const fees = database + const fees: recordTypes.Fee[] = database .prepare( - 'select f.feeId, f.feeName, f.feeDescription,' + - ' f.occupancyTypeId, o.occupancyType,' + - ' f.lotTypeId, l.lotType,' + - ' ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction,' + - ' f.taxAmount, f.taxPercentage,' + - ' f.includeQuantity, f.quantityUnit,' + - ' f.isRequired, f.orderNumber' + - ' from Fees f' + - ' left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId' + - ' left join LotTypes l on f.lotTypeId = l.lotTypeId' + - sqlWhereClause + - ' order by f.orderNumber, f.feeName' + `select f.feeId, f.feeName, f.feeDescription, + f.occupancyTypeId, o.occupancyType, + f.lotTypeId, l.lotType, + ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction, + f.taxAmount, f.taxPercentage, + f.includeQuantity, f.quantityUnit, + f.isRequired, f.orderNumber, + ifnull(lo.lotOccupancyFeeCount, 0) as lotOccupancyFeeCount + from Fees f + left join ( + select feeId, count(lotOccupancyId) as lotOccupancyFeeCount + from LotOccupancyFees + where recordDelete_timeMillis is null + group by feeId + ) lo on f.feeId = lo.feeId + left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId + left join LotTypes l on f.lotTypeId = l.lotTypeId + ${sqlWhereClause} + order by f.orderNumber, f.feeName` ) .all(sqlParameters) diff --git a/types/recordTypes.d.ts b/types/recordTypes.d.ts index f4b69cec..e42fd44b 100644 --- a/types/recordTypes.d.ts +++ b/types/recordTypes.d.ts @@ -128,6 +128,7 @@ export interface Fee extends Record { taxPercentage?: number; isRequired?: boolean; orderNumber?: number; + lotOccupancyFeeCount?: number; } export interface LotOccupancyFee extends Fee, Record { lotOccupancyId?: number; diff --git a/types/recordTypes.ts b/types/recordTypes.ts index c6d91aff..2365e51e 100644 --- a/types/recordTypes.ts +++ b/types/recordTypes.ts @@ -171,6 +171,8 @@ export interface Fee extends Record { isRequired?: boolean orderNumber?: number + + lotOccupancyFeeCount?: number } export interface LotOccupancyFee extends Fee, Record {