From 62a4506a49e73e4bdd571845f2605239a8f30e5c Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Tue, 27 Sep 2022 10:58:25 -0400 Subject: [PATCH] lot reports --- handlers/reports-get/search.js | 7 +- handlers/reports-get/search.ts | 7 +- helpers/lotOccupancyDB/getReportData.js | 39 +++++++++ helpers/lotOccupancyDB/getReportData.ts | 48 +++++++++++ views/report-search.ejs | 105 ++++++++++++++++++++++++ 5 files changed, 204 insertions(+), 2 deletions(-) diff --git a/handlers/reports-get/search.js b/handlers/reports-get/search.js index 7f976cb3..d1415bf1 100644 --- a/handlers/reports-get/search.js +++ b/handlers/reports-get/search.js @@ -1,12 +1,17 @@ import * as dateTimeFunctions from "@cityssm/expressjs-server-js/dateTimeFns.js"; import { getMaps } from "../../helpers/lotOccupancyDB/getMaps.js"; +import { getLotStatuses, getLotTypes } from "../../helpers/functions.cache.js"; export const handler = (_request, response) => { const rightNow = new Date(); const maps = getMaps(); + const lotTypes = getLotTypes(); + const lotStatuses = getLotStatuses(); response.render("report-search", { headTitle: "Reports", todayDateString: dateTimeFunctions.dateToString(rightNow), - maps + maps, + lotTypes, + lotStatuses }); }; export default handler; diff --git a/handlers/reports-get/search.ts b/handlers/reports-get/search.ts index 276cc93a..57419f0d 100644 --- a/handlers/reports-get/search.ts +++ b/handlers/reports-get/search.ts @@ -3,16 +3,21 @@ import type { RequestHandler } from "express"; import * as dateTimeFunctions from "@cityssm/expressjs-server-js/dateTimeFns.js"; import { getMaps } from "../../helpers/lotOccupancyDB/getMaps.js"; +import { getLotStatuses, getLotTypes } from "../../helpers/functions.cache.js"; export const handler: RequestHandler = (_request, response) => { const rightNow = new Date(); const maps = getMaps(); + const lotTypes = getLotTypes(); + const lotStatuses = getLotStatuses(); response.render("report-search", { headTitle: "Reports", todayDateString: dateTimeFunctions.dateToString(rightNow), - maps + maps, + lotTypes, + lotStatuses }); }; diff --git a/helpers/lotOccupancyDB/getReportData.js b/helpers/lotOccupancyDB/getReportData.js index 18d9ffa7..f846d8a8 100644 --- a/helpers/lotOccupancyDB/getReportData.js +++ b/helpers/lotOccupancyDB/getReportData.js @@ -51,6 +51,45 @@ export const getReportData = (reportName, reportParameters) => { case "lots-all": sql = "select * from Lots"; break; + case "lots-byLotTypeId": + sql = + "select l.lotId," + + " m.mapName, l.lotName," + + " t.lotType, s.lotStatus" + + " 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," + + " m.mapName, l.lotName," + + " t.lotType, s.lotStatus" + + " 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," + + " m.mapName, l.lotName," + + " t.lotType, s.lotStatus" + + " 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; case "lotComments-all": sql = "select * from LotComments"; break; diff --git a/helpers/lotOccupancyDB/getReportData.ts b/helpers/lotOccupancyDB/getReportData.ts index b1e9ecc2..ac29a10c 100644 --- a/helpers/lotOccupancyDB/getReportData.ts +++ b/helpers/lotOccupancyDB/getReportData.ts @@ -70,6 +70,54 @@ export const getReportData = ( sql = "select * from Lots"; break; + case "lots-byLotTypeId": + sql = + "select l.lotId," + + " m.mapName, l.lotName," + + " t.lotType, s.lotStatus" + + " 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," + + " m.mapName, l.lotName," + + " t.lotType, s.lotStatus" + + " 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," + + " m.mapName, l.lotName," + + " t.lotType, s.lotStatus" + + " 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; + case "lotComments-all": sql = "select * from LotComments"; break; diff --git a/views/report-search.ejs b/views/report-search.ejs index 5b075b3f..cad9c7a1 100644 --- a/views/report-search.ejs +++ b/views/report-search.ejs @@ -114,6 +114,111 @@