major refactoring

simplify by remove "burial site" from "burial site contracts"
deepsource-autofix-76c6eb20
Dan Gowans 2025-02-28 13:15:49 -05:00
parent a6524635c0
commit 414a45041c
276 changed files with 2873 additions and 2867 deletions

View File

@ -1,8 +0,0 @@
import { type DateString, type TimeString } from '@cityssm/utils-datetime';
export interface AddBurialSiteContractCommentForm {
burialSiteContractId: string | number;
commentDateString?: DateString;
commentTimeString?: TimeString;
comment: string;
}
export default function addBurialSiteContractComment(commentForm: AddBurialSiteContractCommentForm, user: User): Promise<number>;

View File

@ -1,9 +0,0 @@
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>;

View File

@ -1,5 +0,0 @@
export interface AddBurialSiteContractCategoryForm {
burialSiteContractId: number | string;
feeCategoryId: number | string;
}
export default function addBurialSiteContractFeeCategory(addFeeCategoryForm: AddBurialSiteContractCategoryForm, user: User): Promise<number>;

View File

@ -1,34 +0,0 @@
import { dateStringToInteger, dateToInteger, dateToTimeInteger, timeStringToInteger } from '@cityssm/utils-datetime';
import { acquireConnection } from './pool.js';
export default async function addBurialSiteContractTransaction(burialSiteContractTransactionForm, user) {
const database = await acquireConnection();
let transactionIndex = 0;
const maxIndexResult = database
.prepare(`select transactionIndex
from BurialSiteContractTransactions
where burialSiteContractId = ?
order by transactionIndex desc
limit 1`)
.get(burialSiteContractTransactionForm.burialSiteContractId);
if (maxIndexResult !== undefined) {
transactionIndex = maxIndexResult.transactionIndex + 1;
}
const rightNow = new Date();
const transactionDate = burialSiteContractTransactionForm.transactionDateString
? dateStringToInteger(burialSiteContractTransactionForm.transactionDateString)
: dateToInteger(rightNow);
const transactionTime = burialSiteContractTransactionForm.transactionTimeString
? timeStringToInteger(burialSiteContractTransactionForm.transactionTimeString)
: dateToTimeInteger(rightNow);
database
.prepare(`insert into BurialSiteContractTransactions (
burialSiteContractId, transactionIndex,
transactionDate, transactionTime,
transactionAmount, externalReceiptNumber, transactionNote,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
.run(burialSiteContractTransactionForm.burialSiteContractId, transactionIndex, transactionDate, transactionTime, burialSiteContractTransactionForm.transactionAmount, burialSiteContractTransactionForm.externalReceiptNumber, burialSiteContractTransactionForm.transactionNote, user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
database.release();
return transactionIndex;
}

View File

@ -1,5 +1,5 @@
import type { PoolConnection } from 'better-sqlite-pool';
export interface AddBurialSiteContractForm {
export interface AddContractForm {
contractTypeId: string | number;
burialSiteId: string | number;
contractStartDateString: string;
@ -18,4 +18,4 @@ export interface AddBurialSiteContractForm {
occupantEmailAddress?: string;
occupantComment?: string;
}
export default function addBurialSiteContract(addForm: AddBurialSiteContractForm, user: User, connectedDatabase?: PoolConnection): Promise<number>;
export default function addContract(addForm: AddContractForm, user: User, connectedDatabase?: PoolConnection): Promise<number>;

View File

@ -1,12 +1,12 @@
import { dateStringToInteger } from '@cityssm/utils-datetime';
import addOrUpdateBurialSiteContractField from './addOrUpdateBurialSiteContractField.js';
import addOrUpdateContractField from './addOrUpdateContractField.js';
import { acquireConnection } from './pool.js';
export default async function addBurialSiteContract(addForm, user, connectedDatabase) {
export default async function addContract(addForm, user, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection());
const rightNowMillis = Date.now();
const contractStartDate = dateStringToInteger(addForm.contractStartDateString);
const result = database
.prepare(`insert into BurialSiteContracts (
.prepare(`insert into Contracts (
contractTypeId, lotId,
contractStartDate, contractEndDate,
recordCreate_userName, recordCreate_timeMillis,
@ -15,13 +15,13 @@ export default async function addBurialSiteContract(addForm, user, connectedData
.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 contractId = result.lastInsertRowid;
const contractTypeFieldIds = (addForm.contractTypeFieldIds ?? '').split(',');
for (const contractTypeFieldId of contractTypeFieldIds) {
const fieldValue = addForm[`fieldValue_${contractTypeFieldId}`];
if ((fieldValue ?? '') !== '') {
await addOrUpdateBurialSiteContractField({
burialSiteContractId,
await addOrUpdateContractField({
contractId,
contractTypeFieldId,
fieldValue: fieldValue ?? ''
}, user, database);
@ -30,5 +30,5 @@ export default async function addBurialSiteContract(addForm, user, connectedData
if (connectedDatabase === undefined) {
database.release();
}
return burialSiteContractId;
return contractId;
}

View File

@ -1,10 +1,10 @@
import { type DateString, dateStringToInteger } from '@cityssm/utils-datetime'
import type { PoolConnection } from 'better-sqlite-pool'
import addOrUpdateBurialSiteContractField from './addOrUpdateBurialSiteContractField.js'
import addOrUpdateContractField from './addOrUpdateContractField.js'
import { acquireConnection } from './pool.js'
export interface AddBurialSiteContractForm {
export interface AddContractForm {
contractTypeId: string | number
burialSiteId: string | number
@ -27,8 +27,8 @@ export interface AddBurialSiteContractForm {
occupantComment?: string
}
export default async function addBurialSiteContract(
addForm: AddBurialSiteContractForm,
export default async function addContract(
addForm: AddContractForm,
user: User,
connectedDatabase?: PoolConnection
): Promise<number> {
@ -42,7 +42,7 @@ export default async function addBurialSiteContract(
const result = database
.prepare(
`insert into BurialSiteContracts (
`insert into Contracts (
contractTypeId, lotId,
contractStartDate, contractEndDate,
recordCreate_userName, recordCreate_timeMillis,
@ -62,7 +62,7 @@ export default async function addBurialSiteContract(
rightNowMillis
)
const burialSiteContractId = result.lastInsertRowid as number
const contractId = result.lastInsertRowid as number
const contractTypeFieldIds = (addForm.contractTypeFieldIds ?? '').split(',')
@ -72,9 +72,9 @@ export default async function addBurialSiteContract(
| undefined
if ((fieldValue ?? '') !== '') {
await addOrUpdateBurialSiteContractField(
await addOrUpdateContractField(
{
burialSiteContractId,
contractId,
contractTypeFieldId,
fieldValue: fieldValue ?? ''
},
@ -88,5 +88,5 @@ export default async function addBurialSiteContract(
database.release()
}
return burialSiteContractId
return contractId
}

View File

@ -0,0 +1,8 @@
import { type DateString, type TimeString } from '@cityssm/utils-datetime';
export interface AddContractCommentForm {
contractId: string | number;
commentDateString?: DateString;
commentTimeString?: TimeString;
comment: string;
}
export default function addContractComment(commentForm: AddContractCommentForm, user: User): Promise<number>;

View File

@ -1,6 +1,6 @@
import { dateStringToInteger, dateToInteger, dateToTimeInteger, timeStringToInteger } from '@cityssm/utils-datetime';
import { acquireConnection } from './pool.js';
export default async function addBurialSiteContractComment(commentForm, user) {
export default async function addContractComment(commentForm, user) {
const rightNow = new Date();
let commentDate = 0;
let commentTime = 0;
@ -15,13 +15,13 @@ export default async function addBurialSiteContractComment(commentForm, user) {
const database = await acquireConnection();
const result = database
.prepare(`insert into BurialSiteContactComments (
burialSiteContractId,
contractId,
commentDate, commentTime,
comment,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?, ?)`)
.run(commentForm.burialSiteContractId, commentDate, commentTime ?? 0, commentForm.comment, user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
.run(commentForm.contractId, commentDate, commentTime ?? 0, commentForm.comment, user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
database.release();
return result.lastInsertRowid;
}

View File

@ -9,15 +9,15 @@ import {
import { acquireConnection } from './pool.js'
export interface AddBurialSiteContractCommentForm {
burialSiteContractId: string | number
export interface AddContractCommentForm {
contractId: string | number
commentDateString?: DateString
commentTimeString?: TimeString
comment: string
}
export default async function addBurialSiteContractComment(
commentForm: AddBurialSiteContractCommentForm,
export default async function addContractComment(
commentForm: AddContractCommentForm,
user: User
): Promise<number> {
const rightNow = new Date()
@ -42,7 +42,7 @@ export default async function addBurialSiteContractComment(
const result = database
.prepare(
`insert into BurialSiteContactComments (
burialSiteContractId,
contractId,
commentDate, commentTime,
comment,
recordCreate_userName, recordCreate_timeMillis,
@ -50,7 +50,7 @@ export default async function addBurialSiteContractComment(
values (?, ?, ?, ?, ?, ?, ?, ?)`
)
.run(
commentForm.burialSiteContractId,
commentForm.contractId,
commentDate,
commentTime ?? 0,
commentForm.comment,

9
database/addContractFee.d.ts vendored 100644
View File

@ -0,0 +1,9 @@
import type { PoolConnection } from 'better-sqlite-pool';
export interface AddContractFeeForm {
contractId: number | string;
feeId: number | string;
quantity: number | string;
feeAmount?: number | string;
taxAmount?: number | string;
}
export default function addContractFee(addFeeForm: AddContractFeeForm, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;

View File

@ -1,17 +1,17 @@
import { calculateFeeAmount, calculateTaxAmount } from '../helpers/functions.fee.js';
import getBurialSiteContract from './getBurialSiteContract.js';
import getContract from './getContract.js';
import getFee from './getFee.js';
import { acquireConnection } from './pool.js';
export default async function addBurialSiteContractFee(addFeeForm, user, connectedDatabase) {
export default async function addContractFee(addFeeForm, user, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection());
const rightNowMillis = Date.now();
// Calculate fee and tax (if not set)
let feeAmount;
let taxAmount;
if ((addFeeForm.feeAmount ?? '') === '') {
const burialSiteContract = (await getBurialSiteContract(addFeeForm.burialSiteContractId));
const contract = (await getContract(addFeeForm.contractId));
const fee = (await getFee(addFeeForm.feeId));
feeAmount = calculateFeeAmount(fee, burialSiteContract);
feeAmount = calculateFeeAmount(fee, contract);
taxAmount = calculateTaxAmount(fee, feeAmount);
}
else {
@ -28,29 +28,29 @@ export default async function addBurialSiteContractFee(addFeeForm, user, connect
// Check if record already exists
const record = database
.prepare(`select feeAmount, taxAmount, recordDelete_timeMillis
from BurialSiteContractFees
where burialSiteContractId = ?
from ContractFees
where contractId = ?
and feeId = ?`)
.get(addFeeForm.burialSiteContractId, addFeeForm.feeId);
.get(addFeeForm.contractId, addFeeForm.feeId);
if (record !== undefined) {
if (record.recordDelete_timeMillis !== null) {
database
.prepare(`delete from BurialSiteContractFees
.prepare(`delete from ContractFees
where recordDelete_timeMillis is not null
and burialSiteContractId = ?
and contractId = ?
and feeId = ?`)
.run(addFeeForm.burialSiteContractId, addFeeForm.feeId);
.run(addFeeForm.contractId, addFeeForm.feeId);
}
else if (record.feeAmount === feeAmount &&
record.taxAmount === taxAmount) {
database
.prepare(`update BurialSiteContractFees
.prepare(`update ContractFees
set quantity = quantity + ?,
recordUpdate_userName = ?,
recordUpdate_timeMillis = ?
where burialSiteContractId = ?
where contractId = ?
and feeId = ?`)
.run(addFeeForm.quantity, user.userName, rightNowMillis, addFeeForm.burialSiteContractId, addFeeForm.feeId);
.run(addFeeForm.quantity, user.userName, rightNowMillis, addFeeForm.contractId, addFeeForm.feeId);
return true;
}
else {
@ -58,27 +58,27 @@ export default async function addBurialSiteContractFee(addFeeForm, user, connect
? Number.parseFloat(addFeeForm.quantity)
: addFeeForm.quantity;
database
.prepare(`update BurialSiteContractFees
.prepare(`update ContractFees
set feeAmount = (feeAmount * quantity) + ?,
taxAmount = (taxAmount * quantity) + ?,
quantity = 1,
recordUpdate_userName = ?,
recordUpdate_timeMillis = ?
where burialSiteContractId = ?
where contractId = ?
and feeId = ?`)
.run(feeAmount * quantity, taxAmount * quantity, user.userName, rightNowMillis, addFeeForm.burialSiteContractId, addFeeForm.feeId);
.run(feeAmount * quantity, taxAmount * quantity, user.userName, rightNowMillis, addFeeForm.contractId, addFeeForm.feeId);
return true;
}
}
// Create new record
const result = database
.prepare(`insert into BurialSiteContractFees (
burialSiteContractId, feeId,
.prepare(`insert into ContractFees (
contractId, feeId,
quantity, feeAmount, taxAmount,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
.run(addFeeForm.burialSiteContractId, addFeeForm.feeId, addFeeForm.quantity, feeAmount, taxAmount, user.userName, rightNowMillis, user.userName, rightNowMillis);
.run(addFeeForm.contractId, addFeeForm.feeId, addFeeForm.quantity, feeAmount, taxAmount, user.userName, rightNowMillis, user.userName, rightNowMillis);
return result.changes > 0;
}
finally {

View File

@ -4,22 +4,22 @@ import {
calculateFeeAmount,
calculateTaxAmount
} from '../helpers/functions.fee.js'
import type { BurialSiteContract, Fee } from '../types/recordTypes.js'
import type { Contract, Fee } from '../types/recordTypes.js'
import getBurialSiteContract from './getBurialSiteContract.js'
import getContract from './getContract.js'
import getFee from './getFee.js'
import { acquireConnection } from './pool.js'
export interface AddBurialSiteContractFeeForm {
burialSiteContractId: number | string
export interface AddContractFeeForm {
contractId: number | string
feeId: number | string
quantity: number | string
feeAmount?: number | string
taxAmount?: number | string
}
export default async function addBurialSiteContractFee(
addFeeForm: AddBurialSiteContractFeeForm,
export default async function addContractFee(
addFeeForm: AddContractFeeForm,
user: User,
connectedDatabase?: PoolConnection
): Promise<boolean> {
@ -32,13 +32,13 @@ export default async function addBurialSiteContractFee(
let taxAmount: number
if ((addFeeForm.feeAmount ?? '') === '') {
const burialSiteContract = (await getBurialSiteContract(
addFeeForm.burialSiteContractId
)) as BurialSiteContract
const contract = (await getContract(
addFeeForm.contractId
)) as Contract
const fee = (await getFee(addFeeForm.feeId)) as Fee
feeAmount = calculateFeeAmount(fee, burialSiteContract)
feeAmount = calculateFeeAmount(fee, contract)
taxAmount = calculateTaxAmount(fee, feeAmount)
} else {
feeAmount =
@ -56,11 +56,11 @@ export default async function addBurialSiteContractFee(
const record = database
.prepare(
`select feeAmount, taxAmount, recordDelete_timeMillis
from BurialSiteContractFees
where burialSiteContractId = ?
from ContractFees
where contractId = ?
and feeId = ?`
)
.get(addFeeForm.burialSiteContractId, addFeeForm.feeId) as
.get(addFeeForm.contractId, addFeeForm.feeId) as
| {
feeAmount: number | null
taxAmount: number | null
@ -72,30 +72,30 @@ export default async function addBurialSiteContractFee(
if (record.recordDelete_timeMillis !== null) {
database
.prepare(
`delete from BurialSiteContractFees
`delete from ContractFees
where recordDelete_timeMillis is not null
and burialSiteContractId = ?
and contractId = ?
and feeId = ?`
)
.run(addFeeForm.burialSiteContractId, addFeeForm.feeId)
.run(addFeeForm.contractId, addFeeForm.feeId)
} else if (
record.feeAmount === feeAmount &&
record.taxAmount === taxAmount
) {
database
.prepare(
`update BurialSiteContractFees
`update ContractFees
set quantity = quantity + ?,
recordUpdate_userName = ?,
recordUpdate_timeMillis = ?
where burialSiteContractId = ?
where contractId = ?
and feeId = ?`
)
.run(
addFeeForm.quantity,
user.userName,
rightNowMillis,
addFeeForm.burialSiteContractId,
addFeeForm.contractId,
addFeeForm.feeId
)
@ -108,13 +108,13 @@ export default async function addBurialSiteContractFee(
database
.prepare(
`update BurialSiteContractFees
`update ContractFees
set feeAmount = (feeAmount * quantity) + ?,
taxAmount = (taxAmount * quantity) + ?,
quantity = 1,
recordUpdate_userName = ?,
recordUpdate_timeMillis = ?
where burialSiteContractId = ?
where contractId = ?
and feeId = ?`
)
.run(
@ -122,7 +122,7 @@ export default async function addBurialSiteContractFee(
taxAmount * quantity,
user.userName,
rightNowMillis,
addFeeForm.burialSiteContractId,
addFeeForm.contractId,
addFeeForm.feeId
)
@ -133,15 +133,15 @@ export default async function addBurialSiteContractFee(
// Create new record
const result = database
.prepare(
`insert into BurialSiteContractFees (
burialSiteContractId, feeId,
`insert into ContractFees (
contractId, feeId,
quantity, feeAmount, taxAmount,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?, ?, ?)`
)
.run(
addFeeForm.burialSiteContractId,
addFeeForm.contractId,
addFeeForm.feeId,
addFeeForm.quantity,
feeAmount,

View File

@ -0,0 +1,5 @@
export interface AddContractCategoryForm {
contractId: number | string;
feeCategoryId: number | string;
}
export default function addContractFeeCategory(addFeeCategoryForm: AddContractCategoryForm, user: User): Promise<number>;

View File

@ -1,13 +1,13 @@
import addBurialSiteContractFee from './addBurialSiteContractFee.js';
import addContractFee from './addContractFee.js';
import { getFeeCategory } from './getFeeCategories.js';
import { acquireConnection } from './pool.js';
export default async function addBurialSiteContractFeeCategory(addFeeCategoryForm, user) {
export default async function addContractFeeCategory(addFeeCategoryForm, user) {
const database = await acquireConnection();
const feeCategory = await getFeeCategory(addFeeCategoryForm.feeCategoryId, database);
let addedFeeCount = 0;
for (const fee of feeCategory?.fees ?? []) {
const success = await addBurialSiteContractFee({
burialSiteContractId: addFeeCategoryForm.burialSiteContractId,
const success = await addContractFee({
contractId: addFeeCategoryForm.contractId,
feeId: fee.feeId,
quantity: 1
}, user, database);

View File

@ -1,14 +1,14 @@
import addBurialSiteContractFee from './addBurialSiteContractFee.js'
import addContractFee from './addContractFee.js'
import { getFeeCategory } from './getFeeCategories.js'
import { acquireConnection } from './pool.js'
export interface AddBurialSiteContractCategoryForm {
burialSiteContractId: number | string
export interface AddContractCategoryForm {
contractId: number | string
feeCategoryId: number | string
}
export default async function addBurialSiteContractFeeCategory(
addFeeCategoryForm: AddBurialSiteContractCategoryForm,
export default async function addContractFeeCategory(
addFeeCategoryForm: AddContractCategoryForm,
user: User
): Promise<number> {
const database = await acquireConnection()
@ -21,9 +21,9 @@ export default async function addBurialSiteContractFeeCategory(
let addedFeeCount = 0
for (const fee of feeCategory?.fees ?? []) {
const success = await addBurialSiteContractFee(
const success = await addContractFee(
{
burialSiteContractId: addFeeCategoryForm.burialSiteContractId,
contractId: addFeeCategoryForm.contractId,
feeId: fee.feeId,
quantity: 1
},

View File

@ -1,9 +1,9 @@
export interface AddTransactionForm {
burialSiteContractId: string | number;
contractId: string | number;
transactionDateString?: string;
transactionTimeString?: string;
transactionAmount: string | number;
externalReceiptNumber: string;
transactionNote: string;
}
export default function addBurialSiteContractTransaction(burialSiteContractTransactionForm: AddTransactionForm, user: User): Promise<number>;
export default function addContractTransaction(contractTransactionForm: AddTransactionForm, user: User): Promise<number>;

View File

@ -0,0 +1,34 @@
import { dateStringToInteger, dateToInteger, dateToTimeInteger, timeStringToInteger } from '@cityssm/utils-datetime';
import { acquireConnection } from './pool.js';
export default async function addContractTransaction(contractTransactionForm, user) {
const database = await acquireConnection();
let transactionIndex = 0;
const maxIndexResult = database
.prepare(`select transactionIndex
from ContractTransactions
where contractId = ?
order by transactionIndex desc
limit 1`)
.get(contractTransactionForm.contractId);
if (maxIndexResult !== undefined) {
transactionIndex = maxIndexResult.transactionIndex + 1;
}
const rightNow = new Date();
const transactionDate = contractTransactionForm.transactionDateString
? dateStringToInteger(contractTransactionForm.transactionDateString)
: dateToInteger(rightNow);
const transactionTime = contractTransactionForm.transactionTimeString
? timeStringToInteger(contractTransactionForm.transactionTimeString)
: dateToTimeInteger(rightNow);
database
.prepare(`insert into ContractTransactions (
contractId, transactionIndex,
transactionDate, transactionTime,
transactionAmount, externalReceiptNumber, transactionNote,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
.run(contractTransactionForm.contractId, transactionIndex, transactionDate, transactionTime, contractTransactionForm.transactionAmount, contractTransactionForm.externalReceiptNumber, contractTransactionForm.transactionNote, user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
database.release();
return transactionIndex;
}

View File

@ -8,7 +8,7 @@ import {
import { acquireConnection } from './pool.js'
export interface AddTransactionForm {
burialSiteContractId: string | number
contractId: string | number
transactionDateString?: string
transactionTimeString?: string
transactionAmount: string | number
@ -16,8 +16,8 @@ export interface AddTransactionForm {
transactionNote: string
}
export default async function addBurialSiteContractTransaction(
burialSiteContractTransactionForm: AddTransactionForm,
export default async function addContractTransaction(
contractTransactionForm: AddTransactionForm,
user: User
): Promise<number> {
const database = await acquireConnection()
@ -27,12 +27,12 @@ export default async function addBurialSiteContractTransaction(
const maxIndexResult = database
.prepare(
`select transactionIndex
from BurialSiteContractTransactions
where burialSiteContractId = ?
from ContractTransactions
where contractId = ?
order by transactionIndex desc
limit 1`
)
.get(burialSiteContractTransactionForm.burialSiteContractId) as
.get(contractTransactionForm.contractId) as
| { transactionIndex: number }
| undefined
@ -42,18 +42,18 @@ export default async function addBurialSiteContractTransaction(
const rightNow = new Date()
const transactionDate = burialSiteContractTransactionForm.transactionDateString
? dateStringToInteger(burialSiteContractTransactionForm.transactionDateString)
const transactionDate = contractTransactionForm.transactionDateString
? dateStringToInteger(contractTransactionForm.transactionDateString)
: dateToInteger(rightNow)
const transactionTime = burialSiteContractTransactionForm.transactionTimeString
? timeStringToInteger(burialSiteContractTransactionForm.transactionTimeString)
const transactionTime = contractTransactionForm.transactionTimeString
? timeStringToInteger(contractTransactionForm.transactionTimeString)
: dateToTimeInteger(rightNow)
database
.prepare(
`insert into BurialSiteContractTransactions (
burialSiteContractId, transactionIndex,
`insert into ContractTransactions (
contractId, transactionIndex,
transactionDate, transactionTime,
transactionAmount, externalReceiptNumber, transactionNote,
recordCreate_userName, recordCreate_timeMillis,
@ -61,13 +61,13 @@ export default async function addBurialSiteContractTransaction(
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
)
.run(
burialSiteContractTransactionForm.burialSiteContractId,
contractTransactionForm.contractId,
transactionIndex,
transactionDate,
transactionTime,
burialSiteContractTransactionForm.transactionAmount,
burialSiteContractTransactionForm.externalReceiptNumber,
burialSiteContractTransactionForm.transactionNote,
contractTransactionForm.transactionAmount,
contractTransactionForm.externalReceiptNumber,
contractTransactionForm.transactionNote,
user.userName,
rightNow.getTime(),
user.userName,

View File

@ -1,7 +0,0 @@
import type { PoolConnection } from 'better-sqlite-pool';
export interface BurialSiteContractFieldForm {
burialSiteContractId: string | number;
contractTypeFieldId: string | number;
fieldValue: string;
}
export default function addOrUpdateBurialSiteContractField(fieldForm: BurialSiteContractFieldForm, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;

View File

@ -0,0 +1,7 @@
import type { PoolConnection } from 'better-sqlite-pool';
export interface ContractFieldForm {
contractId: string | number;
contractTypeFieldId: string | number;
fieldValue: string;
}
export default function addOrUpdateContractField(fieldForm: ContractFieldForm, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;

View File

@ -1,25 +1,25 @@
import { acquireConnection } from './pool.js';
export default async function addOrUpdateBurialSiteContractField(fieldForm, user, connectedDatabase) {
export default async function addOrUpdateContractField(fieldForm, user, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection());
const rightNowMillis = Date.now();
let result = database
.prepare(`update BurialSiteContractFields
.prepare(`update ContractFields
set fieldValue = ?,
recordUpdate_userName = ?,
recordUpdate_timeMillis = ?,
recordDelete_userName = null,
recordDelete_timeMillis = null
where burialSiteContractId = ?
where contractId = ?
and contractTypeFieldId = ?`)
.run(fieldForm.fieldValue, user.userName, rightNowMillis, fieldForm.burialSiteContractId, fieldForm.contractTypeFieldId);
.run(fieldForm.fieldValue, user.userName, rightNowMillis, fieldForm.contractId, fieldForm.contractTypeFieldId);
if (result.changes === 0) {
result = database
.prepare(`insert into BurialSiteContractFields (
burialSiteContractId, contractTypeFieldId, fieldValue,
.prepare(`insert into ContractFields (
contractId, contractTypeFieldId, fieldValue,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?)`)
.run(fieldForm.burialSiteContractId, fieldForm.contractTypeFieldId, fieldForm.fieldValue, user.userName, rightNowMillis, user.userName, rightNowMillis);
.run(fieldForm.contractId, fieldForm.contractTypeFieldId, fieldForm.fieldValue, user.userName, rightNowMillis, user.userName, rightNowMillis);
}
if (connectedDatabase === undefined) {
database.release();

View File

@ -2,14 +2,14 @@ import type { PoolConnection } from 'better-sqlite-pool'
import { acquireConnection } from './pool.js'
export interface BurialSiteContractFieldForm {
burialSiteContractId: string | number
export interface ContractFieldForm {
contractId: string | number
contractTypeFieldId: string | number
fieldValue: string
}
export default async function addOrUpdateBurialSiteContractField(
fieldForm: BurialSiteContractFieldForm,
export default async function addOrUpdateContractField(
fieldForm: ContractFieldForm,
user: User,
connectedDatabase?: PoolConnection
): Promise<boolean> {
@ -19,34 +19,34 @@ export default async function addOrUpdateBurialSiteContractField(
let result = database
.prepare(
`update BurialSiteContractFields
`update ContractFields
set fieldValue = ?,
recordUpdate_userName = ?,
recordUpdate_timeMillis = ?,
recordDelete_userName = null,
recordDelete_timeMillis = null
where burialSiteContractId = ?
where contractId = ?
and contractTypeFieldId = ?`
)
.run(
fieldForm.fieldValue,
user.userName,
rightNowMillis,
fieldForm.burialSiteContractId,
fieldForm.contractId,
fieldForm.contractTypeFieldId
)
if (result.changes === 0) {
result = database
.prepare(
`insert into BurialSiteContractFields (
burialSiteContractId, contractTypeFieldId, fieldValue,
`insert into ContractFields (
contractId, contractTypeFieldId, fieldValue,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?)`
)
.run(
fieldForm.burialSiteContractId,
fieldForm.contractId,
fieldForm.contractTypeFieldId,
fieldForm.fieldValue,
user.userName,

View File

@ -4,6 +4,6 @@ export interface AddWorkOrderForm {
workOrderDescription: string;
workOrderOpenDateString?: string;
workOrderCloseDateString?: string;
burialSiteContractId?: string;
contractId?: string;
}
export default function addWorkOrder(workOrderForm: AddWorkOrderForm, user: User): Promise<number>;

View File

@ -1,5 +1,5 @@
import { dateStringToInteger, dateToInteger } from '@cityssm/utils-datetime';
import addWorkOrderBurialSiteContract from './addWorkOrderBurialSiteContract.js';
import addWorkOrderContract from './addWorkOrderContract.js';
import getNextWorkOrderNumber from './getNextWorkOrderNumber.js';
import { acquireConnection } from './pool.js';
export default async function addWorkOrder(workOrderForm, user) {
@ -22,10 +22,10 @@ export default async function addWorkOrder(workOrderForm, user) {
? undefined
: dateStringToInteger(workOrderForm.workOrderCloseDateString), user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
const workOrderId = result.lastInsertRowid;
if ((workOrderForm.burialSiteContractId ?? '') !== '') {
await addWorkOrderBurialSiteContract({
if ((workOrderForm.contractId ?? '') !== '') {
await addWorkOrderContract({
workOrderId,
burialSiteContractId: workOrderForm.burialSiteContractId
contractId: workOrderForm.contractId
}, user, database);
}
database.release();

View File

@ -4,7 +4,7 @@ import {
dateToInteger
} from '@cityssm/utils-datetime'
import addWorkOrderBurialSiteContract from './addWorkOrderBurialSiteContract.js'
import addWorkOrderContract from './addWorkOrderContract.js'
import getNextWorkOrderNumber from './getNextWorkOrderNumber.js'
import { acquireConnection } from './pool.js'
@ -14,7 +14,7 @@ export interface AddWorkOrderForm {
workOrderDescription: string
workOrderOpenDateString?: string
workOrderCloseDateString?: string
burialSiteContractId?: string
contractId?: string
}
export default async function addWorkOrder(
@ -62,11 +62,11 @@ export default async function addWorkOrder(
const workOrderId = result.lastInsertRowid as number
if ((workOrderForm.burialSiteContractId ?? '') !== '') {
await addWorkOrderBurialSiteContract(
if ((workOrderForm.contractId ?? '') !== '') {
await addWorkOrderContract(
{
workOrderId,
burialSiteContractId: workOrderForm.burialSiteContractId as string
contractId: workOrderForm.contractId as string
},
user,
database

View File

@ -1,6 +0,0 @@
import type { PoolConnection } from 'better-sqlite-pool';
export interface AddWorkOrderBurialSiteContractOccupancyForm {
workOrderId: number | string;
burialSiteContractId: number | string;
}
export default function addWorkOrderBurialSiteContract(addForm: AddWorkOrderBurialSiteContractOccupancyForm, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;

View File

@ -0,0 +1,6 @@
import type { PoolConnection } from 'better-sqlite-pool';
export interface AddWorkOrderContractOccupancyForm {
workOrderId: number | string;
contractId: number | string;
}
export default function addWorkOrderContract(addForm: AddWorkOrderContractOccupancyForm, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;

View File

@ -1,27 +1,27 @@
import { acquireConnection } from './pool.js';
export default async function addWorkOrderBurialSiteContract(addForm, user, connectedDatabase) {
export default async function addWorkOrderContract(addForm, user, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection());
const rightNowMillis = Date.now();
const recordDeleteTimeMillis = database
.prepare(`select recordDelete_timeMillis
from WorkOrderBurialSiteContracts
from WorkOrderContracts
where workOrderId = ?
and burialSiteContractId = ?`)
and contractId = ?`)
.pluck()
.get(addForm.workOrderId, addForm.burialSiteContractId);
.get(addForm.workOrderId, addForm.contractId);
if (recordDeleteTimeMillis === undefined) {
database
.prepare(`insert into WorkOrderBurialSiteContracts (
workOrderId, burialSiteContractId,
.prepare(`insert into WorkOrderContracts (
workOrderId, contractId,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?)`)
.run(addForm.workOrderId, addForm.burialSiteContractId, user.userName, rightNowMillis, user.userName, rightNowMillis);
.run(addForm.workOrderId, addForm.contractId, user.userName, rightNowMillis, user.userName, rightNowMillis);
}
else {
if (recordDeleteTimeMillis !== null) {
database
.prepare(`update WorkOrderBurialSiteContracts
.prepare(`update WorkOrderContracts
set recordCreate_userName = ?,
recordCreate_timeMillis = ?,
recordUpdate_userName = ?,
@ -29,8 +29,8 @@ export default async function addWorkOrderBurialSiteContract(addForm, user, conn
recordDelete_userName = null,
recordDelete_timeMillis = null
where workOrderId = ?
and burialSiteContractId = ?`)
.run(user.userName, rightNowMillis, user.userName, rightNowMillis, addForm.workOrderId, addForm.burialSiteContractId);
and contractId = ?`)
.run(user.userName, rightNowMillis, user.userName, rightNowMillis, addForm.workOrderId, addForm.contractId);
}
}
if (connectedDatabase === undefined) {

View File

@ -2,13 +2,13 @@ import type { PoolConnection } from 'better-sqlite-pool'
import { acquireConnection } from './pool.js'
export interface AddWorkOrderBurialSiteContractOccupancyForm {
export interface AddWorkOrderContractOccupancyForm {
workOrderId: number | string
burialSiteContractId: number | string
contractId: number | string
}
export default async function addWorkOrderBurialSiteContract(
addForm: AddWorkOrderBurialSiteContractOccupancyForm,
export default async function addWorkOrderContract(
addForm: AddWorkOrderContractOccupancyForm,
user: User,
connectedDatabase?: PoolConnection
): Promise<boolean> {
@ -19,28 +19,28 @@ export default async function addWorkOrderBurialSiteContract(
const recordDeleteTimeMillis: number | null | undefined = database
.prepare(
`select recordDelete_timeMillis
from WorkOrderBurialSiteContracts
from WorkOrderContracts
where workOrderId = ?
and burialSiteContractId = ?`
and contractId = ?`
)
.pluck()
.get(
addForm.workOrderId,
addForm.burialSiteContractId
addForm.contractId
) as number | null | undefined
if (recordDeleteTimeMillis === undefined) {
database
.prepare(
`insert into WorkOrderBurialSiteContracts (
workOrderId, burialSiteContractId,
`insert into WorkOrderContracts (
workOrderId, contractId,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?)`
)
.run(
addForm.workOrderId,
addForm.burialSiteContractId,
addForm.contractId,
user.userName,
rightNowMillis,
user.userName,
@ -50,7 +50,7 @@ export default async function addWorkOrderBurialSiteContract(
if (recordDeleteTimeMillis !== null) {
database
.prepare(
`update WorkOrderBurialSiteContracts
`update WorkOrderContracts
set recordCreate_userName = ?,
recordCreate_timeMillis = ?,
recordUpdate_userName = ?,
@ -58,7 +58,7 @@ export default async function addWorkOrderBurialSiteContract(
recordDelete_userName = null,
recordDelete_timeMillis = null
where workOrderId = ?
and burialSiteContractId = ?`
and contractId = ?`
)
.run(
user.userName,
@ -66,7 +66,7 @@ export default async function addWorkOrderBurialSiteContract(
user.userName,
rightNowMillis,
addForm.workOrderId,
addForm.burialSiteContractId
addForm.contractId
)
}
}

View File

@ -26,7 +26,7 @@ export default async function cleanupDatabase(user) {
* Work Order Burial Site Contracts
*/
inactivatedRecordCount += database
.prepare(`update WorkOrderBurialSiteContracts
.prepare(`update WorkOrderContracts
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where recordDelete_timeMillis is null
@ -34,7 +34,7 @@ export default async function cleanupDatabase(user) {
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`)
.run(user.userName, rightNowMillis).changes;
purgedRecordCount += database
.prepare('delete from WorkOrderBurialSiteContracts where recordDelete_timeMillis <= ?')
.prepare('delete from WorkOrderContracts where recordDelete_timeMillis <= ?')
.run(recordDeleteTimeMillisMin).changes;
/*
* Work Order Burial Sites
@ -71,7 +71,7 @@ export default async function cleanupDatabase(user) {
.prepare(`delete from WorkOrders
where recordDelete_timeMillis <= ?
and workOrderId not in (select workOrderId from WorkOrderComments)
and workOrderId not in (select workOrderId from WorkOrderBurialSiteContracts)
and workOrderId not in (select workOrderId from WorkOrderContracts)
and workOrderId not in (select workOrderId from WorkOrderBurialSites)
and workOrderId not in (select workOrderId from WorkOrderMilestones)`)
.run(recordDeleteTimeMillisMin).changes;
@ -96,51 +96,51 @@ export default async function cleanupDatabase(user) {
* Burial Site Contract Comments
*/
inactivatedRecordCount += database
.prepare(`update BurialSiteContractComments
.prepare(`update ContractComments
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where recordDelete_timeMillis is null
and burialSiteContractId in (
select burialSiteContractId from BurialSiteContracts where recordDelete_timeMillis is not null)`)
and contractId in (
select contractId from Contracts where recordDelete_timeMillis is not null)`)
.run(user.userName, rightNowMillis).changes;
purgedRecordCount += database
.prepare('delete from BurialSiteContractComments where recordDelete_timeMillis <= ?')
.prepare('delete from ContractComments where recordDelete_timeMillis <= ?')
.run(recordDeleteTimeMillisMin).changes;
/*
* Burial Site Contract Fields
*/
inactivatedRecordCount += database
.prepare(`update BurialSiteContractFields
.prepare(`update ContractFields
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where recordDelete_timeMillis is null
and burialSiteContractId in (select burialSiteContractId from BurialSiteContracts where recordDelete_timeMillis is not null)`)
and contractId in (select contractId from Contracts where recordDelete_timeMillis is not null)`)
.run(user.userName, rightNowMillis).changes;
purgedRecordCount += database
.prepare('delete from BurialSiteContractFields where recordDelete_timeMillis <= ?')
.prepare('delete from ContractFields where recordDelete_timeMillis <= ?')
.run(recordDeleteTimeMillisMin).changes;
/*
* Burial Site Contract Fees/Transactions
* - Maintain financials, do not delete related.
*/
purgedRecordCount += database
.prepare('delete from BurialSiteContractFees where recordDelete_timeMillis <= ?')
.prepare('delete from ContractFees where recordDelete_timeMillis <= ?')
.run(recordDeleteTimeMillisMin).changes;
purgedRecordCount += database
.prepare('delete from BurialSiteContractTransactions where recordDelete_timeMillis <= ?')
.prepare('delete from ContractTransactions where recordDelete_timeMillis <= ?')
.run(recordDeleteTimeMillisMin).changes;
/*
* Burial Site Contracts
*/
purgedRecordCount += database
.prepare(`delete from BurialSiteContracts
.prepare(`delete from Contracts
where recordDelete_timeMillis <= ?
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractComments)
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractFees)
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractFields)
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractInterments)
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractTransactions)
and burialSiteContractId not in (select burialSiteContractId from WorkOrderBurialSiteContracts)`)
and contractId not in (select contractId from ContractComments)
and contractId not in (select contractId from ContractFees)
and contractId not in (select contractId from ContractFields)
and contractId not in (select contractId from ContractInterments)
and contractId not in (select contractId from ContractTransactions)
and contractId not in (select contractId from WorkOrderContracts)`)
.run(recordDeleteTimeMillisMin).changes;
/*
* Fees
@ -155,7 +155,7 @@ export default async function cleanupDatabase(user) {
purgedRecordCount += database
.prepare(`delete from Fees
where recordDelete_timeMillis <= ?
and feeId not in (select feeId from BurialSiteContractFees)`)
and feeId not in (select feeId from ContractFees)`)
.run(recordDeleteTimeMillisMin).changes;
/*
* Fee Categories
@ -178,7 +178,7 @@ export default async function cleanupDatabase(user) {
purgedRecordCount += database
.prepare(`delete from ContractTypeFields
where recordDelete_timeMillis <= ?
and contractTypeFieldId not in (select contractTypeFieldId from BurialSiteContractFields)`)
and contractTypeFieldId not in (select contractTypeFieldId from ContractFields)`)
.run(recordDeleteTimeMillisMin).changes;
/*
* Occupancy Type Prints
@ -201,7 +201,7 @@ export default async function cleanupDatabase(user) {
where recordDelete_timeMillis <= ?
and contractTypeId not in (select contractTypeId from ContractTypeFields)
and contractTypeId not in (select contractTypeId from ContractTypePrints)
and contractTypeId not in (select contractTypeId from BurialSiteContracts)
and contractTypeId not in (select contractTypeId from Contracts)
and contractTypeId not in (select contractTypeId from Fees)`)
.run(recordDeleteTimeMillisMin).changes;
/*
@ -245,7 +245,7 @@ export default async function cleanupDatabase(user) {
where recordDelete_timeMillis <= ?
and burialSiteId not in (select burialSiteId from BurialSiteComments)
and burialSiteId not in (select burialSiteId from BurialSiteFields)
and burialSiteId not in (select burialSiteId from BurialSiteContracts)
and burialSiteId not in (select burialSiteId from Contracts)
and burialSiteId not in (select burialSiteId from WorkOrderLots)`)
.run(recordDeleteTimeMillisMin).changes;
/*

View File

@ -42,7 +42,7 @@ export default async function cleanupDatabase(
inactivatedRecordCount += database
.prepare(
`update WorkOrderBurialSiteContracts
`update WorkOrderContracts
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where recordDelete_timeMillis is null
@ -53,7 +53,7 @@ export default async function cleanupDatabase(
purgedRecordCount += database
.prepare(
'delete from WorkOrderBurialSiteContracts where recordDelete_timeMillis <= ?'
'delete from WorkOrderContracts where recordDelete_timeMillis <= ?'
)
.run(recordDeleteTimeMillisMin).changes
@ -108,7 +108,7 @@ export default async function cleanupDatabase(
`delete from WorkOrders
where recordDelete_timeMillis <= ?
and workOrderId not in (select workOrderId from WorkOrderComments)
and workOrderId not in (select workOrderId from WorkOrderBurialSiteContracts)
and workOrderId not in (select workOrderId from WorkOrderContracts)
and workOrderId not in (select workOrderId from WorkOrderBurialSites)
and workOrderId not in (select workOrderId from WorkOrderMilestones)`
)
@ -145,18 +145,18 @@ export default async function cleanupDatabase(
inactivatedRecordCount += database
.prepare(
`update BurialSiteContractComments
`update ContractComments
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where recordDelete_timeMillis is null
and burialSiteContractId in (
select burialSiteContractId from BurialSiteContracts where recordDelete_timeMillis is not null)`
and contractId in (
select contractId from Contracts where recordDelete_timeMillis is not null)`
)
.run(user.userName, rightNowMillis).changes
purgedRecordCount += database
.prepare(
'delete from BurialSiteContractComments where recordDelete_timeMillis <= ?'
'delete from ContractComments where recordDelete_timeMillis <= ?'
)
.run(recordDeleteTimeMillisMin).changes
@ -166,17 +166,17 @@ export default async function cleanupDatabase(
inactivatedRecordCount += database
.prepare(
`update BurialSiteContractFields
`update ContractFields
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where recordDelete_timeMillis is null
and burialSiteContractId in (select burialSiteContractId from BurialSiteContracts where recordDelete_timeMillis is not null)`
and contractId in (select contractId from Contracts where recordDelete_timeMillis is not null)`
)
.run(user.userName, rightNowMillis).changes
purgedRecordCount += database
.prepare(
'delete from BurialSiteContractFields where recordDelete_timeMillis <= ?'
'delete from ContractFields where recordDelete_timeMillis <= ?'
)
.run(recordDeleteTimeMillisMin).changes
@ -187,13 +187,13 @@ export default async function cleanupDatabase(
purgedRecordCount += database
.prepare(
'delete from BurialSiteContractFees where recordDelete_timeMillis <= ?'
'delete from ContractFees where recordDelete_timeMillis <= ?'
)
.run(recordDeleteTimeMillisMin).changes
purgedRecordCount += database
.prepare(
'delete from BurialSiteContractTransactions where recordDelete_timeMillis <= ?'
'delete from ContractTransactions where recordDelete_timeMillis <= ?'
)
.run(recordDeleteTimeMillisMin).changes
@ -203,14 +203,14 @@ export default async function cleanupDatabase(
purgedRecordCount += database
.prepare(
`delete from BurialSiteContracts
`delete from Contracts
where recordDelete_timeMillis <= ?
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractComments)
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractFees)
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractFields)
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractInterments)
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractTransactions)
and burialSiteContractId not in (select burialSiteContractId from WorkOrderBurialSiteContracts)`
and contractId not in (select contractId from ContractComments)
and contractId not in (select contractId from ContractFees)
and contractId not in (select contractId from ContractFields)
and contractId not in (select contractId from ContractInterments)
and contractId not in (select contractId from ContractTransactions)
and contractId not in (select contractId from WorkOrderContracts)`
)
.run(recordDeleteTimeMillisMin).changes
@ -232,7 +232,7 @@ export default async function cleanupDatabase(
.prepare(
`delete from Fees
where recordDelete_timeMillis <= ?
and feeId not in (select feeId from BurialSiteContractFees)`
and feeId not in (select feeId from ContractFees)`
)
.run(recordDeleteTimeMillisMin).changes
@ -266,7 +266,7 @@ export default async function cleanupDatabase(
.prepare(
`delete from ContractTypeFields
where recordDelete_timeMillis <= ?
and contractTypeFieldId not in (select contractTypeFieldId from BurialSiteContractFields)`
and contractTypeFieldId not in (select contractTypeFieldId from ContractFields)`
)
.run(recordDeleteTimeMillisMin).changes
@ -300,7 +300,7 @@ export default async function cleanupDatabase(
where recordDelete_timeMillis <= ?
and contractTypeId not in (select contractTypeId from ContractTypeFields)
and contractTypeId not in (select contractTypeId from ContractTypePrints)
and contractTypeId not in (select contractTypeId from BurialSiteContracts)
and contractTypeId not in (select contractTypeId from Contracts)
and contractTypeId not in (select contractTypeId from Fees)`
)
.run(recordDeleteTimeMillisMin).changes
@ -363,7 +363,7 @@ export default async function cleanupDatabase(
where recordDelete_timeMillis <= ?
and burialSiteId not in (select burialSiteId from BurialSiteComments)
and burialSiteId not in (select burialSiteId from BurialSiteFields)
and burialSiteId not in (select burialSiteId from BurialSiteContracts)
and burialSiteId not in (select burialSiteId from Contracts)
and burialSiteId not in (select burialSiteId from WorkOrderLots)`
)
.run(recordDeleteTimeMillisMin).changes

View File

@ -1 +0,0 @@
export default function copyBurialSiteContract(oldBurialSiteContractId: number | string, user: User): Promise<number>;

View File

@ -1,62 +0,0 @@
import { dateToString } from '@cityssm/utils-datetime';
import addBurialSiteContract from './addBurialSiteContract.js';
import addBurialSiteContractComment from './addBurialSiteContractComment.js';
// import addBurialSiteContractOccupant from './addBurialSiteContractOccupant.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.burialSiteContractOccupants ?? []) {
await addBurialSiteContractOccupant(
{
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
database/copyContract.d.ts vendored 100644
View File

@ -0,0 +1 @@
export default function copyContract(oldContractId: number | string, user: User): Promise<number>;

View File

@ -0,0 +1,62 @@
import { dateToString } from '@cityssm/utils-datetime';
import addContract from './addContract.js';
import addContractComment from './addContractComment.js';
// import addContractOccupant from './addContractOccupant.js'
import getContract from './getContract.js';
import { acquireConnection } from './pool.js';
export default async function copyContract(oldContractId, user) {
const database = await acquireConnection();
const oldContract = (await getContract(oldContractId, database));
const newContractId = await addContract({
burialSiteId: oldContract.burialSiteId ?? '',
contractTypeId: oldContract.contractTypeId,
contractStartDateString: dateToString(new Date()),
contractEndDateString: ''
}, user, database);
/*
* Copy Fields
*/
const rightNowMillis = Date.now();
for (const field of oldContract.contractFields ?? []) {
database
.prepare(`insert into ContractFields (
contractId, contractTypeFieldId, fieldValue,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?)`)
.run(newContractId, field.contractTypeFieldId, field.fieldValue, user.userName, rightNowMillis, user.userName, rightNowMillis);
}
/*
* Copy Occupants
*/
/*
for (const occupant of oldContract.contractOccupants ?? []) {
await addContractOccupant(
{
contractId: newContractId,
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 addContractComment({
contractId: newContractId,
comment: `New record copied from #${oldContractId}.`
}, user);
database.release();
return newContractId;
}

View File

@ -1,25 +1,28 @@
import { dateToString } from '@cityssm/utils-datetime'
import type { BurialSiteContract } from '../types/recordTypes.js'
import type { Contract } from '../types/recordTypes.js'
import addBurialSiteContract from './addBurialSiteContract.js'
import addBurialSiteContractComment from './addBurialSiteContractComment.js'
// import addBurialSiteContractOccupant from './addBurialSiteContractOccupant.js'
import getBurialSiteContract from './getBurialSiteContract.js'
import addContract from './addContract.js'
import addContractComment from './addContractComment.js'
// import addContractOccupant from './addContractOccupant.js'
import getContract from './getContract.js'
import { acquireConnection } from './pool.js'
export default async function copyBurialSiteContract(
oldBurialSiteContractId: number | string,
export default async function copyContract(
oldContractId: number | string,
user: User
): Promise<number> {
const database = await acquireConnection()
const oldBurialSiteContract = await getBurialSiteContract(oldBurialSiteContractId, database) as BurialSiteContract
const oldContract = (await getContract(
oldContractId,
database
)) as Contract
const newBurialSiteContractId = await addBurialSiteContract(
const newContractId = await addContract(
{
burialSiteId: oldBurialSiteContract.burialSiteId ?? '',
contractTypeId: oldBurialSiteContract.contractTypeId,
burialSiteId: oldContract.burialSiteId ?? '',
contractTypeId: oldContract.contractTypeId,
contractStartDateString: dateToString(new Date()),
contractEndDateString: ''
},
@ -33,17 +36,17 @@ export default async function copyBurialSiteContract(
const rightNowMillis = Date.now()
for (const field of oldBurialSiteContract.burialSiteContractFields ?? []) {
for (const field of oldContract.contractFields ?? []) {
database
.prepare(
`insert into BurialSiteContractFields (
burialSiteContractId, contractTypeFieldId, fieldValue,
`insert into ContractFields (
contractId, contractTypeFieldId, fieldValue,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?)`
)
.run(
newBurialSiteContractId,
newContractId,
field.contractTypeFieldId,
field.fieldValue,
user.userName,
@ -58,10 +61,10 @@ export default async function copyBurialSiteContract(
*/
/*
for (const occupant of oldBurialSiteContract.burialSiteContractOccupants ?? []) {
await addBurialSiteContractOccupant(
for (const occupant of oldContract.contractOccupants ?? []) {
await addContractOccupant(
{
burialSiteContractId: newBurialSiteContractId,
contractId: newContractId,
lotOccupantTypeId: occupant.lotOccupantTypeId!,
occupantName: occupant.occupantName!,
occupantFamilyName: occupant.occupantFamilyName!,
@ -83,12 +86,15 @@ export default async function copyBurialSiteContract(
* Add Comment
*/
await addBurialSiteContractComment({
burialSiteContractId: newBurialSiteContractId,
comment: `New record copied from #${oldBurialSiteContractId}.`
}, user)
await addContractComment(
{
contractId: newContractId,
comment: `New record copied from #${oldContractId}.`
},
user
)
database.release()
return newBurialSiteContractId
return newContractId
}

View File

@ -1 +0,0 @@
export default function deleteBurialSiteContractFee(burialSiteContractId: number | string, feeId: number | string, user: User): Promise<boolean>;

View File

@ -1,2 +0,0 @@
import type { PoolConnection } from 'better-sqlite-pool';
export default function deleteBurialSiteContractField(burialSiteContractId: number | string, contractTypeFieldId: number | string, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;

View File

@ -1 +0,0 @@
export default function deleteBurialSiteContractInterment(burialSiteContractId: number | string, intermentNumber: number | string, user: User): Promise<boolean>;

View File

@ -1 +0,0 @@
export default function deleteBurialSiteContractTransaction(burialSiteContractId: number | string, transactionIndex: number | string, user: User): Promise<boolean>;

View File

@ -0,0 +1 @@
export default function deleteContractFee(contractId: number | string, feeId: number | string, user: User): Promise<boolean>;

View File

@ -1,13 +1,13 @@
import { acquireConnection } from './pool.js';
export default async function deleteBurialSiteContractFee(burialSiteContractId, feeId, user) {
export default async function deleteContractFee(contractId, feeId, user) {
const database = await acquireConnection();
const result = database
.prepare(`update BurialSteContractFees
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where burialSiteContractId = ?
where contractId = ?
and feeId = ?`)
.run(user.userName, Date.now(), burialSiteContractId, feeId);
.run(user.userName, Date.now(), contractId, feeId);
database.release();
return result.changes > 0;
}

View File

@ -1,7 +1,7 @@
import { acquireConnection } from './pool.js'
export default async function deleteBurialSiteContractFee(
burialSiteContractId: number | string,
export default async function deleteContractFee(
contractId: number | string,
feeId: number | string,
user: User
): Promise<boolean> {
@ -12,10 +12,10 @@ export default async function deleteBurialSiteContractFee(
`update BurialSteContractFees
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where burialSiteContractId = ?
where contractId = ?
and feeId = ?`
)
.run(user.userName, Date.now(), burialSiteContractId, feeId)
.run(user.userName, Date.now(), contractId, feeId)
database.release()

View File

@ -0,0 +1,2 @@
import type { PoolConnection } from 'better-sqlite-pool';
export default function deleteContractField(contractId: number | string, contractTypeFieldId: number | string, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;

View File

@ -1,13 +1,13 @@
import { acquireConnection } from './pool.js';
export default async function deleteBurialSiteContractField(burialSiteContractId, contractTypeFieldId, user, connectedDatabase) {
export default async function deleteContractField(contractId, contractTypeFieldId, user, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection());
const result = database
.prepare(`update BurialSiteContractFields
.prepare(`update ContractFields
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where burialSiteContractId = ?
where contractId = ?
and contractTypeFieldId = ?`)
.run(user.userName, Date.now(), burialSiteContractId, contractTypeFieldId);
.run(user.userName, Date.now(), contractId, contractTypeFieldId);
if (connectedDatabase === undefined) {
database.release();
}

View File

@ -2,8 +2,8 @@ import type { PoolConnection } from 'better-sqlite-pool'
import { acquireConnection } from './pool.js'
export default async function deleteBurialSiteContractField(
burialSiteContractId: number | string,
export default async function deleteContractField(
contractId: number | string,
contractTypeFieldId: number | string,
user: User,
connectedDatabase?: PoolConnection
@ -12,13 +12,13 @@ export default async function deleteBurialSiteContractField(
const result = database
.prepare(
`update BurialSiteContractFields
`update ContractFields
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where burialSiteContractId = ?
where contractId = ?
and contractTypeFieldId = ?`
)
.run(user.userName, Date.now(), burialSiteContractId, contractTypeFieldId)
.run(user.userName, Date.now(), contractId, contractTypeFieldId)
if (connectedDatabase === undefined) {
database.release()

View File

@ -0,0 +1 @@
export default function deleteContractInterment(contractId: number | string, intermentNumber: number | string, user: User): Promise<boolean>;

View File

@ -1,13 +1,13 @@
import { acquireConnection } from './pool.js';
export default async function deleteBurialSiteContractInterment(burialSiteContractId, intermentNumber, user) {
export default async function deleteContractInterment(contractId, intermentNumber, user) {
const database = await acquireConnection();
const result = database
.prepare(`update BurialSiteContractInterments
.prepare(`update ContractInterments
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where burialSiteContractId = ?
where contractId = ?
and intermentNumber = ?`)
.run(user.userName, Date.now(), burialSiteContractId, intermentNumber);
.run(user.userName, Date.now(), contractId, intermentNumber);
database.release();
return result.changes > 0;
}

View File

@ -1,7 +1,7 @@
import { acquireConnection } from './pool.js'
export default async function deleteBurialSiteContractInterment(
burialSiteContractId: number | string,
export default async function deleteContractInterment(
contractId: number | string,
intermentNumber: number | string,
user: User
): Promise<boolean> {
@ -9,13 +9,13 @@ export default async function deleteBurialSiteContractInterment(
const result = database
.prepare(
`update BurialSiteContractInterments
`update ContractInterments
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where burialSiteContractId = ?
where contractId = ?
and intermentNumber = ?`
)
.run(user.userName, Date.now(), burialSiteContractId, intermentNumber)
.run(user.userName, Date.now(), contractId, intermentNumber)
database.release()

View File

@ -0,0 +1 @@
export default function deleteContractTransaction(contractId: number | string, transactionIndex: number | string, user: User): Promise<boolean>;

View File

@ -1,13 +1,13 @@
import { acquireConnection } from './pool.js';
export default async function deleteBurialSiteContractTransaction(burialSiteContractId, transactionIndex, user) {
export default async function deleteContractTransaction(contractId, transactionIndex, user) {
const database = await acquireConnection();
const result = database
.prepare(`update BurialSiteContractTransactions
.prepare(`update ContractTransactions
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where burialSiteContractId = ?
where contractId = ?
and transactionIndex = ?`)
.run(user.userName, Date.now(), burialSiteContractId, transactionIndex);
.run(user.userName, Date.now(), contractId, transactionIndex);
database.release();
return result.changes > 0;
}

View File

@ -1,7 +1,7 @@
import { acquireConnection } from './pool.js'
export default async function deleteBurialSiteContractTransaction(
burialSiteContractId: number | string,
export default async function deleteContractTransaction(
contractId: number | string,
transactionIndex: number | string,
user: User
): Promise<boolean> {
@ -9,13 +9,13 @@ export default async function deleteBurialSiteContractTransaction(
const result = database
.prepare(
`update BurialSiteContractTransactions
`update ContractTransactions
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where burialSiteContractId = ?
where contractId = ?
and transactionIndex = ?`
)
.run(user.userName, Date.now(), burialSiteContractId, transactionIndex)
.run(user.userName, Date.now(), contractId, transactionIndex)
database.release()

View File

@ -1,3 +1,3 @@
type RecordTable = 'FeeCategories' | 'Fees' | 'BurialSites' | 'BurialSiteComments' | 'BurialSiteContracts' | 'BurialSiteContractComments' | 'BurialSiteStatuses' | 'BurialSiteTypes' | 'BurialSiteTypeFields' | 'Cemeteries' | 'ContractTypes' | 'ContractTypeFields' | 'WorkOrders' | 'WorkOrderComments' | 'WorkOrderMilestones' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes';
type RecordTable = 'FeeCategories' | 'Fees' | 'BurialSites' | 'BurialSiteComments' | 'Contracts' | 'ContractComments' | 'BurialSiteStatuses' | 'BurialSiteTypes' | 'BurialSiteTypeFields' | 'Cemeteries' | 'ContractTypes' | 'ContractTypeFields' | 'WorkOrders' | 'WorkOrderComments' | 'WorkOrderMilestones' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes';
export declare function deleteRecord(recordTable: RecordTable, recordId: number | string, user: User): Promise<boolean>;
export {};

View File

@ -5,8 +5,8 @@ recordIdColumns.set('FeeCategories', 'feeCategoryId');
recordIdColumns.set('Fees', 'feeId');
recordIdColumns.set('BurialSites', 'burialSiteId');
recordIdColumns.set('BurialSiteComments', 'burialSiteCommentId');
recordIdColumns.set('BurialSiteContracts', 'burialSiteContractId');
recordIdColumns.set('BurialSiteContractComments', 'burialSiteContractCommentId');
recordIdColumns.set('Contracts', 'contractId');
recordIdColumns.set('ContractComments', 'contractCommentId');
recordIdColumns.set('BurialSiteStatuses', 'burialSiteStatusId');
recordIdColumns.set('BurialSiteTypes', 'burialSiteTypeId');
recordIdColumns.set('BurialSiteTypeFields', 'burialSiteFieldTypeId');
@ -21,9 +21,9 @@ recordIdColumns.set('WorkOrderTypes', 'workOrderTypeId');
const relatedTables = new Map();
relatedTables.set('FeeCategories', ['Fees']);
relatedTables.set('BurialSites', ['BurialSiteFields', 'BurialSiteComments']);
relatedTables.set('BurialSiteContracts', [
'BurialSiteContractFields',
'BurialSiteContractComments'
relatedTables.set('Contracts', [
'ContractFields',
'ContractComments'
]);
relatedTables.set('BurialSiteTypes', ['BurialSiteTypeFields']);
relatedTables.set('Cemeteries', ['BurialSites']);
@ -31,7 +31,7 @@ relatedTables.set('ContractTypes', ['ContractTypePrints', 'ContractTypeFields'])
relatedTables.set('WorkOrders', [
'WorkOrderMilestones',
'WorkOrderLots',
'WorkOrderBurialSiteContracts',
'WorkOrderContracts',
'WorkOrderComments'
]);
export async function deleteRecord(recordTable, recordId, user) {

View File

@ -7,8 +7,8 @@ type RecordTable =
| 'Fees'
| 'BurialSites'
| 'BurialSiteComments'
| 'BurialSiteContracts'
| 'BurialSiteContractComments'
| 'Contracts'
| 'ContractComments'
| 'BurialSiteStatuses'
| 'BurialSiteTypes'
| 'BurialSiteTypeFields'
@ -26,8 +26,8 @@ recordIdColumns.set('FeeCategories', 'feeCategoryId')
recordIdColumns.set('Fees', 'feeId')
recordIdColumns.set('BurialSites', 'burialSiteId')
recordIdColumns.set('BurialSiteComments', 'burialSiteCommentId')
recordIdColumns.set('BurialSiteContracts', 'burialSiteContractId')
recordIdColumns.set('BurialSiteContractComments', 'burialSiteContractCommentId')
recordIdColumns.set('Contracts', 'contractId')
recordIdColumns.set('ContractComments', 'contractCommentId')
recordIdColumns.set('BurialSiteStatuses', 'burialSiteStatusId')
recordIdColumns.set('BurialSiteTypes', 'burialSiteTypeId')
recordIdColumns.set('BurialSiteTypeFields', 'burialSiteFieldTypeId')
@ -43,9 +43,9 @@ recordIdColumns.set('WorkOrderTypes', 'workOrderTypeId')
const relatedTables = new Map<RecordTable, string[]>()
relatedTables.set('FeeCategories', ['Fees'])
relatedTables.set('BurialSites', ['BurialSiteFields', 'BurialSiteComments'])
relatedTables.set('BurialSiteContracts', [
'BurialSiteContractFields',
'BurialSiteContractComments'
relatedTables.set('Contracts', [
'ContractFields',
'ContractComments'
])
relatedTables.set('BurialSiteTypes', ['BurialSiteTypeFields'])
relatedTables.set('Cemeteries', ['BurialSites'])
@ -53,7 +53,7 @@ relatedTables.set('ContractTypes', ['ContractTypePrints', 'ContractTypeFields'])
relatedTables.set('WorkOrders', [
'WorkOrderMilestones',
'WorkOrderLots',
'WorkOrderBurialSiteContracts',
'WorkOrderContracts',
'WorkOrderComments'
])

View File

@ -1 +0,0 @@
export default function deleteWorkOrderBurialSiteContract(workOrderId: number | string, burialSiteContractId: number | string, user: User): Promise<boolean>;

View File

@ -0,0 +1 @@
export default function deleteWorkOrderContract(workOrderId: number | string, contractId: number | string, user: User): Promise<boolean>;

View File

@ -1,13 +1,13 @@
import { acquireConnection } from './pool.js';
export default async function deleteWorkOrderBurialSiteContract(workOrderId, burialSiteContractId, user) {
export default async function deleteWorkOrderContract(workOrderId, contractId, user) {
const database = await acquireConnection();
const result = database
.prepare(`update WorkOrderBurialSiteContracts
.prepare(`update WorkOrderContracts
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where workOrderId = ?
and burialSiteContractId = ?`)
.run(user.userName, Date.now(), workOrderId, burialSiteContractId);
and contractId = ?`)
.run(user.userName, Date.now(), workOrderId, contractId);
database.release();
return result.changes > 0;
}

View File

@ -1,21 +1,21 @@
import { acquireConnection } from './pool.js'
export default async function deleteWorkOrderBurialSiteContract(
export default async function deleteWorkOrderContract(
workOrderId: number | string,
burialSiteContractId: number | string,
contractId: number | string,
user: User
): Promise<boolean> {
const database = await acquireConnection()
const result = database
.prepare(
`update WorkOrderBurialSiteContracts
`update WorkOrderContracts
set recordDelete_userName = ?,
recordDelete_timeMillis = ?
where workOrderId = ?
and burialSiteContractId = ?`
and contractId = ?`
)
.run(user.userName, Date.now(), workOrderId, burialSiteContractId)
.run(user.userName, Date.now(), workOrderId, contractId)
database.release()

View File

@ -1,5 +1,5 @@
import getBurialSiteComments from './getBurialSiteComments.js';
import getBurialSiteInterments from './getBurialSiteContracts.js';
import getBurialSiteInterments from './getContracts.js';
import getBurialSiteFields from './getBurialSiteFields.js';
import { acquireConnection } from './pool.js';
const baseSQL = `select l.burialSiteId,
@ -24,7 +24,7 @@ async function _getBurialSite(sql, burialSiteIdOrLotName) {
const database = await acquireConnection();
const burialSite = database.prepare(sql).get(burialSiteIdOrLotName);
if (burialSite !== undefined) {
const burialSiteContracts = await getBurialSiteInterments({
const contracts = await getBurialSiteInterments({
burialSiteId: burialSite.burialSiteId
}, {
includeInterments: true,
@ -33,7 +33,7 @@ async function _getBurialSite(sql, burialSiteIdOrLotName) {
limit: -1,
offset: 0
}, database);
burialSite.burialSiteContracts = burialSiteContracts.burialSiteContracts;
burialSite.contracts = contracts.contracts;
burialSite.burialSiteFields = await getBurialSiteFields(burialSite.burialSiteId, database);
burialSite.burialSiteComments = await getBurialSiteComments(burialSite.burialSiteId, database);
}

View File

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

View File

@ -1,3 +0,0 @@
import type { PoolConnection } from 'better-sqlite-pool';
import type { BurialSiteContract } from '../types/recordTypes.js';
export default function getBurialSiteContract(burialSiteContractId: number | string, connectedDatabase?: PoolConnection): Promise<BurialSiteContract | undefined>;

View File

@ -1,3 +0,0 @@
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[]>;

View File

@ -1,3 +0,0 @@
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[]>;

View File

@ -1,3 +0,0 @@
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[]>;

View File

@ -1,3 +0,0 @@
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[]>;

View File

@ -1,5 +0,0 @@
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[]>;

View File

@ -13,7 +13,7 @@ export interface GetBurialSitesOptions {
/** -1 for no limit */
limit: number;
offset: string | number;
includeBurialSiteContractCount?: boolean;
includeContractCount?: boolean;
}
export default function getBurialSites(filters: GetBurialSitesFilters, options: GetBurialSitesOptions, connectedDatabase?: PoolConnection): Promise<{
count: number;

View File

@ -21,11 +21,11 @@ function buildWhereClause(filters) {
}
if ((filters.contractStatus ?? '') !== '') {
if (filters.contractStatus === 'occupied') {
sqlWhereClause += ' and burialSiteContractCount > 0';
sqlWhereClause += ' and contractCount > 0';
}
else if (filters.contractStatus === 'unoccupied') {
sqlWhereClause +=
' and (burialSiteContractCount is null or burialSiteContractCount = 0)';
' and (contractCount is null or contractCount = 0)';
}
}
if ((filters.workOrderId ?? '') !== '') {
@ -48,7 +48,7 @@ export default async function getBurialSites(filters, options, connectedDatabase
.prepare(`select count(*) as recordCount
from BurialSites l
left join (
select burialSiteId, count(burialSiteContractId) as burialSiteContractCount from BurialSiteContracts
select burialSiteId, count(contractId) as contractCount from Contracts
where recordDelete_timeMillis is null
and contractStartDate <= ${currentDate.toString()}
and (contractEndDate is null or contractEndDate >= ${currentDate.toString()})
@ -59,8 +59,8 @@ export default async function getBurialSites(filters, options, connectedDatabase
}
let burialSites = [];
if (options.limit === -1 || count > 0) {
const includeBurialSiteContractCount = options.includeBurialSiteContractCount ?? true;
if (includeBurialSiteContractCount) {
const includeContractCount = options.includeContractCount ?? true;
if (includeContractCount) {
sqlParameters.unshift(currentDate, currentDate);
}
burialSites = database
@ -74,17 +74,17 @@ export default async function getBurialSites(filters, options, connectedDatabase
t.burialSiteType,
l.cemeteryId, m.cemeteryName, l.cemeterySvgId,
l.burialSiteStatusId, s.burialSiteStatus
${includeBurialSiteContractCount
? ', ifnull(o.burialSiteContractCount, 0) as burialSiteContractCount'
${includeContractCount
? ', ifnull(o.contractCount, 0) as contractCount'
: ''}
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
${includeContractCount
? `left join (
select burialSiteId, count(burialSiteContractId) as burialSiteContractCount
from BurialSiteContracts
select burialSiteId, count(contractId) as contractCount
from Contracts
where recordDelete_timeMillis is null
and contractStartDate <= ?
and (contractEndDate is null or contractEndDate >= ?)

View File

@ -20,7 +20,7 @@ export interface GetBurialSitesOptions {
/** -1 for no limit */
limit: number
offset: string | number
includeBurialSiteContractCount?: boolean
includeContractCount?: boolean
}
function buildWhereClause(filters: GetBurialSitesFilters): {
@ -55,10 +55,10 @@ function buildWhereClause(filters: GetBurialSitesFilters): {
if ((filters.contractStatus ?? '') !== '') {
if (filters.contractStatus === 'occupied') {
sqlWhereClause += ' and burialSiteContractCount > 0'
sqlWhereClause += ' and contractCount > 0'
} else if (filters.contractStatus === 'unoccupied') {
sqlWhereClause +=
' and (burialSiteContractCount is null or burialSiteContractCount = 0)'
' and (contractCount is null or contractCount = 0)'
}
}
@ -94,7 +94,7 @@ export default async function getBurialSites(
`select count(*) as recordCount
from BurialSites l
left join (
select burialSiteId, count(burialSiteContractId) as burialSiteContractCount from BurialSiteContracts
select burialSiteId, count(contractId) as contractCount from Contracts
where recordDelete_timeMillis is null
and contractStartDate <= ${currentDate.toString()}
and (contractEndDate is null or contractEndDate >= ${currentDate.toString()})
@ -109,9 +109,9 @@ export default async function getBurialSites(
let burialSites: BurialSite[] = []
if (options.limit === -1 || count > 0) {
const includeBurialSiteContractCount = options.includeBurialSiteContractCount ?? true
const includeContractCount = options.includeContractCount ?? true
if (includeBurialSiteContractCount) {
if (includeContractCount) {
sqlParameters.unshift(currentDate, currentDate)
}
@ -128,8 +128,8 @@ export default async function getBurialSites(
l.cemeteryId, m.cemeteryName, l.cemeterySvgId,
l.burialSiteStatusId, s.burialSiteStatus
${
includeBurialSiteContractCount
? ', ifnull(o.burialSiteContractCount, 0) as burialSiteContractCount'
includeContractCount
? ', ifnull(o.contractCount, 0) as contractCount'
: ''
}
from BurialSites l
@ -137,10 +137,10 @@ export default async function getBurialSites(
left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId
left join Cemeteries m on l.cemeteryId = m.cemeteryId
${
includeBurialSiteContractCount
includeContractCount
? `left join (
select burialSiteId, count(burialSiteContractId) as burialSiteContractCount
from BurialSiteContracts
select burialSiteId, count(contractId) as contractCount
from Contracts
where recordDelete_timeMillis is null
and contractStartDate <= ?
and (contractEndDate is null or contractEndDate >= ?)

3
database/getContract.d.ts vendored 100644
View File

@ -0,0 +1,3 @@
import type { PoolConnection } from 'better-sqlite-pool';
import type { Contract } from '../types/recordTypes.js';
export default function getContract(contractId: number | string, connectedDatabase?: PoolConnection): Promise<Contract | undefined>;

View File

@ -1,16 +1,16 @@
import { dateIntegerToString } from '@cityssm/utils-datetime';
import getBurialSiteContractComments from './getBurialSiteContractComments.js';
import getBurialSiteContractFees from './getBurialSiteContractFees.js';
import getBurialSiteContractFields from './getBurialSiteContractFields.js';
// import getBurialSiteContractOccupants from './getBurialSiteContractOccupants.js'
import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js';
import getContractComments from './getContractComments.js';
import getContractFees from './getContractFees.js';
import getContractFields from './getContractFields.js';
// import getContractOccupants from './getContractOccupants.js'
import getContractTransactions from './getContractTransactions.js';
import { getWorkOrders } from './getWorkOrders.js';
import { acquireConnection } from './pool.js';
export default async function getBurialSiteContract(burialSiteContractId, connectedDatabase) {
export default async function getContract(contractId, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection());
database.function('userFn_dateIntegerToString', dateIntegerToString);
const contract = database
.prepare(`select o.burialSiteContractId,
.prepare(`select o.contractId,
o.contractTypeId, t.contractType,
o.burialSiteId,
l.burialSiteName,
@ -19,26 +19,26 @@ export default async function getBurialSiteContract(burialSiteContractId, connec
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
o.recordUpdate_timeMillis
from BurialSiteContracts o
from Contracts o
left join ContractTypes t on o.contractTypeId = t.contractTypeId
left join BurialSites l on o.burialSiteId = l.burialSiteId
left join Maps m on l.cemeteryId = m.cemeteryId
where o.recordDelete_timeMillis is null
and o.burialSiteContractId = ?`)
.get(burialSiteContractId);
and o.contractId = ?`)
.get(contractId);
if (contract !== undefined) {
contract.burialSiteContractFields = await getBurialSiteContractFields(burialSiteContractId, database);
contract.contractFields = await getContractFields(contractId, database);
/*
contract.burialSiteContractInterments = await getBurialSiteContractOccupants(
burialSiteContractId,
contract.contractInterments = await getContractOccupants(
contractId,
database
)
*/
contract.burialSiteContractComments = await getBurialSiteContractComments(burialSiteContractId, database);
contract.burialSiteContractFees = await getBurialSiteContractFees(burialSiteContractId, database);
contract.burialSiteContractTransactions = await getBurialSiteContractTransactions(burialSiteContractId, { includeIntegrations: true }, database);
contract.contractComments = await getContractComments(contractId, database);
contract.contractFees = await getContractFees(contractId, database);
contract.contractTransactions = await getContractTransactions(contractId, { includeIntegrations: true }, database);
const workOrdersResults = await getWorkOrders({
burialSiteContractId
contractId
}, {
limit: -1,
offset: 0

View File

@ -1,27 +1,27 @@
import { dateIntegerToString } from '@cityssm/utils-datetime'
import type { PoolConnection } from 'better-sqlite-pool'
import type { BurialSiteContract } from '../types/recordTypes.js'
import type { Contract } from '../types/recordTypes.js'
import getBurialSiteContractComments from './getBurialSiteContractComments.js'
import getBurialSiteContractFees from './getBurialSiteContractFees.js'
import getBurialSiteContractFields from './getBurialSiteContractFields.js'
// import getBurialSiteContractOccupants from './getBurialSiteContractOccupants.js'
import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js'
import getContractComments from './getContractComments.js'
import getContractFees from './getContractFees.js'
import getContractFields from './getContractFields.js'
// import getContractOccupants from './getContractOccupants.js'
import getContractTransactions from './getContractTransactions.js'
import { getWorkOrders } from './getWorkOrders.js'
import { acquireConnection } from './pool.js'
export default async function getBurialSiteContract(
burialSiteContractId: number | string,
export default async function getContract(
contractId: number | string,
connectedDatabase?: PoolConnection
): Promise<BurialSiteContract | undefined> {
): Promise<Contract | undefined> {
const database = connectedDatabase ?? (await acquireConnection())
database.function('userFn_dateIntegerToString', dateIntegerToString)
const contract = database
.prepare(
`select o.burialSiteContractId,
`select o.contractId,
o.contractTypeId, t.contractType,
o.burialSiteId,
l.burialSiteName,
@ -30,43 +30,43 @@ export default async function getBurialSiteContract(
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
o.recordUpdate_timeMillis
from BurialSiteContracts o
from Contracts o
left join ContractTypes t on o.contractTypeId = t.contractTypeId
left join BurialSites l on o.burialSiteId = l.burialSiteId
left join Maps m on l.cemeteryId = m.cemeteryId
where o.recordDelete_timeMillis is null
and o.burialSiteContractId = ?`
and o.contractId = ?`
)
.get(burialSiteContractId) as BurialSiteContract | undefined
.get(contractId) as Contract | undefined
if (contract !== undefined) {
contract.burialSiteContractFields = await getBurialSiteContractFields(
burialSiteContractId,
contract.contractFields = await getContractFields(
contractId,
database
)
/*
contract.burialSiteContractInterments = await getBurialSiteContractOccupants(
burialSiteContractId,
contract.contractInterments = await getContractOccupants(
contractId,
database
)
*/
contract.burialSiteContractComments = await getBurialSiteContractComments(
burialSiteContractId,
contract.contractComments = await getContractComments(
contractId,
database
)
contract.burialSiteContractFees = await getBurialSiteContractFees(
burialSiteContractId,
contract.contractFees = await getContractFees(
contractId,
database
)
contract.burialSiteContractTransactions = await getBurialSiteContractTransactions(
burialSiteContractId,
contract.contractTransactions = await getContractTransactions(
contractId,
{ includeIntegrations: true },
database
)
const workOrdersResults = await getWorkOrders(
{
burialSiteContractId
contractId
},
{
limit: -1,

View File

@ -0,0 +1,3 @@
import type { PoolConnection } from 'better-sqlite-pool';
import type { ContractComment } from '../types/recordTypes.js';
export default function getContractComments(contractId: number | string, connectedDatabase?: PoolConnection): Promise<ContractComment[]>;

View File

@ -1,23 +1,23 @@
import { dateIntegerToString, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime';
import { acquireConnection } from './pool.js';
export default async function getBurialSiteContractComments(burialSiteContractId, connectedDatabase) {
export default async function getContractComments(contractId, 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,
.prepare(`select contractCommentId,
commentDate, userFn_dateIntegerToString(commentDate) as commentDateString,
commentTime,
userFn_timeIntegerToString(commentTime) as commentTimeString,
userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString,
comment,
recordCreate_userName, recordUpdate_userName
from BurialSiteContractComments
from ContractComments
where recordDelete_timeMillis is null
and burialSiteContractId = ?
order by commentDate desc, commentTime desc, burialSiteContractCommentId desc`)
.all(burialSiteContractId);
and contractId = ?
order by commentDate desc, commentTime desc, contractCommentId desc`)
.all(contractId);
if (connectedDatabase === undefined) {
database.release();
}

View File

@ -5,14 +5,14 @@ import {
} from '@cityssm/utils-datetime'
import type { PoolConnection } from 'better-sqlite-pool'
import type { BurialSiteContractComment } from '../types/recordTypes.js'
import type { ContractComment } from '../types/recordTypes.js'
import { acquireConnection } from './pool.js'
export default async function getBurialSiteContractComments(
burialSiteContractId: number | string,
export default async function getContractComments(
contractId: number | string,
connectedDatabase?: PoolConnection
): Promise<BurialSiteContractComment[]> {
): Promise<ContractComment[]> {
const database = connectedDatabase ?? (await acquireConnection())
database.function('userFn_dateIntegerToString', dateIntegerToString)
@ -24,19 +24,19 @@ export default async function getBurialSiteContractComments(
const comments = database
.prepare(
`select burialSiteContractCommentId,
`select contractCommentId,
commentDate, userFn_dateIntegerToString(commentDate) as commentDateString,
commentTime,
userFn_timeIntegerToString(commentTime) as commentTimeString,
userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString,
comment,
recordCreate_userName, recordUpdate_userName
from BurialSiteContractComments
from ContractComments
where recordDelete_timeMillis is null
and burialSiteContractId = ?
order by commentDate desc, commentTime desc, burialSiteContractCommentId desc`
and contractId = ?
order by commentDate desc, commentTime desc, contractCommentId desc`
)
.all(burialSiteContractId) as BurialSiteContractComment[]
.all(contractId) as ContractComment[]
if (connectedDatabase === undefined) {
database.release()

3
database/getContractFees.d.ts vendored 100644
View File

@ -0,0 +1,3 @@
import type { PoolConnection } from 'better-sqlite-pool';
import type { ContractFee } from '../types/recordTypes.js';
export default function getContractFees(contractId: number | string, connectedDatabase?: PoolConnection): Promise<ContractFee[]>;

View File

@ -1,17 +1,17 @@
import { acquireConnection } from './pool.js';
export default async function getBurialSiteContractFees(burialSiteContractId, connectedDatabase) {
export default async function getContractFees(contractId, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection());
const fees = database
.prepare(`select o.burialSiteContractId, o.feeId,
.prepare(`select o.contractId, o.feeId,
c.feeCategory, f.feeName,
f.includeQuantity, o.feeAmount, o.taxAmount, o.quantity, f.quantityUnit
from BurialSiteContractFees o
from ContractFees 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.burialSiteContractId = ?
and o.contractId = ?
order by o.recordCreate_timeMillis`)
.all(burialSiteContractId);
.all(contractId);
if (connectedDatabase === undefined) {
database.release();
}

View File

@ -1,28 +1,28 @@
import type { PoolConnection } from 'better-sqlite-pool'
import type { BurialSiteContractFee } from '../types/recordTypes.js'
import type { ContractFee } from '../types/recordTypes.js'
import { acquireConnection } from './pool.js'
export default async function getBurialSiteContractFees(
burialSiteContractId: number | string,
export default async function getContractFees(
contractId: number | string,
connectedDatabase?: PoolConnection
): Promise<BurialSiteContractFee[]> {
): Promise<ContractFee[]> {
const database = connectedDatabase ?? (await acquireConnection())
const fees = database
.prepare(
`select o.burialSiteContractId, o.feeId,
`select o.contractId, o.feeId,
c.feeCategory, f.feeName,
f.includeQuantity, o.feeAmount, o.taxAmount, o.quantity, f.quantityUnit
from BurialSiteContractFees o
from ContractFees 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.burialSiteContractId = ?
and o.contractId = ?
order by o.recordCreate_timeMillis`
)
.all(burialSiteContractId) as BurialSiteContractFee[]
.all(contractId) as ContractFee[]
if (connectedDatabase === undefined) {
database.release()

View File

@ -0,0 +1,3 @@
import type { PoolConnection } from 'better-sqlite-pool';
import type { ContractField } from '../types/recordTypes.js';
export default function getContractField(contractId: number | string, connectedDatabase?: PoolConnection): Promise<ContractField[]>;

View File

@ -1,20 +1,20 @@
import { acquireConnection } from './pool.js';
export default async function getBurialSiteContractField(burialSiteContractId, connectedDatabase) {
export default async function getContractField(contractId, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection());
const fields = database
.prepare(`select o.burialSiteContractId, o.contractTypeFieldId,
.prepare(`select o.contractId, o.contractTypeFieldId,
o.fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
f.isRequired, f.pattern, f.minLength, f.maxLength,
f.orderNumber, t.orderNumber as contractTypeOrderNumber
from BurialSiteContractFields o
from ContractFields 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 = ?
and o.contractId = ?
union
select ? as burialSiteContractId, f.contractTypeFieldId,
select ? as contractId, f.contractTypeFieldId,
'' as fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
f.isRequired, f.pattern, f.minLength, f.maxLength,
f.orderNumber, t.orderNumber as contractTypeOrderNumber
@ -22,10 +22,10 @@ export default async function getBurialSiteContractField(burialSiteContractId, c
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)
or f.contractTypeId in (select contractTypeId from Contracts where contractId = ?))
and f.contractTypeFieldId not in (select contractTypeFieldId from ContractFields where contractId = ? and recordDelete_timeMillis is null)
order by contractTypeOrderNumber, f.orderNumber, f.contractTypeField`)
.all(burialSiteContractId, burialSiteContractId, burialSiteContractId, burialSiteContractId);
.all(contractId, contractId, contractId, contractId);
if (connectedDatabase === undefined) {
database.release();
}

View File

@ -1,30 +1,30 @@
import type { PoolConnection } from 'better-sqlite-pool'
import type { BurialSiteContractField } from '../types/recordTypes.js'
import type { ContractField } from '../types/recordTypes.js'
import { acquireConnection } from './pool.js'
export default async function getBurialSiteContractField(
burialSiteContractId: number | string,
export default async function getContractField(
contractId: number | string,
connectedDatabase?: PoolConnection
): Promise<BurialSiteContractField[]> {
): Promise<ContractField[]> {
const database = connectedDatabase ?? (await acquireConnection())
const fields = database
.prepare(
`select o.burialSiteContractId, o.contractTypeFieldId,
`select o.contractId, o.contractTypeFieldId,
o.fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
f.isRequired, f.pattern, f.minLength, f.maxLength,
f.orderNumber, t.orderNumber as contractTypeOrderNumber
from BurialSiteContractFields o
from ContractFields 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 = ?
and o.contractId = ?
union
select ? as burialSiteContractId, f.contractTypeFieldId,
select ? as contractId, f.contractTypeFieldId,
'' as fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
f.isRequired, f.pattern, f.minLength, f.maxLength,
f.orderNumber, t.orderNumber as contractTypeOrderNumber
@ -32,16 +32,16 @@ export default async function getBurialSiteContractField(
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)
or f.contractTypeId in (select contractTypeId from Contracts where contractId = ?))
and f.contractTypeFieldId not in (select contractTypeFieldId from ContractFields where contractId = ? and recordDelete_timeMillis is null)
order by contractTypeOrderNumber, f.orderNumber, f.contractTypeField`
)
.all(
burialSiteContractId,
burialSiteContractId,
burialSiteContractId,
burialSiteContractId
) as BurialSiteContractField[]
contractId,
contractId,
contractId,
contractId
) as ContractField[]
if (connectedDatabase === undefined) {
database.release()

View File

@ -0,0 +1,3 @@
import type { PoolConnection } from 'better-sqlite-pool';
import type { ContractInterment } from '../types/recordTypes.js';
export default function getContractInterments(contractId: number | string, connectedDatabase?: PoolConnection): Promise<ContractInterment[]>;

View File

@ -1,11 +1,11 @@
import { dateIntegerToString, timeIntegerToString } from '@cityssm/utils-datetime';
import { acquireConnection } from './pool.js';
export default async function getBurialSiteContractInterments(burialSiteContractId, connectedDatabase) {
export default async function getContractInterments(contractId, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection());
database.function('userFn_dateIntegerToString', dateIntegerToString);
database.function('userFn_timeIntegerToString', timeIntegerToString);
const interments = database
.prepare(`select o.burialSiteContractId, o.intermentNumber,
.prepare(`select o.contractId, o.intermentNumber,
o.isCremated,
o.deceasedName,
birthDate, userFn_dateIntegerToString(birthDate) as birthDateString,
@ -19,14 +19,14 @@ export default async function getBurialSiteContractInterments(burialSiteContract
intermentContainerTypeId, t.intermentContainerType,
intermentCommittalTypeId, c.intermentCommittalType
from BurialSiteContractInterments o
from ContractInterments o
left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId
left join IntermentCommittalTypes c on o.intermentCommittalTypeId = c.intermentCommittalTypeId
where o.recordDelete_timeMillis is null
and o.burialSiteContractId = ?
and o.contractId = ?
order by t.orderNumber, o.deceasedName, o.intermentNumber`)
.all(burialSiteContractId);
.all(contractId);
if (connectedDatabase === undefined) {
database.release();
}

View File

@ -4,14 +4,14 @@ import {
} from '@cityssm/utils-datetime'
import type { PoolConnection } from 'better-sqlite-pool'
import type { BurialSiteContractInterment } from '../types/recordTypes.js'
import type { ContractInterment } from '../types/recordTypes.js'
import { acquireConnection } from './pool.js'
export default async function getBurialSiteContractInterments(
burialSiteContractId: number | string,
export default async function getContractInterments(
contractId: number | string,
connectedDatabase?: PoolConnection
): Promise<BurialSiteContractInterment[]> {
): Promise<ContractInterment[]> {
const database = connectedDatabase ?? (await acquireConnection())
database.function('userFn_dateIntegerToString', dateIntegerToString)
@ -19,7 +19,7 @@ export default async function getBurialSiteContractInterments(
const interments = database
.prepare(
`select o.burialSiteContractId, o.intermentNumber,
`select o.contractId, o.intermentNumber,
o.isCremated,
o.deceasedName,
birthDate, userFn_dateIntegerToString(birthDate) as birthDateString,
@ -33,15 +33,15 @@ export default async function getBurialSiteContractInterments(
intermentContainerTypeId, t.intermentContainerType,
intermentCommittalTypeId, c.intermentCommittalType
from BurialSiteContractInterments o
from ContractInterments o
left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId
left join IntermentCommittalTypes c on o.intermentCommittalTypeId = c.intermentCommittalTypeId
where o.recordDelete_timeMillis is null
and o.burialSiteContractId = ?
and o.contractId = ?
order by t.orderNumber, o.deceasedName, o.intermentNumber`
)
.all(burialSiteContractId) as BurialSiteContractInterment[]
.all(contractId) as ContractInterment[]
if (connectedDatabase === undefined) {
database.release()

View File

@ -0,0 +1,5 @@
import type { PoolConnection } from 'better-sqlite-pool';
import type { ContractTransaction } from '../types/recordTypes.js';
export default function GetContractTransactions(contractId: number | string, options: {
includeIntegrations: boolean;
}, connectedDatabase?: PoolConnection): Promise<ContractTransaction[]>;

View File

@ -2,26 +2,26 @@ 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 GetBurialSiteContractTransactions(burialSiteContractId, options, connectedDatabase) {
export default async function GetContractTransactions(contractId, options, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection());
database.function('userFn_dateIntegerToString', dateIntegerToString);
database.function('userFn_timeIntegerToString', timeIntegerToString);
const burialSiteContractTransactions = database
.prepare(`select burialSiteContractId, transactionIndex,
const contractTransactions = database
.prepare(`select contractId, transactionIndex,
transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString,
transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString,
transactionAmount, externalReceiptNumber, transactionNote
from BurialSiteContractTransactions
from ContractTransactions
where recordDelete_timeMillis is null
and burialSiteContractId = ?
and contractId = ?
order by transactionDate, transactionTime, transactionIndex`)
.all(burialSiteContractId);
.all(contractId);
if (connectedDatabase === undefined) {
database.release();
}
if (options.includeIntegrations &&
getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) {
for (const transaction of burialSiteContractTransactions) {
for (const transaction of contractTransactions) {
if ((transaction.externalReceiptNumber ?? '') !== '') {
const gpDocument = await getDynamicsGPDocument(transaction.externalReceiptNumber ?? '');
if (gpDocument !== undefined) {
@ -30,5 +30,5 @@ export default async function GetBurialSiteContractTransactions(burialSiteContra
}
}
}
return burialSiteContractTransactions;
return contractTransactions;
}

View File

@ -6,34 +6,34 @@ import type { PoolConnection } from 'better-sqlite-pool'
import { getConfigProperty } from '../helpers/config.helpers.js'
import { getDynamicsGPDocument } from '../helpers/functions.dynamicsGP.js'
import type { BurialSiteContractTransaction } from '../types/recordTypes.js'
import type { ContractTransaction } from '../types/recordTypes.js'
import { acquireConnection } from './pool.js'
export default async function GetBurialSiteContractTransactions(
burialSiteContractId: number | string,
export default async function GetContractTransactions(
contractId: number | string,
options: {
includeIntegrations: boolean
},
connectedDatabase?: PoolConnection
): Promise<BurialSiteContractTransaction[]> {
): Promise<ContractTransaction[]> {
const database = connectedDatabase ?? (await acquireConnection())
database.function('userFn_dateIntegerToString', dateIntegerToString)
database.function('userFn_timeIntegerToString', timeIntegerToString)
const burialSiteContractTransactions = database
const contractTransactions = database
.prepare(
`select burialSiteContractId, transactionIndex,
`select contractId, transactionIndex,
transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString,
transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString,
transactionAmount, externalReceiptNumber, transactionNote
from BurialSiteContractTransactions
from ContractTransactions
where recordDelete_timeMillis is null
and burialSiteContractId = ?
and contractId = ?
order by transactionDate, transactionTime, transactionIndex`
)
.all(burialSiteContractId) as BurialSiteContractTransaction[]
.all(contractId) as ContractTransaction[]
if (connectedDatabase === undefined) {
database.release()
@ -43,7 +43,7 @@ export default async function GetBurialSiteContractTransactions(
options.includeIntegrations &&
getConfigProperty('settings.dynamicsGP.integrationIsEnabled')
) {
for (const transaction of burialSiteContractTransactions) {
for (const transaction of contractTransactions) {
if ((transaction.externalReceiptNumber ?? '') !== '') {
const gpDocument = await getDynamicsGPDocument(
transaction.externalReceiptNumber ?? ''
@ -56,5 +56,5 @@ export default async function GetBurialSiteContractTransactions(
}
}
return burialSiteContractTransactions
return contractTransactions
}

View File

@ -1,7 +1,7 @@
import { type DateString } from '@cityssm/utils-datetime';
import type { PoolConnection } from 'better-sqlite-pool';
import type { BurialSiteContract } from '../types/recordTypes.js';
export interface GetBurialSiteContractsFilters {
import type { Contract } from '../types/recordTypes.js';
export interface GetContractsFilters {
burialSiteId?: number | string;
occupancyTime?: '' | 'past' | 'current' | 'future';
contractStartDateString?: DateString;
@ -15,7 +15,7 @@ export interface GetBurialSiteContractsFilters {
workOrderId?: number | string;
notWorkOrderId?: number | string;
}
export interface GetBurialSiteContractsOptions {
export interface GetContractsOptions {
/** -1 for no limit */
limit: number | string;
offset: number | string;
@ -23,7 +23,7 @@ export interface GetBurialSiteContractsOptions {
includeFees: boolean;
includeTransactions: boolean;
}
export default function getBurialSiteContracts(filters: GetBurialSiteContractsFilters, options: GetBurialSiteContractsOptions, connectedDatabase?: PoolConnection): Promise<{
export default function getContracts(filters: GetContractsFilters, options: GetContractsOptions, connectedDatabase?: PoolConnection): Promise<{
count: number;
burialSiteContracts: BurialSiteContract[];
contracts: Contract[];
}>;

View File

@ -2,9 +2,9 @@ import { dateIntegerToString, dateStringToInteger } from '@cityssm/utils-datetim
import { getConfigProperty } from '../helpers/config.helpers.js';
import { getContractTypeById } from '../helpers/functions.cache.js';
import { getBurialSiteNameWhereClause, getOccupancyTimeWhereClause, getOccupantNameWhereClause } from '../helpers/functions.sqlFilters.js';
import getBurialSiteContractFees from './getBurialSiteContractFees.js';
// import getBurialSiteContractOccupants from './getBurialSiteContractOccupants.js'
import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js';
import getContractFees from './getContractFees.js';
// import getContractOccupants from './getContractOccupants.js'
import getContractTransactions from './getContractTransactions.js';
import { acquireConnection } from './pool.js';
function buildWhereClause(filters) {
let sqlWhereClause = ' where o.recordDelete_timeMillis is null';
@ -18,8 +18,8 @@ function buildWhereClause(filters) {
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
sqlWhereClause += ` and o.contractId in (
select contractId from LotOccupancyOccupants o
where recordDelete_timeMillis is null
${occupantNameFilters.sqlWhereClause})`;
sqlParameters.push(...occupantNameFilters.sqlParameters);
@ -52,12 +52,12 @@ function buildWhereClause(filters) {
}
if ((filters.workOrderId ?? '') !== '') {
sqlWhereClause +=
' and o.burialSiteContractId in (select burialSiteContractId from WorkOrderBurialSiteContracts where recordDelete_timeMillis is null and workOrderId = ?)';
' and o.contractId in (select contractId from WorkOrderContracts 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 = ?)';
' and o.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)';
sqlParameters.push(filters.notWorkOrderId);
}
return {
@ -65,26 +65,26 @@ function buildWhereClause(filters) {
sqlParameters
};
}
async function addInclusions(burialSiteContract, options, database) {
async function addInclusions(contract, options, database) {
if (options.includeFees) {
burialSiteContract.burialSiteContractFees = await getBurialSiteContractFees(burialSiteContract.burialSiteContractId, database);
contract.contractFees = await getContractFees(contract.contractId, database);
}
if (options.includeTransactions) {
burialSiteContract.burialSiteContractTransactions =
await getBurialSiteContractTransactions(burialSiteContract.burialSiteContractId, { includeIntegrations: false }, database);
contract.contractTransactions =
await getContractTransactions(contract.contractId, { includeIntegrations: false }, database);
}
/*
if (options.includeInterments) {
burialSiteContract.burialSiteContractInterments =
await getBurialSiteContractOccupants(
burialSiteContract.burialSiteContractId,
contract.contractInterments =
await getContractOccupants(
contract.contractId,
database
)
}
*/
return burialSiteContract;
return contract;
}
export default async function getBurialSiteContracts(filters, options, connectedDatabase) {
export default async function getContracts(filters, options, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection());
database.function('userFn_dateIntegerToString', dateIntegerToString);
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
@ -95,22 +95,22 @@ export default async function getBurialSiteContracts(filters, options, connected
if (isLimited) {
count = database
.prepare(`select count(*) as recordCount
from BurialSiteContracts o
from Contracts o
left join BurialSites l on o.burialSiteId = l.burialSiteId
${sqlWhereClause}`)
.get(sqlParameters).recordCount;
}
let burialSiteContracts = [];
let contracts = [];
if (count !== 0) {
burialSiteContracts = database
.prepare(`select o.burialSiteContractId,
contracts = database
.prepare(`select o.contractId,
o.contractTypeId, t.contractType,
o.burialSiteId, lt.burialSiteType,
l.burialSiteName,
l.cemeteryId, m.cemeteryName,
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString
from BurialSiteContracts o
from Contracts 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
@ -122,20 +122,20 @@ export default async function getBurialSiteContracts(filters, options, connected
l.burialSiteNameSegment3,
l.burialSiteNameSegment4,
l.burialSiteNameSegment5,
o.burialSiteId, o.burialSiteContractId desc
o.burialSiteId, o.contractId desc
${isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''}`)
.all(sqlParameters);
if (!isLimited) {
count = burialSiteContracts.length;
count = contracts.length;
}
for (const burialSiteContract of burialSiteContracts) {
const contractType = await getContractTypeById(burialSiteContract.contractTypeId);
for (const contract of contracts) {
const contractType = await getContractTypeById(contract.contractTypeId);
if (contractType !== undefined) {
burialSiteContract.printEJS = (contractType.contractTypePrints ?? []).includes('*')
contract.printEJS = (contractType.contractTypePrints ?? []).includes('*')
? getConfigProperty('settings.contracts.prints')[0]
: (contractType.contractTypePrints ?? [])[0];
}
await addInclusions(burialSiteContract, options, database);
await addInclusions(contract, options, database);
}
}
if (connectedDatabase === undefined) {
@ -143,6 +143,6 @@ export default async function getBurialSiteContracts(filters, options, connected
}
return {
count,
burialSiteContracts
contracts
};
}

View File

@ -12,14 +12,14 @@ import {
getOccupancyTimeWhereClause,
getOccupantNameWhereClause
} from '../helpers/functions.sqlFilters.js'
import type { BurialSiteContract } from '../types/recordTypes.js'
import type { Contract } from '../types/recordTypes.js'
import getBurialSiteContractFees from './getBurialSiteContractFees.js'
// import getBurialSiteContractOccupants from './getBurialSiteContractOccupants.js'
import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js'
import getContractFees from './getContractFees.js'
// import getContractOccupants from './getContractOccupants.js'
import getContractTransactions from './getContractTransactions.js'
import { acquireConnection } from './pool.js'
export interface GetBurialSiteContractsFilters {
export interface GetContractsFilters {
burialSiteId?: number | string
occupancyTime?: '' | 'past' | 'current' | 'future'
contractStartDateString?: DateString
@ -34,7 +34,7 @@ export interface GetBurialSiteContractsFilters {
notWorkOrderId?: number | string
}
export interface GetBurialSiteContractsOptions {
export interface GetContractsOptions {
/** -1 for no limit */
limit: number | string
offset: number | string
@ -43,7 +43,7 @@ export interface GetBurialSiteContractsOptions {
includeTransactions: boolean
}
function buildWhereClause(filters: GetBurialSiteContractsFilters): {
function buildWhereClause(filters: GetContractsFilters): {
sqlWhereClause: string
sqlParameters: unknown[]
} {
@ -68,8 +68,8 @@ function buildWhereClause(filters: GetBurialSiteContractsFilters): {
'o'
)
if (occupantNameFilters.sqlParameters.length > 0) {
sqlWhereClause += ` and o.burialSiteContractId in (
select burialSiteContractId from LotOccupancyOccupants o
sqlWhereClause += ` and o.contractId in (
select contractId from LotOccupancyOccupants o
where recordDelete_timeMillis is null
${occupantNameFilters.sqlWhereClause})`
sqlParameters.push(...occupantNameFilters.sqlParameters)
@ -117,13 +117,13 @@ function buildWhereClause(filters: GetBurialSiteContractsFilters): {
if ((filters.workOrderId ?? '') !== '') {
sqlWhereClause +=
' and o.burialSiteContractId in (select burialSiteContractId from WorkOrderBurialSiteContracts where recordDelete_timeMillis is null and workOrderId = ?)'
' and o.contractId in (select contractId from WorkOrderContracts 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 = ?)'
' and o.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)'
sqlParameters.push(filters.notWorkOrderId)
}
@ -134,21 +134,21 @@ function buildWhereClause(filters: GetBurialSiteContractsFilters): {
}
async function addInclusions(
burialSiteContract: BurialSiteContract,
options: GetBurialSiteContractsOptions,
contract: Contract,
options: GetContractsOptions,
database: PoolConnection
): Promise<BurialSiteContract> {
): Promise<Contract> {
if (options.includeFees) {
burialSiteContract.burialSiteContractFees = await getBurialSiteContractFees(
burialSiteContract.burialSiteContractId,
contract.contractFees = await getContractFees(
contract.contractId,
database
)
}
if (options.includeTransactions) {
burialSiteContract.burialSiteContractTransactions =
await getBurialSiteContractTransactions(
burialSiteContract.burialSiteContractId,
contract.contractTransactions =
await getContractTransactions(
contract.contractId,
{ includeIntegrations: false },
database
)
@ -156,22 +156,22 @@ async function addInclusions(
/*
if (options.includeInterments) {
burialSiteContract.burialSiteContractInterments =
await getBurialSiteContractOccupants(
burialSiteContract.burialSiteContractId,
contract.contractInterments =
await getContractOccupants(
contract.contractId,
database
)
}
*/
return burialSiteContract
return contract
}
export default async function getBurialSiteContracts(
filters: GetBurialSiteContractsFilters,
options: GetBurialSiteContractsOptions,
export default async function getContracts(
filters: GetContractsFilters,
options: GetContractsOptions,
connectedDatabase?: PoolConnection
): Promise<{ count: number; burialSiteContracts: BurialSiteContract[] }> {
): Promise<{ count: number; contracts: Contract[] }> {
const database = connectedDatabase ?? (await acquireConnection())
database.function('userFn_dateIntegerToString', dateIntegerToString)
@ -190,7 +190,7 @@ export default async function getBurialSiteContracts(
database
.prepare(
`select count(*) as recordCount
from BurialSiteContracts o
from Contracts o
left join BurialSites l on o.burialSiteId = l.burialSiteId
${sqlWhereClause}`
)
@ -198,19 +198,19 @@ export default async function getBurialSiteContracts(
).recordCount
}
let burialSiteContracts: BurialSiteContract[] = []
let contracts: Contract[] = []
if (count !== 0) {
burialSiteContracts = database
contracts = database
.prepare(
`select o.burialSiteContractId,
`select o.contractId,
o.contractTypeId, t.contractType,
o.burialSiteId, lt.burialSiteType,
l.burialSiteName,
l.cemeteryId, m.cemeteryName,
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString
from BurialSiteContracts o
from Contracts 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
@ -222,31 +222,31 @@ export default async function getBurialSiteContracts(
l.burialSiteNameSegment3,
l.burialSiteNameSegment4,
l.burialSiteNameSegment5,
o.burialSiteId, o.burialSiteContractId desc
o.burialSiteId, o.contractId desc
${
isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''
}`
)
.all(sqlParameters) as BurialSiteContract[]
.all(sqlParameters) as Contract[]
if (!isLimited) {
count = burialSiteContracts.length
count = contracts.length
}
for (const burialSiteContract of burialSiteContracts) {
for (const contract of contracts) {
const contractType = await getContractTypeById(
burialSiteContract.contractTypeId
contract.contractTypeId
)
if (contractType !== undefined) {
burialSiteContract.printEJS = (
contract.printEJS = (
contractType.contractTypePrints ?? []
).includes('*')
? getConfigProperty('settings.contracts.prints')[0]
: (contractType.contractTypePrints ?? [])[0]
}
await addInclusions(burialSiteContract, options, database)
await addInclusions(contract, options, database)
}
}
@ -256,6 +256,6 @@ export default async function getBurialSiteContracts(
return {
count,
burialSiteContracts
contracts
}
}

View File

@ -24,11 +24,11 @@ export default async function getFees(feeCategoryId, additionalFilters, connecte
f.taxAmount, f.taxPercentage,
f.includeQuantity, f.quantityUnit,
f.isRequired, f.orderNumber,
ifnull(lo.burialSiteContractFeeCount, 0) as burialSiteContractFeeCount
ifnull(lo.contractFeeCount, 0) as contractFeeCount
from Fees f
left join (
select feeId, count(burialSiteContractId) as burialSiteContractFeeCount
from BurialSiteContractFees
select feeId, count(contractId) as contractFeeCount
from ContractFees
where recordDelete_timeMillis is null
group by feeId
) lo on f.feeId = lo.feeId

View File

@ -50,11 +50,11 @@ export default async function getFees(
f.taxAmount, f.taxPercentage,
f.includeQuantity, f.quantityUnit,
f.isRequired, f.orderNumber,
ifnull(lo.burialSiteContractFeeCount, 0) as burialSiteContractFeeCount
ifnull(lo.contractFeeCount, 0) as contractFeeCount
from Fees f
left join (
select feeId, count(burialSiteContractId) as burialSiteContractFeeCount
from BurialSiteContractFees
select feeId, count(contractId) as contractFeeCount
from ContractFees
where recordDelete_timeMillis is null
group by feeId
) lo on f.feeId = lo.feeId

View File

@ -90,12 +90,12 @@ export default async function getReportData(reportName, reportParameters = {}) {
sql = 'select * from BurialSiteFields';
break;
}
case 'burialSiteContracts-all': {
sql = 'select * from BurialSiteContracts';
case 'contracts-all': {
sql = 'select * from Contracts';
break;
}
case 'burialSiteContracts-current-byCemeteryId': {
sql = `select o.burialSiteContractId,
case 'contracts-current-byCemeteryId': {
sql = `select o.contractId,
l.burialSiteNameSegment1,
l.burialSiteNameSegment2,
l.burialSiteNameSegment3,
@ -105,7 +105,7 @@ export default async function getReportData(reportName, reportParameters = {}) {
ot.contractType,
o.contractStartDate,
o.contractEndDate
from BurialSiteContracts o
from Contracts o
left join ContractTypes ot on o.contractTypeId = ot.contractTypeId
left join BurialSites l on o.burialSiteId = l.burialSiteId
left join Cemeteries m on l.cemeteryId = m.cemeteryId
@ -115,28 +115,28 @@ export default async function getReportData(reportName, reportParameters = {}) {
sqlParameters.push(dateToInteger(new Date()), reportParameters.cemeteryId);
break;
}
case 'burialSiteContractComments-all': {
sql = 'select * from BurialSiteContractComments';
case 'contractComments-all': {
sql = 'select * from ContractComments';
break;
}
case 'burialSiteContractFees-all': {
sql = 'select * from BurialSiteContractFees';
case 'contractFees-all': {
sql = 'select * from ContractFees';
break;
}
case 'burialSiteContractFields-all': {
sql = 'select * from BurialSiteContractFields';
case 'contractFields-all': {
sql = 'select * from ContractFields';
break;
}
case 'burialSiteContractTransactions-all': {
sql = 'select * from BurialSiteContractTransactions';
case 'contractTransactions-all': {
sql = 'select * from ContractTransactions';
break;
}
case 'burialSiteContractTransactions-byTransactionDateString': {
sql = `select t.burialSiteContractId, t.transactionIndex,
case 'contractTransactions-byTransactionDateString': {
sql = `select t.contractId, t.transactionIndex,
t.transactionDate, t.transactionTime,
t.transactionAmount,
t.externalReceiptNumber, t.transactionNote
from BurialSiteContractTransactions t
from ContractTransactions t
where t.recordDelete_timeMillis is null
and t.transactionDate = ?`;
sqlParameters.push(dateStringToInteger(reportParameters.transactionDateString));

View File

@ -119,13 +119,13 @@ export default async function getReportData(
break
}
case 'burialSiteContracts-all': {
sql = 'select * from BurialSiteContracts'
case 'contracts-all': {
sql = 'select * from Contracts'
break
}
case 'burialSiteContracts-current-byCemeteryId': {
sql = `select o.burialSiteContractId,
case 'contracts-current-byCemeteryId': {
sql = `select o.contractId,
l.burialSiteNameSegment1,
l.burialSiteNameSegment2,
l.burialSiteNameSegment3,
@ -135,7 +135,7 @@ export default async function getReportData(
ot.contractType,
o.contractStartDate,
o.contractEndDate
from BurialSiteContracts o
from Contracts o
left join ContractTypes ot on o.contractTypeId = ot.contractTypeId
left join BurialSites l on o.burialSiteId = l.burialSiteId
left join Cemeteries m on l.cemeteryId = m.cemeteryId
@ -148,32 +148,32 @@ export default async function getReportData(
break
}
case 'burialSiteContractComments-all': {
sql = 'select * from BurialSiteContractComments'
case 'contractComments-all': {
sql = 'select * from ContractComments'
break
}
case 'burialSiteContractFees-all': {
sql = 'select * from BurialSiteContractFees'
case 'contractFees-all': {
sql = 'select * from ContractFees'
break
}
case 'burialSiteContractFields-all': {
sql = 'select * from BurialSiteContractFields'
case 'contractFields-all': {
sql = 'select * from ContractFields'
break
}
case 'burialSiteContractTransactions-all': {
sql = 'select * from BurialSiteContractTransactions'
case 'contractTransactions-all': {
sql = 'select * from ContractTransactions'
break
}
case 'burialSiteContractTransactions-byTransactionDateString': {
sql = `select t.burialSiteContractId, t.transactionIndex,
case 'contractTransactions-byTransactionDateString': {
sql = `select t.contractId, t.transactionIndex,
t.transactionDate, t.transactionTime,
t.transactionAmount,
t.externalReceiptNumber, t.transactionNote
from BurialSiteContractTransactions t
from ContractTransactions t
where t.recordDelete_timeMillis is null
and t.transactionDate = ?`

View File

@ -1,6 +1,6 @@
import { dateIntegerToString } from '@cityssm/utils-datetime';
import getBurialSiteContracts from './getBurialSiteContracts.js';
import getBurialSites from './getBurialSites.js';
import getContracts from './getContracts.js';
import getWorkOrderComments from './getWorkOrderComments.js';
import getWorkOrderMilestones from './getWorkOrderMilestones.js';
import { acquireConnection } from './pool.js';
@ -24,10 +24,10 @@ async function _getWorkOrder(sql, workOrderIdOrWorkOrderNumber, options, connect
}, {
limit: -1,
offset: 0,
includeBurialSiteContractCount: false
includeContractCount: false
}, database);
workOrder.workOrderBurialSites = burialSiteResults.burialSites;
const workOrderBurialSiteContractsResults = await getBurialSiteContracts({
const workOrderContractsResults = await getContracts({
workOrderId: workOrder.workOrderId
}, {
limit: -1,
@ -36,8 +36,8 @@ async function _getWorkOrder(sql, workOrderIdOrWorkOrderNumber, options, connect
includeFees: false,
includeTransactions: false
}, database);
workOrder.workOrderBurialSiteContracts =
workOrderBurialSiteContractsResults.burialSiteContracts;
workOrder.workOrderContracts =
workOrderContractsResults.contracts;
}
if (options.includeComments) {
workOrder.workOrderComments = await getWorkOrderComments(workOrder.workOrderId, database);

View File

@ -3,8 +3,8 @@ import type { PoolConnection } from 'better-sqlite-pool'
import type { WorkOrder } from '../types/recordTypes.js'
import getBurialSiteContracts from './getBurialSiteContracts.js'
import getBurialSites from './getBurialSites.js'
import getContracts from './getContracts.js'
import getWorkOrderComments from './getWorkOrderComments.js'
import getWorkOrderMilestones from './getWorkOrderMilestones.js'
import { acquireConnection } from './pool.js'
@ -48,14 +48,14 @@ async function _getWorkOrder(
{
limit: -1,
offset: 0,
includeBurialSiteContractCount: false
includeContractCount: false
},
database
)
workOrder.workOrderBurialSites = burialSiteResults.burialSites
const workOrderBurialSiteContractsResults = await getBurialSiteContracts(
const workOrderContractsResults = await getContracts(
{
workOrderId: workOrder.workOrderId
},
@ -69,8 +69,8 @@ async function _getWorkOrder(
database
)
workOrder.workOrderBurialSiteContracts =
workOrderBurialSiteContractsResults.burialSiteContracts
workOrder.workOrderContracts =
workOrderContractsResults.contracts
}
if (options.includeComments) {

View File

@ -1,6 +1,6 @@
import { dateIntegerToString, dateStringToInteger, dateToInteger, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime';
import { getConfigProperty } from '../helpers/config.helpers.js';
import getBurialSiteContracts from './getBurialSiteContracts.js';
import getContracts from './getContracts.js';
import getBurialSites from './getBurialSites.js';
import { acquireConnection } from './pool.js';
// eslint-disable-next-line security/detect-unsafe-regex
@ -127,10 +127,10 @@ export default async function getWorkOrderMilestones(filters, options, connected
}, {
limit: -1,
offset: 0,
includeBurialSiteContractCount: false
includeContractCount: false
}, database);
workOrderMilestone.workOrderBurialSites = burialSites.burialSites;
const burialSiteContracts = await getBurialSiteContracts({
const contracts = await getContracts({
workOrderId: workOrderMilestone.workOrderId
}, {
limit: -1,
@ -139,8 +139,8 @@ export default async function getWorkOrderMilestones(filters, options, connected
includeFees: false,
includeTransactions: false
}, database);
workOrderMilestone.workOrderBurialSiteContracts =
burialSiteContracts.burialSiteContracts;
workOrderMilestone.workOrderContracts =
contracts.contracts;
}
}
if (connectedDatabase === undefined) {

View File

@ -11,7 +11,7 @@ import type { PoolConnection } from 'better-sqlite-pool'
import { getConfigProperty } from '../helpers/config.helpers.js'
import type { WorkOrderMilestone } from '../types/recordTypes.js'
import getBurialSiteContracts from './getBurialSiteContracts.js'
import getContracts from './getContracts.js'
import getBurialSites from './getBurialSites.js'
import { acquireConnection } from './pool.js'
@ -214,14 +214,14 @@ export default async function getWorkOrderMilestones(
{
limit: -1,
offset: 0,
includeBurialSiteContractCount: false
includeContractCount: false
},
database
)
workOrderMilestone.workOrderBurialSites = burialSites.burialSites
const burialSiteContracts = await getBurialSiteContracts(
const contracts = await getContracts(
{
workOrderId: workOrderMilestone.workOrderId
},
@ -235,8 +235,8 @@ export default async function getWorkOrderMilestones(
database
)
workOrderMilestone.workOrderBurialSiteContracts =
burialSiteContracts.burialSiteContracts
workOrderMilestone.workOrderContracts =
contracts.contracts
}
}

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