major refactoring
parent
0ea7494b8c
commit
547c2e224f
18
app.js
18
app.js
|
|
@ -9,20 +9,20 @@ import rateLimit from 'express-rate-limit';
|
|||
import session from 'express-session';
|
||||
import createError from 'http-errors';
|
||||
import FileStore from 'session-file-store';
|
||||
import { useTestDatabases } from './data/databasePaths.js';
|
||||
import { initializeDatabase } from './database/initializeDatabase.js';
|
||||
import { DEBUG_NAMESPACE } from './debug.config.js';
|
||||
import * as permissionHandlers from './handlers/permissions.js';
|
||||
import { getSafeRedirectURL } from './helpers/functions.authentication.js';
|
||||
import * as configFunctions from './helpers/config.helpers.js';
|
||||
import { useTestDatabases } from './helpers/database.helpers.js';
|
||||
import { getSafeRedirectURL } from './helpers/functions.authentication.js';
|
||||
import * as printFunctions from './helpers/functions.print.js';
|
||||
import { initializeDatabase } from './helpers/helpers.database.js';
|
||||
import routerAdmin from './routes/admin.js';
|
||||
import routerApi from './routes/api.js';
|
||||
import routerBurialSites from './routes/burialSites.js';
|
||||
import routerCemeteries from './routes/cemeteries.js';
|
||||
import routerContracts from './routes/contracts.js';
|
||||
import routerDashboard from './routes/dashboard.js';
|
||||
import routerLogin from './routes/login.js';
|
||||
import routerLotOccupancies from './routes/lotOccupancies.js';
|
||||
import routerLots from './routes/lots.js';
|
||||
import routerMaps from './routes/maps.js';
|
||||
import routerPrint from './routes/print.js';
|
||||
import routerReports from './routes/reports.js';
|
||||
import routerWorkOrders from './routes/workOrders.js';
|
||||
|
|
@ -140,9 +140,9 @@ app.get(`${urlPrefix}/`, sessionChecker, (_request, response) => {
|
|||
app.use(`${urlPrefix}/dashboard`, sessionChecker, routerDashboard);
|
||||
app.use(`${urlPrefix}/api/:apiKey`, permissionHandlers.apiGetHandler, routerApi);
|
||||
app.use(`${urlPrefix}/print`, sessionChecker, routerPrint);
|
||||
app.use(`${urlPrefix}/maps`, sessionChecker, routerMaps);
|
||||
app.use(`${urlPrefix}/lots`, sessionChecker, routerLots);
|
||||
app.use(`${urlPrefix}/lotOccupancies`, sessionChecker, routerLotOccupancies);
|
||||
app.use(`${urlPrefix}/cemeteries`, sessionChecker, routerCemeteries);
|
||||
app.use(`${urlPrefix}/burialSites`, sessionChecker, routerBurialSites);
|
||||
app.use(`${urlPrefix}/contracts`, sessionChecker, routerContracts);
|
||||
app.use(`${urlPrefix}/workOrders`, sessionChecker, routerWorkOrders);
|
||||
app.use(`${urlPrefix}/reports`, sessionChecker, routerReports);
|
||||
app.use(`${urlPrefix}/admin`, sessionChecker, permissionHandlers.adminGetHandler, routerAdmin);
|
||||
|
|
|
|||
18
app.ts
18
app.ts
|
|
@ -11,20 +11,20 @@ import session from 'express-session'
|
|||
import createError from 'http-errors'
|
||||
import FileStore from 'session-file-store'
|
||||
|
||||
import { useTestDatabases } from './data/databasePaths.js'
|
||||
import { initializeDatabase } from './database/initializeDatabase.js'
|
||||
import { DEBUG_NAMESPACE } from './debug.config.js'
|
||||
import * as permissionHandlers from './handlers/permissions.js'
|
||||
import { getSafeRedirectURL } from './helpers/functions.authentication.js'
|
||||
import * as configFunctions from './helpers/config.helpers.js'
|
||||
import { useTestDatabases } from './helpers/database.helpers.js'
|
||||
import { getSafeRedirectURL } from './helpers/functions.authentication.js'
|
||||
import * as printFunctions from './helpers/functions.print.js'
|
||||
import { initializeDatabase } from './helpers/helpers.database.js'
|
||||
import routerAdmin from './routes/admin.js'
|
||||
import routerApi from './routes/api.js'
|
||||
import routerBurialSites from './routes/burialSites.js'
|
||||
import routerCemeteries from './routes/cemeteries.js'
|
||||
import routerContracts from './routes/contracts.js'
|
||||
import routerDashboard from './routes/dashboard.js'
|
||||
import routerLogin from './routes/login.js'
|
||||
import routerLotOccupancies from './routes/lotOccupancies.js'
|
||||
import routerLots from './routes/lots.js'
|
||||
import routerMaps from './routes/maps.js'
|
||||
import routerPrint from './routes/print.js'
|
||||
import routerReports from './routes/reports.js'
|
||||
import routerWorkOrders from './routes/workOrders.js'
|
||||
|
|
@ -231,9 +231,9 @@ app.use(`${urlPrefix}/dashboard`, sessionChecker, routerDashboard)
|
|||
app.use(`${urlPrefix}/api/:apiKey`, permissionHandlers.apiGetHandler, routerApi)
|
||||
|
||||
app.use(`${urlPrefix}/print`, sessionChecker, routerPrint)
|
||||
app.use(`${urlPrefix}/maps`, sessionChecker, routerMaps)
|
||||
app.use(`${urlPrefix}/lots`, sessionChecker, routerLots)
|
||||
app.use(`${urlPrefix}/lotOccupancies`, sessionChecker, routerLotOccupancies)
|
||||
app.use(`${urlPrefix}/cemeteries`, sessionChecker, routerCemeteries)
|
||||
app.use(`${urlPrefix}/burialSites`, sessionChecker, routerBurialSites)
|
||||
app.use(`${urlPrefix}/contracts`, sessionChecker, routerContracts)
|
||||
app.use(`${urlPrefix}/workOrders`, sessionChecker, routerWorkOrders)
|
||||
|
||||
app.use(`${urlPrefix}/reports`, sessionChecker, routerReports)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
import { getConfigProperty } from '../../../helpers/config.helpers.js';
|
||||
import { testUpdate } from '../../../test/_globals.js';
|
||||
import { login, logout } from '../../support/index.js';
|
||||
describe('Update - Cemeteries', () => {
|
||||
beforeEach('Loads page', () => {
|
||||
logout();
|
||||
login(testUpdate);
|
||||
});
|
||||
afterEach(logout);
|
||||
it('Has a "Create" link on the Cemetery Search', () => {
|
||||
cy.visit('/cemeteries');
|
||||
cy.location('pathname').should('equal', '/cemeteries');
|
||||
cy.get("a[href$='/cemeteries/new']").should('exist');
|
||||
});
|
||||
it('Creates a new cemetery', () => {
|
||||
cy.visit('/cemeteries/new');
|
||||
cy.log('Check the accessibility');
|
||||
cy.injectAxe();
|
||||
cy.checkA11y();
|
||||
cy.log('Populate the fields');
|
||||
cy.fixture('cemetery.json').then((cemeteryData) => {
|
||||
cy.get("input[name='cemeteryName']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryName ?? '');
|
||||
cy.get("textarea[name='cemeteryDescription']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryDescription ?? '');
|
||||
cy.get("input[name='cemeteryAddress1']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryAddress1 ?? '');
|
||||
cy.get("input[name='cemeteryAddress2']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryAddress2 ?? '');
|
||||
cy.get("input[name='cemeteryPostalCode']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryPostalCode ?? '');
|
||||
cy.get("input[name='cemeteryPhoneNumber']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryPhoneNumber ?? '');
|
||||
cy.get("input[name='cemeteryLatitude']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryLatitude?.toString() ?? '');
|
||||
cy.get("input[name='cemeteryLongitude']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryLongitude?.toString() ?? '');
|
||||
});
|
||||
cy.log('Ensure the default city and province are used');
|
||||
cy.get("input[name='cemeteryCity']").should('have.value', getConfigProperty('settings.cemeteries.cityDefault'));
|
||||
cy.get("input[name='cemeteryProvince']").should('have.value', getConfigProperty('settings.cemeteries.provinceDefault'));
|
||||
cy.log('Submit the form');
|
||||
cy.get('#form--cemetery').submit();
|
||||
cy.wait(1000);
|
||||
cy.location('pathname')
|
||||
.should('not.contain', '/new')
|
||||
.should('contain', '/edit');
|
||||
cy.fixture('cemetery.json').then((cemeteryData) => {
|
||||
cy.get("input[name='cemeteryName']").should('have.value', cemeteryData.cemeteryName);
|
||||
cy.get("textarea[name='cemeteryDescription']").should('have.value', cemeteryData.cemeteryDescription);
|
||||
cy.get("input[name='cemeteryAddress1']").should('have.value', cemeteryData.cemeteryAddress1);
|
||||
cy.get("input[name='cemeteryAddress2']").should('have.value', cemeteryData.cemeteryAddress2);
|
||||
cy.get("input[name='cemeteryCity']").should('have.value', getConfigProperty('settings.cemeteries.cityDefault'));
|
||||
cy.get("input[name='cemeteryProvince']").should('have.value', getConfigProperty('settings.cemeteries.provinceDefault'));
|
||||
cy.get("input[name='cemeteryPostalCode']").should('have.value', cemeteryData.cemeteryPostalCode);
|
||||
cy.get("input[name='cemeteryPhoneNumber']").should('have.value', cemeteryData.cemeteryPhoneNumber);
|
||||
cy.get("input[name='cemeteryLatitude']").should('have.value', cemeteryData.cemeteryLatitude?.toString());
|
||||
cy.get("input[name='cemeteryLongitude']").should('have.value', cemeteryData.cemeteryLongitude?.toString());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
import { getConfigProperty } from '../../../helpers/config.helpers.js'
|
||||
import { testUpdate } from '../../../test/_globals.js'
|
||||
import type { Cemetery } from '../../../types/recordTypes.js'
|
||||
import { login, logout } from '../../support/index.js'
|
||||
|
||||
describe('Update - Cemeteries', () => {
|
||||
beforeEach('Loads page', () => {
|
||||
logout()
|
||||
login(testUpdate)
|
||||
})
|
||||
|
||||
afterEach(logout)
|
||||
|
||||
it('Has a "Create" link on the Cemetery Search', () => {
|
||||
cy.visit('/cemeteries')
|
||||
cy.location('pathname').should('equal', '/cemeteries')
|
||||
cy.get("a[href$='/cemeteries/new']").should('exist')
|
||||
})
|
||||
|
||||
it('Creates a new cemetery', () => {
|
||||
cy.visit('/cemeteries/new')
|
||||
|
||||
cy.log('Check the accessibility')
|
||||
|
||||
cy.injectAxe()
|
||||
cy.checkA11y()
|
||||
|
||||
cy.log('Populate the fields')
|
||||
|
||||
cy.fixture('cemetery.json').then((cemeteryData: Cemetery) => {
|
||||
cy.get("input[name='cemeteryName']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryName ?? '')
|
||||
|
||||
cy.get("textarea[name='cemeteryDescription']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryDescription ?? '')
|
||||
|
||||
cy.get("input[name='cemeteryAddress1']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryAddress1 ?? '')
|
||||
|
||||
cy.get("input[name='cemeteryAddress2']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryAddress2 ?? '')
|
||||
|
||||
cy.get("input[name='cemeteryPostalCode']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryPostalCode ?? '')
|
||||
|
||||
cy.get("input[name='cemeteryPhoneNumber']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryPhoneNumber ?? '')
|
||||
|
||||
cy.get("input[name='cemeteryLatitude']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryLatitude?.toString() ?? '')
|
||||
|
||||
cy.get("input[name='cemeteryLongitude']")
|
||||
.clear()
|
||||
.type(cemeteryData.cemeteryLongitude?.toString() ?? '')
|
||||
})
|
||||
|
||||
cy.log('Ensure the default city and province are used')
|
||||
|
||||
cy.get("input[name='cemeteryCity']").should(
|
||||
'have.value',
|
||||
getConfigProperty('settings.cemeteries.cityDefault')
|
||||
)
|
||||
|
||||
cy.get("input[name='cemeteryProvince']").should(
|
||||
'have.value',
|
||||
getConfigProperty('settings.cemeteries.provinceDefault')
|
||||
)
|
||||
|
||||
cy.log('Submit the form')
|
||||
|
||||
cy.get('#form--cemetery').submit()
|
||||
|
||||
cy.wait(1000)
|
||||
|
||||
cy.location('pathname')
|
||||
.should('not.contain', '/new')
|
||||
.should('contain', '/edit')
|
||||
|
||||
cy.fixture('cemetery.json').then((cemeteryData: Cemetery) => {
|
||||
cy.get("input[name='cemeteryName']").should(
|
||||
'have.value',
|
||||
cemeteryData.cemeteryName
|
||||
)
|
||||
|
||||
cy.get("textarea[name='cemeteryDescription']").should(
|
||||
'have.value',
|
||||
cemeteryData.cemeteryDescription
|
||||
)
|
||||
|
||||
cy.get("input[name='cemeteryAddress1']").should(
|
||||
'have.value',
|
||||
cemeteryData.cemeteryAddress1
|
||||
)
|
||||
|
||||
cy.get("input[name='cemeteryAddress2']").should(
|
||||
'have.value',
|
||||
cemeteryData.cemeteryAddress2
|
||||
)
|
||||
|
||||
cy.get("input[name='cemeteryCity']").should(
|
||||
'have.value',
|
||||
getConfigProperty('settings.cemeteries.cityDefault')
|
||||
)
|
||||
|
||||
cy.get("input[name='cemeteryProvince']").should(
|
||||
'have.value',
|
||||
getConfigProperty('settings.cemeteries.provinceDefault')
|
||||
)
|
||||
|
||||
cy.get("input[name='cemeteryPostalCode']").should(
|
||||
'have.value',
|
||||
cemeteryData.cemeteryPostalCode
|
||||
)
|
||||
|
||||
cy.get("input[name='cemeteryPhoneNumber']").should(
|
||||
'have.value',
|
||||
cemeteryData.cemeteryPhoneNumber
|
||||
)
|
||||
|
||||
cy.get("input[name='cemeteryLatitude']").should(
|
||||
'have.value',
|
||||
cemeteryData.cemeteryLatitude?.toString()
|
||||
)
|
||||
|
||||
cy.get("input[name='cemeteryLongitude']").should(
|
||||
'have.value',
|
||||
cemeteryData.cemeteryLongitude?.toString()
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
import { getConfigProperty } from '../../../helpers/config.helpers.js';
|
||||
import { testUpdate } from '../../../test/_globals.js';
|
||||
import { login, logout } from '../../support/index.js';
|
||||
describe('Update - Maps', () => {
|
||||
beforeEach('Loads page', () => {
|
||||
logout();
|
||||
login(testUpdate);
|
||||
});
|
||||
afterEach(logout);
|
||||
it('Has a "Create" link on the Map Search', () => {
|
||||
cy.visit('/maps');
|
||||
cy.location('pathname').should('equal', '/maps');
|
||||
cy.get("a[href$='/maps/new']").should('exist');
|
||||
});
|
||||
it('Creates a new map', () => {
|
||||
cy.visit('/maps/new');
|
||||
cy.log('Check the accessibility');
|
||||
cy.injectAxe();
|
||||
cy.checkA11y();
|
||||
cy.log('Populate the fields');
|
||||
// eslint-disable-next-line promise/catch-or-return, promise/always-return
|
||||
cy.fixture('map.json').then((mapJSON) => {
|
||||
cy.get("input[name='mapName']")
|
||||
.clear()
|
||||
.type(mapJSON.mapName ?? '');
|
||||
cy.get("textarea[name='mapDescription']")
|
||||
.clear()
|
||||
.type(mapJSON.mapDescription ?? '');
|
||||
cy.get("input[name='mapAddress1']")
|
||||
.clear()
|
||||
.type(mapJSON.mapAddress1 ?? '');
|
||||
cy.get("input[name='mapAddress2']")
|
||||
.clear()
|
||||
.type(mapJSON.mapAddress2 ?? '');
|
||||
cy.get("input[name='mapPostalCode']")
|
||||
.clear()
|
||||
.type(mapJSON.mapPostalCode ?? '');
|
||||
cy.get("input[name='mapPhoneNumber']")
|
||||
.clear()
|
||||
.type(mapJSON.mapPhoneNumber ?? '');
|
||||
cy.get("input[name='mapLatitude']")
|
||||
.clear()
|
||||
.type(mapJSON.mapLatitude?.toString() ?? '');
|
||||
cy.get("input[name='mapLongitude']")
|
||||
.clear()
|
||||
.type(mapJSON.mapLongitude?.toString() ?? '');
|
||||
});
|
||||
cy.log('Ensure the default city and province are used');
|
||||
cy.get("input[name='mapCity']").should('have.value', getConfigProperty('settings.map.mapCityDefault'));
|
||||
cy.get("input[name='mapProvince']").should('have.value', getConfigProperty('settings.map.mapProvinceDefault'));
|
||||
cy.log('Submit the form');
|
||||
cy.get('#form--map').submit();
|
||||
cy.wait(1000);
|
||||
cy.location('pathname')
|
||||
.should('not.contain', '/new')
|
||||
.should('contain', '/edit');
|
||||
// eslint-disable-next-line promise/catch-or-return, promise/always-return
|
||||
cy.fixture('map.json').then((mapJSON) => {
|
||||
cy.get("input[name='mapName']").should('have.value', mapJSON.mapName);
|
||||
cy.get("textarea[name='mapDescription']").should('have.value', mapJSON.mapDescription);
|
||||
cy.get("input[name='mapAddress1']").should('have.value', mapJSON.mapAddress1);
|
||||
cy.get("input[name='mapAddress2']").should('have.value', mapJSON.mapAddress2);
|
||||
cy.get("input[name='mapCity']").should('have.value', getConfigProperty('settings.map.mapCityDefault'));
|
||||
cy.get("input[name='mapProvince']").should('have.value', getConfigProperty('settings.map.mapProvinceDefault'));
|
||||
cy.get("input[name='mapPostalCode']").should('have.value', mapJSON.mapPostalCode);
|
||||
cy.get("input[name='mapPhoneNumber']").should('have.value', mapJSON.mapPhoneNumber);
|
||||
cy.get("input[name='mapLatitude']").should('have.value', mapJSON.mapLatitude?.toString());
|
||||
cy.get("input[name='mapLongitude']").should('have.value', mapJSON.mapLongitude?.toString());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
import { getConfigProperty } from '../../../helpers/config.helpers.js'
|
||||
import { testUpdate } from '../../../test/_globals.js'
|
||||
import type { MapRecord } from '../../../types/recordTypes.js'
|
||||
import { login, logout } from '../../support/index.js'
|
||||
|
||||
describe('Update - Maps', () => {
|
||||
beforeEach('Loads page', () => {
|
||||
logout()
|
||||
login(testUpdate)
|
||||
})
|
||||
|
||||
afterEach(logout)
|
||||
|
||||
it('Has a "Create" link on the Map Search', () => {
|
||||
cy.visit('/maps')
|
||||
cy.location('pathname').should('equal', '/maps')
|
||||
cy.get("a[href$='/maps/new']").should('exist')
|
||||
})
|
||||
|
||||
it('Creates a new map', () => {
|
||||
cy.visit('/maps/new')
|
||||
|
||||
cy.log('Check the accessibility')
|
||||
|
||||
cy.injectAxe()
|
||||
cy.checkA11y()
|
||||
|
||||
cy.log('Populate the fields')
|
||||
|
||||
// eslint-disable-next-line promise/catch-or-return, promise/always-return
|
||||
cy.fixture('map.json').then((mapJSON: MapRecord) => {
|
||||
cy.get("input[name='mapName']")
|
||||
.clear()
|
||||
.type(mapJSON.mapName ?? '')
|
||||
cy.get("textarea[name='mapDescription']")
|
||||
.clear()
|
||||
.type(mapJSON.mapDescription ?? '')
|
||||
|
||||
cy.get("input[name='mapAddress1']")
|
||||
.clear()
|
||||
.type(mapJSON.mapAddress1 ?? '')
|
||||
cy.get("input[name='mapAddress2']")
|
||||
.clear()
|
||||
.type(mapJSON.mapAddress2 ?? '')
|
||||
cy.get("input[name='mapPostalCode']")
|
||||
.clear()
|
||||
.type(mapJSON.mapPostalCode ?? '')
|
||||
cy.get("input[name='mapPhoneNumber']")
|
||||
.clear()
|
||||
.type(mapJSON.mapPhoneNumber ?? '')
|
||||
|
||||
cy.get("input[name='mapLatitude']")
|
||||
.clear()
|
||||
.type(mapJSON.mapLatitude?.toString() ?? '')
|
||||
cy.get("input[name='mapLongitude']")
|
||||
.clear()
|
||||
.type(mapJSON.mapLongitude?.toString() ?? '')
|
||||
})
|
||||
|
||||
cy.log('Ensure the default city and province are used')
|
||||
|
||||
cy.get("input[name='mapCity']").should(
|
||||
'have.value',
|
||||
getConfigProperty('settings.map.mapCityDefault')
|
||||
)
|
||||
|
||||
cy.get("input[name='mapProvince']").should(
|
||||
'have.value',
|
||||
getConfigProperty('settings.map.mapProvinceDefault')
|
||||
)
|
||||
|
||||
cy.log('Submit the form')
|
||||
|
||||
cy.get('#form--map').submit()
|
||||
|
||||
cy.wait(1000)
|
||||
|
||||
cy.location('pathname')
|
||||
.should('not.contain', '/new')
|
||||
.should('contain', '/edit')
|
||||
|
||||
// eslint-disable-next-line promise/catch-or-return, promise/always-return
|
||||
cy.fixture('map.json').then((mapJSON: MapRecord) => {
|
||||
cy.get("input[name='mapName']").should('have.value', mapJSON.mapName)
|
||||
cy.get("textarea[name='mapDescription']").should(
|
||||
'have.value',
|
||||
mapJSON.mapDescription
|
||||
)
|
||||
|
||||
cy.get("input[name='mapAddress1']").should(
|
||||
'have.value',
|
||||
mapJSON.mapAddress1
|
||||
)
|
||||
cy.get("input[name='mapAddress2']").should(
|
||||
'have.value',
|
||||
mapJSON.mapAddress2
|
||||
)
|
||||
|
||||
cy.get("input[name='mapCity']").should(
|
||||
'have.value',
|
||||
getConfigProperty('settings.map.mapCityDefault')
|
||||
)
|
||||
cy.get("input[name='mapProvince']").should(
|
||||
'have.value',
|
||||
getConfigProperty('settings.map.mapProvinceDefault')
|
||||
)
|
||||
|
||||
cy.get("input[name='mapPostalCode']").should(
|
||||
'have.value',
|
||||
mapJSON.mapPostalCode
|
||||
)
|
||||
cy.get("input[name='mapPhoneNumber']").should(
|
||||
'have.value',
|
||||
mapJSON.mapPhoneNumber
|
||||
)
|
||||
|
||||
cy.get("input[name='mapLatitude']").should(
|
||||
'have.value',
|
||||
mapJSON.mapLatitude?.toString()
|
||||
)
|
||||
cy.get("input[name='mapLongitude']").should(
|
||||
'have.value',
|
||||
mapJSON.mapLongitude?.toString()
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"cemeteryName": "Cypress Test - Holy Sepulchre",
|
||||
"cemeteryDescription": "Operated by the City of Sault Ste. Marie",
|
||||
"cemeteryAddress1": "Fourth Line and Peoples Road",
|
||||
"cemeteryAddress2": "27 Fourth Line East",
|
||||
"cemeteryPostalCode": "P6A 5K8",
|
||||
"cemeteryPhoneNumber": "705-759-5336",
|
||||
"cemeteryLatitude": 46.56874795,
|
||||
"cemeteryLongitude": -84.34842824
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"mapName": "Cypress Test - Holy Sepulchre",
|
||||
"mapDescription": "Operated by the City of Sault Ste. Marie",
|
||||
"mapAddress1": "Fourth Line and Peoples Road",
|
||||
"mapAddress2": "27 Fourth Line East",
|
||||
"mapPostalCode": "P6A 5K8",
|
||||
"mapPhoneNumber": "705-759-5336",
|
||||
"mapLatitude": 46.56874795,
|
||||
"mapLongitude": -84.34842824
|
||||
}
|
||||
|
|
@ -24,15 +24,12 @@ export declare const configDefaultValues: {
|
|||
'aliases.externalReceiptNumber': string;
|
||||
'aliases.workOrderOpenDate': string;
|
||||
'aliases.workOrderCloseDate': string;
|
||||
'settings.map.mapCityDefault': string;
|
||||
'settings.map.mapProvinceDefault': string;
|
||||
'settings.lot.lotNamePattern': RegExp | undefined;
|
||||
'settings.lot.lotNameHelpText': string;
|
||||
'settings.lot.lotNameSortNameFunction': (lotName: string) => string;
|
||||
'settings.lotOccupancy.occupancyEndDateIsRequired': boolean;
|
||||
'settings.lotOccupancy.occupantCityDefault': string;
|
||||
'settings.lotOccupancy.occupantProvinceDefault': string;
|
||||
'settings.lotOccupancy.prints': string[];
|
||||
'settings.cemeteries.cityDefault': string;
|
||||
'settings.cemeteries.provinceDefault': string;
|
||||
'settings.contracts.burialSiteIdIsRequired': boolean;
|
||||
'settings.contracts.cityDefault': string;
|
||||
'settings.contracts.provinceDefault': string;
|
||||
'settings.contracts.prints': string[];
|
||||
'settings.fees.taxPercentageDefault': number;
|
||||
'settings.workOrders.workOrderNumberLength': number;
|
||||
'settings.workOrders.workOrderMilestoneDateRecentBeforeDays': number;
|
||||
|
|
|
|||
|
|
@ -23,16 +23,12 @@ export const configDefaultValues = {
|
|||
'aliases.externalReceiptNumber': 'External Receipt Number',
|
||||
'aliases.workOrderOpenDate': 'Order Date',
|
||||
'aliases.workOrderCloseDate': 'Completion Date',
|
||||
'settings.map.mapCityDefault': '',
|
||||
'settings.map.mapProvinceDefault': '',
|
||||
'settings.lot.lotNamePattern': undefined,
|
||||
'settings.lot.lotNameHelpText': '',
|
||||
'settings.lot.lotNameSortNameFunction': (lotName) => lotName,
|
||||
// eslint-disable-next-line no-secrets/no-secrets
|
||||
'settings.lotOccupancy.occupancyEndDateIsRequired': true,
|
||||
'settings.lotOccupancy.occupantCityDefault': '',
|
||||
'settings.lotOccupancy.occupantProvinceDefault': '',
|
||||
'settings.lotOccupancy.prints': ['screen/lotOccupancy'],
|
||||
'settings.cemeteries.cityDefault': '',
|
||||
'settings.cemeteries.provinceDefault': '',
|
||||
'settings.contracts.burialSiteIdIsRequired': true,
|
||||
'settings.contracts.cityDefault': '',
|
||||
'settings.contracts.provinceDefault': '',
|
||||
'settings.contracts.prints': ['screen/contract'],
|
||||
'settings.fees.taxPercentageDefault': 0,
|
||||
'settings.workOrders.workOrderNumberLength': 6,
|
||||
'settings.workOrders.workOrderMilestoneDateRecentBeforeDays': 5,
|
||||
|
|
|
|||
|
|
@ -38,17 +38,13 @@ export const configDefaultValues = {
|
|||
'aliases.workOrderOpenDate': 'Order Date',
|
||||
'aliases.workOrderCloseDate': 'Completion Date',
|
||||
|
||||
'settings.map.mapCityDefault': '',
|
||||
'settings.map.mapProvinceDefault': '',
|
||||
'settings.cemeteries.cityDefault': '',
|
||||
'settings.cemeteries.provinceDefault': '',
|
||||
|
||||
'settings.lot.lotNamePattern': undefined as RegExp | undefined,
|
||||
'settings.lot.lotNameHelpText': '',
|
||||
'settings.lot.lotNameSortNameFunction': (lotName: string) => lotName,
|
||||
// eslint-disable-next-line no-secrets/no-secrets
|
||||
'settings.lotOccupancy.occupancyEndDateIsRequired': true,
|
||||
'settings.lotOccupancy.occupantCityDefault': '',
|
||||
'settings.lotOccupancy.occupantProvinceDefault': '',
|
||||
'settings.lotOccupancy.prints': ['screen/lotOccupancy'],
|
||||
'settings.contracts.burialSiteIdIsRequired': true,
|
||||
'settings.contracts.cityDefault': '',
|
||||
'settings.contracts.provinceDefault': '',
|
||||
'settings.contracts.prints': ['screen/contract'],
|
||||
|
||||
'settings.fees.taxPercentageDefault': 0,
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
export interface AddLotForm {
|
||||
lotName: string;
|
||||
lotTypeId: string | number;
|
||||
lotStatusId: string | number;
|
||||
mapId: string | number;
|
||||
mapKey: string;
|
||||
lotLatitude: string;
|
||||
lotLongitude: string;
|
||||
lotTypeFieldIds?: string;
|
||||
[lotFieldValue_lotTypeFieldId: string]: unknown;
|
||||
export interface AddBurialSiteForm {
|
||||
burialSiteNameSegment1: string;
|
||||
burialSiteNameSegment2?: string;
|
||||
burialSiteNameSegment3?: string;
|
||||
burialSiteNameSegment4?: string;
|
||||
burialSiteNameSegment5?: string;
|
||||
burialSiteTypeId: string | number;
|
||||
burialSiteStatusId: string | number;
|
||||
cemeteryId: string | number;
|
||||
cemeterySvgId: string;
|
||||
burialSiteLatitude: string;
|
||||
burialSiteLongitude: string;
|
||||
burialSiteTypeFieldIds?: string;
|
||||
[fieldValue_burialSiteTypeFieldId: string]: unknown;
|
||||
}
|
||||
export default function addLot(lotForm: AddLotForm, user: User): Promise<number>;
|
||||
export default function addLot(burialSiteForm: AddBurialSiteForm, user: User): Promise<number>;
|
||||
|
|
|
|||
|
|
@ -1,29 +1,37 @@
|
|||
import addOrUpdateLotField from './addOrUpdateLotField.js';
|
||||
import addOrUpdateBurialSiteField from './addOrUpdateBurialSiteField.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addLot(lotForm, user) {
|
||||
export default async function addLot(burialSiteForm, user) {
|
||||
const database = await acquireConnection();
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare(`insert into Lots (
|
||||
lotName, lotTypeId, lotStatusId,
|
||||
mapId, mapKey,
|
||||
lotLatitude, lotLongitude,
|
||||
.prepare(`insert into BurialSites (
|
||||
burialSiteNameSegment1,
|
||||
burialSiteNameSegment2,
|
||||
burialSiteNameSegment3,
|
||||
burialSiteNameSegment4,
|
||||
burialSiteNameSegment5,
|
||||
burialSiteTypeId, burialSiteStatusId,
|
||||
cemeteryId, cemeterySvgId,
|
||||
burialSiteLatitude, burialSiteLongitude,
|
||||
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(lotForm.lotName, lotForm.lotTypeId, lotForm.lotStatusId === '' ? undefined : lotForm.lotStatusId, lotForm.mapId === '' ? undefined : lotForm.mapId, lotForm.mapKey, lotForm.lotLatitude === '' ? undefined : lotForm.lotLatitude, lotForm.lotLongitude === '' ? undefined : lotForm.lotLongitude, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
const lotId = result.lastInsertRowid;
|
||||
const lotTypeFieldIds = (lotForm.lotTypeFieldIds ?? '').split(',');
|
||||
for (const lotTypeFieldId of lotTypeFieldIds) {
|
||||
const lotFieldValue = lotForm[`lotFieldValue_${lotTypeFieldId}`];
|
||||
if ((lotFieldValue ?? '') !== '') {
|
||||
await addOrUpdateLotField({
|
||||
lotId,
|
||||
lotTypeFieldId,
|
||||
lotFieldValue: lotFieldValue ?? ''
|
||||
values (?,
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?)`)
|
||||
.run(burialSiteForm.burialSiteNameSegment1, burialSiteForm.burialSiteNameSegment2 ?? '', burialSiteForm.burialSiteNameSegment3 ?? '', burialSiteForm.burialSiteNameSegment4 ?? '', burialSiteForm.burialSiteNameSegment5 ?? '', burialSiteForm.burialSiteTypeId, burialSiteForm.burialSiteStatusId === '' ? undefined : burialSiteForm.burialSiteStatusId, burialSiteForm.cemeteryId === '' ? undefined : burialSiteForm.cemeteryId, burialSiteForm.cemeterySvgId, burialSiteForm.burialSiteLatitude === '' ? undefined : burialSiteForm.burialSiteLatitude, burialSiteForm.burialSiteLongitude === '' ? undefined : burialSiteForm.burialSiteLongitude, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
const burialSiteId = result.lastInsertRowid;
|
||||
const burialSiteTypeFieldIds = (burialSiteForm.burialSiteTypeFieldIds ?? '').split(',');
|
||||
for (const burialSiteTypeFieldId of burialSiteTypeFieldIds) {
|
||||
const fieldValue = burialSiteForm[`burialSiteFieldValue_${burialSiteTypeFieldId}`];
|
||||
if ((fieldValue ?? '') !== '') {
|
||||
await addOrUpdateBurialSiteField({
|
||||
burialSiteId,
|
||||
burialSiteTypeFieldId,
|
||||
fieldValue: fieldValue ?? ''
|
||||
}, user, database);
|
||||
}
|
||||
}
|
||||
database.release();
|
||||
return lotId;
|
||||
return burialSiteId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,28 @@
|
|||
import addOrUpdateLotField from './addOrUpdateLotField.js'
|
||||
import addOrUpdateBurialSiteField from './addOrUpdateBurialSiteField.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddLotForm {
|
||||
lotName: string
|
||||
lotTypeId: string | number
|
||||
lotStatusId: string | number
|
||||
export interface AddBurialSiteForm {
|
||||
burialSiteNameSegment1: string
|
||||
burialSiteNameSegment2?: string
|
||||
burialSiteNameSegment3?: string
|
||||
burialSiteNameSegment4?: string
|
||||
burialSiteNameSegment5?: string
|
||||
|
||||
mapId: string | number
|
||||
mapKey: string
|
||||
burialSiteTypeId: string | number
|
||||
burialSiteStatusId: string | number
|
||||
|
||||
lotLatitude: string
|
||||
lotLongitude: string
|
||||
cemeteryId: string | number
|
||||
cemeterySvgId: string
|
||||
|
||||
lotTypeFieldIds?: string
|
||||
[lotFieldValue_lotTypeFieldId: string]: unknown
|
||||
burialSiteLatitude: string
|
||||
burialSiteLongitude: string
|
||||
|
||||
burialSiteTypeFieldIds?: string
|
||||
[fieldValue_burialSiteTypeFieldId: string]: unknown
|
||||
}
|
||||
|
||||
export default async function addLot(
|
||||
lotForm: AddLotForm,
|
||||
burialSiteForm: AddBurialSiteForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
|
|
@ -26,41 +31,53 @@ export default async function addLot(
|
|||
|
||||
const result = database
|
||||
.prepare(
|
||||
`insert into Lots (
|
||||
lotName, lotTypeId, lotStatusId,
|
||||
mapId, mapKey,
|
||||
lotLatitude, lotLongitude,
|
||||
`insert into BurialSites (
|
||||
burialSiteNameSegment1,
|
||||
burialSiteNameSegment2,
|
||||
burialSiteNameSegment3,
|
||||
burialSiteNameSegment4,
|
||||
burialSiteNameSegment5,
|
||||
burialSiteTypeId, burialSiteStatusId,
|
||||
cemeteryId, cemeterySvgId,
|
||||
burialSiteLatitude, burialSiteLongitude,
|
||||
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
values (?,
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?)`
|
||||
)
|
||||
.run(
|
||||
lotForm.lotName,
|
||||
lotForm.lotTypeId,
|
||||
lotForm.lotStatusId === '' ? undefined : lotForm.lotStatusId,
|
||||
lotForm.mapId === '' ? undefined : lotForm.mapId,
|
||||
lotForm.mapKey,
|
||||
lotForm.lotLatitude === '' ? undefined : lotForm.lotLatitude,
|
||||
lotForm.lotLongitude === '' ? undefined : lotForm.lotLongitude,
|
||||
burialSiteForm.burialSiteNameSegment1,
|
||||
burialSiteForm.burialSiteNameSegment2 ?? '',
|
||||
burialSiteForm.burialSiteNameSegment3 ?? '',
|
||||
burialSiteForm.burialSiteNameSegment4 ?? '',
|
||||
burialSiteForm.burialSiteNameSegment5 ?? '',
|
||||
burialSiteForm.burialSiteTypeId,
|
||||
burialSiteForm.burialSiteStatusId === '' ? undefined : burialSiteForm.burialSiteStatusId,
|
||||
burialSiteForm.cemeteryId === '' ? undefined : burialSiteForm.cemeteryId,
|
||||
burialSiteForm.cemeterySvgId,
|
||||
burialSiteForm.burialSiteLatitude === '' ? undefined : burialSiteForm.burialSiteLatitude,
|
||||
burialSiteForm.burialSiteLongitude === '' ? undefined : burialSiteForm.burialSiteLongitude,
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
user.userName,
|
||||
rightNowMillis
|
||||
)
|
||||
|
||||
const lotId = result.lastInsertRowid as number
|
||||
const burialSiteId = result.lastInsertRowid as number
|
||||
|
||||
const lotTypeFieldIds = (lotForm.lotTypeFieldIds ?? '').split(',')
|
||||
const burialSiteTypeFieldIds = (burialSiteForm.burialSiteTypeFieldIds ?? '').split(',')
|
||||
|
||||
for (const lotTypeFieldId of lotTypeFieldIds) {
|
||||
const lotFieldValue = lotForm[`lotFieldValue_${lotTypeFieldId}`] as string | undefined
|
||||
for (const burialSiteTypeFieldId of burialSiteTypeFieldIds) {
|
||||
const fieldValue = burialSiteForm[`burialSiteFieldValue_${burialSiteTypeFieldId}`] as string | undefined
|
||||
|
||||
if ((lotFieldValue ?? '') !== '') {
|
||||
await addOrUpdateLotField(
|
||||
if ((fieldValue ?? '') !== '') {
|
||||
await addOrUpdateBurialSiteField(
|
||||
{
|
||||
lotId,
|
||||
lotTypeFieldId,
|
||||
lotFieldValue: lotFieldValue ?? ''
|
||||
burialSiteId,
|
||||
burialSiteTypeFieldId,
|
||||
fieldValue: fieldValue ?? ''
|
||||
},
|
||||
user,
|
||||
database
|
||||
|
|
@ -70,5 +87,5 @@ export default async function addLot(
|
|||
|
||||
database.release()
|
||||
|
||||
return lotId
|
||||
return burialSiteId
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
export interface AddBurialSiteContractForm {
|
||||
contractTypeId: string | number;
|
||||
burialSiteId: string | number;
|
||||
contractStartDateString: string;
|
||||
contractEndDateString: string;
|
||||
contractTypeFieldIds?: string;
|
||||
[fieldValue_contractTypeFieldId: string]: unknown;
|
||||
lotOccupantTypeId?: string;
|
||||
occupantName?: string;
|
||||
occupantFamilyName?: string;
|
||||
occupantAddress1?: string;
|
||||
occupantAddress2?: string;
|
||||
occupantCity?: string;
|
||||
occupantProvince?: string;
|
||||
occupantPostalCode?: string;
|
||||
occupantPhoneNumber?: string;
|
||||
occupantEmailAddress?: string;
|
||||
occupantComment?: string;
|
||||
}
|
||||
export default function addLotOccupancy(addForm: AddBurialSiteContractForm, user: User, connectedDatabase?: PoolConnection): Promise<number>;
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
import { dateStringToInteger } from '@cityssm/utils-datetime';
|
||||
import addLotOccupancyOccupant from './addLotOccupancyOccupant.js';
|
||||
import addOrUpdateBurialSiteContractField from './addOrUpdateBurialSiteContractField.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addLotOccupancy(addForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
const rightNowMillis = Date.now();
|
||||
const contractStartDate = dateStringToInteger(addForm.contractStartDateString);
|
||||
if (contractStartDate <= 0) {
|
||||
console.error(addForm);
|
||||
}
|
||||
const result = database
|
||||
.prepare(`insert into BurialSiteContracts (
|
||||
contractTypeId, lotId,
|
||||
contractStartDate, contractEndDate,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(addForm.contractTypeId, addForm.burialSiteId === '' ? undefined : addForm.burialSiteId, contractStartDate, addForm.contractEndDateString === ''
|
||||
? undefined
|
||||
: dateStringToInteger(addForm.contractEndDateString), user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
const burialSiteContractId = result.lastInsertRowid;
|
||||
const contractTypeFieldIds = (addForm.contractTypeFieldIds ?? '').split(',');
|
||||
for (const contractTypeFieldId of contractTypeFieldIds) {
|
||||
const lotOccupancyFieldValue = addForm[`lotOccupancyFieldValue_${contractTypeFieldId}`];
|
||||
if ((lotOccupancyFieldValue ?? '') !== '') {
|
||||
await addOrUpdateBurialSiteContractField({
|
||||
burialSiteContractId,
|
||||
contractTypeFieldId,
|
||||
lotOccupancyFieldValue: lotOccupancyFieldValue ?? ''
|
||||
}, user, database);
|
||||
}
|
||||
}
|
||||
if ((addForm.lotOccupantTypeId ?? '') !== '') {
|
||||
await addLotOccupancyOccupant({
|
||||
burialSiteContractId,
|
||||
lotOccupantTypeId: addForm.lotOccupantTypeId ?? '',
|
||||
occupantName: addForm.occupantName ?? '',
|
||||
occupantFamilyName: addForm.occupantFamilyName ?? '',
|
||||
occupantAddress1: addForm.occupantAddress1 ?? '',
|
||||
occupantAddress2: addForm.occupantAddress2 ?? '',
|
||||
occupantCity: addForm.occupantCity ?? '',
|
||||
occupantProvince: addForm.occupantProvince ?? '',
|
||||
occupantPostalCode: addForm.occupantPostalCode ?? '',
|
||||
occupantPhoneNumber: addForm.occupantPhoneNumber ?? '',
|
||||
occupantEmailAddress: addForm.occupantEmailAddress ?? '',
|
||||
occupantComment: addForm.occupantComment ?? ''
|
||||
}, user, database);
|
||||
}
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return burialSiteContractId;
|
||||
}
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
import { type DateString, dateStringToInteger } from '@cityssm/utils-datetime'
|
||||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import addLotOccupancyOccupant from './addLotOccupancyOccupant.js'
|
||||
import addOrUpdateBurialSiteContractField from './addOrUpdateBurialSiteContractField.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddBurialSiteContractForm {
|
||||
contractTypeId: string | number
|
||||
burialSiteId: string | number
|
||||
|
||||
contractStartDateString: string
|
||||
contractEndDateString: string
|
||||
|
||||
contractTypeFieldIds?: string
|
||||
[fieldValue_contractTypeFieldId: string]: unknown
|
||||
|
||||
lotOccupantTypeId?: string
|
||||
occupantName?: string
|
||||
occupantFamilyName?: string
|
||||
occupantAddress1?: string
|
||||
occupantAddress2?: string
|
||||
occupantCity?: string
|
||||
occupantProvince?: string
|
||||
occupantPostalCode?: string
|
||||
occupantPhoneNumber?: string
|
||||
occupantEmailAddress?: string
|
||||
occupantComment?: string
|
||||
}
|
||||
|
||||
export default async function addLotOccupancy(
|
||||
addForm: AddBurialSiteContractForm,
|
||||
user: User,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<number> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
const contractStartDate = dateStringToInteger(
|
||||
addForm.contractStartDateString as DateString
|
||||
)
|
||||
|
||||
if (contractStartDate <= 0) {
|
||||
console.error(addForm)
|
||||
}
|
||||
|
||||
const result = database
|
||||
.prepare(
|
||||
`insert into BurialSiteContracts (
|
||||
contractTypeId, lotId,
|
||||
contractStartDate, contractEndDate,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
)
|
||||
.run(
|
||||
addForm.contractTypeId,
|
||||
addForm.burialSiteId === '' ? undefined : addForm.burialSiteId,
|
||||
contractStartDate,
|
||||
addForm.contractEndDateString === ''
|
||||
? undefined
|
||||
: dateStringToInteger(
|
||||
addForm.contractEndDateString as DateString
|
||||
),
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
user.userName,
|
||||
rightNowMillis
|
||||
)
|
||||
|
||||
const burialSiteContractId = result.lastInsertRowid as number
|
||||
|
||||
const contractTypeFieldIds = (
|
||||
addForm.contractTypeFieldIds ?? ''
|
||||
).split(',')
|
||||
|
||||
for (const contractTypeFieldId of contractTypeFieldIds) {
|
||||
const lotOccupancyFieldValue = addForm[
|
||||
`lotOccupancyFieldValue_${contractTypeFieldId}`
|
||||
] as string | undefined
|
||||
|
||||
if ((lotOccupancyFieldValue ?? '') !== '') {
|
||||
await addOrUpdateBurialSiteContractField(
|
||||
{
|
||||
burialSiteContractId,
|
||||
contractTypeFieldId,
|
||||
lotOccupancyFieldValue: lotOccupancyFieldValue ?? ''
|
||||
},
|
||||
user,
|
||||
database
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if ((addForm.lotOccupantTypeId ?? '') !== '') {
|
||||
await addLotOccupancyOccupant(
|
||||
{
|
||||
burialSiteContractId,
|
||||
lotOccupantTypeId: addForm.lotOccupantTypeId ?? '',
|
||||
occupantName: addForm.occupantName ?? '',
|
||||
occupantFamilyName: addForm.occupantFamilyName ?? '',
|
||||
occupantAddress1: addForm.occupantAddress1 ?? '',
|
||||
occupantAddress2: addForm.occupantAddress2 ?? '',
|
||||
occupantCity: addForm.occupantCity ?? '',
|
||||
occupantProvince: addForm.occupantProvince ?? '',
|
||||
occupantPostalCode: addForm.occupantPostalCode ?? '',
|
||||
occupantPhoneNumber: addForm.occupantPhoneNumber ?? '',
|
||||
occupantEmailAddress: addForm.occupantEmailAddress ?? '',
|
||||
occupantComment: addForm.occupantComment ?? ''
|
||||
},
|
||||
user,
|
||||
database
|
||||
)
|
||||
}
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return burialSiteContractId
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
export interface AddBurialSiteContractFeeForm {
|
||||
burialSiteContractId: number | string;
|
||||
feeId: number | string;
|
||||
quantity: number | string;
|
||||
feeAmount?: number | string;
|
||||
taxAmount?: number | string;
|
||||
}
|
||||
export default function addBurialSiteContractFee(addFeeForm: AddBurialSiteContractFeeForm, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;
|
||||
|
|
@ -1,84 +1,84 @@
|
|||
import { calculateFeeAmount, calculateTaxAmount } from '../helpers/functions.fee.js';
|
||||
import getBurialSiteContract from './getBurialSiteContract.js';
|
||||
import getFee from './getFee.js';
|
||||
import getLotOccupancy from './getLotOccupancy.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addLotOccupancyFee(lotOccupancyFeeForm, user, connectedDatabase) {
|
||||
export default async function addBurialSiteContractFee(addFeeForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
const rightNowMillis = Date.now();
|
||||
// Calculate fee and tax (if not set)
|
||||
let feeAmount;
|
||||
let taxAmount;
|
||||
if ((lotOccupancyFeeForm.feeAmount ?? '') === '') {
|
||||
const lotOccupancy = (await getLotOccupancy(lotOccupancyFeeForm.lotOccupancyId));
|
||||
const fee = (await getFee(lotOccupancyFeeForm.feeId));
|
||||
if ((addFeeForm.feeAmount ?? '') === '') {
|
||||
const lotOccupancy = (await getBurialSiteContract(addFeeForm.burialSiteContractId));
|
||||
const fee = (await getFee(addFeeForm.feeId));
|
||||
feeAmount = calculateFeeAmount(fee, lotOccupancy);
|
||||
taxAmount = calculateTaxAmount(fee, feeAmount);
|
||||
}
|
||||
else {
|
||||
feeAmount =
|
||||
typeof lotOccupancyFeeForm.feeAmount === 'string'
|
||||
? Number.parseFloat(lotOccupancyFeeForm.feeAmount)
|
||||
typeof addFeeForm.feeAmount === 'string'
|
||||
? Number.parseFloat(addFeeForm.feeAmount)
|
||||
: 0;
|
||||
taxAmount =
|
||||
typeof lotOccupancyFeeForm.taxAmount === 'string'
|
||||
? Number.parseFloat(lotOccupancyFeeForm.taxAmount)
|
||||
typeof addFeeForm.taxAmount === 'string'
|
||||
? Number.parseFloat(addFeeForm.taxAmount)
|
||||
: 0;
|
||||
}
|
||||
try {
|
||||
// Check if record already exists
|
||||
const record = database
|
||||
.prepare(`select feeAmount, taxAmount, recordDelete_timeMillis
|
||||
from LotOccupancyFees
|
||||
where lotOccupancyId = ?
|
||||
from BurialSiteContractFees
|
||||
where burialSiteContractId = ?
|
||||
and feeId = ?`)
|
||||
.get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||
.get(addFeeForm.burialSiteContractId, addFeeForm.feeId);
|
||||
if (record !== undefined) {
|
||||
if (record.recordDelete_timeMillis !== null) {
|
||||
database
|
||||
.prepare(`delete from LotOccupancyFees
|
||||
.prepare(`delete from BurialSiteContractFees
|
||||
where recordDelete_timeMillis is not null
|
||||
and lotOccupancyId = ?
|
||||
and burialSiteContractId = ?
|
||||
and feeId = ?`)
|
||||
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||
.run(addFeeForm.burialSiteContractId, addFeeForm.feeId);
|
||||
}
|
||||
else if (record.feeAmount === feeAmount &&
|
||||
record.taxAmount === taxAmount) {
|
||||
database
|
||||
.prepare(`update LotOccupancyFees
|
||||
.prepare(`update BurialSiteContractFees
|
||||
set quantity = quantity + ?,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where lotOccupancyId = ?
|
||||
where burialSiteContractId = ?
|
||||
and feeId = ?`)
|
||||
.run(lotOccupancyFeeForm.quantity, user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||
.run(addFeeForm.quantity, user.userName, rightNowMillis, addFeeForm.burialSiteContractId, addFeeForm.feeId);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
const quantity = typeof lotOccupancyFeeForm.quantity === 'string'
|
||||
? Number.parseFloat(lotOccupancyFeeForm.quantity)
|
||||
: lotOccupancyFeeForm.quantity;
|
||||
const quantity = typeof addFeeForm.quantity === 'string'
|
||||
? Number.parseFloat(addFeeForm.quantity)
|
||||
: addFeeForm.quantity;
|
||||
database
|
||||
.prepare(`update LotOccupancyFees
|
||||
.prepare(`update BurialSiteContractFees
|
||||
set feeAmount = (feeAmount * quantity) + ?,
|
||||
taxAmount = (taxAmount * quantity) + ?,
|
||||
quantity = 1,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where lotOccupancyId = ?
|
||||
where burialSiteContractId = ?
|
||||
and feeId = ?`)
|
||||
.run(feeAmount * quantity, taxAmount * quantity, user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||
.run(feeAmount * quantity, taxAmount * quantity, user.userName, rightNowMillis, addFeeForm.burialSiteContractId, addFeeForm.feeId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Create new record
|
||||
const result = database
|
||||
.prepare(`insert into LotOccupancyFees (
|
||||
lotOccupancyId, feeId,
|
||||
.prepare(`insert into BurialSiteContractFees (
|
||||
burialSiteContractId, feeId,
|
||||
quantity, feeAmount, taxAmount,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId, lotOccupancyFeeForm.quantity, feeAmount, taxAmount, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
.run(addFeeForm.burialSiteContractId, addFeeForm.feeId, addFeeForm.quantity, feeAmount, taxAmount, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
return result.changes > 0;
|
||||
}
|
||||
finally {
|
||||
|
|
@ -4,22 +4,22 @@ import {
|
|||
calculateFeeAmount,
|
||||
calculateTaxAmount
|
||||
} from '../helpers/functions.fee.js'
|
||||
import type { Fee, LotOccupancy } from '../types/recordTypes.js'
|
||||
import type { BurialSiteContract, Fee } from '../types/recordTypes.js'
|
||||
|
||||
import getBurialSiteContract from './getBurialSiteContract.js'
|
||||
import getFee from './getFee.js'
|
||||
import getLotOccupancy from './getLotOccupancy.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddLotOccupancyFeeForm {
|
||||
lotOccupancyId: number | string
|
||||
export interface AddBurialSiteContractFeeForm {
|
||||
burialSiteContractId: number | string
|
||||
feeId: number | string
|
||||
quantity: number | string
|
||||
feeAmount?: number | string
|
||||
taxAmount?: number | string
|
||||
}
|
||||
|
||||
export default async function addLotOccupancyFee(
|
||||
lotOccupancyFeeForm: AddLotOccupancyFeeForm,
|
||||
export default async function addBurialSiteContractFee(
|
||||
addFeeForm: AddBurialSiteContractFeeForm,
|
||||
user: User,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<boolean> {
|
||||
|
|
@ -31,23 +31,23 @@ export default async function addLotOccupancyFee(
|
|||
let feeAmount: number
|
||||
let taxAmount: number
|
||||
|
||||
if ((lotOccupancyFeeForm.feeAmount ?? '') === '') {
|
||||
const lotOccupancy = (await getLotOccupancy(
|
||||
lotOccupancyFeeForm.lotOccupancyId
|
||||
)) as LotOccupancy
|
||||
if ((addFeeForm.feeAmount ?? '') === '') {
|
||||
const lotOccupancy = (await getBurialSiteContract(
|
||||
addFeeForm.burialSiteContractId
|
||||
)) as BurialSiteContract
|
||||
|
||||
const fee = (await getFee(lotOccupancyFeeForm.feeId)) as Fee
|
||||
const fee = (await getFee(addFeeForm.feeId)) as Fee
|
||||
|
||||
feeAmount = calculateFeeAmount(fee, lotOccupancy)
|
||||
taxAmount = calculateTaxAmount(fee, feeAmount)
|
||||
} else {
|
||||
feeAmount =
|
||||
typeof lotOccupancyFeeForm.feeAmount === 'string'
|
||||
? Number.parseFloat(lotOccupancyFeeForm.feeAmount)
|
||||
typeof addFeeForm.feeAmount === 'string'
|
||||
? Number.parseFloat(addFeeForm.feeAmount)
|
||||
: 0
|
||||
taxAmount =
|
||||
typeof lotOccupancyFeeForm.taxAmount === 'string'
|
||||
? Number.parseFloat(lotOccupancyFeeForm.taxAmount)
|
||||
typeof addFeeForm.taxAmount === 'string'
|
||||
? Number.parseFloat(addFeeForm.taxAmount)
|
||||
: 0
|
||||
}
|
||||
|
||||
|
|
@ -56,11 +56,11 @@ export default async function addLotOccupancyFee(
|
|||
const record = database
|
||||
.prepare(
|
||||
`select feeAmount, taxAmount, recordDelete_timeMillis
|
||||
from LotOccupancyFees
|
||||
where lotOccupancyId = ?
|
||||
from BurialSiteContractFees
|
||||
where burialSiteContractId = ?
|
||||
and feeId = ?`
|
||||
)
|
||||
.get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId) as
|
||||
.get(addFeeForm.burialSiteContractId, addFeeForm.feeId) as
|
||||
| {
|
||||
feeAmount: number | null
|
||||
taxAmount: number | null
|
||||
|
|
@ -72,49 +72,49 @@ export default async function addLotOccupancyFee(
|
|||
if (record.recordDelete_timeMillis !== null) {
|
||||
database
|
||||
.prepare(
|
||||
`delete from LotOccupancyFees
|
||||
`delete from BurialSiteContractFees
|
||||
where recordDelete_timeMillis is not null
|
||||
and lotOccupancyId = ?
|
||||
and burialSiteContractId = ?
|
||||
and feeId = ?`
|
||||
)
|
||||
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId)
|
||||
.run(addFeeForm.burialSiteContractId, addFeeForm.feeId)
|
||||
} else if (
|
||||
record.feeAmount === feeAmount &&
|
||||
record.taxAmount === taxAmount
|
||||
) {
|
||||
database
|
||||
.prepare(
|
||||
`update LotOccupancyFees
|
||||
`update BurialSiteContractFees
|
||||
set quantity = quantity + ?,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where lotOccupancyId = ?
|
||||
where burialSiteContractId = ?
|
||||
and feeId = ?`
|
||||
)
|
||||
.run(
|
||||
lotOccupancyFeeForm.quantity,
|
||||
addFeeForm.quantity,
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
lotOccupancyFeeForm.lotOccupancyId,
|
||||
lotOccupancyFeeForm.feeId
|
||||
addFeeForm.burialSiteContractId,
|
||||
addFeeForm.feeId
|
||||
)
|
||||
|
||||
return true
|
||||
} else {
|
||||
const quantity =
|
||||
typeof lotOccupancyFeeForm.quantity === 'string'
|
||||
? Number.parseFloat(lotOccupancyFeeForm.quantity)
|
||||
: lotOccupancyFeeForm.quantity
|
||||
typeof addFeeForm.quantity === 'string'
|
||||
? Number.parseFloat(addFeeForm.quantity)
|
||||
: addFeeForm.quantity
|
||||
|
||||
database
|
||||
.prepare(
|
||||
`update LotOccupancyFees
|
||||
`update BurialSiteContractFees
|
||||
set feeAmount = (feeAmount * quantity) + ?,
|
||||
taxAmount = (taxAmount * quantity) + ?,
|
||||
quantity = 1,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where lotOccupancyId = ?
|
||||
where burialSiteContractId = ?
|
||||
and feeId = ?`
|
||||
)
|
||||
.run(
|
||||
|
|
@ -122,8 +122,8 @@ export default async function addLotOccupancyFee(
|
|||
taxAmount * quantity,
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
lotOccupancyFeeForm.lotOccupancyId,
|
||||
lotOccupancyFeeForm.feeId
|
||||
addFeeForm.burialSiteContractId,
|
||||
addFeeForm.feeId
|
||||
)
|
||||
|
||||
return true
|
||||
|
|
@ -133,17 +133,17 @@ export default async function addLotOccupancyFee(
|
|||
// Create new record
|
||||
const result = database
|
||||
.prepare(
|
||||
`insert into LotOccupancyFees (
|
||||
lotOccupancyId, feeId,
|
||||
`insert into BurialSiteContractFees (
|
||||
burialSiteContractId, feeId,
|
||||
quantity, feeAmount, taxAmount,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
)
|
||||
.run(
|
||||
lotOccupancyFeeForm.lotOccupancyId,
|
||||
lotOccupancyFeeForm.feeId,
|
||||
lotOccupancyFeeForm.quantity,
|
||||
addFeeForm.burialSiteContractId,
|
||||
addFeeForm.feeId,
|
||||
addFeeForm.quantity,
|
||||
feeAmount,
|
||||
taxAmount,
|
||||
user.userName,
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
export interface AddBurialSiteContractCategoryForm {
|
||||
burialSiteContractId: number | string;
|
||||
feeCategoryId: number | string;
|
||||
}
|
||||
export default function addLotOccupancyFeeCategory(addFeeCategoryForm: AddBurialSiteContractCategoryForm, user: User): Promise<number>;
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
import addLotOccupancyFee from './addLotOccupancyFee.js';
|
||||
import addBurialSiteContractFee from './addBurialSiteContractFee.js';
|
||||
import { getFeeCategory } from './getFeeCategories.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addLotOccupancyFeeCategory(lotOccupancyFeeCategoryForm, user) {
|
||||
export default async function addLotOccupancyFeeCategory(addFeeCategoryForm, user) {
|
||||
const database = await acquireConnection();
|
||||
const feeCategory = await getFeeCategory(lotOccupancyFeeCategoryForm.feeCategoryId, database);
|
||||
const feeCategory = await getFeeCategory(addFeeCategoryForm.feeCategoryId, database);
|
||||
let addedFeeCount = 0;
|
||||
for (const fee of feeCategory?.fees ?? []) {
|
||||
const success = await addLotOccupancyFee({
|
||||
lotOccupancyId: lotOccupancyFeeCategoryForm.lotOccupancyId,
|
||||
const success = await addBurialSiteContractFee({
|
||||
burialSiteContractId: addFeeCategoryForm.burialSiteContractId,
|
||||
feeId: fee.feeId,
|
||||
quantity: 1
|
||||
}, user, database);
|
||||
|
|
@ -1,29 +1,29 @@
|
|||
import addLotOccupancyFee from './addLotOccupancyFee.js'
|
||||
import addBurialSiteContractFee from './addBurialSiteContractFee.js'
|
||||
import { getFeeCategory } from './getFeeCategories.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddLotOccupancyFeeCategoryForm {
|
||||
lotOccupancyId: number | string
|
||||
export interface AddBurialSiteContractCategoryForm {
|
||||
burialSiteContractId: number | string
|
||||
feeCategoryId: number | string
|
||||
}
|
||||
|
||||
export default async function addLotOccupancyFeeCategory(
|
||||
lotOccupancyFeeCategoryForm: AddLotOccupancyFeeCategoryForm,
|
||||
addFeeCategoryForm: AddBurialSiteContractCategoryForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
|
||||
const feeCategory = await getFeeCategory(
|
||||
lotOccupancyFeeCategoryForm.feeCategoryId,
|
||||
addFeeCategoryForm.feeCategoryId,
|
||||
database
|
||||
)
|
||||
|
||||
let addedFeeCount = 0
|
||||
|
||||
for (const fee of feeCategory?.fees ?? []) {
|
||||
const success = await addLotOccupancyFee(
|
||||
const success = await addBurialSiteContractFee(
|
||||
{
|
||||
lotOccupancyId: lotOccupancyFeeCategoryForm.lotOccupancyId,
|
||||
burialSiteContractId: addFeeCategoryForm.burialSiteContractId,
|
||||
feeId: fee.feeId,
|
||||
quantity: 1
|
||||
},
|
||||
|
|
@ -14,6 +14,6 @@ export default async function addContractTypeField(addForm, user) {
|
|||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(addForm.contractTypeId ?? undefined, addForm.contractTypeField, addForm.fieldType ?? 'text', addForm.fieldValues ?? '', addForm.isRequired === '' ? 0 : 1, addForm.pattern ?? '', addForm.minimumLength ?? 0, addForm.maximumLength ?? 100, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
database.release();
|
||||
clearCacheByTableName('OccupancyTypeFields');
|
||||
clearCacheByTableName('ContractTypeFields');
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ export default async function addContractTypeField(
|
|||
|
||||
database.release()
|
||||
|
||||
clearCacheByTableName('OccupancyTypeFields')
|
||||
clearCacheByTableName('ContractTypeFields')
|
||||
|
||||
return result.lastInsertRowid as number
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
export interface AddLotOccupancyForm {
|
||||
occupancyTypeId: string | number;
|
||||
lotId: string | number;
|
||||
occupancyStartDateString: string;
|
||||
occupancyEndDateString: string;
|
||||
occupancyTypeFieldIds?: string;
|
||||
[lotOccupancyFieldValue_occupancyTypeFieldId: string]: unknown;
|
||||
lotOccupantTypeId?: string;
|
||||
occupantName?: string;
|
||||
occupantFamilyName?: string;
|
||||
occupantAddress1?: string;
|
||||
occupantAddress2?: string;
|
||||
occupantCity?: string;
|
||||
occupantProvince?: string;
|
||||
occupantPostalCode?: string;
|
||||
occupantPhoneNumber?: string;
|
||||
occupantEmailAddress?: string;
|
||||
occupantComment?: string;
|
||||
}
|
||||
export default function addLotOccupancy(lotOccupancyForm: AddLotOccupancyForm, user: User, connectedDatabase?: PoolConnection): Promise<number>;
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
import { dateStringToInteger } from '@cityssm/utils-datetime';
|
||||
import addLotOccupancyOccupant from './addLotOccupancyOccupant.js';
|
||||
import addOrUpdateLotOccupancyField from './addOrUpdateLotOccupancyField.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addLotOccupancy(lotOccupancyForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
const rightNowMillis = Date.now();
|
||||
const occupancyStartDate = dateStringToInteger(lotOccupancyForm.occupancyStartDateString);
|
||||
if (occupancyStartDate <= 0) {
|
||||
console.error(lotOccupancyForm);
|
||||
}
|
||||
const result = database
|
||||
.prepare(`insert into LotOccupancies (
|
||||
occupancyTypeId, lotId,
|
||||
occupancyStartDate, occupancyEndDate,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(lotOccupancyForm.occupancyTypeId, lotOccupancyForm.lotId === '' ? undefined : lotOccupancyForm.lotId, occupancyStartDate, lotOccupancyForm.occupancyEndDateString === ''
|
||||
? undefined
|
||||
: dateStringToInteger(lotOccupancyForm.occupancyEndDateString), user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
const lotOccupancyId = result.lastInsertRowid;
|
||||
const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds ?? '').split(',');
|
||||
for (const occupancyTypeFieldId of occupancyTypeFieldIds) {
|
||||
const lotOccupancyFieldValue = lotOccupancyForm[`lotOccupancyFieldValue_${occupancyTypeFieldId}`];
|
||||
if ((lotOccupancyFieldValue ?? '') !== '') {
|
||||
await addOrUpdateLotOccupancyField({
|
||||
lotOccupancyId,
|
||||
occupancyTypeFieldId,
|
||||
lotOccupancyFieldValue: lotOccupancyFieldValue ?? ''
|
||||
}, user, database);
|
||||
}
|
||||
}
|
||||
if ((lotOccupancyForm.lotOccupantTypeId ?? '') !== '') {
|
||||
await addLotOccupancyOccupant({
|
||||
lotOccupancyId,
|
||||
lotOccupantTypeId: lotOccupancyForm.lotOccupantTypeId ?? '',
|
||||
occupantName: lotOccupancyForm.occupantName ?? '',
|
||||
occupantFamilyName: lotOccupancyForm.occupantFamilyName ?? '',
|
||||
occupantAddress1: lotOccupancyForm.occupantAddress1 ?? '',
|
||||
occupantAddress2: lotOccupancyForm.occupantAddress2 ?? '',
|
||||
occupantCity: lotOccupancyForm.occupantCity ?? '',
|
||||
occupantProvince: lotOccupancyForm.occupantProvince ?? '',
|
||||
occupantPostalCode: lotOccupancyForm.occupantPostalCode ?? '',
|
||||
occupantPhoneNumber: lotOccupancyForm.occupantPhoneNumber ?? '',
|
||||
occupantEmailAddress: lotOccupancyForm.occupantEmailAddress ?? '',
|
||||
occupantComment: lotOccupancyForm.occupantComment ?? ''
|
||||
}, user, database);
|
||||
}
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return lotOccupancyId;
|
||||
}
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
import { type DateString, dateStringToInteger } from '@cityssm/utils-datetime'
|
||||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import addLotOccupancyOccupant from './addLotOccupancyOccupant.js'
|
||||
import addOrUpdateLotOccupancyField from './addOrUpdateLotOccupancyField.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddLotOccupancyForm {
|
||||
occupancyTypeId: string | number
|
||||
lotId: string | number
|
||||
|
||||
occupancyStartDateString: string
|
||||
occupancyEndDateString: string
|
||||
|
||||
occupancyTypeFieldIds?: string
|
||||
[lotOccupancyFieldValue_occupancyTypeFieldId: string]: unknown
|
||||
|
||||
lotOccupantTypeId?: string
|
||||
occupantName?: string
|
||||
occupantFamilyName?: string
|
||||
occupantAddress1?: string
|
||||
occupantAddress2?: string
|
||||
occupantCity?: string
|
||||
occupantProvince?: string
|
||||
occupantPostalCode?: string
|
||||
occupantPhoneNumber?: string
|
||||
occupantEmailAddress?: string
|
||||
occupantComment?: string
|
||||
}
|
||||
|
||||
export default async function addLotOccupancy(
|
||||
lotOccupancyForm: AddLotOccupancyForm,
|
||||
user: User,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<number> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
const occupancyStartDate = dateStringToInteger(
|
||||
lotOccupancyForm.occupancyStartDateString as DateString
|
||||
)
|
||||
|
||||
if (occupancyStartDate <= 0) {
|
||||
console.error(lotOccupancyForm)
|
||||
}
|
||||
|
||||
const result = database
|
||||
.prepare(
|
||||
`insert into LotOccupancies (
|
||||
occupancyTypeId, lotId,
|
||||
occupancyStartDate, occupancyEndDate,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
)
|
||||
.run(
|
||||
lotOccupancyForm.occupancyTypeId,
|
||||
lotOccupancyForm.lotId === '' ? undefined : lotOccupancyForm.lotId,
|
||||
occupancyStartDate,
|
||||
lotOccupancyForm.occupancyEndDateString === ''
|
||||
? undefined
|
||||
: dateStringToInteger(
|
||||
lotOccupancyForm.occupancyEndDateString as DateString
|
||||
),
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
user.userName,
|
||||
rightNowMillis
|
||||
)
|
||||
|
||||
const lotOccupancyId = result.lastInsertRowid as number
|
||||
|
||||
const occupancyTypeFieldIds = (
|
||||
lotOccupancyForm.occupancyTypeFieldIds ?? ''
|
||||
).split(',')
|
||||
|
||||
for (const occupancyTypeFieldId of occupancyTypeFieldIds) {
|
||||
const lotOccupancyFieldValue = lotOccupancyForm[
|
||||
`lotOccupancyFieldValue_${occupancyTypeFieldId}`
|
||||
] as string | undefined
|
||||
|
||||
if ((lotOccupancyFieldValue ?? '') !== '') {
|
||||
await addOrUpdateLotOccupancyField(
|
||||
{
|
||||
lotOccupancyId,
|
||||
occupancyTypeFieldId,
|
||||
lotOccupancyFieldValue: lotOccupancyFieldValue ?? ''
|
||||
},
|
||||
user,
|
||||
database
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if ((lotOccupancyForm.lotOccupantTypeId ?? '') !== '') {
|
||||
await addLotOccupancyOccupant(
|
||||
{
|
||||
lotOccupancyId,
|
||||
lotOccupantTypeId: lotOccupancyForm.lotOccupantTypeId ?? '',
|
||||
occupantName: lotOccupancyForm.occupantName ?? '',
|
||||
occupantFamilyName: lotOccupancyForm.occupantFamilyName ?? '',
|
||||
occupantAddress1: lotOccupancyForm.occupantAddress1 ?? '',
|
||||
occupantAddress2: lotOccupancyForm.occupantAddress2 ?? '',
|
||||
occupantCity: lotOccupancyForm.occupantCity ?? '',
|
||||
occupantProvince: lotOccupancyForm.occupantProvince ?? '',
|
||||
occupantPostalCode: lotOccupancyForm.occupantPostalCode ?? '',
|
||||
occupantPhoneNumber: lotOccupancyForm.occupantPhoneNumber ?? '',
|
||||
occupantEmailAddress: lotOccupancyForm.occupantEmailAddress ?? '',
|
||||
occupantComment: lotOccupancyForm.occupantComment ?? ''
|
||||
},
|
||||
user,
|
||||
database
|
||||
)
|
||||
}
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return lotOccupancyId
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
export interface AddLotOccupancyFeeForm {
|
||||
lotOccupancyId: number | string;
|
||||
feeId: number | string;
|
||||
quantity: number | string;
|
||||
feeAmount?: number | string;
|
||||
taxAmount?: number | string;
|
||||
}
|
||||
export default function addLotOccupancyFee(lotOccupancyFeeForm: AddLotOccupancyFeeForm, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
export interface AddLotOccupancyFeeCategoryForm {
|
||||
lotOccupancyId: number | string;
|
||||
feeCategoryId: number | string;
|
||||
}
|
||||
export default function addLotOccupancyFeeCategory(lotOccupancyFeeCategoryForm: AddLotOccupancyFeeCategoryForm, user: User): Promise<number>;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
export interface AddLotOccupancyTransactionForm {
|
||||
lotOccupancyId: string | number;
|
||||
burialSiteContractId: string | number;
|
||||
transactionDateString?: string;
|
||||
transactionTimeString?: string;
|
||||
transactionAmount: string | number;
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ export default async function addLotOccupancyTransaction(lotOccupancyTransaction
|
|||
const maxIndexResult = database
|
||||
.prepare(`select transactionIndex
|
||||
from LotOccupancyTransactions
|
||||
where lotOccupancyId = ?
|
||||
where burialSiteContractId = ?
|
||||
order by transactionIndex desc
|
||||
limit 1`)
|
||||
.get(lotOccupancyTransactionForm.lotOccupancyId);
|
||||
.get(lotOccupancyTransactionForm.burialSiteContractId);
|
||||
if (maxIndexResult !== undefined) {
|
||||
transactionIndex = maxIndexResult.transactionIndex + 1;
|
||||
}
|
||||
|
|
@ -22,13 +22,13 @@ export default async function addLotOccupancyTransaction(lotOccupancyTransaction
|
|||
: dateToTimeInteger(rightNow);
|
||||
database
|
||||
.prepare(`insert into LotOccupancyTransactions (
|
||||
lotOccupancyId, transactionIndex,
|
||||
burialSiteContractId, transactionIndex,
|
||||
transactionDate, transactionTime,
|
||||
transactionAmount, externalReceiptNumber, transactionNote,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(lotOccupancyTransactionForm.lotOccupancyId, transactionIndex, transactionDate, transactionTime, lotOccupancyTransactionForm.transactionAmount, lotOccupancyTransactionForm.externalReceiptNumber, lotOccupancyTransactionForm.transactionNote, user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
|
||||
.run(lotOccupancyTransactionForm.burialSiteContractId, transactionIndex, transactionDate, transactionTime, lotOccupancyTransactionForm.transactionAmount, lotOccupancyTransactionForm.externalReceiptNumber, lotOccupancyTransactionForm.transactionNote, user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
|
||||
database.release();
|
||||
return transactionIndex;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import {
|
|||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddLotOccupancyTransactionForm {
|
||||
lotOccupancyId: string | number
|
||||
burialSiteContractId: string | number
|
||||
transactionDateString?: string
|
||||
transactionTimeString?: string
|
||||
transactionAmount: string | number
|
||||
|
|
@ -28,11 +28,11 @@ export default async function addLotOccupancyTransaction(
|
|||
.prepare(
|
||||
`select transactionIndex
|
||||
from LotOccupancyTransactions
|
||||
where lotOccupancyId = ?
|
||||
where burialSiteContractId = ?
|
||||
order by transactionIndex desc
|
||||
limit 1`
|
||||
)
|
||||
.get(lotOccupancyTransactionForm.lotOccupancyId) as
|
||||
.get(lotOccupancyTransactionForm.burialSiteContractId) as
|
||||
| { transactionIndex: number }
|
||||
| undefined
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ export default async function addLotOccupancyTransaction(
|
|||
database
|
||||
.prepare(
|
||||
`insert into LotOccupancyTransactions (
|
||||
lotOccupancyId, transactionIndex,
|
||||
burialSiteContractId, transactionIndex,
|
||||
transactionDate, transactionTime,
|
||||
transactionAmount, externalReceiptNumber, transactionNote,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
|
|
@ -61,7 +61,7 @@ export default async function addLotOccupancyTransaction(
|
|||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
)
|
||||
.run(
|
||||
lotOccupancyTransactionForm.lotOccupancyId,
|
||||
lotOccupancyTransactionForm.burialSiteContractId,
|
||||
transactionIndex,
|
||||
transactionDate,
|
||||
transactionTime,
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
export default function copyBurialSiteContract(oldBurialSiteContractId: number | string, user: User): Promise<number>;
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
import { dateToString } from '@cityssm/utils-datetime';
|
||||
import addBurialSiteContract from './addBurialSiteContract.js';
|
||||
import addBurialSiteContractComment from './addBurialSiteContractComment.js';
|
||||
// import addLotOccupancyOccupant from './addLotOccupancyOccupant.js'
|
||||
import getBurialSiteContract from './getBurialSiteContract.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function copyBurialSiteContract(oldBurialSiteContractId, user) {
|
||||
const database = await acquireConnection();
|
||||
const oldBurialSiteContract = await getBurialSiteContract(oldBurialSiteContractId, database);
|
||||
const newBurialSiteContractId = await addBurialSiteContract({
|
||||
burialSiteId: oldBurialSiteContract.burialSiteId ?? '',
|
||||
contractTypeId: oldBurialSiteContract.contractTypeId,
|
||||
contractStartDateString: dateToString(new Date()),
|
||||
contractEndDateString: ''
|
||||
}, user, database);
|
||||
/*
|
||||
* Copy Fields
|
||||
*/
|
||||
const rightNowMillis = Date.now();
|
||||
for (const field of oldBurialSiteContract.burialSiteContractFields ?? []) {
|
||||
database
|
||||
.prepare(`insert into BurialSiteContractFields (
|
||||
burialSiteContractId, contractTypeFieldId, fieldValue,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(newBurialSiteContractId, field.contractTypeFieldId, field.fieldValue, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
}
|
||||
/*
|
||||
* Copy Occupants
|
||||
*/
|
||||
/*
|
||||
for (const occupant of oldBurialSiteContract.lotOccupancyOccupants ?? []) {
|
||||
await addLotOccupancyOccupant(
|
||||
{
|
||||
burialSiteContractId: newBurialSiteContractId,
|
||||
lotOccupantTypeId: occupant.lotOccupantTypeId!,
|
||||
occupantName: occupant.occupantName!,
|
||||
occupantFamilyName: occupant.occupantFamilyName!,
|
||||
occupantAddress1: occupant.occupantAddress1!,
|
||||
occupantAddress2: occupant.occupantAddress2!,
|
||||
occupantCity: occupant.occupantCity!,
|
||||
occupantProvince: occupant.occupantProvince!,
|
||||
occupantPostalCode: occupant.occupantPostalCode!,
|
||||
occupantPhoneNumber: occupant.occupantPhoneNumber!,
|
||||
occupantEmailAddress: occupant.occupantEmailAddress!
|
||||
},
|
||||
user,
|
||||
database
|
||||
)
|
||||
}
|
||||
*/
|
||||
/*
|
||||
* Add Comment
|
||||
*/
|
||||
await addBurialSiteContractComment({
|
||||
burialSiteContractId: newBurialSiteContractId,
|
||||
comment: `New record copied from #${oldBurialSiteContractId}.`
|
||||
}, user);
|
||||
database.release();
|
||||
return newBurialSiteContractId;
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
import { dateToString } from '@cityssm/utils-datetime'
|
||||
|
||||
import type { BurialSiteContract } from '../types/recordTypes.js'
|
||||
|
||||
import addBurialSiteContract from './addBurialSiteContract.js'
|
||||
import addBurialSiteContractComment from './addBurialSiteContractComment.js'
|
||||
// import addLotOccupancyOccupant from './addLotOccupancyOccupant.js'
|
||||
import getBurialSiteContract from './getBurialSiteContract.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export default async function copyBurialSiteContract(
|
||||
oldBurialSiteContractId: number | string,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
|
||||
const oldBurialSiteContract = await getBurialSiteContract(oldBurialSiteContractId, database) as BurialSiteContract
|
||||
|
||||
const newBurialSiteContractId = await addBurialSiteContract(
|
||||
{
|
||||
burialSiteId: oldBurialSiteContract.burialSiteId ?? '',
|
||||
contractTypeId: oldBurialSiteContract.contractTypeId,
|
||||
contractStartDateString: dateToString(new Date()),
|
||||
contractEndDateString: ''
|
||||
},
|
||||
user,
|
||||
database
|
||||
)
|
||||
|
||||
/*
|
||||
* Copy Fields
|
||||
*/
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
for (const field of oldBurialSiteContract.burialSiteContractFields ?? []) {
|
||||
database
|
||||
.prepare(
|
||||
`insert into BurialSiteContractFields (
|
||||
burialSiteContractId, contractTypeFieldId, fieldValue,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?)`
|
||||
)
|
||||
.run(
|
||||
newBurialSiteContractId,
|
||||
field.contractTypeFieldId,
|
||||
field.fieldValue,
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
user.userName,
|
||||
rightNowMillis
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy Occupants
|
||||
*/
|
||||
|
||||
/*
|
||||
for (const occupant of oldBurialSiteContract.lotOccupancyOccupants ?? []) {
|
||||
await addLotOccupancyOccupant(
|
||||
{
|
||||
burialSiteContractId: newBurialSiteContractId,
|
||||
lotOccupantTypeId: occupant.lotOccupantTypeId!,
|
||||
occupantName: occupant.occupantName!,
|
||||
occupantFamilyName: occupant.occupantFamilyName!,
|
||||
occupantAddress1: occupant.occupantAddress1!,
|
||||
occupantAddress2: occupant.occupantAddress2!,
|
||||
occupantCity: occupant.occupantCity!,
|
||||
occupantProvince: occupant.occupantProvince!,
|
||||
occupantPostalCode: occupant.occupantPostalCode!,
|
||||
occupantPhoneNumber: occupant.occupantPhoneNumber!,
|
||||
occupantEmailAddress: occupant.occupantEmailAddress!
|
||||
},
|
||||
user,
|
||||
database
|
||||
)
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* Add Comment
|
||||
*/
|
||||
|
||||
await addBurialSiteContractComment({
|
||||
burialSiteContractId: newBurialSiteContractId,
|
||||
comment: `New record copied from #${oldBurialSiteContractId}.`
|
||||
}, user)
|
||||
|
||||
database.release()
|
||||
|
||||
return newBurialSiteContractId
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
export default function copyLotOccupancy(oldLotOccupancyId: number | string, user: User): Promise<number>;
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
import { dateToString } from '@cityssm/utils-datetime';
|
||||
import addLotOccupancy from './addLotOccupancy.js';
|
||||
import addLotOccupancyComment from './addLotOccupancyComment.js';
|
||||
import addLotOccupancyOccupant from './addLotOccupancyOccupant.js';
|
||||
import getLotOccupancy from './getLotOccupancy.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function copyLotOccupancy(oldLotOccupancyId, user) {
|
||||
const database = await acquireConnection();
|
||||
const oldLotOccupancy = await getLotOccupancy(oldLotOccupancyId, database);
|
||||
const newLotOccupancyId = await addLotOccupancy({
|
||||
lotId: oldLotOccupancy.lotId ?? '',
|
||||
occupancyTypeId: oldLotOccupancy.occupancyTypeId,
|
||||
occupancyStartDateString: dateToString(new Date()),
|
||||
occupancyEndDateString: ''
|
||||
}, user, database);
|
||||
/*
|
||||
* Copy Fields
|
||||
*/
|
||||
const rightNowMillis = Date.now();
|
||||
for (const occupancyField of oldLotOccupancy.lotOccupancyFields ?? []) {
|
||||
database
|
||||
.prepare(`insert into LotOccupancyFields (
|
||||
lotOccupancyId, occupancyTypeFieldId, lotOccupancyFieldValue,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(newLotOccupancyId, occupancyField.occupancyTypeFieldId, occupancyField.lotOccupancyFieldValue, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
}
|
||||
/*
|
||||
* Copy Occupants
|
||||
*/
|
||||
for (const occupant of oldLotOccupancy.lotOccupancyOccupants ?? []) {
|
||||
await addLotOccupancyOccupant({
|
||||
lotOccupancyId: newLotOccupancyId,
|
||||
lotOccupantTypeId: occupant.lotOccupantTypeId,
|
||||
occupantName: occupant.occupantName,
|
||||
occupantFamilyName: occupant.occupantFamilyName,
|
||||
occupantAddress1: occupant.occupantAddress1,
|
||||
occupantAddress2: occupant.occupantAddress2,
|
||||
occupantCity: occupant.occupantCity,
|
||||
occupantProvince: occupant.occupantProvince,
|
||||
occupantPostalCode: occupant.occupantPostalCode,
|
||||
occupantPhoneNumber: occupant.occupantPhoneNumber,
|
||||
occupantEmailAddress: occupant.occupantEmailAddress
|
||||
}, user, database);
|
||||
}
|
||||
/*
|
||||
* Add Comment
|
||||
*/
|
||||
await addLotOccupancyComment({
|
||||
lotOccupancyId: newLotOccupancyId,
|
||||
lotOccupancyComment: `New record copied from #${oldLotOccupancyId}.`
|
||||
}, user);
|
||||
database.release();
|
||||
return newLotOccupancyId;
|
||||
}
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
import { dateToString } from '@cityssm/utils-datetime'
|
||||
|
||||
import type { LotOccupancy } from '../types/recordTypes.js'
|
||||
|
||||
import addLotOccupancy from './addLotOccupancy.js'
|
||||
import addLotOccupancyComment from './addLotOccupancyComment.js'
|
||||
import addLotOccupancyOccupant from './addLotOccupancyOccupant.js'
|
||||
import getLotOccupancy from './getLotOccupancy.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export default async function copyLotOccupancy(
|
||||
oldLotOccupancyId: number | string,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
|
||||
const oldLotOccupancy = await getLotOccupancy(oldLotOccupancyId, database) as LotOccupancy
|
||||
|
||||
const newLotOccupancyId = await addLotOccupancy(
|
||||
{
|
||||
lotId: oldLotOccupancy.lotId ?? '',
|
||||
occupancyTypeId: oldLotOccupancy.occupancyTypeId,
|
||||
occupancyStartDateString: dateToString(new Date()),
|
||||
occupancyEndDateString: ''
|
||||
},
|
||||
user,
|
||||
database
|
||||
)
|
||||
|
||||
/*
|
||||
* Copy Fields
|
||||
*/
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
for (const occupancyField of oldLotOccupancy.lotOccupancyFields ?? []) {
|
||||
database
|
||||
.prepare(
|
||||
`insert into LotOccupancyFields (
|
||||
lotOccupancyId, occupancyTypeFieldId, lotOccupancyFieldValue,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?)`
|
||||
)
|
||||
.run(
|
||||
newLotOccupancyId,
|
||||
occupancyField.occupancyTypeFieldId,
|
||||
occupancyField.lotOccupancyFieldValue,
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
user.userName,
|
||||
rightNowMillis
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy Occupants
|
||||
*/
|
||||
|
||||
for (const occupant of oldLotOccupancy.lotOccupancyOccupants ?? []) {
|
||||
await addLotOccupancyOccupant(
|
||||
{
|
||||
lotOccupancyId: newLotOccupancyId,
|
||||
lotOccupantTypeId: occupant.lotOccupantTypeId!,
|
||||
occupantName: occupant.occupantName!,
|
||||
occupantFamilyName: occupant.occupantFamilyName!,
|
||||
occupantAddress1: occupant.occupantAddress1!,
|
||||
occupantAddress2: occupant.occupantAddress2!,
|
||||
occupantCity: occupant.occupantCity!,
|
||||
occupantProvince: occupant.occupantProvince!,
|
||||
occupantPostalCode: occupant.occupantPostalCode!,
|
||||
occupantPhoneNumber: occupant.occupantPhoneNumber!,
|
||||
occupantEmailAddress: occupant.occupantEmailAddress!
|
||||
},
|
||||
user,
|
||||
database
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
* Add Comment
|
||||
*/
|
||||
|
||||
await addLotOccupancyComment({
|
||||
lotOccupancyId: newLotOccupancyId,
|
||||
lotOccupancyComment: `New record copied from #${oldLotOccupancyId}.`
|
||||
}, user)
|
||||
|
||||
database.release()
|
||||
|
||||
return newLotOccupancyId
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ relatedTables.set('ContractTypes', ['ContractTypePrints', 'ContractTypeFields'])
|
|||
relatedTables.set('WorkOrders', [
|
||||
'WorkOrderMilestones',
|
||||
'WorkOrderLots',
|
||||
'WorkOrderLotOccupancies',
|
||||
'WorkOrderBurialSiteContracts',
|
||||
'WorkOrderComments'
|
||||
]);
|
||||
export async function deleteRecord(recordTable, recordId, user) {
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ relatedTables.set('ContractTypes', ['ContractTypePrints', 'ContractTypeFields'])
|
|||
relatedTables.set('WorkOrders', [
|
||||
'WorkOrderMilestones',
|
||||
'WorkOrderLots',
|
||||
'WorkOrderLotOccupancies',
|
||||
'WorkOrderBurialSiteContracts',
|
||||
'WorkOrderComments'
|
||||
])
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
import type { Lot } from '../types/recordTypes.js';
|
||||
export declare function getLotByLotName(lotName: string): Promise<Lot | undefined>;
|
||||
export default function getLot(burialSiteId: number | string): Promise<Lot | undefined>;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import getLotComments from './getLotComments.js';
|
||||
import getLotFields from './getLotFields.js';
|
||||
import getBurialSiteInterments from './getLotOccupancies.js';
|
||||
import getBurialSiteComments from './getBurialSiteComments.js';
|
||||
import getBurialSiteInterments from './getBurialSiteContracts.js';
|
||||
import getBurialSiteFields from './getBurialSiteFields.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
const baseSQL = `select l.burialSiteId,
|
||||
l.burialSiteTypeId, t.burialSiteType,
|
||||
|
|
@ -23,8 +23,8 @@ async function _getBurialSite(sql, burialSiteIdOrLotName) {
|
|||
const database = await acquireConnection();
|
||||
const burialSite = database.prepare(sql).get(burialSiteIdOrLotName);
|
||||
if (burialSite !== undefined) {
|
||||
const lotOccupancies = await getBurialSiteInterments({
|
||||
lotId: burialSite.lotId
|
||||
const BurialSiteContracts = await getBurialSiteInterments({
|
||||
burialSiteId: burialSite.burialSiteId
|
||||
}, {
|
||||
includeOccupants: true,
|
||||
includeFees: false,
|
||||
|
|
@ -32,9 +32,9 @@ async function _getBurialSite(sql, burialSiteIdOrLotName) {
|
|||
limit: -1,
|
||||
offset: 0
|
||||
}, database);
|
||||
burialSite.lotOccupancies = lotOccupancies.lotOccupancies;
|
||||
burialSite.lotFields = await getLotFields(burialSite.lotId, database);
|
||||
burialSite.lotComments = await getLotComments(burialSite.lotId, database);
|
||||
burialSite.burialSiteContracts = BurialSiteContracts.BurialSiteContracts;
|
||||
burialSite.burialSiteFields = await getBurialSiteFields(burialSite.burialSiteId, database);
|
||||
burialSite.burialSiteComments = await getBurialSiteComments(burialSite.burialSiteId, database);
|
||||
}
|
||||
database.release();
|
||||
return burialSite;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import type { Lot } from '../types/recordTypes.js'
|
||||
import type { BurialSite } from '../types/recordTypes.js'
|
||||
|
||||
import getLotComments from './getLotComments.js'
|
||||
import getLotFields from './getLotFields.js'
|
||||
import getBurialSiteInterments from './getLotOccupancies.js'
|
||||
import getBurialSiteComments from './getBurialSiteComments.js'
|
||||
import getBurialSiteInterments from './getBurialSiteContracts.js'
|
||||
import getBurialSiteFields from './getBurialSiteFields.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
const baseSQL = `select l.burialSiteId,
|
||||
|
|
@ -26,15 +26,15 @@ const baseSQL = `select l.burialSiteId,
|
|||
async function _getBurialSite(
|
||||
sql: string,
|
||||
burialSiteIdOrLotName: number | string
|
||||
): Promise<Lot | undefined> {
|
||||
): Promise<BurialSite | undefined> {
|
||||
const database = await acquireConnection()
|
||||
|
||||
const burialSite = database.prepare(sql).get(burialSiteIdOrLotName) as Lot | undefined
|
||||
const burialSite = database.prepare(sql).get(burialSiteIdOrLotName) as BurialSite | undefined
|
||||
|
||||
if (burialSite !== undefined) {
|
||||
const lotOccupancies = await getBurialSiteInterments(
|
||||
const BurialSiteContracts = await getBurialSiteInterments(
|
||||
{
|
||||
lotId: burialSite.lotId
|
||||
burialSiteId: burialSite.burialSiteId
|
||||
},
|
||||
{
|
||||
includeOccupants: true,
|
||||
|
|
@ -46,11 +46,11 @@ async function _getBurialSite(
|
|||
database
|
||||
)
|
||||
|
||||
burialSite.lotOccupancies = lotOccupancies.lotOccupancies
|
||||
burialSite.burialSiteContracts = BurialSiteContracts.BurialSiteContracts
|
||||
|
||||
burialSite.lotFields = await getLotFields(burialSite.lotId, database)
|
||||
burialSite.burialSiteFields = await getBurialSiteFields(burialSite.burialSiteId, database)
|
||||
|
||||
burialSite.lotComments = await getLotComments(burialSite.lotId, database)
|
||||
burialSite.burialSiteComments = await getBurialSiteComments(burialSite.burialSiteId, database)
|
||||
}
|
||||
|
||||
database.release()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import type { BurialSiteComment } from '../types/recordTypes.js';
|
||||
export default function getBurialSiteComments(burialSiteId: number | string, connectedDatabase?: PoolConnection): Promise<BurialSiteComment[]>;
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
import { dateIntegerToString, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function getLotComments(lotId, connectedDatabase) {
|
||||
export default async function getBurialSiteComments(burialSiteId, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
||||
database.function('userFn_timeIntegerToString', timeIntegerToString);
|
||||
database.function('userFn_timeIntegerToPeriodString', timeIntegerToPeriodString);
|
||||
const lotComments = database
|
||||
.prepare(`select lotCommentId,
|
||||
lotCommentDate, userFn_dateIntegerToString(lotCommentDate) as lotCommentDateString,
|
||||
lotCommentTime,
|
||||
userFn_timeIntegerToString(lotCommentTime) as lotCommentTimeString,
|
||||
userFn_timeIntegerToPeriodString(lotCommentTime) as lotCommentTimePeriodString,
|
||||
lotComment,
|
||||
const comments = database
|
||||
.prepare(`select burialSiteCommentId,
|
||||
commentDate, userFn_dateIntegerToString(commentDate) as commentDateString,
|
||||
commentTime,
|
||||
userFn_timeIntegerToString(commentTime) as commentTimeString,
|
||||
userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString,
|
||||
comment,
|
||||
recordCreate_userName, recordUpdate_userName
|
||||
from LotComments
|
||||
from BurialSiteComments
|
||||
where recordDelete_timeMillis is null
|
||||
and lotId = ?
|
||||
order by lotCommentDate desc, lotCommentTime desc, lotCommentId desc`)
|
||||
.all(lotId);
|
||||
and burialSiteId = ?
|
||||
order by commentDate desc, commentTime desc, burialSiteCommentId desc`)
|
||||
.all(burialSiteId);
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return lotComments;
|
||||
return comments;
|
||||
}
|
||||
|
|
@ -5,14 +5,14 @@ import {
|
|||
} from '@cityssm/utils-datetime'
|
||||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import type { LotComment } from '../types/recordTypes.js'
|
||||
import type { BurialSiteComment } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export default async function getLotComments(
|
||||
lotId: number | string,
|
||||
export default async function getBurialSiteComments(
|
||||
burialSiteId: number | string,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<LotComment[]> {
|
||||
): Promise<BurialSiteComment[]> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
||||
|
|
@ -22,25 +22,25 @@ export default async function getLotComments(
|
|||
timeIntegerToPeriodString
|
||||
)
|
||||
|
||||
const lotComments = database
|
||||
const comments = database
|
||||
.prepare(
|
||||
`select lotCommentId,
|
||||
lotCommentDate, userFn_dateIntegerToString(lotCommentDate) as lotCommentDateString,
|
||||
lotCommentTime,
|
||||
userFn_timeIntegerToString(lotCommentTime) as lotCommentTimeString,
|
||||
userFn_timeIntegerToPeriodString(lotCommentTime) as lotCommentTimePeriodString,
|
||||
lotComment,
|
||||
`select burialSiteCommentId,
|
||||
commentDate, userFn_dateIntegerToString(commentDate) as commentDateString,
|
||||
commentTime,
|
||||
userFn_timeIntegerToString(commentTime) as commentTimeString,
|
||||
userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString,
|
||||
comment,
|
||||
recordCreate_userName, recordUpdate_userName
|
||||
from LotComments
|
||||
from BurialSiteComments
|
||||
where recordDelete_timeMillis is null
|
||||
and lotId = ?
|
||||
order by lotCommentDate desc, lotCommentTime desc, lotCommentId desc`
|
||||
and burialSiteId = ?
|
||||
order by commentDate desc, commentTime desc, burialSiteCommentId desc`
|
||||
)
|
||||
.all(lotId) as LotComment[]
|
||||
.all(burialSiteId) as BurialSiteComment[]
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return lotComments
|
||||
return comments
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import type { BurialSiteContract } from '../types/recordTypes.js';
|
||||
export default function getLotOccupancy(burialSiteContractId: number | string, connectedDatabase?: PoolConnection): Promise<BurialSiteContract | undefined>;
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
import { dateIntegerToString } from '@cityssm/utils-datetime';
|
||||
import getBurialSiteContractComments from './getBurialSiteContractComments.js';
|
||||
import getBurialSiteContractFees from './getBurialSiteContractFees.js';
|
||||
import getBurialSiteContractFields from './getBurialSiteContractFields.js';
|
||||
// import getLotOccupancyOccupants from './getLotOccupancyOccupants.js'
|
||||
import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js';
|
||||
import { getWorkOrders } from './getWorkOrders.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function getLotOccupancy(burialSiteContractId, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
||||
const contract = database
|
||||
.prepare(`select o.burialSiteContractId,
|
||||
o.contractTypeId, t.contractType,
|
||||
o.burialSiteId,
|
||||
l.burialSiteNameSegment1,
|
||||
l.burialSiteNameSegment2,
|
||||
l.burialSiteNameSegment3,
|
||||
l.burialSiteNameSegment4,
|
||||
l.burialSiteNameSegment5,
|
||||
l.burialSiteTypeId,
|
||||
l.cemeteryId, m.cemeteryName,
|
||||
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
||||
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
||||
o.recordUpdate_timeMillis
|
||||
from BurialSiteContracts o
|
||||
left join ContractTypes t on o.contractTypeId = t.contractTypeId
|
||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||
left join Maps m on l.cemeteryId = m.cemeteryId
|
||||
where o.recordDelete_timeMillis is null
|
||||
and o.burialSiteContractId = ?`)
|
||||
.get(burialSiteContractId);
|
||||
if (contract !== undefined) {
|
||||
contract.burialSiteContractFields = await getBurialSiteContractFields(burialSiteContractId, database);
|
||||
/*
|
||||
contract.burialSiteContractInterments = await getLotOccupancyOccupants(
|
||||
burialSiteContractId,
|
||||
database
|
||||
)
|
||||
*/
|
||||
contract.burialSiteContractComments = await getBurialSiteContractComments(burialSiteContractId, database);
|
||||
contract.burialSiteContractFees = await getBurialSiteContractFees(burialSiteContractId, database);
|
||||
contract.burialSiteContractTransactions = await getBurialSiteContractTransactions(burialSiteContractId, { includeIntegrations: true }, database);
|
||||
const workOrdersResults = await getWorkOrders({
|
||||
burialSiteContractId
|
||||
}, {
|
||||
limit: -1,
|
||||
offset: 0
|
||||
}, database);
|
||||
contract.workOrders = workOrdersResults.workOrders;
|
||||
}
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return contract;
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
import { dateIntegerToString } from '@cityssm/utils-datetime'
|
||||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import type { BurialSiteContract } from '../types/recordTypes.js'
|
||||
|
||||
import getBurialSiteContractComments from './getBurialSiteContractComments.js'
|
||||
import getBurialSiteContractFees from './getBurialSiteContractFees.js'
|
||||
import getBurialSiteContractFields from './getBurialSiteContractFields.js'
|
||||
// import getLotOccupancyOccupants from './getLotOccupancyOccupants.js'
|
||||
import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js'
|
||||
import { getWorkOrders } from './getWorkOrders.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export default async function getLotOccupancy(
|
||||
burialSiteContractId: number | string,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<BurialSiteContract | undefined> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
||||
|
||||
const contract = database
|
||||
.prepare(
|
||||
`select o.burialSiteContractId,
|
||||
o.contractTypeId, t.contractType,
|
||||
o.burialSiteId,
|
||||
l.burialSiteNameSegment1,
|
||||
l.burialSiteNameSegment2,
|
||||
l.burialSiteNameSegment3,
|
||||
l.burialSiteNameSegment4,
|
||||
l.burialSiteNameSegment5,
|
||||
l.burialSiteTypeId,
|
||||
l.cemeteryId, m.cemeteryName,
|
||||
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
||||
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
||||
o.recordUpdate_timeMillis
|
||||
from BurialSiteContracts o
|
||||
left join ContractTypes t on o.contractTypeId = t.contractTypeId
|
||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||
left join Maps m on l.cemeteryId = m.cemeteryId
|
||||
where o.recordDelete_timeMillis is null
|
||||
and o.burialSiteContractId = ?`
|
||||
)
|
||||
.get(burialSiteContractId) as BurialSiteContract | undefined
|
||||
|
||||
if (contract !== undefined) {
|
||||
contract.burialSiteContractFields = await getBurialSiteContractFields(
|
||||
burialSiteContractId,
|
||||
database
|
||||
)
|
||||
/*
|
||||
contract.burialSiteContractInterments = await getLotOccupancyOccupants(
|
||||
burialSiteContractId,
|
||||
database
|
||||
)
|
||||
*/
|
||||
contract.burialSiteContractComments = await getBurialSiteContractComments(
|
||||
burialSiteContractId,
|
||||
database
|
||||
)
|
||||
contract.burialSiteContractFees = await getBurialSiteContractFees(
|
||||
burialSiteContractId,
|
||||
database
|
||||
)
|
||||
contract.burialSiteContractTransactions = await getBurialSiteContractTransactions(
|
||||
burialSiteContractId,
|
||||
{ includeIntegrations: true },
|
||||
database
|
||||
)
|
||||
|
||||
const workOrdersResults = await getWorkOrders(
|
||||
{
|
||||
burialSiteContractId
|
||||
},
|
||||
{
|
||||
limit: -1,
|
||||
offset: 0
|
||||
},
|
||||
database
|
||||
)
|
||||
|
||||
contract.workOrders = workOrdersResults.workOrders
|
||||
}
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return contract
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import type { BurialSiteContractComment } from '../types/recordTypes.js';
|
||||
export default function getBurialSiteContractComments(burialSiteContractId: number | string, connectedDatabase?: PoolConnection): Promise<BurialSiteContractComment[]>;
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
import { dateIntegerToString, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function getBurialSiteContractComments(burialSiteContractId, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
||||
database.function('userFn_timeIntegerToString', timeIntegerToString);
|
||||
database.function('userFn_timeIntegerToPeriodString', timeIntegerToPeriodString);
|
||||
const comments = database
|
||||
.prepare(`select burialSiteContractCommentId,
|
||||
commentDate, userFn_dateIntegerToString(commentDate) as commentDateString,
|
||||
commentTime,
|
||||
userFn_timeIntegerToString(commentTime) as commentTimeString,
|
||||
userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString,
|
||||
comment,
|
||||
recordCreate_userName, recordUpdate_userName
|
||||
from BurialSiteContractComments
|
||||
where recordDelete_timeMillis is null
|
||||
and burialSiteContractId = ?
|
||||
order by commentDate desc, commentTime desc, burialSiteContractCommentId desc`)
|
||||
.all(burialSiteContractId);
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return comments;
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
import {
|
||||
dateIntegerToString,
|
||||
timeIntegerToPeriodString,
|
||||
timeIntegerToString
|
||||
} from '@cityssm/utils-datetime'
|
||||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import type { BurialSiteContractComment } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export default async function getBurialSiteContractComments(
|
||||
burialSiteContractId: number | string,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<BurialSiteContractComment[]> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
||||
database.function('userFn_timeIntegerToString', timeIntegerToString)
|
||||
database.function(
|
||||
'userFn_timeIntegerToPeriodString',
|
||||
timeIntegerToPeriodString
|
||||
)
|
||||
|
||||
const comments = database
|
||||
.prepare(
|
||||
`select burialSiteContractCommentId,
|
||||
commentDate, userFn_dateIntegerToString(commentDate) as commentDateString,
|
||||
commentTime,
|
||||
userFn_timeIntegerToString(commentTime) as commentTimeString,
|
||||
userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString,
|
||||
comment,
|
||||
recordCreate_userName, recordUpdate_userName
|
||||
from BurialSiteContractComments
|
||||
where recordDelete_timeMillis is null
|
||||
and burialSiteContractId = ?
|
||||
order by commentDate desc, commentTime desc, burialSiteContractCommentId desc`
|
||||
)
|
||||
.all(burialSiteContractId) as BurialSiteContractComment[]
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return comments
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import type { BurialSiteContractFee } from '../types/recordTypes.js';
|
||||
export default function getBurialSiteContractFees(burialSiteContractId: number | string, connectedDatabase?: PoolConnection): Promise<BurialSiteContractFee[]>;
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function getLotOccupancyFees(lotOccupancyId, connectedDatabase) {
|
||||
export default async function getBurialSiteContractFees(burialSiteContractId, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
const lotOccupancyFees = database
|
||||
.prepare(`select o.lotOccupancyId, o.feeId,
|
||||
const fees = database
|
||||
.prepare(`select o.burialSiteContractId, o.feeId,
|
||||
c.feeCategory, f.feeName,
|
||||
f.includeQuantity, o.feeAmount, o.taxAmount, o.quantity, f.quantityUnit
|
||||
from LotOccupancyFees o
|
||||
from BurialSiteContractFees o
|
||||
left join Fees f on o.feeId = f.feeId
|
||||
left join FeeCategories c on f.feeCategoryId = c.feeCategoryId
|
||||
where o.recordDelete_timeMillis is null
|
||||
and o.lotOccupancyId = ?
|
||||
and o.burialSiteContractId = ?
|
||||
order by o.recordCreate_timeMillis`)
|
||||
.all(lotOccupancyId);
|
||||
.all(burialSiteContractId);
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return lotOccupancyFees;
|
||||
return fees;
|
||||
}
|
||||
|
|
@ -1,32 +1,32 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import type { LotOccupancyFee } from '../types/recordTypes.js'
|
||||
import type { BurialSiteContractFee } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export default async function getLotOccupancyFees(
|
||||
lotOccupancyId: number | string,
|
||||
export default async function getBurialSiteContractFees(
|
||||
burialSiteContractId: number | string,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<LotOccupancyFee[]> {
|
||||
): Promise<BurialSiteContractFee[]> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
const lotOccupancyFees = database
|
||||
const fees = database
|
||||
.prepare(
|
||||
`select o.lotOccupancyId, o.feeId,
|
||||
`select o.burialSiteContractId, o.feeId,
|
||||
c.feeCategory, f.feeName,
|
||||
f.includeQuantity, o.feeAmount, o.taxAmount, o.quantity, f.quantityUnit
|
||||
from LotOccupancyFees o
|
||||
from BurialSiteContractFees o
|
||||
left join Fees f on o.feeId = f.feeId
|
||||
left join FeeCategories c on f.feeCategoryId = c.feeCategoryId
|
||||
where o.recordDelete_timeMillis is null
|
||||
and o.lotOccupancyId = ?
|
||||
and o.burialSiteContractId = ?
|
||||
order by o.recordCreate_timeMillis`
|
||||
)
|
||||
.all(lotOccupancyId) as LotOccupancyFee[]
|
||||
.all(burialSiteContractId) as BurialSiteContractFee[]
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return lotOccupancyFees
|
||||
return fees
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import type { BurialSiteContractField } from '../types/recordTypes.js';
|
||||
export default function getBurialSiteContractField(burialSiteContractId: number | string, connectedDatabase?: PoolConnection): Promise<BurialSiteContractField[]>;
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function getBurialSiteContractField(burialSiteContractId, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
const fields = database
|
||||
.prepare(`select o.burialSiteContractId, o.contractTypeFieldId,
|
||||
o.fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
|
||||
f.isRequired, f.pattern, f.minimumLength, f.maximumLength,
|
||||
f.orderNumber, t.orderNumber as contractTypeOrderNumber
|
||||
from BurialSiteContractFields o
|
||||
left join ContractTypeFields f on o.contractTypeFieldId = f.contractTypeFieldId
|
||||
left join ContractTypes t on f.contractTypeId = t.contractTypeId
|
||||
where o.recordDelete_timeMillis is null
|
||||
and o.burialSiteContractId = ?
|
||||
|
||||
union
|
||||
|
||||
select ? as burialSiteContractId, f.contractTypeFieldId,
|
||||
'' as fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
|
||||
f.isRequired, f.pattern, f.minimumLength, f.maximumLength,
|
||||
f.orderNumber, t.orderNumber as contractTypeOrderNumber
|
||||
from ContractTypeFields f
|
||||
left join ContractTypes t on f.contractTypeId = t.contractTypeId
|
||||
where f.recordDelete_timeMillis is null and (
|
||||
f.contractTypeId is null
|
||||
or f.contractTypeId in (select contractTypeId from BurialSiteContracts where burialSiteContractId = ?))
|
||||
and f.contractTypeFieldId not in (select contractTypeFieldId from BurialSiteContractFields where burialSiteContractId = ? and recordDelete_timeMillis is null)
|
||||
order by contractTypeOrderNumber, f.orderNumber, f.contractTypeField`)
|
||||
.all(burialSiteContractId, burialSiteContractId, burialSiteContractId, burialSiteContractId);
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import type { BurialSiteContractField } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export default async function getBurialSiteContractField(
|
||||
burialSiteContractId: number | string,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<BurialSiteContractField[]> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
const fields = database
|
||||
.prepare(
|
||||
`select o.burialSiteContractId, o.contractTypeFieldId,
|
||||
o.fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
|
||||
f.isRequired, f.pattern, f.minimumLength, f.maximumLength,
|
||||
f.orderNumber, t.orderNumber as contractTypeOrderNumber
|
||||
from BurialSiteContractFields o
|
||||
left join ContractTypeFields f on o.contractTypeFieldId = f.contractTypeFieldId
|
||||
left join ContractTypes t on f.contractTypeId = t.contractTypeId
|
||||
where o.recordDelete_timeMillis is null
|
||||
and o.burialSiteContractId = ?
|
||||
|
||||
union
|
||||
|
||||
select ? as burialSiteContractId, f.contractTypeFieldId,
|
||||
'' as fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
|
||||
f.isRequired, f.pattern, f.minimumLength, f.maximumLength,
|
||||
f.orderNumber, t.orderNumber as contractTypeOrderNumber
|
||||
from ContractTypeFields f
|
||||
left join ContractTypes t on f.contractTypeId = t.contractTypeId
|
||||
where f.recordDelete_timeMillis is null and (
|
||||
f.contractTypeId is null
|
||||
or f.contractTypeId in (select contractTypeId from BurialSiteContracts where burialSiteContractId = ?))
|
||||
and f.contractTypeFieldId not in (select contractTypeFieldId from BurialSiteContractFields where burialSiteContractId = ? and recordDelete_timeMillis is null)
|
||||
order by contractTypeOrderNumber, f.orderNumber, f.contractTypeField`
|
||||
)
|
||||
.all(
|
||||
burialSiteContractId,
|
||||
burialSiteContractId,
|
||||
burialSiteContractId,
|
||||
burialSiteContractId
|
||||
) as BurialSiteContractField[]
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return fields
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import type { BurialSiteContractInterment } from '../types/recordTypes.js';
|
||||
export default function getBurialSiteContractInterments(burialSiteContractId: number | string, connectedDatabase?: PoolConnection): Promise<BurialSiteContractInterment[]>;
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
import { dateIntegerToString, timeIntegerToString } from '@cityssm/utils-datetime';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function getBurialSiteContractInterments(burialSiteContractId, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
||||
database.function('userFn_timeIntegerToString', timeIntegerToString);
|
||||
const interments = database
|
||||
.prepare(`select o.burialSiteContractId, o.intermentNumber,
|
||||
o.isCremated,
|
||||
o.deceasedName,
|
||||
birthDate, userFn_dateIntegerToString(birthDate) as birthDateString,
|
||||
birthPlace,
|
||||
deathDate, userFn_dateIntegerToString(deathDate) as deathDateString,
|
||||
deathPlace,
|
||||
|
||||
intermentDate, userFn_dateIntegerToString(intermentDate) as intermentDateString,
|
||||
intermentTime, userFn_timeIntegerToString(intermentTime) as intermentTimeString,
|
||||
|
||||
intermentContainerTypeId, t.intermentContainerType,
|
||||
intermentCommittalTypeId, c.intermentCommittalType
|
||||
|
||||
from BurialSiteContractInterments o
|
||||
left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId
|
||||
left join IntermentCommittalTypes c on o.intermentCommittalTypeId = c.intermentCommittalTypeId
|
||||
|
||||
where o.recordDelete_timeMillis is null
|
||||
and o.burialSiteContractId = ?
|
||||
order by t.orderNumber, o.deceasedName, o.intermentNumber`)
|
||||
.all(burialSiteContractId);
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return interments;
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
import {
|
||||
dateIntegerToString,
|
||||
timeIntegerToString
|
||||
} from '@cityssm/utils-datetime'
|
||||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import type { BurialSiteContractInterment } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export default async function getBurialSiteContractInterments(
|
||||
burialSiteContractId: number | string,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<BurialSiteContractInterment[]> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
||||
database.function('userFn_timeIntegerToString', timeIntegerToString)
|
||||
|
||||
const interments = database
|
||||
.prepare(
|
||||
`select o.burialSiteContractId, o.intermentNumber,
|
||||
o.isCremated,
|
||||
o.deceasedName,
|
||||
birthDate, userFn_dateIntegerToString(birthDate) as birthDateString,
|
||||
birthPlace,
|
||||
deathDate, userFn_dateIntegerToString(deathDate) as deathDateString,
|
||||
deathPlace,
|
||||
|
||||
intermentDate, userFn_dateIntegerToString(intermentDate) as intermentDateString,
|
||||
intermentTime, userFn_timeIntegerToString(intermentTime) as intermentTimeString,
|
||||
|
||||
intermentContainerTypeId, t.intermentContainerType,
|
||||
intermentCommittalTypeId, c.intermentCommittalType
|
||||
|
||||
from BurialSiteContractInterments o
|
||||
left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId
|
||||
left join IntermentCommittalTypes c on o.intermentCommittalTypeId = c.intermentCommittalTypeId
|
||||
|
||||
where o.recordDelete_timeMillis is null
|
||||
and o.burialSiteContractId = ?
|
||||
order by t.orderNumber, o.deceasedName, o.intermentNumber`
|
||||
)
|
||||
.all(burialSiteContractId) as BurialSiteContractInterment[]
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return interments
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import type { BurialSiteContractTransaction } from '../types/recordTypes.js';
|
||||
export default function GetBurialSiteContractTransactions(burialSiteContractId: number | string, options: {
|
||||
includeIntegrations: boolean;
|
||||
}, connectedDatabase?: PoolConnection): Promise<BurialSiteContractTransaction[]>;
|
||||
|
|
@ -2,24 +2,24 @@ import { dateIntegerToString, timeIntegerToString } from '@cityssm/utils-datetim
|
|||
import { getConfigProperty } from '../helpers/config.helpers.js';
|
||||
import { getDynamicsGPDocument } from '../helpers/functions.dynamicsGP.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function getLotOccupancyTransactions(lotOccupancyId, options, connectedDatabase) {
|
||||
export default async function GetBurialSiteContractTransactions(burialSiteContractId, options, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
||||
database.function('userFn_timeIntegerToString', timeIntegerToString);
|
||||
const lotOccupancyTransactions = database
|
||||
.prepare(`select lotOccupancyId, transactionIndex,
|
||||
.prepare(`select burialSiteContractId, transactionIndex,
|
||||
transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString,
|
||||
transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString,
|
||||
transactionAmount, externalReceiptNumber, transactionNote
|
||||
from LotOccupancyTransactions
|
||||
from BurialSiteContractTransactions
|
||||
where recordDelete_timeMillis is null
|
||||
and lotOccupancyId = ?
|
||||
and burialSiteContractId = ?
|
||||
order by transactionDate, transactionTime, transactionIndex`)
|
||||
.all(lotOccupancyId);
|
||||
.all(burialSiteContractId);
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
if ((options?.includeIntegrations ?? false) &&
|
||||
if (options.includeIntegrations &&
|
||||
getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) {
|
||||
for (const transaction of lotOccupancyTransactions) {
|
||||
if ((transaction.externalReceiptNumber ?? '') !== '') {
|
||||
|
|
@ -6,17 +6,17 @@ import type { PoolConnection } from 'better-sqlite-pool'
|
|||
|
||||
import { getConfigProperty } from '../helpers/config.helpers.js'
|
||||
import { getDynamicsGPDocument } from '../helpers/functions.dynamicsGP.js'
|
||||
import type { LotOccupancyTransaction } from '../types/recordTypes.js'
|
||||
import type { BurialSiteContractTransaction } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export default async function getLotOccupancyTransactions(
|
||||
lotOccupancyId: number | string,
|
||||
export default async function GetBurialSiteContractTransactions(
|
||||
burialSiteContractId: number | string,
|
||||
options: {
|
||||
includeIntegrations: boolean
|
||||
},
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<LotOccupancyTransaction[]> {
|
||||
): Promise<BurialSiteContractTransaction[]> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
||||
|
|
@ -24,23 +24,23 @@ export default async function getLotOccupancyTransactions(
|
|||
|
||||
const lotOccupancyTransactions = database
|
||||
.prepare(
|
||||
`select lotOccupancyId, transactionIndex,
|
||||
`select burialSiteContractId, transactionIndex,
|
||||
transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString,
|
||||
transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString,
|
||||
transactionAmount, externalReceiptNumber, transactionNote
|
||||
from LotOccupancyTransactions
|
||||
from BurialSiteContractTransactions
|
||||
where recordDelete_timeMillis is null
|
||||
and lotOccupancyId = ?
|
||||
and burialSiteContractId = ?
|
||||
order by transactionDate, transactionTime, transactionIndex`
|
||||
)
|
||||
.all(lotOccupancyId) as LotOccupancyTransaction[]
|
||||
.all(burialSiteContractId) as BurialSiteContractTransaction[]
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
if (
|
||||
(options?.includeIntegrations ?? false) &&
|
||||
options.includeIntegrations &&
|
||||
getConfigProperty('settings.dynamicsGP.integrationIsEnabled')
|
||||
) {
|
||||
for (const transaction of lotOccupancyTransactions) {
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
import { type DateString } from '@cityssm/utils-datetime';
|
||||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import type { BurialSiteContract } from '../types/recordTypes.js';
|
||||
interface GetBurialSiteContractsFilters {
|
||||
burialSiteId?: number | string;
|
||||
occupancyTime?: '' | 'past' | 'current' | 'future';
|
||||
contractStartDateString?: DateString;
|
||||
occupancyEffectiveDateString?: string;
|
||||
occupantName?: string;
|
||||
contractTypeId?: number | string;
|
||||
cemeteryId?: number | string;
|
||||
burialSiteNameSearchType?: '' | 'startsWith' | 'endsWith';
|
||||
burialSiteName?: string;
|
||||
burialSiteTypeId?: number | string;
|
||||
workOrderId?: number | string;
|
||||
notWorkOrderId?: number | string;
|
||||
}
|
||||
interface GetBurialSiteContractsOptions {
|
||||
/** -1 for no limit */
|
||||
limit: number;
|
||||
offset: number;
|
||||
includeInterments: boolean;
|
||||
includeFees: boolean;
|
||||
includeTransactions: boolean;
|
||||
}
|
||||
export default function getBurialSiteContracts(filters: GetBurialSiteContractsFilters, options: GetBurialSiteContractsOptions, connectedDatabase?: PoolConnection): Promise<{
|
||||
count: number;
|
||||
burialSiteContracts: BurialSiteContract[];
|
||||
}>;
|
||||
export {};
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
import { dateIntegerToString, dateStringToInteger } from '@cityssm/utils-datetime';
|
||||
import { getConfigProperty } from '../helpers/config.helpers.js';
|
||||
import { getContractTypeById } from '../helpers/functions.cache.js';
|
||||
import { getLotNameWhereClause, getOccupancyTimeWhereClause, getOccupantNameWhereClause } from '../helpers/functions.sqlFilters.js';
|
||||
import getBurialSiteContractFees from './getBurialSiteContractFees.js';
|
||||
// import getLotOccupancyOccupants from './getLotOccupancyOccupants.js'
|
||||
import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
function buildWhereClause(filters) {
|
||||
let sqlWhereClause = ' where o.recordDelete_timeMillis is null';
|
||||
const sqlParameters = [];
|
||||
if ((filters.burialSiteId ?? '') !== '') {
|
||||
sqlWhereClause += ' and o.lotId = ?';
|
||||
sqlParameters.push(filters.burialSiteId);
|
||||
}
|
||||
const lotNameFilters = getLotNameWhereClause(filters.burialSiteName, filters.burialSiteNameSearchType ?? '', 'l');
|
||||
sqlWhereClause += lotNameFilters.sqlWhereClause;
|
||||
sqlParameters.push(...lotNameFilters.sqlParameters);
|
||||
const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, 'o');
|
||||
if (occupantNameFilters.sqlParameters.length > 0) {
|
||||
sqlWhereClause += ` and o.burialSiteContractId in (
|
||||
select burialSiteContractId from LotOccupancyOccupants o
|
||||
where recordDelete_timeMillis is null
|
||||
${occupantNameFilters.sqlWhereClause})`;
|
||||
sqlParameters.push(...occupantNameFilters.sqlParameters);
|
||||
}
|
||||
if ((filters.contractTypeId ?? '') !== '') {
|
||||
sqlWhereClause += ' and o.contractTypeId = ?';
|
||||
sqlParameters.push(filters.contractTypeId);
|
||||
}
|
||||
const occupancyTimeFilters = getOccupancyTimeWhereClause(filters.occupancyTime ?? '', 'o');
|
||||
sqlWhereClause += occupancyTimeFilters.sqlWhereClause;
|
||||
sqlParameters.push(...occupancyTimeFilters.sqlParameters);
|
||||
if ((filters.contractStartDateString ?? '') !== '') {
|
||||
sqlWhereClause += ' and o.contractStartDate = ?';
|
||||
sqlParameters.push(dateStringToInteger(filters.contractStartDateString));
|
||||
}
|
||||
if ((filters.occupancyEffectiveDateString ?? '') !== '') {
|
||||
sqlWhereClause += ` and (
|
||||
o.contractEndDate is null
|
||||
or (o.contractStartDate <= ? and o.contractEndDate >= ?)
|
||||
)`;
|
||||
sqlParameters.push(dateStringToInteger(filters.occupancyEffectiveDateString), dateStringToInteger(filters.occupancyEffectiveDateString));
|
||||
}
|
||||
if ((filters.cemeteryId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.cemeteryId = ?';
|
||||
sqlParameters.push(filters.cemeteryId);
|
||||
}
|
||||
if ((filters.burialSiteTypeId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.burialSiteTypeId = ?';
|
||||
sqlParameters.push(filters.burialSiteTypeId);
|
||||
}
|
||||
if ((filters.workOrderId ?? '') !== '') {
|
||||
sqlWhereClause +=
|
||||
' and o.burialSiteContractId in (select burialSiteContractId from WorkOrderBurialSiteContracts where recordDelete_timeMillis is null and workOrderId = ?)';
|
||||
sqlParameters.push(filters.workOrderId);
|
||||
}
|
||||
if ((filters.notWorkOrderId ?? '') !== '') {
|
||||
sqlWhereClause +=
|
||||
' and o.burialSiteContractId not in (select burialSiteContractId from WorkOrderBurialSiteContracts where recordDelete_timeMillis is null and workOrderId = ?)';
|
||||
sqlParameters.push(filters.notWorkOrderId);
|
||||
}
|
||||
return {
|
||||
sqlWhereClause,
|
||||
sqlParameters
|
||||
};
|
||||
}
|
||||
async function addInclusions(burialSiteContract, options, database) {
|
||||
if (options.includeFees) {
|
||||
burialSiteContract.burialSiteContractFees = await getBurialSiteContractFees(burialSiteContract.burialSiteContractId, database);
|
||||
}
|
||||
if (options.includeTransactions) {
|
||||
burialSiteContract.burialSiteContractTransactions =
|
||||
await getBurialSiteContractTransactions(burialSiteContract.burialSiteContractId, { includeIntegrations: false }, database);
|
||||
}
|
||||
/*
|
||||
if (options.includeInterments) {
|
||||
burialSiteContract.burialSiteContractInterments =
|
||||
await getLotOccupancyOccupants(
|
||||
burialSiteContract.burialSiteContractId,
|
||||
database
|
||||
)
|
||||
}
|
||||
*/
|
||||
return burialSiteContract;
|
||||
}
|
||||
export default async function getBurialSiteContracts(filters, options, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
||||
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
|
||||
let count = options.limit;
|
||||
const isLimited = options.limit !== -1;
|
||||
if (isLimited) {
|
||||
count = database
|
||||
.prepare(`select count(*) as recordCount
|
||||
from BurialSiteContracts o
|
||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||
${sqlWhereClause}`)
|
||||
.get(sqlParameters).recordCount;
|
||||
}
|
||||
let burialSiteContracts = [];
|
||||
if (count !== 0) {
|
||||
burialSiteContracts = database
|
||||
.prepare(`select o.burialSiteContractId,
|
||||
o.contractTypeId, t.contractType,
|
||||
o.burialSiteId, lt.burialSiteType,
|
||||
l.burialSiteNameSegment1,
|
||||
l.burialSiteNameSegment2,
|
||||
l.burialSiteNameSegment3,
|
||||
l.burialSiteNameSegment4,
|
||||
l.burialSiteNameSegment5,
|
||||
l.cemeteryId, m.cemeteryName,
|
||||
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
||||
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString
|
||||
from BurialSiteContracts o
|
||||
left join ContractTypes t on o.contractTypeId = t.contractTypeId
|
||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||
${sqlWhereClause}
|
||||
order by o.contractStartDate desc, ifnull(o.contractEndDate, 99999999) desc,
|
||||
l.burialSiteNameSegment1,
|
||||
l.burialSiteNameSegment2,
|
||||
l.burialSiteNameSegment3,
|
||||
l.burialSiteNameSegment4,
|
||||
l.burialSiteNameSegment5,
|
||||
o.burialSiteId, o.burialSiteContractId desc
|
||||
${isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''}`)
|
||||
.all(sqlParameters);
|
||||
if (!isLimited) {
|
||||
count = burialSiteContracts.length;
|
||||
}
|
||||
for (const burialSiteContract of burialSiteContracts) {
|
||||
const contractType = await getContractTypeById(burialSiteContract.contractTypeId);
|
||||
if (contractType !== undefined) {
|
||||
burialSiteContract.printEJS = (contractType.contractTypePrints ?? []).includes('*')
|
||||
? getConfigProperty('settings.contracts.prints')[0]
|
||||
: (contractType.contractTypePrints ?? [])[0];
|
||||
}
|
||||
await addInclusions(burialSiteContract, options, database);
|
||||
}
|
||||
}
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return {
|
||||
count,
|
||||
burialSiteContracts
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,262 @@
|
|||
import {
|
||||
type DateString,
|
||||
dateIntegerToString,
|
||||
dateStringToInteger
|
||||
} from '@cityssm/utils-datetime'
|
||||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import { getConfigProperty } from '../helpers/config.helpers.js'
|
||||
import { getContractTypeById } from '../helpers/functions.cache.js'
|
||||
import {
|
||||
getLotNameWhereClause,
|
||||
getOccupancyTimeWhereClause,
|
||||
getOccupantNameWhereClause
|
||||
} from '../helpers/functions.sqlFilters.js'
|
||||
import type { BurialSiteContract } from '../types/recordTypes.js'
|
||||
|
||||
import getBurialSiteContractFees from './getBurialSiteContractFees.js'
|
||||
// import getLotOccupancyOccupants from './getLotOccupancyOccupants.js'
|
||||
import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
interface GetBurialSiteContractsFilters {
|
||||
burialSiteId?: number | string
|
||||
occupancyTime?: '' | 'past' | 'current' | 'future'
|
||||
contractStartDateString?: DateString
|
||||
occupancyEffectiveDateString?: string
|
||||
occupantName?: string
|
||||
contractTypeId?: number | string
|
||||
cemeteryId?: number | string
|
||||
burialSiteNameSearchType?: '' | 'startsWith' | 'endsWith'
|
||||
burialSiteName?: string
|
||||
burialSiteTypeId?: number | string
|
||||
workOrderId?: number | string
|
||||
notWorkOrderId?: number | string
|
||||
}
|
||||
|
||||
interface GetBurialSiteContractsOptions {
|
||||
/** -1 for no limit */
|
||||
limit: number
|
||||
offset: number
|
||||
includeInterments: boolean
|
||||
includeFees: boolean
|
||||
includeTransactions: boolean
|
||||
}
|
||||
|
||||
function buildWhereClause(filters: GetBurialSiteContractsFilters): {
|
||||
sqlWhereClause: string
|
||||
sqlParameters: unknown[]
|
||||
} {
|
||||
let sqlWhereClause = ' where o.recordDelete_timeMillis is null'
|
||||
const sqlParameters: unknown[] = []
|
||||
|
||||
if ((filters.burialSiteId ?? '') !== '') {
|
||||
sqlWhereClause += ' and o.lotId = ?'
|
||||
sqlParameters.push(filters.burialSiteId)
|
||||
}
|
||||
|
||||
const lotNameFilters = getLotNameWhereClause(
|
||||
filters.burialSiteName,
|
||||
filters.burialSiteNameSearchType ?? '',
|
||||
'l'
|
||||
)
|
||||
sqlWhereClause += lotNameFilters.sqlWhereClause
|
||||
sqlParameters.push(...lotNameFilters.sqlParameters)
|
||||
|
||||
const occupantNameFilters = getOccupantNameWhereClause(
|
||||
filters.occupantName,
|
||||
'o'
|
||||
)
|
||||
if (occupantNameFilters.sqlParameters.length > 0) {
|
||||
sqlWhereClause += ` and o.burialSiteContractId in (
|
||||
select burialSiteContractId from LotOccupancyOccupants o
|
||||
where recordDelete_timeMillis is null
|
||||
${occupantNameFilters.sqlWhereClause})`
|
||||
sqlParameters.push(...occupantNameFilters.sqlParameters)
|
||||
}
|
||||
|
||||
if ((filters.contractTypeId ?? '') !== '') {
|
||||
sqlWhereClause += ' and o.contractTypeId = ?'
|
||||
sqlParameters.push(filters.contractTypeId)
|
||||
}
|
||||
|
||||
const occupancyTimeFilters = getOccupancyTimeWhereClause(
|
||||
filters.occupancyTime ?? '',
|
||||
'o'
|
||||
)
|
||||
sqlWhereClause += occupancyTimeFilters.sqlWhereClause
|
||||
sqlParameters.push(...occupancyTimeFilters.sqlParameters)
|
||||
|
||||
if ((filters.contractStartDateString ?? '') !== '') {
|
||||
sqlWhereClause += ' and o.contractStartDate = ?'
|
||||
sqlParameters.push(
|
||||
dateStringToInteger(filters.contractStartDateString as DateString)
|
||||
)
|
||||
}
|
||||
|
||||
if ((filters.occupancyEffectiveDateString ?? '') !== '') {
|
||||
sqlWhereClause += ` and (
|
||||
o.contractEndDate is null
|
||||
or (o.contractStartDate <= ? and o.contractEndDate >= ?)
|
||||
)`
|
||||
sqlParameters.push(
|
||||
dateStringToInteger(filters.occupancyEffectiveDateString as DateString),
|
||||
dateStringToInteger(filters.occupancyEffectiveDateString as DateString)
|
||||
)
|
||||
}
|
||||
|
||||
if ((filters.cemeteryId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.cemeteryId = ?'
|
||||
sqlParameters.push(filters.cemeteryId)
|
||||
}
|
||||
|
||||
if ((filters.burialSiteTypeId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.burialSiteTypeId = ?'
|
||||
sqlParameters.push(filters.burialSiteTypeId)
|
||||
}
|
||||
|
||||
if ((filters.workOrderId ?? '') !== '') {
|
||||
sqlWhereClause +=
|
||||
' and o.burialSiteContractId in (select burialSiteContractId from WorkOrderBurialSiteContracts where recordDelete_timeMillis is null and workOrderId = ?)'
|
||||
sqlParameters.push(filters.workOrderId)
|
||||
}
|
||||
|
||||
if ((filters.notWorkOrderId ?? '') !== '') {
|
||||
sqlWhereClause +=
|
||||
' and o.burialSiteContractId not in (select burialSiteContractId from WorkOrderBurialSiteContracts where recordDelete_timeMillis is null and workOrderId = ?)'
|
||||
sqlParameters.push(filters.notWorkOrderId)
|
||||
}
|
||||
|
||||
return {
|
||||
sqlWhereClause,
|
||||
sqlParameters
|
||||
}
|
||||
}
|
||||
|
||||
async function addInclusions(
|
||||
burialSiteContract: BurialSiteContract,
|
||||
options: GetBurialSiteContractsOptions,
|
||||
database: PoolConnection
|
||||
): Promise<BurialSiteContract> {
|
||||
if (options.includeFees) {
|
||||
burialSiteContract.burialSiteContractFees = await getBurialSiteContractFees(
|
||||
burialSiteContract.burialSiteContractId,
|
||||
database
|
||||
)
|
||||
}
|
||||
|
||||
if (options.includeTransactions) {
|
||||
burialSiteContract.burialSiteContractTransactions =
|
||||
await getBurialSiteContractTransactions(
|
||||
burialSiteContract.burialSiteContractId,
|
||||
{ includeIntegrations: false },
|
||||
database
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
if (options.includeInterments) {
|
||||
burialSiteContract.burialSiteContractInterments =
|
||||
await getLotOccupancyOccupants(
|
||||
burialSiteContract.burialSiteContractId,
|
||||
database
|
||||
)
|
||||
}
|
||||
*/
|
||||
|
||||
return burialSiteContract
|
||||
}
|
||||
|
||||
export default async function getBurialSiteContracts(
|
||||
filters: GetBurialSiteContractsFilters,
|
||||
options: GetBurialSiteContractsOptions,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<{ count: number; burialSiteContracts: BurialSiteContract[] }> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
||||
|
||||
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters)
|
||||
|
||||
let count = options.limit
|
||||
|
||||
const isLimited = options.limit !== -1
|
||||
|
||||
if (isLimited) {
|
||||
count = (
|
||||
database
|
||||
.prepare(
|
||||
`select count(*) as recordCount
|
||||
from BurialSiteContracts o
|
||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||
${sqlWhereClause}`
|
||||
)
|
||||
.get(sqlParameters) as { recordCount: number }
|
||||
).recordCount
|
||||
}
|
||||
|
||||
let burialSiteContracts: BurialSiteContract[] = []
|
||||
|
||||
if (count !== 0) {
|
||||
burialSiteContracts = database
|
||||
.prepare(
|
||||
`select o.burialSiteContractId,
|
||||
o.contractTypeId, t.contractType,
|
||||
o.burialSiteId, lt.burialSiteType,
|
||||
l.burialSiteNameSegment1,
|
||||
l.burialSiteNameSegment2,
|
||||
l.burialSiteNameSegment3,
|
||||
l.burialSiteNameSegment4,
|
||||
l.burialSiteNameSegment5,
|
||||
l.cemeteryId, m.cemeteryName,
|
||||
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
||||
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString
|
||||
from BurialSiteContracts o
|
||||
left join ContractTypes t on o.contractTypeId = t.contractTypeId
|
||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||
${sqlWhereClause}
|
||||
order by o.contractStartDate desc, ifnull(o.contractEndDate, 99999999) desc,
|
||||
l.burialSiteNameSegment1,
|
||||
l.burialSiteNameSegment2,
|
||||
l.burialSiteNameSegment3,
|
||||
l.burialSiteNameSegment4,
|
||||
l.burialSiteNameSegment5,
|
||||
o.burialSiteId, o.burialSiteContractId desc
|
||||
${
|
||||
isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''
|
||||
}`
|
||||
)
|
||||
.all(sqlParameters) as BurialSiteContract[]
|
||||
|
||||
if (!isLimited) {
|
||||
count = burialSiteContracts.length
|
||||
}
|
||||
|
||||
for (const burialSiteContract of burialSiteContracts) {
|
||||
const contractType = await getContractTypeById(
|
||||
burialSiteContract.contractTypeId!
|
||||
)
|
||||
|
||||
if (contractType !== undefined) {
|
||||
burialSiteContract.printEJS = (
|
||||
contractType.contractTypePrints ?? []
|
||||
).includes('*')
|
||||
? getConfigProperty('settings.contracts.prints')[0]
|
||||
: (contractType.contractTypePrints ?? [])[0]
|
||||
}
|
||||
|
||||
await addInclusions(burialSiteContract, options, database)
|
||||
}
|
||||
}
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return {
|
||||
count,
|
||||
burialSiteContracts
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import type { BurialSiteField } from '../types/recordTypes.js';
|
||||
export default function getBurialSiteFields(burialSiteId: number | string, connectedDatabase?: PoolConnection): Promise<BurialSiteField[]>;
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function getBurialSiteFields(burialSiteId, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
const burialSiteFields = database
|
||||
.prepare(`select l.burialSiteId, l.burialSiteTypeFieldId,
|
||||
l.fieldValue,
|
||||
f.burialSiteTypeField, f.fieldType, f.fieldValues,
|
||||
f.isRequired, f.pattern, f.minimumLength, f.maximumLength,
|
||||
f.orderNumber, t.orderNumber as burialSiteTypeOrderNumber
|
||||
from BurialSiteFields l
|
||||
left join BurialSiteTypeFields f on l.burialSiteTypeFieldId = f.burialSiteTypeFieldId
|
||||
left join BurialSiteTypes t on f.burialSiteTypeId = t.burialSiteTypeId
|
||||
where l.recordDelete_timeMillis is null
|
||||
and l.burialSiteId = ?
|
||||
|
||||
union
|
||||
|
||||
select ? as burialSiteId, f.burialSiteTypeFieldId,
|
||||
'' as fieldValue,
|
||||
f.burialSiteTypeField, f.fieldType, f.fieldValues,
|
||||
f.isRequired, f.pattern, f.minimumLength, f.maximumLength,
|
||||
f.orderNumber, t.orderNumber as burialSiteTypeOrderNumber
|
||||
from BurialSiteTypeFields f
|
||||
left join BurialSiteTypes t on f.burialSiteTypeId = t.burialSiteTypeId
|
||||
where f.recordDelete_timeMillis is null
|
||||
and (
|
||||
f.burialSiteTypeId is null
|
||||
or f.burialSiteTypeId in (select burialSiteTypeId from BurialSites where burialSiteId = ?))
|
||||
and f.burialSiteTypeFieldId not in (select burialSiteTypeFieldId from BurialSiteFields where burialSiteId = ? and recordDelete_timeMillis is null)
|
||||
order by burialSiteTypeOrderNumber, f.orderNumber, f.burialSiteTypeField`)
|
||||
.all(burialSiteId, burialSiteId, burialSiteId, burialSiteId);
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return burialSiteFields;
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import type { BurialSiteField } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export default async function getBurialSiteFields(
|
||||
burialSiteId: number | string,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<BurialSiteField[]> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
const burialSiteFields = database
|
||||
.prepare(
|
||||
`select l.burialSiteId, l.burialSiteTypeFieldId,
|
||||
l.fieldValue,
|
||||
f.burialSiteTypeField, f.fieldType, f.fieldValues,
|
||||
f.isRequired, f.pattern, f.minimumLength, f.maximumLength,
|
||||
f.orderNumber, t.orderNumber as burialSiteTypeOrderNumber
|
||||
from BurialSiteFields l
|
||||
left join BurialSiteTypeFields f on l.burialSiteTypeFieldId = f.burialSiteTypeFieldId
|
||||
left join BurialSiteTypes t on f.burialSiteTypeId = t.burialSiteTypeId
|
||||
where l.recordDelete_timeMillis is null
|
||||
and l.burialSiteId = ?
|
||||
|
||||
union
|
||||
|
||||
select ? as burialSiteId, f.burialSiteTypeFieldId,
|
||||
'' as fieldValue,
|
||||
f.burialSiteTypeField, f.fieldType, f.fieldValues,
|
||||
f.isRequired, f.pattern, f.minimumLength, f.maximumLength,
|
||||
f.orderNumber, t.orderNumber as burialSiteTypeOrderNumber
|
||||
from BurialSiteTypeFields f
|
||||
left join BurialSiteTypes t on f.burialSiteTypeId = t.burialSiteTypeId
|
||||
where f.recordDelete_timeMillis is null
|
||||
and (
|
||||
f.burialSiteTypeId is null
|
||||
or f.burialSiteTypeId in (select burialSiteTypeId from BurialSites where burialSiteId = ?))
|
||||
and f.burialSiteTypeFieldId not in (select burialSiteTypeFieldId from BurialSiteFields where burialSiteId = ? and recordDelete_timeMillis is null)
|
||||
order by burialSiteTypeOrderNumber, f.orderNumber, f.burialSiteTypeField`
|
||||
)
|
||||
.all(
|
||||
burialSiteId,
|
||||
burialSiteId,
|
||||
burialSiteId,
|
||||
burialSiteId
|
||||
) as BurialSiteField[]
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return burialSiteFields
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import type { BurialSiteStatus } from '../types/recordTypes.js';
|
||||
interface GetFilters {
|
||||
cemeteryId?: number | string;
|
||||
}
|
||||
interface BurialSiteStatusSummary extends BurialSiteStatus {
|
||||
burialSiteCount: number;
|
||||
}
|
||||
export default function getBurialSiteStatusSummary(filters: GetFilters): Promise<BurialSiteStatusSummary[]>;
|
||||
export {};
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function getBurialSiteStatusSummary(filters) {
|
||||
const database = await acquireConnection();
|
||||
let sqlWhereClause = ' where l.recordDelete_timeMillis is null';
|
||||
const sqlParameters = [];
|
||||
if ((filters.cemeteryId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.cemeteryId = ?';
|
||||
sqlParameters.push(filters.cemeteryId);
|
||||
}
|
||||
const statuses = database
|
||||
.prepare(`select s.burialSiteStatusId, s.burialSiteStatus,
|
||||
count(l.burialSiteId) as burialSiteCount
|
||||
from BurialSites l
|
||||
left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId
|
||||
${sqlWhereClause}
|
||||
group by s.burialSiteStatusId, s.burialSiteStatus, s.orderNumber
|
||||
order by s.orderNumber`)
|
||||
.all(sqlParameters);
|
||||
database.release();
|
||||
return statuses;
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import type { BurialSiteStatus } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
interface GetFilters {
|
||||
cemeteryId?: number | string
|
||||
}
|
||||
|
||||
interface BurialSiteStatusSummary extends BurialSiteStatus {
|
||||
burialSiteCount: number
|
||||
}
|
||||
|
||||
export default async function getBurialSiteStatusSummary(
|
||||
filters: GetFilters
|
||||
): Promise<BurialSiteStatusSummary[]> {
|
||||
const database = await acquireConnection()
|
||||
|
||||
let sqlWhereClause = ' where l.recordDelete_timeMillis is null'
|
||||
const sqlParameters: unknown[] = []
|
||||
|
||||
if ((filters.cemeteryId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.cemeteryId = ?'
|
||||
sqlParameters.push(filters.cemeteryId)
|
||||
}
|
||||
|
||||
const statuses = database
|
||||
.prepare(
|
||||
`select s.burialSiteStatusId, s.burialSiteStatus,
|
||||
count(l.burialSiteId) as burialSiteCount
|
||||
from BurialSites l
|
||||
left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId
|
||||
${sqlWhereClause}
|
||||
group by s.burialSiteStatusId, s.burialSiteStatus, s.orderNumber
|
||||
order by s.orderNumber`
|
||||
)
|
||||
.all(sqlParameters) as BurialSiteStatusSummary[]
|
||||
|
||||
database.release()
|
||||
|
||||
return statuses
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
import type { BurialSiteStatus } from '../types/recordTypes.js';
|
||||
export default function getBurialSiteStatuses(): Promise<BurialSiteStatus[]>;
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
||||
export default async function getBurialSiteStatuses() {
|
||||
const database = await acquireConnection();
|
||||
const statuses = database
|
||||
.prepare(`select burialSiteStatusId, burialSiteStatus, orderNumber
|
||||
from BurialSiteStatuses
|
||||
where recordDelete_timeMillis is null
|
||||
order by orderNumber, burialSiteStatus`)
|
||||
.all();
|
||||
let expectedOrderNumber = 0;
|
||||
for (const status of statuses) {
|
||||
if (status.orderNumber !== expectedOrderNumber) {
|
||||
updateRecordOrderNumber('BurialSiteStatuses', status.burialSiteStatusId, expectedOrderNumber, database);
|
||||
status.orderNumber = expectedOrderNumber;
|
||||
}
|
||||
expectedOrderNumber += 1;
|
||||
}
|
||||
database.release();
|
||||
return statuses;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
import type { BurialSiteStatus } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
||||
|
||||
export default async function getBurialSiteStatuses(): Promise<BurialSiteStatus[]> {
|
||||
const database = await acquireConnection()
|
||||
|
||||
const statuses = database
|
||||
.prepare(
|
||||
`select burialSiteStatusId, burialSiteStatus, orderNumber
|
||||
from BurialSiteStatuses
|
||||
where recordDelete_timeMillis is null
|
||||
order by orderNumber, burialSiteStatus`
|
||||
)
|
||||
.all() as BurialSiteStatus[]
|
||||
|
||||
let expectedOrderNumber = 0
|
||||
|
||||
for (const status of statuses) {
|
||||
if (status.orderNumber !== expectedOrderNumber) {
|
||||
updateRecordOrderNumber(
|
||||
'BurialSiteStatuses',
|
||||
status.burialSiteStatusId,
|
||||
expectedOrderNumber,
|
||||
database
|
||||
)
|
||||
status.orderNumber = expectedOrderNumber
|
||||
}
|
||||
|
||||
expectedOrderNumber += 1
|
||||
}
|
||||
|
||||
database.release()
|
||||
|
||||
return statuses
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import type { BurialSiteTypeField } from '../types/recordTypes.js';
|
||||
export default function getBurialSiteTypeFields(burialSiteTypeId: number, connectedDatabase?: PoolConnection): Promise<BurialSiteTypeField[]>;
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
||||
export default async function getBurialSiteTypeFields(burialSiteTypeId, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
const typeFields = database
|
||||
.prepare(`select burialSiteTypeFieldId,
|
||||
burialSiteTypeField, fieldType, fieldValues,
|
||||
isRequired, pattern, minimumLength, maximumLength, orderNumber
|
||||
from BurialSiteTypeFields
|
||||
where recordDelete_timeMillis is null
|
||||
and burialSiteTypeId = ?
|
||||
order by orderNumber, burialSiteTypeField`)
|
||||
.all(burialSiteTypeId);
|
||||
let expectedOrderNumber = 0;
|
||||
for (const typeField of typeFields) {
|
||||
if (typeField.orderNumber !== expectedOrderNumber) {
|
||||
updateRecordOrderNumber('BurialSiteTypeFields', typeField.burialSiteTypeFieldId, expectedOrderNumber, database);
|
||||
typeField.orderNumber = expectedOrderNumber;
|
||||
}
|
||||
expectedOrderNumber += 1;
|
||||
}
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return typeFields;
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import type { BurialSiteTypeField } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
||||
|
||||
export default async function getBurialSiteTypeFields(
|
||||
burialSiteTypeId: number,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<BurialSiteTypeField[]> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
const typeFields = database
|
||||
.prepare(
|
||||
`select burialSiteTypeFieldId,
|
||||
burialSiteTypeField, fieldType, fieldValues,
|
||||
isRequired, pattern, minimumLength, maximumLength, orderNumber
|
||||
from BurialSiteTypeFields
|
||||
where recordDelete_timeMillis is null
|
||||
and burialSiteTypeId = ?
|
||||
order by orderNumber, burialSiteTypeField`
|
||||
)
|
||||
.all(burialSiteTypeId) as BurialSiteTypeField[]
|
||||
|
||||
let expectedOrderNumber = 0
|
||||
|
||||
for (const typeField of typeFields) {
|
||||
if (typeField.orderNumber !== expectedOrderNumber) {
|
||||
updateRecordOrderNumber(
|
||||
'BurialSiteTypeFields',
|
||||
typeField.burialSiteTypeFieldId,
|
||||
expectedOrderNumber,
|
||||
database
|
||||
)
|
||||
|
||||
typeField.orderNumber = expectedOrderNumber
|
||||
}
|
||||
|
||||
expectedOrderNumber += 1
|
||||
}
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return typeFields
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import type { BurialSiteType } from '../types/recordTypes.js';
|
||||
interface GetFilters {
|
||||
cemeteryId?: number | string;
|
||||
}
|
||||
interface BurialSiteTypeSummary extends BurialSiteType {
|
||||
lotCount: number;
|
||||
}
|
||||
export default function getBurialSiteTypeSummary(filters: GetFilters): Promise<BurialSiteTypeSummary[]>;
|
||||
export {};
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function getBurialSiteTypeSummary(filters) {
|
||||
const database = await acquireConnection();
|
||||
let sqlWhereClause = ' where l.recordDelete_timeMillis is null';
|
||||
const sqlParameters = [];
|
||||
if ((filters.cemeteryId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.cemeteryId = ?';
|
||||
sqlParameters.push(filters.cemeteryId);
|
||||
}
|
||||
const burialSiteTypes = database
|
||||
.prepare(`select t.burialSiteTypeId, t.burialSiteType,
|
||||
count(l.burialSiteId) as burialSiteCount
|
||||
from BurialSites l
|
||||
left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId
|
||||
${sqlWhereClause}
|
||||
group by t.burialSiteTypeId, t.burialSiteType, t.orderNumber
|
||||
order by t.orderNumber`)
|
||||
.all(sqlParameters);
|
||||
database.release();
|
||||
return burialSiteTypes;
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import type { BurialSiteType } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
interface GetFilters {
|
||||
cemeteryId?: number | string
|
||||
}
|
||||
|
||||
interface BurialSiteTypeSummary extends BurialSiteType {
|
||||
lotCount: number
|
||||
}
|
||||
|
||||
export default async function getBurialSiteTypeSummary(
|
||||
filters: GetFilters
|
||||
): Promise<BurialSiteTypeSummary[]> {
|
||||
const database = await acquireConnection()
|
||||
|
||||
let sqlWhereClause = ' where l.recordDelete_timeMillis is null'
|
||||
const sqlParameters: unknown[] = []
|
||||
|
||||
if ((filters.cemeteryId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.cemeteryId = ?'
|
||||
sqlParameters.push(filters.cemeteryId)
|
||||
}
|
||||
|
||||
const burialSiteTypes = database
|
||||
.prepare(
|
||||
`select t.burialSiteTypeId, t.burialSiteType,
|
||||
count(l.burialSiteId) as burialSiteCount
|
||||
from BurialSites l
|
||||
left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId
|
||||
${sqlWhereClause}
|
||||
group by t.burialSiteTypeId, t.burialSiteType, t.orderNumber
|
||||
order by t.orderNumber`
|
||||
)
|
||||
.all(sqlParameters) as BurialSiteTypeSummary[]
|
||||
|
||||
database.release()
|
||||
|
||||
return burialSiteTypes
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
import type { BurialSiteType } from '../types/recordTypes.js';
|
||||
export default function getBurialSiteTypes(): Promise<BurialSiteType[]>;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import getBurialSiteTypeFields from './getBurialSiteTypeFields.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
||||
export default async function getBurialSiteTypes() {
|
||||
const database = await acquireConnection();
|
||||
const burialSiteTypes = database
|
||||
.prepare(`select burialSiteTypeId, burialSiteType, orderNumber
|
||||
from BurialSiteTypes
|
||||
where recordDelete_timeMillis is null
|
||||
order by orderNumber, burialSiteType`)
|
||||
.all();
|
||||
let expectedOrderNumber = -1;
|
||||
for (const burialSiteType of burialSiteTypes) {
|
||||
expectedOrderNumber += 1;
|
||||
if (burialSiteType.orderNumber !== expectedOrderNumber) {
|
||||
updateRecordOrderNumber('BurialSiteTypes', burialSiteType.burialSiteTypeId, expectedOrderNumber, database);
|
||||
burialSiteType.orderNumber = expectedOrderNumber;
|
||||
}
|
||||
burialSiteType.burialSiteTypeFields = await getBurialSiteTypeFields(burialSiteType.burialSiteTypeId, database);
|
||||
}
|
||||
database.release();
|
||||
return burialSiteTypes;
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
import type { BurialSiteType } from '../types/recordTypes.js'
|
||||
|
||||
import getBurialSiteTypeFields from './getBurialSiteTypeFields.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
||||
|
||||
export default async function getBurialSiteTypes(): Promise<BurialSiteType[]> {
|
||||
const database = await acquireConnection()
|
||||
|
||||
const burialSiteTypes = database
|
||||
.prepare(
|
||||
`select burialSiteTypeId, burialSiteType, orderNumber
|
||||
from BurialSiteTypes
|
||||
where recordDelete_timeMillis is null
|
||||
order by orderNumber, burialSiteType`
|
||||
)
|
||||
.all() as BurialSiteType[]
|
||||
|
||||
let expectedOrderNumber = -1
|
||||
|
||||
for (const burialSiteType of burialSiteTypes) {
|
||||
expectedOrderNumber += 1
|
||||
|
||||
if (burialSiteType.orderNumber !== expectedOrderNumber) {
|
||||
updateRecordOrderNumber(
|
||||
'BurialSiteTypes',
|
||||
burialSiteType.burialSiteTypeId,
|
||||
expectedOrderNumber,
|
||||
database
|
||||
)
|
||||
|
||||
burialSiteType.orderNumber = expectedOrderNumber
|
||||
}
|
||||
|
||||
burialSiteType.burialSiteTypeFields = await getBurialSiteTypeFields(
|
||||
burialSiteType.burialSiteTypeId,
|
||||
database
|
||||
)
|
||||
}
|
||||
|
||||
database.release()
|
||||
|
||||
return burialSiteTypes
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import type { BurialSite } from '../types/recordTypes.js';
|
||||
interface GetBurialSitesFilters {
|
||||
burialSiteNameSearchType?: '' | 'startsWith' | 'endsWith';
|
||||
burialSiteName?: string;
|
||||
cemeteryId?: number | string;
|
||||
burialSiteTypeId?: number | string;
|
||||
burialSiteStatusId?: number | string;
|
||||
contractStatus?: '' | 'occupied' | 'unoccupied';
|
||||
workOrderId?: number | string;
|
||||
}
|
||||
interface GetBurialSitesOptions {
|
||||
/** -1 for no limit */
|
||||
limit: number;
|
||||
offset: number;
|
||||
includeBurialSiteContractCount?: boolean;
|
||||
}
|
||||
export default function getBurialSites(filters: GetBurialSitesFilters, options: GetBurialSitesOptions, connectedDatabase?: PoolConnection): Promise<{
|
||||
count: number;
|
||||
burialSites: BurialSite[];
|
||||
}>;
|
||||
export {};
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
import { dateToInteger } from '@cityssm/utils-datetime';
|
||||
import { getLotNameWhereClause } from '../helpers/functions.sqlFilters.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
function buildWhereClause(filters) {
|
||||
let sqlWhereClause = ' where l.recordDelete_timeMillis is null';
|
||||
const sqlParameters = [];
|
||||
const lotNameFilters = getLotNameWhereClause(filters.burialSiteName, filters.burialSiteNameSearchType ?? '', 'l');
|
||||
sqlWhereClause += lotNameFilters.sqlWhereClause;
|
||||
sqlParameters.push(...lotNameFilters.sqlParameters);
|
||||
if ((filters.cemeteryId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.cemeteryId = ?';
|
||||
sqlParameters.push(filters.cemeteryId);
|
||||
}
|
||||
if ((filters.burialSiteTypeId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.burialSiteTypeId = ?';
|
||||
sqlParameters.push(filters.burialSiteTypeId);
|
||||
}
|
||||
if ((filters.burialSiteStatusId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.burialSiteStatusId = ?';
|
||||
sqlParameters.push(filters.burialSiteStatusId);
|
||||
}
|
||||
if ((filters.contractStatus ?? '') !== '') {
|
||||
if (filters.contractStatus === 'occupied') {
|
||||
sqlWhereClause += ' and lotOccupancyCount > 0';
|
||||
}
|
||||
else if (filters.contractStatus === 'unoccupied') {
|
||||
sqlWhereClause +=
|
||||
' and (lotOccupancyCount is null or lotOccupancyCount = 0)';
|
||||
}
|
||||
}
|
||||
if ((filters.workOrderId ?? '') !== '') {
|
||||
sqlWhereClause +=
|
||||
' and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)';
|
||||
sqlParameters.push(filters.workOrderId);
|
||||
}
|
||||
return {
|
||||
sqlWhereClause,
|
||||
sqlParameters
|
||||
};
|
||||
}
|
||||
export default async function getBurialSites(filters, options, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
|
||||
const currentDate = dateToInteger(new Date());
|
||||
let count = 0;
|
||||
if (options.limit !== -1) {
|
||||
count = database
|
||||
.prepare(`select count(*) as recordCount
|
||||
from BurialSites l
|
||||
left join (
|
||||
select burialSiteId, count(burialSiteContractId) as burialSiteContractCount from BurialSiteContracts
|
||||
where recordDelete_timeMillis is null
|
||||
and contractStartDate <= ${currentDate.toString()}
|
||||
and (contractEndDate is null or contractEndDate >= ${currentDate.toString()})
|
||||
group by burialSiteId
|
||||
) o on l.burialSiteId = o.burialSiteId
|
||||
${sqlWhereClause}`)
|
||||
.get(sqlParameters).recordCount;
|
||||
}
|
||||
let burialSites = [];
|
||||
if (options.limit === -1 || count > 0) {
|
||||
const includeBurialSiteContractCount = options.includeBurialSiteContractCount ?? true;
|
||||
if (includeBurialSiteContractCount) {
|
||||
sqlParameters.unshift(currentDate, currentDate);
|
||||
}
|
||||
burialSites = database
|
||||
.prepare(`select l.burialSiteId,
|
||||
l.burialSiteNameSegment1,
|
||||
l.burialSiteNameSegment2,
|
||||
l.burialSiteNameSegment3,
|
||||
l.burialSiteNameSegment4,
|
||||
l.burialSiteNameSegment5,
|
||||
t.burialSiteType,
|
||||
l.cemeteryId, m.cemeteryName, l.cemeterySvgId,
|
||||
l.burialSiteStatusId, s.burialSiteStatus
|
||||
${includeBurialSiteContractCount
|
||||
? ', ifnull(o.burialSiteContractCount, 0) as burialSiteContractCount'
|
||||
: ''}
|
||||
from BurialSites l
|
||||
left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId
|
||||
left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId
|
||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||
${includeBurialSiteContractCount
|
||||
? `left join (
|
||||
select burialSiteId, count(burialSiteContractId) as burialSiteContractCount
|
||||
from BurialSiteContracts
|
||||
where recordDelete_timeMillis is null
|
||||
and contractStartDate <= ?
|
||||
and (contractEndDate is null or contractEndDate >= ?)
|
||||
group by burialSiteId) o on l.burialSiteId = o.burialSiteId`
|
||||
: ''}
|
||||
${sqlWhereClause}
|
||||
order by l.burialSiteNameSegment1,
|
||||
l.burialSiteNameSegment2,
|
||||
l.burialSiteNameSegment3,
|
||||
l.burialSiteNameSegment4,
|
||||
l.burialSiteNameSegment5,
|
||||
l.burialSiteId
|
||||
${options.limit === -1
|
||||
? ''
|
||||
: ` limit ${options.limit.toString()} offset ${options.offset.toString()}`}`)
|
||||
.all(sqlParameters);
|
||||
if (options.limit === -1) {
|
||||
count = burialSites.length;
|
||||
}
|
||||
}
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return {
|
||||
count,
|
||||
burialSites
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,177 @@
|
|||
import { dateToInteger } from '@cityssm/utils-datetime'
|
||||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import { getLotNameWhereClause } from '../helpers/functions.sqlFilters.js'
|
||||
import type { BurialSite } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
interface GetBurialSitesFilters {
|
||||
burialSiteNameSearchType?: '' | 'startsWith' | 'endsWith'
|
||||
burialSiteName?: string
|
||||
cemeteryId?: number | string
|
||||
burialSiteTypeId?: number | string
|
||||
burialSiteStatusId?: number | string
|
||||
contractStatus?: '' | 'occupied' | 'unoccupied'
|
||||
workOrderId?: number | string
|
||||
}
|
||||
|
||||
interface GetBurialSitesOptions {
|
||||
/** -1 for no limit */
|
||||
limit: number
|
||||
offset: number
|
||||
includeBurialSiteContractCount?: boolean
|
||||
}
|
||||
|
||||
function buildWhereClause(filters: GetBurialSitesFilters): {
|
||||
sqlWhereClause: string
|
||||
sqlParameters: unknown[]
|
||||
} {
|
||||
let sqlWhereClause = ' where l.recordDelete_timeMillis is null'
|
||||
const sqlParameters: unknown[] = []
|
||||
|
||||
const lotNameFilters = getLotNameWhereClause(
|
||||
filters.burialSiteName,
|
||||
filters.burialSiteNameSearchType ?? '',
|
||||
'l'
|
||||
)
|
||||
sqlWhereClause += lotNameFilters.sqlWhereClause
|
||||
sqlParameters.push(...lotNameFilters.sqlParameters)
|
||||
|
||||
if ((filters.cemeteryId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.cemeteryId = ?'
|
||||
sqlParameters.push(filters.cemeteryId)
|
||||
}
|
||||
|
||||
if ((filters.burialSiteTypeId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.burialSiteTypeId = ?'
|
||||
sqlParameters.push(filters.burialSiteTypeId)
|
||||
}
|
||||
|
||||
if ((filters.burialSiteStatusId ?? '') !== '') {
|
||||
sqlWhereClause += ' and l.burialSiteStatusId = ?'
|
||||
sqlParameters.push(filters.burialSiteStatusId)
|
||||
}
|
||||
|
||||
if ((filters.contractStatus ?? '') !== '') {
|
||||
if (filters.contractStatus === 'occupied') {
|
||||
sqlWhereClause += ' and lotOccupancyCount > 0'
|
||||
} else if (filters.contractStatus === 'unoccupied') {
|
||||
sqlWhereClause +=
|
||||
' and (lotOccupancyCount is null or lotOccupancyCount = 0)'
|
||||
}
|
||||
}
|
||||
|
||||
if ((filters.workOrderId ?? '') !== '') {
|
||||
sqlWhereClause +=
|
||||
' and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)'
|
||||
sqlParameters.push(filters.workOrderId)
|
||||
}
|
||||
|
||||
return {
|
||||
sqlWhereClause,
|
||||
sqlParameters
|
||||
}
|
||||
}
|
||||
|
||||
export default async function getBurialSites(
|
||||
filters: GetBurialSitesFilters,
|
||||
options: GetBurialSitesOptions,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<{ count: number; burialSites: BurialSite[] }> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters)
|
||||
|
||||
const currentDate = dateToInteger(new Date())
|
||||
|
||||
let count = 0
|
||||
|
||||
if (options.limit !== -1) {
|
||||
count = (
|
||||
database
|
||||
.prepare(
|
||||
`select count(*) as recordCount
|
||||
from BurialSites l
|
||||
left join (
|
||||
select burialSiteId, count(burialSiteContractId) as burialSiteContractCount from BurialSiteContracts
|
||||
where recordDelete_timeMillis is null
|
||||
and contractStartDate <= ${currentDate.toString()}
|
||||
and (contractEndDate is null or contractEndDate >= ${currentDate.toString()})
|
||||
group by burialSiteId
|
||||
) o on l.burialSiteId = o.burialSiteId
|
||||
${sqlWhereClause}`
|
||||
)
|
||||
.get(sqlParameters) as { recordCount: number }
|
||||
).recordCount
|
||||
}
|
||||
|
||||
let burialSites: BurialSite[] = []
|
||||
|
||||
if (options.limit === -1 || count > 0) {
|
||||
const includeBurialSiteContractCount = options.includeBurialSiteContractCount ?? true
|
||||
|
||||
if (includeBurialSiteContractCount) {
|
||||
sqlParameters.unshift(currentDate, currentDate)
|
||||
}
|
||||
|
||||
burialSites = database
|
||||
.prepare(
|
||||
`select l.burialSiteId,
|
||||
l.burialSiteNameSegment1,
|
||||
l.burialSiteNameSegment2,
|
||||
l.burialSiteNameSegment3,
|
||||
l.burialSiteNameSegment4,
|
||||
l.burialSiteNameSegment5,
|
||||
t.burialSiteType,
|
||||
l.cemeteryId, m.cemeteryName, l.cemeterySvgId,
|
||||
l.burialSiteStatusId, s.burialSiteStatus
|
||||
${
|
||||
includeBurialSiteContractCount
|
||||
? ', ifnull(o.burialSiteContractCount, 0) as burialSiteContractCount'
|
||||
: ''
|
||||
}
|
||||
from BurialSites l
|
||||
left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId
|
||||
left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId
|
||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||
${
|
||||
includeBurialSiteContractCount
|
||||
? `left join (
|
||||
select burialSiteId, count(burialSiteContractId) as burialSiteContractCount
|
||||
from BurialSiteContracts
|
||||
where recordDelete_timeMillis is null
|
||||
and contractStartDate <= ?
|
||||
and (contractEndDate is null or contractEndDate >= ?)
|
||||
group by burialSiteId) o on l.burialSiteId = o.burialSiteId`
|
||||
: ''
|
||||
}
|
||||
${sqlWhereClause}
|
||||
order by l.burialSiteNameSegment1,
|
||||
l.burialSiteNameSegment2,
|
||||
l.burialSiteNameSegment3,
|
||||
l.burialSiteNameSegment4,
|
||||
l.burialSiteNameSegment5,
|
||||
l.burialSiteId
|
||||
${
|
||||
options.limit === -1
|
||||
? ''
|
||||
: ` limit ${options.limit.toString()} offset ${options.offset.toString()}`
|
||||
}`
|
||||
)
|
||||
.all(sqlParameters) as BurialSite[]
|
||||
|
||||
if (options.limit === -1) {
|
||||
count = burialSites.length
|
||||
}
|
||||
}
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return {
|
||||
count,
|
||||
burialSites
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
import type { Cemetery } from '../types/recordTypes.js';
|
||||
export default function getCemeteries(): Promise<Cemetery[]>;
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function getCemeteries() {
|
||||
const database = await acquireConnection();
|
||||
const cemeteries = database
|
||||
.prepare(`select m.cemeteryId, m.cemeteryName, m.cemeteryDescription,
|
||||
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
|
||||
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
|
||||
m.cemeteryPhoneNumber,
|
||||
ifnull(l.burialSiteCount, 0) as burialSiteCount
|
||||
from Cemeteries m
|
||||
left join (
|
||||
select cemeteryId, count(burialSiteId) as burialSiteCount
|
||||
from BurialSites
|
||||
where recordDelete_timeMillis is null
|
||||
group by cemeteryId
|
||||
) l on m.cemeteryId = l.cemeteryId
|
||||
where m.recordDelete_timeMillis is null
|
||||
order by m.cemeteryName, m.cemeteryId`)
|
||||
.all();
|
||||
database.release();
|
||||
return cemeteries;
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
import type { Cemetery } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export default async function getCemeteries(): Promise<Cemetery[]> {
|
||||
const database = await acquireConnection()
|
||||
|
||||
const cemeteries = database
|
||||
.prepare(
|
||||
`select m.cemeteryId, m.cemeteryName, m.cemeteryDescription,
|
||||
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
|
||||
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
|
||||
m.cemeteryPhoneNumber,
|
||||
ifnull(l.burialSiteCount, 0) as burialSiteCount
|
||||
from Cemeteries m
|
||||
left join (
|
||||
select cemeteryId, count(burialSiteId) as burialSiteCount
|
||||
from BurialSites
|
||||
where recordDelete_timeMillis is null
|
||||
group by cemeteryId
|
||||
) l on m.cemeteryId = l.cemeteryId
|
||||
where m.recordDelete_timeMillis is null
|
||||
order by m.cemeteryName, m.cemeteryId`
|
||||
)
|
||||
.all() as Cemetery[]
|
||||
|
||||
database.release()
|
||||
|
||||
return cemeteries
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
import type { Cemetery } from '../types/recordTypes.js';
|
||||
export default function getMap(cemeteryId: number | string): Promise<Cemetery | undefined>;
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function getMap(cemeteryId) {
|
||||
const database = await acquireConnection();
|
||||
const map = database
|
||||
.prepare(`select m.cemeteryId, m.cemeteryName, m.cemeteryDescription,
|
||||
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
|
||||
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
|
||||
m.cemeteryPhoneNumber,
|
||||
m.recordCreate_userName, m.recordCreate_timeMillis,
|
||||
m.recordUpdate_userName, m.recordUpdate_timeMillis,
|
||||
m.recordDelete_userName, m.recordDelete_timeMillis,
|
||||
count(l.burialSiteId) as burialSiteCount
|
||||
from Cemeteries m
|
||||
left join BurialSites l on m.cemeteryId = l.cemeteryId and l.recordDelete_timeMillis is null
|
||||
where m.cemeteryId = ?
|
||||
and m.recordDelete_timeMillis is null
|
||||
group by m.cemeteryId, m.cemeteryName, m.cemeteryDescription,
|
||||
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
|
||||
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
|
||||
m.cemeteryPhoneNumber,
|
||||
m.recordCreate_userName, m.recordCreate_timeMillis,
|
||||
m.recordUpdate_userName, m.recordUpdate_timeMillis,
|
||||
m.recordDelete_userName, m.recordDelete_timeMillis`)
|
||||
.get(cemeteryId);
|
||||
database.release();
|
||||
return map;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
import type { Cemetery } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export default async function getMap(
|
||||
cemeteryId: number | string
|
||||
): Promise<Cemetery | undefined> {
|
||||
const database = await acquireConnection()
|
||||
|
||||
const map = database
|
||||
.prepare(
|
||||
`select m.cemeteryId, m.cemeteryName, m.cemeteryDescription,
|
||||
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
|
||||
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
|
||||
m.cemeteryPhoneNumber,
|
||||
m.recordCreate_userName, m.recordCreate_timeMillis,
|
||||
m.recordUpdate_userName, m.recordUpdate_timeMillis,
|
||||
m.recordDelete_userName, m.recordDelete_timeMillis,
|
||||
count(l.burialSiteId) as burialSiteCount
|
||||
from Cemeteries m
|
||||
left join BurialSites l on m.cemeteryId = l.cemeteryId and l.recordDelete_timeMillis is null
|
||||
where m.cemeteryId = ?
|
||||
and m.recordDelete_timeMillis is null
|
||||
group by m.cemeteryId, m.cemeteryName, m.cemeteryDescription,
|
||||
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
|
||||
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
|
||||
m.cemeteryPhoneNumber,
|
||||
m.recordCreate_userName, m.recordCreate_timeMillis,
|
||||
m.recordUpdate_userName, m.recordUpdate_timeMillis,
|
||||
m.recordDelete_userName, m.recordDelete_timeMillis`
|
||||
)
|
||||
.get(cemeteryId) as Cemetery | undefined
|
||||
|
||||
database.release()
|
||||
|
||||
return map
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import type { ContractTypeField } from '../types/recordTypes.js';
|
||||
export default function getContractTypeFields(contractTypeId?: number, connectedDatabase?: PoolConnection): Promise<ContractTypeField[]>;
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
||||
export default async function getContractTypeFields(contractTypeId, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
const sqlParameters = [];
|
||||
if ((contractTypeId ?? -1) !== -1) {
|
||||
sqlParameters.push(contractTypeId);
|
||||
}
|
||||
const contractTypeFields = database
|
||||
.prepare(`select contractTypeFieldId, contractTypeField, fieldType,
|
||||
fieldValues, isRequired, pattern, minimumLength, maximumLength, orderNumber
|
||||
from ContractTypeFields
|
||||
where recordDelete_timeMillis is null
|
||||
${(contractTypeId ?? -1) === -1
|
||||
? ' and contractTypeId is null'
|
||||
: ' and contractTypeId = ?'}
|
||||
order by orderNumber, contractTypeField`)
|
||||
.all(sqlParameters);
|
||||
let expectedOrderNumber = 0;
|
||||
for (const contractTypeField of contractTypeFields) {
|
||||
if (contractTypeField.orderNumber !== expectedOrderNumber) {
|
||||
updateRecordOrderNumber('ContractTypeFields', contractTypeField.contractTypeFieldId, expectedOrderNumber, database);
|
||||
contractTypeField.orderNumber = expectedOrderNumber;
|
||||
}
|
||||
expectedOrderNumber += 1;
|
||||
}
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return contractTypeFields;
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import type { ContractTypeField } from '../types/recordTypes.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
||||
|
||||
export default async function getContractTypeFields(
|
||||
contractTypeId?: number,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<ContractTypeField[]> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
const sqlParameters: unknown[] = []
|
||||
|
||||
if ((contractTypeId ?? -1) !== -1) {
|
||||
sqlParameters.push(contractTypeId)
|
||||
}
|
||||
|
||||
const contractTypeFields = database
|
||||
.prepare(
|
||||
`select contractTypeFieldId, contractTypeField, fieldType,
|
||||
fieldValues, isRequired, pattern, minimumLength, maximumLength, orderNumber
|
||||
from ContractTypeFields
|
||||
where recordDelete_timeMillis is null
|
||||
${
|
||||
(contractTypeId ?? -1) === -1
|
||||
? ' and contractTypeId is null'
|
||||
: ' and contractTypeId = ?'
|
||||
}
|
||||
order by orderNumber, contractTypeField`
|
||||
)
|
||||
.all(sqlParameters) as ContractTypeField[]
|
||||
|
||||
let expectedOrderNumber = 0
|
||||
|
||||
for (const contractTypeField of contractTypeFields) {
|
||||
if (contractTypeField.orderNumber !== expectedOrderNumber) {
|
||||
updateRecordOrderNumber(
|
||||
'ContractTypeFields',
|
||||
contractTypeField.contractTypeFieldId,
|
||||
expectedOrderNumber,
|
||||
database
|
||||
)
|
||||
|
||||
contractTypeField.orderNumber = expectedOrderNumber
|
||||
}
|
||||
|
||||
expectedOrderNumber += 1
|
||||
}
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return contractTypeFields
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
export default function getContractTypePrints(contractTypeId: number, connectedDatabase?: PoolConnection): Promise<string[]>;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue