From 6990fd0a10f61f06917732eee169a8bf9cb6a65d Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Thu, 13 Oct 2022 10:13:45 -0400 Subject: [PATCH] ssm burial permit --- handlers/print-get/pdf.js | 5 +- handlers/print-get/pdf.ts | 6 +- helpers/functions.lotOccupancy.d.ts | 3 + helpers/functions.lotOccupancy.js | 17 +++++ helpers/functions.lotOccupancy.ts | 31 ++++++++ helpers/initializer.database.cemetery.js | 8 +- helpers/initializer.database.cemetery.ts | 12 ++- helpers/lotOccupancyDB/getLotOccupancy.js | 3 +- helpers/lotOccupancyDB/getLotOccupancy.ts | 3 +- views/print/pdf/ssm.cemetery.burialPermit.ejs | 73 ++++++++++++++++++- views/print/pdf/style.css | 37 +++++++++- views/print/pdf/workOrder-commentLog.ejs | 2 +- views/print/pdf/workOrder.ejs | 2 +- 13 files changed, 189 insertions(+), 13 deletions(-) create mode 100644 helpers/functions.lotOccupancy.d.ts create mode 100644 helpers/functions.lotOccupancy.js create mode 100644 helpers/functions.lotOccupancy.ts diff --git a/handlers/print-get/pdf.js b/handlers/print-get/pdf.js index c2eccdf3..5df76984 100644 --- a/handlers/print-get/pdf.js +++ b/handlers/print-get/pdf.js @@ -2,9 +2,11 @@ import path from "path"; import * as ejs from "ejs"; import * as configFunctions from "../../helpers/functions.config.js"; import * as dateTimeFunctions from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import * as lotOccupancyFunctions from "../../helpers/functions.lotOccupancy.js"; import { getReportData, getPdfPrintConfig } from "../../helpers/functions.print.js"; import { convertHTMLToPDF } from "@cityssm/pdf-puppeteer"; import camelcase from "camelcase"; +const attachmentOrInline = "attachment"; export const handler = async (request, response, next) => { const printName = request.params.printName; const printConfig = getPdfPrintConfig(printName); @@ -15,7 +17,7 @@ export const handler = async (request, response, next) => { const reportData = getReportData(printConfig, request.query); const reportPath = path.join("views", "print", "pdf", printName + ".ejs"); const pdfCallbackFunction = (pdf) => { - response.setHeader("Content-Disposition", "attachment;" + " filename=" + camelcase(printConfig.title) + ".pdf"); + response.setHeader("Content-Disposition", attachmentOrInline + ";" + " filename=" + camelcase(printConfig.title) + ".pdf"); response.setHeader("Content-Type", "application/pdf"); response.send(pdf); }; @@ -35,6 +37,7 @@ export const handler = async (request, response, next) => { }; reportData.configFunctions = configFunctions; reportData.dateTimeFunctions = dateTimeFunctions; + reportData.lotOccupancyFunctions = lotOccupancyFunctions; await ejs.renderFile(reportPath, reportData, {}, ejsCallbackFunction); }; export default handler; diff --git a/handlers/print-get/pdf.ts b/handlers/print-get/pdf.ts index daf83dd2..694d745e 100644 --- a/handlers/print-get/pdf.ts +++ b/handlers/print-get/pdf.ts @@ -5,12 +5,15 @@ import * as ejs from "ejs"; import * as configFunctions from "../../helpers/functions.config.js"; import * as dateTimeFunctions from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import * as lotOccupancyFunctions from "../../helpers/functions.lotOccupancy.js"; import { getReportData, getPdfPrintConfig } from "../../helpers/functions.print.js"; import { convertHTMLToPDF } from "@cityssm/pdf-puppeteer"; import camelcase from "camelcase"; +const attachmentOrInline: "attachment" | "inline" = "attachment"; + export const handler: RequestHandler = async (request, response, next) => { const printName = request.params.printName; @@ -30,7 +33,7 @@ export const handler: RequestHandler = async (request, response, next) => { const pdfCallbackFunction = (pdf: Buffer) => { response.setHeader( "Content-Disposition", - "attachment;" + " filename=" + camelcase(printConfig.title) + ".pdf" + attachmentOrInline + ";" + " filename=" + camelcase(printConfig.title) + ".pdf" ); response.setHeader("Content-Type", "application/pdf"); @@ -63,6 +66,7 @@ export const handler: RequestHandler = async (request, response, next) => { reportData.configFunctions = configFunctions; reportData.dateTimeFunctions = dateTimeFunctions; + reportData.lotOccupancyFunctions = lotOccupancyFunctions; await ejs.renderFile(reportPath, reportData, {}, ejsCallbackFunction); }; diff --git a/helpers/functions.lotOccupancy.d.ts b/helpers/functions.lotOccupancy.d.ts new file mode 100644 index 00000000..3869a95d --- /dev/null +++ b/helpers/functions.lotOccupancy.d.ts @@ -0,0 +1,3 @@ +import type * as recordTypes from "../types/recordTypes"; +export declare const filterOccupantsByLotOccupantType: (lotOccupancy: recordTypes.LotOccupancy, lotOccupantType: string) => recordTypes.LotOccupancyOccupant[]; +export declare const getFieldValueByOccupancyTypeField: (lotOccupancy: recordTypes.LotOccupancy, occupancyTypeField: string) => string; diff --git a/helpers/functions.lotOccupancy.js b/helpers/functions.lotOccupancy.js new file mode 100644 index 00000000..72620d9e --- /dev/null +++ b/helpers/functions.lotOccupancy.js @@ -0,0 +1,17 @@ +export const filterOccupantsByLotOccupantType = (lotOccupancy, lotOccupantType) => { + const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase(); + const occupants = lotOccupancy.lotOccupancyOccupants.filter((possibleOccupant) => { + return possibleOccupant.lotOccupantType.toLowerCase() === lotOccupantTypeLowerCase; + }); + return occupants; +}; +export const getFieldValueByOccupancyTypeField = (lotOccupancy, occupancyTypeField) => { + const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase(); + const field = lotOccupancy.lotOccupancyFields.find((possibleField) => { + return possibleField.occupancyTypeField.toLowerCase() === occupancyTypeFieldLowerCase; + }); + if (field) { + return field.lotOccupancyFieldValue; + } + return undefined; +}; diff --git a/helpers/functions.lotOccupancy.ts b/helpers/functions.lotOccupancy.ts new file mode 100644 index 00000000..b8c45036 --- /dev/null +++ b/helpers/functions.lotOccupancy.ts @@ -0,0 +1,31 @@ +import type * as recordTypes from "../types/recordTypes"; + +export const filterOccupantsByLotOccupantType = ( + lotOccupancy: recordTypes.LotOccupancy, + lotOccupantType: string +): recordTypes.LotOccupancyOccupant[] => { + const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase(); + + const occupants = lotOccupancy.lotOccupancyOccupants.filter((possibleOccupant) => { + return possibleOccupant.lotOccupantType.toLowerCase() === lotOccupantTypeLowerCase; + }); + + return occupants; +}; + +export const getFieldValueByOccupancyTypeField = ( + lotOccupancy: recordTypes.LotOccupancy, + occupancyTypeField: string +): string => { + const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase(); + + const field = lotOccupancy.lotOccupancyFields.find((possibleField) => { + return possibleField.occupancyTypeField.toLowerCase() === occupancyTypeFieldLowerCase; + }); + + if (field) { + return field.lotOccupancyFieldValue; + } + + return undefined; +}; diff --git a/helpers/initializer.database.cemetery.js b/helpers/initializer.database.cemetery.js index 42d88ccc..ee54cdbd 100644 --- a/helpers/initializer.database.cemetery.js +++ b/helpers/initializer.database.cemetery.js @@ -68,13 +68,17 @@ const initializeCemeteryDatabase = () => { orderNumber: 1 }, session); addLotOccupantType({ - lotOccupantType: "Preneed Owner", + lotOccupantType: "Funeral Director", orderNumber: 2 }, session); addLotOccupantType({ - lotOccupantType: "Purchaser", + lotOccupantType: "Preneed Owner", orderNumber: 3 }, session); + addLotOccupantType({ + lotOccupantType: "Purchaser", + orderNumber: 4 + }, session); addOccupancyType({ occupancyType: "Preneed", orderNumber: 1 diff --git a/helpers/initializer.database.cemetery.ts b/helpers/initializer.database.cemetery.ts index 1f223f7e..23227792 100644 --- a/helpers/initializer.database.cemetery.ts +++ b/helpers/initializer.database.cemetery.ts @@ -143,7 +143,7 @@ const initializeCemeteryDatabase = () => { addLotOccupantType( { - lotOccupantType: "Preneed Owner", + lotOccupantType: "Funeral Director", orderNumber: 2 }, session @@ -151,12 +151,20 @@ const initializeCemeteryDatabase = () => { addLotOccupantType( { - lotOccupantType: "Purchaser", + lotOccupantType: "Preneed Owner", orderNumber: 3 }, session ); + addLotOccupantType( + { + lotOccupantType: "Purchaser", + orderNumber: 4 + }, + session + ); + /* * Occupancy Types */ diff --git a/helpers/lotOccupancyDB/getLotOccupancy.js b/helpers/lotOccupancyDB/getLotOccupancy.js index acae0482..5336358f 100644 --- a/helpers/lotOccupancyDB/getLotOccupancy.js +++ b/helpers/lotOccupancyDB/getLotOccupancy.js @@ -17,7 +17,8 @@ export const getLotOccupancy = (lotOccupancyId) => { " o.lotId, l.lotName, l.lotTypeId," + " l.mapId, m.mapName," + " o.occupancyStartDate, userFn_dateIntegerToString(o.occupancyStartDate) as occupancyStartDateString," + - " o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString" + + " o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString," + + " o.recordUpdate_timeMillis" + " from LotOccupancies o" + " left join OccupancyTypes t on o.occupancyTypeId = t.occupancyTypeId" + " left join Lots l on o.lotId = l.lotId" + diff --git a/helpers/lotOccupancyDB/getLotOccupancy.ts b/helpers/lotOccupancyDB/getLotOccupancy.ts index c1ca4feb..df10dd0c 100644 --- a/helpers/lotOccupancyDB/getLotOccupancy.ts +++ b/helpers/lotOccupancyDB/getLotOccupancy.ts @@ -32,7 +32,8 @@ export const getLotOccupancy = ( " o.lotId, l.lotName, l.lotTypeId," + " l.mapId, m.mapName," + " o.occupancyStartDate, userFn_dateIntegerToString(o.occupancyStartDate) as occupancyStartDateString," + - " o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString" + + " o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString," + + " o.recordUpdate_timeMillis" + " from LotOccupancies o" + " left join OccupancyTypes t on o.occupancyTypeId = t.occupancyTypeId" + " left join Lots l on o.lotId = l.lotId" + diff --git a/views/print/pdf/ssm.cemetery.burialPermit.ejs b/views/print/pdf/ssm.cemetery.burialPermit.ejs index bbf98173..9b9491ff 100644 --- a/views/print/pdf/ssm.cemetery.burialPermit.ejs +++ b/views/print/pdf/ssm.cemetery.burialPermit.ejs @@ -1,10 +1,79 @@ +<% + const funeralDirectorLotOccupantType = "Funeral Director"; + const funeralDirectorOccupants = lotOccupancyFunctions.filterOccupantsByLotOccupantType(lotOccupancy, funeralDirectorLotOccupantType); + + const deceasedLotOccupantType = "Deceased"; + const deceasedOccupants = lotOccupancyFunctions.filterOccupantsByLotOccupantType(lotOccupancy, deceasedLotOccupantType); + + const deathDateOccupantTypeField = "Death Date"; +%> - -

Burial Permit

+ +

Province of Ontario

+

Vital Statistics Act

+

Burial Permit

+ +

+ Under the Vital Statistics Act + and the regulations, + subject to the limitations thereof, + this permit is granted to:
+

+ +

+ <% if (funeralDirectorOccupants.length > 0) { %> + <% const funeralDirector = funeralDirectorOccupants[0]; %> + <%= funeralDirector.occupantName %>
+ <%= funeralDirector.occupantAddress1 %>
+ <% if (funeralDirector.occupantAddress2) { %><%= funeralDirector.occupantAddress2 %>
<% } %> + <%= funeralDirector.occupantCity %>, <%= funeralDirector.occupantProvince %>
+ <%= funeralDirector.occupantPostalCode %> + <% } %> +

+ +

+ for the purpose of the burial or other disposition of the body of: +

+ +

+ <% if (deceasedOccupants.length > 0) { %> + <% const deceased = deceasedOccupants[0]; %> + <%= deceased.occupantName %> + <% } %> +

+ +

+ who died at +   + in Ontario on + + <%= lotOccupancyFunctions.getFieldValueByOccupancyTypeField(lotOccupancy, deathDateOccupantTypeField); %> + + . +

+ +

+  
+ (Signature of Division Registrar) +

+ +

+ Sault Ste. Marie +   +   +   + 5724 +

+ +

+ + <%= dateTimeFunctions.dateToString(new Date(lotOccupancy.recordUpdate_timeMillis)) %> + +

\ No newline at end of file diff --git a/views/print/pdf/style.css b/views/print/pdf/style.css index 142971a9..5894257a 100644 --- a/views/print/pdf/style.css +++ b/views/print/pdf/style.css @@ -29,6 +29,13 @@ body { content: '\2714'; } +.field { + border-bottom: 1px solid black; + display: inline-block; + width: 100%; + padding: 10px 0; +} + /* Data Table */ .data-table { @@ -78,10 +85,30 @@ td.is-width-1 { margin-top: 10px; } +.mt-4 { + margin-top: 40px; +} + +.mt-6 { + margin-top: 60px; +} + .mb-0 { margin-bottom: 0; } +.mb-1 { + margin-bottom: 10px; +} + +.mb-2 { + margin-bottom: 20px; +} + +.mb-4 { + margin-bottom: 40px; +} + .pl-1 { padding-left: 10px; } @@ -96,7 +123,15 @@ td.is-width-1 { text-align: right; } -.has-text-italicized { +.has-text-centered { + text-align: center; +} + +.is-capitalized { + text-transform: uppercase; +} + +.is-italic { font-style: italic; } diff --git a/views/print/pdf/workOrder-commentLog.ejs b/views/print/pdf/workOrder-commentLog.ejs index f922e9ef..82a84f78 100644 --- a/views/print/pdf/workOrder-commentLog.ejs +++ b/views/print/pdf/workOrder-commentLog.ejs @@ -72,7 +72,7 @@ <% } %> -

+

<% const recordCreateDate = new Date(workOrder.recordCreate_timeMillis); const currentDate = new Date(); diff --git a/views/print/pdf/workOrder.ejs b/views/print/pdf/workOrder.ejs index 6c22be60..935430c4 100644 --- a/views/print/pdf/workOrder.ejs +++ b/views/print/pdf/workOrder.ejs @@ -143,7 +143,7 @@

Notes

-

+

<% const recordCreateDate = new Date(workOrder.recordCreate_timeMillis); const currentDate = new Date();