legacy import

pull/3/head
Dan Gowans 2025-03-18 13:40:03 -04:00
parent 545941e69e
commit d4aa83fd7a
103 changed files with 3561 additions and 3355 deletions

5
app.js
View File

@ -9,7 +9,6 @@ import rateLimit from 'express-rate-limit';
import session from 'express-session'; import session from 'express-session';
import createError from 'http-errors'; import createError from 'http-errors';
import FileStore from 'session-file-store'; import FileStore from 'session-file-store';
import { initializeDatabase } from './database/initializeDatabase.js';
import { DEBUG_NAMESPACE } from './debug.config.js'; import { DEBUG_NAMESPACE } from './debug.config.js';
import * as permissionHandlers from './handlers/permissions.js'; import * as permissionHandlers from './handlers/permissions.js';
import * as configFunctions from './helpers/config.helpers.js'; import * as configFunctions from './helpers/config.helpers.js';
@ -29,10 +28,6 @@ import routerReports from './routes/reports.js';
import routerWorkOrders from './routes/workOrders.js'; import routerWorkOrders from './routes/workOrders.js';
import { version } from './version.js'; import { version } from './version.js';
const debug = Debug(`${DEBUG_NAMESPACE}:app:${process.pid}`); const debug = Debug(`${DEBUG_NAMESPACE}:app:${process.pid}`);
/*
* INITIALIZE THE DATABASE
*/
await initializeDatabase();
/* /*
* INITIALIZE APP * INITIALIZE APP
*/ */

7
app.ts
View File

@ -11,7 +11,6 @@ import session from 'express-session'
import createError from 'http-errors' import createError from 'http-errors'
import FileStore from 'session-file-store' import FileStore from 'session-file-store'
import { initializeDatabase } from './database/initializeDatabase.js'
import { DEBUG_NAMESPACE } from './debug.config.js' import { DEBUG_NAMESPACE } from './debug.config.js'
import * as permissionHandlers from './handlers/permissions.js' import * as permissionHandlers from './handlers/permissions.js'
import * as configFunctions from './helpers/config.helpers.js' import * as configFunctions from './helpers/config.helpers.js'
@ -33,12 +32,6 @@ import { version } from './version.js'
const debug = Debug(`${DEBUG_NAMESPACE}:app:${process.pid}`) const debug = Debug(`${DEBUG_NAMESPACE}:app:${process.pid}`)
/*
* INITIALIZE THE DATABASE
*/
await initializeDatabase()
/* /*
* INITIALIZE APP * INITIALIZE APP
*/ */

View File

