diff --git a/helpers/lotOccupancyDB/getReportData.js b/helpers/lotOccupancyDB/getReportData.js index cb3b4943..8346e894 100644 --- a/helpers/lotOccupancyDB/getReportData.js +++ b/helpers/lotOccupancyDB/getReportData.js @@ -31,26 +31,17 @@ export function getReportData(reportName, reportParameters) { break; } case "maps-formatted": { - sql = - "select mapName as " + - mapNameAlias + - "," + - (" mapDescription as " + mapDescriptionAlias) + - "," + - (" mapAddress1 as " + mapAddress1Alias) + - "," + - (" mapAddress2 as " + mapAddress2Alias) + - "," + - (" mapCity as " + mapCityAlias) + - "," + - (" mapProvince as " + mapProvinceAlias) + - "," + - (" mapPostalCode as " + mapPostalCodeAlias) + - "," + - (" mapPhoneNumber as " + mapPhoneNumberAlias) + - " from Maps" + - " where recordDelete_timeMillis is null" + - " order by mapName"; + sql = `select mapName as ${mapNameAlias}, + mapDescription as ${mapDescriptionAlias}, + mapAddress1 as ${mapAddress1Alias}, + mapAddress2 as ${mapAddress2Alias}, + mapCity as ${mapCityAlias}, + mapProvince as ${mapProvinceAlias}, + mapPostalCode as ${mapPostalCodeAlias}, + mapPhoneNumber as ${mapPhoneNumberAlias} + from Maps + where recordDelete_timeMillis is null + order by mapName`; break; } case "lots-all": { @@ -58,65 +49,47 @@ export function getReportData(reportName, reportParameters) { break; } case "lots-byLotTypeId": { - sql = - "select l.lotId as " + - lotIdAlias + - "," + - (" m.mapName as " + mapNameAlias) + - "," + - (" l.lotName as " + lotNameAlias) + - "," + - (" t.lotType as " + lotTypeAlias) + - "," + - (" s.lotStatus as " + lotStatusAlias) + - " from Lots l" + - " left join LotTypes t on l.lotTypeId = t.lotTypeId" + - " left join LotStatuses s on l.lotStatusId = s.lotStatusId" + - " left join Maps m on l.mapId = m.mapId" + - " where l.recordDelete_timeMillis is null" + - " and l.lotTypeId = ?"; + sql = `select l.lotId as ${lotIdAlias}, + m.mapName as ${mapNameAlias}, + l.lotName as ${lotNameAlias}, + t.lotType as ${lotTypeAlias}, + s.lotStatus as ${lotStatusAlias} + from Lots l + left join LotTypes t on l.lotTypeId = t.lotTypeId + left join LotStatuses s on l.lotStatusId = s.lotStatusId + left join Maps m on l.mapId = m.mapId + where l.recordDelete_timeMillis is null + and l.lotTypeId = ?`; sqlParameters.push(reportParameters.lotTypeId); break; } case "lots-byLotStatusId": { - sql = - "select l.lotId as " + - lotIdAlias + - "," + - (" m.mapName as " + mapNameAlias) + - "," + - (" l.lotName as " + lotNameAlias) + - "," + - (" t.lotType as " + lotTypeAlias) + - "," + - (" s.lotStatus as " + lotStatusAlias) + - " from Lots l" + - " left join LotTypes t on l.lotTypeId = t.lotTypeId" + - " left join LotStatuses s on l.lotStatusId = s.lotStatusId" + - " left join Maps m on l.mapId = m.mapId" + - " where l.recordDelete_timeMillis is null" + - " and l.lotStatusId = ?"; + sql = `select l.lotId as ${lotIdAlias}, + m.mapName as ${mapNameAlias}, + l.lotName as ${lotNameAlias}, + t.lotType as ${lotTypeAlias}, + s.lotStatus as ${lotStatusAlias} + from Lots l + left join LotTypes t on l.lotTypeId = t.lotTypeId + left join LotStatuses s on l.lotStatusId = s.lotStatusId + left join Maps m on l.mapId = m.mapId + where l.recordDelete_timeMillis is null + and l.lotStatusId = ?`; sqlParameters.push(reportParameters.lotStatusId); break; } case "lots-byMapId": { - sql = - "select l.lotId as " + - lotIdAlias + - "," + - (" m.mapName as " + mapNameAlias) + - "," + - (" l.lotName as " + lotNameAlias) + - "," + - (" t.lotType as " + lotTypeAlias) + - "," + - (" s.lotStatus as " + lotStatusAlias) + - " from Lots l" + - " left join LotTypes t on l.lotTypeId = t.lotTypeId" + - " left join LotStatuses s on l.lotStatusId = s.lotStatusId" + - " left join Maps m on l.mapId = m.mapId" + - " where l.recordDelete_timeMillis is null" + - " and l.mapId = ?"; + sql = `select l.lotId as ${lotIdAlias}, + m.mapName as ${mapNameAlias}, + l.lotName as ${lotNameAlias}, + t.lotType as ${lotTypeAlias}, + s.lotStatus as ${lotStatusAlias} + from Lots l + left join LotTypes t on l.lotTypeId = t.lotTypeId + left join LotStatuses s on l.lotStatusId = s.lotStatusId + left join Maps m on l.mapId = m.mapId + where l.recordDelete_timeMillis is null + and l.mapId = ?`; sqlParameters.push(reportParameters.mapId); break; } @@ -133,26 +106,19 @@ export function getReportData(reportName, reportParameters) { break; } case "lotOccupancies-current-byMapId": { - sql = - "select o.lotOccupancyId as " + - lotOccupancyIdAlias + - "," + - (" l.lotName as " + lotNameAlias) + - "," + - (" m.mapName as " + mapNameAlias) + - "," + - (" ot.occupancyType as " + occupancyTypeAlias) + - "," + - (" o.occupancyStartDate as " + occupancyStartDateAlias) + - "," + - (" o.occupancyEndDate as " + occupancyEndDateAlias) + - " from LotOccupancies o" + - " left join OccupancyTypes ot on o.occupancyTypeId = ot.occupancyTypeId" + - " left join Lots l on o.lotId = l.lotId" + - " left join Maps m on l.mapId = m.mapId" + - " where o.recordDelete_timeMillis is null" + - " and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)" + - " and l.mapId = ?"; + sql = `select o.lotOccupancyId as ${lotOccupancyIdAlias}, + l.lotName as ${lotNameAlias}, + m.mapName as ${mapNameAlias}, + ot.occupancyType as ${occupancyTypeAlias}, + o.occupancyStartDate as ${occupancyStartDateAlias}, + o.occupancyEndDate as ${occupancyEndDateAlias} + from LotOccupancies o + left join OccupancyTypes ot on o.occupancyTypeId = ot.occupancyTypeId + left join Lots l on o.lotId = l.lotId + left join Maps m on l.mapId = m.mapId + where o.recordDelete_timeMillis is null + and (o.occupancyEndDate is null or o.occupancyEndDate >= ?) + and l.mapId = ?`; sqlParameters.push(dateTimeFunctions.dateToInteger(new Date()), reportParameters.mapId); break; } @@ -177,14 +143,13 @@ export function getReportData(reportName, reportParameters) { break; } case "lotOccupancyTransactions-byTransactionDateString": { - sql = - "select t.lotOccupancyId, t.transactionIndex," + - " t.transactionDate, t.transactionTime," + - " t.transactionAmount, t.externalReceiptNumber," + - " t.transactionNote" + - " from LotOccupancyTransactions t" + - " where t.recordDelete_timeMillis is null" + - " and t.transactionDate = ?"; + sql = `select t.lotOccupancyId, t.transactionIndex, + t.transactionDate, t.transactionTime, + t.transactionAmount, + t.externalReceiptNumber, t.transactionNote + from LotOccupancyTransactions t + where t.recordDelete_timeMillis is null + and t.transactionDate = ?`; sqlParameters.push(dateTimeFunctions.dateStringToInteger(reportParameters.transactionDateString)); break; } @@ -193,23 +158,22 @@ export function getReportData(reportName, reportParameters) { break; } case "workOrders-open": { - sql = - "select w.workOrderId, w.workOrderNumber," + - " t.workOrderType, w.workOrderDescription," + - " w.workOrderOpenDate," + - " m.workOrderMilestoneCount, m.workOrderMilestoneCompletionCount" + - " from WorkOrders w" + - " left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId" + - (" left join (" + - "select m.workOrderId," + - " count(m.workOrderMilestoneId) as workOrderMilestoneCount," + - " sum(case when m.workOrderMilestoneCompletionDate is null then 0 else 1 end) as workOrderMilestoneCompletionCount" + - " from WorkOrderMilestones m" + - " where m.recordDelete_timeMillis is null" + - " group by m.workOrderId" + - ") m on w.workOrderId = m.workOrderId") + - " where w.recordDelete_timeMillis is null" + - " and w.workOrderCloseDate is null"; + sql = `select w.workOrderId, w.workOrderNumber, + t.workOrderType, w.workOrderDescription, + w.workOrderOpenDate, + m.workOrderMilestoneCount, m.workOrderMilestoneCompletionCount + from WorkOrders w + left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId + left join ( + select m.workOrderId, + count(m.workOrderMilestoneId) as workOrderMilestoneCount, + sum(case when m.workOrderMilestoneCompletionDate is null then 0 else 1 end) as workOrderMilestoneCompletionCount + from WorkOrderMilestones m + where m.recordDelete_timeMillis is null + group by m.workOrderId + ) m on w.workOrderId = m.workOrderId + where w.recordDelete_timeMillis is null + and w.workOrderCloseDate is null`; break; } case "workOrderComments-all": { diff --git a/helpers/lotOccupancyDB/getReportData.ts b/helpers/lotOccupancyDB/getReportData.ts index 598ecb81..1ce34396 100644 --- a/helpers/lotOccupancyDB/getReportData.ts +++ b/helpers/lotOccupancyDB/getReportData.ts @@ -49,26 +49,17 @@ export function getReportData( } case "maps-formatted": { - sql = - "select mapName as " + - mapNameAlias + - "," + - (" mapDescription as " + mapDescriptionAlias) + - "," + - (" mapAddress1 as " + mapAddress1Alias) + - "," + - (" mapAddress2 as " + mapAddress2Alias) + - "," + - (" mapCity as " + mapCityAlias) + - "," + - (" mapProvince as " + mapProvinceAlias) + - "," + - (" mapPostalCode as " + mapPostalCodeAlias) + - "," + - (" mapPhoneNumber as " + mapPhoneNumberAlias) + - " from Maps" + - " where recordDelete_timeMillis is null" + - " order by mapName"; + sql = `select mapName as ${mapNameAlias}, + mapDescription as ${mapDescriptionAlias}, + mapAddress1 as ${mapAddress1Alias}, + mapAddress2 as ${mapAddress2Alias}, + mapCity as ${mapCityAlias}, + mapProvince as ${mapProvinceAlias}, + mapPostalCode as ${mapPostalCodeAlias}, + mapPhoneNumber as ${mapPhoneNumberAlias} + from Maps + where recordDelete_timeMillis is null + order by mapName`; break; } @@ -79,23 +70,17 @@ export function getReportData( } case "lots-byLotTypeId": { - sql = - "select l.lotId as " + - lotIdAlias + - "," + - (" m.mapName as " + mapNameAlias) + - "," + - (" l.lotName as " + lotNameAlias) + - "," + - (" t.lotType as " + lotTypeAlias) + - "," + - (" s.lotStatus as " + lotStatusAlias) + - " from Lots l" + - " left join LotTypes t on l.lotTypeId = t.lotTypeId" + - " left join LotStatuses s on l.lotStatusId = s.lotStatusId" + - " left join Maps m on l.mapId = m.mapId" + - " where l.recordDelete_timeMillis is null" + - " and l.lotTypeId = ?"; + sql = `select l.lotId as ${lotIdAlias}, + m.mapName as ${mapNameAlias}, + l.lotName as ${lotNameAlias}, + t.lotType as ${lotTypeAlias}, + s.lotStatus as ${lotStatusAlias} + from Lots l + left join LotTypes t on l.lotTypeId = t.lotTypeId + left join LotStatuses s on l.lotStatusId = s.lotStatusId + left join Maps m on l.mapId = m.mapId + where l.recordDelete_timeMillis is null + and l.lotTypeId = ?`; sqlParameters.push(reportParameters.lotTypeId); @@ -103,23 +88,17 @@ export function getReportData( } case "lots-byLotStatusId": { - sql = - "select l.lotId as " + - lotIdAlias + - "," + - (" m.mapName as " + mapNameAlias) + - "," + - (" l.lotName as " + lotNameAlias) + - "," + - (" t.lotType as " + lotTypeAlias) + - "," + - (" s.lotStatus as " + lotStatusAlias) + - " from Lots l" + - " left join LotTypes t on l.lotTypeId = t.lotTypeId" + - " left join LotStatuses s on l.lotStatusId = s.lotStatusId" + - " left join Maps m on l.mapId = m.mapId" + - " where l.recordDelete_timeMillis is null" + - " and l.lotStatusId = ?"; + sql = `select l.lotId as ${lotIdAlias}, + m.mapName as ${mapNameAlias}, + l.lotName as ${lotNameAlias}, + t.lotType as ${lotTypeAlias}, + s.lotStatus as ${lotStatusAlias} + from Lots l + left join LotTypes t on l.lotTypeId = t.lotTypeId + left join LotStatuses s on l.lotStatusId = s.lotStatusId + left join Maps m on l.mapId = m.mapId + where l.recordDelete_timeMillis is null + and l.lotStatusId = ?`; sqlParameters.push(reportParameters.lotStatusId); @@ -127,23 +106,17 @@ export function getReportData( } case "lots-byMapId": { - sql = - "select l.lotId as " + - lotIdAlias + - "," + - (" m.mapName as " + mapNameAlias) + - "," + - (" l.lotName as " + lotNameAlias) + - "," + - (" t.lotType as " + lotTypeAlias) + - "," + - (" s.lotStatus as " + lotStatusAlias) + - " from Lots l" + - " left join LotTypes t on l.lotTypeId = t.lotTypeId" + - " left join LotStatuses s on l.lotStatusId = s.lotStatusId" + - " left join Maps m on l.mapId = m.mapId" + - " where l.recordDelete_timeMillis is null" + - " and l.mapId = ?"; + sql = `select l.lotId as ${lotIdAlias}, + m.mapName as ${mapNameAlias}, + l.lotName as ${lotNameAlias}, + t.lotType as ${lotTypeAlias}, + s.lotStatus as ${lotStatusAlias} + from Lots l + left join LotTypes t on l.lotTypeId = t.lotTypeId + left join LotStatuses s on l.lotStatusId = s.lotStatusId + left join Maps m on l.mapId = m.mapId + where l.recordDelete_timeMillis is null + and l.mapId = ?`; sqlParameters.push(reportParameters.mapId); @@ -166,26 +139,19 @@ export function getReportData( } case "lotOccupancies-current-byMapId": { - sql = - "select o.lotOccupancyId as " + - lotOccupancyIdAlias + - "," + - (" l.lotName as " + lotNameAlias) + - "," + - (" m.mapName as " + mapNameAlias) + - "," + - (" ot.occupancyType as " + occupancyTypeAlias) + - "," + - (" o.occupancyStartDate as " + occupancyStartDateAlias) + - "," + - (" o.occupancyEndDate as " + occupancyEndDateAlias) + - " from LotOccupancies o" + - " left join OccupancyTypes ot on o.occupancyTypeId = ot.occupancyTypeId" + - " left join Lots l on o.lotId = l.lotId" + - " left join Maps m on l.mapId = m.mapId" + - " where o.recordDelete_timeMillis is null" + - " and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)" + - " and l.mapId = ?"; + sql = `select o.lotOccupancyId as ${lotOccupancyIdAlias}, + l.lotName as ${lotNameAlias}, + m.mapName as ${mapNameAlias}, + ot.occupancyType as ${occupancyTypeAlias}, + o.occupancyStartDate as ${occupancyStartDateAlias}, + o.occupancyEndDate as ${occupancyEndDateAlias} + from LotOccupancies o + left join OccupancyTypes ot on o.occupancyTypeId = ot.occupancyTypeId + left join Lots l on o.lotId = l.lotId + left join Maps m on l.mapId = m.mapId + where o.recordDelete_timeMillis is null + and (o.occupancyEndDate is null or o.occupancyEndDate >= ?) + and l.mapId = ?`; sqlParameters.push(dateTimeFunctions.dateToInteger(new Date()), reportParameters.mapId); @@ -218,19 +184,16 @@ export function getReportData( } case "lotOccupancyTransactions-byTransactionDateString": { - sql = - "select t.lotOccupancyId, t.transactionIndex," + - " t.transactionDate, t.transactionTime," + - " t.transactionAmount, t.externalReceiptNumber," + - " t.transactionNote" + - " from LotOccupancyTransactions t" + - " where t.recordDelete_timeMillis is null" + - " and t.transactionDate = ?"; + sql = `select t.lotOccupancyId, t.transactionIndex, + t.transactionDate, t.transactionTime, + t.transactionAmount, + t.externalReceiptNumber, t.transactionNote + from LotOccupancyTransactions t + where t.recordDelete_timeMillis is null + and t.transactionDate = ?`; sqlParameters.push( - dateTimeFunctions.dateStringToInteger( - reportParameters.transactionDateString as string - ) + dateTimeFunctions.dateStringToInteger(reportParameters.transactionDateString as string) ); break; } @@ -241,23 +204,22 @@ export function getReportData( } case "workOrders-open": { - sql = - "select w.workOrderId, w.workOrderNumber," + - " t.workOrderType, w.workOrderDescription," + - " w.workOrderOpenDate," + - " m.workOrderMilestoneCount, m.workOrderMilestoneCompletionCount" + - " from WorkOrders w" + - " left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId" + - (" left join (" + - "select m.workOrderId," + - " count(m.workOrderMilestoneId) as workOrderMilestoneCount," + - " sum(case when m.workOrderMilestoneCompletionDate is null then 0 else 1 end) as workOrderMilestoneCompletionCount" + - " from WorkOrderMilestones m" + - " where m.recordDelete_timeMillis is null" + - " group by m.workOrderId" + - ") m on w.workOrderId = m.workOrderId") + - " where w.recordDelete_timeMillis is null" + - " and w.workOrderCloseDate is null"; + sql = `select w.workOrderId, w.workOrderNumber, + t.workOrderType, w.workOrderDescription, + w.workOrderOpenDate, + m.workOrderMilestoneCount, m.workOrderMilestoneCompletionCount + from WorkOrders w + left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId + left join ( + select m.workOrderId, + count(m.workOrderMilestoneId) as workOrderMilestoneCount, + sum(case when m.workOrderMilestoneCompletionDate is null then 0 else 1 end) as workOrderMilestoneCompletionCount + from WorkOrderMilestones m + where m.recordDelete_timeMillis is null + group by m.workOrderId + ) m on w.workOrderId = m.workOrderId + where w.recordDelete_timeMillis is null + and w.workOrderCloseDate is null`; break; }