From 48262b2d92cb1673c6080924eb3da138ecb91064 Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Tue, 4 Mar 2025 15:45:10 -0500 Subject: [PATCH] refactoring contracts --- database/addContract.d.ts | 42 +- database/addContract.js | 42 +- database/addContract.ts | 126 +- database/addContractType.d.ts | 6 + database/addContractType.js | 16 + database/addContractType.ts | 41 + database/addRecord.d.ts | 2 +- database/addRecord.js | 3 +- database/addRecord.ts | 6 +- database/getContract.js | 21 +- database/getContract.ts | 35 +- database/getContractInterments.js | 18 +- database/getContractInterments.ts | 19 +- database/getContractTypes.js | 2 +- database/getContractTypes.ts | 2 +- database/getContracts.js | 30 +- database/getContracts.ts | 56 +- database/getIntermentCommittalTypes.d.ts | 2 + database/getIntermentCommittalTypes.js | 12 + database/getIntermentCommittalTypes.ts | 22 + database/getIntermentContainerTypes.d.ts | 2 + database/getIntermentContainerTypes.js | 12 + database/getIntermentContainerTypes.ts | 22 + database/initializeDatabase.js | 36 +- database/initializeDatabase.ts | 49 +- database/updateContract.d.ts | 13 +- database/updateContract.js | 13 +- database/updateContract.ts | 37 +- database/updateContractType.d.ts | 6 + database/updateContractType.js | 18 + database/updateContractType.ts | 42 + database/updateRecord.d.ts | 2 +- database/updateRecord.js | 11 +- database/updateRecord.ts | 12 +- handlers/admin-post/doAddContractType.d.ts | 6 +- handlers/admin-post/doAddContractType.js | 4 +- handlers/admin-post/doAddContractType.ts | 16 +- handlers/admin-post/doUpdateContractType.d.ts | 6 +- handlers/admin-post/doUpdateContractType.js | 4 +- handlers/admin-post/doUpdateContractType.ts | 16 +- handlers/contracts-get/edit.js | 12 +- handlers/contracts-get/edit.ts | 12 +- handlers/contracts-get/new.js | 18 +- handlers/contracts-get/new.ts | 22 +- helpers/functions.cache.d.ts | 8 +- helpers/functions.cache.js | 44 + helpers/functions.cache.ts | 78 + public/html/adminContractTypes-add.html | 44 +- public/html/adminContractTypes-edit.html | 52 +- public/html/contract-selectBurialSite.html | 172 +- public/javascripts/contract.edit.js | 1601 ++++++----- public/javascripts/contract.edit.ts | 2413 ++++++++--------- public/javascripts/contractTypes.admin.js | 51 +- public/javascripts/contractTypes.admin.ts | 57 +- temp/legacy.importFromCSV.js | 6 +- temp/legacy.importFromCSV.ts | 6 +- types/recordTypes.d.ts | 24 +- types/recordTypes.ts | 29 +- views/contract-edit.ejs | 471 +++- 59 files changed, 3313 insertions(+), 2637 deletions(-) create mode 100644 database/addContractType.d.ts create mode 100644 database/addContractType.js create mode 100644 database/addContractType.ts create mode 100644 database/getIntermentCommittalTypes.d.ts create mode 100644 database/getIntermentCommittalTypes.js create mode 100644 database/getIntermentCommittalTypes.ts create mode 100644 database/getIntermentContainerTypes.d.ts create mode 100644 database/getIntermentContainerTypes.js create mode 100644 database/getIntermentContainerTypes.ts create mode 100644 database/updateContractType.d.ts create mode 100644 database/updateContractType.js create mode 100644 database/updateContractType.ts diff --git a/database/addContract.d.ts b/database/addContract.d.ts index a277e070..5cd0cb29 100644 --- a/database/addContract.d.ts +++ b/database/addContract.d.ts @@ -1,21 +1,35 @@ +import { type DateString } from '@cityssm/utils-datetime'; import type { PoolConnection } from 'better-sqlite-pool'; export interface AddContractForm { contractTypeId: string | number; burialSiteId: string | number; - contractStartDateString: string; - contractEndDateString: string; + contractStartDateString: DateString | ''; + contractEndDateString: DateString | ''; contractTypeFieldIds?: string; - [fieldValue_contractTypeFieldId: string]: unknown; - lotOccupantTypeId?: string; - occupantName?: string; - occupantFamilyName?: string; - occupantAddress1?: string; - occupantAddress2?: string; - occupantCity?: string; - occupantProvince?: string; - occupantPostalCode?: string; - occupantPhoneNumber?: string; - occupantEmailAddress?: string; - occupantComment?: string; + [fieldValue_contractTypeFieldId: `fieldValue_${string}`]: unknown; + purchaserName?: string; + purchaserAddress1?: string; + purchaserAddress2?: string; + purchaserCity?: string; + purchaserProvince?: string; + purchaserPostalCode?: string; + purchaserPhoneNumber?: string; + purchaserEmail?: string; + purchaserRelationship?: string; + funeralHomeId?: string | number; + funeralDirectorName?: string; + deceasedName?: string; + deceasedAddress1?: string; + deceasedAddress2?: string; + deceasedCity?: string; + deceasedProvince?: string; + deceasedPostalCode?: string; + birthDateString?: DateString | ''; + 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 8b256964..2348e7a2 100644 --- a/database/addContract.js +++ b/database/addContract.js @@ -1,21 +1,29 @@ import { dateStringToInteger } from '@cityssm/utils-datetime'; import addOrUpdateContractField from './addOrUpdateContractField.js'; import { acquireConnection } from './pool.js'; +// eslint-disable-next-line complexity export default async function addContract(addForm, user, connectedDatabase) { const database = connectedDatabase ?? (await acquireConnection()); const rightNowMillis = Date.now(); const contractStartDate = dateStringToInteger(addForm.contractStartDateString); const result = database .prepare(`insert into Contracts ( - contractTypeId, lotId, + contractTypeId, burialSiteId, contractStartDate, contractEndDate, + purchaserName, purchaserAddress1, purchaserAddress2, + purchaserCity, purchaserProvince, purchaserPostalCode, + purchaserPhoneNumber, purchaserEmail, purchaserRelationship, + funeralHomeId, funeralDirectorName, 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), 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 ?? '', user.userName, rightNowMillis, user.userName, rightNowMillis); const contractId = result.lastInsertRowid; + /* + * Add contract fields + */ const contractTypeFieldIds = (addForm.contractTypeFieldIds ?? '').split(','); for (const contractTypeFieldId of contractTypeFieldIds) { const fieldValue = addForm[`fieldValue_${contractTypeFieldId}`]; @@ -27,6 +35,34 @@ export default async function addContract(addForm, user, connectedDatabase) { }, user, database); } } + /* + * Add deceased information + */ + if ((addForm.deceasedName ?? '') !== '') { + database + .prepare(`insert into ContractInterments ( + contractId, intermentNumber, + deceasedName, deceasedAddress1, deceasedAddress2, + deceasedCity, deceasedProvince, deceasedPostalCode, + birthDate, deathDate, + birthPlace, deathPlace, + intermentDate, + intermentContainerTypeId, intermentCommittalTypeId, + recordCreate_userName, recordCreate_timeMillis, + recordUpdate_userName, recordUpdate_timeMillis) + 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 === '' + ? undefined + : dateStringToInteger(addForm.intermentDateString), addForm.intermentContainerTypeId === '' + ? undefined + : addForm.intermentContainerTypeId, addForm.intermentCommittalTypeId === '' + ? undefined + : addForm.intermentCommittalTypeId, user.userName, rightNowMillis, user.userName, rightNowMillis); + } if (connectedDatabase === undefined) { database.release(); } diff --git a/database/addContract.ts b/database/addContract.ts index fb759e81..10928413 100644 --- a/database/addContract.ts +++ b/database/addContract.ts @@ -1,4 +1,7 @@ -import { type DateString, dateStringToInteger } from '@cityssm/utils-datetime' +import { + type DateString, + dateStringToInteger +} from '@cityssm/utils-datetime' import type { PoolConnection } from 'better-sqlite-pool' import addOrUpdateContractField from './addOrUpdateContractField.js' @@ -8,25 +11,42 @@ export interface AddContractForm { contractTypeId: string | number burialSiteId: string | number - contractStartDateString: string - contractEndDateString: string + contractStartDateString: DateString | '' + contractEndDateString: DateString | '' contractTypeFieldIds?: string - [fieldValue_contractTypeFieldId: string]: unknown + [fieldValue_contractTypeFieldId: `fieldValue_${string}`]: unknown - lotOccupantTypeId?: string - occupantName?: string - occupantFamilyName?: string - occupantAddress1?: string - occupantAddress2?: string - occupantCity?: string - occupantProvince?: string - occupantPostalCode?: string - occupantPhoneNumber?: string - occupantEmailAddress?: string - occupantComment?: string + purchaserName?: string + purchaserAddress1?: string + purchaserAddress2?: string + purchaserCity?: string + purchaserProvince?: string + purchaserPostalCode?: string + purchaserPhoneNumber?: string + purchaserEmail?: string + purchaserRelationship?: string + + funeralHomeId?: string | number + funeralDirectorName?: string + + deceasedName?: string + deceasedAddress1?: string + deceasedAddress2?: string + deceasedCity?: string + deceasedProvince?: string + deceasedPostalCode?: string + + birthDateString?: DateString | '' + birthPlace?: string + deathDateString?: DateString | '' + deathPlace?: string + intermentDateString?: DateString | '' + intermentContainerTypeId?: string | number + intermentCommittalTypeId?: string | number } +// eslint-disable-next-line complexity export default async function addContract( addForm: AddContractForm, user: User, @@ -43,11 +63,15 @@ export default async function addContract( const result = database .prepare( `insert into Contracts ( - contractTypeId, lotId, + contractTypeId, burialSiteId, contractStartDate, contractEndDate, + purchaserName, purchaserAddress1, purchaserAddress2, + purchaserCity, purchaserProvince, purchaserPostalCode, + purchaserPhoneNumber, purchaserEmail, purchaserRelationship, + funeralHomeId, funeralDirectorName, recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis) - values (?, ?, ?, ?, ?, ?, ?, ?)` + values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` ) .run( addForm.contractTypeId, @@ -56,6 +80,17 @@ export default async function addContract( addForm.contractEndDateString === '' ? undefined : dateStringToInteger(addForm.contractEndDateString as DateString), + 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, @@ -64,6 +99,10 @@ export default async function addContract( const contractId = result.lastInsertRowid as number + /* + * Add contract fields + */ + const contractTypeFieldIds = (addForm.contractTypeFieldIds ?? '').split(',') for (const contractTypeFieldId of contractTypeFieldIds) { @@ -84,6 +123,59 @@ export default async function addContract( } } + /* + * Add deceased information + */ + + if ((addForm.deceasedName ?? '') !== '') { + database + .prepare( + `insert into ContractInterments ( + contractId, intermentNumber, + deceasedName, deceasedAddress1, deceasedAddress2, + deceasedCity, deceasedProvince, deceasedPostalCode, + birthDate, deathDate, + birthPlace, deathPlace, + intermentDate, + intermentContainerTypeId, intermentCommittalTypeId, + recordCreate_userName, recordCreate_timeMillis, + recordUpdate_userName, recordUpdate_timeMillis) + values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` + ) + + .run( + contractId, + 1, + addForm.deceasedName ?? '', + addForm.deceasedAddress1 ?? '', + addForm.deceasedAddress2 ?? '', + addForm.deceasedCity ?? '', + addForm.deceasedProvince ?? '', + addForm.deceasedPostalCode ?? '', + addForm.birthDateString === '' + ? undefined + : dateStringToInteger(addForm.birthDateString as DateString), + addForm.deathDateString === '' + ? undefined + : 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, + rightNowMillis + ) + } + if (connectedDatabase === undefined) { database.release() } diff --git a/database/addContractType.d.ts b/database/addContractType.d.ts new file mode 100644 index 00000000..17f5ae3a --- /dev/null +++ b/database/addContractType.d.ts @@ -0,0 +1,6 @@ +export interface AddForm { + contractType: string; + isPreneed?: string; + orderNumber?: number; +} +export default function addContractType(addForm: AddForm, user: User): Promise; diff --git a/database/addContractType.js b/database/addContractType.js new file mode 100644 index 00000000..fd9f9fc8 --- /dev/null +++ b/database/addContractType.js @@ -0,0 +1,16 @@ +import { clearCacheByTableName } from '../helpers/functions.cache.js'; +import { acquireConnection } from './pool.js'; +export default async function addContractType(addForm, user) { + const database = await acquireConnection(); + const rightNowMillis = Date.now(); + const result = database + .prepare(`insert into ContractTypes ( + contractType, isPreneed, orderNumber, + recordCreate_userName, recordCreate_timeMillis, + recordUpdate_userName, recordUpdate_timeMillis) + values (?, ?, ?, ?, ?, ?, ?)`) + .run(addForm.contractType, addForm.isPreneed === undefined ? 0 : 1, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis); + database.release(); + clearCacheByTableName('ContractTypes'); + return result.lastInsertRowid; +} diff --git a/database/addContractType.ts b/database/addContractType.ts new file mode 100644 index 00000000..80ddda25 --- /dev/null +++ b/database/addContractType.ts @@ -0,0 +1,41 @@ +import { clearCacheByTableName } from '../helpers/functions.cache.js' +import { acquireConnection } from './pool.js' + +export interface AddForm { + contractType: string + isPreneed?: string + orderNumber?: number +} + +export default async function addContractType( + addForm: AddForm, + user: User +): Promise { + const database = await acquireConnection() + + const rightNowMillis = Date.now() + + const result = database + .prepare( + `insert into ContractTypes ( + contractType, isPreneed, orderNumber, + recordCreate_userName, recordCreate_timeMillis, + recordUpdate_userName, recordUpdate_timeMillis) + values (?, ?, ?, ?, ?, ?, ?)` + ) + .run( + addForm.contractType, + addForm.isPreneed === undefined ? 0 : 1, + addForm.orderNumber ?? -1, + user.userName, + rightNowMillis, + user.userName, + rightNowMillis + ) + + database.release() + + clearCacheByTableName('ContractTypes') + + return result.lastInsertRowid as number +} diff --git a/database/addRecord.d.ts b/database/addRecord.d.ts index d1527b6e..f0c95c15 100644 --- a/database/addRecord.d.ts +++ b/database/addRecord.d.ts @@ -1,3 +1,3 @@ -type RecordTable = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'ContractTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; +type RecordTable = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'IntermentContainerTypes' | 'IntermentCommittalTypes' | '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 97387734..8da2958d 100644 --- a/database/addRecord.js +++ b/database/addRecord.js @@ -3,7 +3,8 @@ import { acquireConnection } from './pool.js'; const recordNameColumns = new Map(); recordNameColumns.set('BurialSiteStatuses', 'burialSiteStatus'); recordNameColumns.set('BurialSiteTypes', 'burialSiteType'); -recordNameColumns.set('ContractTypes', 'contractType'); +recordNameColumns.set('IntermentContainerTypes', 'intermentContainerType'); +recordNameColumns.set('IntermentCommittalTypes', 'intermentCommittalType'); 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 ff050ed5..756be3bc 100644 --- a/database/addRecord.ts +++ b/database/addRecord.ts @@ -5,14 +5,16 @@ import { acquireConnection } from './pool.js' type RecordTable = | 'BurialSiteStatuses' | 'BurialSiteTypes' - | 'ContractTypes' + | 'IntermentContainerTypes' + | 'IntermentCommittalTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes' const recordNameColumns = new Map() recordNameColumns.set('BurialSiteStatuses', 'burialSiteStatus') recordNameColumns.set('BurialSiteTypes', 'burialSiteType') -recordNameColumns.set('ContractTypes', 'contractType') +recordNameColumns.set('IntermentContainerTypes', 'intermentContainerType') +recordNameColumns.set('IntermentCommittalTypes', 'intermentCommittalType') recordNameColumns.set('WorkOrderMilestoneTypes', 'workOrderMilestoneType') recordNameColumns.set('WorkOrderTypes', 'workOrderType') diff --git a/database/getContract.js b/database/getContract.js index db182f8c..841c0053 100644 --- a/database/getContract.js +++ b/database/getContract.js @@ -2,7 +2,7 @@ import { dateIntegerToString } from '@cityssm/utils-datetime'; import getContractComments from './getContractComments.js'; import getContractFees from './getContractFees.js'; import getContractFields from './getContractFields.js'; -// import getContractOccupants from './getContractOccupants.js' +import getContractInterments from './getContractInterments.js'; import getContractTransactions from './getContractTransactions.js'; import { getWorkOrders } from './getWorkOrders.js'; import { acquireConnection } from './pool.js'; @@ -11,29 +11,26 @@ export default async function getContract(contractId, connectedDatabase) { database.function('userFn_dateIntegerToString', dateIntegerToString); const contract = database .prepare(`select o.contractId, - o.contractTypeId, t.contractType, - o.burialSiteId, - l.burialSiteName, - l.burialSiteTypeId, + o.contractTypeId, t.contractType, t.isPreneed, + o.burialSiteId, l.burialSiteName, l.burialSiteTypeId, l.cemeteryId, m.cemeteryName, o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString, o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString, + o.purchaserName, o.purchaserAddress1, o.purchaserAddress2, + o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode, + o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship, + o.funeralHomeId, o.funeralDirectorName, o.recordUpdate_timeMillis from Contracts o left join ContractTypes t on o.contractTypeId = t.contractTypeId left join BurialSites l on o.burialSiteId = l.burialSiteId - left join Maps m on l.cemeteryId = m.cemeteryId + left join Cemeteries m on l.cemeteryId = m.cemeteryId where o.recordDelete_timeMillis is null and o.contractId = ?`) .get(contractId); if (contract !== undefined) { contract.contractFields = await getContractFields(contractId, database); - /* - contract.contractInterments = await getContractOccupants( - contractId, - database - ) - */ + contract.contractInterments = await getContractInterments(contractId, database); contract.contractComments = await getContractComments(contractId, database); contract.contractFees = await getContractFees(contractId, database); contract.contractTransactions = await getContractTransactions(contractId, { includeIntegrations: true }, database); diff --git a/database/getContract.ts b/database/getContract.ts index 0fbd1172..7cdc9e55 100644 --- a/database/getContract.ts +++ b/database/getContract.ts @@ -6,7 +6,7 @@ import type { Contract } from '../types/recordTypes.js' import getContractComments from './getContractComments.js' import getContractFees from './getContractFees.js' import getContractFields from './getContractFields.js' -// import getContractOccupants from './getContractOccupants.js' +import getContractInterments from './getContractInterments.js' import getContractTransactions from './getContractTransactions.js' import { getWorkOrders } from './getWorkOrders.js' import { acquireConnection } from './pool.js' @@ -22,42 +22,35 @@ export default async function getContract( const contract = database .prepare( `select o.contractId, - o.contractTypeId, t.contractType, - o.burialSiteId, - l.burialSiteName, - l.burialSiteTypeId, + o.contractTypeId, t.contractType, t.isPreneed, + o.burialSiteId, l.burialSiteName, l.burialSiteTypeId, l.cemeteryId, m.cemeteryName, o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString, o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString, + o.purchaserName, o.purchaserAddress1, o.purchaserAddress2, + o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode, + o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship, + o.funeralHomeId, o.funeralDirectorName, o.recordUpdate_timeMillis from Contracts o left join ContractTypes t on o.contractTypeId = t.contractTypeId left join BurialSites l on o.burialSiteId = l.burialSiteId - left join Maps m on l.cemeteryId = m.cemeteryId + left join Cemeteries m on l.cemeteryId = m.cemeteryId where o.recordDelete_timeMillis is null and o.contractId = ?` ) .get(contractId) as Contract | undefined if (contract !== undefined) { - contract.contractFields = await getContractFields( - contractId, - database - ) - /* - contract.contractInterments = await getContractOccupants( - contractId, - database - ) - */ - contract.contractComments = await getContractComments( - contractId, - database - ) - contract.contractFees = await getContractFees( + contract.contractFields = await getContractFields(contractId, database) + + contract.contractInterments = await getContractInterments( contractId, database ) + + contract.contractComments = await getContractComments(contractId, database) + contract.contractFees = await getContractFees(contractId, database) contract.contractTransactions = await getContractTransactions( contractId, { includeIntegrations: true }, diff --git a/database/getContractInterments.js b/database/getContractInterments.js index 3de3d89e..b6813ccd 100644 --- a/database/getContractInterments.js +++ b/database/getContractInterments.js @@ -1,23 +1,21 @@ -import { dateIntegerToString, timeIntegerToString } from '@cityssm/utils-datetime'; +import { dateIntegerToString } from '@cityssm/utils-datetime'; import { acquireConnection } from './pool.js'; export default async function getContractInterments(contractId, connectedDatabase) { const database = connectedDatabase ?? (await acquireConnection()); database.function('userFn_dateIntegerToString', dateIntegerToString); - database.function('userFn_timeIntegerToString', timeIntegerToString); const interments = database .prepare(`select o.contractId, o.intermentNumber, o.isCremated, o.deceasedName, - birthDate, userFn_dateIntegerToString(birthDate) as birthDateString, - birthPlace, - deathDate, userFn_dateIntegerToString(deathDate) as deathDateString, - deathPlace, + o.birthDate, userFn_dateIntegerToString(o.birthDate) as birthDateString, + o.birthPlace, + o.deathDate, userFn_dateIntegerToString(o.deathDate) as deathDateString, + o.deathPlace, - intermentDate, userFn_dateIntegerToString(intermentDate) as intermentDateString, - intermentTime, userFn_timeIntegerToString(intermentTime) as intermentTimeString, + o.intermentDate, userFn_dateIntegerToString(o.intermentDate) as intermentDateString, - intermentContainerTypeId, t.intermentContainerType, - intermentCommittalTypeId, c.intermentCommittalType + o.intermentContainerTypeId, t.intermentContainerType, + o.intermentCommittalTypeId, c.intermentCommittalType from ContractInterments o left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId diff --git a/database/getContractInterments.ts b/database/getContractInterments.ts index 233e8ca4..b3b5a825 100644 --- a/database/getContractInterments.ts +++ b/database/getContractInterments.ts @@ -1,6 +1,5 @@ import { - dateIntegerToString, - timeIntegerToString + dateIntegerToString } from '@cityssm/utils-datetime' import type { PoolConnection } from 'better-sqlite-pool' @@ -15,23 +14,21 @@ export default async function getContractInterments( const database = connectedDatabase ?? (await acquireConnection()) database.function('userFn_dateIntegerToString', dateIntegerToString) - database.function('userFn_timeIntegerToString', timeIntegerToString) const interments = database .prepare( `select o.contractId, o.intermentNumber, o.isCremated, o.deceasedName, - birthDate, userFn_dateIntegerToString(birthDate) as birthDateString, - birthPlace, - deathDate, userFn_dateIntegerToString(deathDate) as deathDateString, - deathPlace, + o.birthDate, userFn_dateIntegerToString(o.birthDate) as birthDateString, + o.birthPlace, + o.deathDate, userFn_dateIntegerToString(o.deathDate) as deathDateString, + o.deathPlace, - intermentDate, userFn_dateIntegerToString(intermentDate) as intermentDateString, - intermentTime, userFn_timeIntegerToString(intermentTime) as intermentTimeString, + o.intermentDate, userFn_dateIntegerToString(o.intermentDate) as intermentDateString, - intermentContainerTypeId, t.intermentContainerType, - intermentCommittalTypeId, c.intermentCommittalType + o.intermentContainerTypeId, t.intermentContainerType, + o.intermentCommittalTypeId, c.intermentCommittalType from ContractInterments o left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId diff --git a/database/getContractTypes.js b/database/getContractTypes.js index e45d9875..b4ddaa3c 100644 --- a/database/getContractTypes.js +++ b/database/getContractTypes.js @@ -5,7 +5,7 @@ import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; export default async function getContractTypes() { const database = await acquireConnection(); const contractTypes = database - .prepare(`select contractTypeId, contractType, orderNumber + .prepare(`select contractTypeId, contractType, isPreneed, orderNumber from ContractTypes where recordDelete_timeMillis is null order by orderNumber, contractType`) diff --git a/database/getContractTypes.ts b/database/getContractTypes.ts index f7d99214..ec020646 100644 --- a/database/getContractTypes.ts +++ b/database/getContractTypes.ts @@ -10,7 +10,7 @@ export default async function getContractTypes(): Promise { const contractTypes = database .prepare( - `select contractTypeId, contractType, orderNumber + `select contractTypeId, contractType, isPreneed, orderNumber from ContractTypes where recordDelete_timeMillis is null order by orderNumber, contractType` diff --git a/database/getContracts.js b/database/getContracts.js index def913dd..2b08ee77 100644 --- a/database/getContracts.js +++ b/database/getContracts.js @@ -3,7 +3,7 @@ import { getConfigProperty } from '../helpers/config.helpers.js'; import { getContractTypeById } from '../helpers/functions.cache.js'; import { getBurialSiteNameWhereClause, getOccupancyTimeWhereClause, getOccupantNameWhereClause } from '../helpers/functions.sqlFilters.js'; import getContractFees from './getContractFees.js'; -// import getContractOccupants from './getContractOccupants.js' +import getContractInterments from './getContractInterments.js'; import getContractTransactions from './getContractTransactions.js'; import { acquireConnection } from './pool.js'; function buildWhereClause(filters) { @@ -70,18 +70,11 @@ async function addInclusions(contract, options, database) { contract.contractFees = await getContractFees(contract.contractId, database); } if (options.includeTransactions) { - contract.contractTransactions = - await getContractTransactions(contract.contractId, { includeIntegrations: false }, database); + contract.contractTransactions = await getContractTransactions(contract.contractId, { includeIntegrations: false }, database); } - /* if (options.includeInterments) { - contract.contractInterments = - await getContractOccupants( - contract.contractId, - database - ) + contract.contractInterments = await getContractInterments(contract.contractId, database); } - */ return contract; } export default async function getContracts(filters, options, connectedDatabase) { @@ -95,21 +88,24 @@ export default async function getContracts(filters, options, connectedDatabase) if (isLimited) { count = database .prepare(`select count(*) as recordCount - from Contracts o - left join BurialSites l on o.burialSiteId = l.burialSiteId - ${sqlWhereClause}`) + from Contracts o + left join BurialSites l on o.burialSiteId = l.burialSiteId + ${sqlWhereClause}`) .get(sqlParameters).recordCount; } let contracts = []; if (count !== 0) { contracts = database .prepare(`select o.contractId, - o.contractTypeId, t.contractType, - o.burialSiteId, lt.burialSiteType, - l.burialSiteName, + o.contractTypeId, t.contractType, t.isPreneed, + o.burialSiteId, lt.burialSiteType, l.burialSiteName, l.cemeteryId, m.cemeteryName, o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString, - o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString + o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString, + o.purchaserName, o.purchaserAddress1, o.purchaserAddress2, + o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode, + o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship, + o.funeralHomeId, o.funeralDirectorName from Contracts o left join ContractTypes t on o.contractTypeId = t.contractTypeId left join BurialSites l on o.burialSiteId = l.burialSiteId diff --git a/database/getContracts.ts b/database/getContracts.ts index 5e8b3a23..5107579a 100644 --- a/database/getContracts.ts +++ b/database/getContracts.ts @@ -15,7 +15,7 @@ import { import type { Contract } from '../types/recordTypes.js' import getContractFees from './getContractFees.js' -// import getContractOccupants from './getContractOccupants.js' +import getContractInterments from './getContractInterments.js' import getContractTransactions from './getContractTransactions.js' import { acquireConnection } from './pool.js' @@ -139,30 +139,23 @@ async function addInclusions( database: PoolConnection ): Promise { if (options.includeFees) { - contract.contractFees = await getContractFees( + contract.contractFees = await getContractFees(contract.contractId, database) + } + + if (options.includeTransactions) { + contract.contractTransactions = await getContractTransactions( contract.contractId, + { includeIntegrations: false }, database ) } - if (options.includeTransactions) { - contract.contractTransactions = - await getContractTransactions( - contract.contractId, - { includeIntegrations: false }, - database - ) - } - - /* if (options.includeInterments) { - contract.contractInterments = - await getContractOccupants( - contract.contractId, - database - ) + contract.contractInterments = await getContractInterments( + contract.contractId, + database + ) } - */ return contract } @@ -190,9 +183,9 @@ export default async function getContracts( database .prepare( `select count(*) as recordCount - from Contracts o - left join BurialSites l on o.burialSiteId = l.burialSiteId - ${sqlWhereClause}` + from Contracts o + left join BurialSites l on o.burialSiteId = l.burialSiteId + ${sqlWhereClause}` ) .get(sqlParameters) as { recordCount: number } ).recordCount @@ -204,12 +197,15 @@ export default async function getContracts( contracts = database .prepare( `select o.contractId, - o.contractTypeId, t.contractType, - o.burialSiteId, lt.burialSiteType, - l.burialSiteName, + o.contractTypeId, t.contractType, t.isPreneed, + o.burialSiteId, lt.burialSiteType, l.burialSiteName, l.cemeteryId, m.cemeteryName, o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString, - o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString + o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString, + o.purchaserName, o.purchaserAddress1, o.purchaserAddress2, + o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode, + o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship, + o.funeralHomeId, o.funeralDirectorName from Contracts o left join ContractTypes t on o.contractTypeId = t.contractTypeId left join BurialSites l on o.burialSiteId = l.burialSiteId @@ -234,14 +230,12 @@ export default async function getContracts( } for (const contract of contracts) { - const contractType = await getContractTypeById( - contract.contractTypeId - ) + const contractType = await getContractTypeById(contract.contractTypeId) if (contractType !== undefined) { - contract.printEJS = ( - contractType.contractTypePrints ?? [] - ).includes('*') + contract.printEJS = (contractType.contractTypePrints ?? []).includes( + '*' + ) ? getConfigProperty('settings.contracts.prints')[0] : (contractType.contractTypePrints ?? [])[0] } diff --git a/database/getIntermentCommittalTypes.d.ts b/database/getIntermentCommittalTypes.d.ts new file mode 100644 index 00000000..1591ae96 --- /dev/null +++ b/database/getIntermentCommittalTypes.d.ts @@ -0,0 +1,2 @@ +import type { IntermentCommittalType } from '../types/recordTypes.js'; +export default function getIntermentCommittalTypes(): Promise; diff --git a/database/getIntermentCommittalTypes.js b/database/getIntermentCommittalTypes.js new file mode 100644 index 00000000..cbe95e40 --- /dev/null +++ b/database/getIntermentCommittalTypes.js @@ -0,0 +1,12 @@ +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 new file mode 100644 index 00000000..a9f1e5ad --- /dev/null +++ b/database/getIntermentCommittalTypes.ts @@ -0,0 +1,22 @@ +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.d.ts b/database/getIntermentContainerTypes.d.ts new file mode 100644 index 00000000..d3be3712 --- /dev/null +++ b/database/getIntermentContainerTypes.d.ts @@ -0,0 +1,2 @@ +import type { IntermentContainerType } from '../types/recordTypes.js'; +export default function getIntermentContainerTypes(): Promise; diff --git a/database/getIntermentContainerTypes.js b/database/getIntermentContainerTypes.js new file mode 100644 index 00000000..ddc474da --- /dev/null +++ b/database/getIntermentContainerTypes.js @@ -0,0 +1,12 @@ +import { acquireConnection } from './pool.js'; +export default async function getIntermentContainerTypes() { + const database = await acquireConnection(); + const containerTypes = database + .prepare(`select intermentContainerTypeId, intermentContainerType, orderNumber + from IntermentContainerTypes + where recordDelete_timeMillis is null + order by orderNumber, intermentContainerType, intermentContainerTypeId`) + .all(); + database.release(); + return containerTypes; +} diff --git a/database/getIntermentContainerTypes.ts b/database/getIntermentContainerTypes.ts new file mode 100644 index 00000000..61d7cdcc --- /dev/null +++ b/database/getIntermentContainerTypes.ts @@ -0,0 +1,22 @@ +import type { IntermentContainerType } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' + +export default async function getIntermentContainerTypes(): Promise< + IntermentContainerType[] +> { + const database = await acquireConnection() + + const containerTypes = database + .prepare( + `select intermentContainerTypeId, intermentContainerType, orderNumber + from IntermentContainerTypes + where recordDelete_timeMillis is null + order by orderNumber, intermentContainerType, intermentContainerTypeId` + ) + .all() as IntermentContainerType[] + + database.release() + + return containerTypes +} diff --git a/database/initializeDatabase.js b/database/initializeDatabase.js index b17c78bf..d4ba3054 100644 --- a/database/initializeDatabase.js +++ b/database/initializeDatabase.js @@ -4,6 +4,7 @@ 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 addRecord from './addRecord.js'; const debug = Debug(`${DEBUG_NAMESPACE}:database/initializeDatabase`); @@ -132,6 +133,7 @@ const createStatements = [ `create table if not exists ContractTypes ( contractTypeId integer not null primary key autoincrement, contractType varchar(100) not null, + isPreneed bit not null default 0, orderNumber smallint not null default 0, ${recordColumns})`, `create index if not exists idx_ContractTypes_orderNumber @@ -175,6 +177,7 @@ const createStatements = [ purchaserPostalCode varchar(7), purchaserPhoneNumber varchar(30), purchaserEmail varchar(100), + purchaserRelationship varchar(50), funeralHomeId integer, funeralDirectorName varchar(100), @@ -225,6 +228,12 @@ const createStatements = [ deceasedName varchar(50) not null, isCremated bit not null default 0, + deceasedAddress1 varchar(50), + deceasedAddress2 varchar(50), + deceasedCity varchar(20), + deceasedProvince varchar(2), + deceasedPostalCode varchar(7), + birthDate integer, birthPlace varchar(100), @@ -393,9 +402,30 @@ async function initializeData() { await addRecord('BurialSiteStatuses', 'Available', 1, initializingUser); await addRecord('BurialSiteStatuses', 'Reserved', 2, initializingUser); await addRecord('BurialSiteStatuses', 'Taken', 3, initializingUser); - await addRecord('ContractTypes', 'Preneed', 1, initializingUser); - await addRecord('ContractTypes', 'Interment', 2, initializingUser); - await addRecord('ContractTypes', 'Cremation', 3, initializingUser); + await addContractType({ + contractType: 'Preneed', + isPreneed: '1', + orderNumber: 1 + }, 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); /* * Fee Categories */ diff --git a/database/initializeDatabase.ts b/database/initializeDatabase.ts index eb655cd9..3488ccfd 100644 --- a/database/initializeDatabase.ts +++ b/database/initializeDatabase.ts @@ -7,6 +7,7 @@ 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 addRecord from './addRecord.js' @@ -156,6 +157,7 @@ const createStatements = [ `create table if not exists ContractTypes ( contractTypeId integer not null primary key autoincrement, contractType varchar(100) not null, + isPreneed bit not null default 0, orderNumber smallint not null default 0, ${recordColumns})`, @@ -205,6 +207,7 @@ const createStatements = [ purchaserPostalCode varchar(7), purchaserPhoneNumber varchar(30), purchaserEmail varchar(100), + purchaserRelationship varchar(50), funeralHomeId integer, funeralDirectorName varchar(100), @@ -264,6 +267,12 @@ const createStatements = [ deceasedName varchar(50) not null, isCremated bit not null default 0, + deceasedAddress1 varchar(50), + deceasedAddress2 varchar(50), + deceasedCity varchar(20), + deceasedProvince varchar(2), + deceasedPostalCode varchar(7), + birthDate integer, birthPlace varchar(100), @@ -464,9 +473,43 @@ async function initializeData(): Promise { await addRecord('BurialSiteStatuses', 'Reserved', 2, initializingUser) await addRecord('BurialSiteStatuses', 'Taken', 3, initializingUser) - await addRecord('ContractTypes', 'Preneed', 1, initializingUser) - await addRecord('ContractTypes', 'Interment', 2, initializingUser) - await addRecord('ContractTypes', 'Cremation', 3, initializingUser) + await addContractType( + { + contractType: 'Preneed', + isPreneed: '1', + orderNumber: 1 + }, + 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) /* * Fee Categories diff --git a/database/updateContract.d.ts b/database/updateContract.d.ts index 518c188f..968bafcc 100644 --- a/database/updateContract.d.ts +++ b/database/updateContract.d.ts @@ -5,7 +5,18 @@ export interface UpdateContractForm { burialSiteId: string | number; contractStartDateString: DateString; contractEndDateString: DateString | ''; + funeralHomeId?: string | number; + funeralDirectorName?: string; + purchaserName?: string; + purchaserAddress1?: string; + purchaserAddress2?: string; + purchaserCity?: string; + purchaserProvince?: string; + purchaserPostalCode?: string; + purchaserPhoneNumber?: string; + purchaserEmail?: string; + purchaserRelationship?: string; contractTypeFieldIds?: string; - [fieldValue_contractTypeFieldId: string]: unknown; + [fieldValue_contractTypeFieldId: `fieldValue_${string}`]: unknown; } export default function updateContract(updateForm: UpdateContractForm, user: User): Promise; diff --git a/database/updateContract.js b/database/updateContract.js index 3ef5e1c6..0d602dc3 100644 --- a/database/updateContract.js +++ b/database/updateContract.js @@ -10,13 +10,24 @@ export default async function updateContract(updateForm, user) { burialSiteId = ?, contractStartDate = ?, contractEndDate = ?, + funeralHomeId = ?, + funeralDirectorName = ?, + purchaserName = ?, + purchaserAddress1 = ?, + purchaserAddress2 = ?, + purchaserCity = ?, + purchaserProvince = ?, + purchaserPostalCode = ?, + purchaserPhoneNumber = ?, + purchaserEmail = ?, + purchaserRelationship = ?, recordUpdate_userName = ?, recordUpdate_timeMillis = ? where contractId = ? and recordDelete_timeMillis is null`) .run(updateForm.contractTypeId, updateForm.burialSiteId === '' ? undefined : updateForm.burialSiteId, dateStringToInteger(updateForm.contractStartDateString), updateForm.contractEndDateString === '' ? undefined - : dateStringToInteger(updateForm.contractEndDateString), user.userName, Date.now(), updateForm.contractId); + : dateStringToInteger(updateForm.contractEndDateString), updateForm.funeralHomeId === '' ? undefined : updateForm.funeralHomeId, updateForm.funeralDirectorName ?? '', updateForm.purchaserName ?? '', updateForm.purchaserAddress1 ?? '', updateForm.purchaserAddress2 ?? '', updateForm.purchaserCity ?? '', updateForm.purchaserProvince ?? '', updateForm.purchaserPostalCode ?? '', updateForm.purchaserPhoneNumber ?? '', updateForm.purchaserEmail ?? '', updateForm.purchaserRelationship ?? '', user.userName, Date.now(), updateForm.contractId); if (result.changes > 0) { const contractTypeFieldIds = (updateForm.contractTypeFieldIds ?? '').split(','); for (const contractTypeFieldId of contractTypeFieldIds) { diff --git a/database/updateContract.ts b/database/updateContract.ts index bca99df5..61be62c9 100644 --- a/database/updateContract.ts +++ b/database/updateContract.ts @@ -12,8 +12,21 @@ export interface UpdateContractForm { contractStartDateString: DateString contractEndDateString: DateString | '' + funeralHomeId?: string | number + funeralDirectorName?: string + + purchaserName?: string + purchaserAddress1?: string + purchaserAddress2?: string + purchaserCity?: string + purchaserProvince?: string + purchaserPostalCode?: string + purchaserPhoneNumber?: string + purchaserEmail?: string + purchaserRelationship?: string + contractTypeFieldIds?: string - [fieldValue_contractTypeFieldId: string]: unknown + [fieldValue_contractTypeFieldId: `fieldValue_${string}`]: unknown } export default async function updateContract( @@ -29,6 +42,17 @@ export default async function updateContract( burialSiteId = ?, contractStartDate = ?, contractEndDate = ?, + funeralHomeId = ?, + funeralDirectorName = ?, + purchaserName = ?, + purchaserAddress1 = ?, + purchaserAddress2 = ?, + purchaserCity = ?, + purchaserProvince = ?, + purchaserPostalCode = ?, + purchaserPhoneNumber = ?, + purchaserEmail = ?, + purchaserRelationship = ?, recordUpdate_userName = ?, recordUpdate_timeMillis = ? where contractId = ? @@ -41,6 +65,17 @@ export default async function updateContract( updateForm.contractEndDateString === '' ? undefined : dateStringToInteger(updateForm.contractEndDateString), + updateForm.funeralHomeId === '' ? undefined : updateForm.funeralHomeId, + updateForm.funeralDirectorName ?? '', + updateForm.purchaserName ?? '', + updateForm.purchaserAddress1 ?? '', + updateForm.purchaserAddress2 ?? '', + updateForm.purchaserCity ?? '', + updateForm.purchaserProvince ?? '', + updateForm.purchaserPostalCode ?? '', + updateForm.purchaserPhoneNumber ?? '', + updateForm.purchaserEmail ?? '', + updateForm.purchaserRelationship ?? '', user.userName, Date.now(), updateForm.contractId diff --git a/database/updateContractType.d.ts b/database/updateContractType.d.ts new file mode 100644 index 00000000..e86f5a52 --- /dev/null +++ b/database/updateContractType.d.ts @@ -0,0 +1,6 @@ +export interface UpdateForm { + contractTypeId: number | string; + contractType: string; + isPreneed?: string; +} +export default function updateContractType(updateForm: UpdateForm, user: User): Promise; diff --git a/database/updateContractType.js b/database/updateContractType.js new file mode 100644 index 00000000..e74ed750 --- /dev/null +++ b/database/updateContractType.js @@ -0,0 +1,18 @@ +import { clearCacheByTableName } from '../helpers/functions.cache.js'; +import { acquireConnection } from './pool.js'; +export default async function updateContractType(updateForm, user) { + const database = await acquireConnection(); + const rightNowMillis = Date.now(); + const result = database + .prepare(`update ContractTypes + set contractType = ?, + isPreneed = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where recordDelete_timeMillis is null + and contractTypeId = ?`) + .run(updateForm.contractType, updateForm.isPreneed === undefined ? 0 : 1, user.userName, rightNowMillis, updateForm.contractTypeId); + database.release(); + clearCacheByTableName('ContractTypes'); + return result.changes > 0; +} diff --git a/database/updateContractType.ts b/database/updateContractType.ts new file mode 100644 index 00000000..c0fb9963 --- /dev/null +++ b/database/updateContractType.ts @@ -0,0 +1,42 @@ +import { clearCacheByTableName } from '../helpers/functions.cache.js' + +import { acquireConnection } from './pool.js' + +export interface UpdateForm { + contractTypeId: number | string + contractType: string + isPreneed?: string +} + +export default async function updateContractType( + updateForm: UpdateForm, + user: User +): Promise { + const database = await acquireConnection() + + const rightNowMillis = Date.now() + + const result = database + .prepare( + `update ContractTypes + set contractType = ?, + isPreneed = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where recordDelete_timeMillis is null + and contractTypeId = ?` + ) + .run( + updateForm.contractType, + updateForm.isPreneed === undefined ? 0 : 1, + user.userName, + rightNowMillis, + updateForm.contractTypeId + ) + + database.release() + + clearCacheByTableName('ContractTypes') + + return result.changes > 0 +} diff --git a/database/updateRecord.d.ts b/database/updateRecord.d.ts index 31d33036..c2c6feb7 100644 --- a/database/updateRecord.d.ts +++ b/database/updateRecord.d.ts @@ -1,3 +1,3 @@ -type RecordTable = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'ContractTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; +type RecordTable = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; export declare function updateRecord(recordTable: RecordTable, recordId: number | string, recordName: string, user: User): Promise; export {}; diff --git a/database/updateRecord.js b/database/updateRecord.js index 8dff0d9a..ebc4bdf3 100644 --- a/database/updateRecord.js +++ b/database/updateRecord.js @@ -1,9 +1,14 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js'; import { acquireConnection } from './pool.js'; const recordNameIdColumns = new Map(); -recordNameIdColumns.set('BurialSiteStatuses', ['burialSiteStatus', 'burialSiteStatusId']); -recordNameIdColumns.set('BurialSiteTypes', ['burialSiteType', 'burialSiteTypeId']); -recordNameIdColumns.set('ContractTypes', ['contractType', 'contractTypeId']); +recordNameIdColumns.set('BurialSiteStatuses', [ + 'burialSiteStatus', + 'burialSiteStatusId' +]); +recordNameIdColumns.set('BurialSiteTypes', [ + 'burialSiteType', + 'burialSiteTypeId' +]); recordNameIdColumns.set('WorkOrderMilestoneTypes', [ 'workOrderMilestoneType', 'workOrderMilestoneTypeId' diff --git a/database/updateRecord.ts b/database/updateRecord.ts index 653db97a..7312f8f9 100644 --- a/database/updateRecord.ts +++ b/database/updateRecord.ts @@ -5,14 +5,18 @@ import { acquireConnection } from './pool.js' type RecordTable = | 'BurialSiteStatuses' | 'BurialSiteTypes' - | 'ContractTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes' const recordNameIdColumns = new Map() -recordNameIdColumns.set('BurialSiteStatuses', ['burialSiteStatus', 'burialSiteStatusId']) -recordNameIdColumns.set('BurialSiteTypes', ['burialSiteType', 'burialSiteTypeId']) -recordNameIdColumns.set('ContractTypes', ['contractType', 'contractTypeId']) +recordNameIdColumns.set('BurialSiteStatuses', [ + 'burialSiteStatus', + 'burialSiteStatusId' +]) +recordNameIdColumns.set('BurialSiteTypes', [ + 'burialSiteType', + 'burialSiteTypeId' +]) recordNameIdColumns.set('WorkOrderMilestoneTypes', [ 'workOrderMilestoneType', 'workOrderMilestoneTypeId' diff --git a/handlers/admin-post/doAddContractType.d.ts b/handlers/admin-post/doAddContractType.d.ts index 285a30a9..b3f98166 100644 --- a/handlers/admin-post/doAddContractType.d.ts +++ b/handlers/admin-post/doAddContractType.d.ts @@ -1,5 +1,3 @@ import type { Request, Response } from 'express'; -export default function handler(request: Request, response: Response): Promise; +import { type AddForm } from '../../database/addContractType.js'; +export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doAddContractType.js b/handlers/admin-post/doAddContractType.js index 824e6890..20e32e03 100644 --- a/handlers/admin-post/doAddContractType.js +++ b/handlers/admin-post/doAddContractType.js @@ -1,7 +1,7 @@ -import addRecord from '../../database/addRecord.js'; +import addContractType from '../../database/addContractType.js'; import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const contractTypeId = await addRecord('ContractTypes', request.body.contractType, request.body.orderNumber ?? -1, request.session.user); + const contractTypeId = await addContractType(request.body, request.session.user); const contractTypes = await getContractTypes(); const allContractTypeFields = await getAllContractTypeFields(); response.json({ diff --git a/handlers/admin-post/doAddContractType.ts b/handlers/admin-post/doAddContractType.ts index 12a798f2..f18aa4b7 100644 --- a/handlers/admin-post/doAddContractType.ts +++ b/handlers/admin-post/doAddContractType.ts @@ -1,23 +1,19 @@ import type { Request, Response } from 'express' -import addRecord from '../../database/addRecord.js' +import addContractType, { + type AddForm +} from '../../database/addContractType.js' import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( - request: Request< - unknown, - unknown, - { contractType: string; orderNumber?: number | string } - >, + request: Request, response: Response ): Promise { - const contractTypeId = await addRecord( - 'ContractTypes', - request.body.contractType, - request.body.orderNumber ?? -1, + const contractTypeId = await addContractType( + request.body, request.session.user as User ) diff --git a/handlers/admin-post/doUpdateContractType.d.ts b/handlers/admin-post/doUpdateContractType.d.ts index 8bd56034..0746ff1a 100644 --- a/handlers/admin-post/doUpdateContractType.d.ts +++ b/handlers/admin-post/doUpdateContractType.d.ts @@ -1,5 +1,3 @@ import type { Request, Response } from 'express'; -export default function handler(request: Request, response: Response): Promise; +import { type UpdateForm } from '../../database/updateContractType.js'; +export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doUpdateContractType.js b/handlers/admin-post/doUpdateContractType.js index ba73d2b7..a22d133e 100644 --- a/handlers/admin-post/doUpdateContractType.js +++ b/handlers/admin-post/doUpdateContractType.js @@ -1,7 +1,7 @@ -import { updateRecord } from '../../database/updateRecord.js'; +import updateContractType from '../../database/updateContractType.js'; import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const success = await updateRecord('ContractTypes', request.body.contractTypeId, request.body.contractType, request.session.user); + const success = await updateContractType(request.body, request.session.user); const contractTypes = await getContractTypes(); const allContractTypeFields = await getAllContractTypeFields(); response.json({ diff --git a/handlers/admin-post/doUpdateContractType.ts b/handlers/admin-post/doUpdateContractType.ts index 76079502..6a6936a6 100644 --- a/handlers/admin-post/doUpdateContractType.ts +++ b/handlers/admin-post/doUpdateContractType.ts @@ -1,23 +1,19 @@ import type { Request, Response } from 'express' -import { updateRecord } from '../../database/updateRecord.js' +import updateContractType, { + type UpdateForm +} from '../../database/updateContractType.js' import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( - request: Request< - unknown, - unknown, - { contractTypeId: string; contractType: string } - >, + request: Request, response: Response ): Promise { - const success = await updateRecord( - 'ContractTypes', - request.body.contractTypeId, - request.body.contractType, + const success = await updateContractType( + request.body, request.session.user as User ) diff --git a/handlers/contracts-get/edit.js b/handlers/contracts-get/edit.js index 8304b6b3..a486e398 100644 --- a/handlers/contracts-get/edit.js +++ b/handlers/contracts-get/edit.js @@ -1,7 +1,7 @@ -import getCemeteries from '../../database/getCemeteries.js'; import getContract from '../../database/getContract.js'; +import getFuneralHomes from '../../database/getFuneralHomes.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; -import { getBurialSiteStatuses, getBurialSiteTypes, getContractTypePrintsById, getContractTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js'; +import { getContractTypePrintsById, getContractTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const contract = await getContract(request.params.contractId); if (contract === undefined) { @@ -10,18 +10,14 @@ export default async function handler(request, response) { } const contractTypePrints = await getContractTypePrintsById(contract.contractTypeId); const contractTypes = await getContractTypes(); - const burialSiteTypes = await getBurialSiteTypes(); - const burialSiteStatuses = await getBurialSiteStatuses(); - const cemeteries = await getCemeteries(); + const funeralHomes = await getFuneralHomes(); const workOrderTypes = await getWorkOrderTypes(); response.render('contract-edit', { headTitle: 'Contract Update', contract, contractTypePrints, contractTypes, - burialSiteTypes, - burialSiteStatuses, - cemeteries, + funeralHomes, workOrderTypes, isCreate: false }); diff --git a/handlers/contracts-get/edit.ts b/handlers/contracts-get/edit.ts index aaf1bca9..20422bd6 100644 --- a/handlers/contracts-get/edit.ts +++ b/handlers/contracts-get/edit.ts @@ -1,11 +1,9 @@ import type { Request, Response } from 'express' -import getCemeteries from '../../database/getCemeteries.js' import getContract from '../../database/getContract.js' +import getFuneralHomes from '../../database/getFuneralHomes.js' import { getConfigProperty } from '../../helpers/config.helpers.js' import { - getBurialSiteStatuses, - getBurialSiteTypes, getContractTypePrintsById, getContractTypes, getWorkOrderTypes @@ -33,9 +31,7 @@ export default async function handler( ) const contractTypes = await getContractTypes() - const burialSiteTypes = await getBurialSiteTypes() - const burialSiteStatuses = await getBurialSiteStatuses() - const cemeteries = await getCemeteries() + const funeralHomes = await getFuneralHomes() const workOrderTypes = await getWorkOrderTypes() response.render('contract-edit', { @@ -44,9 +40,7 @@ export default async function handler( contractTypePrints, contractTypes, - burialSiteTypes, - burialSiteStatuses, - cemeteries, + funeralHomes, workOrderTypes, isCreate: false diff --git a/handlers/contracts-get/new.js b/handlers/contracts-get/new.js index b3ee6299..bee37d07 100644 --- a/handlers/contracts-get/new.js +++ b/handlers/contracts-get/new.js @@ -1,12 +1,16 @@ import { dateToInteger, dateToString } from '@cityssm/utils-datetime'; import getBurialSite from '../../database/getBurialSite.js'; -import getCemeteries from '../../database/getCemeteries.js'; -import { getBurialSiteStatuses, getBurialSiteTypes, getContractTypes } from '../../helpers/functions.cache.js'; +import getFuneralHomes from '../../database/getFuneralHomes.js'; +import { getConfigProperty } from '../../helpers/config.helpers.js'; +import { getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const startDate = new Date(); const contract = { + isPreneed: false, contractStartDate: dateToInteger(startDate), - contractStartDateString: dateToString(startDate) + contractStartDateString: dateToString(startDate), + purchaserCity: getConfigProperty('settings.cityDefault'), + purchaserProvince: getConfigProperty('settings.provinceDefault') }; if (request.query.burialSiteId !== undefined) { const burialSite = await getBurialSite(request.query.burialSiteId); @@ -18,16 +22,12 @@ export default async function handler(request, response) { } } const contractTypes = await getContractTypes(); - const burialSiteTypes = await getBurialSiteTypes(); - const burialSiteStatuses = await getBurialSiteStatuses(); - const cemeteries = await getCemeteries(); + const funeralHomes = await getFuneralHomes(); response.render('contract-edit', { headTitle: 'Create a New Contract', contract, contractTypes, - burialSiteTypes, - burialSiteStatuses, - cemeteries, + funeralHomes, isCreate: true }); } diff --git a/handlers/contracts-get/new.ts b/handlers/contracts-get/new.ts index c6646704..4b816ff7 100644 --- a/handlers/contracts-get/new.ts +++ b/handlers/contracts-get/new.ts @@ -2,12 +2,9 @@ import { dateToInteger, dateToString } from '@cityssm/utils-datetime' import type { Request, Response } from 'express' import getBurialSite from '../../database/getBurialSite.js' -import getCemeteries from '../../database/getCemeteries.js' -import { - getBurialSiteStatuses, - getBurialSiteTypes, - getContractTypes -} from '../../helpers/functions.cache.js' +import getFuneralHomes from '../../database/getFuneralHomes.js' +import { getConfigProperty } from '../../helpers/config.helpers.js' +import { getContractTypes } from '../../helpers/functions.cache.js' import type { Contract } from '../../types/recordTypes.js' export default async function handler( @@ -17,8 +14,11 @@ export default async function handler( const startDate = new Date() const contract: Partial = { + isPreneed: false, contractStartDate: dateToInteger(startDate), - contractStartDateString: dateToString(startDate) + contractStartDateString: dateToString(startDate), + purchaserCity: getConfigProperty('settings.cityDefault'), + purchaserProvince: getConfigProperty('settings.provinceDefault') } if (request.query.burialSiteId !== undefined) { @@ -33,18 +33,14 @@ export default async function handler( } const contractTypes = await getContractTypes() - const burialSiteTypes = await getBurialSiteTypes() - const burialSiteStatuses = await getBurialSiteStatuses() - const cemeteries = await getCemeteries() + const funeralHomes = await getFuneralHomes() response.render('contract-edit', { headTitle: 'Create a New Contract', contract, contractTypes, - burialSiteTypes, - burialSiteStatuses, - cemeteries, + funeralHomes, isCreate: true }) diff --git a/helpers/functions.cache.d.ts b/helpers/functions.cache.d.ts index f6eb1801..22d2ca88 100644 --- a/helpers/functions.cache.d.ts +++ b/helpers/functions.cache.d.ts @@ -1,4 +1,4 @@ -import type { BurialSiteStatus, BurialSiteType, ContractType, ContractTypeField, WorkOrderMilestoneType, WorkOrderType } from '../types/recordTypes.js'; +import type { BurialSiteStatus, BurialSiteType, ContractType, ContractTypeField, IntermentCommittalType, 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; @@ -10,6 +10,10 @@ export declare function getAllContractTypeFields(): Promise export declare function getContractTypeById(contractTypeId: number): Promise; export declare function getContractTypeByContractType(contractTypeString: string): Promise; 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 getWorkOrderTypes(): Promise; export declare function getWorkOrderTypeById(workOrderTypeId: number): Promise; export declare function getWorkOrderMilestoneTypes(): Promise; @@ -17,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' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes' | 'FeeCategories' | 'Fees'; +type CacheTableNames = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'BurialSiteTypeFields' | 'ContractTypes' | 'ContractTypeFields' | 'ContractTypePrints' | 'IntermentContainerTypes' | 'IntermentCommittalTypes' | '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 bab645eb..21b81ad4 100644 --- a/helpers/functions.cache.js +++ b/helpers/functions.cache.js @@ -6,6 +6,8 @@ import getBurialSiteStatusesFromDatabase from '../database/getBurialSiteStatuses import getBurialSiteTypesFromDatabase from '../database/getBurialSiteTypes.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'; import { DEBUG_NAMESPACE } from '../debug.config.js'; @@ -96,6 +98,40 @@ function clearContractTypesCache() { contractTypes = undefined; allContractTypeFields = undefined; } +/* + * Interment Container Types + */ +let intermentContainerTypes; +export async function getIntermentContainerTypes() { + if (intermentContainerTypes === undefined) { + intermentContainerTypes = await getIntermentContainerTypesFromDatabase(); + } + return intermentContainerTypes; +} +export async function getIntermentContainerTypeById(intermentContainerTypeId) { + const cachedContainerTypes = await getIntermentContainerTypes(); + return cachedContainerTypes.find((currentContainerType) => currentContainerType.intermentContainerTypeId === intermentContainerTypeId); +} +function clearIntermentContainerTypesCache() { + intermentContainerTypes = undefined; +} +/* + * Interment Committal Types + */ +let intermentCommittalTypes; +export async function getIntermentCommittalTypes() { + if (intermentCommittalTypes === undefined) { + intermentCommittalTypes = await getIntermentCommittalTypesFromDatabase(); + } + return intermentCommittalTypes; +} +export async function getIntermentCommittalTypeById(intermentCommittalTypeId) { + const cachedCommittalTypes = await getIntermentCommittalTypes(); + return cachedCommittalTypes.find((currentCommittalType) => currentCommittalType.intermentCommittalTypeId === intermentCommittalTypeId); +} +function clearIntermentCommittalTypesCache() { + intermentCommittalTypes = undefined; +} /* * Work Order Types */ @@ -169,6 +205,14 @@ export function clearCacheByTableName(tableName, relayMessage = true) { clearContractTypesCache(); break; } + case 'IntermentContainerTypes': { + clearIntermentContainerTypesCache(); + break; + } + case 'IntermentCommittalTypes': { + clearIntermentCommittalTypesCache(); + break; + } case 'WorkOrderMilestoneTypes': { clearWorkOrderMilestoneTypesCache(); break; diff --git a/helpers/functions.cache.ts b/helpers/functions.cache.ts index c84d07aa..e9ac2571 100644 --- a/helpers/functions.cache.ts +++ b/helpers/functions.cache.ts @@ -9,6 +9,8 @@ import getBurialSiteStatusesFromDatabase from '../database/getBurialSiteStatuses import getBurialSiteTypesFromDatabase from '../database/getBurialSiteTypes.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' import { DEBUG_NAMESPACE } from '../debug.config.js' @@ -21,6 +23,8 @@ import type { BurialSiteType, ContractType, ContractTypeField, + IntermentCommittalType, + IntermentContainerType, WorkOrderMilestoneType, WorkOrderType } from '../types/recordTypes.js' @@ -178,6 +182,68 @@ function clearContractTypesCache(): void { allContractTypeFields = undefined } +/* + * Interment Container Types + */ + +let intermentContainerTypes: IntermentContainerType[] | undefined + +export async function getIntermentContainerTypes(): Promise< + IntermentContainerType[] +> { + if (intermentContainerTypes === undefined) { + intermentContainerTypes = await getIntermentContainerTypesFromDatabase() + } + + return intermentContainerTypes +} + +export async function getIntermentContainerTypeById( + intermentContainerTypeId: number +): Promise { + const cachedContainerTypes = await getIntermentContainerTypes() + + return cachedContainerTypes.find( + (currentContainerType) => + currentContainerType.intermentContainerTypeId === intermentContainerTypeId + ) +} + +function clearIntermentContainerTypesCache(): void { + intermentContainerTypes = undefined +} + +/* + * Interment Committal Types + */ + +let intermentCommittalTypes: IntermentCommittalType[] | undefined + +export async function getIntermentCommittalTypes(): Promise< + IntermentCommittalType[] +> { + if (intermentCommittalTypes === undefined) { + intermentCommittalTypes = await getIntermentCommittalTypesFromDatabase() + } + + return intermentCommittalTypes +} + +export async function getIntermentCommittalTypeById( + intermentCommittalTypeId: number +): Promise { + const cachedCommittalTypes = await getIntermentCommittalTypes() + + return cachedCommittalTypes.find( + (currentCommittalType) => + currentCommittalType.intermentCommittalTypeId === intermentCommittalTypeId + ) +} + +function clearIntermentCommittalTypesCache(): void { + intermentCommittalTypes = undefined +} + /* * Work Order Types */ @@ -278,6 +344,8 @@ type CacheTableNames = | 'ContractTypes' | 'ContractTypeFields' | 'ContractTypePrints' + | 'IntermentContainerTypes' + | 'IntermentCommittalTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes' | 'FeeCategories' @@ -306,6 +374,16 @@ export function clearCacheByTableName( break } + case 'IntermentContainerTypes': { + clearIntermentContainerTypesCache() + break + } + + case 'IntermentCommittalTypes': { + clearIntermentCommittalTypesCache() + break + } + case 'WorkOrderMilestoneTypes': { clearWorkOrderMilestoneTypesCache() break diff --git a/public/html/adminContractTypes-add.html b/public/html/adminContractTypes-add.html index 3eaf5cc5..fd96697f 100644 --- a/public/html/adminContractTypes-add.html +++ b/public/html/adminContractTypes-add.html @@ -13,19 +13,37 @@