From 5f6c6a0be5a9eb8ed35a796fe85b1bd4138bb3af Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Wed, 5 Mar 2025 15:45:55 -0500 Subject: [PATCH] refactoring, development on contracts --- data/config.base.js | 1 - data/config.base.ts | 1 - database/addContract.d.ts | 7 +- database/addContract.js | 25 +- database/addContract.ts | 31 +- database/addContractType.ts | 1 + database/addIntermentContainerType.d.ts | 6 + database/addIntermentContainerType.js | 16 + database/addIntermentContainerType.ts | 42 ++ database/addRecord.d.ts | 2 +- database/addRecord.js | 3 +- database/addRecord.ts | 6 +- database/getCommittalTypes.d.ts | 2 + database/getCommittalTypes.js | 21 + database/getCommittalTypes.ts | 38 ++ database/getContract.js | 7 +- database/getContract.ts | 7 +- database/getContractInterments.js | 11 +- database/getContractInterments.ts | 11 +- database/getContractTypes.js | 2 +- database/getContractTypes.ts | 2 +- database/getContracts.js | 15 +- database/getContracts.ts | 16 +- database/getIntermentCommittalTypes.d.ts | 2 - database/getIntermentCommittalTypes.js | 12 - database/getIntermentCommittalTypes.ts | 22 - database/getIntermentContainerTypes.js | 13 +- database/getIntermentContainerTypes.ts | 22 +- database/getWorkOrders.d.ts | 2 +- database/getWorkOrders.js | 4 +- database/getWorkOrders.ts | 6 +- database/initializeDatabase.js | 71 ++- database/initializeDatabase.ts | 105 +++- database/updateRecordOrderNumber.d.ts | 2 +- database/updateRecordOrderNumber.js | 2 + database/updateRecordOrderNumber.ts | 4 + handlers/api-get/milestoneICS.js | 2 +- handlers/api-get/milestoneICS.ts | 2 +- handlers/contracts-get/edit.js | 6 +- handlers/contracts-get/edit.ts | 6 + handlers/contracts-get/new.js | 6 +- handlers/contracts-get/new.ts | 6 +- .../doUpdateBurialSiteStatus.d.ts | 2 +- .../doUpdateBurialSiteStatus.js | 2 +- .../doUpdateBurialSiteStatus.ts | 4 +- helpers/functions.cache.d.ts | 8 +- helpers/functions.cache.js | 32 +- helpers/functions.cache.ts | 42 +- public/html/burialSite-editLotStatus.html | 6 +- public/html/workOrder-addLot.html | 6 +- public/html/workOrder-addLotOccupancy.html | 6 +- public/javascripts/contract.edit.js | 114 +++- public/javascripts/contract.edit.ts | 150 ++++-- public/javascripts/contract.search.js | 3 +- public/javascripts/contract.search.ts | 3 +- public/javascripts/dashboard.js | 4 +- public/javascripts/dashboard.ts | 6 +- public/javascripts/workOrder.edit.js | 56 +- public/javascripts/workOrder.edit.ts | 68 +-- .../workOrder.milestoneCalendar.js | 2 +- .../workOrder.milestoneCalendar.ts | 2 +- public/javascripts/workOrder.search.js | 4 +- public/javascripts/workOrder.search.ts | 4 +- routes/funeralHomes.js | 2 +- routes/funeralHomes.ts | 4 +- temp/legacy.importFromCSV.js | 44 +- temp/legacy.importFromCSV.ts | 44 +- test/functions.js | 6 +- test/functions.ts | 6 +- types/recordTypes.d.ts | 19 +- types/recordTypes.ts | 23 +- views/contract-edit.ejs | 251 ++++++--- views/contract-view.ejs | 503 ++++++++++-------- views/print/pdf/ssm.cemetery.contract.ejs | 8 +- views/print/pdf/workOrder.ejs | 10 +- views/print/screen/contract.ejs | 16 +- views/report-search.ejs | 182 +++---- views/workOrder-edit.ejs | 2 +- views/workOrder-search.ejs | 4 +- views/workOrder-view.ejs | 16 +- 80 files changed, 1376 insertions(+), 856 deletions(-) create mode 100644 database/addIntermentContainerType.d.ts create mode 100644 database/addIntermentContainerType.js create mode 100644 database/addIntermentContainerType.ts create mode 100644 database/getCommittalTypes.d.ts create mode 100644 database/getCommittalTypes.js create mode 100644 database/getCommittalTypes.ts delete mode 100644 database/getIntermentCommittalTypes.d.ts delete mode 100644 database/getIntermentCommittalTypes.js delete mode 100644 database/getIntermentCommittalTypes.ts diff --git a/data/config.base.js b/data/config.base.js index 4f24c6e7..b782334f 100644 --- a/data/config.base.js +++ b/data/config.base.js @@ -6,7 +6,6 @@ export const config = { aliases: {}, settings: { fees: {}, - cemeteries: {}, burialSites: {}, contracts: {}, workOrders: {}, diff --git a/data/config.base.ts b/data/config.base.ts index 05960e83..38107974 100644 --- a/data/config.base.ts +++ b/data/config.base.ts @@ -8,7 +8,6 @@ export const config: Config = { aliases: {}, settings: { fees: {}, - cemeteries: {}, burialSites: {}, contracts: {}, workOrders: {}, diff --git a/database/addContract.d.ts b/database/addContract.d.ts index 5cd0cb29..7600d93e 100644 --- a/database/addContract.d.ts +++ b/database/addContract.d.ts @@ -1,4 +1,4 @@ -import { type DateString } from '@cityssm/utils-datetime'; +import { type DateString, type TimeString } from '@cityssm/utils-datetime'; import type { PoolConnection } from 'better-sqlite-pool'; export interface AddContractForm { contractTypeId: string | number; @@ -18,6 +18,9 @@ export interface AddContractForm { purchaserRelationship?: string; funeralHomeId?: string | number; funeralDirectorName?: string; + funeralDateString?: DateString | ''; + funeralTimeString?: TimeString | ''; + committalTypeId?: string | number; deceasedName?: string; deceasedAddress1?: string; deceasedAddress2?: string; @@ -28,8 +31,6 @@ export interface AddContractForm { birthPlace?: string; deathDateString?: DateString | ''; deathPlace?: string; - intermentDateString?: DateString | ''; intermentContainerTypeId?: string | number; - intermentCommittalTypeId?: string | number; } export default function addContract(addForm: AddContractForm, user: User, connectedDatabase?: PoolConnection): Promise; diff --git a/database/addContract.js b/database/addContract.js index 2348e7a2..f6a7109f 100644 --- a/database/addContract.js +++ b/database/addContract.js @@ -1,4 +1,4 @@ -import { dateStringToInteger } from '@cityssm/utils-datetime'; +import { dateStringToInteger, timeStringToInteger } from '@cityssm/utils-datetime'; import addOrUpdateContractField from './addOrUpdateContractField.js'; import { acquireConnection } from './pool.js'; // eslint-disable-next-line complexity @@ -14,12 +14,18 @@ export default async function addContract(addForm, user, connectedDatabase) { purchaserCity, purchaserProvince, purchaserPostalCode, purchaserPhoneNumber, purchaserEmail, purchaserRelationship, funeralHomeId, funeralDirectorName, + funeralDate, funeralTime, + committalTypeId, recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis) - values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) + values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) .run(addForm.contractTypeId, addForm.burialSiteId === '' ? undefined : addForm.burialSiteId, contractStartDate, addForm.contractEndDateString === '' ? undefined - : dateStringToInteger(addForm.contractEndDateString), addForm.purchaserName ?? '', addForm.purchaserAddress1 ?? '', addForm.purchaserAddress2 ?? '', addForm.purchaserCity ?? '', addForm.purchaserProvince ?? '', addForm.purchaserPostalCode ?? '', addForm.purchaserPhoneNumber ?? '', addForm.purchaserEmail ?? '', addForm.purchaserRelationship ?? '', addForm.funeralHomeId === '' ? undefined : addForm.funeralHomeId, addForm.funeralDirectorName ?? '', user.userName, rightNowMillis, user.userName, rightNowMillis); + : dateStringToInteger(addForm.contractEndDateString), addForm.purchaserName ?? '', addForm.purchaserAddress1 ?? '', addForm.purchaserAddress2 ?? '', addForm.purchaserCity ?? '', addForm.purchaserProvince ?? '', addForm.purchaserPostalCode ?? '', addForm.purchaserPhoneNumber ?? '', addForm.purchaserEmail ?? '', addForm.purchaserRelationship ?? '', addForm.funeralHomeId === '' ? undefined : addForm.funeralHomeId, addForm.funeralDirectorName ?? '', addForm.funeralDateString === '' + ? undefined + : dateStringToInteger(addForm.funeralDateString), addForm.funeralTimeString === '' + ? undefined + : timeStringToInteger(addForm.funeralTimeString), addForm.committalTypeId === '' ? undefined : addForm.committalTypeId, user.userName, rightNowMillis, user.userName, rightNowMillis); const contractId = result.lastInsertRowid; /* * Add contract fields @@ -46,22 +52,17 @@ export default async function addContract(addForm, user, connectedDatabase) { deceasedCity, deceasedProvince, deceasedPostalCode, birthDate, deathDate, birthPlace, deathPlace, - intermentDate, - intermentContainerTypeId, intermentCommittalTypeId, + intermentContainerTypeId, recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis) - values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) + values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) .run(contractId, 1, addForm.deceasedName ?? '', addForm.deceasedAddress1 ?? '', addForm.deceasedAddress2 ?? '', addForm.deceasedCity ?? '', addForm.deceasedProvince ?? '', addForm.deceasedPostalCode ?? '', addForm.birthDateString === '' ? undefined : dateStringToInteger(addForm.birthDateString), addForm.deathDateString === '' ? undefined - : dateStringToInteger(addForm.deathDateString), addForm.birthPlace ?? '', addForm.deathPlace ?? '', addForm.intermentDateString === '' + : dateStringToInteger(addForm.deathDateString), addForm.birthPlace ?? '', addForm.deathPlace ?? '', addForm.intermentContainerTypeId === '' ? undefined - : dateStringToInteger(addForm.intermentDateString), addForm.intermentContainerTypeId === '' - ? undefined - : addForm.intermentContainerTypeId, addForm.intermentCommittalTypeId === '' - ? undefined - : addForm.intermentCommittalTypeId, user.userName, rightNowMillis, user.userName, rightNowMillis); + : addForm.intermentContainerTypeId, user.userName, rightNowMillis, user.userName, rightNowMillis); } if (connectedDatabase === undefined) { database.release(); diff --git a/database/addContract.ts b/database/addContract.ts index 10928413..2900d06d 100644 --- a/database/addContract.ts +++ b/database/addContract.ts @@ -1,6 +1,8 @@ import { type DateString, - dateStringToInteger + type TimeString, + dateStringToInteger, + timeStringToInteger } from '@cityssm/utils-datetime' import type { PoolConnection } from 'better-sqlite-pool' @@ -29,6 +31,9 @@ export interface AddContractForm { funeralHomeId?: string | number funeralDirectorName?: string + funeralDateString?: DateString | '' + funeralTimeString?: TimeString | '' + committalTypeId?: string | number deceasedName?: string deceasedAddress1?: string @@ -41,9 +46,7 @@ export interface AddContractForm { birthPlace?: string deathDateString?: DateString | '' deathPlace?: string - intermentDateString?: DateString | '' intermentContainerTypeId?: string | number - intermentCommittalTypeId?: string | number } // eslint-disable-next-line complexity @@ -69,9 +72,11 @@ export default async function addContract( purchaserCity, purchaserProvince, purchaserPostalCode, purchaserPhoneNumber, purchaserEmail, purchaserRelationship, funeralHomeId, funeralDirectorName, + funeralDate, funeralTime, + committalTypeId, recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis) - values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` + values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` ) .run( addForm.contractTypeId, @@ -91,6 +96,13 @@ export default async function addContract( addForm.purchaserRelationship ?? '', addForm.funeralHomeId === '' ? undefined : addForm.funeralHomeId, addForm.funeralDirectorName ?? '', + addForm.funeralDateString === '' + ? undefined + : dateStringToInteger(addForm.funeralDateString as DateString), + addForm.funeralTimeString === '' + ? undefined + : timeStringToInteger(addForm.funeralTimeString as TimeString), + addForm.committalTypeId === '' ? undefined : addForm.committalTypeId, user.userName, rightNowMillis, user.userName, @@ -136,11 +148,10 @@ export default async function addContract( deceasedCity, deceasedProvince, deceasedPostalCode, birthDate, deathDate, birthPlace, deathPlace, - intermentDate, - intermentContainerTypeId, intermentCommittalTypeId, + intermentContainerTypeId, recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis) - values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` + values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` ) .run( @@ -160,15 +171,9 @@ export default async function addContract( : dateStringToInteger(addForm.deathDateString as DateString), addForm.birthPlace ?? '', addForm.deathPlace ?? '', - addForm.intermentDateString === '' - ? undefined - : dateStringToInteger(addForm.intermentDateString as DateString), addForm.intermentContainerTypeId === '' ? undefined : addForm.intermentContainerTypeId, - addForm.intermentCommittalTypeId === '' - ? undefined - : addForm.intermentCommittalTypeId, user.userName, rightNowMillis, user.userName, diff --git a/database/addContractType.ts b/database/addContractType.ts index 80ddda25..6a9fe4c6 100644 --- a/database/addContractType.ts +++ b/database/addContractType.ts @@ -1,4 +1,5 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js' + import { acquireConnection } from './pool.js' export interface AddForm { diff --git a/database/addIntermentContainerType.d.ts b/database/addIntermentContainerType.d.ts new file mode 100644 index 00000000..399e41bf --- /dev/null +++ b/database/addIntermentContainerType.d.ts @@ -0,0 +1,6 @@ +export interface AddForm { + intermentContainerType: string; + isCremationType?: string; + orderNumber?: number; +} +export default function addIntermentContainerType(addForm: AddForm, user: User): Promise; diff --git a/database/addIntermentContainerType.js b/database/addIntermentContainerType.js new file mode 100644 index 00000000..bfec6eb2 --- /dev/null +++ b/database/addIntermentContainerType.js @@ -0,0 +1,16 @@ +import { clearCacheByTableName } from '../helpers/functions.cache.js'; +import { acquireConnection } from './pool.js'; +export default async function addIntermentContainerType(addForm, user) { + const database = await acquireConnection(); + const rightNowMillis = Date.now(); + const result = database + .prepare(`insert into IntermentContainerTypes ( + intermentContainerType, isCremationType, orderNumber, + recordCreate_userName, recordCreate_timeMillis, + recordUpdate_userName, recordUpdate_timeMillis) + values (?, ?, ?, ?, ?, ?, ?)`) + .run(addForm.intermentContainerType, addForm.isCremationType === undefined ? 0 : 1, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis); + database.release(); + clearCacheByTableName('IntermentContainerTypes'); + return result.lastInsertRowid; +} diff --git a/database/addIntermentContainerType.ts b/database/addIntermentContainerType.ts new file mode 100644 index 00000000..83852760 --- /dev/null +++ b/database/addIntermentContainerType.ts @@ -0,0 +1,42 @@ +import { clearCacheByTableName } from '../helpers/functions.cache.js' + +import { acquireConnection } from './pool.js' + +export interface AddForm { + intermentContainerType: string + isCremationType?: string + orderNumber?: number +} + +export default async function addIntermentContainerType( + addForm: AddForm, + user: User +): Promise { + const database = await acquireConnection() + + const rightNowMillis = Date.now() + + const result = database + .prepare( + `insert into IntermentContainerTypes ( + intermentContainerType, isCremationType, orderNumber, + recordCreate_userName, recordCreate_timeMillis, + recordUpdate_userName, recordUpdate_timeMillis) + values (?, ?, ?, ?, ?, ?, ?)` + ) + .run( + addForm.intermentContainerType, + addForm.isCremationType === undefined ? 0 : 1, + addForm.orderNumber ?? -1, + user.userName, + rightNowMillis, + user.userName, + rightNowMillis + ) + + database.release() + + clearCacheByTableName('IntermentContainerTypes') + + return result.lastInsertRowid as number +} diff --git a/database/addRecord.d.ts b/database/addRecord.d.ts index f0c95c15..cf62d577 100644 --- a/database/addRecord.d.ts +++ b/database/addRecord.d.ts @@ -1,3 +1,3 @@ -type RecordTable = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'IntermentContainerTypes' | 'IntermentCommittalTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; +type RecordTable = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'CommittalTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; export default function addRecord(recordTable: RecordTable, recordName: string, orderNumber: number | string, user: User): Promise; export {}; diff --git a/database/addRecord.js b/database/addRecord.js index 8da2958d..4d00e72e 100644 --- a/database/addRecord.js +++ b/database/addRecord.js @@ -3,8 +3,7 @@ import { acquireConnection } from './pool.js'; const recordNameColumns = new Map(); recordNameColumns.set('BurialSiteStatuses', 'burialSiteStatus'); recordNameColumns.set('BurialSiteTypes', 'burialSiteType'); -recordNameColumns.set('IntermentContainerTypes', 'intermentContainerType'); -recordNameColumns.set('IntermentCommittalTypes', 'intermentCommittalType'); +recordNameColumns.set('CommittalTypes', 'committalType'); recordNameColumns.set('WorkOrderMilestoneTypes', 'workOrderMilestoneType'); recordNameColumns.set('WorkOrderTypes', 'workOrderType'); export default async function addRecord(recordTable, recordName, orderNumber, user) { diff --git a/database/addRecord.ts b/database/addRecord.ts index 756be3bc..4e35c2be 100644 --- a/database/addRecord.ts +++ b/database/addRecord.ts @@ -5,16 +5,14 @@ import { acquireConnection } from './pool.js' type RecordTable = | 'BurialSiteStatuses' | 'BurialSiteTypes' - | 'IntermentContainerTypes' - | 'IntermentCommittalTypes' + | 'CommittalTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes' const recordNameColumns = new Map() recordNameColumns.set('BurialSiteStatuses', 'burialSiteStatus') recordNameColumns.set('BurialSiteTypes', 'burialSiteType') -recordNameColumns.set('IntermentContainerTypes', 'intermentContainerType') -recordNameColumns.set('IntermentCommittalTypes', 'intermentCommittalType') +recordNameColumns.set('CommittalTypes', 'committalType') recordNameColumns.set('WorkOrderMilestoneTypes', 'workOrderMilestoneType') recordNameColumns.set('WorkOrderTypes', 'workOrderType') diff --git a/database/getCommittalTypes.d.ts b/database/getCommittalTypes.d.ts new file mode 100644 index 00000000..55569a89 --- /dev/null +++ b/database/getCommittalTypes.d.ts @@ -0,0 +1,2 @@ +import type { CommittalType } from '../types/recordTypes.js'; +export default function getCommittalTypes(): Promise; diff --git a/database/getCommittalTypes.js b/database/getCommittalTypes.js new file mode 100644 index 00000000..dbab67b2 --- /dev/null +++ b/database/getCommittalTypes.js @@ -0,0 +1,21 @@ +import { acquireConnection } from './pool.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; +export default async function getCommittalTypes() { + const database = await acquireConnection(); + const committalTypes = database + .prepare(`select committalTypeId, committalType, orderNumber + from CommittalTypes + where recordDelete_timeMillis is null + order by orderNumber, committalType, committalTypeId`) + .all(); + let expectedOrderNumber = -1; + for (const committalType of committalTypes) { + expectedOrderNumber += 1; + if (committalType.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber('CommittalTypes', committalType.committalTypeId, expectedOrderNumber, database); + committalType.orderNumber = expectedOrderNumber; + } + } + database.release(); + return committalTypes; +} diff --git a/database/getCommittalTypes.ts b/database/getCommittalTypes.ts new file mode 100644 index 00000000..0783edc8 --- /dev/null +++ b/database/getCommittalTypes.ts @@ -0,0 +1,38 @@ +import type { CommittalType } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' + +export default async function getCommittalTypes(): Promise { + const database = await acquireConnection() + + const committalTypes = database + .prepare( + `select committalTypeId, committalType, orderNumber + from CommittalTypes + where recordDelete_timeMillis is null + order by orderNumber, committalType, committalTypeId` + ) + .all() as CommittalType[] + + let expectedOrderNumber = -1 + + for (const committalType of committalTypes) { + expectedOrderNumber += 1 + + if (committalType.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber( + 'CommittalTypes', + committalType.committalTypeId, + expectedOrderNumber, + database + ) + + committalType.orderNumber = expectedOrderNumber + } + } + + database.release() + + return committalTypes +} diff --git a/database/getContract.js b/database/getContract.js index 841c0053..f6b02241 100644 --- a/database/getContract.js +++ b/database/getContract.js @@ -1,4 +1,4 @@ -import { dateIntegerToString } from '@cityssm/utils-datetime'; +import { dateIntegerToString, timeIntegerToString } from '@cityssm/utils-datetime'; import getContractComments from './getContractComments.js'; import getContractFees from './getContractFees.js'; import getContractFields from './getContractFields.js'; @@ -9,6 +9,7 @@ import { acquireConnection } from './pool.js'; export default async function getContract(contractId, connectedDatabase) { const database = connectedDatabase ?? (await acquireConnection()); database.function('userFn_dateIntegerToString', dateIntegerToString); + database.function('userFn_timeIntegerToString', timeIntegerToString); const contract = database .prepare(`select o.contractId, o.contractTypeId, t.contractType, t.isPreneed, @@ -20,9 +21,13 @@ export default async function getContract(contractId, connectedDatabase) { o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode, o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship, o.funeralHomeId, o.funeralDirectorName, + o.funeralDate, userFn_dateIntegerToString(o.funeralDate) as funeralDateString, + o.funeralTime, userFn_timeIntegerToString(o.funeralTime) as funeralTimeString, + o.committalTypeId, c.committalType, o.recordUpdate_timeMillis from Contracts o left join ContractTypes t on o.contractTypeId = t.contractTypeId + left join CommittalTypes c on o.committalTypeId = c.committalTypeId left join BurialSites l on o.burialSiteId = l.burialSiteId left join Cemeteries m on l.cemeteryId = m.cemeteryId where o.recordDelete_timeMillis is null diff --git a/database/getContract.ts b/database/getContract.ts index 7cdc9e55..00e28b5a 100644 --- a/database/getContract.ts +++ b/database/getContract.ts @@ -1,4 +1,4 @@ -import { dateIntegerToString } from '@cityssm/utils-datetime' +import { dateIntegerToString, timeIntegerToString } from '@cityssm/utils-datetime' import type { PoolConnection } from 'better-sqlite-pool' import type { Contract } from '../types/recordTypes.js' @@ -18,6 +18,7 @@ export default async function getContract( const database = connectedDatabase ?? (await acquireConnection()) database.function('userFn_dateIntegerToString', dateIntegerToString) + database.function('userFn_timeIntegerToString', timeIntegerToString) const contract = database .prepare( @@ -31,9 +32,13 @@ export default async function getContract( o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode, o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship, o.funeralHomeId, o.funeralDirectorName, + o.funeralDate, userFn_dateIntegerToString(o.funeralDate) as funeralDateString, + o.funeralTime, userFn_timeIntegerToString(o.funeralTime) as funeralTimeString, + o.committalTypeId, c.committalType, o.recordUpdate_timeMillis from Contracts o left join ContractTypes t on o.contractTypeId = t.contractTypeId + left join CommittalTypes c on o.committalTypeId = c.committalTypeId left join BurialSites l on o.burialSiteId = l.burialSiteId left join Cemeteries m on l.cemeteryId = m.cemeteryId where o.recordDelete_timeMillis is null diff --git a/database/getContractInterments.js b/database/getContractInterments.js index b6813ccd..1f3c5f9c 100644 --- a/database/getContractInterments.js +++ b/database/getContractInterments.js @@ -5,21 +5,18 @@ export default async function getContractInterments(contractId, connectedDatabas database.function('userFn_dateIntegerToString', dateIntegerToString); const interments = database .prepare(`select o.contractId, o.intermentNumber, - o.isCremated, o.deceasedName, + o.deceasedAddress1, o.deceasedAddress2, o.deceasedCity, o.deceasedProvince, o.deceasedPostalCode, + o.birthDate, userFn_dateIntegerToString(o.birthDate) as birthDateString, o.birthPlace, o.deathDate, userFn_dateIntegerToString(o.deathDate) as deathDateString, o.deathPlace, - - o.intermentDate, userFn_dateIntegerToString(o.intermentDate) as intermentDateString, - - o.intermentContainerTypeId, t.intermentContainerType, - o.intermentCommittalTypeId, c.intermentCommittalType + + o.intermentContainerTypeId, t.intermentContainerType, t.isCremationType from ContractInterments o left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId - left join IntermentCommittalTypes c on o.intermentCommittalTypeId = c.intermentCommittalTypeId where o.recordDelete_timeMillis is null and o.contractId = ? diff --git a/database/getContractInterments.ts b/database/getContractInterments.ts index b3b5a825..aeecad88 100644 --- a/database/getContractInterments.ts +++ b/database/getContractInterments.ts @@ -18,21 +18,18 @@ export default async function getContractInterments( const interments = database .prepare( `select o.contractId, o.intermentNumber, - o.isCremated, o.deceasedName, + o.deceasedAddress1, o.deceasedAddress2, o.deceasedCity, o.deceasedProvince, o.deceasedPostalCode, + o.birthDate, userFn_dateIntegerToString(o.birthDate) as birthDateString, o.birthPlace, o.deathDate, userFn_dateIntegerToString(o.deathDate) as deathDateString, o.deathPlace, - - o.intermentDate, userFn_dateIntegerToString(o.intermentDate) as intermentDateString, - - o.intermentContainerTypeId, t.intermentContainerType, - o.intermentCommittalTypeId, c.intermentCommittalType + + o.intermentContainerTypeId, t.intermentContainerType, t.isCremationType from ContractInterments o left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId - left join IntermentCommittalTypes c on o.intermentCommittalTypeId = c.intermentCommittalTypeId where o.recordDelete_timeMillis is null and o.contractId = ? diff --git a/database/getContractTypes.js b/database/getContractTypes.js index b4ddaa3c..6f290c4b 100644 --- a/database/getContractTypes.js +++ b/database/getContractTypes.js @@ -8,7 +8,7 @@ export default async function getContractTypes() { .prepare(`select contractTypeId, contractType, isPreneed, orderNumber from ContractTypes where recordDelete_timeMillis is null - order by orderNumber, contractType`) + order by orderNumber, contractType, contractTypeId`) .all(); let expectedOrderNumber = -1; for (const contractType of contractTypes) { diff --git a/database/getContractTypes.ts b/database/getContractTypes.ts index ec020646..17b4f1f5 100644 --- a/database/getContractTypes.ts +++ b/database/getContractTypes.ts @@ -13,7 +13,7 @@ export default async function getContractTypes(): Promise { `select contractTypeId, contractType, isPreneed, orderNumber from ContractTypes where recordDelete_timeMillis is null - order by orderNumber, contractType` + order by orderNumber, contractType, contractTypeId` ) .all() as ContractType[] diff --git a/database/getContracts.js b/database/getContracts.js index 2b08ee77..71245b84 100644 --- a/database/getContracts.js +++ b/database/getContracts.js @@ -1,4 +1,4 @@ -import { dateIntegerToString, dateStringToInteger } from '@cityssm/utils-datetime'; +import { dateIntegerToString, dateStringToInteger, timeIntegerToString } from '@cityssm/utils-datetime'; import { getConfigProperty } from '../helpers/config.helpers.js'; import { getContractTypeById } from '../helpers/functions.cache.js'; import { getBurialSiteNameWhereClause, getOccupancyTimeWhereClause, getOccupantNameWhereClause } from '../helpers/functions.sqlFilters.js'; @@ -13,9 +13,9 @@ function buildWhereClause(filters) { sqlWhereClause += ' and o.burialSiteId = ?'; sqlParameters.push(filters.burialSiteId); } - const lotNameFilters = getBurialSiteNameWhereClause(filters.burialSiteName, filters.burialSiteNameSearchType ?? '', 'l'); - sqlWhereClause += lotNameFilters.sqlWhereClause; - sqlParameters.push(...lotNameFilters.sqlParameters); + const burialSiteNameFilters = getBurialSiteNameWhereClause(filters.burialSiteName, filters.burialSiteNameSearchType ?? '', 'l'); + sqlWhereClause += burialSiteNameFilters.sqlWhereClause; + sqlParameters.push(...burialSiteNameFilters.sqlParameters); const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, 'o'); if (occupantNameFilters.sqlParameters.length > 0) { sqlWhereClause += ` and o.contractId in ( @@ -80,6 +80,7 @@ async function addInclusions(contract, options, database) { export default async function getContracts(filters, options, connectedDatabase) { const database = connectedDatabase ?? (await acquireConnection()); database.function('userFn_dateIntegerToString', dateIntegerToString); + database.function('userFn_timeIntegerToString', timeIntegerToString); const { sqlWhereClause, sqlParameters } = buildWhereClause(filters); let count = typeof options.limit === 'string' ? Number.parseInt(options.limit, 10) @@ -105,9 +106,13 @@ export default async function getContracts(filters, options, connectedDatabase) o.purchaserName, o.purchaserAddress1, o.purchaserAddress2, o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode, o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship, - o.funeralHomeId, o.funeralDirectorName + o.funeralHomeId, o.funeralDirectorName, + o.funeralDate, userFn_dateIntegerToString(o.funeralDate) as funeralDateString, + o.funeralTime, userFn_timeIntegerToString(o.funeralTime) as funeralTimeString, + o.committalTypeId, c.committalType from Contracts o left join ContractTypes t on o.contractTypeId = t.contractTypeId + left join CommittalTypes c on o.committalTypeId = c.committalTypeId left join BurialSites l on o.burialSiteId = l.burialSiteId left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId left join Cemeteries m on l.cemeteryId = m.cemeteryId diff --git a/database/getContracts.ts b/database/getContracts.ts index 5107579a..5976085e 100644 --- a/database/getContracts.ts +++ b/database/getContracts.ts @@ -1,7 +1,8 @@ import { type DateString, dateIntegerToString, - dateStringToInteger + dateStringToInteger, + timeIntegerToString } from '@cityssm/utils-datetime' import type { PoolConnection } from 'better-sqlite-pool' @@ -55,13 +56,13 @@ function buildWhereClause(filters: GetContractsFilters): { sqlParameters.push(filters.burialSiteId) } - const lotNameFilters = getBurialSiteNameWhereClause( + const burialSiteNameFilters = getBurialSiteNameWhereClause( filters.burialSiteName, filters.burialSiteNameSearchType ?? '', 'l' ) - sqlWhereClause += lotNameFilters.sqlWhereClause - sqlParameters.push(...lotNameFilters.sqlParameters) + sqlWhereClause += burialSiteNameFilters.sqlWhereClause + sqlParameters.push(...burialSiteNameFilters.sqlParameters) const occupantNameFilters = getOccupantNameWhereClause( filters.occupantName, @@ -168,6 +169,7 @@ export default async function getContracts( const database = connectedDatabase ?? (await acquireConnection()) database.function('userFn_dateIntegerToString', dateIntegerToString) + database.function('userFn_timeIntegerToString', timeIntegerToString) const { sqlWhereClause, sqlParameters } = buildWhereClause(filters) @@ -205,9 +207,13 @@ export default async function getContracts( o.purchaserName, o.purchaserAddress1, o.purchaserAddress2, o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode, o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship, - o.funeralHomeId, o.funeralDirectorName + o.funeralHomeId, o.funeralDirectorName, + o.funeralDate, userFn_dateIntegerToString(o.funeralDate) as funeralDateString, + o.funeralTime, userFn_timeIntegerToString(o.funeralTime) as funeralTimeString, + o.committalTypeId, c.committalType from Contracts o left join ContractTypes t on o.contractTypeId = t.contractTypeId + left join CommittalTypes c on o.committalTypeId = c.committalTypeId left join BurialSites l on o.burialSiteId = l.burialSiteId left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId left join Cemeteries m on l.cemeteryId = m.cemeteryId diff --git a/database/getIntermentCommittalTypes.d.ts b/database/getIntermentCommittalTypes.d.ts deleted file mode 100644 index 1591ae96..00000000 --- a/database/getIntermentCommittalTypes.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { IntermentCommittalType } from '../types/recordTypes.js'; -export default function getIntermentCommittalTypes(): Promise; diff --git a/database/getIntermentCommittalTypes.js b/database/getIntermentCommittalTypes.js deleted file mode 100644 index cbe95e40..00000000 --- a/database/getIntermentCommittalTypes.js +++ /dev/null @@ -1,12 +0,0 @@ -import { acquireConnection } from './pool.js'; -export default async function getIntermentCommittalTypes() { - const database = await acquireConnection(); - const committalTypes = database - .prepare(`select intermentCommittalTypeId, intermentCommittalType, orderNumber - from IntermentCommittalTypes - where recordDelete_timeMillis is null - order by orderNumber, intermentCommittalType, intermentCommittalTypeId`) - .all(); - database.release(); - return committalTypes; -} diff --git a/database/getIntermentCommittalTypes.ts b/database/getIntermentCommittalTypes.ts deleted file mode 100644 index a9f1e5ad..00000000 --- a/database/getIntermentCommittalTypes.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { IntermentCommittalType } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' - -export default async function getIntermentCommittalTypes(): Promise< - IntermentCommittalType[] -> { - const database = await acquireConnection() - - const committalTypes = database - .prepare( - `select intermentCommittalTypeId, intermentCommittalType, orderNumber - from IntermentCommittalTypes - where recordDelete_timeMillis is null - order by orderNumber, intermentCommittalType, intermentCommittalTypeId` - ) - .all() as IntermentCommittalType[] - - database.release() - - return committalTypes -} diff --git a/database/getIntermentContainerTypes.js b/database/getIntermentContainerTypes.js index ddc474da..9d7e66bc 100644 --- a/database/getIntermentContainerTypes.js +++ b/database/getIntermentContainerTypes.js @@ -1,12 +1,21 @@ import { acquireConnection } from './pool.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; export default async function getIntermentContainerTypes() { const database = await acquireConnection(); const containerTypes = database - .prepare(`select intermentContainerTypeId, intermentContainerType, orderNumber + .prepare(`select intermentContainerTypeId, intermentContainerType, isCremationType, orderNumber from IntermentContainerTypes where recordDelete_timeMillis is null - order by orderNumber, intermentContainerType, intermentContainerTypeId`) + order by isCremationType, orderNumber, intermentContainerType, intermentContainerTypeId`) .all(); + let expectedOrderNumber = -1; + for (const containerType of containerTypes) { + expectedOrderNumber += 1; + if (containerType.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber('IntermentContainerTypes', containerType.intermentContainerTypeId, expectedOrderNumber, database); + containerType.orderNumber = expectedOrderNumber; + } + } database.release(); return containerTypes; } diff --git a/database/getIntermentContainerTypes.ts b/database/getIntermentContainerTypes.ts index 61d7cdcc..d0237419 100644 --- a/database/getIntermentContainerTypes.ts +++ b/database/getIntermentContainerTypes.ts @@ -1,6 +1,7 @@ import type { IntermentContainerType } from '../types/recordTypes.js' import { acquireConnection } from './pool.js' +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' export default async function getIntermentContainerTypes(): Promise< IntermentContainerType[] @@ -9,13 +10,30 @@ export default async function getIntermentContainerTypes(): Promise< const containerTypes = database .prepare( - `select intermentContainerTypeId, intermentContainerType, orderNumber + `select intermentContainerTypeId, intermentContainerType, isCremationType, orderNumber from IntermentContainerTypes where recordDelete_timeMillis is null - order by orderNumber, intermentContainerType, intermentContainerTypeId` + order by isCremationType, orderNumber, intermentContainerType, intermentContainerTypeId` ) .all() as IntermentContainerType[] + let expectedOrderNumber = -1 + + for (const containerType of containerTypes) { + expectedOrderNumber += 1 + + if (containerType.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber( + 'IntermentContainerTypes', + containerType.intermentContainerTypeId, + expectedOrderNumber, + database + ) + + containerType.orderNumber = expectedOrderNumber + } + } + database.release() return containerTypes diff --git a/database/getWorkOrders.d.ts b/database/getWorkOrders.d.ts index 17ead16b..dce60c27 100644 --- a/database/getWorkOrders.d.ts +++ b/database/getWorkOrders.d.ts @@ -5,7 +5,7 @@ export interface GetWorkOrdersFilters { workOrderOpenStatus?: '' | 'open' | 'closed'; workOrderOpenDateString?: string; occupantName?: string; - lotName?: string; + burialSiteName?: string; contractId?: number | string; } interface GetWorkOrdersOptions { diff --git a/database/getWorkOrders.js b/database/getWorkOrders.js index 0908fadd..7f8de6c9 100644 --- a/database/getWorkOrders.js +++ b/database/getWorkOrders.js @@ -36,7 +36,7 @@ function buildWhereClause(filters) { ))`; sqlParameters.push(...occupantNameFilters.sqlParameters); } - const burialSiteNameFilters = getBurialSiteNameWhereClause(filters.lotName, '', 'l'); + const burialSiteNameFilters = getBurialSiteNameWhereClause(filters.burialSiteName, '', 'l'); if (burialSiteNameFilters.sqlParameters.length > 0) { sqlWhereClause += ` and w.workOrderId in ( @@ -130,7 +130,7 @@ export async function getWorkOrders(filters, options, connectedDatabase) { where recordDelete_timeMillis is null group by workOrderId) m on w.workOrderId = m.workOrderId left join ( - select workOrderId, count(lotId) as workOrderLotCount + select workOrderId, count(burialSiteId) as workOrderLotCount from WorkOrderLots where recordDelete_timeMillis is null group by workOrderId) l on w.workOrderId = l.workOrderId diff --git a/database/getWorkOrders.ts b/database/getWorkOrders.ts index e2b4a3b4..fcafa68d 100644 --- a/database/getWorkOrders.ts +++ b/database/getWorkOrders.ts @@ -22,7 +22,7 @@ export interface GetWorkOrdersFilters { workOrderOpenStatus?: '' | 'open' | 'closed' workOrderOpenDateString?: string occupantName?: string - lotName?: string + burialSiteName?: string contractId?: number | string } @@ -77,7 +77,7 @@ function buildWhereClause(filters: GetWorkOrdersFilters): { sqlParameters.push(...occupantNameFilters.sqlParameters) } - const burialSiteNameFilters = getBurialSiteNameWhereClause(filters.lotName, '', 'l') + const burialSiteNameFilters = getBurialSiteNameWhereClause(filters.burialSiteName, '', 'l') if (burialSiteNameFilters.sqlParameters.length > 0) { sqlWhereClause += ` and w.workOrderId in ( @@ -213,7 +213,7 @@ export async function getWorkOrders( where recordDelete_timeMillis is null group by workOrderId) m on w.workOrderId = m.workOrderId left join ( - select workOrderId, count(lotId) as workOrderLotCount + select workOrderId, count(burialSiteId) as workOrderLotCount from WorkOrderLots where recordDelete_timeMillis is null group by workOrderId) l on w.workOrderId = l.workOrderId diff --git a/database/initializeDatabase.js b/database/initializeDatabase.js index d4ba3054..a0eeb8c1 100644 --- a/database/initializeDatabase.js +++ b/database/initializeDatabase.js @@ -1,11 +1,12 @@ // eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair -/* eslint-disable no-secrets/no-secrets */ +/* eslint-disable max-lines, no-secrets/no-secrets */ import sqlite from 'better-sqlite3'; import Debug from 'debug'; import { DEBUG_NAMESPACE } from '../debug.config.js'; import { sunriseDB as databasePath } from '../helpers/database.helpers.js'; import addContractType from './addContractType.js'; import addFeeCategory from './addFeeCategory.js'; +import addIntermentContainerType from './addIntermentContainerType.js'; import addRecord from './addRecord.js'; const debug = Debug(`${DEBUG_NAMESPACE}:database/initializeDatabase`); const recordColumns = `recordCreate_userName varchar(30) not null, @@ -162,6 +163,13 @@ const createStatements = [ foreign key (contractTypeId) references ContractTypes (contractTypeId))`, `create index if not exists idx_ContractTypePrints_orderNumber on ContractTypePrints (contractTypeId, orderNumber, printEJS)`, + `create table if not exists CommittalTypes ( + committalTypeId integer not null primary key autoincrement, + committalType varchar(100) not null, + orderNumber smallint not null default 0, + ${recordColumns})`, + `create index if not exists idx_CommittalType_orderNumber + on CommittalTypes (orderNumber, committalType)`, `create table if not exists Contracts ( contractId integer not null primary key autoincrement, contractTypeId integer not null, @@ -181,11 +189,15 @@ const createStatements = [ funeralHomeId integer, funeralDirectorName varchar(100), + funeralDate integer check (funeralDate > 0), + funeralTime integer check (funeralTime >= 0), + committalTypeId integer, ${recordColumns}, foreign key (burialSiteId) references BurialSites (burialSiteId), foreign key (contractTypeId) references ContractTypes (contractTypeId), - foreign key (funeralHomeId) references FuneralHomes (funeralHomeId))`, + foreign key (funeralHomeId) references FuneralHomes (funeralHomeId), + foreign key (committalTypeId) references CommittalTypes (committalTypeId))`, `create table if not exists ContractFields ( contractId integer not null, contractTypeFieldId integer not null, @@ -210,17 +222,11 @@ const createStatements = [ `create table if not exists IntermentContainerTypes ( intermentContainerTypeId integer not null primary key autoincrement, intermentContainerType varchar(100) not null, + isCremationType bit not null default 0, orderNumber smallint not null default 0, ${recordColumns})`, `create index if not exists idx_IntermentContainerTypes_orderNumber on IntermentContainerTypes (orderNumber, intermentContainerType)`, - `create table if not exists IntermentCommittalTypes ( - intermentCommittalTypeId integer not null primary key autoincrement, - intermentCommittalType varchar(100) not null, - orderNumber smallint not null default 0, - ${recordColumns})`, - `create index if not exists idx_IntermentCommittalType_orderNumber - on IntermentCommittalTypes (orderNumber, intermentCommittalType)`, `create table if not exists ContractInterments ( contractId integer not null, intermentNumber integer not null, @@ -240,17 +246,12 @@ const createStatements = [ deathDate integer, deathPlace varchar(100), - intermentDate integer check (intermentDate > 0), - intermentTime integer check (intermentTime >= 0), - intermentContainerTypeId integer, - intermentCommittalTypeId integer, ${recordColumns}, primary key (contractId, intermentNumber), foreign key (contractId) references Contracts (contractId), - foreign key (intermentContainerTypeId) references IntermentContainerTypes (intermentContainerTypeId), - foreign key (intermentCommittalTypeId) references IntermentCommittalTypes (intermentCommittalTypeId)) without rowid`, + foreign key (intermentContainerTypeId) references IntermentContainerTypes (intermentContainerTypeId)) without rowid`, /* * Fees and Transactions */ @@ -402,6 +403,7 @@ async function initializeData() { await addRecord('BurialSiteStatuses', 'Available', 1, initializingUser); await addRecord('BurialSiteStatuses', 'Reserved', 2, initializingUser); await addRecord('BurialSiteStatuses', 'Taken', 3, initializingUser); + // Contract Types await addContractType({ contractType: 'Preneed', isPreneed: '1', @@ -409,23 +411,40 @@ async function initializeData() { }, initializingUser); await addContractType({ contractType: 'Interment', - isPreneed: '0', orderNumber: 2 }, initializingUser); await addContractType({ contractType: 'Cremation', - isPreneed: '0', orderNumber: 3 }, initializingUser); - await addRecord('IntermentContainerTypes', 'No Shell', 1, initializingUser); - await addRecord('IntermentContainerTypes', 'Concrete Liner', 2, initializingUser); - await addRecord('IntermentContainerTypes', 'Unpainted Vault', 3, initializingUser); - await addRecord('IntermentContainerTypes', 'Concrete Vault', 4, initializingUser); - await addRecord('IntermentContainerTypes', 'Wooden Shell', 5, initializingUser); - await addRecord('IntermentContainerTypes', 'Steel Vault', 6, initializingUser); - await addRecord('IntermentCommittalTypes', 'Graveside', 1, initializingUser); - await addRecord('IntermentCommittalTypes', 'Chapel', 2, initializingUser); - await addRecord('IntermentCommittalTypes', 'Church', 3, initializingUser); + // Interment Container Types + await addIntermentContainerType({ + intermentContainerType: 'No Shell', + orderNumber: 1 + }, initializingUser); + await addIntermentContainerType({ + intermentContainerType: 'Concrete Liner', + orderNumber: 2 + }, initializingUser); + await addIntermentContainerType({ + intermentContainerType: 'Unpainted Vault', + orderNumber: 3 + }, initializingUser); + await addIntermentContainerType({ + intermentContainerType: 'Concrete Vault', + orderNumber: 4 + }, initializingUser); + await addIntermentContainerType({ intermentContainerType: 'Wooden Shell', orderNumber: 5 }, initializingUser); + await addIntermentContainerType({ intermentContainerType: 'Steel Vault', orderNumber: 6 }, initializingUser); + await addIntermentContainerType({ + intermentContainerType: 'Urn', + isCremationType: '1', + orderNumber: 7 + }, initializingUser); + // Committal Types + await addRecord('CommittalTypes', 'Graveside', 1, initializingUser); + await addRecord('CommittalTypes', 'Chapel', 2, initializingUser); + await addRecord('CommittalTypes', 'Church', 3, initializingUser); /* * Fee Categories */ diff --git a/database/initializeDatabase.ts b/database/initializeDatabase.ts index 3488ccfd..afa23ee8 100644 --- a/database/initializeDatabase.ts +++ b/database/initializeDatabase.ts @@ -1,5 +1,5 @@ // eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair -/* eslint-disable no-secrets/no-secrets */ +/* eslint-disable max-lines, no-secrets/no-secrets */ import sqlite from 'better-sqlite3' import Debug from 'debug' @@ -9,6 +9,7 @@ import { sunriseDB as databasePath } from '../helpers/database.helpers.js' import addContractType from './addContractType.js' import addFeeCategory from './addFeeCategory.js' +import addIntermentContainerType from './addIntermentContainerType.js' import addRecord from './addRecord.js' const debug = Debug(`${DEBUG_NAMESPACE}:database/initializeDatabase`) @@ -192,6 +193,15 @@ const createStatements = [ `create index if not exists idx_ContractTypePrints_orderNumber on ContractTypePrints (contractTypeId, orderNumber, printEJS)`, + `create table if not exists CommittalTypes ( + committalTypeId integer not null primary key autoincrement, + committalType varchar(100) not null, + orderNumber smallint not null default 0, + ${recordColumns})`, + + `create index if not exists idx_CommittalType_orderNumber + on CommittalTypes (orderNumber, committalType)`, + `create table if not exists Contracts ( contractId integer not null primary key autoincrement, contractTypeId integer not null, @@ -211,11 +221,15 @@ const createStatements = [ funeralHomeId integer, funeralDirectorName varchar(100), + funeralDate integer check (funeralDate > 0), + funeralTime integer check (funeralTime >= 0), + committalTypeId integer, ${recordColumns}, foreign key (burialSiteId) references BurialSites (burialSiteId), foreign key (contractTypeId) references ContractTypes (contractTypeId), - foreign key (funeralHomeId) references FuneralHomes (funeralHomeId))`, + foreign key (funeralHomeId) references FuneralHomes (funeralHomeId), + foreign key (committalTypeId) references CommittalTypes (committalTypeId))`, `create table if not exists ContractFields ( contractId integer not null, @@ -245,21 +259,13 @@ const createStatements = [ `create table if not exists IntermentContainerTypes ( intermentContainerTypeId integer not null primary key autoincrement, intermentContainerType varchar(100) not null, + isCremationType bit not null default 0, orderNumber smallint not null default 0, ${recordColumns})`, `create index if not exists idx_IntermentContainerTypes_orderNumber on IntermentContainerTypes (orderNumber, intermentContainerType)`, - `create table if not exists IntermentCommittalTypes ( - intermentCommittalTypeId integer not null primary key autoincrement, - intermentCommittalType varchar(100) not null, - orderNumber smallint not null default 0, - ${recordColumns})`, - - `create index if not exists idx_IntermentCommittalType_orderNumber - on IntermentCommittalTypes (orderNumber, intermentCommittalType)`, - `create table if not exists ContractInterments ( contractId integer not null, intermentNumber integer not null, @@ -279,17 +285,12 @@ const createStatements = [ deathDate integer, deathPlace varchar(100), - intermentDate integer check (intermentDate > 0), - intermentTime integer check (intermentTime >= 0), - intermentContainerTypeId integer, - intermentCommittalTypeId integer, ${recordColumns}, primary key (contractId, intermentNumber), foreign key (contractId) references Contracts (contractId), - foreign key (intermentContainerTypeId) references IntermentContainerTypes (intermentContainerTypeId), - foreign key (intermentCommittalTypeId) references IntermentCommittalTypes (intermentCommittalTypeId)) without rowid`, + foreign key (intermentContainerTypeId) references IntermentContainerTypes (intermentContainerTypeId)) without rowid`, /* * Fees and Transactions @@ -473,6 +474,8 @@ async function initializeData(): Promise { await addRecord('BurialSiteStatuses', 'Reserved', 2, initializingUser) await addRecord('BurialSiteStatuses', 'Taken', 3, initializingUser) + // Contract Types + await addContractType( { contractType: 'Preneed', @@ -485,7 +488,6 @@ async function initializeData(): Promise { await addContractType( { contractType: 'Interment', - isPreneed: '0', orderNumber: 2 }, initializingUser @@ -494,22 +496,69 @@ async function initializeData(): Promise { await addContractType( { contractType: 'Cremation', - isPreneed: '0', orderNumber: 3 }, initializingUser ) - await addRecord('IntermentContainerTypes', 'No Shell', 1, initializingUser) - await addRecord('IntermentContainerTypes', 'Concrete Liner', 2, initializingUser) - await addRecord('IntermentContainerTypes', 'Unpainted Vault', 3, initializingUser) - await addRecord('IntermentContainerTypes', 'Concrete Vault', 4, initializingUser) - await addRecord('IntermentContainerTypes', 'Wooden Shell', 5, initializingUser) - await addRecord('IntermentContainerTypes', 'Steel Vault', 6, initializingUser) + // Interment Container Types - await addRecord('IntermentCommittalTypes', 'Graveside', 1, initializingUser) - await addRecord('IntermentCommittalTypes', 'Chapel', 2, initializingUser) - await addRecord('IntermentCommittalTypes', 'Church', 3, initializingUser) + await addIntermentContainerType( + { + intermentContainerType: 'No Shell', + orderNumber: 1 + }, + initializingUser + ) + + await addIntermentContainerType( + { + intermentContainerType: 'Concrete Liner', + orderNumber: 2 + }, + initializingUser + ) + + await addIntermentContainerType( + { + intermentContainerType: 'Unpainted Vault', + orderNumber: 3 + }, + initializingUser + ) + + await addIntermentContainerType( + { + intermentContainerType: 'Concrete Vault', + orderNumber: 4 + }, + initializingUser + ) + + await addIntermentContainerType( + { intermentContainerType: 'Wooden Shell', orderNumber: 5 }, + initializingUser + ) + + await addIntermentContainerType( + { intermentContainerType: 'Steel Vault', orderNumber: 6 }, + initializingUser + ) + + await addIntermentContainerType( + { + intermentContainerType: 'Urn', + isCremationType: '1', + orderNumber: 7 + }, + initializingUser + ) + + // Committal Types + + await addRecord('CommittalTypes', 'Graveside', 1, initializingUser) + await addRecord('CommittalTypes', 'Chapel', 2, initializingUser) + await addRecord('CommittalTypes', 'Church', 3, initializingUser) /* * Fee Categories diff --git a/database/updateRecordOrderNumber.d.ts b/database/updateRecordOrderNumber.d.ts index 1ce0e85a..bf2cd125 100644 --- a/database/updateRecordOrderNumber.d.ts +++ b/database/updateRecordOrderNumber.d.ts @@ -1,4 +1,4 @@ import type { PoolConnection } from 'better-sqlite-pool'; -type RecordTable = 'FeeCategories' | 'Fees' | 'BurialSiteStatuses' | 'BurialSiteTypes' | 'BurialSiteTypeFields' | 'ContractTypes' | 'ContractTypeFields' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; +type RecordTable = 'FeeCategories' | 'Fees' | 'BurialSiteStatuses' | 'BurialSiteTypes' | 'BurialSiteTypeFields' | 'IntermentContainerTypes' | 'CommittalTypes' | 'ContractTypes' | 'ContractTypeFields' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; export declare function updateRecordOrderNumber(recordTable: RecordTable, recordId: number | string, orderNumber: number | string, connectedDatabase: PoolConnection): boolean; export {}; diff --git a/database/updateRecordOrderNumber.js b/database/updateRecordOrderNumber.js index d9a18018..1cca7340 100644 --- a/database/updateRecordOrderNumber.js +++ b/database/updateRecordOrderNumber.js @@ -4,6 +4,8 @@ recordIdColumns.set('Fees', 'feeId'); recordIdColumns.set('BurialSiteStatuses', 'burialSiteStatusId'); recordIdColumns.set('BurialSiteTypes', 'burialSiteTypeId'); recordIdColumns.set('BurialSiteTypeFields', 'burialSiteTypeFieldId'); +recordIdColumns.set('IntermentContainerTypes', 'intermentContainerTypeId'); +recordIdColumns.set('CommittalTypes', 'committalTypeId'); recordIdColumns.set('ContractTypes', 'contractTypeId'); recordIdColumns.set('ContractTypeFields', 'contractTypeFieldId'); recordIdColumns.set('WorkOrderMilestoneTypes', 'workOrderMilestoneTypeId'); diff --git a/database/updateRecordOrderNumber.ts b/database/updateRecordOrderNumber.ts index 2757e1dd..6b9d3993 100644 --- a/database/updateRecordOrderNumber.ts +++ b/database/updateRecordOrderNumber.ts @@ -6,6 +6,8 @@ type RecordTable = | 'BurialSiteStatuses' | 'BurialSiteTypes' | 'BurialSiteTypeFields' + | 'IntermentContainerTypes' + | 'CommittalTypes' | 'ContractTypes' | 'ContractTypeFields' | 'WorkOrderMilestoneTypes' @@ -17,6 +19,8 @@ recordIdColumns.set('Fees', 'feeId') recordIdColumns.set('BurialSiteStatuses', 'burialSiteStatusId') recordIdColumns.set('BurialSiteTypes', 'burialSiteTypeId') recordIdColumns.set('BurialSiteTypeFields', 'burialSiteTypeFieldId') +recordIdColumns.set('IntermentContainerTypes', 'intermentContainerTypeId') +recordIdColumns.set('CommittalTypes', 'committalTypeId') recordIdColumns.set('ContractTypes', 'contractTypeId') recordIdColumns.set('ContractTypeFields', 'contractTypeFieldId') recordIdColumns.set('WorkOrderMilestoneTypes', 'workOrderMilestoneTypeId') diff --git a/handlers/api-get/milestoneICS.js b/handlers/api-get/milestoneICS.js index c2c8661f..80419a6f 100644 --- a/handlers/api-get/milestoneICS.js +++ b/handlers/api-get/milestoneICS.js @@ -64,7 +64,7 @@ function buildEventDescriptionHTML_occupancies(request, milestone) { - ${occupancy.lotName ? escapeHTML(occupancy.lotName) : '(Not Set)'} + ${occupancy.burialSiteName ? escapeHTML(occupancy.burialSiteName) : '(Not Set)'} ${occupancy.contractStartDateString} diff --git a/handlers/api-get/milestoneICS.ts b/handlers/api-get/milestoneICS.ts index 8a6a52d3..6a118d4a 100644 --- a/handlers/api-get/milestoneICS.ts +++ b/handlers/api-get/milestoneICS.ts @@ -99,7 +99,7 @@ function buildEventDescriptionHTML_occupancies( - ${occupancy.lotName ? escapeHTML(occupancy.lotName) : '(Not Set)'} + ${occupancy.burialSiteName ? escapeHTML(occupancy.burialSiteName) : '(Not Set)'} ${occupancy.contractStartDateString} diff --git a/handlers/contracts-get/edit.js b/handlers/contracts-get/edit.js index a486e398..82b3e8d0 100644 --- a/handlers/contracts-get/edit.js +++ b/handlers/contracts-get/edit.js @@ -1,7 +1,7 @@ import getContract from '../../database/getContract.js'; import getFuneralHomes from '../../database/getFuneralHomes.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; -import { getContractTypePrintsById, getContractTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js'; +import { getCommittalTypes, getContractTypePrintsById, getContractTypes, getIntermentContainerTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const contract = await getContract(request.params.contractId); if (contract === undefined) { @@ -11,6 +11,8 @@ export default async function handler(request, response) { const contractTypePrints = await getContractTypePrintsById(contract.contractTypeId); const contractTypes = await getContractTypes(); const funeralHomes = await getFuneralHomes(); + const committalTypes = await getCommittalTypes(); + const intermentContainerTypes = await getIntermentContainerTypes(); const workOrderTypes = await getWorkOrderTypes(); response.render('contract-edit', { headTitle: 'Contract Update', @@ -18,6 +20,8 @@ export default async function handler(request, response) { contractTypePrints, contractTypes, funeralHomes, + committalTypes, + intermentContainerTypes, workOrderTypes, isCreate: false }); diff --git a/handlers/contracts-get/edit.ts b/handlers/contracts-get/edit.ts index 20422bd6..f317d3c0 100644 --- a/handlers/contracts-get/edit.ts +++ b/handlers/contracts-get/edit.ts @@ -4,8 +4,10 @@ import getContract from '../../database/getContract.js' import getFuneralHomes from '../../database/getFuneralHomes.js' import { getConfigProperty } from '../../helpers/config.helpers.js' import { + getCommittalTypes, getContractTypePrintsById, getContractTypes, + getIntermentContainerTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js' @@ -32,6 +34,8 @@ export default async function handler( const contractTypes = await getContractTypes() const funeralHomes = await getFuneralHomes() + const committalTypes = await getCommittalTypes() + const intermentContainerTypes = await getIntermentContainerTypes() const workOrderTypes = await getWorkOrderTypes() response.render('contract-edit', { @@ -41,6 +45,8 @@ export default async function handler( contractTypes, funeralHomes, + committalTypes, + intermentContainerTypes, workOrderTypes, isCreate: false diff --git a/handlers/contracts-get/new.js b/handlers/contracts-get/new.js index bee37d07..f3d758d0 100644 --- a/handlers/contracts-get/new.js +++ b/handlers/contracts-get/new.js @@ -2,7 +2,7 @@ import { dateToInteger, dateToString } from '@cityssm/utils-datetime'; import getBurialSite from '../../database/getBurialSite.js'; import getFuneralHomes from '../../database/getFuneralHomes.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; -import { getContractTypes } from '../../helpers/functions.cache.js'; +import { getCommittalTypes, getContractTypes, getIntermentContainerTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const startDate = new Date(); const contract = { @@ -23,11 +23,15 @@ export default async function handler(request, response) { } const contractTypes = await getContractTypes(); const funeralHomes = await getFuneralHomes(); + const committalTypes = await getCommittalTypes(); + const intermentContainerTypes = await getIntermentContainerTypes(); response.render('contract-edit', { headTitle: 'Create a New Contract', contract, contractTypes, funeralHomes, + committalTypes, + intermentContainerTypes, isCreate: true }); } diff --git a/handlers/contracts-get/new.ts b/handlers/contracts-get/new.ts index 4b816ff7..9d44beb9 100644 --- a/handlers/contracts-get/new.ts +++ b/handlers/contracts-get/new.ts @@ -4,7 +4,7 @@ import type { Request, Response } from 'express' import getBurialSite from '../../database/getBurialSite.js' import getFuneralHomes from '../../database/getFuneralHomes.js' import { getConfigProperty } from '../../helpers/config.helpers.js' -import { getContractTypes } from '../../helpers/functions.cache.js' +import { getCommittalTypes, getContractTypes, getIntermentContainerTypes } from '../../helpers/functions.cache.js' import type { Contract } from '../../types/recordTypes.js' export default async function handler( @@ -34,6 +34,8 @@ export default async function handler( const contractTypes = await getContractTypes() const funeralHomes = await getFuneralHomes() + const committalTypes = await getCommittalTypes() + const intermentContainerTypes = await getIntermentContainerTypes() response.render('contract-edit', { headTitle: 'Create a New Contract', @@ -41,6 +43,8 @@ export default async function handler( contractTypes, funeralHomes, + committalTypes, + intermentContainerTypes, isCreate: true }) diff --git a/handlers/workOrders-post/doUpdateBurialSiteStatus.d.ts b/handlers/workOrders-post/doUpdateBurialSiteStatus.d.ts index 87151a8c..ce9e06c2 100644 --- a/handlers/workOrders-post/doUpdateBurialSiteStatus.d.ts +++ b/handlers/workOrders-post/doUpdateBurialSiteStatus.d.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/workOrders-post/doUpdateBurialSiteStatus.js b/handlers/workOrders-post/doUpdateBurialSiteStatus.js index d2ddc193..b5db744c 100644 --- a/handlers/workOrders-post/doUpdateBurialSiteStatus.js +++ b/handlers/workOrders-post/doUpdateBurialSiteStatus.js @@ -1,7 +1,7 @@ import getBurialSites from '../../database/getBurialSites.js'; import { updateBurialSiteStatus } from '../../database/updateBurialSite.js'; export default async function handler(request, response) { - const success = await updateBurialSiteStatus(request.body.lotId, request.body.burialSiteStatusId, request.session.user); + const success = await updateBurialSiteStatus(request.body.burialSiteId, request.body.burialSiteStatusId, request.session.user); const results = await getBurialSites({ workOrderId: request.body.workOrderId }, { diff --git a/handlers/workOrders-post/doUpdateBurialSiteStatus.ts b/handlers/workOrders-post/doUpdateBurialSiteStatus.ts index 5e265272..af90fab5 100644 --- a/handlers/workOrders-post/doUpdateBurialSiteStatus.ts +++ b/handlers/workOrders-post/doUpdateBurialSiteStatus.ts @@ -7,12 +7,12 @@ export default async function handler( request: Request< unknown, unknown, - { lotId: string; burialSiteStatusId: string; workOrderId: string } + { burialSiteId: string; burialSiteStatusId: string; workOrderId: string } >, response: Response ): Promise { const success = await updateBurialSiteStatus( - request.body.lotId, + request.body.burialSiteId, request.body.burialSiteStatusId, request.session.user as User ) diff --git a/helpers/functions.cache.d.ts b/helpers/functions.cache.d.ts index 22d2ca88..3900b72e 100644 --- a/helpers/functions.cache.d.ts +++ b/helpers/functions.cache.d.ts @@ -1,4 +1,4 @@ -import type { BurialSiteStatus, BurialSiteType, ContractType, ContractTypeField, IntermentCommittalType, IntermentContainerType, WorkOrderMilestoneType, WorkOrderType } from '../types/recordTypes.js'; +import type { BurialSiteStatus, BurialSiteType, CommittalType, ContractType, ContractTypeField, IntermentContainerType, WorkOrderMilestoneType, WorkOrderType } from '../types/recordTypes.js'; export declare function getBurialSiteStatuses(): Promise; export declare function getBurialSiteStatusById(burialSiteStatusId: number): Promise; export declare function getBurialSiteStatusByBurialSiteStatus(burialSiteStatus: string): Promise; @@ -12,8 +12,8 @@ export declare function getContractTypeByContractType(contractTypeString: string export declare function getContractTypePrintsById(contractTypeId: number): Promise; export declare function getIntermentContainerTypes(): Promise; export declare function getIntermentContainerTypeById(intermentContainerTypeId: number): Promise; -export declare function getIntermentCommittalTypes(): Promise; -export declare function getIntermentCommittalTypeById(intermentCommittalTypeId: number): Promise; +export declare function getCommittalTypes(): Promise; +export declare function getCommittalTypeById(committalTypeId: number): Promise; export declare function getWorkOrderTypes(): Promise; export declare function getWorkOrderTypeById(workOrderTypeId: number): Promise; export declare function getWorkOrderMilestoneTypes(): Promise; @@ -21,6 +21,6 @@ export declare function getWorkOrderMilestoneTypeById(workOrderMilestoneTypeId: export declare function getWorkOrderMilestoneTypeByWorkOrderMilestoneType(workOrderMilestoneTypeString: string): Promise; export declare function preloadCaches(): Promise; export declare function clearCaches(): void; -type CacheTableNames = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'BurialSiteTypeFields' | 'ContractTypes' | 'ContractTypeFields' | 'ContractTypePrints' | 'IntermentContainerTypes' | 'IntermentCommittalTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes' | 'FeeCategories' | 'Fees'; +type CacheTableNames = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'BurialSiteTypeFields' | 'ContractTypes' | 'ContractTypeFields' | 'ContractTypePrints' | 'IntermentContainerTypes' | 'CommittalTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes' | 'FeeCategories' | 'Fees'; export declare function clearCacheByTableName(tableName: CacheTableNames, relayMessage?: boolean): void; export {}; diff --git a/helpers/functions.cache.js b/helpers/functions.cache.js index 21b81ad4..52def610 100644 --- a/helpers/functions.cache.js +++ b/helpers/functions.cache.js @@ -4,9 +4,9 @@ import cluster from 'node:cluster'; import Debug from 'debug'; import getBurialSiteStatusesFromDatabase from '../database/getBurialSiteStatuses.js'; import getBurialSiteTypesFromDatabase from '../database/getBurialSiteTypes.js'; +import getCommittalTypesFromDatabase from '../database/getCommittalTypes.js'; import getContractTypeFieldsFromDatabase from '../database/getContractTypeFields.js'; import getContractTypesFromDatabase from '../database/getContractTypes.js'; -import getIntermentCommittalTypesFromDatabase from '../database/getIntermentCommittalTypes.js'; import getIntermentContainerTypesFromDatabase from '../database/getIntermentContainerTypes.js'; import getWorkOrderMilestoneTypesFromDatabase from '../database/getWorkOrderMilestoneTypes.js'; import getWorkOrderTypesFromDatabase from '../database/getWorkOrderTypes.js'; @@ -116,21 +116,21 @@ function clearIntermentContainerTypesCache() { intermentContainerTypes = undefined; } /* - * Interment Committal Types + * Committal Types */ -let intermentCommittalTypes; -export async function getIntermentCommittalTypes() { - if (intermentCommittalTypes === undefined) { - intermentCommittalTypes = await getIntermentCommittalTypesFromDatabase(); +let committalTypes; +export async function getCommittalTypes() { + if (committalTypes === undefined) { + committalTypes = await getCommittalTypesFromDatabase(); } - return intermentCommittalTypes; + return committalTypes; } -export async function getIntermentCommittalTypeById(intermentCommittalTypeId) { - const cachedCommittalTypes = await getIntermentCommittalTypes(); - return cachedCommittalTypes.find((currentCommittalType) => currentCommittalType.intermentCommittalTypeId === intermentCommittalTypeId); +export async function getCommittalTypeById(committalTypeId) { + const cachedCommittalTypes = await getCommittalTypes(); + return cachedCommittalTypes.find((currentCommittalType) => currentCommittalType.committalTypeId === committalTypeId); } -function clearIntermentCommittalTypesCache() { - intermentCommittalTypes = undefined; +function clearCommittalTypesCache() { + committalTypes = undefined; } /* * Work Order Types @@ -175,6 +175,8 @@ export async function preloadCaches() { await getBurialSiteStatuses(); await getBurialSiteTypes(); await getContractTypes(); + await getCommittalTypes(); + await getIntermentContainerTypes(); await getWorkOrderTypes(); await getWorkOrderMilestoneTypes(); } @@ -182,6 +184,8 @@ export function clearCaches() { clearBurialSiteStatusesCache(); clearBurialSiteTypesCache(); clearContractTypesCache(); + clearCommittalTypesCache(); + clearIntermentContainerTypesCache(); clearWorkOrderTypesCache(); clearWorkOrderMilestoneTypesCache(); } @@ -209,8 +213,8 @@ export function clearCacheByTableName(tableName, relayMessage = true) { clearIntermentContainerTypesCache(); break; } - case 'IntermentCommittalTypes': { - clearIntermentCommittalTypesCache(); + case 'CommittalTypes': { + clearCommittalTypesCache(); break; } case 'WorkOrderMilestoneTypes': { diff --git a/helpers/functions.cache.ts b/helpers/functions.cache.ts index e9ac2571..f98950fb 100644 --- a/helpers/functions.cache.ts +++ b/helpers/functions.cache.ts @@ -7,9 +7,9 @@ import Debug from 'debug' import getBurialSiteStatusesFromDatabase from '../database/getBurialSiteStatuses.js' import getBurialSiteTypesFromDatabase from '../database/getBurialSiteTypes.js' +import getCommittalTypesFromDatabase from '../database/getCommittalTypes.js' import getContractTypeFieldsFromDatabase from '../database/getContractTypeFields.js' import getContractTypesFromDatabase from '../database/getContractTypes.js' -import getIntermentCommittalTypesFromDatabase from '../database/getIntermentCommittalTypes.js' import getIntermentContainerTypesFromDatabase from '../database/getIntermentContainerTypes.js' import getWorkOrderMilestoneTypesFromDatabase from '../database/getWorkOrderMilestoneTypes.js' import getWorkOrderTypesFromDatabase from '../database/getWorkOrderTypes.js' @@ -21,9 +21,9 @@ import type { import type { BurialSiteStatus, BurialSiteType, + CommittalType, ContractType, ContractTypeField, - IntermentCommittalType, IntermentContainerType, WorkOrderMilestoneType, WorkOrderType @@ -214,34 +214,34 @@ function clearIntermentContainerTypesCache(): void { } /* - * Interment Committal Types + * Committal Types */ -let intermentCommittalTypes: IntermentCommittalType[] | undefined +let committalTypes: CommittalType[] | undefined -export async function getIntermentCommittalTypes(): Promise< - IntermentCommittalType[] +export async function getCommittalTypes(): Promise< + CommittalType[] > { - if (intermentCommittalTypes === undefined) { - intermentCommittalTypes = await getIntermentCommittalTypesFromDatabase() + if (committalTypes === undefined) { + committalTypes = await getCommittalTypesFromDatabase() } - return intermentCommittalTypes + return committalTypes } -export async function getIntermentCommittalTypeById( - intermentCommittalTypeId: number -): Promise { - const cachedCommittalTypes = await getIntermentCommittalTypes() +export async function getCommittalTypeById( + committalTypeId: number +): Promise { + const cachedCommittalTypes = await getCommittalTypes() return cachedCommittalTypes.find( (currentCommittalType) => - currentCommittalType.intermentCommittalTypeId === intermentCommittalTypeId + currentCommittalType.committalTypeId === committalTypeId ) } -function clearIntermentCommittalTypesCache(): void { - intermentCommittalTypes = undefined +function clearCommittalTypesCache(): void { + committalTypes = undefined } /* @@ -321,6 +321,8 @@ export async function preloadCaches(): Promise { await getBurialSiteStatuses() await getBurialSiteTypes() await getContractTypes() + await getCommittalTypes() + await getIntermentContainerTypes() await getWorkOrderTypes() await getWorkOrderMilestoneTypes() } @@ -329,6 +331,8 @@ export function clearCaches(): void { clearBurialSiteStatusesCache() clearBurialSiteTypesCache() clearContractTypesCache() + clearCommittalTypesCache() + clearIntermentContainerTypesCache() clearWorkOrderTypesCache() clearWorkOrderMilestoneTypesCache() } @@ -345,7 +349,7 @@ type CacheTableNames = | 'ContractTypeFields' | 'ContractTypePrints' | 'IntermentContainerTypes' - | 'IntermentCommittalTypes' + | 'CommittalTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes' | 'FeeCategories' @@ -379,8 +383,8 @@ export function clearCacheByTableName( break } - case 'IntermentCommittalTypes': { - clearIntermentCommittalTypesCache() + case 'CommittalTypes': { + clearCommittalTypesCache() break } diff --git a/public/html/burialSite-editLotStatus.html b/public/html/burialSite-editLotStatus.html index fbc3f270..8692a16f 100644 --- a/public/html/burialSite-editLotStatus.html +++ b/public/html/burialSite-editLotStatus.html @@ -13,16 +13,16 @@