@ -6,9 +6,12 @@ import ntfyPublish from '@cityssm/ntfy-publish';
import { secondsToMillis } from '@cityssm/to-millis'; import { secondsToMillis } from '@cityssm/to-millis';
import Debug from 'debug'; import Debug from 'debug';
import exitHook from 'exit-hook'; import exitHook from 'exit-hook';
import { initializeDatabase } from '../database/initializeDatabase.js';
import { DEBUG_NAMESPACE } from '../debug.config.js'; import { DEBUG_NAMESPACE } from '../debug.config.js';
import { getConfigProperty } from '../helpers/config.helpers.js'; import { getConfigProperty } from '../helpers/config.helpers.js';
const debug = Debug(`${DEBUG_NAMESPACE}:www:${process.pid}`); const debug = Debug(`${DEBUG_NAMESPACE}:www:${process.pid}`);
// INITIALIZE THE DATABASE
await initializeDatabase();
const directoryName = path.dirname(fileURLToPath(import.meta.url)); const directoryName = path.dirname(fileURLToPath(import.meta.url));
const processCount = Math.min(getConfigProperty('application.maximumProcesses'), os.cpus().length); const processCount = Math.min(getConfigProperty('application.maximumProcesses'), os.cpus().length);
process.title = `${getConfigProperty('application.applicationName')} (Primary)`; process.title = `${getConfigProperty('application.applicationName')} (Primary)`;
@ -26,6 +29,7 @@ for (let index = 0; index < processCount; index += 1) {
} }
cluster.on('message', (worker, message) => { cluster.on('message', (worker, message) => {
for (const [pid, activeWorker] of activeWorkers.entries()) { for (const [pid, activeWorker] of activeWorkers.entries()) {
// eslint-disable-next-line sonarjs/different-types-comparison, @typescript-eslint/no-unnecessary-condition
if (activeWorker === undefined || pid === message.pid) { if (activeWorker === undefined || pid === message.pid) {
continue; continue;
} }

View File

@ -8,12 +8,16 @@ import { secondsToMillis } from '@cityssm/to-millis'
import Debug from 'debug' import Debug from 'debug'
import exitHook from 'exit-hook' import exitHook from 'exit-hook'
import { initializeDatabase } from '../database/initializeDatabase.js'
import { DEBUG_NAMESPACE } from '../debug.config.js' import { DEBUG_NAMESPACE } from '../debug.config.js'
import { getConfigProperty } from '../helpers/config.helpers.js' import { getConfigProperty } from '../helpers/config.helpers.js'
import type { WorkerMessage } from '../types/applicationTypes.js' import type { WorkerMessage } from '../types/applicationTypes.js'
const debug = Debug(`${DEBUG_NAMESPACE}:www:${process.pid}`) const debug = Debug(`${DEBUG_NAMESPACE}:www:${process.pid}`)
// INITIALIZE THE DATABASE
await initializeDatabase()
const directoryName = path.dirname(fileURLToPath(import.meta.url)) const directoryName = path.dirname(fileURLToPath(import.meta.url))
const processCount = Math.min( const processCount = Math.min(
@ -42,6 +46,7 @@ for (let index = 0; index < processCount; index += 1) {
cluster.on('message', (worker, message: WorkerMessage) => { cluster.on('message', (worker, message: WorkerMessage) => {
for (const [pid, activeWorker] of activeWorkers.entries()) { for (const [pid, activeWorker] of activeWorkers.entries()) {
// eslint-disable-next-line sonarjs/different-types-comparison, @typescript-eslint/no-unnecessary-condition
if (activeWorker === undefined || pid === message.pid) { if (activeWorker === undefined || pid === message.pid) {
continue continue
} }

View File

@ -4,9 +4,14 @@ import http from 'node:http';
import Debug from 'debug'; import Debug from 'debug';
import exitHook from 'exit-hook'; import exitHook from 'exit-hook';
import { app } from '../app.js'; import { app } from '../app.js';
import { initializeDatabase } from '../database/initializeDatabase.js';
import { DEBUG_NAMESPACE } from '../debug.config.js'; import { DEBUG_NAMESPACE } from '../debug.config.js';
import { getConfigProperty } from '../helpers/config.helpers.js'; import { getConfigProperty } from '../helpers/config.helpers.js';
const debug = Debug(`${DEBUG_NAMESPACE}:wwwProcess:${process.pid}`); const debug = Debug(`${DEBUG_NAMESPACE}:wwwProcess:${process.pid}`);
if (process.send === undefined) {
// INITIALIZE THE DATABASE
await initializeDatabase();
}
function onError(error) { function onError(error) {
if (error.syscall !== 'listen') { if (error.syscall !== 'listen') {
throw error; throw error;

View File

@ -7,11 +7,17 @@ import Debug from 'debug'
import exitHook from 'exit-hook' import exitHook from 'exit-hook'
import { app } from '../app.js' import { app } from '../app.js'
import { initializeDatabase } from '../database/initializeDatabase.js'
import { DEBUG_NAMESPACE } from '../debug.config.js' import { DEBUG_NAMESPACE } from '../debug.config.js'
import { getConfigProperty } from '../helpers/config.helpers.js' import { getConfigProperty } from '../helpers/config.helpers.js'
const debug = Debug(`${DEBUG_NAMESPACE}:wwwProcess:${process.pid}`) const debug = Debug(`${DEBUG_NAMESPACE}:wwwProcess:${process.pid}`)
if (process.send === undefined) {
// INITIALIZE THE DATABASE
await initializeDatabase()
}
interface ServerError extends Error { interface ServerError extends Error {
syscall: string syscall: string
code: string code: string

View File

@ -28,6 +28,8 @@ export declare const configDefaultValues: {
'settings.provinceDefault': string; 'settings.provinceDefault': string;
'settings.burialSites.burialSiteNameSegments': ConfigBurialSiteNameSegments; 'settings.burialSites.burialSiteNameSegments': ConfigBurialSiteNameSegments;
'settings.contracts.burialSiteIdIsRequired': boolean; 'settings.contracts.burialSiteIdIsRequired': boolean;
'settings.contracts.contractEndDateIsRequired': boolean;
'settings.contracts.deathAgePeriods': string[];
'settings.contracts.prints': string[]; 'settings.contracts.prints': string[];
'settings.fees.taxPercentageDefault': number; 'settings.fees.taxPercentageDefault': number;
'settings.workOrders.workOrderNumberLength': number; 'settings.workOrders.workOrderNumberLength': number;

View File

@ -38,6 +38,8 @@ export const configDefaultValues = {
} }
}, },
'settings.contracts.burialSiteIdIsRequired': true, 'settings.contracts.burialSiteIdIsRequired': true,
'settings.contracts.contractEndDateIsRequired': false,
'settings.contracts.deathAgePeriods': ['Years', 'Months', 'Days', 'Stillborn'],
'settings.contracts.prints': ['screen/contract'], 'settings.contracts.prints': ['screen/contract'],
'settings.fees.taxPercentageDefault': 0, 'settings.fees.taxPercentageDefault': 0,
'settings.workOrders.workOrderNumberLength': 6, 'settings.workOrders.workOrderNumberLength': 6,

View File

@ -57,6 +57,8 @@ export const configDefaultValues = {
'settings.contracts.burialSiteIdIsRequired': true, 'settings.contracts.burialSiteIdIsRequired': true,
'settings.contracts.contractEndDateIsRequired': false,
'settings.contracts.deathAgePeriods': ['Years', 'Months', 'Days', 'Stillborn'],
'settings.contracts.prints': ['screen/contract'], 'settings.contracts.prints': ['screen/contract'],
'settings.fees.taxPercentageDefault': 0, 'settings.fees.taxPercentageDefault': 0,

6
database/addCommittalType.d.ts vendored 100644
View File

@ -0,0 +1,6 @@
export interface AddForm {
committalType: string;
committalTypeKey?: string;
orderNumber?: number;
}
export default function addCommittalType(addForm: AddForm, user: User): Promise<number>;

View File

@ -0,0 +1,16 @@
import { clearCacheByTableName } from '../helpers/functions.cache.js';
import { acquireConnection } from './pool.js';
export default async function addCommittalType(addForm, user) {
const database = await acquireConnection();
const rightNowMillis = Date.now();
const result = database
.prepare(`insert into CommittalTypes (
committalType, committalTypeKey, orderNumber,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?)`)
.run(addForm.committalType, addForm.committalTypeKey ?? '', addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
database.release();
clearCacheByTableName('CommittalTypes');
return result.lastInsertRowid;
}

View File

@ -0,0 +1,42 @@
import { clearCacheByTableName } from '../helpers/functions.cache.js'
import { acquireConnection } from './pool.js'
export interface AddForm {
committalType: string
committalTypeKey?: string
orderNumber?: number
}
export default async function addCommittalType(
addForm: AddForm,
user: User
): Promise<number> {
const database = await acquireConnection()
const rightNowMillis = Date.now()
const result = database
.prepare(
`insert into CommittalTypes (
committalType, committalTypeKey, orderNumber,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?)`
)
.run(
addForm.committalType,
addForm.committalTypeKey ?? '',
addForm.orderNumber ?? -1,
user.userName,
rightNowMillis,
user.userName,
rightNowMillis
)
database.release()
clearCacheByTableName('CommittalTypes')
return result.lastInsertRowid as number
}

View File

@ -31,6 +31,8 @@ export interface AddContractForm {
birthPlace?: string; birthPlace?: string;
deathDateString?: DateString | ''; deathDateString?: DateString | '';
deathPlace?: string; deathPlace?: string;
deathAge?: string;
deathAgePeriod?: string;
intermentContainerTypeId?: string | number; intermentContainerTypeId?: string | number;
} }
export default function addContract(addForm: AddContractForm, user: User, connectedDatabase?: PoolConnection): Promise<number>; export default function addContract(addForm: AddContractForm, user: User, connectedDatabase?: PoolConnection): Promise<number>;

View File

@ -52,15 +52,16 @@ export default async function addContract(addForm, user, connectedDatabase) {
deceasedCity, deceasedProvince, deceasedPostalCode, deceasedCity, deceasedProvince, deceasedPostalCode,
birthDate, deathDate, birthDate, deathDate,
birthPlace, deathPlace, birthPlace, deathPlace,
deathAge, deathAgePeriod,
intermentContainerTypeId, intermentContainerTypeId,
recordCreate_userName, recordCreate_timeMillis, recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis) recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
.run(contractId, 1, addForm.deceasedName ?? '', addForm.deceasedAddress1 ?? '', addForm.deceasedAddress2 ?? '', addForm.deceasedCity ?? '', addForm.deceasedProvince ?? '', addForm.deceasedPostalCode ?? '', addForm.birthDateString === '' .run(contractId, 1, addForm.deceasedName ?? '', addForm.deceasedAddress1 ?? '', addForm.deceasedAddress2 ?? '', addForm.deceasedCity ?? '', addForm.deceasedProvince ?? '', addForm.deceasedPostalCode ?? '', addForm.birthDateString === ''
? undefined ? undefined
: dateStringToInteger(addForm.birthDateString), addForm.deathDateString === '' : dateStringToInteger(addForm.birthDateString), addForm.deathDateString === ''
? undefined ? undefined
: dateStringToInteger(addForm.deathDateString), addForm.birthPlace ?? '', addForm.deathPlace ?? '', addForm.intermentContainerTypeId === '' : dateStringToInteger(addForm.deathDateString), addForm.birthPlace ?? '', addForm.deathPlace ?? '', addForm.deathAge ?? undefined, addForm.deathAgePeriod ?? '', addForm.intermentContainerTypeId === ''
? undefined ? undefined
: addForm.intermentContainerTypeId, user.userName, rightNowMillis, user.userName, rightNowMillis); : addForm.intermentContainerTypeId, user.userName, rightNowMillis, user.userName, rightNowMillis);
} }

View File

@ -46,6 +46,8 @@ export interface AddContractForm {
birthPlace?: string birthPlace?: string
deathDateString?: DateString | '' deathDateString?: DateString | ''
deathPlace?: string deathPlace?: string
deathAge?: string
deathAgePeriod?: string
intermentContainerTypeId?: string | number intermentContainerTypeId?: string | number
} }
@ -148,10 +150,11 @@ export default async function addContract(
deceasedCity, deceasedProvince, deceasedPostalCode, deceasedCity, deceasedProvince, deceasedPostalCode,
birthDate, deathDate, birthDate, deathDate,
birthPlace, deathPlace, birthPlace, deathPlace,
deathAge, deathAgePeriod,
intermentContainerTypeId, intermentContainerTypeId,
recordCreate_userName, recordCreate_timeMillis, recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis) recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
) )
.run( .run(
@ -171,6 +174,8 @@ export default async function addContract(
: dateStringToInteger(addForm.deathDateString as DateString), : dateStringToInteger(addForm.deathDateString as DateString),
addForm.birthPlace ?? '', addForm.birthPlace ?? '',
addForm.deathPlace ?? '', addForm.deathPlace ?? '',
addForm.deathAge ?? undefined,
addForm.deathAgePeriod ?? '',
addForm.intermentContainerTypeId === '' addForm.intermentContainerTypeId === ''
? undefined ? undefined
: addForm.intermentContainerTypeId, : addForm.intermentContainerTypeId,

View File

@ -11,6 +11,8 @@ export interface AddForm {
birthPlace: string; birthPlace: string;
deathDateString: DateString | ''; deathDateString: DateString | '';
deathPlace: string; deathPlace: string;
deathAge: string;
deathAgePeriod: string;
intermentContainerTypeId: string | number; intermentContainerTypeId: string | number;
} }
export default function addContractInterment(contractForm: AddForm, user: User): Promise<number>; export default function addContractInterment(contractForm: AddForm, user: User): Promise<number>;

View File

@ -14,6 +14,8 @@ export interface AddForm {
birthPlace: string birthPlace: string
deathDateString: DateString | '' deathDateString: DateString | ''
deathPlace: string deathPlace: string
deathAge: string
deathAgePeriod: string
intermentContainerTypeId: string | number intermentContainerTypeId: string | number
} }

View File

@ -1,10 +1,10 @@
export interface AddFeeForm { export interface AddFeeForm {
feeCategoryId: string; feeCategoryId: string | number;
feeName: string; feeName: string;
feeDescription: string; feeDescription: string;
feeAccount: string; feeAccount: string;
contractTypeId: string; contractTypeId: string | number;
burialSiteTypeId: string; burialSiteTypeId: string | number;
feeAmount?: string; feeAmount?: string;
feeFunction?: string; feeFunction?: string;
taxAmount?: string; taxAmount?: string;

View File

@ -14,7 +14,7 @@ export default async function addFee(feeForm, user) {
recordCreate_userName, recordCreate_timeMillis, recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis) recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
.run(feeForm.feeCategoryId, feeForm.feeName, feeForm.feeDescription, feeForm.feeAccount, feeForm.contractTypeId === '' ? undefined : feeForm.contractTypeId, feeForm.burialSiteTypeId === '' ? undefined : feeForm.burialSiteTypeId, feeForm.feeAmount ?? undefined, feeForm.feeFunction ?? undefined, feeForm.taxAmount ?? undefined, feeForm.taxPercentage ?? undefined, (feeForm.includeQuantity ?? '') === '' ? 0 : 1, feeForm.quantityUnit, (feeForm.isRequired ?? '') === '' ? 0 : 1, feeForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis); .run(feeForm.feeCategoryId, feeForm.feeName, feeForm.feeDescription, feeForm.feeAccount, feeForm.contractTypeId === '' ? undefined : feeForm.contractTypeId, feeForm.burialSiteTypeId === '' ? undefined : feeForm.burialSiteTypeId, feeForm.feeAmount === '' ? undefined : feeForm.feeAmount, feeForm.feeFunction ?? undefined, feeForm.taxAmount === '' ? undefined : feeForm.taxAmount, feeForm.taxPercentage === '' ? undefined : feeForm.taxPercentage, (feeForm.includeQuantity ?? '') === '' ? 0 : 1, feeForm.quantityUnit, (feeForm.isRequired ?? '') === '' ? 0 : 1, feeForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
database.release(); database.release();
return result.lastInsertRowid; return result.lastInsertRowid;
} }

View File

@ -1,12 +1,12 @@
import { acquireConnection } from './pool.js' import { acquireConnection } from './pool.js'
export interface AddFeeForm { export interface AddFeeForm {
feeCategoryId: string feeCategoryId: string | number
feeName: string feeName: string
feeDescription: string feeDescription: string
feeAccount: string feeAccount: string
contractTypeId: string contractTypeId: string | number
burialSiteTypeId: string burialSiteTypeId: string | number
feeAmount?: string feeAmount?: string
feeFunction?: string feeFunction?: string
taxAmount?: string taxAmount?: string
@ -46,10 +46,10 @@ export default async function addFee(
feeForm.feeAccount, feeForm.feeAccount,
feeForm.contractTypeId === '' ? undefined : feeForm.contractTypeId, feeForm.contractTypeId === '' ? undefined : feeForm.contractTypeId,
feeForm.burialSiteTypeId === '' ? undefined : feeForm.burialSiteTypeId, feeForm.burialSiteTypeId === '' ? undefined : feeForm.burialSiteTypeId,
feeForm.feeAmount ?? undefined, feeForm.feeAmount === '' ? undefined : feeForm.feeAmount,
feeForm.feeFunction ?? undefined, feeForm.feeFunction ?? undefined,
feeForm.taxAmount ?? undefined, feeForm.taxAmount === '' ? undefined : feeForm.taxAmount,
feeForm.taxPercentage ?? undefined, feeForm.taxPercentage === '' ? undefined : feeForm.taxPercentage,
(feeForm.includeQuantity ?? '') === '' ? 0 : 1, (feeForm.includeQuantity ?? '') === '' ? 0 : 1,
feeForm.quantityUnit, feeForm.quantityUnit,
(feeForm.isRequired ?? '') === '' ? 0 : 1, (feeForm.isRequired ?? '') === '' ? 0 : 1,

View File

@ -1,5 +1,6 @@
export interface AddForm { export interface AddForm {
funeralHomeName: string; funeralHomeName: string;
funeralHomeKey: string;
funeralHomeAddress1: string; funeralHomeAddress1: string;
funeralHomeAddress2: string; funeralHomeAddress2: string;
funeralHomeCity: string; funeralHomeCity: string;

View File

@ -4,12 +4,12 @@ export default async function addFuneralHome(addForm, user) {
const rightNowMillis = Date.now(); const rightNowMillis = Date.now();
const result = database const result = database
.prepare(`insert into FuneralHomes ( .prepare(`insert into FuneralHomes (
funeralHomeName, funeralHomeAddress1, funeralHomeAddress2, funeralHomeName, funeralHomeKey, funeralHomeAddress1, funeralHomeAddress2,
funeralHomeCity, funeralHomeProvince, funeralHomePostalCode, funeralHomePhoneNumber, funeralHomeCity, funeralHomeProvince, funeralHomePostalCode, funeralHomePhoneNumber,
recordCreate_userName, recordCreate_timeMillis, recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis) recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
.run(addForm.funeralHomeName, addForm.funeralHomeAddress1, addForm.funeralHomeAddress2, addForm.funeralHomeCity, addForm.funeralHomeProvince, addForm.funeralHomePostalCode, addForm.funeralHomePhoneNumber, user.userName, rightNowMillis, user.userName, rightNowMillis); .run(addForm.funeralHomeName, addForm.funeralHomeKey, addForm.funeralHomeAddress1, addForm.funeralHomeAddress2, addForm.funeralHomeCity, addForm.funeralHomeProvince, addForm.funeralHomePostalCode, addForm.funeralHomePhoneNumber, user.userName, rightNowMillis, user.userName, rightNowMillis);
database.release(); database.release();
return result.lastInsertRowid; return result.lastInsertRowid;
} }

View File

@ -2,6 +2,7 @@ import { acquireConnection } from './pool.js'
export interface AddForm { export interface AddForm {
funeralHomeName: string funeralHomeName: string
funeralHomeKey: string
funeralHomeAddress1: string funeralHomeAddress1: string
funeralHomeAddress2: string funeralHomeAddress2: string
funeralHomeCity: string funeralHomeCity: string
@ -21,14 +22,15 @@ export default async function addFuneralHome(
const result = database const result = database
.prepare( .prepare(
`insert into FuneralHomes ( `insert into FuneralHomes (
funeralHomeName, funeralHomeAddress1, funeralHomeAddress2, funeralHomeName, funeralHomeKey, funeralHomeAddress1, funeralHomeAddress2,
funeralHomeCity, funeralHomeProvince, funeralHomePostalCode, funeralHomePhoneNumber, funeralHomeCity, funeralHomeProvince, funeralHomePostalCode, funeralHomePhoneNumber,
recordCreate_userName, recordCreate_timeMillis, recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis) recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
) )
.run( .run(
addForm.funeralHomeName, addForm.funeralHomeName,
addForm.funeralHomeKey,
addForm.funeralHomeAddress1, addForm.funeralHomeAddress1,
addForm.funeralHomeAddress2, addForm.funeralHomeAddress2,
addForm.funeralHomeCity, addForm.funeralHomeCity,

View File

@ -1,5 +1,6 @@
export interface AddForm { export interface AddForm {
intermentContainerType: string; intermentContainerType: string;
intermentContainerTypeKey?: string;
isCremationType?: string; isCremationType?: string;
orderNumber?: number; orderNumber?: number;
} }

View File

@ -5,11 +5,11 @@ export default async function addIntermentContainerType(addForm, user) {
const rightNowMillis = Date.now(); const rightNowMillis = Date.now();
const result = database const result = database
.prepare(`insert into IntermentContainerTypes ( .prepare(`insert into IntermentContainerTypes (
intermentContainerType, isCremationType, orderNumber, intermentContainerType, intermentContainerTypeKey, isCremationType, orderNumber,
recordCreate_userName, recordCreate_timeMillis, recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis) recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?)`) values (?, ?, ?, ?, ?, ?, ?, ?)`)
.run(addForm.intermentContainerType, addForm.isCremationType === undefined ? 0 : 1, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis); .run(addForm.intermentContainerType, addForm.intermentContainerTypeKey ?? '', addForm.isCremationType === undefined ? 0 : 1, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
database.release(); database.release();
clearCacheByTableName('IntermentContainerTypes'); clearCacheByTableName('IntermentContainerTypes');
return result.lastInsertRowid; return result.lastInsertRowid;

View File

@ -4,6 +4,7 @@ import { acquireConnection } from './pool.js'
export interface AddForm { export interface AddForm {
intermentContainerType: string intermentContainerType: string
intermentContainerTypeKey?: string
isCremationType?: string isCremationType?: string
orderNumber?: number orderNumber?: number
} }
@ -19,13 +20,14 @@ export default async function addIntermentContainerType(
const result = database const result = database
.prepare( .prepare(
`insert into IntermentContainerTypes ( `insert into IntermentContainerTypes (
intermentContainerType, isCremationType, orderNumber, intermentContainerType, intermentContainerTypeKey, isCremationType, orderNumber,
recordCreate_userName, recordCreate_timeMillis, recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis) recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?)` values (?, ?, ?, ?, ?, ?, ?, ?)`
) )
.run( .run(
addForm.intermentContainerType, addForm.intermentContainerType,
addForm.intermentContainerTypeKey ?? '',
addForm.isCremationType === undefined ? 0 : 1, addForm.isCremationType === undefined ? 0 : 1,
addForm.orderNumber ?? -1, addForm.orderNumber ?? -1,
user.userName, user.userName,

View File

@ -1,3 +1,3 @@
type RecordTable = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'CommittalTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; type RecordTable = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes';
export default function addRecord(recordTable: RecordTable, recordName: string, orderNumber: number | string, user: User): Promise<number>; export default function addRecord(recordTable: RecordTable, recordName: string, orderNumber: number | string, user: User): Promise<number>;
export {}; export {};

View File

@ -3,7 +3,6 @@ import { acquireConnection } from './pool.js';
const recordNameColumns = new Map(); const recordNameColumns = new Map();
recordNameColumns.set('BurialSiteStatuses', 'burialSiteStatus'); recordNameColumns.set('BurialSiteStatuses', 'burialSiteStatus');
recordNameColumns.set('BurialSiteTypes', 'burialSiteType'); recordNameColumns.set('BurialSiteTypes', 'burialSiteType');
recordNameColumns.set('CommittalTypes', 'committalType');
recordNameColumns.set('WorkOrderMilestoneTypes', 'workOrderMilestoneType'); recordNameColumns.set('WorkOrderMilestoneTypes', 'workOrderMilestoneType');
recordNameColumns.set('WorkOrderTypes', 'workOrderType'); recordNameColumns.set('WorkOrderTypes', 'workOrderType');
export default async function addRecord(recordTable, recordName, orderNumber, user) { export default async function addRecord(recordTable, recordName, orderNumber, user) {

View File

@ -5,14 +5,12 @@ import { acquireConnection } from './pool.js'
type RecordTable = type RecordTable =
| 'BurialSiteStatuses' | 'BurialSiteStatuses'
| 'BurialSiteTypes' | 'BurialSiteTypes'
| 'CommittalTypes'
| 'WorkOrderMilestoneTypes' | 'WorkOrderMilestoneTypes'
| 'WorkOrderTypes' | 'WorkOrderTypes'
const recordNameColumns = new Map<RecordTable, string>() const recordNameColumns = new Map<RecordTable, string>()
recordNameColumns.set('BurialSiteStatuses', 'burialSiteStatus') recordNameColumns.set('BurialSiteStatuses', 'burialSiteStatus')
recordNameColumns.set('BurialSiteTypes', 'burialSiteType') recordNameColumns.set('BurialSiteTypes', 'burialSiteType')
recordNameColumns.set('CommittalTypes', 'committalType')
recordNameColumns.set('WorkOrderMilestoneTypes', 'workOrderMilestoneType') recordNameColumns.set('WorkOrderMilestoneTypes', 'workOrderMilestoneType')
recordNameColumns.set('WorkOrderTypes', 'workOrderType') recordNameColumns.set('WorkOrderTypes', 'workOrderType')

View File

@ -1,6 +1,6 @@
import getBurialSiteComments from './getBurialSiteComments.js'; import getBurialSiteComments from './getBurialSiteComments.js';
import getBurialSiteInterments from './getContracts.js';
import getBurialSiteFields from './getBurialSiteFields.js'; import getBurialSiteFields from './getBurialSiteFields.js';
import getContracts from './getContracts.js';
import { acquireConnection } from './pool.js'; import { acquireConnection } from './pool.js';
const baseSQL = `select l.burialSiteId, const baseSQL = `select l.burialSiteId,
l.burialSiteTypeId, t.burialSiteType, l.burialSiteTypeId, t.burialSiteType,
@ -24,7 +24,7 @@ async function _getBurialSite(sql, burialSiteIdOrLotName) {
const database = await acquireConnection(); const database = await acquireConnection();
const burialSite = database.prepare(sql).get(burialSiteIdOrLotName); const burialSite = database.prepare(sql).get(burialSiteIdOrLotName);
if (burialSite !== undefined) { if (burialSite !== undefined) {
const contracts = await getBurialSiteInterments({ const contracts = await getContracts({
burialSiteId: burialSite.burialSiteId burialSiteId: burialSite.burialSiteId
}, { }, {
includeInterments: true, includeInterments: true,

View File

@ -1,8 +1,8 @@
import type { BurialSite } from '../types/recordTypes.js' import type { BurialSite } from '../types/recordTypes.js'
import getBurialSiteComments from './getBurialSiteComments.js' import getBurialSiteComments from './getBurialSiteComments.js'
import getBurialSiteInterments from './getContracts.js'
import getBurialSiteFields from './getBurialSiteFields.js' import getBurialSiteFields from './getBurialSiteFields.js'
import getContracts from './getContracts.js'
import { acquireConnection } from './pool.js' import { acquireConnection } from './pool.js'
const baseSQL = `select l.burialSiteId, const baseSQL = `select l.burialSiteId,
@ -33,7 +33,7 @@ async function _getBurialSite(
const burialSite = database.prepare(sql).get(burialSiteIdOrLotName) as BurialSite | undefined const burialSite = database.prepare(sql).get(burialSiteIdOrLotName) as BurialSite | undefined
if (burialSite !== undefined) { if (burialSite !== undefined) {
const contracts = await getBurialSiteInterments( const contracts = await getContracts(
{ {
burialSiteId: burialSite.burialSiteId burialSiteId: burialSite.burialSiteId
}, },

View File

@ -1,3 +1,4 @@
import type { PoolConnection } from 'better-sqlite-pool'; import type { PoolConnection } from 'better-sqlite-pool';
import type { Cemetery } from '../types/recordTypes.js'; import type { Cemetery } from '../types/recordTypes.js';
export default function getCemetery(cemeteryId: number | string, connectedDatabase?: PoolConnection): Promise<Cemetery | undefined>; export default function getCemetery(cemeteryId: number | string, connectedDatabase?: PoolConnection): Promise<Cemetery | undefined>;
export declare function getCemeteryByKey(cemeteryKey: string, connectedDatabase?: PoolConnection): Promise<Cemetery | undefined>;

View File

@ -1,5 +1,5 @@
import { acquireConnection } from './pool.js'; import { acquireConnection } from './pool.js';
export default async function getCemetery(cemeteryId, connectedDatabase) { async function _getCemetery(keyColumn, cemeteryIdOrKey, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection()); const database = connectedDatabase ?? (await acquireConnection());
const cemetery = database const cemetery = database
.prepare(`select m.cemeteryId, m.cemeteryName, m.cemeteryKey, m.cemeteryDescription, .prepare(`select m.cemeteryId, m.cemeteryName, m.cemeteryKey, m.cemeteryDescription,
@ -12,7 +12,7 @@ export default async function getCemetery(cemeteryId, connectedDatabase) {
count(l.burialSiteId) as burialSiteCount count(l.burialSiteId) as burialSiteCount
from Cemeteries m from Cemeteries m
left join BurialSites l on m.cemeteryId = l.cemeteryId and l.recordDelete_timeMillis is null left join BurialSites l on m.cemeteryId = l.cemeteryId and l.recordDelete_timeMillis is null
where m.cemeteryId = ? where m.${keyColumn} = ?
and m.recordDelete_timeMillis is null and m.recordDelete_timeMillis is null
group by m.cemeteryId, m.cemeteryName, m.cemeteryDescription, group by m.cemeteryId, m.cemeteryName, m.cemeteryDescription,
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
@ -21,9 +21,15 @@ export default async function getCemetery(cemeteryId, connectedDatabase) {
m.recordCreate_userName, m.recordCreate_timeMillis, m.recordCreate_userName, m.recordCreate_timeMillis,
m.recordUpdate_userName, m.recordUpdate_timeMillis, m.recordUpdate_userName, m.recordUpdate_timeMillis,
m.recordDelete_userName, m.recordDelete_timeMillis`) m.recordDelete_userName, m.recordDelete_timeMillis`)
.get(cemeteryId); .get(cemeteryIdOrKey);
if (connectedDatabase === undefined) { if (connectedDatabase === undefined) {
database.release(); database.release();
} }
return cemetery; return cemetery;
} }
export default async function getCemetery(cemeteryId, connectedDatabase) {
return await _getCemetery('cemeteryId', cemeteryId, connectedDatabase);
}
export async function getCemeteryByKey(cemeteryKey, connectedDatabase) {
return await _getCemetery('cemeteryKey', cemeteryKey, connectedDatabase);
}

View File

@ -4,8 +4,9 @@ import type { Cemetery } from '../types/recordTypes.js'
import { acquireConnection } from './pool.js' import { acquireConnection } from './pool.js'
export default async function getCemetery( async function _getCemetery(
cemeteryId: number | string, keyColumn: 'cemeteryId' | 'cemeteryKey',
cemeteryIdOrKey: number | string,
connectedDatabase?: PoolConnection connectedDatabase?: PoolConnection
): Promise<Cemetery | undefined> { ): Promise<Cemetery | undefined> {
const database = connectedDatabase ?? (await acquireConnection()) const database = connectedDatabase ?? (await acquireConnection())
@ -22,7 +23,7 @@ export default async function getCemetery(
count(l.burialSiteId) as burialSiteCount count(l.burialSiteId) as burialSiteCount
from Cemeteries m from Cemeteries m
left join BurialSites l on m.cemeteryId = l.cemeteryId and l.recordDelete_timeMillis is null left join BurialSites l on m.cemeteryId = l.cemeteryId and l.recordDelete_timeMillis is null
where m.cemeteryId = ? where m.${keyColumn} = ?
and m.recordDelete_timeMillis is null and m.recordDelete_timeMillis is null
group by m.cemeteryId, m.cemeteryName, m.cemeteryDescription, group by m.cemeteryId, m.cemeteryName, m.cemeteryDescription,
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
@ -32,7 +33,7 @@ export default async function getCemetery(
m.recordUpdate_userName, m.recordUpdate_timeMillis, m.recordUpdate_userName, m.recordUpdate_timeMillis,
m.recordDelete_userName, m.recordDelete_timeMillis` m.recordDelete_userName, m.recordDelete_timeMillis`
) )
.get(cemeteryId) as Cemetery | undefined .get(cemeteryIdOrKey) as Cemetery | undefined
if (connectedDatabase === undefined) { if (connectedDatabase === undefined) {
database.release() database.release()
@ -40,3 +41,17 @@ export default async function getCemetery(
return cemetery return cemetery
} }
export default async function getCemetery(
cemeteryId: number | string,
connectedDatabase?: PoolConnection
): Promise<Cemetery | undefined> {
return await _getCemetery('cemeteryId', cemeteryId, connectedDatabase)
}
export async function getCemeteryByKey(
cemeteryKey: string,
connectedDatabase?: PoolConnection
): Promise<Cemetery | undefined> {
return await _getCemetery('cemeteryKey', cemeteryKey, connectedDatabase)
}

View File

@ -3,7 +3,7 @@ import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
export default async function getCommittalTypes() { export default async function getCommittalTypes() {
const database = await acquireConnection(); const database = await acquireConnection();
const committalTypes = database const committalTypes = database
.prepare(`select committalTypeId, committalType, orderNumber .prepare(`select committalTypeId, committalTypeKey, committalType, orderNumber
from CommittalTypes from CommittalTypes
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
order by orderNumber, committalType, committalTypeId`) order by orderNumber, committalType, committalTypeId`)

View File

@ -8,7 +8,7 @@ export default async function getCommittalTypes(): Promise<CommittalType[]> {
const committalTypes = database const committalTypes = database
.prepare( .prepare(
`select committalTypeId, committalType, orderNumber `select committalTypeId, committalTypeKey, committalType, orderNumber
from CommittalTypes from CommittalTypes
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
order by orderNumber, committalType, committalTypeId` order by orderNumber, committalType, committalTypeId`

View File

@ -20,7 +20,7 @@ export default async function getContract(contractId, connectedDatabase) {
o.purchaserName, o.purchaserAddress1, o.purchaserAddress2, o.purchaserName, o.purchaserAddress1, o.purchaserAddress2,
o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode, o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode,
o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship, o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship,
o.funeralHomeId, o.funeralDirectorName, o.funeralHomeId, o.funeralDirectorName, f.funeralHomeKey,
f.funeralHomeName, f.funeralHomeAddress1, f.funeralHomeAddress2, f.funeralHomeName, f.funeralHomeAddress1, f.funeralHomeAddress2,
f.funeralHomeCity, f.funeralHomeProvince, f.funeralHomePostalCode, f.funeralHomeCity, f.funeralHomeProvince, f.funeralHomePostalCode,
o.funeralDate, userFn_dateIntegerToString(o.funeralDate) as funeralDateString, o.funeralDate, userFn_dateIntegerToString(o.funeralDate) as funeralDateString,

View File

@ -31,7 +31,7 @@ export default async function getContract(
o.purchaserName, o.purchaserAddress1, o.purchaserAddress2, o.purchaserName, o.purchaserAddress1, o.purchaserAddress2,
o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode, o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode,
o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship, o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship,
o.funeralHomeId, o.funeralDirectorName, o.funeralHomeId, o.funeralDirectorName, f.funeralHomeKey,
f.funeralHomeName, f.funeralHomeAddress1, f.funeralHomeAddress2, f.funeralHomeName, f.funeralHomeAddress1, f.funeralHomeAddress2,
f.funeralHomeCity, f.funeralHomeProvince, f.funeralHomePostalCode, f.funeralHomeCity, f.funeralHomeProvince, f.funeralHomePostalCode,
o.funeralDate, userFn_dateIntegerToString(o.funeralDate) as funeralDateString, o.funeralDate, userFn_dateIntegerToString(o.funeralDate) as funeralDateString,

View File

@ -12,6 +12,7 @@ export default async function getContractInterments(contractId, connectedDatabas
o.birthPlace, o.birthPlace,
o.deathDate, userFn_dateIntegerToString(o.deathDate) as deathDateString, o.deathDate, userFn_dateIntegerToString(o.deathDate) as deathDateString,
o.deathPlace, o.deathPlace,
o.deathAge, o.deathAgePeriod,
o.intermentContainerTypeId, t.intermentContainerType, t.isCremationType o.intermentContainerTypeId, t.intermentContainerType, t.isCremationType

View File

@ -25,6 +25,7 @@ export default async function getContractInterments(
o.birthPlace, o.birthPlace,
o.deathDate, userFn_dateIntegerToString(o.deathDate) as deathDateString, o.deathDate, userFn_dateIntegerToString(o.deathDate) as deathDateString,
o.deathPlace, o.deathPlace,
o.deathAge, o.deathAgePeriod,
o.intermentContainerTypeId, t.intermentContainerType, t.isCremationType o.intermentContainerTypeId, t.intermentContainerType, t.isCremationType

View File

@ -1,2 +1,3 @@
import type { FuneralHome } from '../types/recordTypes.js'; import type { FuneralHome } from '../types/recordTypes.js';
export default function getFuneralHome(funeralHomeId: number | string): Promise<FuneralHome | undefined>; export default function getFuneralHome(funeralHomeId: number | string): Promise<FuneralHome | undefined>;
export declare function getFuneralHomeByKey(funeralHomeKey: string): Promise<FuneralHome | undefined>;

View File

@ -1,15 +1,21 @@
import { acquireConnection } from './pool.js'; import { acquireConnection } from './pool.js';
export default async function getFuneralHome(funeralHomeId) { async function _getFuneralHome(keyColumn, funeralHomeIdOrKey) {
const database = await acquireConnection(); const database = await acquireConnection();
const funeralHome = database const funeralHome = database
.prepare(`select funeralHomeId, funeralHomeName, .prepare(`select funeralHomeId, funeralHomeKey, funeralHomeName,
funeralHomeAddress1, funeralHomeAddress2, funeralHomeAddress1, funeralHomeAddress2,
funeralHomeCity, funeralHomeProvince, funeralHomePostalCode, funeralHomePhoneNumber funeralHomeCity, funeralHomeProvince, funeralHomePostalCode, funeralHomePhoneNumber
from FuneralHomes f from FuneralHomes f
where f.recordDelete_timeMillis is null where f.recordDelete_timeMillis is null
and f.funeralHomeId = ? and f.${keyColumn} = ?
order by f.funeralHomeName, f.funeralHomeId`) order by f.funeralHomeName, f.funeralHomeId`)
.get(funeralHomeId); .get(funeralHomeIdOrKey);
database.release(); database.release();
return funeralHome; return funeralHome;
} }
export default async function getFuneralHome(funeralHomeId) {
return await _getFuneralHome('funeralHomeId', funeralHomeId);
}
export async function getFuneralHomeByKey(funeralHomeKey) {
return await _getFuneralHome('funeralHomeKey', funeralHomeKey);
}

View File

@ -2,24 +2,37 @@ import type { Cemetery, FuneralHome } from '../types/recordTypes.js'
import { acquireConnection } from './pool.js' import { acquireConnection } from './pool.js'
export default async function getFuneralHome( async function _getFuneralHome(
funeralHomeId: number | string keyColumn: 'funeralHomeId' | 'funeralHomeKey',
funeralHomeIdOrKey: number | string
): Promise<FuneralHome | undefined> { ): Promise<FuneralHome | undefined> {
const database = await acquireConnection() const database = await acquireConnection()
const funeralHome = database const funeralHome = database
.prepare( .prepare(
`select funeralHomeId, funeralHomeName, `select funeralHomeId, funeralHomeKey, funeralHomeName,
funeralHomeAddress1, funeralHomeAddress2, funeralHomeAddress1, funeralHomeAddress2,
funeralHomeCity, funeralHomeProvince, funeralHomePostalCode, funeralHomePhoneNumber funeralHomeCity, funeralHomeProvince, funeralHomePostalCode, funeralHomePhoneNumber
from FuneralHomes f from FuneralHomes f
where f.recordDelete_timeMillis is null where f.recordDelete_timeMillis is null
and f.funeralHomeId = ? and f.${keyColumn} = ?
order by f.funeralHomeName, f.funeralHomeId` order by f.funeralHomeName, f.funeralHomeId`
) )
.get(funeralHomeId) as Cemetery | undefined .get(funeralHomeIdOrKey) as Cemetery | undefined
database.release() database.release()
return funeralHome return funeralHome
} }
export default async function getFuneralHome(
funeralHomeId: number | string
): Promise<FuneralHome | undefined> {
return await _getFuneralHome('funeralHomeId', funeralHomeId)
}
export async function getFuneralHomeByKey(
funeralHomeKey: string
): Promise<FuneralHome | undefined> {
return await _getFuneralHome('funeralHomeKey', funeralHomeKey)
}

View File

@ -2,7 +2,7 @@ import { acquireConnection } from './pool.js';
export default async function getFuneralHomes() { export default async function getFuneralHomes() {
const database = await acquireConnection(); const database = await acquireConnection();
const funeralHomes = database const funeralHomes = database
.prepare(`select funeralHomeId, funeralHomeName, .prepare(`select funeralHomeId, funeralHomeKey, funeralHomeName,
funeralHomeAddress1, funeralHomeAddress2, funeralHomeAddress1, funeralHomeAddress2,
funeralHomeCity, funeralHomeProvince, funeralHomePostalCode, funeralHomePhoneNumber funeralHomeCity, funeralHomeProvince, funeralHomePostalCode, funeralHomePhoneNumber
from FuneralHomes f from FuneralHomes f

View File

@ -7,7 +7,7 @@ export default async function getFuneralHomes(): Promise<FuneralHome[]> {
const funeralHomes = database const funeralHomes = database
.prepare( .prepare(
`select funeralHomeId, funeralHomeName, `select funeralHomeId, funeralHomeKey, funeralHomeName,
funeralHomeAddress1, funeralHomeAddress2, funeralHomeAddress1, funeralHomeAddress2,
funeralHomeCity, funeralHomeProvince, funeralHomePostalCode, funeralHomePhoneNumber funeralHomeCity, funeralHomeProvince, funeralHomePostalCode, funeralHomePhoneNumber
from FuneralHomes f from FuneralHomes f

View File

@ -3,7 +3,7 @@ import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
export default async function getIntermentContainerTypes() { export default async function getIntermentContainerTypes() {
const database = await acquireConnection(); const database = await acquireConnection();
const containerTypes = database const containerTypes = database
.prepare(`select intermentContainerTypeId, intermentContainerType, isCremationType, orderNumber .prepare(`select intermentContainerTypeId, intermentContainerType, intermentContainerTypeKey, isCremationType, orderNumber
from IntermentContainerTypes from IntermentContainerTypes
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
order by isCremationType, orderNumber, intermentContainerType, intermentContainerTypeId`) order by isCremationType, orderNumber, intermentContainerType, intermentContainerTypeId`)

View File

@ -10,7 +10,7 @@ export default async function getIntermentContainerTypes(): Promise<
const containerTypes = database const containerTypes = database
.prepare( .prepare(
`select intermentContainerTypeId, intermentContainerType, isCremationType, orderNumber `select intermentContainerTypeId, intermentContainerType, intermentContainerTypeKey, isCremationType, orderNumber
from IntermentContainerTypes from IntermentContainerTypes
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
order by isCremationType, orderNumber, intermentContainerType, intermentContainerTypeId` order by isCremationType, orderNumber, intermentContainerType, intermentContainerTypeId`

View File

@ -4,6 +4,7 @@ import sqlite from 'better-sqlite3';
import Debug from 'debug'; import Debug from 'debug';
import { DEBUG_NAMESPACE } from '../debug.config.js'; import { DEBUG_NAMESPACE } from '../debug.config.js';
import { sunriseDB as databasePath } from '../helpers/database.helpers.js'; import { sunriseDB as databasePath } from '../helpers/database.helpers.js';
import addCommittalType from './addCommittalType.js';
import addContractType from './addContractType.js'; import addContractType from './addContractType.js';
import addFeeCategory from './addFeeCategory.js'; import addFeeCategory from './addFeeCategory.js';
import addIntermentContainerType from './addIntermentContainerType.js'; import addIntermentContainerType from './addIntermentContainerType.js';
@ -121,6 +122,7 @@ const createStatements = [
`create table if not exists FuneralHomes ( `create table if not exists FuneralHomes (
funeralHomeId integer not null primary key autoincrement, funeralHomeId integer not null primary key autoincrement,
funeralHomeName varchar(200) not null, funeralHomeName varchar(200) not null,
funeralHomeKey varchar(20) not null default '',
funeralHomeAddress1 varchar(50), funeralHomeAddress1 varchar(50),
funeralHomeAddress2 varchar(50), funeralHomeAddress2 varchar(50),
funeralHomeCity varchar(20), funeralHomeCity varchar(20),
@ -165,6 +167,7 @@ const createStatements = [
on ContractTypePrints (contractTypeId, orderNumber, printEJS)`, on ContractTypePrints (contractTypeId, orderNumber, printEJS)`,
`create table if not exists CommittalTypes ( `create table if not exists CommittalTypes (
committalTypeId integer not null primary key autoincrement, committalTypeId integer not null primary key autoincrement,
committalTypeKey varchar(20) not null default '',
committalType varchar(100) not null, committalType varchar(100) not null,
orderNumber smallint not null default 0, orderNumber smallint not null default 0,
${recordColumns})`, ${recordColumns})`,
@ -222,6 +225,7 @@ const createStatements = [
`create table if not exists IntermentContainerTypes ( `create table if not exists IntermentContainerTypes (
intermentContainerTypeId integer not null primary key autoincrement, intermentContainerTypeId integer not null primary key autoincrement,
intermentContainerType varchar(100) not null, intermentContainerType varchar(100) not null,
intermentContainerTypeKey varchar(20) not null default '',
isCremationType bit not null default 0, isCremationType bit not null default 0,
orderNumber smallint not null default 0, orderNumber smallint not null default 0,
${recordColumns})`, ${recordColumns})`,
@ -245,6 +249,8 @@ const createStatements = [
deathDate integer, deathDate integer,
deathPlace varchar(100), deathPlace varchar(100),
deathAge integer,
deathAgePeriod varchar(10),
intermentContainerTypeId integer, intermentContainerTypeId integer,
@ -393,7 +399,7 @@ export async function initializeDatabase() {
return true; return true;
} }
async function initializeData() { async function initializeData() {
debug("Initializing data..."); debug('Initializing data...');
await addRecord('BurialSiteTypes', 'Casket Grave', 1, initializingUser); await addRecord('BurialSiteTypes', 'Casket Grave', 1, initializingUser);
await addRecord('BurialSiteTypes', 'Columbarium', 2, initializingUser); await addRecord('BurialSiteTypes', 'Columbarium', 2, initializingUser);
await addRecord('BurialSiteTypes', 'Mausoleum', 2, initializingUser); await addRecord('BurialSiteTypes', 'Mausoleum', 2, initializingUser);
@ -420,31 +426,54 @@ async function initializeData() {
// Interment Container Types // Interment Container Types
await addIntermentContainerType({ await addIntermentContainerType({
intermentContainerType: 'No Shell', intermentContainerType: 'No Shell',
intermentContainerTypeKey: 'NS',
orderNumber: 1 orderNumber: 1
}, initializingUser); }, initializingUser);
await addIntermentContainerType({ await addIntermentContainerType({
intermentContainerType: 'Concrete Liner', intermentContainerType: 'Concrete Liner',
intermentContainerTypeKey: 'CL',
orderNumber: 2 orderNumber: 2
}, initializingUser); }, initializingUser);
await addIntermentContainerType({ await addIntermentContainerType({
intermentContainerType: 'Unpainted Vault', intermentContainerType: 'Unpainted Vault',
intermentContainerTypeKey: 'UV',
orderNumber: 3 orderNumber: 3
}, initializingUser); }, initializingUser);
await addIntermentContainerType({ await addIntermentContainerType({
intermentContainerType: 'Concrete Vault', intermentContainerType: 'Concrete Vault',
intermentContainerTypeKey: 'CV',
orderNumber: 4 orderNumber: 4
}, initializingUser); }, initializingUser);
await addIntermentContainerType({ intermentContainerType: 'Wooden Shell', orderNumber: 5 }, initializingUser); await addIntermentContainerType({
await addIntermentContainerType({ intermentContainerType: 'Steel Vault', orderNumber: 6 }, initializingUser); intermentContainerType: 'Wooden Shell',
intermentContainerTypeKey: 'WS',
orderNumber: 5
}, initializingUser);
await addIntermentContainerType({ intermentContainerType: 'Steel Vault',
intermentContainerTypeKey: 'SV',
orderNumber: 6 }, initializingUser);
await addIntermentContainerType({ await addIntermentContainerType({
intermentContainerType: 'Urn', intermentContainerType: 'Urn',
intermentContainerTypeKey: 'U',
isCremationType: '1', isCremationType: '1',
orderNumber: 7 orderNumber: 7
}, initializingUser); }, initializingUser);
// Committal Types // Committal Types
await addRecord('CommittalTypes', 'Graveside', 1, initializingUser); await addCommittalType({
await addRecord('CommittalTypes', 'Chapel', 2, initializingUser); committalType: 'Graveside',
await addRecord('CommittalTypes', 'Church', 3, initializingUser); committalTypeKey: 'GS',
orderNumber: 1
}, initializingUser);
await addCommittalType({
committalType: 'Chapel',
committalTypeKey: 'CS',
orderNumber: 2
}, initializingUser);
await addCommittalType({
committalType: 'Church',
committalTypeKey: 'CH',
orderNumber: 3
}, initializingUser);
/* /*
* Fee Categories * Fee Categories
*/ */

View File

@ -7,6 +7,7 @@ import Debug from 'debug'
import { DEBUG_NAMESPACE } from '../debug.config.js' import { DEBUG_NAMESPACE } from '../debug.config.js'
import { sunriseDB as databasePath } from '../helpers/database.helpers.js' import { sunriseDB as databasePath } from '../helpers/database.helpers.js'
import addCommittalType from './addCommittalType.js'
import addContractType from './addContractType.js' import addContractType from './addContractType.js'
import addFeeCategory from './addFeeCategory.js' import addFeeCategory from './addFeeCategory.js'
import addIntermentContainerType from './addIntermentContainerType.js' import addIntermentContainerType from './addIntermentContainerType.js'
@ -143,6 +144,7 @@ const createStatements = [
`create table if not exists FuneralHomes ( `create table if not exists FuneralHomes (
funeralHomeId integer not null primary key autoincrement, funeralHomeId integer not null primary key autoincrement,
funeralHomeName varchar(200) not null, funeralHomeName varchar(200) not null,
funeralHomeKey varchar(20) not null default '',
funeralHomeAddress1 varchar(50), funeralHomeAddress1 varchar(50),
funeralHomeAddress2 varchar(50), funeralHomeAddress2 varchar(50),
funeralHomeCity varchar(20), funeralHomeCity varchar(20),
@ -195,6 +197,7 @@ const createStatements = [
`create table if not exists CommittalTypes ( `create table if not exists CommittalTypes (
committalTypeId integer not null primary key autoincrement, committalTypeId integer not null primary key autoincrement,
committalTypeKey varchar(20) not null default '',
committalType varchar(100) not null, committalType varchar(100) not null,
orderNumber smallint not null default 0, orderNumber smallint not null default 0,
${recordColumns})`, ${recordColumns})`,
@ -259,6 +262,7 @@ const createStatements = [
`create table if not exists IntermentContainerTypes ( `create table if not exists IntermentContainerTypes (
intermentContainerTypeId integer not null primary key autoincrement, intermentContainerTypeId integer not null primary key autoincrement,
intermentContainerType varchar(100) not null, intermentContainerType varchar(100) not null,
intermentContainerTypeKey varchar(20) not null default '',
isCremationType bit not null default 0, isCremationType bit not null default 0,
orderNumber smallint not null default 0, orderNumber smallint not null default 0,
${recordColumns})`, ${recordColumns})`,
@ -284,6 +288,8 @@ const createStatements = [
deathDate integer, deathDate integer,
deathPlace varchar(100), deathPlace varchar(100),
deathAge integer,
deathAgePeriod varchar(10),
intermentContainerTypeId integer, intermentContainerTypeId integer,
@ -461,7 +467,7 @@ export async function initializeDatabase(): Promise<boolean> {
} }
async function initializeData(): Promise<void> { async function initializeData(): Promise<void> {
debug("Initializing data...") debug('Initializing data...')
await addRecord('BurialSiteTypes', 'Casket Grave', 1, initializingUser) await addRecord('BurialSiteTypes', 'Casket Grave', 1, initializingUser)
await addRecord('BurialSiteTypes', 'Columbarium', 2, initializingUser) await addRecord('BurialSiteTypes', 'Columbarium', 2, initializingUser)
@ -506,6 +512,7 @@ async function initializeData(): Promise<void> {
await addIntermentContainerType( await addIntermentContainerType(
{ {
intermentContainerType: 'No Shell', intermentContainerType: 'No Shell',
intermentContainerTypeKey: 'NS',
orderNumber: 1 orderNumber: 1
}, },
initializingUser initializingUser
@ -514,6 +521,7 @@ async function initializeData(): Promise<void> {
await addIntermentContainerType( await addIntermentContainerType(
{ {
intermentContainerType: 'Concrete Liner', intermentContainerType: 'Concrete Liner',
intermentContainerTypeKey: 'CL',
orderNumber: 2 orderNumber: 2
}, },
initializingUser initializingUser
@ -522,6 +530,7 @@ async function initializeData(): Promise<void> {
await addIntermentContainerType( await addIntermentContainerType(
{ {
intermentContainerType: 'Unpainted Vault', intermentContainerType: 'Unpainted Vault',
intermentContainerTypeKey: 'UV',
orderNumber: 3 orderNumber: 3
}, },
initializingUser initializingUser
@ -530,24 +539,32 @@ async function initializeData(): Promise<void> {
await addIntermentContainerType( await addIntermentContainerType(
{ {
intermentContainerType: 'Concrete Vault', intermentContainerType: 'Concrete Vault',
intermentContainerTypeKey: 'CV',
orderNumber: 4 orderNumber: 4
}, },
initializingUser initializingUser
) )
await addIntermentContainerType( await addIntermentContainerType(
{ intermentContainerType: 'Wooden Shell', orderNumber: 5 }, {
intermentContainerType: 'Wooden Shell',
intermentContainerTypeKey: 'WS',
orderNumber: 5
},
initializingUser initializingUser
) )
await addIntermentContainerType( await addIntermentContainerType(
{ intermentContainerType: 'Steel Vault', orderNumber: 6 }, { intermentContainerType: 'Steel Vault',
intermentContainerTypeKey: 'SV',
orderNumber: 6 },
initializingUser initializingUser
) )
await addIntermentContainerType( await addIntermentContainerType(
{ {
intermentContainerType: 'Urn', intermentContainerType: 'Urn',
intermentContainerTypeKey: 'U',
isCremationType: '1', isCremationType: '1',
orderNumber: 7 orderNumber: 7
}, },
@ -556,9 +573,23 @@ async function initializeData(): Promise<void> {
// Committal Types // Committal Types
await addRecord('CommittalTypes', 'Graveside', 1, initializingUser) await addCommittalType({
await addRecord('CommittalTypes', 'Chapel', 2, initializingUser) committalType: 'Graveside',
await addRecord('CommittalTypes', 'Church', 3, initializingUser) committalTypeKey: 'GS',
orderNumber: 1
}, initializingUser)
await addCommittalType({
committalType: 'Chapel',
committalTypeKey: 'CS',
orderNumber: 2
}, initializingUser)
await addCommittalType({
committalType: 'Church',
committalTypeKey: 'CH',
orderNumber: 3
}, initializingUser)
/* /*
* Fee Categories * Fee Categories

View File

@ -12,6 +12,8 @@ export interface UpdateForm {
birthPlace: string; birthPlace: string;
deathDateString: DateString | ''; deathDateString: DateString | '';
deathPlace: string; deathPlace: string;
deathAge: string;
deathAgePeriod: string;
intermentContainerTypeId: string | number; intermentContainerTypeId: string | number;
} }
export default function updateContractInterment(contractForm: UpdateForm, user: User): Promise<boolean>; export default function updateContractInterment(contractForm: UpdateForm, user: User): Promise<boolean>;

View File

@ -14,6 +14,8 @@ export default async function updateContractInterment(contractForm, user) {
birthPlace = ?, birthPlace = ?,
deathDate = ?, deathDate = ?,
deathPlace = ?, deathPlace = ?,
deathAge = ?,
deathAgePeriod = ?,
intermentContainerTypeId = ?, intermentContainerTypeId = ?,
recordUpdate_userName = ?, recordUpdate_userName = ?,
recordUpdate_timeMillis = ? recordUpdate_timeMillis = ?
@ -24,7 +26,7 @@ export default async function updateContractInterment(contractForm, user) {
? undefined ? undefined
: dateStringToInteger(contractForm.birthDateString), contractForm.birthPlace, contractForm.deathDateString === '' : dateStringToInteger(contractForm.birthDateString), contractForm.birthPlace, contractForm.deathDateString === ''
? undefined ? undefined
: dateStringToInteger(contractForm.deathDateString), contractForm.deathPlace, contractForm.intermentContainerTypeId === '' : dateStringToInteger(contractForm.deathDateString), contractForm.deathPlace, contractForm.deathAge, contractForm.deathAgePeriod, contractForm.intermentContainerTypeId === ''
? undefined ? undefined
: contractForm.intermentContainerTypeId, user.userName, Date.now(), contractForm.contractId, contractForm.intermentNumber); : contractForm.intermentContainerTypeId, user.userName, Date.now(), contractForm.contractId, contractForm.intermentNumber);
database.release(); database.release();

View File

@ -15,6 +15,8 @@ export interface UpdateForm {
birthPlace: string birthPlace: string
deathDateString: DateString | '' deathDateString: DateString | ''
deathPlace: string deathPlace: string
deathAge: string
deathAgePeriod: string
intermentContainerTypeId: string | number intermentContainerTypeId: string | number
} }
@ -37,6 +39,8 @@ export default async function updateContractInterment(
birthPlace = ?, birthPlace = ?,
deathDate = ?, deathDate = ?,
deathPlace = ?, deathPlace = ?,
deathAge = ?,
deathAgePeriod = ?,
intermentContainerTypeId = ?, intermentContainerTypeId = ?,
recordUpdate_userName = ?, recordUpdate_userName = ?,
recordUpdate_timeMillis = ? recordUpdate_timeMillis = ?
@ -59,6 +63,8 @@ export default async function updateContractInterment(
? undefined ? undefined
: dateStringToInteger(contractForm.deathDateString), : dateStringToInteger(contractForm.deathDateString),
contractForm.deathPlace, contractForm.deathPlace,
contractForm.deathAge,
contractForm.deathAgePeriod,
contractForm.intermentContainerTypeId === '' contractForm.intermentContainerTypeId === ''
? undefined ? undefined
: contractForm.intermentContainerTypeId, : contractForm.intermentContainerTypeId,

View File

@ -22,7 +22,7 @@ export default async function updateFee(feeForm, user) {
and feeId = ?`) and feeId = ?`)
.run(feeForm.feeCategoryId, feeForm.feeName, feeForm.feeDescription, feeForm.feeAccount, feeForm.contractTypeId === '' ? undefined : feeForm.contractTypeId, feeForm.burialSiteTypeId === '' ? undefined : feeForm.burialSiteTypeId, feeForm.feeAmount === undefined || feeForm.feeAmount === '' .run(feeForm.feeCategoryId, feeForm.feeName, feeForm.feeDescription, feeForm.feeAccount, feeForm.contractTypeId === '' ? undefined : feeForm.contractTypeId, feeForm.burialSiteTypeId === '' ? undefined : feeForm.burialSiteTypeId, feeForm.feeAmount === undefined || feeForm.feeAmount === ''
? 0 ? 0
: feeForm.feeAmount, feeForm.feeFunction ?? undefined, feeForm.taxAmount ?? undefined, feeForm.taxPercentage ?? undefined, feeForm.includeQuantity === '' ? 0 : 1, feeForm.quantityUnit, feeForm.isRequired === '' ? 0 : 1, user.userName, Date.now(), feeForm.feeId); : feeForm.feeAmount, feeForm.feeFunction ?? undefined, feeForm.taxAmount === '' ? undefined : feeForm.taxAmount, feeForm.taxPercentage === '' ? undefined : feeForm.taxPercentage, feeForm.includeQuantity === '' ? 0 : 1, feeForm.quantityUnit, feeForm.isRequired === '' ? 0 : 1, user.userName, Date.now(), feeForm.feeId);
database.release(); database.release();
return result.changes > 0; return result.changes > 0;
} }

View File

@ -55,8 +55,8 @@ export default async function updateFee(
? 0 ? 0
: feeForm.feeAmount, : feeForm.feeAmount,
feeForm.feeFunction ?? undefined, feeForm.feeFunction ?? undefined,
feeForm.taxAmount ?? undefined, feeForm.taxAmount === '' ? undefined : feeForm.taxAmount,
feeForm.taxPercentage ?? undefined, feeForm.taxPercentage === '' ? undefined : feeForm.taxPercentage,
feeForm.includeQuantity === '' ? 0 : 1, feeForm.includeQuantity === '' ? 0 : 1,
feeForm.quantityUnit, feeForm.quantityUnit,
feeForm.isRequired === '' ? 0 : 1, feeForm.isRequired === '' ? 0 : 1,

View File

@ -243,7 +243,9 @@ export function clearCacheByTableName(tableName, relayMessage = true) {
} }
} }
} }
catch { } catch {
// ignore
}
} }
process.on('message', (message) => { process.on('message', (message) => {
if (message.messageType === 'clearCache' && message.pid !== process.pid) { if (message.messageType === 'clearCache' && message.pid !== process.pid) {

View File

@ -418,7 +418,9 @@ export function clearCacheByTableName(
process.send(workerMessage) process.send(workerMessage)
} }
} }
} catch {} } catch {
// ignore
}
} }
process.on('message', (message: WorkerMessage) => { process.on('message', (message: WorkerMessage) => {

View File

@ -18,8 +18,7 @@
"test": "cross-env NODE_ENV=dev DEBUG=sunrise:* TEST_DATABASES=true mocha --timeout 30000 --exit", "test": "cross-env NODE_ENV=dev DEBUG=sunrise:* TEST_DATABASES=true mocha --timeout 30000 --exit",
"test:startup": "cross-env NODE_ENV=dev DEBUG=sunrise:* TEST_DATABASES=true STARTUP_TEST=true node ./bin/www.js", "test:startup": "cross-env NODE_ENV=dev DEBUG=sunrise:* TEST_DATABASES=true STARTUP_TEST=true node ./bin/www.js",
"coverage": "cross-env NODE_ENV=dev DEBUG=sunrise:* TEST_DATABASES=true c8 --reporter=lcov --reporter=text --reporter=text-summary mocha --timeout 30000 --exit", "coverage": "cross-env NODE_ENV=dev DEBUG=sunrise:* TEST_DATABASES=true c8 --reporter=lcov --reporter=text --reporter=text-summary mocha --timeout 30000 --exit",
"temp:legacy:importFromCsv": "cross-env NODE_ENV=dev DEBUG=sunrise:* TEST_DATABASES=true node ./temp/legacy.importFromCsv.js", "temp:legacyImportFromCsv": "cross-env NODE_ENV=dev DEBUG=sunrise:* TEST_DATABASES=true node ./temp/legacyImportFromCsv/index.js"
"temp:so:exportMaps": "node ./temp/so.exportMaps.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -174,6 +174,18 @@
</div> </div>
</div> </div>
</div> </div>
<label class="label" for="contractIntermentAdd--deathAge">Death Age</label>
<div class="field has-addons">
<div class="control is-expanded">
<input class="input has-text-right" id="contractIntermentAdd--deathAge" name="deathAge" type="number" min="0" max="150" />
</div>
<div class="control is-expanded">
<div class="select is-fullwidth">
<select id="contractIntermentAdd--deathAgePeriod" name="deathAgePeriod" aria-label="Death Age Period">
</select>
</div>
</div>
</div>
<div class="field"> <div class="field">
<label class="label" for="contractIntermentAdd--intermentContainerTypeId">Container</label> <label class="label" for="contractIntermentAdd--intermentContainerTypeId">Container</label>
<div class="control"> <div class="control">

View File

@ -181,6 +181,18 @@
</div> </div>
</div> </div>
</div> </div>
<label class="label" for="contractIntermentEdit--deathAge">Death Age</label>
<div class="field has-addons">
<div class="control is-expanded">
<input class="input has-text-right" id="contractIntermentEdit--deathAge" name="deathAge" type="number" min="0" max="150" />
</div>
<div class="control is-expanded">
<div class="select is-fullwidth">
<select id="contractIntermentEdit--deathAgePeriod" name="deathAgePeriod" aria-label="Death Age Period">
</select>
</div>
</div>
</div>
<div class="field"> <div class="field">
<label class="label" for="contractIntermentEdit--intermentContainerTypeId">Container</label> <label class="label" for="contractIntermentEdit--intermentContainerTypeId">Container</label>
<div class="control"> <div class="control">

View File

@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
const contractId = document.querySelector('#contract--contractId').value; const contractId = document.querySelector('#contract--contractId').value;
let contractInterments = exports.contractInterments; let contractInterments = exports.contractInterments;
delete exports.contractInterments; delete exports.contractInterments;
const deathAgePeriods = exports.deathAgePeriods;
delete exports.deathAgePeriods;
const intermentContainerTypes = exports.intermentContainerTypes; const intermentContainerTypes = exports.intermentContainerTypes;
delete exports.intermentContainerTypes; delete exports.intermentContainerTypes;
function openEditContractInterment(clickEvent) { function openEditContractInterment(clickEvent) {
@ -66,6 +68,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
modalElement modalElement
.querySelector('#contractIntermentEdit--deathPlace') .querySelector('#contractIntermentEdit--deathPlace')
?.setAttribute('value', contractInterment.deathPlace ?? ''); ?.setAttribute('value', contractInterment.deathPlace ?? '');
modalElement
.querySelector('#contractIntermentEdit--deathAge')
?.setAttribute('value', contractInterment.deathAge?.toString() ?? '');
const deathAgePeriodElement = modalElement.querySelector('#contractIntermentEdit--deathAgePeriod');
let deathAgePeriodIsFound = false;
for (const deathAgePeriod of deathAgePeriods) {
const optionElement = document.createElement('option');
optionElement.value = deathAgePeriod;
optionElement.text = deathAgePeriod;
if (deathAgePeriod === contractInterment.deathAgePeriod) {
optionElement.selected = true;
deathAgePeriodIsFound = true;
}
deathAgePeriodElement.append(optionElement);
}
if (!deathAgePeriodIsFound) {
const optionElement = document.createElement('option');
optionElement.value = contractInterment.deathAgePeriod ?? '';
optionElement.text = contractInterment.deathAgePeriod ?? '(Not Set)';
optionElement.selected = true;
deathAgePeriodElement.append(optionElement);
}
const containerTypeElement = modalElement.querySelector('#contractIntermentEdit--intermentContainerTypeId'); const containerTypeElement = modalElement.querySelector('#contractIntermentEdit--intermentContainerTypeId');
let containerTypeIsFound = false; let containerTypeIsFound = false;
for (const containerType of intermentContainerTypes) { for (const containerType of intermentContainerTypes) {
@ -131,6 +155,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
} }
}); });
} }
// eslint-disable-next-line complexity
function renderContractInterments() { function renderContractInterments() {
const containerElement = document.querySelector('#container--contractInterments'); const containerElement = document.querySelector('#container--contractInterments');
if (contractInterments.length === 0) { if (contractInterments.length === 0) {
@ -180,6 +205,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
${cityssm.escapeHTML(interment.deathPlace ?? '(No Death Place)')} ${cityssm.escapeHTML(interment.deathPlace ?? '(No Death Place)')}
</div> </div>
</div> </div>
<div class="columns">
<div class="column">
<strong>Age:</strong>
</div>
<div class="column">
${cityssm.escapeHTML(interment.deathAge === undefined ? '(No Age)' : interment.deathAge.toString())}
${cityssm.escapeHTML(interment.deathAgePeriod ?? '')}
</div>
</div>
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<strong>Container:</strong> <strong>Container:</strong>
@ -229,6 +263,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
modalElement modalElement
.querySelector('#contractIntermentAdd--contractId') .querySelector('#contractIntermentAdd--contractId')
?.setAttribute('value', contractId); ?.setAttribute('value', contractId);
const deathAgePeriodElement = modalElement.querySelector('#contractIntermentAdd--deathAgePeriod');
for (const deathAgePeriod of deathAgePeriods) {
const optionElement = document.createElement('option');
optionElement.value = deathAgePeriod;
optionElement.text = deathAgePeriod;
deathAgePeriodElement.append(optionElement);
}
const containerTypeElement = modalElement.querySelector('#contractIntermentAdd--intermentContainerTypeId'); const containerTypeElement = modalElement.querySelector('#contractIntermentAdd--intermentContainerTypeId');
for (const containerType of intermentContainerTypes) { for (const containerType of intermentContainerTypes) {
const optionElement = document.createElement('option'); const optionElement = document.createElement('option');

View File

@ -17,6 +17,9 @@ declare const exports: Record<string, unknown>
let contractInterments = exports.contractInterments as ContractInterment[] let contractInterments = exports.contractInterments as ContractInterment[]
delete exports.contractInterments delete exports.contractInterments
const deathAgePeriods = exports.deathAgePeriods as string[]
delete exports.deathAgePeriods
const intermentContainerTypes = const intermentContainerTypes =
exports.intermentContainerTypes as IntermentContainerType[] exports.intermentContainerTypes as IntermentContainerType[]
delete exports.intermentContainerTypes delete exports.intermentContainerTypes
@ -112,6 +115,37 @@ declare const exports: Record<string, unknown>
.querySelector('#contractIntermentEdit--deathPlace') .querySelector('#contractIntermentEdit--deathPlace')
?.setAttribute('value', contractInterment.deathPlace ?? '') ?.setAttribute('value', contractInterment.deathPlace ?? '')
modalElement
.querySelector('#contractIntermentEdit--deathAge')
?.setAttribute('value', contractInterment.deathAge?.toString() ?? '')
const deathAgePeriodElement = modalElement.querySelector(
'#contractIntermentEdit--deathAgePeriod'
) as HTMLSelectElement
let deathAgePeriodIsFound = false
for (const deathAgePeriod of deathAgePeriods) {
const optionElement = document.createElement('option')
optionElement.value = deathAgePeriod
optionElement.text = deathAgePeriod
if (deathAgePeriod === contractInterment.deathAgePeriod) {
optionElement.selected = true
deathAgePeriodIsFound = true
}
deathAgePeriodElement.append(optionElement)
}
if (!deathAgePeriodIsFound) {
const optionElement = document.createElement('option')
optionElement.value = contractInterment.deathAgePeriod ?? ''
optionElement.text = contractInterment.deathAgePeriod ?? '(Not Set)'
optionElement.selected = true
deathAgePeriodElement.append(optionElement)
}
const containerTypeElement = modalElement.querySelector( const containerTypeElement = modalElement.querySelector(
'#contractIntermentEdit--intermentContainerTypeId' '#contractIntermentEdit--intermentContainerTypeId'
) as HTMLSelectElement ) as HTMLSelectElement
@ -211,6 +245,7 @@ declare const exports: Record<string, unknown>
}) })
} }
// eslint-disable-next-line complexity
function renderContractInterments(): void { function renderContractInterments(): void {
const containerElement = document.querySelector( const containerElement = document.querySelector(
'#container--contractInterments' '#container--contractInterments'
@ -269,6 +304,15 @@ declare const exports: Record<string, unknown>
${cityssm.escapeHTML(interment.deathPlace ?? '(No Death Place)')} ${cityssm.escapeHTML(interment.deathPlace ?? '(No Death Place)')}
</div> </div>
</div> </div>
<div class="columns">
<div class="column">
<strong>Age:</strong>
</div>
<div class="column">
${cityssm.escapeHTML(interment.deathAge === undefined ? '(No Age)' : interment.deathAge.toString())}
${cityssm.escapeHTML(interment.deathAgePeriod ?? '')}
</div>
</div>
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<strong>Container:</strong> <strong>Container:</strong>
@ -335,6 +379,18 @@ declare const exports: Record<string, unknown>
.querySelector('#contractIntermentAdd--contractId') .querySelector('#contractIntermentAdd--contractId')
?.setAttribute('value', contractId) ?.setAttribute('value', contractId)
const deathAgePeriodElement = modalElement.querySelector(
'#contractIntermentAdd--deathAgePeriod'
) as HTMLSelectElement
for (const deathAgePeriod of deathAgePeriods) {
const optionElement = document.createElement('option')
optionElement.value = deathAgePeriod
optionElement.text = deathAgePeriod
deathAgePeriodElement.append(optionElement)
}
const containerTypeElement = modalElement.querySelector( const containerTypeElement = modalElement.querySelector(
'#contractIntermentAdd--intermentContainerTypeId' '#contractIntermentAdd--intermentContainerTypeId'
) as HTMLSelectElement ) as HTMLSelectElement

View File

@ -1,977 +0,0 @@
/* eslint-disable max-lines */
import fs from 'node:fs';
import { dateIntegerToString, dateToString } from '@cityssm/utils-datetime';
import sqlite from 'better-sqlite3';
import papa from 'papaparse';
import { sunriseDB as databasePath } from '../helpers/database.helpers.js';
import addBurialSite from '../database/addBurialSite.js';
import addContract from '../database/addContract.js';
import addContractComment from '../database/addContractComment.js';
import addContractFee from '../database/addContractFee.js';
import addContractOccupant from '../database/addContractOccupant.js';
import addContractTransaction from '../database/addContractTransaction.js';
import addCemetery from '../database/addCemetery.js';
import addOrUpdateContractField from '../database/addOrUpdateContractField.js';
import addWorkOrder from '../database/addWorkOrder.js';
import addWorkOrderBurialSite from '../database/addWorkOrderBurialSite.js';
import addWorkOrderContract from '../database/addWorkOrderContract.js';
import addWorkOrderMilestone from '../database/addWorkOrderMilestone.js';
import closeWorkOrder from '../database/closeWorkOrder.js';
import getBurialSite from '../database/getBurialSite.js';
import getContracts from '../database/getContracts.js';
import getCemeteryFromDatabase from '../database/getCemetery.js';
import getWorkOrder, { getWorkOrderByWorkOrderNumber } from '../database/getWorkOrder.js';
import reopenWorkOrder from '../database/reopenWorkOrder.js';
import { updateBurialSiteStatus } from '../database/updateBurialSite.js';
import * as importData from './legacy.importFromCsv.data.js';
import * as importIds from './legacy.importFromCsv.ids.js';
const user = {
userName: 'import.unix',
userProperties: {
canUpdate: true,
isAdmin: false,
apiKey: ''
}
};
function purgeTables() {
console.time('purgeTables');
const tablesToPurge = [
'WorkOrderMilestones',
'WorkOrderComments',
'WorkOrderBurialSites',
'WorkOrderContracts',
'WorkOrders',
'ContractTransactions',
'ContractFees',
'ContractFields',
'ContractComments',
'ContractInterments',
'Contracts',
'BurialSiteFields',
'BurialSiteComments',
'BurialSites'
];
const database = sqlite(databasePath);
for (const tableName of tablesToPurge) {
database.prepare(`delete from ${tableName}`).run();
database
.prepare('delete from sqlite_sequence where name = ?')
.run(tableName);
}
database.close();
console.timeEnd('purgeTables');
}
function purgeConfigTables() {
console.time('purgeConfigTables');
const database = sqlite(databasePath);
database.prepare('delete from Cemeteries').run();
database.prepare("delete from sqlite_sequence where name in ('Cemeteries')").run();
database.close();
console.timeEnd('purgeConfigTables');
}
function getCemeteryByDescription(cemeteryDescription) {
const database = sqlite(databasePath, {
readonly: true
});
const cemetery = database
.prepare('select * from Cemeteries where cemeteryDescription = ?')
.get(cemeteryDescription);
database.close();
return cemetery;
}
function formatDateString(year, month, day) {
const formattedYear = `0000${year}`.slice(-4);
const formattedMonth = `00${month}`.slice(-2);
const formattedDay = `00${day}`.slice(-2);
return `${formattedYear}-${formattedMonth}-${formattedDay}`;
}
function formatTimeString(hour, minute) {
const formattedHour = `00${hour}`.slice(-2);
const formattedMinute = `00${minute}`.slice(-2);
return `${formattedHour}:${formattedMinute}`;
}
const cemeteryToCemeteryName = {
'00': 'Crematorium',
GC: 'New Greenwood - Columbarium',
HC: 'Holy Sepulchre - Columbarium',
HS: 'Holy Sepulchre',
MA: 'Holy Sepulchre - Mausoleum',
NG: 'New Greenwood',
NW: 'Niche Wall',
OG: 'Old Greenwood',
PG: 'Pine Grove',
UG: 'New Greenwood - Urn Garden',
WK: 'West Korah'
};
const cemeteryCache = new Map();
async function getCemetery(dataRow) {
const mapCacheKey = dataRow.cemetery;
/*
if (masterRow.CM_CEMETERY === "HS" &&
(masterRow.CM_BLOCK === "F" || masterRow.CM_BLOCK === "G" || masterRow.CM_BLOCK === "H" || masterRow.CM_BLOCK === "J")) {
mapCacheKey += "-" + masterRow.CM_BLOCK;
}
*/
if (cemeteryCache.has(mapCacheKey)) {
return cemeteryCache.get(mapCacheKey);
}
let cemetery = getCemeteryByDescription(mapCacheKey);
if (cemetery === undefined) {
console.log(`Creating cemetery: ${dataRow.cemetery}`);
const cemeteryId = await addCemetery({
cemeteryName: cemeteryToCemeteryName[dataRow.cemetery] ?? dataRow.cemetery,
cemeteryDescription: dataRow.cemetery,
cemeterySvg: '',
cemeteryLatitude: '',
cemeteryLongitude: '',
cemeteryAddress1: '',
cemeteryAddress2: '',
cemeteryCity: 'Sault Ste. Marie',
cemeteryProvince: 'ON',
cemeteryPostalCode: '',
cemeteryPhoneNumber: ''
}, user);
cemetery = (await getCemeteryFromDatabase(cemeteryId));
}
cemeteryCache.set(mapCacheKey, cemetery);
return cemetery;
}
async function importFromMasterCSV() {
console.time('importFromMasterCSV');
let masterRow;
const rawData = fs.readFileSync('./temp/CMMASTER.csv').toString();
const cmmaster = papa.parse(rawData, {
delimiter: ',',
header: true,
skipEmptyLines: true
});
for (const parseError of cmmaster.errors) {
console.log(parseError);
}
try {
for (masterRow of cmmaster.data) {
const cemetery = await getCemetery({
cemetery: masterRow.CM_CEMETERY
});
const burialSiteTypeId = importIds.getburialSiteTypeId({
cemetery: masterRow.CM_CEMETERY
});
let burialSiteId;
if (masterRow.CM_CEMETERY !== '00') {
burialSiteId = await addBurialSite({
burialSiteName,
burialSiteTypeId,
burialSiteStatusId: importIds.availableBurialSiteStatusId,
cemeteryId: cemetery.cemeteryId,
cemeterySvgId: '',
burialSiteLatitude: '',
burialSiteLongitude: ''
}, user);
}
let preneedcontractStartDateString;
let preneedcontractId;
if (masterRow.CM_PRENEED_OWNER !== '' || masterRow.CM_STATUS === 'P') {
preneedcontractStartDateString = formatDateString(masterRow.CM_PURCHASE_YR, masterRow.CM_PURCHASE_MON, masterRow.CM_PURCHASE_DAY);
let contractEndDateString = '';
if (masterRow.CM_INTERMENT_YR !== '' &&
masterRow.CM_INTERMENT_YR !== '0') {
contractEndDateString = formatDateString(masterRow.CM_INTERMENT_YR, masterRow.CM_INTERMENT_MON, masterRow.CM_INTERMENT_DAY);
}
// if purchase date unavailable
if (preneedcontractStartDateString === '0000-00-00' &&
contractEndDateString !== '') {
preneedcontractStartDateString = contractEndDateString;
}
// if end date unavailable
if (preneedcontractStartDateString === '0000-00-00' &&
masterRow.CM_DEATH_YR !== '' &&
masterRow.CM_DEATH_YR !== '0') {
preneedcontractStartDateString = formatDateString(masterRow.CM_DEATH_YR, masterRow.CM_DEATH_MON, masterRow.CM_DEATH_DAY);
// if death took place, and there's no preneed end date
if (contractEndDateString === '0000-00-00' ||
contractEndDateString === '') {
contractEndDateString = preneedcontractStartDateString;
}
}
if (preneedcontractStartDateString === '' ||
preneedcontractStartDateString === '0000-00-00') {
preneedcontractStartDateString = '0001-01-01';
}
preneedcontractId = await addContract({
contractTypeId: importIds.preneedContractType.contractTypeId,
burialSiteId: burialSiteId ?? '',
contractStartDateString: preneedcontractStartDateString,
contractEndDateString,
contractTypeFieldIds: ''
}, user);
const occupantPostalCode = `${masterRow.CM_POST1} ${masterRow.CM_POST2}`.trim();
await addContractOccupant({
contractId: preneedcontractId,
lotOccupantTypeId: importIds.preneedOwnerLotOccupantTypeId,
occupantName: masterRow.CM_PRENEED_OWNER,
occupantFamilyName: '',
occupantAddress1: masterRow.CM_ADDRESS,
occupantAddress2: '',
occupantCity: masterRow.CM_CITY,
occupantProvince: masterRow.CM_PROV,
occupantPostalCode,
occupantPhoneNumber: '',
occupantEmailAddress: ''
}, user);
if (masterRow.CM_REMARK1 !== '') {
await addContractComment({
contractId: preneedcontractId,
contractCommentDateString: preneedcontractStartDateString,
contractCommentTimeString: '00:00',
contractComment: masterRow.CM_REMARK1
}, user);
}
if (masterRow.CM_REMARK2 !== '') {
await addContractComment({
contractId: preneedcontractId,
contractCommentDateString: preneedcontractStartDateString,
contractCommentTimeString: '00:00',
contractComment: masterRow.CM_REMARK2
}, user);
}
if (masterRow.CM_WORK_ORDER.trim() !== '') {
await addContractComment({
contractId: preneedcontractId,
contractCommentDateString: preneedcontractStartDateString,
contractCommentTimeString: '00:00',
contractComment: `Imported Contract #${masterRow.CM_WORK_ORDER}`
}, user);
}
if (contractEndDateString === '') {
await updateBurialSiteStatus(burialSiteId ?? '', importIds.reservedburialSiteStatusId, user);
}
}
let deceasedcontractStartDateString;
let deceasedcontractId;
if (masterRow.CM_DECEASED_NAME !== '') {
deceasedcontractStartDateString = formatDateString(masterRow.CM_INTERMENT_YR, masterRow.CM_INTERMENT_MON, masterRow.CM_INTERMENT_DAY);
// if interment date unavailable
if (deceasedcontractStartDateString === '0000-00-00' &&
masterRow.CM_DEATH_YR !== '' &&
masterRow.CM_DEATH_YR !== '0') {
deceasedcontractStartDateString = formatDateString(masterRow.CM_DEATH_YR, masterRow.CM_DEATH_MON, masterRow.CM_DEATH_DAY);
}
if (deceasedcontractStartDateString === '' ||
deceasedcontractStartDateString === '0000-00-00') {
deceasedcontractStartDateString = '0001-01-01';
}
const deceasedcontractEndDateString = burialSiteId
? ''
: deceasedcontractStartDateString;
const contractType = burialSiteId
? importIds.deceasedContractType
: importIds.cremationContractType;
deceasedcontractId = await addContract({
contractTypeId: contractType.contractTypeId,
burialSiteId: burialSiteId ?? '',
contractStartDateString: deceasedcontractStartDateString,
contractEndDateString: deceasedcontractEndDateString,
contractTypeFieldIds: ''
}, user);
const deceasedPostalCode = `${masterRow.CM_POST1} ${masterRow.CM_POST2}`.trim();
await addContractOccupant({
contractId: deceasedcontractId,
lotOccupantTypeId: importIds.deceasedLotOccupantTypeId,
occupantName: masterRow.CM_DECEASED_NAME,
occupantFamilyName: '',
occupantAddress1: masterRow.CM_ADDRESS,
occupantAddress2: '',
occupantCity: masterRow.CM_CITY,
occupantProvince: masterRow.CM_PROV,
occupantPostalCode: deceasedPostalCode,
occupantPhoneNumber: '',
occupantEmailAddress: ''
}, user);
if (masterRow.CM_DEATH_YR !== '') {
const contractFieldValue = formatDateString(masterRow.CM_DEATH_YR, masterRow.CM_DEATH_MON, masterRow.CM_DEATH_DAY);
await addOrUpdateContractField({
contractId: deceasedcontractId,
contractTypeFieldId: contractType.ContractTypeFields.find((contractTypeField) => contractTypeField.contractTypeField === 'Death Date').contractTypeFieldId,
contractFieldValue
}, user);
}
if (masterRow.CM_AGE !== '') {
await addOrUpdateContractField({
contractId: deceasedcontractId,
contractTypeFieldId: contractType.ContractTypeFields.find((contractTypeField) => contractTypeField.contractTypeField === 'Death Age').contractTypeFieldId,
contractFieldValue: masterRow.CM_AGE
}, user);
}
if (masterRow.CM_PERIOD !== '') {
const period = importData.getDeathAgePeriod(masterRow.CM_PERIOD);
await addOrUpdateContractField({
contractId: deceasedcontractId,
contractTypeFieldId: contractType.ContractTypeFields.find((contractTypeField) => contractTypeField.contractTypeField === 'Death Age Period').contractTypeFieldId,
contractFieldValue: period
}, user);
}
if (masterRow.CM_FUNERAL_HOME !== '') {
const funeralHomeOccupant = importData.getFuneralHomeLotOccupancyOccupantData(masterRow.CM_FUNERAL_HOME);
await addContractOccupant({
contractId: deceasedcontractId,
lotOccupantTypeId: funeralHomeOccupant.lotOccupantTypeId ?? '',
occupantName: funeralHomeOccupant.occupantName ?? '',
occupantFamilyName: '',
occupantAddress1: funeralHomeOccupant.occupantAddress1 ?? '',
occupantAddress2: funeralHomeOccupant.occupantAddress2 ?? '',
occupantCity: funeralHomeOccupant.occupantCity ?? '',
occupantProvince: funeralHomeOccupant.occupantProvince ?? '',
occupantPostalCode: funeralHomeOccupant.occupantPostalCode ?? '',
occupantPhoneNumber: funeralHomeOccupant.occupantPhoneNumber ?? '',
occupantEmailAddress: funeralHomeOccupant.occupantEmailAddress ?? ''
}, user);
/*
addOrUpdateContractField(
{
contractId: deceasedcontractId,
contractTypeFieldId: allContractTypeFields.find(
(contractTypeField) => {
return contractTypeField.contractTypeField === "Funeral Home";
}
).contractTypeFieldId,
contractFieldValue: masterRow.CM_FUNERAL_HOME
},
user
);
*/
}
if (masterRow.CM_FUNERAL_YR !== '') {
const contractFieldValue = formatDateString(masterRow.CM_FUNERAL_YR, masterRow.CM_FUNERAL_MON, masterRow.CM_FUNERAL_DAY);
await addOrUpdateContractField({
contractId: deceasedcontractId,
contractTypeFieldId: contractType.ContractTypeFields.find((contractTypeField) => contractTypeField.contractTypeField === 'Funeral Date').contractTypeFieldId,
contractFieldValue
}, user);
}
if (contractType.contractType !== 'Cremation') {
if (masterRow.CM_CONTAINER_TYPE !== '') {
await addOrUpdateContractField({
contractId: deceasedcontractId,
contractTypeFieldId: contractType.contractTypeFields.find((contractTypeField) => contractTypeField.contractTypeField === 'Container Type').contractTypeFieldId,
contractFieldValue: masterRow.CM_CONTAINER_TYPE
}, user);
}
if (masterRow.CM_COMMITTAL_TYPE !== '') {
let commitalType = masterRow.CM_COMMITTAL_TYPE;
if (commitalType === 'GS') {
commitalType = 'Graveside';
}
await addOrUpdateContractField({
contractId: deceasedcontractId,
contractTypeFieldId: contractType.ContractTypeFields.find((contractTypeField) => contractTypeField.contractTypeField === 'Committal Type').contractTypeFieldId,
contractFieldValue: commitalType
}, user);
}
}
if (masterRow.CM_REMARK1 !== '') {
await addContractComment({
contractId: deceasedcontractId,
contractCommentDateString: deceasedcontractStartDateString,
contractCommentTimeString: '00:00',
contractComment: masterRow.CM_REMARK1
}, user);
}
if (masterRow.CM_REMARK2 !== '') {
await addContractComment({
contractId: deceasedcontractId,
contractCommentDateString: deceasedcontractStartDateString,
contractCommentTimeString: '00:00',
contractComment: masterRow.CM_REMARK2
}, user);
}
if (masterRow.CM_WORK_ORDER.trim() !== '') {
await addContractComment({
contractId: deceasedcontractId,
contractCommentDateString: deceasedcontractStartDateString,
contractCommentTimeString: '00:00',
contractComment: `Imported Contract #${masterRow.CM_WORK_ORDER}`
}, user);
}
await updateBurialSiteStatus(burialSiteId ?? '', importIds.takenburialSiteStatusId, user);
if (masterRow.CM_PRENEED_OWNER !== '') {
await addContractOccupant({
contractId: deceasedcontractId,
lotOccupantTypeId: importIds.preneedOwnerLotOccupantTypeId,
occupantName: masterRow.CM_PRENEED_OWNER,
occupantFamilyName: '',
occupantAddress1: '',
occupantAddress2: '',
occupantCity: '',
occupantProvince: '',
occupantPostalCode: '',
occupantPhoneNumber: '',
occupantEmailAddress: ''
}, user);
}
}
}
}
catch (error) {
console.error(error);
console.log(masterRow);
}
console.timeEnd('importFromMasterCSV');
}
async function importFromPrepaidCSV() {
console.time('importFromPrepaidCSV');
let prepaidRow;
const rawData = fs.readFileSync('./temp/CMPRPAID.csv').toString();
const cmprpaid = papa.parse(rawData, {
delimiter: ',',
header: true,
skipEmptyLines: true
});
for (const parseError of cmprpaid.errors) {
console.log(parseError);
}
try {
for (prepaidRow of cmprpaid.data) {
if (!prepaidRow.CMPP_PREPAID_FOR_NAME) {
continue;
}
let cemetery = prepaidRow.CMPP_CEMETERY;
if (cemetery === '.m') {
cemetery = 'HC';
}
let lot;
if (cemetery !== '') {
const map = await getCemetery({
cemetery
});
const burialSiteName = importData.buildLotName({
cemetery,
block: prepaidRow.CMPP_BLOCK,
range1: prepaidRow.CMPP_RANGE1,
range2: prepaidRow.CMPP_RANGE2,
lot1: prepaidRow.CMPP_LOT1,
lot2: prepaidRow.CMPP_LOT2,
grave1: prepaidRow.CMPP_GRAVE1,
grave2: prepaidRow.CMPP_GRAVE2,
interment: prepaidRow.CMPP_INTERMENT
});
lot = await getBurialSiteByLotName(burialSiteName);
if (!lot) {
const burialSiteTypeId = importIds.getburialSiteTypeId({
cemetery
});
const burialSiteId = await addBurialSite({
burialSiteName,
burialSiteTypeId,
burialSiteStatusId: importIds.reservedburialSiteStatusId,
cemeteryId: map.cemeteryId ?? '',
mapKey: burialSiteName.includes(',') ? burialSiteName.split(',')[0] : burialSiteName,
burialSiteLatitude: '',
burialSiteLongitude: ''
}, user);
lot = await getBurialSite(burialSiteId);
}
}
if (lot &&
lot.burialSiteStatusId === importIds.availableburialSiteStatusId) {
await updateBurialSiteStatus(lot.burialSiteId, importIds.reservedburialSiteStatusId, user);
}
const contractStartDateString = formatDateString(prepaidRow.CMPP_PURCH_YR, prepaidRow.CMPP_PURCH_MON, prepaidRow.CMPP_PURCH_DAY);
let contractId;
if (lot) {
const possibleLotOccupancies = await getContracts({
burialSiteId: lot.burialSiteId,
contractTypeId: importIds.preneedContractType.contractTypeId,
deceasedName: prepaidRow.CMPP_PREPAID_FOR_NAME,
contractStartDateString
}, {
includeOccupants: false,
includeFees: false,
includeTransactions: false,
limit: -1,
offset: 0
});
if (possibleLotOccupancies.lotOccupancies.length > 0) {
contractId =
possibleLotOccupancies.lotOccupancies[0].contractId;
}
}
contractId ||= await addContract({
burialSiteId: lot ? lot.burialSiteId : '',
contractTypeId: importIds.preneedContractType.contractTypeId,
contractStartDateString,
contractEndDateString: ''
}, user);
await addContractOccupant({
contractId,
lotOccupantTypeId: importIds.preneedOwnerLotOccupantTypeId,
occupantName: prepaidRow.CMPP_PREPAID_FOR_NAME,
occupantFamilyName: '',
occupantAddress1: prepaidRow.CMPP_ADDRESS,
occupantAddress2: '',
occupantCity: prepaidRow.CMPP_CITY,
occupantProvince: prepaidRow.CMPP_PROV.slice(0, 2),
occupantPostalCode: `${prepaidRow.CMPP_POSTAL1} ${prepaidRow.CMPP_POSTAL2}`,
occupantPhoneNumber: '',
occupantEmailAddress: ''
}, user);
if (prepaidRow.CMPP_ARRANGED_BY_NAME) {
await addContractOccupant({
contractId,
lotOccupantTypeId: importIds.purchaserLotOccupantTypeId,
occupantName: prepaidRow.CMPP_ARRANGED_BY_NAME,
occupantFamilyName: '',
occupantAddress1: '',
occupantAddress2: '',
occupantCity: '',
occupantProvince: '',
occupantPostalCode: '',
occupantPhoneNumber: '',
occupantEmailAddress: ''
}, user);
}
if (prepaidRow.CMPP_FEE_GRAV_SD !== '0.0') {
await addContractFee({
contractId,
feeId: importIds.getFeeIdByFeeDescription('CMPP_FEE_GRAV_SD'),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_GRAV_SD,
taxAmount: prepaidRow.CMPP_GST_GRAV_SD
}, user);
}
if (prepaidRow.CMPP_FEE_GRAV_DD !== '0.0') {
await addContractFee({
contractId,
feeId: importIds.getFeeIdByFeeDescription('CMPP_FEE_GRAV_DD'),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_GRAV_DD,
taxAmount: prepaidRow.CMPP_GST_GRAV_DD
}, user);
}
if (prepaidRow.CMPP_FEE_CHAP_SD !== '0.0') {
await addContractFee({
contractId,
feeId: importIds.getFeeIdByFeeDescription('CMPP_FEE_CHAP_SD'),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_CHAP_SD,
taxAmount: prepaidRow.CMPP_GST_CHAP_SD
}, user);
}
if (prepaidRow.CMPP_FEE_CHAP_DD !== '0.0') {
await addContractFee({
contractId,
feeId: importIds.getFeeIdByFeeDescription('CMPP_FEE_CHAP_DD'),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_CHAP_DD,
taxAmount: prepaidRow.CMPP_GST_CHAP_DD
}, user);
}
if (prepaidRow.CMPP_FEE_ENTOMBMENT !== '0.0') {
await addContractFee({
contractId,
feeId: importIds.getFeeIdByFeeDescription('CMPP_FEE_ENTOMBMENT'),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_ENTOMBMENT,
taxAmount: prepaidRow.CMPP_GST_ENTOMBMENT
}, user);
}
if (prepaidRow.CMPP_FEE_CREM !== '0.0') {
await addContractFee({
contractId,
feeId: importIds.getFeeIdByFeeDescription('CMPP_FEE_CREM'),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_CREM,
taxAmount: prepaidRow.CMPP_GST_CREM
}, user);
}
if (prepaidRow.CMPP_FEE_NICHE !== '0.0') {
await addContractFee({
contractId,
feeId: importIds.getFeeIdByFeeDescription('CMPP_FEE_NICHE'),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_NICHE,
taxAmount: prepaidRow.CMPP_GST_NICHE
}, user);
}
if (prepaidRow.CMPP_FEE_DISINTERMENT !== '0.0' &&
prepaidRow.CMPP_FEE_DISINTERMENT !== '20202.02') {
await addContractFee({
contractId,
feeId: importIds.getFeeIdByFeeDescription('CMPP_FEE_DISINTERMENT'),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_DISINTERMENT,
taxAmount: prepaidRow.CMPP_GST_DISINTERMENT
}, user);
}
const transactionAmount = Number.parseFloat(prepaidRow.CMPP_FEE_GRAV_SD) +
Number.parseFloat(prepaidRow.CMPP_GST_GRAV_SD) +
Number.parseFloat(prepaidRow.CMPP_FEE_GRAV_DD) +
Number.parseFloat(prepaidRow.CMPP_GST_GRAV_DD) +
Number.parseFloat(prepaidRow.CMPP_FEE_CHAP_SD) +
Number.parseFloat(prepaidRow.CMPP_GST_CHAP_SD) +
Number.parseFloat(prepaidRow.CMPP_FEE_CHAP_DD) +
Number.parseFloat(prepaidRow.CMPP_GST_CHAP_DD) +
Number.parseFloat(prepaidRow.CMPP_FEE_ENTOMBMENT) +
Number.parseFloat(prepaidRow.CMPP_GST_ENTOMBMENT) +
Number.parseFloat(prepaidRow.CMPP_FEE_CREM) +
Number.parseFloat(prepaidRow.CMPP_GST_CREM) +
Number.parseFloat(prepaidRow.CMPP_FEE_NICHE) +
Number.parseFloat(prepaidRow.CMPP_GST_NICHE) +
Number.parseFloat(prepaidRow.CMPP_FEE_DISINTERMENT === '20202.02'
? '0'
: prepaidRow.CMPP_FEE_DISINTERMENT) +
Number.parseFloat(prepaidRow.CMPP_GST_DISINTERMENT === '20202.02'
? '0'
: prepaidRow.CMPP_GST_DISINTERMENT);
await addContractTransaction({
contractId,
externalReceiptNumber: '',
transactionAmount,
transactionDateString: contractStartDateString,
transactionNote: `Order Number: ${prepaidRow.CMPP_ORDER_NO}`
}, user);
if (prepaidRow.CMPP_REMARK1) {
await addContractComment({
contractId,
contractCommentDateString: contractStartDateString,
contractComment: prepaidRow.CMPP_REMARK1
}, user);
}
if (prepaidRow.CMPP_REMARK2) {
await addContractComment({
contractId,
contractCommentDateString: contractStartDateString,
contractComment: prepaidRow.CMPP_REMARK2
}, user);
}
}
}
catch (error) {
console.error(error);
console.log(prepaidRow);
}
console.timeEnd('importFromPrepaidCSV');
}
async function importFromWorkOrderCSV() {
console.time('importFromWorkOrderCSV');
let workOrderRow;
const rawData = fs.readFileSync('./temp/CMWKORDR.csv').toString();
const cmwkordr = papa.parse(rawData, {
delimiter: ',',
header: true,
skipEmptyLines: true
});
for (const parseError of cmwkordr.errors) {
console.log(parseError);
}
const currentDateString = dateToString(new Date());
try {
for (workOrderRow of cmwkordr.data) {
const workOrderNumber = `000000${workOrderRow.WO_WORK_ORDER}`.slice(-6);
let workOrder = await getWorkOrderByWorkOrderNumber(workOrderNumber);
const workOrderOpenDateString = dateIntegerToString(Number.parseInt(workOrderRow.WO_INITIATION_DATE, 10));
if (workOrder) {
if (workOrder.workOrderCloseDate) {
await reopenWorkOrder(workOrder.workOrderId, user);
delete workOrder.workOrderCloseDate;
delete workOrder.workOrderCloseDateString;
}
}
else {
const workOrderId = await addWorkOrder({
workOrderNumber,
workOrderTypeId: importIds.workOrderTypeId,
workOrderDescription: `${workOrderRow.WO_REMARK1} ${workOrderRow.WO_REMARK2} ${workOrderRow.WO_REMARK3}`.trim(),
workOrderOpenDateString
}, user);
workOrder = await getWorkOrder(workOrderId, {
includeLotsAndLotOccupancies: true,
includeComments: true,
includeMilestones: true
});
}
let lot;
if (workOrderRow.WO_CEMETERY !== '00') {
const burialSiteName = importData.buildLotName({
cemetery: workOrderRow.WO_CEMETERY,
block: workOrderRow.WO_BLOCK,
range1: workOrderRow.WO_RANGE1,
range2: workOrderRow.WO_RANGE2,
lot1: workOrderRow.WO_LOT1,
lot2: workOrderRow.WO_LOT2,
grave1: workOrderRow.WO_GRAVE1,
grave2: workOrderRow.WO_GRAVE2,
interment: workOrderRow.WO_INTERMENT
});
lot = await getBurialSiteByLotName(burialSiteName);
if (lot) {
await updateBurialSiteStatus(lot.burialSiteId, importIds.takenburialSiteStatusId, user);
}
else {
const map = await getCemetery({ cemetery: workOrderRow.WO_CEMETERY });
const burialSiteTypeId = importIds.getburialSiteTypeId({
cemetery: workOrderRow.WO_CEMETERY
});
const burialSiteId = await addBurialSite({
cemeteryId: map.cemeteryId,
burialSiteName,
mapKey: burialSiteName.includes(',') ? burialSiteName.split(',')[0] : burialSiteName,
burialSiteStatusId: importIds.takenburialSiteStatusId,
burialSiteTypeId,
burialSiteLatitude: '',
burialSiteLongitude: ''
}, user);
lot = await getBurialSite(burialSiteId);
}
const workOrderContainsLot = workOrder.workOrderLots.find((possibleLot) => (possibleLot.burialSiteId = lot.burialSiteId));
if (!workOrderContainsLot) {
await addWorkOrderBurialSite({
workOrderId: workOrder.workOrderId,
burialSiteId: lot.burialSiteId
}, user);
workOrder.workOrderLots.push(lot);
}
}
let contractStartDateString = workOrderOpenDateString;
if (workOrderRow.WO_INTERMENT_YR) {
contractStartDateString = formatDateString(workOrderRow.WO_INTERMENT_YR, workOrderRow.WO_INTERMENT_MON, workOrderRow.WO_INTERMENT_DAY);
}
const contractType = lot
? importIds.deceasedContractType
: importIds.cremationContractType;
const contractId = await addContract({
burialSiteId: lot ? lot.burialSiteId : '',
contractTypeId: contractType.contractTypeId,
contractStartDateString,
contractEndDateString: ''
}, user);
await addContractOccupant({
contractId,
lotOccupantTypeId: importIds.deceasedLotOccupantTypeId,
occupantName: workOrderRow.WO_DECEASED_NAME,
occupantFamilyName: '',
occupantAddress1: workOrderRow.WO_ADDRESS,
occupantAddress2: '',
occupantCity: workOrderRow.WO_CITY,
occupantProvince: workOrderRow.WO_PROV.slice(0, 2),
occupantPostalCode: `${workOrderRow.WO_POST1} ${workOrderRow.WO_POST2}`,
occupantPhoneNumber: '',
occupantEmailAddress: ''
}, user);
if (workOrderRow.WO_DEATH_YR !== '') {
const contractFieldValue = formatDateString(workOrderRow.WO_DEATH_YR, workOrderRow.WO_DEATH_MON, workOrderRow.WO_DEATH_DAY);
await addOrUpdateContractField({
contractId,
contractTypeFieldId: contractType.ContractTypeFields.find((contractTypeField) => contractTypeField.contractTypeField === 'Death Date').contractTypeFieldId,
contractFieldValue
}, user);
}
if (workOrderRow.WO_DEATH_PLACE !== '') {
await addOrUpdateContractField({
contractId,
contractTypeFieldId: contractType.ContractTypeFields.find((contractTypeField) => contractTypeField.contractTypeField === 'Death Place').contractTypeFieldId,
contractFieldValue: workOrderRow.WO_DEATH_PLACE
}, user);
}
if (workOrderRow.WO_AGE !== '') {
await addOrUpdateContractField({
contractId,
contractTypeFieldId: contractType.ContractTypeFields.find((contractTypeField) => contractTypeField.contractTypeField === 'Death Age').contractTypeFieldId,
contractFieldValue: workOrderRow.WO_AGE
}, user);
}
if (workOrderRow.WO_PERIOD !== '') {
const period = importData.getDeathAgePeriod(workOrderRow.WO_PERIOD);
await addOrUpdateContractField({
contractId,
contractTypeFieldId: contractType.ContractTypeFields.find((contractTypeField) => contractTypeField.contractTypeField === 'Death Age Period').contractTypeFieldId,
contractFieldValue: period
}, user);
}
if (workOrderRow.WO_FUNERAL_HOME !== '') {
const funeralHomeOccupant = importData.getFuneralHomeLotOccupancyOccupantData(workOrderRow.WO_FUNERAL_HOME);
await addContractOccupant({
contractId,
lotOccupantTypeId: funeralHomeOccupant.lotOccupantTypeId,
occupantName: funeralHomeOccupant.occupantName,
occupantFamilyName: '',
occupantAddress1: funeralHomeOccupant.occupantAddress1,
occupantAddress2: funeralHomeOccupant.occupantAddress2,
occupantCity: funeralHomeOccupant.occupantCity,
occupantProvince: funeralHomeOccupant.occupantProvince,
occupantPostalCode: funeralHomeOccupant.occupantPostalCode,
occupantPhoneNumber: funeralHomeOccupant.occupantPhoneNumber,
occupantEmailAddress: funeralHomeOccupant.occupantEmailAddress
}, user);
/*
addOrUpdateContractField(
{
contractId: contractId,
contractTypeFieldId: allContractTypeFields.find((contractTypeField) => {
return contractTypeField.contractTypeField === "Funeral Home";
}).contractTypeFieldId,
contractFieldValue: workOrderRow.WO_FUNERAL_HOME
},
user
);
*/
}
if (workOrderRow.WO_FUNERAL_YR !== '') {
const contractFieldValue = formatDateString(workOrderRow.WO_FUNERAL_YR, workOrderRow.WO_FUNERAL_MON, workOrderRow.WO_FUNERAL_DAY);
await addOrUpdateContractField({
contractId,
contractTypeFieldId: contractType.ContractTypeFields.find((contractTypeField) => contractTypeField.contractTypeField === 'Funeral Date').contractTypeFieldId,
contractFieldValue
}, user);
}
if (contractType.contractType !== 'Cremation') {
if (workOrderRow.WO_CONTAINER_TYPE !== '') {
await addOrUpdateContractField({
contractId,
contractTypeFieldId: contractType.ContractTypeFields.find((contractTypeField) => contractTypeField.contractTypeField === 'Container Type').contractTypeFieldId,
contractFieldValue: workOrderRow.WO_CONTAINER_TYPE
}, user);
}
if (workOrderRow.WO_COMMITTAL_TYPE !== '') {
let commitalType = workOrderRow.WO_COMMITTAL_TYPE;
if (commitalType === 'GS') {
commitalType = 'Graveside';
}
await addOrUpdateContractField({
contractId,
contractTypeFieldId: contractType.ContractTypeFields.find((contractTypeField) => contractTypeField.contractTypeField === 'Committal Type').contractTypeFieldId,
contractFieldValue: commitalType
}, user);
}
}
await addWorkOrderContract({
workOrderId: workOrder.workOrderId,
contractId
}, user);
// Milestones
let hasIncompleteMilestones = !workOrderRow.WO_CONFIRMATION_IN;
let maxMilestoneCompletionDateString = workOrderOpenDateString;
if (importIds.acknowledgedWorkOrderMilestoneTypeId) {
await addWorkOrderMilestone({
workOrderId: workOrder.workOrderId,
workOrderMilestoneTypeId: importIds.acknowledgedWorkOrderMilestoneTypeId,
workOrderMilestoneDateString: workOrderOpenDateString,
workOrderMilestoneDescription: '',
workOrderMilestoneCompletionDateString: workOrderRow.WO_CONFIRMATION_IN
? workOrderOpenDateString
: undefined,
workOrderMilestoneCompletionTimeString: workOrderRow.WO_CONFIRMATION_IN ? '00:00' : undefined
}, user);
}
if (workOrderRow.WO_DEATH_YR) {
const workOrderMilestoneDateString = formatDateString(workOrderRow.WO_DEATH_YR, workOrderRow.WO_DEATH_MON, workOrderRow.WO_DEATH_DAY);
if (importIds.deathWorkOrderMilestoneTypeId) {
await addWorkOrderMilestone({
workOrderId: workOrder.workOrderId,
workOrderMilestoneTypeId: importIds.deathWorkOrderMilestoneTypeId,
workOrderMilestoneDateString,
workOrderMilestoneDescription: `Death Place: ${workOrderRow.WO_DEATH_PLACE}`,
workOrderMilestoneCompletionDateString: workOrderMilestoneDateString < currentDateString
? workOrderMilestoneDateString
: undefined,
workOrderMilestoneCompletionTimeString: workOrderMilestoneDateString < currentDateString
? '00:00'
: undefined
}, user);
}
if (workOrderMilestoneDateString > maxMilestoneCompletionDateString) {
maxMilestoneCompletionDateString = workOrderMilestoneDateString;
}
if (workOrderMilestoneDateString >= currentDateString) {
hasIncompleteMilestones = true;
}
}
if (workOrderRow.WO_FUNERAL_YR) {
const workOrderMilestoneDateString = formatDateString(workOrderRow.WO_FUNERAL_YR, workOrderRow.WO_FUNERAL_MON, workOrderRow.WO_FUNERAL_DAY);
let funeralHour = Number.parseInt(workOrderRow.WO_FUNERAL_HR, 10);
if (funeralHour <= 6) {
funeralHour += 12;
}
const workOrderMilestoneTimeString = formatTimeString(funeralHour.toString(), workOrderRow.WO_FUNERAL_MIN);
if (importIds.funeralWorkOrderMilestoneTypeId) {
await addWorkOrderMilestone({
workOrderId: workOrder.workOrderId,
workOrderMilestoneTypeId: importIds.funeralWorkOrderMilestoneTypeId,
workOrderMilestoneDateString,
workOrderMilestoneTimeString,
workOrderMilestoneDescription: `Funeral Home: ${workOrderRow.WO_FUNERAL_HOME}`,
workOrderMilestoneCompletionDateString: workOrderMilestoneDateString < currentDateString
? workOrderMilestoneDateString
: undefined,
workOrderMilestoneCompletionTimeString: workOrderMilestoneDateString < currentDateString
? workOrderMilestoneTimeString
: undefined
}, user);
}
if (workOrderMilestoneDateString > maxMilestoneCompletionDateString) {
maxMilestoneCompletionDateString = workOrderMilestoneDateString;
}
if (workOrderMilestoneDateString >= currentDateString) {
hasIncompleteMilestones = true;
}
}
if (workOrderRow.WO_CREMATION === 'Y' &&
importIds.cremationWorkOrderMilestoneTypeId) {
await addWorkOrderMilestone({
workOrderId: workOrder.workOrderId,
workOrderMilestoneTypeId: importIds.cremationWorkOrderMilestoneTypeId,
workOrderMilestoneDateString: maxMilestoneCompletionDateString,
workOrderMilestoneDescription: '',
workOrderMilestoneCompletionDateString: maxMilestoneCompletionDateString < currentDateString
? maxMilestoneCompletionDateString
: undefined,
workOrderMilestoneCompletionTimeString: maxMilestoneCompletionDateString < currentDateString
? '00:00'
: undefined
}, user);
}
if (workOrderRow.WO_INTERMENT_YR) {
const workOrderMilestoneDateString = formatDateString(workOrderRow.WO_INTERMENT_YR, workOrderRow.WO_INTERMENT_MON, workOrderRow.WO_INTERMENT_DAY);
if (importIds.intermentWorkOrderMilestoneTypeId) {
await addWorkOrderMilestone({
workOrderId: workOrder.workOrderId,
workOrderMilestoneTypeId: importIds.intermentWorkOrderMilestoneTypeId,
workOrderMilestoneDateString,
workOrderMilestoneDescription: `Depth: ${workOrderRow.WO_DEPTH}`,
workOrderMilestoneCompletionDateString: workOrderMilestoneDateString < currentDateString
? workOrderMilestoneDateString
: undefined,
workOrderMilestoneCompletionTimeString: workOrderMilestoneDateString < currentDateString
? '23:59'
: undefined
}, user);
}
if (workOrderMilestoneDateString > maxMilestoneCompletionDateString) {
maxMilestoneCompletionDateString = workOrderMilestoneDateString;
}
if (workOrderMilestoneDateString >= currentDateString) {
hasIncompleteMilestones = true;
}
}
if (!hasIncompleteMilestones) {
await closeWorkOrder({
workOrderId: workOrder.workOrderId,
workOrderCloseDateString: maxMilestoneCompletionDateString
}, user);
}
}
}
catch (error) {
console.error(error);
console.log(workOrderRow);
}
console.timeEnd('importFromWorkOrderCSV');
}
console.log(`Started ${new Date().toLocaleString()}`);
console.time('importFromCsv');
purgeTables();
// purgeConfigTables();
await importFromMasterCSV();
await importFromPrepaidCSV();
await importFromWorkOrderCSV();
console.timeEnd('importFromCsv');
console.log(`Finished ${new Date().toLocaleString()}`);

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +0,0 @@
import type { LotOccupancyOccupant } from '../types/recordTypes.js';
export declare function getFuneralHomeLotOccupancyOccupantData(funeralHomeKey: string): LotOccupancyOccupant;
export declare function getDeathAgePeriod(legacyDeathAgePeriod: string): string;

View File

@ -1,120 +0,0 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable @cspell/spellchecker */
import * as importIds from './legacy.importFromCsv.ids.js';
export function getFuneralHomeLotOccupancyOccupantData(funeralHomeKey) {
switch (funeralHomeKey) {
case 'AR': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: 'Arthur Funeral Home',
occupantAddress1: '492 Wellington Street East',
occupantAddress2: '',
occupantCity: 'Sault Ste. Marie',
occupantProvince: 'ON',
occupantPostalCode: 'P6A 2L9',
occupantPhoneNumber: '705-759-2522',
occupantEmailAddress: ''
};
}
case 'BG': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: 'Beggs Funeral Home',
occupantAddress1: '175 Main Street',
occupantAddress2: 'P.O. Box 280',
occupantCity: 'Thessalon',
occupantProvince: 'ON',
occupantPostalCode: 'P0R 1L0',
occupantPhoneNumber: '705-842-2520',
occupantEmailAddress: 'bfh@beggsfh.ca'
};
}
case 'BK': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: 'Barton and Kiteley',
occupantAddress1: '',
occupantAddress2: '',
occupantCity: 'Sault Ste. Marie',
occupantProvince: 'ON',
occupantPostalCode: '',
occupantPhoneNumber: '',
occupantEmailAddress: ''
};
}
case 'DA': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: 'Damignani Burial, Cremation and Transfer Service',
occupantAddress1: '215 St. James Street',
occupantAddress2: '',
occupantCity: 'Sault Ste. Marie',
occupantProvince: 'ON',
occupantPostalCode: 'P6A 1P7',
occupantPhoneNumber: '705-759-8456',
occupantEmailAddress: ''
};
}
case 'GL': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: 'Gilmartin P.M. Funeral Home',
occupantAddress1: '140 Churchill Avenue',
occupantAddress2: '',
occupantCity: 'Wawa',
occupantProvince: 'ON',
occupantPostalCode: 'P0S 1K0',
occupantPhoneNumber: '705-856-7340',
occupantEmailAddress: ''
};
}
case 'NO': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: 'Northwood Funeral Home',
occupantAddress1: '942 Great Northern Road',
occupantAddress2: '',
occupantCity: 'Sault Ste. Marie',
occupantProvince: 'ON',
occupantPostalCode: 'P6B 0B6',
occupantPhoneNumber: '705-945-7758',
occupantEmailAddress: ''
};
}
case 'OS': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: "O'Sullivan Funeral Home",
occupantAddress1: '215 St. James Street',
occupantAddress2: '',
occupantCity: 'Sault Ste. Marie',
occupantProvince: 'ON',
occupantPostalCode: 'P6A 1P7',
occupantPhoneNumber: '705-759-8456',
occupantEmailAddress: ''
};
}
}
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: funeralHomeKey,
occupantCity: 'Sault Ste. Marie',
occupantProvince: 'ON'
};
}
export function getDeathAgePeriod(legacyDeathAgePeriod) {
switch (legacyDeathAgePeriod.toLowerCase()) {
case 'yrs': {
return 'Years';
}
case 'mts': {
return 'Months';
}
case 'dys': {
return 'Days';
}
default: {
return legacyDeathAgePeriod;
}
}
}

View File

@ -1,129 +0,0 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable @cspell/spellchecker */
import type { LotOccupancyOccupant } from '../types/recordTypes.js'
import * as importIds from './legacy.importFromCsv.ids.js'
export function getFuneralHomeLotOccupancyOccupantData(
funeralHomeKey: string
): LotOccupancyOccupant {
switch (funeralHomeKey) {
case 'AR': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: 'Arthur Funeral Home',
occupantAddress1: '492 Wellington Street East',
occupantAddress2: '',
occupantCity: 'Sault Ste. Marie',
occupantProvince: 'ON',
occupantPostalCode: 'P6A 2L9',
occupantPhoneNumber: '705-759-2522',
occupantEmailAddress: ''
}
}
case 'BG': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: 'Beggs Funeral Home',
occupantAddress1: '175 Main Street',
occupantAddress2: 'P.O. Box 280',
occupantCity: 'Thessalon',
occupantProvince: 'ON',
occupantPostalCode: 'P0R 1L0',
occupantPhoneNumber: '705-842-2520',
occupantEmailAddress: 'bfh@beggsfh.ca'
}
}
case 'BK': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: 'Barton and Kiteley',
occupantAddress1: '',
occupantAddress2: '',
occupantCity: 'Sault Ste. Marie',
occupantProvince: 'ON',
occupantPostalCode: '',
occupantPhoneNumber: '',
occupantEmailAddress: ''
}
}
case 'DA': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: 'Damignani Burial, Cremation and Transfer Service',
occupantAddress1: '215 St. James Street',
occupantAddress2: '',
occupantCity: 'Sault Ste. Marie',
occupantProvince: 'ON',
occupantPostalCode: 'P6A 1P7',
occupantPhoneNumber: '705-759-8456',
occupantEmailAddress: ''
}
}
case 'GL': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: 'Gilmartin P.M. Funeral Home',
occupantAddress1: '140 Churchill Avenue',
occupantAddress2: '',
occupantCity: 'Wawa',
occupantProvince: 'ON',
occupantPostalCode: 'P0S 1K0',
occupantPhoneNumber: '705-856-7340',
occupantEmailAddress: ''
}
}
case 'NO': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: 'Northwood Funeral Home',
occupantAddress1: '942 Great Northern Road',
occupantAddress2: '',
occupantCity: 'Sault Ste. Marie',
occupantProvince: 'ON',
occupantPostalCode: 'P6B 0B6',
occupantPhoneNumber: '705-945-7758',
occupantEmailAddress: ''
}
}
case 'OS': {
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: "O'Sullivan Funeral Home",
occupantAddress1: '215 St. James Street',
occupantAddress2: '',
occupantCity: 'Sault Ste. Marie',
occupantProvince: 'ON',
occupantPostalCode: 'P6A 1P7',
occupantPhoneNumber: '705-759-8456',
occupantEmailAddress: ''
}
}
}
return {
lotOccupantTypeId: importIds.funeralDirectorLotOccupantTypeId,
occupantName: funeralHomeKey,
occupantCity: 'Sault Ste. Marie',
occupantProvince: 'ON'
}
}
export function getDeathAgePeriod(legacyDeathAgePeriod: string): string {
switch (legacyDeathAgePeriod.toLowerCase()) {
case 'yrs': {
return 'Years'
}
case 'mts': {
return 'Months'
}
case 'dys': {
return 'Days'
}
default: {
return legacyDeathAgePeriod
}
}
}

View File

@ -1,20 +0,0 @@
export declare function getFeeIdByFeeDescription(feeDescription: string): number;
export declare const preneedOwnerLotOccupantTypeId: any;
export declare const funeralDirectorLotOccupantTypeId: any;
export declare const deceasedLotOccupantTypeId: any;
export declare const purchaserLotOccupantTypeId: any;
export declare const availableburialSiteStatusId: any;
export declare const reservedburialSiteStatusId: any;
export declare const takenburialSiteStatusId: any;
export declare function getburialSiteTypeId(dataRow: {
cemetery: string;
}): number;
export declare const preneedContractType: import("../types/recordTypes.js").ContractType;
export declare const deceasedContractType: import("../types/recordTypes.js").ContractType;
export declare const cremationContractType: import("../types/recordTypes.js").ContractType;
export declare const acknowledgedWorkOrderMilestoneTypeId: number | undefined;
export declare const deathWorkOrderMilestoneTypeId: number | undefined;
export declare const funeralWorkOrderMilestoneTypeId: number | undefined;
export declare const cremationWorkOrderMilestoneTypeId: number | undefined;
export declare const intermentWorkOrderMilestoneTypeId: number | undefined;
export declare const workOrderTypeId = 1;

View File

@ -1,89 +0,0 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable unicorn/no-await-expression-member */
import sqlite from 'better-sqlite3';
import { sunriseDB as databasePath } from '../data/databasePaths.js';
import * as cacheFunctions from '../helpers/functions.cache.js';
/*
* Fee IDs
*/
const feeCache = new Map();
export function getFeeIdByFeeDescription(feeDescription) {
if (feeCache.keys.length === 0) {
const database = sqlite(databasePath, {
readonly: true
});
const records = database
.prepare("select feeId, feeDescription from Fees where feeDescription like 'CMPP_FEE_%'")
.all();
for (const record of records) {
feeCache.set(record.feeDescription, record.feeId);
}
database.close();
}
return feeCache.get(feeDescription);
}
/*
* Lot Occupant Type IDs
*/
export const preneedOwnerLotOccupantTypeId = (await cacheFunctions.getBurialSiteOccupantTypeByLotOccupantType('Preneed Owner'))
.lotOccupantTypeId;
export const funeralDirectorLotOccupantTypeId = (await cacheFunctions.getBurialSiteOccupantTypeByLotOccupantType('Funeral Director')).lotOccupantTypeId;
export const deceasedLotOccupantTypeId = (await cacheFunctions.getBurialSiteOccupantTypeByLotOccupantType('Deceased'))
.lotOccupantTypeId;
export const purchaserLotOccupantTypeId = (await cacheFunctions.getBurialSiteOccupantTypeByLotOccupantType('Purchaser'))
.lotOccupantTypeId;
/*
* Lot Status IDs
*/
export const availableburialSiteStatusId = (await cacheFunctions.getBurialSiteStatusByLotStatus('Available')).burialSiteStatusId;
export const reservedburialSiteStatusId = (await cacheFunctions.getBurialSiteStatusByLotStatus('Reserved')).burialSiteStatusId;
export const takenburialSiteStatusId = (await cacheFunctions.getBurialSiteStatusByLotStatus('Taken')).burialSiteStatusId;
/*
* Lot Type IDs
*/
const casketburialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType('Casket Grave')).burialSiteTypeId;
const columbariumburialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType('Columbarium')).burialSiteTypeId;
const crematoriumburialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType('Crematorium')).burialSiteTypeId;
const mausoleumburialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType('Mausoleum')).burialSiteTypeId;
const nicheWallburialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType('Niche Wall')).burialSiteTypeId;
const urnGardenburialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType('Urn Garden')).burialSiteTypeId;
export function getburialSiteTypeId(dataRow) {
switch (dataRow.cemetery) {
case '00': {
return crematoriumburialSiteTypeId;
}
case 'GC':
case 'HC': {
return columbariumburialSiteTypeId;
}
case 'MA': {
return mausoleumburialSiteTypeId;
}
case 'MN':
case 'NW': {
return nicheWallburialSiteTypeId;
}
case 'UG': {
return urnGardenburialSiteTypeId;
}
}
return casketburialSiteTypeId;
}
/*
* Occupancy Type IDs
*/
export const preneedContractType = (await cacheFunctions.getContractTypeByContractType('Preneed'));
export const deceasedContractType = (await cacheFunctions.getContractTypeByContractType('Interment'));
export const cremationContractType = (await cacheFunctions.getContractTypeByContractType('Cremation'));
/*
* Work Order Milestone Type IDs
*/
export const acknowledgedWorkOrderMilestoneTypeId = (await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Acknowledged'))?.workOrderMilestoneTypeId;
export const deathWorkOrderMilestoneTypeId = (await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Death'))?.workOrderMilestoneTypeId;
export const funeralWorkOrderMilestoneTypeId = (await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Funeral'))?.workOrderMilestoneTypeId;
export const cremationWorkOrderMilestoneTypeId = (await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Cremation'))?.workOrderMilestoneTypeId;
export const intermentWorkOrderMilestoneTypeId = (await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Interment'))?.workOrderMilestoneTypeId;
/*
* Work Order Type IDs
*/
export const workOrderTypeId = 1;

View File

@ -1,171 +0,0 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable unicorn/no-await-expression-member */
import sqlite from 'better-sqlite3'
import { sunriseDB as databasePath } from '../data/databasePaths.js'
import * as cacheFunctions from '../helpers/functions.cache.js'
/*
* Fee IDs
*/
const feeCache = new Map<string, number>()
export function getFeeIdByFeeDescription(feeDescription: string): number {
if (feeCache.keys.length === 0) {
const database = sqlite(databasePath, {
readonly: true
})
const records = database
.prepare(
"select feeId, feeDescription from Fees where feeDescription like 'CMPP_FEE_%'"
)
.all() as Array<{
feeId: number
feeDescription: string
}>
for (const record of records) {
feeCache.set(record.feeDescription, record.feeId)
}
database.close()
}
return feeCache.get(feeDescription)!
}
/*
* Lot Occupant Type IDs
*/
export const preneedOwnerLotOccupantTypeId =
(await cacheFunctions.getBurialSiteOccupantTypeByLotOccupantType('Preneed Owner'))!
.lotOccupantTypeId
export const funeralDirectorLotOccupantTypeId =
(await cacheFunctions.getBurialSiteOccupantTypeByLotOccupantType(
'Funeral Director'
))!.lotOccupantTypeId
export const deceasedLotOccupantTypeId =
(await cacheFunctions.getBurialSiteOccupantTypeByLotOccupantType('Deceased'))!
.lotOccupantTypeId
export const purchaserLotOccupantTypeId =
(await cacheFunctions.getBurialSiteOccupantTypeByLotOccupantType('Purchaser'))!
.lotOccupantTypeId
/*
* Lot Status IDs
*/
export const availableburialSiteStatusId =
(await cacheFunctions.getBurialSiteStatusByLotStatus('Available'))!.burialSiteStatusId
export const reservedburialSiteStatusId =
(await cacheFunctions.getBurialSiteStatusByLotStatus('Reserved'))!.burialSiteStatusId
export const takenburialSiteStatusId = (await cacheFunctions.getBurialSiteStatusByLotStatus(
'Taken'
))!.burialSiteStatusId
/*
* Lot Type IDs
*/
const casketburialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType(
'Casket Grave'
))!.burialSiteTypeId
const columbariumburialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType(
'Columbarium'
))!.burialSiteTypeId
const crematoriumburialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType(
'Crematorium'
))!.burialSiteTypeId
const mausoleumburialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType(
'Mausoleum'
))!.burialSiteTypeId
const nicheWallburialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType(
'Niche Wall'
))!.burialSiteTypeId
const urnGardenburialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType(
'Urn Garden'
))!.burialSiteTypeId
export function getburialSiteTypeId(dataRow: { cemetery: string }): number {
switch (dataRow.cemetery) {
case '00': {
return crematoriumburialSiteTypeId
}
case 'GC':
case 'HC': {
return columbariumburialSiteTypeId
}
case 'MA': {
return mausoleumburialSiteTypeId
}
case 'MN':
case 'NW': {
return nicheWallburialSiteTypeId
}
case 'UG': {
return urnGardenburialSiteTypeId
}
}
return casketburialSiteTypeId
}
/*
* Occupancy Type IDs
*/
export const preneedContractType =
(await cacheFunctions.getContractTypeByContractType('Preneed'))!
export const deceasedContractType =
(await cacheFunctions.getContractTypeByContractType('Interment'))!
export const cremationContractType =
(await cacheFunctions.getContractTypeByContractType('Cremation'))!
/*
* Work Order Milestone Type IDs
*/
export const acknowledgedWorkOrderMilestoneTypeId = (
await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType(
'Acknowledged'
)
)?.workOrderMilestoneTypeId
export const deathWorkOrderMilestoneTypeId = (
await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType(
'Death'
)
)?.workOrderMilestoneTypeId
export const funeralWorkOrderMilestoneTypeId = (
await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType(
'Funeral'
)
)?.workOrderMilestoneTypeId
export const cremationWorkOrderMilestoneTypeId = (
await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType(
'Cremation'
)
)?.workOrderMilestoneTypeId
export const intermentWorkOrderMilestoneTypeId = (
await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType(
'Interment'
)
)?.workOrderMilestoneTypeId
/*
* Work Order Type IDs
*/
export const workOrderTypeId = 1

View File

@ -0,0 +1 @@
export declare function getBurialSiteTypeId(cemeteryKey: string): number;

View File

@ -0,0 +1,35 @@
import * as cacheFunctions from '../../helpers/functions.cache.js';
const casketBurialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType('Casket Grave'))
.burialSiteTypeId;
const columbariumBurialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType('Columbarium'))
.burialSiteTypeId;
const cremationBurialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType('Crematorium'))
.burialSiteTypeId;
const mausoleumBurialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType('Mausoleum'))
.burialSiteTypeId;
const nicheWallBurialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType('Niche Wall'))
.burialSiteTypeId;
const urnGardenBurialSiteTypeId = (await cacheFunctions.getBurialSiteTypesByBurialSiteType('Urn Garden'))
.burialSiteTypeId;
export function getBurialSiteTypeId(cemeteryKey) {
switch (cemeteryKey) {
case '00': {
return cremationBurialSiteTypeId;
}
case 'GC':
case 'HC': {
return columbariumBurialSiteTypeId;
}
case 'MA': {
return mausoleumBurialSiteTypeId;
}
case 'MN':
case 'NW': {
return nicheWallBurialSiteTypeId;
}
case 'UG': {
return urnGardenBurialSiteTypeId;
}
}
return casketBurialSiteTypeId;
}

View File

@ -0,0 +1,45 @@
import * as cacheFunctions from '../../helpers/functions.cache.js'
const casketBurialSiteTypeId =
(await cacheFunctions.getBurialSiteTypesByBurialSiteType('Casket Grave'))!
.burialSiteTypeId
const columbariumBurialSiteTypeId =
(await cacheFunctions.getBurialSiteTypesByBurialSiteType('Columbarium'))!
.burialSiteTypeId
const cremationBurialSiteTypeId =
(await cacheFunctions.getBurialSiteTypesByBurialSiteType('Crematorium'))!
.burialSiteTypeId
const mausoleumBurialSiteTypeId =
(await cacheFunctions.getBurialSiteTypesByBurialSiteType('Mausoleum'))!
.burialSiteTypeId
const nicheWallBurialSiteTypeId =
(await cacheFunctions.getBurialSiteTypesByBurialSiteType('Niche Wall'))!
.burialSiteTypeId
const urnGardenBurialSiteTypeId =
(await cacheFunctions.getBurialSiteTypesByBurialSiteType('Urn Garden'))!
.burialSiteTypeId
export function getBurialSiteTypeId(cemeteryKey: string): number {
switch (cemeteryKey) {
case '00': {
return cremationBurialSiteTypeId
}
case 'GC':
case 'HC': {
return columbariumBurialSiteTypeId
}
case 'MA': {
return mausoleumBurialSiteTypeId
}
case 'MN':
case 'NW': {
return nicheWallBurialSiteTypeId
}
case 'UG': {
return urnGardenBurialSiteTypeId
}
}
return casketBurialSiteTypeId
}

View File

@ -0,0 +1 @@
export declare function getCemeteryIdByKey(cemeteryKey: string, user: User): Promise<number>;

View File

@ -0,0 +1,51 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable no-console */
import addCemetery from '../../database/addCemetery.js';
import { getCemeteryByKey } from '../../database/getCemetery.js';
const cemeteryToCemeteryName = {
'00': 'Crematorium',
GC: 'New Greenwood - Columbarium',
HC: 'Holy Sepulchre - Columbarium',
HS: 'Holy Sepulchre',
MA: 'Holy Sepulchre - Mausoleum',
MN: 'Mausoleum Niche',
NG: 'New Greenwood',
NW: 'Niche Wall',
OG: 'Old Greenwood',
PG: 'Pine Grove',
UG: 'New Greenwood - Urn Garden',
WK: 'West Korah',
WS: 'West Section'
};
const cemeteryCache = new Map();
export async function getCemeteryIdByKey(cemeteryKey, user) {
/*
if (masterRow.CM_CEMETERY === "HS" &&
(masterRow.CM_BLOCK === "F" || masterRow.CM_BLOCK === "G" || masterRow.CM_BLOCK === "H" || masterRow.CM_BLOCK === "J")) {
mapCacheKey += "-" + masterRow.CM_BLOCK;
}
*/
if (cemeteryCache.has(cemeteryKey)) {
return cemeteryCache.get(cemeteryKey);
}
const cemetery = await getCemeteryByKey(cemeteryKey);
if (cemetery === undefined) {
console.log(`Creating cemetery: ${cemeteryKey}`);
const cemeteryId = await addCemetery({
cemeteryName: cemeteryToCemeteryName[cemeteryKey] ?? cemeteryKey,
cemeteryKey,
cemeteryDescription: '',
cemeterySvg: '',
cemeteryLatitude: '',
cemeteryLongitude: '',
cemeteryAddress1: '',
cemeteryAddress2: '',
cemeteryCity: 'Sault Ste. Marie',
cemeteryProvince: 'ON',
cemeteryPostalCode: '',
cemeteryPhoneNumber: ''
}, user);
cemeteryCache.set(cemeteryKey, cemeteryId);
}
return cemeteryCache.get(cemeteryKey);
}

View File

@ -0,0 +1,67 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable no-console */
import addCemetery from '../../database/addCemetery.js'
import { getCemeteryByKey } from '../../database/getCemetery.js'
const cemeteryToCemeteryName = {
'00': 'Crematorium',
GC: 'New Greenwood - Columbarium',
HC: 'Holy Sepulchre - Columbarium',
HS: 'Holy Sepulchre',
MA: 'Holy Sepulchre - Mausoleum',
MN: 'Mausoleum Niche',
NG: 'New Greenwood',
NW: 'Niche Wall',
OG: 'Old Greenwood',
PG: 'Pine Grove',
UG: 'New Greenwood - Urn Garden',
WK: 'West Korah',
WS: 'West Section'
}
const cemeteryCache = new Map<string, number>()
export async function getCemeteryIdByKey(
cemeteryKey: string,
user: User
): Promise<number> {
/*
if (masterRow.CM_CEMETERY === "HS" &&
(masterRow.CM_BLOCK === "F" || masterRow.CM_BLOCK === "G" || masterRow.CM_BLOCK === "H" || masterRow.CM_BLOCK === "J")) {
mapCacheKey += "-" + masterRow.CM_BLOCK;
}
*/
if (cemeteryCache.has(cemeteryKey)) {
return cemeteryCache.get(cemeteryKey) as number
}
const cemetery = await getCemeteryByKey(cemeteryKey)
if (cemetery === undefined) {
console.log(`Creating cemetery: ${cemeteryKey}`)
const cemeteryId = await addCemetery(
{
cemeteryName: cemeteryToCemeteryName[cemeteryKey] ?? cemeteryKey,
cemeteryKey,
cemeteryDescription: '',
cemeterySvg: '',
cemeteryLatitude: '',
cemeteryLongitude: '',
cemeteryAddress1: '',
cemeteryAddress2: '',
cemeteryCity: 'Sault Ste. Marie',
cemeteryProvince: 'ON',
cemeteryPostalCode: '',
cemeteryPhoneNumber: ''
},
user
)
cemeteryCache.set(cemeteryKey, cemeteryId)
}
return cemeteryCache.get(cemeteryKey) as number
}

View File

@ -0,0 +1 @@
export declare function getCommittalTypeIdByKey(committalTypeKey: string, user: User): Promise<number>;

View File

@ -0,0 +1,16 @@
import addCommittalType from "../../database/addCommittalType.js";
import getCommittalTypes from "../../database/getCommittalTypes.js";
let committalTypes = await getCommittalTypes();
export async function getCommittalTypeIdByKey(committalTypeKey, user) {
const committalType = committalTypes.find((committalType) => committalType.committalTypeKey ===
committalTypeKey);
if (committalType === undefined) {
const committalTypeId = await addCommittalType({
committalTypeKey,
committalType: committalTypeKey
}, user);
committalTypes = await getCommittalTypes();
return committalTypeId;
}
return committalType.committalTypeId;
}

View File

@ -0,0 +1,31 @@
import addCommittalType from "../../database/addCommittalType.js";
import getCommittalTypes from "../../database/getCommittalTypes.js";
let committalTypes = await getCommittalTypes()
export async function getCommittalTypeIdByKey(
committalTypeKey: string,
user: User
): Promise<number> {
const committalType = committalTypes.find(
(committalType) =>
committalType.committalTypeKey ===
committalTypeKey
)
if (committalType === undefined) {
const committalTypeId = await addCommittalType(
{
committalTypeKey,
committalType: committalTypeKey
},
user
)
committalTypes = await getCommittalTypes()
return committalTypeId
}
return committalType.committalTypeId
}

View File

@ -0,0 +1 @@
export declare function getDeathAgePeriod(legacyDeathAgePeriod: string): string;

View File

@ -0,0 +1,16 @@
export function getDeathAgePeriod(legacyDeathAgePeriod) {
switch (legacyDeathAgePeriod.toLowerCase()) {
case 'yrs': {
return 'Years';
}
case 'mts': {
return 'Months';
}
case 'dys': {
return 'Days';
}
default: {
return legacyDeathAgePeriod;
}
}
}

View File

@ -0,0 +1,17 @@
export function getDeathAgePeriod(legacyDeathAgePeriod: string): string {
switch (legacyDeathAgePeriod.toLowerCase()) {
case 'yrs': {
return 'Years'
}
case 'mts': {
return 'Months'
}
case 'dys': {
return 'Days'
}
default: {
return legacyDeathAgePeriod
}
}
}

View File

@ -0,0 +1 @@
export declare function getFeeIdByFeeDescription(feeDescription: string, user: User): Promise<number>;

View File

@ -0,0 +1,37 @@
import sqlite from 'better-sqlite3';
import addFee from '../../database/addFee.js';
import { sunriseDB as databasePath } from '../../helpers/database.helpers.js';
let feeCategoryId = 0;
const feeCache = new Map();
export async function getFeeIdByFeeDescription(feeDescription, user) {
if (feeCache.keys.length === 0) {
const database = sqlite(databasePath, {
readonly: true
});
const records = database
.prepare(`select feeId, feeCategoryId, feeDescription
from Fees
where feeDescription like 'CMPP_FEE_%'`)
.all();
for (const record of records) {
if (feeCategoryId === 0) {
feeCategoryId = record.feeCategoryId;
}
feeCache.set(record.feeDescription, record.feeId);
}
database.close();
}
let feeId = feeCache.get(feeDescription);
if (feeId === undefined) {
feeId = await addFee({
feeName: feeDescription.slice(9),
feeDescription,
feeCategoryId,
feeAccount: '',
contractTypeId: '',
burialSiteTypeId: ''
}, user);
feeCache.set(feeDescription, feeId);
}
return feeId;
}

View File

@ -0,0 +1,61 @@
import sqlite from 'better-sqlite3'
import addFee from '../../database/addFee.js'
import { sunriseDB as databasePath } from '../../helpers/database.helpers.js'
let feeCategoryId = 0
const feeCache = new Map<string, number>()
export async function getFeeIdByFeeDescription(
feeDescription: string,
user: User
): Promise<number> {
if (feeCache.keys.length === 0) {
const database = sqlite(databasePath, {
readonly: true
})
const records = database
.prepare(
`select feeId, feeCategoryId, feeDescription
from Fees
where feeDescription like 'CMPP_FEE_%'`
)
.all() as Array<{
feeId: number
feeCategoryId: number
feeDescription: string
}>
for (const record of records) {
if (feeCategoryId === 0) {
feeCategoryId = record.feeCategoryId
}
feeCache.set(record.feeDescription, record.feeId)
}
database.close()
}
let feeId = feeCache.get(feeDescription)
if (feeId === undefined) {
feeId = await addFee(
{
feeName: feeDescription.slice(9),
feeDescription,
feeCategoryId,
feeAccount: '',
contractTypeId: '',
burialSiteTypeId: ''
},
user
)
feeCache.set(feeDescription, feeId)
}
return feeId
}

View File

@ -0,0 +1,2 @@
export declare function initializeFuneralHomes(user: User): Promise<void>;
export declare function getFuneralHomeIdByKey(funeralHomeKey: string, user: User): Promise<number>;

View File

@ -0,0 +1,106 @@
import addFuneralHome from "../../database/addFuneralHome.js";
const funeralHomes = [
{
funeralHomeKey: 'AR',
funeralHomeName: 'Arthur Funeral Home',
funeralHomeAddress1: '492 Wellington Street East',
funeralHomeAddress2: '',
funeralHomeCity: 'Sault Ste. Marie',
funeralHomeProvince: 'ON',
funeralHomePostalCode: 'P6A 2L9',
funeralHomePhoneNumber: '705-759-2522'
},
{
funeralHomeKey: 'BG',
funeralHomeName: 'Beggs Funeral Home',
funeralHomeAddress1: '175 Main Street',
funeralHomeAddress2: 'P.O. Box 280',
funeralHomeCity: 'Thessalon',
funeralHomeProvince: 'ON',
funeralHomePostalCode: 'P0R 1L0',
funeralHomePhoneNumber: '705-842-2520'
},
{
funeralHomeKey: 'BK',
funeralHomeName: 'Barton and Kiteley',
funeralHomeAddress1: '',
funeralHomeAddress2: '',
funeralHomeCity: 'Sault Ste. Marie',
funeralHomeProvince: 'ON',
funeralHomePostalCode: '',
funeralHomePhoneNumber: ''
},
{
funeralHomeKey: 'DA',
funeralHomeName: 'Damignani Burial, Cremation and Transfer Service',
funeralHomeAddress1: '215 St. James Street',
funeralHomeAddress2: '',
funeralHomeCity: 'Sault Ste. Marie',
funeralHomeProvince: 'ON',
funeralHomePostalCode: 'P6A 1P7',
funeralHomePhoneNumber: '705-759-8456'
},
{
funeralHomeKey: 'GL',
funeralHomeName: 'Gilmartin P.M. Funeral Home',
funeralHomeAddress1: '140 Churchill Avenue',
funeralHomeAddress2: '',
funeralHomeCity: 'Wawa',
funeralHomeProvince: 'ON',
funeralHomePostalCode: 'P0S 1K0',
funeralHomePhoneNumber: '705-856-7340'
},
{
funeralHomeKey: 'NO',
funeralHomeName: 'Northwood Funeral Home',
funeralHomeAddress1: '942 Great Northern Road',
funeralHomeAddress2: '',
funeralHomeCity: 'Sault Ste. Marie',
funeralHomeProvince: 'ON',
funeralHomePostalCode: 'P6B 0B6',
funeralHomePhoneNumber: '705-945-7758'
},
{
funeralHomeKey: 'OS',
funeralHomeName: "O'Sullivan Funeral Home",
funeralHomeAddress1: '215 St. James Street',
funeralHomeAddress2: '',
funeralHomeCity: 'Sault Ste. Marie',
funeralHomeProvince: 'ON',
funeralHomePostalCode: 'P6A 1P7',
funeralHomePhoneNumber: '705-759-8456'
}
];
const funeralHomeKeyToId = new Map();
export async function initializeFuneralHomes(user) {
for (const funeralHome of funeralHomes) {
const funeralHomeId = await addFuneralHome({
funeralHomeName: funeralHome.funeralHomeName ?? '',
funeralHomeKey: funeralHome.funeralHomeKey ?? '',
funeralHomeAddress1: funeralHome.funeralHomeAddress1 ?? '',
funeralHomeAddress2: funeralHome.funeralHomeAddress2 ?? '',
funeralHomeCity: funeralHome.funeralHomeCity ?? '',
funeralHomeProvince: funeralHome.funeralHomeProvince ?? '',
funeralHomePostalCode: funeralHome.funeralHomePostalCode ?? '',
funeralHomePhoneNumber: funeralHome.funeralHomePhoneNumber ?? ''
}, user);
funeralHomeKeyToId.set(funeralHome.funeralHomeKey ?? '', funeralHomeId);
}
}
export async function getFuneralHomeIdByKey(funeralHomeKey, user) {
if (funeralHomeKeyToId.has(funeralHomeKey)) {
return funeralHomeKeyToId.get(funeralHomeKey);
}
const funeralHomeId = await addFuneralHome({
funeralHomeName: funeralHomeKey,
funeralHomeKey,
funeralHomeAddress1: '',
funeralHomeAddress2: '',
funeralHomeCity: '',
funeralHomeProvince: '',
funeralHomePostalCode: '',
funeralHomePhoneNumber: ''
}, user);
funeralHomeKeyToId.set(funeralHomeKey, funeralHomeId);
return funeralHomeId;
}

View File

@ -0,0 +1,124 @@
import addFuneralHome from "../../database/addFuneralHome.js"
import type { FuneralHome } from "../../types/recordTypes.js"
const funeralHomes: FuneralHome[] = [
{
funeralHomeKey: 'AR',
funeralHomeName: 'Arthur Funeral Home',
funeralHomeAddress1: '492 Wellington Street East',
funeralHomeAddress2: '',
funeralHomeCity: 'Sault Ste. Marie',
funeralHomeProvince: 'ON',
funeralHomePostalCode: 'P6A 2L9',
funeralHomePhoneNumber: '705-759-2522'
},
{
funeralHomeKey: 'BG',
funeralHomeName: 'Beggs Funeral Home',
funeralHomeAddress1: '175 Main Street',
funeralHomeAddress2: 'P.O. Box 280',
funeralHomeCity: 'Thessalon',
funeralHomeProvince: 'ON',
funeralHomePostalCode: 'P0R 1L0',
funeralHomePhoneNumber: '705-842-2520'
},
{
funeralHomeKey: 'BK',
funeralHomeName: 'Barton and Kiteley',
funeralHomeAddress1: '',
funeralHomeAddress2: '',
funeralHomeCity: 'Sault Ste. Marie',
funeralHomeProvince: 'ON',
funeralHomePostalCode: '',
funeralHomePhoneNumber: ''
},
{
funeralHomeKey: 'DA',
funeralHomeName: 'Damignani Burial, Cremation and Transfer Service',
funeralHomeAddress1: '215 St. James Street',
funeralHomeAddress2: '',
funeralHomeCity: 'Sault Ste. Marie',
funeralHomeProvince: 'ON',
funeralHomePostalCode: 'P6A 1P7',
funeralHomePhoneNumber: '705-759-8456'
},
{
funeralHomeKey: 'GL',
funeralHomeName: 'Gilmartin P.M. Funeral Home',
funeralHomeAddress1: '140 Churchill Avenue',
funeralHomeAddress2: '',
funeralHomeCity: 'Wawa',
funeralHomeProvince: 'ON',
funeralHomePostalCode: 'P0S 1K0',
funeralHomePhoneNumber: '705-856-7340'
},
{
funeralHomeKey: 'NO',
funeralHomeName: 'Northwood Funeral Home',
funeralHomeAddress1: '942 Great Northern Road',
funeralHomeAddress2: '',
funeralHomeCity: 'Sault Ste. Marie',
funeralHomeProvince: 'ON',
funeralHomePostalCode: 'P6B 0B6',
funeralHomePhoneNumber: '705-945-7758'
},
{
funeralHomeKey: 'OS',
funeralHomeName: "O'Sullivan Funeral Home",
funeralHomeAddress1: '215 St. James Street',
funeralHomeAddress2: '',
funeralHomeCity: 'Sault Ste. Marie',
funeralHomeProvince: 'ON',
funeralHomePostalCode: 'P6A 1P7',
funeralHomePhoneNumber: '705-759-8456'
}
]
const funeralHomeKeyToId = new Map<string, number>()
export async function initializeFuneralHomes(user: User): Promise<void> {
for (const funeralHome of funeralHomes) {
const funeralHomeId = await addFuneralHome(
{
funeralHomeName: funeralHome.funeralHomeName ?? '',
funeralHomeKey: funeralHome.funeralHomeKey ?? '',
funeralHomeAddress1: funeralHome.funeralHomeAddress1 ?? '',
funeralHomeAddress2: funeralHome.funeralHomeAddress2 ?? '',
funeralHomeCity: funeralHome.funeralHomeCity ?? '',
funeralHomeProvince: funeralHome.funeralHomeProvince ?? '',
funeralHomePostalCode: funeralHome.funeralHomePostalCode ?? '',
funeralHomePhoneNumber: funeralHome.funeralHomePhoneNumber ?? ''
},
user
)
funeralHomeKeyToId.set(funeralHome.funeralHomeKey ?? '', funeralHomeId)
}
}
export async function getFuneralHomeIdByKey(
funeralHomeKey: string,
user: User
): Promise<number> {
if (funeralHomeKeyToId.has(funeralHomeKey)) {
return funeralHomeKeyToId.get(funeralHomeKey) as number
}
const funeralHomeId = await addFuneralHome(
{
funeralHomeName: funeralHomeKey,
funeralHomeKey,
funeralHomeAddress1: '',
funeralHomeAddress2: '',
funeralHomeCity: '',
funeralHomeProvince: '',
funeralHomePostalCode: '',
funeralHomePhoneNumber: ''
},
user
)
funeralHomeKeyToId.set(funeralHomeKey, funeralHomeId)
return funeralHomeId
}

View File

@ -0,0 +1,12 @@
export declare const availableBurialSiteStatusId: number;
export declare const reservedBurialSiteStatusId: number;
export declare const takenBurialSiteStatusId: number;
export declare const preneedContractType: import("../../types/recordTypes.js").ContractType;
export declare const deceasedContractType: import("../../types/recordTypes.js").ContractType;
export declare const cremationContractType: import("../../types/recordTypes.js").ContractType;
export declare const acknowledgedWorkOrderMilestoneTypeId: number | undefined;
export declare const deathWorkOrderMilestoneTypeId: number | undefined;
export declare const funeralWorkOrderMilestoneTypeId: number | undefined;
export declare const cremationWorkOrderMilestoneTypeId: number | undefined;
export declare const intermentWorkOrderMilestoneTypeId: number | undefined;
export declare const workOrderTypeId = 1;

View File

@ -0,0 +1,30 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/no-await-expression-member */
import * as cacheFunctions from '../../helpers/functions.cache.js';
/*
* Burial Site Status IDs
*/
export const availableBurialSiteStatusId = (await cacheFunctions.getBurialSiteStatusByBurialSiteStatus('Available'))
.burialSiteStatusId;
export const reservedBurialSiteStatusId = (await cacheFunctions.getBurialSiteStatusByBurialSiteStatus('Reserved'))
.burialSiteStatusId;
export const takenBurialSiteStatusId = (await cacheFunctions.getBurialSiteStatusByBurialSiteStatus('Taken'))
.burialSiteStatusId;
/*
* Contract Type IDs
*/
export const preneedContractType = (await cacheFunctions.getContractTypeByContractType('Preneed'));
export const deceasedContractType = (await cacheFunctions.getContractTypeByContractType('Interment'));
export const cremationContractType = (await cacheFunctions.getContractTypeByContractType('Cremation'));
/*
* Work Order Milestone Type IDs
*/
export const acknowledgedWorkOrderMilestoneTypeId = (await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Acknowledged'))?.workOrderMilestoneTypeId;
export const deathWorkOrderMilestoneTypeId = (await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Death'))?.workOrderMilestoneTypeId;
export const funeralWorkOrderMilestoneTypeId = (await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Funeral'))?.workOrderMilestoneTypeId;
export const cremationWorkOrderMilestoneTypeId = (await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Cremation'))?.workOrderMilestoneTypeId;
export const intermentWorkOrderMilestoneTypeId = (await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Interment'))?.workOrderMilestoneTypeId;
/*
* Work Order Type IDs
*/
export const workOrderTypeId = 1;

View File

@ -0,0 +1,74 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/no-await-expression-member */
import * as cacheFunctions from '../../helpers/functions.cache.js'
/*
* Burial Site Status IDs
*/
export const availableBurialSiteStatusId =
(await cacheFunctions.getBurialSiteStatusByBurialSiteStatus('Available'))!
.burialSiteStatusId
export const reservedBurialSiteStatusId =
(await cacheFunctions.getBurialSiteStatusByBurialSiteStatus('Reserved'))!
.burialSiteStatusId
export const takenBurialSiteStatusId =
(await cacheFunctions.getBurialSiteStatusByBurialSiteStatus('Taken'))!
.burialSiteStatusId
/*
* Contract Type IDs
*/
export const preneedContractType =
(await cacheFunctions.getContractTypeByContractType('Preneed'))!
export const deceasedContractType =
(await cacheFunctions.getContractTypeByContractType('Interment'))!
export const cremationContractType =
(await cacheFunctions.getContractTypeByContractType('Cremation'))!
/*
* Work Order Milestone Type IDs
*/
export const acknowledgedWorkOrderMilestoneTypeId = (
await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType(
'Acknowledged'
)
)?.workOrderMilestoneTypeId
export const deathWorkOrderMilestoneTypeId = (
await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType(
'Death'
)
)?.workOrderMilestoneTypeId
export const funeralWorkOrderMilestoneTypeId = (
await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType(
'Funeral'
)
)?.workOrderMilestoneTypeId
export const cremationWorkOrderMilestoneTypeId = (
await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType(
'Cremation'
)
)?.workOrderMilestoneTypeId
export const intermentWorkOrderMilestoneTypeId = (
await cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType(
'Interment'
)
)?.workOrderMilestoneTypeId
/*
* Work Order Type IDs
*/
export const workOrderTypeId = 1

View File

@ -0,0 +1 @@
export declare function getIntermentContainerTypeIdByKey(intermentContainerTypeKey: string, user: User): Promise<number>;

View File

@ -0,0 +1,16 @@
import addIntermentContainerType from '../../database/addIntermentContainerType.js';
import getIntermentContainerTypes from '../../database/getIntermentContainerTypes.js';
let intermentContainerTypes = await getIntermentContainerTypes();
export async function getIntermentContainerTypeIdByKey(intermentContainerTypeKey, user) {
const intermentContainerType = intermentContainerTypes.find((intermentContainerType) => intermentContainerType.intermentContainerTypeKey ===
intermentContainerTypeKey);
if (intermentContainerType === undefined) {
const intermentContainerTypeId = await addIntermentContainerType({
intermentContainerTypeKey,
intermentContainerType: intermentContainerTypeKey
}, user);
intermentContainerTypes = await getIntermentContainerTypes();
return intermentContainerTypeId;
}
return intermentContainerType.intermentContainerTypeId;
}

View File

@ -0,0 +1,31 @@
import addIntermentContainerType from '../../database/addIntermentContainerType.js'
import getIntermentContainerTypes from '../../database/getIntermentContainerTypes.js'
let intermentContainerTypes = await getIntermentContainerTypes()
export async function getIntermentContainerTypeIdByKey(
intermentContainerTypeKey: string,
user: User
): Promise<number> {
const intermentContainerType = intermentContainerTypes.find(
(intermentContainerType) =>
intermentContainerType.intermentContainerTypeKey ===
intermentContainerTypeKey
)
if (intermentContainerType === undefined) {
const intermentContainerTypeId = await addIntermentContainerType(
{
intermentContainerTypeKey,
intermentContainerType: intermentContainerTypeKey
},
user
)
intermentContainerTypes = await getIntermentContainerTypes()
return intermentContainerTypeId
}
return intermentContainerType.intermentContainerTypeId
}

View File

@ -0,0 +1,818 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable @cspell/spellchecker, @typescript-eslint/no-non-null-assertion, no-console, max-lines */
import fs from 'node:fs';
import { dateIntegerToString, dateToString } from '@cityssm/utils-datetime';
import sqlite from 'better-sqlite3';
import papa from 'papaparse';
import addBurialSite from '../../database/addBurialSite.js';
import addContract from '../../database/addContract.js';
import addContractComment from '../../database/addContractComment.js';
import addContractFee from '../../database/addContractFee.js';
import addContractTransaction from '../../database/addContractTransaction.js';
import addWorkOrder from '../../database/addWorkOrder.js';
import addWorkOrderBurialSite from '../../database/addWorkOrderBurialSite.js';
import addWorkOrderContract from '../../database/addWorkOrderContract.js';
import addWorkOrderMilestone from '../../database/addWorkOrderMilestone.js';
import closeWorkOrder from '../../database/closeWorkOrder.js';
import getBurialSite, { getBurialSiteByBurialSiteName } from '../../database/getBurialSite.js';
import getContracts from '../../database/getContracts.js';
import getWorkOrder, { getWorkOrderByWorkOrderNumber } from '../../database/getWorkOrder.js';
import reopenWorkOrder from '../../database/reopenWorkOrder.js';
import { updateBurialSiteStatus } from '../../database/updateBurialSite.js';
import { buildBurialSiteName } from '../../helpers/burialSites.helpers.js';
import { sunriseDB as databasePath } from '../../helpers/database.helpers.js';
import { getBurialSiteTypeId } from './data.burialSiteTypes.js';
import { getCemeteryIdByKey } from './data.cemeteries.js';
import { getCommittalTypeIdByKey } from './data.committalTypes.js';
import { getDeathAgePeriod } from './data.deathAgePeriods.js';
import { getFeeIdByFeeDescription } from './data.fees.js';
import { getFuneralHomeIdByKey } from './data.funeralHomes.js';
import * as importIds from './data.ids.js';
import { getIntermentContainerTypeIdByKey } from './data.intermentContainerTypes.js';
const user = {
userName: 'import.unix',
userProperties: {
canUpdate: true,
isAdmin: false,
apiKey: ''
}
};
function purgeTables() {
console.time('purgeTables');
const tablesToPurge = [
'WorkOrderMilestones',
'WorkOrderComments',
'WorkOrderBurialSites',
'WorkOrderContracts',
'WorkOrders',
'ContractTransactions',
'ContractFees',
'ContractFields',
'ContractComments',
'ContractInterments',
'Contracts',
'FuneralHomes',
'BurialSiteFields',
'BurialSiteComments',
'BurialSites'
];
const database = sqlite(databasePath);
for (const tableName of tablesToPurge) {
database.prepare(`delete from ${tableName}`).run();
database
.prepare('delete from sqlite_sequence where name = ?')
.run(tableName);
}
database.close();
console.timeEnd('purgeTables');
}
function purgeConfigTables() {
console.time('purgeConfigTables');
const database = sqlite(databasePath);
database.prepare('delete from Cemeteries').run();
database
.prepare("delete from sqlite_sequence where name in ('Cemeteries')")
.run();
database.close();
console.timeEnd('purgeConfigTables');
}
function formatDateString(year, month, day) {
const formattedYear = `0000${year}`.slice(-4);
const formattedMonth = `00${month}`.slice(-2);
const formattedDay = `00${day}`.slice(-2);
return `${formattedYear}-${formattedMonth}-${formattedDay}`;
}
function formatTimeString(hour, minute) {
const formattedHour = `00${hour}`.slice(-2);
const formattedMinute = `00${minute}`.slice(-2);
return `${formattedHour}:${formattedMinute}`;
}
// eslint-disable-next-line complexity
async function importFromMasterCSV() {
console.time('importFromMasterCSV');
let masterRow;
const rawData = fs.readFileSync('./temp/CMMASTER.csv').toString();
const cmmaster = papa.parse(rawData, {
delimiter: ',',
header: true,
skipEmptyLines: true
});
for (const parseError of cmmaster.errors) {
console.log(parseError);
}
try {
for (masterRow of cmmaster.data) {
const cemeteryId = await getCemeteryIdByKey(masterRow.CM_CEMETERY, user);
const burialSiteTypeId = getBurialSiteTypeId(masterRow.CM_CEMETERY);
let burialSiteId;
if (masterRow.CM_CEMETERY !== '00') {
const burialSiteNameSegment1 = masterRow.CM_BLOCK === '0' ? '' : masterRow.CM_BLOCK;
const burialSiteNameSegment2 = (masterRow.CM_RANGE1 === '0' ? '' : masterRow.CM_RANGE1) +
(masterRow.CM_RANGE2 === '0' ? '' : masterRow.CM_RANGE2);
const burialSiteNameSegment3 = (masterRow.CM_LOT1 === '0' ? '' : masterRow.CM_LOT1) +
(masterRow.CM_LOT2 === '0' ? '' : masterRow.CM_LOT2);
const burialSiteNameSegment4 = (masterRow.CM_GRAVE1 === '0' ? '' : masterRow.CM_GRAVE1) +
(masterRow.CM_GRAVE2 === '0' ? '' : masterRow.CM_GRAVE2);
const burialSiteName = buildBurialSiteName(masterRow.CM_CEMETERY, {
burialSiteNameSegment1,
burialSiteNameSegment2,
burialSiteNameSegment3,
burialSiteNameSegment4
});
const burialSite = await getBurialSiteByBurialSiteName(burialSiteName);
burialSiteId =
burialSite === undefined
? await addBurialSite({
burialSiteNameSegment1,
burialSiteNameSegment2,
burialSiteNameSegment3,
burialSiteNameSegment4,
burialSiteTypeId,
burialSiteStatusId: importIds.availableBurialSiteStatusId,
cemeteryId,
cemeterySvgId: '',
burialSiteLatitude: '',
burialSiteLongitude: ''
}, user)
: burialSite.burialSiteId;
}
/*
* Preneed Record
*/
let preneedContractStartDateString;
let preneedContractId;
if (masterRow.CM_PRENEED_OWNER !== '' || masterRow.CM_STATUS === 'P') {
preneedContractStartDateString = formatDateString(masterRow.CM_PURCHASE_YR, masterRow.CM_PURCHASE_MON, masterRow.CM_PURCHASE_DAY);
let contractEndDateString = '';
if (masterRow.CM_INTERMENT_YR !== '' &&
masterRow.CM_INTERMENT_YR !== '0') {
contractEndDateString = formatDateString(masterRow.CM_INTERMENT_YR, masterRow.CM_INTERMENT_MON, masterRow.CM_INTERMENT_DAY);
}
// if purchase date unavailable
if (preneedContractStartDateString === '0000-00-00' &&
contractEndDateString !== '') {
preneedContractStartDateString = contractEndDateString;
}
// if end date unavailable
if (preneedContractStartDateString === '0000-00-00' &&
masterRow.CM_DEATH_YR !== '' &&
masterRow.CM_DEATH_YR !== '0') {
preneedContractStartDateString = formatDateString(masterRow.CM_DEATH_YR, masterRow.CM_DEATH_MON, masterRow.CM_DEATH_DAY);
// if death took place, and there's no preneed end date
if (contractEndDateString === '0000-00-00' ||
contractEndDateString === '') {
contractEndDateString = preneedContractStartDateString;
}
}
if (preneedContractStartDateString === '' ||
preneedContractStartDateString === '0000-00-00') {
preneedContractStartDateString = '0001-01-01';
}
const purchaserPostalCode = `${masterRow.CM_POST1} ${masterRow.CM_POST2}`.trim();
preneedContractId = await addContract({
contractTypeId: importIds.preneedContractType.contractTypeId,
burialSiteId: burialSiteId ?? '',
contractStartDateString: preneedContractStartDateString,
contractEndDateString,
contractTypeFieldIds: '',
purchaserName: masterRow.CM_PRENEED_OWNER,
purchaserAddress1: masterRow.CM_ADDRESS,
purchaserAddress2: '',
purchaserCity: masterRow.CM_CITY,
purchaserProvince: masterRow.CM_PROV,
purchaserPostalCode,
purchaserPhoneNumber: '',
purchaserEmail: '',
deceasedName: masterRow.CM_DECEASED_NAME === ''
? masterRow.CM_PRENEED_OWNER
: masterRow.CM_DECEASED_NAME,
deceasedAddress1: masterRow.CM_ADDRESS,
deceasedAddress2: '',
deceasedCity: masterRow.CM_CITY,
deceasedProvince: masterRow.CM_PROV,
deceasedPostalCode: purchaserPostalCode
}, user);
if (masterRow.CM_REMARK1 !== '') {
await addContractComment({
contractId: preneedContractId,
commentDateString: preneedContractStartDateString,
commentTimeString: '00:00',
comment: masterRow.CM_REMARK1
}, user);
}
if (masterRow.CM_REMARK2 !== '') {
await addContractComment({
contractId: preneedContractId,
commentDateString: preneedContractStartDateString,
commentTimeString: '00:00',
comment: masterRow.CM_REMARK2
}, user);
}
if (masterRow.CM_WORK_ORDER.trim() !== '') {
await addContractComment({
contractId: preneedContractId,
commentDateString: preneedContractStartDateString,
commentTimeString: '00:00',
comment: `Imported Contract #${masterRow.CM_WORK_ORDER}`
}, user);
}
if (contractEndDateString === '') {
await updateBurialSiteStatus(burialSiteId ?? '', importIds.reservedBurialSiteStatusId, user);
}
}
/*
* Interment Record
*/
let deceasedContractStartDateString;
let deceasedContractId;
if (masterRow.CM_DECEASED_NAME !== '') {
deceasedContractStartDateString = formatDateString(masterRow.CM_INTERMENT_YR, masterRow.CM_INTERMENT_MON, masterRow.CM_INTERMENT_DAY);
// if interment date unavailable
if (deceasedContractStartDateString === '0000-00-00' &&
masterRow.CM_DEATH_YR !== '' &&
masterRow.CM_DEATH_YR !== '0') {
deceasedContractStartDateString = formatDateString(masterRow.CM_DEATH_YR, masterRow.CM_DEATH_MON, masterRow.CM_DEATH_DAY);
}
if (deceasedContractStartDateString === '' ||
deceasedContractStartDateString === '0000-00-00') {
deceasedContractStartDateString = '0001-01-01';
}
const deceasedContractEndDateString = burialSiteId
? ''
: deceasedContractStartDateString;
const contractType = burialSiteId
? importIds.deceasedContractType
: importIds.cremationContractType;
const deceasedPostalCode = `${masterRow.CM_POST1} ${masterRow.CM_POST2}`.trim();
const funeralHomeId = masterRow.CM_FUNERAL_HOME === ''
? ''
: await getFuneralHomeIdByKey(masterRow.CM_FUNERAL_HOME, user);
const funeralDateString = masterRow.CM_FUNERAL_YR === ''
? ''
: formatDateString(masterRow.CM_FUNERAL_YR, masterRow.CM_FUNERAL_MON, masterRow.CM_FUNERAL_DAY);
const committalTypeId = contractType.contractType === 'Cremation' ||
masterRow.CM_COMMITTAL_TYPE === ''
? ''
: await getCommittalTypeIdByKey(masterRow.CM_COMMITTAL_TYPE, user);
const deathDateString = masterRow.CM_DEATH_YR === ''
? ''
: formatDateString(masterRow.CM_DEATH_YR, masterRow.CM_DEATH_MON, masterRow.CM_DEATH_DAY);
const intermentContainerTypeKey = contractType.contractType === 'Cremation' &&
masterRow.CM_CONTAINER_TYPE !== ''
? 'U'
: masterRow.CM_CONTAINER_TYPE;
const intermentContainerTypeId = intermentContainerTypeKey === ''
? ''
: await getIntermentContainerTypeIdByKey(intermentContainerTypeKey, user);
deceasedContractId = await addContract({
contractTypeId: contractType.contractTypeId,
burialSiteId: burialSiteId ?? '',
contractStartDateString: deceasedContractStartDateString,
contractEndDateString: deceasedContractEndDateString,
contractTypeFieldIds: '',
funeralHomeId,
funeralDirectorName: masterRow.CM_FUNERAL_HOME,
funeralDateString,
committalTypeId,
purchaserName: masterRow.CM_PRENEED_OWNER === ''
? masterRow.CM_DECEASED_NAME
: masterRow.CM_PRENEED_OWNER,
purchaserAddress1: masterRow.CM_ADDRESS,
purchaserAddress2: '',
purchaserCity: masterRow.CM_CITY,
purchaserProvince: masterRow.CM_PROV,
purchaserPostalCode: deceasedPostalCode,
purchaserPhoneNumber: '',
purchaserEmail: '',
deceasedName: masterRow.CM_DECEASED_NAME,
deceasedAddress1: masterRow.CM_ADDRESS,
deceasedAddress2: '',
deceasedCity: masterRow.CM_CITY,
deceasedProvince: masterRow.CM_PROV,
deceasedPostalCode,
birthDateString: '',
birthPlace: '',
deathDateString,
deathPlace: '',
deathAge: masterRow.CM_AGE,
deathAgePeriod: getDeathAgePeriod(masterRow.CM_PERIOD),
intermentContainerTypeId
}, user);
if (masterRow.CM_REMARK1 !== '') {
await addContractComment({
contractId: deceasedContractId,
commentDateString: deceasedContractStartDateString,
commentTimeString: '00:00',
comment: masterRow.CM_REMARK1
}, user);
}
if (masterRow.CM_REMARK2 !== '') {
await addContractComment({
contractId: deceasedContractId,
commentDateString: deceasedContractStartDateString,
commentTimeString: '00:00',
comment: masterRow.CM_REMARK2
}, user);
}
if (masterRow.CM_WORK_ORDER.trim() !== '') {
await addContractComment({
contractId: deceasedContractId,
commentDateString: deceasedContractStartDateString,
commentTimeString: '00:00',
comment: `Imported Contract #${masterRow.CM_WORK_ORDER}`
}, user);
}
await updateBurialSiteStatus(burialSiteId ?? '', importIds.takenBurialSiteStatusId, user);
}
}
}
catch (error) {
console.error(error);
console.log(masterRow);
}
console.timeEnd('importFromMasterCSV');
}
// eslint-disable-next-line complexity
async function importFromPrepaidCSV() {
console.time('importFromPrepaidCSV');
let prepaidRow;
const rawData = fs.readFileSync('./temp/CMPRPAID.csv').toString();
const cmprpaid = papa.parse(rawData, {
delimiter: ',',
header: true,
skipEmptyLines: true
});
for (const parseError of cmprpaid.errors) {
console.log(parseError);
}
try {
for (prepaidRow of cmprpaid.data) {
if (!prepaidRow.CMPP_PREPAID_FOR_NAME) {
continue;
}
let cemeteryKey = prepaidRow.CMPP_CEMETERY;
if (cemeteryKey === '.m') {
cemeteryKey = 'HC';
}
let burialSite;
if (cemeteryKey !== '') {
const cemeteryId = await getCemeteryIdByKey(cemeteryKey, user);
const burialSiteNameSegment1 = prepaidRow.CMPP_BLOCK === '0' ? '' : prepaidRow.CMPP_BLOCK;
const burialSiteNameSegment2 = (prepaidRow.CMPP_RANGE1 === '0' ? '' : prepaidRow.CMPP_RANGE1) +
(prepaidRow.CMPP_RANGE2 === '0' ? '' : prepaidRow.CMPP_RANGE2);
const burialSiteNameSegment3 = (prepaidRow.CMPP_LOT1 === '0' ? '' : prepaidRow.CMPP_LOT1) +
(prepaidRow.CMPP_LOT2 === '0' ? '' : prepaidRow.CMPP_LOT2);
const burialSiteNameSegment4 = (prepaidRow.CMPP_GRAVE1 === '0' ? '' : prepaidRow.CMPP_GRAVE1) +
(prepaidRow.CMPP_GRAVE2 === '0' ? '' : prepaidRow.CMPP_GRAVE2);
const burialSiteName = buildBurialSiteName(cemeteryKey, {
burialSiteNameSegment1,
burialSiteNameSegment2,
burialSiteNameSegment3,
burialSiteNameSegment4
});
burialSite = await getBurialSiteByBurialSiteName(burialSiteName);
if (!burialSite) {
const burialSiteTypeId = getBurialSiteTypeId(cemeteryKey);
const burialSiteId = await addBurialSite({
burialSiteNameSegment1,
burialSiteNameSegment2,
burialSiteNameSegment3,
burialSiteNameSegment4,
burialSiteTypeId,
burialSiteStatusId: importIds.reservedBurialSiteStatusId,
cemeteryId,
cemeterySvgId: burialSiteName.includes(',')
? burialSiteName.split(',')[0]
: burialSiteName,
burialSiteLatitude: '',
burialSiteLongitude: ''
}, user);
burialSite = await getBurialSite(burialSiteId);
}
}
if (burialSite &&
burialSite.burialSiteStatusId === importIds.availableBurialSiteStatusId) {
await updateBurialSiteStatus(burialSite.burialSiteId, importIds.reservedBurialSiteStatusId, user);
}
const contractStartDateString = formatDateString(prepaidRow.CMPP_PURCH_YR, prepaidRow.CMPP_PURCH_MON, prepaidRow.CMPP_PURCH_DAY);
let contractId;
if (burialSite) {
const possibleContracts = await getContracts({
burialSiteId: burialSite.burialSiteId,
contractTypeId: importIds.preneedContractType.contractTypeId,
deceasedName: prepaidRow.CMPP_PREPAID_FOR_NAME,
contractStartDateString
}, {
includeInterments: false,
includeFees: false,
includeTransactions: false,
limit: -1,
offset: 0
});
if (possibleContracts.contracts.length > 0) {
contractId = possibleContracts.contracts[0].contractId;
}
}
contractId ||= await addContract({
burialSiteId: burialSite ? burialSite.burialSiteId : '',
contractTypeId: importIds.preneedContractType.contractTypeId,
contractStartDateString,
contractEndDateString: '',
purchaserName: prepaidRow.CMPP_ARRANGED_BY_NAME,
deceasedName: prepaidRow.CMPP_PREPAID_FOR_NAME,
deceasedAddress1: prepaidRow.CMPP_ADDRESS,
deceasedAddress2: '',
deceasedCity: prepaidRow.CMPP_CITY,
deceasedProvince: prepaidRow.CMPP_PROV.slice(0, 2),
deceasedPostalCode: `${prepaidRow.CMPP_POSTAL1} ${prepaidRow.CMPP_POSTAL2}`
}, user);
if (prepaidRow.CMPP_FEE_GRAV_SD !== '0.0') {
await addContractFee({
contractId,
feeId: await getFeeIdByFeeDescription('CMPP_FEE_GRAV_SD', user),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_GRAV_SD,
taxAmount: prepaidRow.CMPP_GST_GRAV_SD
}, user);
}
if (prepaidRow.CMPP_FEE_GRAV_DD !== '0.0') {
await addContractFee({
contractId,
feeId: await getFeeIdByFeeDescription('CMPP_FEE_GRAV_DD', user),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_GRAV_DD,
taxAmount: prepaidRow.CMPP_GST_GRAV_DD
}, user);
}
if (prepaidRow.CMPP_FEE_CHAP_SD !== '0.0') {
await addContractFee({
contractId,
feeId: await getFeeIdByFeeDescription('CMPP_FEE_CHAP_SD', user),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_CHAP_SD,
taxAmount: prepaidRow.CMPP_GST_CHAP_SD
}, user);
}
if (prepaidRow.CMPP_FEE_CHAP_DD !== '0.0') {
await addContractFee({
contractId,
feeId: await getFeeIdByFeeDescription('CMPP_FEE_CHAP_DD', user),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_CHAP_DD,
taxAmount: prepaidRow.CMPP_GST_CHAP_DD
}, user);
}
if (prepaidRow.CMPP_FEE_ENTOMBMENT !== '0.0') {
await addContractFee({
contractId,
feeId: await getFeeIdByFeeDescription('CMPP_FEE_ENTOMBMENT', user),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_ENTOMBMENT,
taxAmount: prepaidRow.CMPP_GST_ENTOMBMENT
}, user);
}
if (prepaidRow.CMPP_FEE_CREM !== '0.0') {
await addContractFee({
contractId,
feeId: await getFeeIdByFeeDescription('CMPP_FEE_CREM', user),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_CREM,
taxAmount: prepaidRow.CMPP_GST_CREM
}, user);
}
if (prepaidRow.CMPP_FEE_NICHE !== '0.0') {
await addContractFee({
contractId,
feeId: await getFeeIdByFeeDescription('CMPP_FEE_NICHE', user),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_NICHE,
taxAmount: prepaidRow.CMPP_GST_NICHE
}, user);
}
if (prepaidRow.CMPP_FEE_DISINTERMENT !== '0.0' &&
prepaidRow.CMPP_FEE_DISINTERMENT !== '20202.02') {
await addContractFee({
contractId,
feeId: await getFeeIdByFeeDescription('CMPP_FEE_DISINTERMENT', user),
quantity: 1,
feeAmount: prepaidRow.CMPP_FEE_DISINTERMENT,
taxAmount: prepaidRow.CMPP_GST_DISINTERMENT
}, user);
}
const transactionAmount = Number.parseFloat(prepaidRow.CMPP_FEE_GRAV_SD) +
Number.parseFloat(prepaidRow.CMPP_GST_GRAV_SD) +
Number.parseFloat(prepaidRow.CMPP_FEE_GRAV_DD) +
Number.parseFloat(prepaidRow.CMPP_GST_GRAV_DD) +
Number.parseFloat(prepaidRow.CMPP_FEE_CHAP_SD) +
Number.parseFloat(prepaidRow.CMPP_GST_CHAP_SD) +
Number.parseFloat(prepaidRow.CMPP_FEE_CHAP_DD) +
Number.parseFloat(prepaidRow.CMPP_GST_CHAP_DD) +
Number.parseFloat(prepaidRow.CMPP_FEE_ENTOMBMENT) +
Number.parseFloat(prepaidRow.CMPP_GST_ENTOMBMENT) +
Number.parseFloat(prepaidRow.CMPP_FEE_CREM) +
Number.parseFloat(prepaidRow.CMPP_GST_CREM) +
Number.parseFloat(prepaidRow.CMPP_FEE_NICHE) +
Number.parseFloat(prepaidRow.CMPP_GST_NICHE) +
Number.parseFloat(prepaidRow.CMPP_FEE_DISINTERMENT === '20202.02'
? '0'
: prepaidRow.CMPP_FEE_DISINTERMENT) +
Number.parseFloat(prepaidRow.CMPP_GST_DISINTERMENT === '20202.02'
? '0'
: prepaidRow.CMPP_GST_DISINTERMENT);
await addContractTransaction({
contractId,
externalReceiptNumber: '',
transactionAmount,
transactionDateString: contractStartDateString,
transactionNote: `Order Number: ${prepaidRow.CMPP_ORDER_NO}`
}, user);
if (prepaidRow.CMPP_REMARK1 !== '') {
await addContractComment({
contractId,
commentDateString: contractStartDateString,
comment: prepaidRow.CMPP_REMARK1
}, user);
}
if (prepaidRow.CMPP_REMARK2 !== '') {
await addContractComment({
contractId,
commentDateString: contractStartDateString,
comment: prepaidRow.CMPP_REMARK2
}, user);
}
}
}
catch (error) {
console.error(error);
console.log(prepaidRow);
}
console.timeEnd('importFromPrepaidCSV');
}
// eslint-disable-next-line complexity
async function importFromWorkOrderCSV() {
console.time('importFromWorkOrderCSV');
let workOrderRow;
const rawData = fs.readFileSync('./temp/CMWKORDR.csv').toString();
const cmwkordr = papa.parse(rawData, {
delimiter: ',',
header: true,
skipEmptyLines: true
});
for (const parseError of cmwkordr.errors) {
console.log(parseError);
}
const currentDateString = dateToString(new Date());
try {
for (workOrderRow of cmwkordr.data) {
const workOrderNumber = `000000${workOrderRow.WO_WORK_ORDER}`.slice(-6);
let workOrder = await getWorkOrderByWorkOrderNumber(workOrderNumber);
const workOrderOpenDateString = dateIntegerToString(Number.parseInt(workOrderRow.WO_INITIATION_DATE, 10));
if (workOrder) {
if (workOrder.workOrderCloseDate) {
await reopenWorkOrder(workOrder.workOrderId, user);
delete workOrder.workOrderCloseDate;
delete workOrder.workOrderCloseDateString;
}
}
else {
const workOrderId = await addWorkOrder({
workOrderNumber,
workOrderTypeId: importIds.workOrderTypeId,
workOrderDescription: `${workOrderRow.WO_REMARK1} ${workOrderRow.WO_REMARK2} ${workOrderRow.WO_REMARK3}`.trim(),
workOrderOpenDateString
}, user);
workOrder = await getWorkOrder(workOrderId, {
includeBurialSites: true,
includeComments: true,
includeMilestones: true
});
}
let burialSite;
if (workOrderRow.WO_CEMETERY !== '00') {
const burialSiteNameSegment1 = workOrderRow.WO_BLOCK === '0' ? '' : workOrderRow.WO_BLOCK;
const burialSiteNameSegment2 = (workOrderRow.WO_RANGE1 === '0' ? '' : workOrderRow.WO_RANGE1) +
(workOrderRow.WO_RANGE2 === '0' ? '' : workOrderRow.WO_RANGE2);
const burialSiteNameSegment3 = (workOrderRow.WO_LOT1 === '0' ? '' : workOrderRow.WO_LOT1) +
(workOrderRow.WO_LOT2 === '0' ? '' : workOrderRow.WO_LOT2);
const burialSiteNameSegment4 = (workOrderRow.WO_GRAVE1 === '0' ? '' : workOrderRow.WO_GRAVE1) +
(workOrderRow.WO_GRAVE2 === '0' ? '' : workOrderRow.WO_GRAVE2);
const burialSiteName = buildBurialSiteName(workOrderRow.WO_CEMETERY, {
burialSiteNameSegment1,
burialSiteNameSegment2,
burialSiteNameSegment3,
burialSiteNameSegment4
});
burialSite = await getBurialSiteByBurialSiteName(burialSiteName);
if (burialSite) {
await updateBurialSiteStatus(burialSite.burialSiteId, importIds.takenBurialSiteStatusId, user);
}
else {
const cemeteryId = await getCemeteryIdByKey(workOrderRow.WO_CEMETERY, user);
const burialSiteTypeId = getBurialSiteTypeId(workOrderRow.WO_CEMETERY);
const burialSiteId = await addBurialSite({
cemeteryId,
burialSiteNameSegment1,
burialSiteNameSegment2,
burialSiteNameSegment3,
burialSiteNameSegment4,
cemeterySvgId: burialSiteName.includes(',')
? burialSiteName.split(',')[0]
: burialSiteName,
burialSiteStatusId: importIds.takenBurialSiteStatusId,
burialSiteTypeId,
burialSiteLatitude: '',
burialSiteLongitude: ''
}, user);
burialSite = await getBurialSite(burialSiteId);
}
const workOrderContainsLot = workOrder.workOrderBurialSites.find((possibleLot) => (possibleLot.burialSiteId = burialSite.burialSiteId));
if (!workOrderContainsLot) {
await addWorkOrderBurialSite({
workOrderId: workOrder.workOrderId,
burialSiteId: burialSite.burialSiteId
}, user);
workOrder.workOrderBurialSites.push(burialSite);
}
}
let contractStartDateString = workOrderOpenDateString;
if (workOrderRow.WO_INTERMENT_YR) {
contractStartDateString = formatDateString(workOrderRow.WO_INTERMENT_YR, workOrderRow.WO_INTERMENT_MON, workOrderRow.WO_INTERMENT_DAY);
}
const contractType = burialSite
? importIds.deceasedContractType
: importIds.cremationContractType;
const funeralHomeId = workOrderRow.WO_FUNERAL_HOME === ''
? ''
: await getFuneralHomeIdByKey(workOrderRow.WO_FUNERAL_HOME, user);
const committalTypeId = contractType.contractType === 'Cremation' ||
workOrderRow.WO_COMMITTAL_TYPE === ''
? ''
: await getCommittalTypeIdByKey(workOrderRow.WO_COMMITTAL_TYPE, user);
const intermentContainerTypeKey = contractType.contractType === 'Cremation' &&
workOrderRow.WO_CONTAINER_TYPE !== ''
? 'U'
: workOrderRow.WO_CONTAINER_TYPE;
const intermentContainerTypeId = intermentContainerTypeKey === ''
? ''
: await getIntermentContainerTypeIdByKey(intermentContainerTypeKey, user);
const contractId = await addContract({
burialSiteId: burialSite ? burialSite.burialSiteId : '',
contractTypeId: contractType.contractTypeId,
contractStartDateString,
contractEndDateString: '',
funeralHomeId,
funeralDirectorName: workOrderRow.WO_FUNERAL_HOME,
funeralDateString: workOrderRow.WO_FUNERAL_YR === ''
? ''
: formatDateString(workOrderRow.WO_FUNERAL_YR, workOrderRow.WO_FUNERAL_MON, workOrderRow.WO_FUNERAL_DAY),
committalTypeId,
deceasedName: workOrderRow.WO_DECEASED_NAME,
deceasedAddress1: workOrderRow.WO_ADDRESS,
deceasedAddress2: '',
deceasedCity: workOrderRow.WO_CITY,
deceasedProvince: workOrderRow.WO_PROV.slice(0, 2),
deceasedPostalCode: `${workOrderRow.WO_POST1} ${workOrderRow.WO_POST2}`,
deathDateString: workOrderRow.WO_DEATH_YR === ''
? ''
: formatDateString(workOrderRow.WO_DEATH_YR, workOrderRow.WO_DEATH_MON, workOrderRow.WO_DEATH_DAY),
deathPlace: workOrderRow.WO_DEATH_PLACE,
deathAge: workOrderRow.WO_AGE,
deathAgePeriod: getDeathAgePeriod(workOrderRow.WO_PERIOD),
intermentContainerTypeId
}, user);
await addWorkOrderContract({
workOrderId: workOrder.workOrderId,
contractId
}, user);
// Milestones
let hasIncompleteMilestones = !workOrderRow.WO_CONFIRMATION_IN;
let maxMilestoneCompletionDateString = workOrderOpenDateString;
if (importIds.acknowledgedWorkOrderMilestoneTypeId) {
await addWorkOrderMilestone({
workOrderId: workOrder.workOrderId,
workOrderMilestoneTypeId: importIds.acknowledgedWorkOrderMilestoneTypeId,
workOrderMilestoneDateString: workOrderOpenDateString,
workOrderMilestoneDescription: '',
workOrderMilestoneCompletionDateString: workOrderRow.WO_CONFIRMATION_IN
? workOrderOpenDateString
: undefined,
workOrderMilestoneCompletionTimeString: workOrderRow.WO_CONFIRMATION_IN ? '00:00' : undefined
}, user);
}
if (workOrderRow.WO_DEATH_YR) {
const workOrderMilestoneDateString = formatDateString(workOrderRow.WO_DEATH_YR, workOrderRow.WO_DEATH_MON, workOrderRow.WO_DEATH_DAY);
if (importIds.deathWorkOrderMilestoneTypeId) {
await addWorkOrderMilestone({
workOrderId: workOrder.workOrderId,
workOrderMilestoneTypeId: importIds.deathWorkOrderMilestoneTypeId,
workOrderMilestoneDateString,
workOrderMilestoneDescription: `Death Place: ${workOrderRow.WO_DEATH_PLACE}`,
workOrderMilestoneCompletionDateString: workOrderMilestoneDateString < currentDateString
? workOrderMilestoneDateString
: undefined,
workOrderMilestoneCompletionTimeString: workOrderMilestoneDateString < currentDateString
? '00:00'
: undefined
}, user);
}
if (workOrderMilestoneDateString > maxMilestoneCompletionDateString) {
maxMilestoneCompletionDateString = workOrderMilestoneDateString;
}
if (workOrderMilestoneDateString >= currentDateString) {
hasIncompleteMilestones = true;
}
}
if (workOrderRow.WO_FUNERAL_YR) {
const workOrderMilestoneDateString = formatDateString(workOrderRow.WO_FUNERAL_YR, workOrderRow.WO_FUNERAL_MON, workOrderRow.WO_FUNERAL_DAY);
let funeralHour = Number.parseInt(workOrderRow.WO_FUNERAL_HR === '' ? '0' : workOrderRow.WO_FUNERAL_HR, 10);
if (funeralHour <= 6) {
funeralHour += 12;
}
const workOrderMilestoneTimeString = formatTimeString(funeralHour.toString(), workOrderRow.WO_FUNERAL_MIN === '' ? '0' : workOrderRow.WO_FUNERAL_MIN);
if (importIds.funeralWorkOrderMilestoneTypeId) {
await addWorkOrderMilestone({
workOrderId: workOrder.workOrderId,
workOrderMilestoneTypeId: importIds.funeralWorkOrderMilestoneTypeId,
workOrderMilestoneDateString,
workOrderMilestoneTimeString,
workOrderMilestoneDescription: `Funeral Home: ${workOrderRow.WO_FUNERAL_HOME}`,
workOrderMilestoneCompletionDateString: workOrderMilestoneDateString < currentDateString
? workOrderMilestoneDateString
: undefined,
workOrderMilestoneCompletionTimeString: workOrderMilestoneDateString < currentDateString
? workOrderMilestoneTimeString
: undefined
}, user);
}
if (workOrderMilestoneDateString > maxMilestoneCompletionDateString) {
maxMilestoneCompletionDateString = workOrderMilestoneDateString;
}
if (workOrderMilestoneDateString >= currentDateString) {
hasIncompleteMilestones = true;
}
}
if (workOrderRow.WO_CREMATION === 'Y' &&
importIds.cremationWorkOrderMilestoneTypeId) {
await addWorkOrderMilestone({
workOrderId: workOrder.workOrderId,
workOrderMilestoneTypeId: importIds.cremationWorkOrderMilestoneTypeId,
workOrderMilestoneDateString: maxMilestoneCompletionDateString,
workOrderMilestoneDescription: '',
workOrderMilestoneCompletionDateString: maxMilestoneCompletionDateString < currentDateString
? maxMilestoneCompletionDateString
: undefined,
workOrderMilestoneCompletionTimeString: maxMilestoneCompletionDateString < currentDateString
? '00:00'
: undefined
}, user);
}
if (workOrderRow.WO_INTERMENT_YR) {
const workOrderMilestoneDateString = formatDateString(workOrderRow.WO_INTERMENT_YR, workOrderRow.WO_INTERMENT_MON, workOrderRow.WO_INTERMENT_DAY);
if (importIds.intermentWorkOrderMilestoneTypeId) {
await addWorkOrderMilestone({
workOrderId: workOrder.workOrderId,
workOrderMilestoneTypeId: importIds.intermentWorkOrderMilestoneTypeId,
workOrderMilestoneDateString,
workOrderMilestoneDescription: `Depth: ${workOrderRow.WO_DEPTH}`,
workOrderMilestoneCompletionDateString: workOrderMilestoneDateString < currentDateString
? workOrderMilestoneDateString
: undefined,
workOrderMilestoneCompletionTimeString: workOrderMilestoneDateString < currentDateString
? '23:59'
: undefined
}, user);
}
if (workOrderMilestoneDateString > maxMilestoneCompletionDateString) {
maxMilestoneCompletionDateString = workOrderMilestoneDateString;
}
if (workOrderMilestoneDateString >= currentDateString) {
hasIncompleteMilestones = true;
}
}
if (!hasIncompleteMilestones) {
await closeWorkOrder({
workOrderId: workOrder.workOrderId,
workOrderCloseDateString: maxMilestoneCompletionDateString
}, user);
}
}
}
catch (error) {
console.error(error);
console.log(workOrderRow);
}
console.timeEnd('importFromWorkOrderCSV');
}
console.log(`Started ${new Date().toLocaleString()}`);
console.time('importFromCsv');
// Purge Tables
//purgeTables()
//purgeConfigTables()
// Initialize SSM Data
//await initializeFuneralHomes(user)
// Do Imports
//await importFromMasterCSV()
await importFromPrepaidCSV();
await importFromWorkOrderCSV();
console.timeEnd('importFromCsv');
console.log(`Finished ${new Date().toLocaleString()}`);

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,7 @@ export interface Config {
contracts: { contracts: {
burialSiteIdIsRequired?: boolean; burialSiteIdIsRequired?: boolean;
contractEndDateIsRequired?: boolean; contractEndDateIsRequired?: boolean;
deathAgePeriods?: string[];
prints?: string[]; prints?: string[];
}; };
workOrders: { workOrders: {

View File

@ -32,6 +32,7 @@ export interface Config {
contracts: { contracts: {
burialSiteIdIsRequired?: boolean burialSiteIdIsRequired?: boolean
contractEndDateIsRequired?: boolean contractEndDateIsRequired?: boolean
deathAgePeriods?: string[]
prints?: string[] prints?: string[]
} }
workOrders: { workOrders: {

View File

@ -28,6 +28,7 @@ export interface Cemetery extends Record {
} }
export interface FuneralHome extends Record { export interface FuneralHome extends Record {
funeralHomeId?: number; funeralHomeId?: number;
funeralHomeKey?: string;
funeralHomeName?: string; funeralHomeName?: string;
funeralHomeAddress1?: string; funeralHomeAddress1?: string;
funeralHomeAddress2?: string; funeralHomeAddress2?: string;
@ -172,12 +173,14 @@ export interface DynamicsGPDocument {
export interface IntermentContainerType extends Record { export interface IntermentContainerType extends Record {
intermentContainerTypeId: number; intermentContainerTypeId: number;
intermentContainerType: string; intermentContainerType: string;
intermentContainerTypeKey: string;
isCremationType: boolean; isCremationType: boolean;
orderNumber?: number; orderNumber?: number;
} }
export interface CommittalType extends Record { export interface CommittalType extends Record {
committalTypeId: number; committalTypeId: number;
committalType: string; committalType: string;
committalTypeKey: string;
orderNumber?: number; orderNumber?: number;
} }
export interface ContractInterment extends Record { export interface ContractInterment extends Record {
@ -195,6 +198,8 @@ export interface ContractInterment extends Record {
deathDate?: number; deathDate?: number;
deathDateString?: string; deathDateString?: string;
deathPlace?: string; deathPlace?: string;
deathAge?: number;
deathAgePeriod?: string;
intermentContainerTypeId?: number; intermentContainerTypeId?: number;
intermentContainerType?: string; intermentContainerType?: string;
isCremationType?: boolean; isCremationType?: boolean;
@ -242,6 +247,7 @@ export interface Contract extends Record {
purchaserEmail?: string; purchaserEmail?: string;
purchaserRelationship?: string; purchaserRelationship?: string;
funeralHomeId?: number; funeralHomeId?: number;
funeralHomeKey?: string;
funeralHomeName?: string; funeralHomeName?: string;
funeralDirectorName?: string; funeralDirectorName?: string;
funeralHomeAddress1?: string; funeralHomeAddress1?: string;

View File

@ -39,6 +39,7 @@ export interface Cemetery extends Record {
export interface FuneralHome extends Record { export interface FuneralHome extends Record {
funeralHomeId?: number funeralHomeId?: number
funeralHomeKey?: string
funeralHomeName?: string funeralHomeName?: string
funeralHomeAddress1?: string funeralHomeAddress1?: string
funeralHomeAddress2?: string funeralHomeAddress2?: string
@ -222,6 +223,7 @@ export interface DynamicsGPDocument {
export interface IntermentContainerType extends Record { export interface IntermentContainerType extends Record {
intermentContainerTypeId: number intermentContainerTypeId: number
intermentContainerType: string intermentContainerType: string
intermentContainerTypeKey: string
isCremationType: boolean isCremationType: boolean
orderNumber?: number orderNumber?: number
} }
@ -229,6 +231,7 @@ export interface IntermentContainerType extends Record {
export interface CommittalType extends Record { export interface CommittalType extends Record {
committalTypeId: number committalTypeId: number
committalType: string committalType: string
committalTypeKey: string
orderNumber?: number orderNumber?: number
} }
@ -250,6 +253,8 @@ export interface ContractInterment extends Record {
deathDate?: number deathDate?: number
deathDateString?: string deathDateString?: string
deathPlace?: string deathPlace?: string
deathAge?: number
deathAgePeriod?: string
intermentContainerTypeId?: number intermentContainerTypeId?: number
intermentContainerType?: string intermentContainerType?: string
@ -313,6 +318,7 @@ export interface Contract extends Record {
purchaserRelationship?: string purchaserRelationship?: string
funeralHomeId?: number funeralHomeId?: number
funeralHomeKey?: string
funeralHomeName?: string funeralHomeName?: string
funeralDirectorName?: string funeralDirectorName?: string
funeralHomeAddress1?: string funeralHomeAddress1?: string

Some files were not shown because too many files have changed in this diff Show More