From 528ab4b7c28e204d2ac6d92033111d7108a58e2b Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Wed, 24 Aug 2022 09:46:57 -0400 Subject: [PATCH] basic lot occupancy print --- handlers/lotOccupancies-get/print.d.ts | 3 + handlers/lotOccupancies-get/print.js | 13 ++ handlers/lotOccupancies-get/print.ts | 27 +++ routes/lotOccupancies.js | 2 + routes/lotOccupancies.ts | 4 + views/lotOccupancy-edit.ejs | 30 +++- views/lotOccupancy-print.ejs | 225 +++++++++++++++++++++++++ views/lotOccupancy-view.ejs | 20 ++- 8 files changed, 314 insertions(+), 10 deletions(-) create mode 100644 handlers/lotOccupancies-get/print.d.ts create mode 100644 handlers/lotOccupancies-get/print.js create mode 100644 handlers/lotOccupancies-get/print.ts create mode 100644 views/lotOccupancy-print.ejs diff --git a/handlers/lotOccupancies-get/print.d.ts b/handlers/lotOccupancies-get/print.d.ts new file mode 100644 index 00000000..9621c611 --- /dev/null +++ b/handlers/lotOccupancies-get/print.d.ts @@ -0,0 +1,3 @@ +import type { RequestHandler } from "express"; +export declare const handler: RequestHandler; +export default handler; diff --git a/handlers/lotOccupancies-get/print.js b/handlers/lotOccupancies-get/print.js new file mode 100644 index 00000000..71d22633 --- /dev/null +++ b/handlers/lotOccupancies-get/print.js @@ -0,0 +1,13 @@ +import * as configFunctions from "../../helpers/functions.config.js"; +import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js"; +export const handler = (request, response) => { + const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId); + if (!lotOccupancy) { + return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lotOccupancies/?error=lotOccupancyIdNotFound"); + } + return response.render("lotOccupancy-print", { + headTitle: configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " Print", + lotOccupancy + }); +}; +export default handler; diff --git a/handlers/lotOccupancies-get/print.ts b/handlers/lotOccupancies-get/print.ts new file mode 100644 index 00000000..f5067354 --- /dev/null +++ b/handlers/lotOccupancies-get/print.ts @@ -0,0 +1,27 @@ +import type { + RequestHandler +} from "express"; + +import * as configFunctions from "../../helpers/functions.config.js"; + +import { + getLotOccupancy +} from "../../helpers/lotOccupancyDB/getLotOccupancy.js"; + + +export const handler: RequestHandler = (request, response) => { + + const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId); + + if (!lotOccupancy) { + return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lotOccupancies/?error=lotOccupancyIdNotFound"); + } + + return response.render("lotOccupancy-print", { + headTitle: configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " Print", + lotOccupancy + }); +}; + + +export default handler; \ No newline at end of file diff --git a/routes/lotOccupancies.js b/routes/lotOccupancies.js index 3704d4aa..ea373333 100644 --- a/routes/lotOccupancies.js +++ b/routes/lotOccupancies.js @@ -2,6 +2,7 @@ import { Router } from "express"; import handler_search from "../handlers/lotOccupancies-get/search.js"; import handler_doSearchLotOccupancies from "../handlers/lotOccupancies-post/doSearchLotOccupancies.js"; import handler_view from "../handlers/lotOccupancies-get/view.js"; +import handler_print from "../handlers/lotOccupancies-get/print.js"; import handler_new from "../handlers/lotOccupancies-get/new.js"; import handler_doGetOccupancyTypeFields from "../handlers/lotOccupancies-post/doGetOccupancyTypeFields.js"; import handler_doCreateLotOccupancy from "../handlers/lotOccupancies-post/doCreateLotOccupancy.js"; @@ -27,6 +28,7 @@ router.get("/new", permissionHandlers.updateGetHandler, handler_new); router.post("/doGetOccupancyTypeFields", permissionHandlers.updatePostHandler, handler_doGetOccupancyTypeFields); router.post("/doCreateLotOccupancy", permissionHandlers.updatePostHandler, handler_doCreateLotOccupancy); router.get("/:lotOccupancyId", handler_view); +router.get("/:lotOccupancyId/print", handler_print); router.get("/:lotOccupancyId/edit", permissionHandlers.updateGetHandler, handler_edit); router.post("/doUpdateLotOccupancy", permissionHandlers.updatePostHandler, handler_doUpdateLotOccupancy); router.post("/doDeleteLotOccupancy", permissionHandlers.updatePostHandler, handler_doDeleteLotOccupancy); diff --git a/routes/lotOccupancies.ts b/routes/lotOccupancies.ts index 1bd079c0..80319918 100644 --- a/routes/lotOccupancies.ts +++ b/routes/lotOccupancies.ts @@ -6,6 +6,7 @@ import handler_search from "../handlers/lotOccupancies-get/search.js"; import handler_doSearchLotOccupancies from "../handlers/lotOccupancies-post/doSearchLotOccupancies.js"; import handler_view from "../handlers/lotOccupancies-get/view.js"; +import handler_print from "../handlers/lotOccupancies-get/print.js"; import handler_new from "../handlers/lotOccupancies-get/new.js"; import handler_doGetOccupancyTypeFields from "../handlers/lotOccupancies-post/doGetOccupancyTypeFields.js"; @@ -62,6 +63,9 @@ router.post("/doCreateLotOccupancy", router.get("/:lotOccupancyId", handler_view); +router.get("/:lotOccupancyId/print", + handler_print); + // Edit router.get("/:lotOccupancyId/edit", diff --git a/views/lotOccupancy-edit.ejs b/views/lotOccupancy-edit.ejs index 2b5bf6d8..9b9eb163 100644 --- a/views/lotOccupancy-edit.ejs +++ b/views/lotOccupancy-edit.ejs @@ -17,7 +17,7 @@ <% if (!isCreate) { %>
  • - <%= configFunctions.getProperty("aliases.occupancy") %>: <%= lotOccupancy.lotName %> + <%= configFunctions.getProperty("aliases.occupancy") %>: <%= lotOccupancy.lotName || ("(No " + configFunctions.getProperty("aliases.lot") + ")") %>
  • <% } %> @@ -33,13 +33,29 @@ -

    - <% if (isCreate) { %> +<% if (isCreate) { %> +

    Create a New <%= configFunctions.getProperty("aliases.occupancy") %> Record - <% } else { %> - Update <%= configFunctions.getProperty("aliases.occupancy") %> - <% } %> -

    + +<% } else { %> +
    +
    +
    +

    + Update <%= configFunctions.getProperty("aliases.occupancy") %> +

    +
    +
    + +
    +<% } %>
    diff --git a/views/lotOccupancy-print.ejs b/views/lotOccupancy-print.ejs new file mode 100644 index 00000000..9d995ead --- /dev/null +++ b/views/lotOccupancy-print.ejs @@ -0,0 +1,225 @@ +<%- include('_header-print'); -%> + +

    + <%= configFunctions.getProperty("aliases.lot") %> + <%= configFunctions.getProperty("aliases.occupancy") %> +

    + +
    +
    +

    + <%= configFunctions.getProperty("aliases.occupancy") %> Type
    + <%= lotOccupancy.occupancyType %> +

    +
    +
    +

    + <%= configFunctions.getProperty("aliases.lot") %>
    + <% if (lotOccupancy.lotId) { %> + <%= lotOccupancy.lotName %> + <% } else { %> + (No <%= configFunctions.getProperty("aliases.lot") %>) + <% } %> +

    +

    + <%= configFunctions.getProperty("aliases.map") %>
    + <% if (lotOccupancy.mapId) { %> + <%= lotOccupancy.mapName %> + <% } else { %> + (No <%= configFunctions.getProperty("aliases.map") %>) + <% } %> +

    +
    +
    +

    + Start Date
    + <%= lotOccupancy.occupancyStartDateString %> +

    +

    + End Date
    + <%= (lotOccupancy.occupancyEndDateString === "" ? "(No End Date)" : lotOccupancy.occupancyEndDateString) %> +

    +
    + <% if (lotOccupancy.lotOccupancyFields.length > 0) { %> +
    + <% for (const lotOccupancyField of lotOccupancy.lotOccupancyFields) { %> +

    + <%= lotOccupancyField.occupancyTypeField %>
    + <%= lotOccupancyField.lotOccupancyFieldValue || "(No Value)" %> +

    + <% } %> +
    + <% } %> +
    + +
    +

    <%= configFunctions.getProperty("aliases.occupants") %>

    + + <% if (lotOccupancy.lotOccupancyOccupants.length === 0) { %> +
    +

    + There are no <%= configFunctions.getProperty("aliases.occupants").toLowerCase() %> + associated with this record. +

    +
    + <% } else { %> + + + + + + + + + + + <% for (const lotOccupancyOccupant of lotOccupancy.lotOccupancyOccupants) { %> + + + + + + + <% } %> + +
    <%= configFunctions.getProperty("aliases.occupant") %> Type<%= configFunctions.getProperty("aliases.occupant") %>AddressPhone Number
    <%= lotOccupancyOccupant.lotOccupantType %><%= lotOccupancyOccupant.occupantName %> + <%= lotOccupancyOccupant.occupantAddress1 %>
    + <% if (lotOccupancyOccupant.occupantAddress2 && lotOccupancyOccupant.occupantAddress2 !== "") { %> + <%= lotOccupancyOccupant.occupantAddress2 %>
    + <% } %> + <%= lotOccupancyOccupant.occupantCity %>, <%= lotOccupancyOccupant.occupantProvince %>
    + <%= lotOccupancyOccupant.occupantPostalCode %> +
    + <%= lotOccupancyOccupant.occupantPhoneNumber %> +
    + <% } %> +
    + +<% if (lotOccupancy.lotOccupancyComments.length > 0) { %> +
    +

    Comments

    + + + + + + + + + + + <% for (const lotOccupancyComment of lotOccupancy.lotOccupancyComments) { %> + + + + + + <% } %> + +
    CommentorComment DateComment
    <%= lotOccupancyComment.recordCreate_userName %> + <%= lotOccupancyComment.lotOccupancyCommentDateString %> + <%= (lotOccupancyComment.lotOccupancyCommentTime === 0 ? "" : lotOccupancyComment.lotOccupancyCommentTimeString) %> + <%= lotOccupancyComment.lotOccupancyComment %>
    +
    +<% } %> + +
    +

    Fees

    + + <% if (lotOccupancy.lotOccupancyFees.length === 0) { %> +
    +

    + There are no fees applied to this <%= configFunctions.getProperty("aliases.occupancy").toLowerCase() %> record. +

    +
    + <% } else { %> + <% + let feeAmountTotal = 0; + let taxAmountTotal = 0; + %> + + + + + + + + + + + + + <% for (const lotOccupancyFee of lotOccupancy.lotOccupancyFees) { %> + <% + feeAmountTotal += (lotOccupancyFee.feeAmount * lotOccupancyFee.quantity); + taxAmountTotal += (lotOccupancyFee.taxAmount * lotOccupancyFee.quantity); + %> + + + <% if (lotOccupancyFee.quantity !== 1) { %> + + + + + <% } %> + + + <% } %> + + + + + + + + + + + + + + + +
    FeeUnit Cost×Quantity=Total
    "> + <%= lotOccupancyFee.feeName %> + $<%= lotOccupancyFee.feeAmount.toFixed(2) %>×<%= lotOccupancyFee.quantity %>=$<%= (lotOccupancyFee.feeAmount * lotOccupancyFee.quantity).toFixed(2) %>
    Subtotal$<%= feeAmountTotal.toFixed(2) %>
    Tax$<%= taxAmountTotal.toFixed(2) %>
    Grand Total$<%= (feeAmountTotal + taxAmountTotal).toFixed(2) %>
    + <% } %> +
    + +
    +

    Transactions

    + + <% if (lotOccupancy.lotOccupancyTransactions.length === 0) { %> +
    +

    + There are no transactions associated with this <%= configFunctions.getProperty("aliases.occupancy").toLowerCase() %> record. +

    +
    + <% } else { %> + + + + + + + + + + <% for (const lotOccupancyTransaction of lotOccupancy.lotOccupancyTransactions) { %> + + + + + + <% } %> + +
    Date<%= configFunctions.getProperty("aliases.externalReceiptNumber") %>Amount
    <%= lotOccupancyTransaction.transactionDateString %> + <%= lotOccupancyTransaction.externalReceiptNumber %>
    + <%= lotOccupancyTransaction.transactionNote %> +
    + $<%= lotOccupancyTransaction.transactionAmount.toFixed(2) %> +
    + <% } %> +
    + +<%- include('_footer-print'); -%> \ No newline at end of file diff --git a/views/lotOccupancy-view.ejs b/views/lotOccupancy-view.ejs index dea929d5..e3cee590 100644 --- a/views/lotOccupancy-view.ejs +++ b/views/lotOccupancy-view.ejs @@ -23,9 +23,23 @@ -

    - <%= configFunctions.getProperty("aliases.occupancy") %>: <%= lotOccupancy.lotName || ("(No " + configFunctions.getProperty("aliases.lot") + ")") %> -

    +
    +
    +
    +

    + <%= configFunctions.getProperty("aliases.occupancy") %>: <%= lotOccupancy.lotName || ("(No " + configFunctions.getProperty("aliases.lot") + ")") %> +

    +
    +
    + +
    <% if (user.userProperties.canUpdate) { %>