major refactoring
simplify by remove "burial site" from "burial site contracts"deepsource-autofix-76c6eb20
parent
a6524635c0
commit
414a45041c
|
|
@ -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>;
|
|
||||||
|
|
@ -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>;
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
export interface AddBurialSiteContractCategoryForm {
|
|
||||||
burialSiteContractId: number | string;
|
|
||||||
feeCategoryId: number | string;
|
|
||||||
}
|
|
||||||
export default function addBurialSiteContractFeeCategory(addFeeCategoryForm: AddBurialSiteContractCategoryForm, user: User): Promise<number>;
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import type { PoolConnection } from 'better-sqlite-pool';
|
import type { PoolConnection } from 'better-sqlite-pool';
|
||||||
export interface AddBurialSiteContractForm {
|
export interface AddContractForm {
|
||||||
contractTypeId: string | number;
|
contractTypeId: string | number;
|
||||||
burialSiteId: string | number;
|
burialSiteId: string | number;
|
||||||
contractStartDateString: string;
|
contractStartDateString: string;
|
||||||
|
|
@ -18,4 +18,4 @@ export interface AddBurialSiteContractForm {
|
||||||
occupantEmailAddress?: string;
|
occupantEmailAddress?: string;
|
||||||
occupantComment?: 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>;
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import { dateStringToInteger } from '@cityssm/utils-datetime';
|
import { dateStringToInteger } from '@cityssm/utils-datetime';
|
||||||
import addOrUpdateBurialSiteContractField from './addOrUpdateBurialSiteContractField.js';
|
import addOrUpdateContractField from './addOrUpdateContractField.js';
|
||||||
import { acquireConnection } from './pool.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 database = connectedDatabase ?? (await acquireConnection());
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
const contractStartDate = dateStringToInteger(addForm.contractStartDateString);
|
const contractStartDate = dateStringToInteger(addForm.contractStartDateString);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`insert into BurialSiteContracts (
|
.prepare(`insert into Contracts (
|
||||||
contractTypeId, lotId,
|
contractTypeId, lotId,
|
||||||
contractStartDate, contractEndDate,
|
contractStartDate, contractEndDate,
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
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 === ''
|
.run(addForm.contractTypeId, addForm.burialSiteId === '' ? undefined : addForm.burialSiteId, contractStartDate, addForm.contractEndDateString === ''
|
||||||
? undefined
|
? undefined
|
||||||
: dateStringToInteger(addForm.contractEndDateString), user.userName, rightNowMillis, user.userName, rightNowMillis);
|
: dateStringToInteger(addForm.contractEndDateString), user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||||
const burialSiteContractId = result.lastInsertRowid;
|
const contractId = result.lastInsertRowid;
|
||||||
const contractTypeFieldIds = (addForm.contractTypeFieldIds ?? '').split(',');
|
const contractTypeFieldIds = (addForm.contractTypeFieldIds ?? '').split(',');
|
||||||
for (const contractTypeFieldId of contractTypeFieldIds) {
|
for (const contractTypeFieldId of contractTypeFieldIds) {
|
||||||
const fieldValue = addForm[`fieldValue_${contractTypeFieldId}`];
|
const fieldValue = addForm[`fieldValue_${contractTypeFieldId}`];
|
||||||
if ((fieldValue ?? '') !== '') {
|
if ((fieldValue ?? '') !== '') {
|
||||||
await addOrUpdateBurialSiteContractField({
|
await addOrUpdateContractField({
|
||||||
burialSiteContractId,
|
contractId,
|
||||||
contractTypeFieldId,
|
contractTypeFieldId,
|
||||||
fieldValue: fieldValue ?? ''
|
fieldValue: fieldValue ?? ''
|
||||||
}, user, database);
|
}, user, database);
|
||||||
|
|
@ -30,5 +30,5 @@ export default async function addBurialSiteContract(addForm, user, connectedData
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release();
|
database.release();
|
||||||
}
|
}
|
||||||
return burialSiteContractId;
|
return contractId;
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { type DateString, dateStringToInteger } from '@cityssm/utils-datetime'
|
import { type DateString, dateStringToInteger } from '@cityssm/utils-datetime'
|
||||||
import type { PoolConnection } from 'better-sqlite-pool'
|
import type { PoolConnection } from 'better-sqlite-pool'
|
||||||
|
|
||||||
import addOrUpdateBurialSiteContractField from './addOrUpdateBurialSiteContractField.js'
|
import addOrUpdateContractField from './addOrUpdateContractField.js'
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export interface AddBurialSiteContractForm {
|
export interface AddContractForm {
|
||||||
contractTypeId: string | number
|
contractTypeId: string | number
|
||||||
burialSiteId: string | number
|
burialSiteId: string | number
|
||||||
|
|
||||||
|
|
@ -27,8 +27,8 @@ export interface AddBurialSiteContractForm {
|
||||||
occupantComment?: string
|
occupantComment?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function addBurialSiteContract(
|
export default async function addContract(
|
||||||
addForm: AddBurialSiteContractForm,
|
addForm: AddContractForm,
|
||||||
user: User,
|
user: User,
|
||||||
connectedDatabase?: PoolConnection
|
connectedDatabase?: PoolConnection
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
|
|
@ -42,7 +42,7 @@ export default async function addBurialSiteContract(
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`insert into BurialSiteContracts (
|
`insert into Contracts (
|
||||||
contractTypeId, lotId,
|
contractTypeId, lotId,
|
||||||
contractStartDate, contractEndDate,
|
contractStartDate, contractEndDate,
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
|
|
@ -62,7 +62,7 @@ export default async function addBurialSiteContract(
|
||||||
rightNowMillis
|
rightNowMillis
|
||||||
)
|
)
|
||||||
|
|
||||||
const burialSiteContractId = result.lastInsertRowid as number
|
const contractId = result.lastInsertRowid as number
|
||||||
|
|
||||||
const contractTypeFieldIds = (addForm.contractTypeFieldIds ?? '').split(',')
|
const contractTypeFieldIds = (addForm.contractTypeFieldIds ?? '').split(',')
|
||||||
|
|
||||||
|
|
@ -72,9 +72,9 @@ export default async function addBurialSiteContract(
|
||||||
| undefined
|
| undefined
|
||||||
|
|
||||||
if ((fieldValue ?? '') !== '') {
|
if ((fieldValue ?? '') !== '') {
|
||||||
await addOrUpdateBurialSiteContractField(
|
await addOrUpdateContractField(
|
||||||
{
|
{
|
||||||
burialSiteContractId,
|
contractId,
|
||||||
contractTypeFieldId,
|
contractTypeFieldId,
|
||||||
fieldValue: fieldValue ?? ''
|
fieldValue: fieldValue ?? ''
|
||||||
},
|
},
|
||||||
|
|
@ -88,5 +88,5 @@ export default async function addBurialSiteContract(
|
||||||
database.release()
|
database.release()
|
||||||
}
|
}
|
||||||
|
|
||||||
return burialSiteContractId
|
return contractId
|
||||||
}
|
}
|
||||||
|
|
@ -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>;
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { dateStringToInteger, dateToInteger, dateToTimeInteger, timeStringToInteger } from '@cityssm/utils-datetime';
|
import { dateStringToInteger, dateToInteger, dateToTimeInteger, timeStringToInteger } from '@cityssm/utils-datetime';
|
||||||
import { acquireConnection } from './pool.js';
|
import { acquireConnection } from './pool.js';
|
||||||
export default async function addBurialSiteContractComment(commentForm, user) {
|
export default async function addContractComment(commentForm, user) {
|
||||||
const rightNow = new Date();
|
const rightNow = new Date();
|
||||||
let commentDate = 0;
|
let commentDate = 0;
|
||||||
let commentTime = 0;
|
let commentTime = 0;
|
||||||
|
|
@ -15,13 +15,13 @@ export default async function addBurialSiteContractComment(commentForm, user) {
|
||||||
const database = await acquireConnection();
|
const database = await acquireConnection();
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`insert into BurialSiteContactComments (
|
.prepare(`insert into BurialSiteContactComments (
|
||||||
burialSiteContractId,
|
contractId,
|
||||||
commentDate, commentTime,
|
commentDate, commentTime,
|
||||||
comment,
|
comment,
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
recordUpdate_userName, recordUpdate_timeMillis)
|
||||||
values (?, ?, ?, ?, ?, ?, ?, ?)`)
|
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();
|
database.release();
|
||||||
return result.lastInsertRowid;
|
return result.lastInsertRowid;
|
||||||
}
|
}
|
||||||
|
|
@ -9,15 +9,15 @@ import {
|
||||||
|
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export interface AddBurialSiteContractCommentForm {
|
export interface AddContractCommentForm {
|
||||||
burialSiteContractId: string | number
|
contractId: string | number
|
||||||
commentDateString?: DateString
|
commentDateString?: DateString
|
||||||
commentTimeString?: TimeString
|
commentTimeString?: TimeString
|
||||||
comment: string
|
comment: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function addBurialSiteContractComment(
|
export default async function addContractComment(
|
||||||
commentForm: AddBurialSiteContractCommentForm,
|
commentForm: AddContractCommentForm,
|
||||||
user: User
|
user: User
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const rightNow = new Date()
|
const rightNow = new Date()
|
||||||
|
|
@ -42,7 +42,7 @@ export default async function addBurialSiteContractComment(
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`insert into BurialSiteContactComments (
|
`insert into BurialSiteContactComments (
|
||||||
burialSiteContractId,
|
contractId,
|
||||||
commentDate, commentTime,
|
commentDate, commentTime,
|
||||||
comment,
|
comment,
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
|
|
@ -50,7 +50,7 @@ export default async function addBurialSiteContractComment(
|
||||||
values (?, ?, ?, ?, ?, ?, ?, ?)`
|
values (?, ?, ?, ?, ?, ?, ?, ?)`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
commentForm.burialSiteContractId,
|
commentForm.contractId,
|
||||||
commentDate,
|
commentDate,
|
||||||
commentTime ?? 0,
|
commentTime ?? 0,
|
||||||
commentForm.comment,
|
commentForm.comment,
|
||||||
|
|
@ -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>;
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
import { calculateFeeAmount, calculateTaxAmount } from '../helpers/functions.fee.js';
|
import { calculateFeeAmount, calculateTaxAmount } from '../helpers/functions.fee.js';
|
||||||
import getBurialSiteContract from './getBurialSiteContract.js';
|
import getContract from './getContract.js';
|
||||||
import getFee from './getFee.js';
|
import getFee from './getFee.js';
|
||||||
import { acquireConnection } from './pool.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 database = connectedDatabase ?? (await acquireConnection());
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
// Calculate fee and tax (if not set)
|
// Calculate fee and tax (if not set)
|
||||||
let feeAmount;
|
let feeAmount;
|
||||||
let taxAmount;
|
let taxAmount;
|
||||||
if ((addFeeForm.feeAmount ?? '') === '') {
|
if ((addFeeForm.feeAmount ?? '') === '') {
|
||||||
const burialSiteContract = (await getBurialSiteContract(addFeeForm.burialSiteContractId));
|
const contract = (await getContract(addFeeForm.contractId));
|
||||||
const fee = (await getFee(addFeeForm.feeId));
|
const fee = (await getFee(addFeeForm.feeId));
|
||||||
feeAmount = calculateFeeAmount(fee, burialSiteContract);
|
feeAmount = calculateFeeAmount(fee, contract);
|
||||||
taxAmount = calculateTaxAmount(fee, feeAmount);
|
taxAmount = calculateTaxAmount(fee, feeAmount);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -28,29 +28,29 @@ export default async function addBurialSiteContractFee(addFeeForm, user, connect
|
||||||
// Check if record already exists
|
// Check if record already exists
|
||||||
const record = database
|
const record = database
|
||||||
.prepare(`select feeAmount, taxAmount, recordDelete_timeMillis
|
.prepare(`select feeAmount, taxAmount, recordDelete_timeMillis
|
||||||
from BurialSiteContractFees
|
from ContractFees
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and feeId = ?`)
|
and feeId = ?`)
|
||||||
.get(addFeeForm.burialSiteContractId, addFeeForm.feeId);
|
.get(addFeeForm.contractId, addFeeForm.feeId);
|
||||||
if (record !== undefined) {
|
if (record !== undefined) {
|
||||||
if (record.recordDelete_timeMillis !== null) {
|
if (record.recordDelete_timeMillis !== null) {
|
||||||
database
|
database
|
||||||
.prepare(`delete from BurialSiteContractFees
|
.prepare(`delete from ContractFees
|
||||||
where recordDelete_timeMillis is not null
|
where recordDelete_timeMillis is not null
|
||||||
and burialSiteContractId = ?
|
and contractId = ?
|
||||||
and feeId = ?`)
|
and feeId = ?`)
|
||||||
.run(addFeeForm.burialSiteContractId, addFeeForm.feeId);
|
.run(addFeeForm.contractId, addFeeForm.feeId);
|
||||||
}
|
}
|
||||||
else if (record.feeAmount === feeAmount &&
|
else if (record.feeAmount === feeAmount &&
|
||||||
record.taxAmount === taxAmount) {
|
record.taxAmount === taxAmount) {
|
||||||
database
|
database
|
||||||
.prepare(`update BurialSiteContractFees
|
.prepare(`update ContractFees
|
||||||
set quantity = quantity + ?,
|
set quantity = quantity + ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and feeId = ?`)
|
and feeId = ?`)
|
||||||
.run(addFeeForm.quantity, user.userName, rightNowMillis, addFeeForm.burialSiteContractId, addFeeForm.feeId);
|
.run(addFeeForm.quantity, user.userName, rightNowMillis, addFeeForm.contractId, addFeeForm.feeId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -58,27 +58,27 @@ export default async function addBurialSiteContractFee(addFeeForm, user, connect
|
||||||
? Number.parseFloat(addFeeForm.quantity)
|
? Number.parseFloat(addFeeForm.quantity)
|
||||||
: addFeeForm.quantity;
|
: addFeeForm.quantity;
|
||||||
database
|
database
|
||||||
.prepare(`update BurialSiteContractFees
|
.prepare(`update ContractFees
|
||||||
set feeAmount = (feeAmount * quantity) + ?,
|
set feeAmount = (feeAmount * quantity) + ?,
|
||||||
taxAmount = (taxAmount * quantity) + ?,
|
taxAmount = (taxAmount * quantity) + ?,
|
||||||
quantity = 1,
|
quantity = 1,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and feeId = ?`)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Create new record
|
// Create new record
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`insert into BurialSiteContractFees (
|
.prepare(`insert into ContractFees (
|
||||||
burialSiteContractId, feeId,
|
contractId, feeId,
|
||||||
quantity, feeAmount, taxAmount,
|
quantity, feeAmount, taxAmount,
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
recordUpdate_userName, recordUpdate_timeMillis)
|
||||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
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;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|
@ -4,22 +4,22 @@ import {
|
||||||
calculateFeeAmount,
|
calculateFeeAmount,
|
||||||
calculateTaxAmount
|
calculateTaxAmount
|
||||||
} from '../helpers/functions.fee.js'
|
} 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 getFee from './getFee.js'
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export interface AddBurialSiteContractFeeForm {
|
export interface AddContractFeeForm {
|
||||||
burialSiteContractId: number | string
|
contractId: number | string
|
||||||
feeId: number | string
|
feeId: number | string
|
||||||
quantity: number | string
|
quantity: number | string
|
||||||
feeAmount?: number | string
|
feeAmount?: number | string
|
||||||
taxAmount?: number | string
|
taxAmount?: number | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function addBurialSiteContractFee(
|
export default async function addContractFee(
|
||||||
addFeeForm: AddBurialSiteContractFeeForm,
|
addFeeForm: AddContractFeeForm,
|
||||||
user: User,
|
user: User,
|
||||||
connectedDatabase?: PoolConnection
|
connectedDatabase?: PoolConnection
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
|
@ -32,13 +32,13 @@ export default async function addBurialSiteContractFee(
|
||||||
let taxAmount: number
|
let taxAmount: number
|
||||||
|
|
||||||
if ((addFeeForm.feeAmount ?? '') === '') {
|
if ((addFeeForm.feeAmount ?? '') === '') {
|
||||||
const burialSiteContract = (await getBurialSiteContract(
|
const contract = (await getContract(
|
||||||
addFeeForm.burialSiteContractId
|
addFeeForm.contractId
|
||||||
)) as BurialSiteContract
|
)) as Contract
|
||||||
|
|
||||||
const fee = (await getFee(addFeeForm.feeId)) as Fee
|
const fee = (await getFee(addFeeForm.feeId)) as Fee
|
||||||
|
|
||||||
feeAmount = calculateFeeAmount(fee, burialSiteContract)
|
feeAmount = calculateFeeAmount(fee, contract)
|
||||||
taxAmount = calculateTaxAmount(fee, feeAmount)
|
taxAmount = calculateTaxAmount(fee, feeAmount)
|
||||||
} else {
|
} else {
|
||||||
feeAmount =
|
feeAmount =
|
||||||
|
|
@ -56,11 +56,11 @@ export default async function addBurialSiteContractFee(
|
||||||
const record = database
|
const record = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select feeAmount, taxAmount, recordDelete_timeMillis
|
`select feeAmount, taxAmount, recordDelete_timeMillis
|
||||||
from BurialSiteContractFees
|
from ContractFees
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and feeId = ?`
|
and feeId = ?`
|
||||||
)
|
)
|
||||||
.get(addFeeForm.burialSiteContractId, addFeeForm.feeId) as
|
.get(addFeeForm.contractId, addFeeForm.feeId) as
|
||||||
| {
|
| {
|
||||||
feeAmount: number | null
|
feeAmount: number | null
|
||||||
taxAmount: number | null
|
taxAmount: number | null
|
||||||
|
|
@ -72,30 +72,30 @@ export default async function addBurialSiteContractFee(
|
||||||
if (record.recordDelete_timeMillis !== null) {
|
if (record.recordDelete_timeMillis !== null) {
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from BurialSiteContractFees
|
`delete from ContractFees
|
||||||
where recordDelete_timeMillis is not null
|
where recordDelete_timeMillis is not null
|
||||||
and burialSiteContractId = ?
|
and contractId = ?
|
||||||
and feeId = ?`
|
and feeId = ?`
|
||||||
)
|
)
|
||||||
.run(addFeeForm.burialSiteContractId, addFeeForm.feeId)
|
.run(addFeeForm.contractId, addFeeForm.feeId)
|
||||||
} else if (
|
} else if (
|
||||||
record.feeAmount === feeAmount &&
|
record.feeAmount === feeAmount &&
|
||||||
record.taxAmount === taxAmount
|
record.taxAmount === taxAmount
|
||||||
) {
|
) {
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSiteContractFees
|
`update ContractFees
|
||||||
set quantity = quantity + ?,
|
set quantity = quantity + ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and feeId = ?`
|
and feeId = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
addFeeForm.quantity,
|
addFeeForm.quantity,
|
||||||
user.userName,
|
user.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
addFeeForm.burialSiteContractId,
|
addFeeForm.contractId,
|
||||||
addFeeForm.feeId
|
addFeeForm.feeId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -108,13 +108,13 @@ export default async function addBurialSiteContractFee(
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSiteContractFees
|
`update ContractFees
|
||||||
set feeAmount = (feeAmount * quantity) + ?,
|
set feeAmount = (feeAmount * quantity) + ?,
|
||||||
taxAmount = (taxAmount * quantity) + ?,
|
taxAmount = (taxAmount * quantity) + ?,
|
||||||
quantity = 1,
|
quantity = 1,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and feeId = ?`
|
and feeId = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
|
|
@ -122,7 +122,7 @@ export default async function addBurialSiteContractFee(
|
||||||
taxAmount * quantity,
|
taxAmount * quantity,
|
||||||
user.userName,
|
user.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
addFeeForm.burialSiteContractId,
|
addFeeForm.contractId,
|
||||||
addFeeForm.feeId
|
addFeeForm.feeId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -133,15 +133,15 @@ export default async function addBurialSiteContractFee(
|
||||||
// Create new record
|
// Create new record
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`insert into BurialSiteContractFees (
|
`insert into ContractFees (
|
||||||
burialSiteContractId, feeId,
|
contractId, feeId,
|
||||||
quantity, feeAmount, taxAmount,
|
quantity, feeAmount, taxAmount,
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
recordUpdate_userName, recordUpdate_timeMillis)
|
||||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
values (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
addFeeForm.burialSiteContractId,
|
addFeeForm.contractId,
|
||||||
addFeeForm.feeId,
|
addFeeForm.feeId,
|
||||||
addFeeForm.quantity,
|
addFeeForm.quantity,
|
||||||
feeAmount,
|
feeAmount,
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
export interface AddContractCategoryForm {
|
||||||
|
contractId: number | string;
|
||||||
|
feeCategoryId: number | string;
|
||||||
|
}
|
||||||
|
export default function addContractFeeCategory(addFeeCategoryForm: AddContractCategoryForm, user: User): Promise<number>;
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import addBurialSiteContractFee from './addBurialSiteContractFee.js';
|
import addContractFee from './addContractFee.js';
|
||||||
import { getFeeCategory } from './getFeeCategories.js';
|
import { getFeeCategory } from './getFeeCategories.js';
|
||||||
import { acquireConnection } from './pool.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 database = await acquireConnection();
|
||||||
const feeCategory = await getFeeCategory(addFeeCategoryForm.feeCategoryId, database);
|
const feeCategory = await getFeeCategory(addFeeCategoryForm.feeCategoryId, database);
|
||||||
let addedFeeCount = 0;
|
let addedFeeCount = 0;
|
||||||
for (const fee of feeCategory?.fees ?? []) {
|
for (const fee of feeCategory?.fees ?? []) {
|
||||||
const success = await addBurialSiteContractFee({
|
const success = await addContractFee({
|
||||||
burialSiteContractId: addFeeCategoryForm.burialSiteContractId,
|
contractId: addFeeCategoryForm.contractId,
|
||||||
feeId: fee.feeId,
|
feeId: fee.feeId,
|
||||||
quantity: 1
|
quantity: 1
|
||||||
}, user, database);
|
}, user, database);
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
import addBurialSiteContractFee from './addBurialSiteContractFee.js'
|
import addContractFee from './addContractFee.js'
|
||||||
import { getFeeCategory } from './getFeeCategories.js'
|
import { getFeeCategory } from './getFeeCategories.js'
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export interface AddBurialSiteContractCategoryForm {
|
export interface AddContractCategoryForm {
|
||||||
burialSiteContractId: number | string
|
contractId: number | string
|
||||||
feeCategoryId: number | string
|
feeCategoryId: number | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function addBurialSiteContractFeeCategory(
|
export default async function addContractFeeCategory(
|
||||||
addFeeCategoryForm: AddBurialSiteContractCategoryForm,
|
addFeeCategoryForm: AddContractCategoryForm,
|
||||||
user: User
|
user: User
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const database = await acquireConnection()
|
const database = await acquireConnection()
|
||||||
|
|
@ -21,9 +21,9 @@ export default async function addBurialSiteContractFeeCategory(
|
||||||
let addedFeeCount = 0
|
let addedFeeCount = 0
|
||||||
|
|
||||||
for (const fee of feeCategory?.fees ?? []) {
|
for (const fee of feeCategory?.fees ?? []) {
|
||||||
const success = await addBurialSiteContractFee(
|
const success = await addContractFee(
|
||||||
{
|
{
|
||||||
burialSiteContractId: addFeeCategoryForm.burialSiteContractId,
|
contractId: addFeeCategoryForm.contractId,
|
||||||
feeId: fee.feeId,
|
feeId: fee.feeId,
|
||||||
quantity: 1
|
quantity: 1
|
||||||
},
|
},
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
export interface AddTransactionForm {
|
export interface AddTransactionForm {
|
||||||
burialSiteContractId: string | number;
|
contractId: string | number;
|
||||||
transactionDateString?: string;
|
transactionDateString?: string;
|
||||||
transactionTimeString?: string;
|
transactionTimeString?: string;
|
||||||
transactionAmount: string | number;
|
transactionAmount: string | number;
|
||||||
externalReceiptNumber: string;
|
externalReceiptNumber: string;
|
||||||
transactionNote: string;
|
transactionNote: string;
|
||||||
}
|
}
|
||||||
export default function addBurialSiteContractTransaction(burialSiteContractTransactionForm: AddTransactionForm, user: User): Promise<number>;
|
export default function addContractTransaction(contractTransactionForm: AddTransactionForm, user: User): Promise<number>;
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ import {
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export interface AddTransactionForm {
|
export interface AddTransactionForm {
|
||||||
burialSiteContractId: string | number
|
contractId: string | number
|
||||||
transactionDateString?: string
|
transactionDateString?: string
|
||||||
transactionTimeString?: string
|
transactionTimeString?: string
|
||||||
transactionAmount: string | number
|
transactionAmount: string | number
|
||||||
|
|
@ -16,8 +16,8 @@ export interface AddTransactionForm {
|
||||||
transactionNote: string
|
transactionNote: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function addBurialSiteContractTransaction(
|
export default async function addContractTransaction(
|
||||||
burialSiteContractTransactionForm: AddTransactionForm,
|
contractTransactionForm: AddTransactionForm,
|
||||||
user: User
|
user: User
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const database = await acquireConnection()
|
const database = await acquireConnection()
|
||||||
|
|
@ -27,12 +27,12 @@ export default async function addBurialSiteContractTransaction(
|
||||||
const maxIndexResult = database
|
const maxIndexResult = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select transactionIndex
|
`select transactionIndex
|
||||||
from BurialSiteContractTransactions
|
from ContractTransactions
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
order by transactionIndex desc
|
order by transactionIndex desc
|
||||||
limit 1`
|
limit 1`
|
||||||
)
|
)
|
||||||
.get(burialSiteContractTransactionForm.burialSiteContractId) as
|
.get(contractTransactionForm.contractId) as
|
||||||
| { transactionIndex: number }
|
| { transactionIndex: number }
|
||||||
| undefined
|
| undefined
|
||||||
|
|
||||||
|
|
@ -42,18 +42,18 @@ export default async function addBurialSiteContractTransaction(
|
||||||
|
|
||||||
const rightNow = new Date()
|
const rightNow = new Date()
|
||||||
|
|
||||||
const transactionDate = burialSiteContractTransactionForm.transactionDateString
|
const transactionDate = contractTransactionForm.transactionDateString
|
||||||
? dateStringToInteger(burialSiteContractTransactionForm.transactionDateString)
|
? dateStringToInteger(contractTransactionForm.transactionDateString)
|
||||||
: dateToInteger(rightNow)
|
: dateToInteger(rightNow)
|
||||||
|
|
||||||
const transactionTime = burialSiteContractTransactionForm.transactionTimeString
|
const transactionTime = contractTransactionForm.transactionTimeString
|
||||||
? timeStringToInteger(burialSiteContractTransactionForm.transactionTimeString)
|
? timeStringToInteger(contractTransactionForm.transactionTimeString)
|
||||||
: dateToTimeInteger(rightNow)
|
: dateToTimeInteger(rightNow)
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`insert into BurialSiteContractTransactions (
|
`insert into ContractTransactions (
|
||||||
burialSiteContractId, transactionIndex,
|
contractId, transactionIndex,
|
||||||
transactionDate, transactionTime,
|
transactionDate, transactionTime,
|
||||||
transactionAmount, externalReceiptNumber, transactionNote,
|
transactionAmount, externalReceiptNumber, transactionNote,
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
|
|
@ -61,13 +61,13 @@ export default async function addBurialSiteContractTransaction(
|
||||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
burialSiteContractTransactionForm.burialSiteContractId,
|
contractTransactionForm.contractId,
|
||||||
transactionIndex,
|
transactionIndex,
|
||||||
transactionDate,
|
transactionDate,
|
||||||
transactionTime,
|
transactionTime,
|
||||||
burialSiteContractTransactionForm.transactionAmount,
|
contractTransactionForm.transactionAmount,
|
||||||
burialSiteContractTransactionForm.externalReceiptNumber,
|
contractTransactionForm.externalReceiptNumber,
|
||||||
burialSiteContractTransactionForm.transactionNote,
|
contractTransactionForm.transactionNote,
|
||||||
user.userName,
|
user.userName,
|
||||||
rightNow.getTime(),
|
rightNow.getTime(),
|
||||||
user.userName,
|
user.userName,
|
||||||
|
|
@ -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>;
|
|
||||||
|
|
@ -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>;
|
||||||
|
|
@ -1,25 +1,25 @@
|
||||||
import { acquireConnection } from './pool.js';
|
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 database = connectedDatabase ?? (await acquireConnection());
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
let result = database
|
let result = database
|
||||||
.prepare(`update BurialSiteContractFields
|
.prepare(`update ContractFields
|
||||||
set fieldValue = ?,
|
set fieldValue = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?,
|
recordUpdate_timeMillis = ?,
|
||||||
recordDelete_userName = null,
|
recordDelete_userName = null,
|
||||||
recordDelete_timeMillis = null
|
recordDelete_timeMillis = null
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and contractTypeFieldId = ?`)
|
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) {
|
if (result.changes === 0) {
|
||||||
result = database
|
result = database
|
||||||
.prepare(`insert into BurialSiteContractFields (
|
.prepare(`insert into ContractFields (
|
||||||
burialSiteContractId, contractTypeFieldId, fieldValue,
|
contractId, contractTypeFieldId, fieldValue,
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
recordUpdate_userName, recordUpdate_timeMillis)
|
||||||
values (?, ?, ?, ?, ?, ?, ?)`)
|
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) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release();
|
database.release();
|
||||||
|
|
@ -2,14 +2,14 @@ import type { PoolConnection } from 'better-sqlite-pool'
|
||||||
|
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export interface BurialSiteContractFieldForm {
|
export interface ContractFieldForm {
|
||||||
burialSiteContractId: string | number
|
contractId: string | number
|
||||||
contractTypeFieldId: string | number
|
contractTypeFieldId: string | number
|
||||||
fieldValue: string
|
fieldValue: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function addOrUpdateBurialSiteContractField(
|
export default async function addOrUpdateContractField(
|
||||||
fieldForm: BurialSiteContractFieldForm,
|
fieldForm: ContractFieldForm,
|
||||||
user: User,
|
user: User,
|
||||||
connectedDatabase?: PoolConnection
|
connectedDatabase?: PoolConnection
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
|
@ -19,34 +19,34 @@ export default async function addOrUpdateBurialSiteContractField(
|
||||||
|
|
||||||
let result = database
|
let result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSiteContractFields
|
`update ContractFields
|
||||||
set fieldValue = ?,
|
set fieldValue = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?,
|
recordUpdate_timeMillis = ?,
|
||||||
recordDelete_userName = null,
|
recordDelete_userName = null,
|
||||||
recordDelete_timeMillis = null
|
recordDelete_timeMillis = null
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and contractTypeFieldId = ?`
|
and contractTypeFieldId = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
fieldForm.fieldValue,
|
fieldForm.fieldValue,
|
||||||
user.userName,
|
user.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
fieldForm.burialSiteContractId,
|
fieldForm.contractId,
|
||||||
fieldForm.contractTypeFieldId
|
fieldForm.contractTypeFieldId
|
||||||
)
|
)
|
||||||
|
|
||||||
if (result.changes === 0) {
|
if (result.changes === 0) {
|
||||||
result = database
|
result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`insert into BurialSiteContractFields (
|
`insert into ContractFields (
|
||||||
burialSiteContractId, contractTypeFieldId, fieldValue,
|
contractId, contractTypeFieldId, fieldValue,
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
recordUpdate_userName, recordUpdate_timeMillis)
|
||||||
values (?, ?, ?, ?, ?, ?, ?)`
|
values (?, ?, ?, ?, ?, ?, ?)`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
fieldForm.burialSiteContractId,
|
fieldForm.contractId,
|
||||||
fieldForm.contractTypeFieldId,
|
fieldForm.contractTypeFieldId,
|
||||||
fieldForm.fieldValue,
|
fieldForm.fieldValue,
|
||||||
user.userName,
|
user.userName,
|
||||||
|
|
@ -4,6 +4,6 @@ export interface AddWorkOrderForm {
|
||||||
workOrderDescription: string;
|
workOrderDescription: string;
|
||||||
workOrderOpenDateString?: string;
|
workOrderOpenDateString?: string;
|
||||||
workOrderCloseDateString?: string;
|
workOrderCloseDateString?: string;
|
||||||
burialSiteContractId?: string;
|
contractId?: string;
|
||||||
}
|
}
|
||||||
export default function addWorkOrder(workOrderForm: AddWorkOrderForm, user: User): Promise<number>;
|
export default function addWorkOrder(workOrderForm: AddWorkOrderForm, user: User): Promise<number>;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { dateStringToInteger, dateToInteger } from '@cityssm/utils-datetime';
|
import { dateStringToInteger, dateToInteger } from '@cityssm/utils-datetime';
|
||||||
import addWorkOrderBurialSiteContract from './addWorkOrderBurialSiteContract.js';
|
import addWorkOrderContract from './addWorkOrderContract.js';
|
||||||
import getNextWorkOrderNumber from './getNextWorkOrderNumber.js';
|
import getNextWorkOrderNumber from './getNextWorkOrderNumber.js';
|
||||||
import { acquireConnection } from './pool.js';
|
import { acquireConnection } from './pool.js';
|
||||||
export default async function addWorkOrder(workOrderForm, user) {
|
export default async function addWorkOrder(workOrderForm, user) {
|
||||||
|
|
@ -22,10 +22,10 @@ export default async function addWorkOrder(workOrderForm, user) {
|
||||||
? undefined
|
? undefined
|
||||||
: dateStringToInteger(workOrderForm.workOrderCloseDateString), user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
|
: dateStringToInteger(workOrderForm.workOrderCloseDateString), user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
|
||||||
const workOrderId = result.lastInsertRowid;
|
const workOrderId = result.lastInsertRowid;
|
||||||
if ((workOrderForm.burialSiteContractId ?? '') !== '') {
|
if ((workOrderForm.contractId ?? '') !== '') {
|
||||||
await addWorkOrderBurialSiteContract({
|
await addWorkOrderContract({
|
||||||
workOrderId,
|
workOrderId,
|
||||||
burialSiteContractId: workOrderForm.burialSiteContractId
|
contractId: workOrderForm.contractId
|
||||||
}, user, database);
|
}, user, database);
|
||||||
}
|
}
|
||||||
database.release();
|
database.release();
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import {
|
||||||
dateToInteger
|
dateToInteger
|
||||||
} from '@cityssm/utils-datetime'
|
} from '@cityssm/utils-datetime'
|
||||||
|
|
||||||
import addWorkOrderBurialSiteContract from './addWorkOrderBurialSiteContract.js'
|
import addWorkOrderContract from './addWorkOrderContract.js'
|
||||||
import getNextWorkOrderNumber from './getNextWorkOrderNumber.js'
|
import getNextWorkOrderNumber from './getNextWorkOrderNumber.js'
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@ export interface AddWorkOrderForm {
|
||||||
workOrderDescription: string
|
workOrderDescription: string
|
||||||
workOrderOpenDateString?: string
|
workOrderOpenDateString?: string
|
||||||
workOrderCloseDateString?: string
|
workOrderCloseDateString?: string
|
||||||
burialSiteContractId?: string
|
contractId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function addWorkOrder(
|
export default async function addWorkOrder(
|
||||||
|
|
@ -62,11 +62,11 @@ export default async function addWorkOrder(
|
||||||
|
|
||||||
const workOrderId = result.lastInsertRowid as number
|
const workOrderId = result.lastInsertRowid as number
|
||||||
|
|
||||||
if ((workOrderForm.burialSiteContractId ?? '') !== '') {
|
if ((workOrderForm.contractId ?? '') !== '') {
|
||||||
await addWorkOrderBurialSiteContract(
|
await addWorkOrderContract(
|
||||||
{
|
{
|
||||||
workOrderId,
|
workOrderId,
|
||||||
burialSiteContractId: workOrderForm.burialSiteContractId as string
|
contractId: workOrderForm.contractId as string
|
||||||
},
|
},
|
||||||
user,
|
user,
|
||||||
database
|
database
|
||||||
|
|
|
||||||
|
|
@ -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>;
|
|
||||||
|
|
@ -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>;
|
||||||
|
|
@ -1,27 +1,27 @@
|
||||||
import { acquireConnection } from './pool.js';
|
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 database = connectedDatabase ?? (await acquireConnection());
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
const recordDeleteTimeMillis = database
|
const recordDeleteTimeMillis = database
|
||||||
.prepare(`select recordDelete_timeMillis
|
.prepare(`select recordDelete_timeMillis
|
||||||
from WorkOrderBurialSiteContracts
|
from WorkOrderContracts
|
||||||
where workOrderId = ?
|
where workOrderId = ?
|
||||||
and burialSiteContractId = ?`)
|
and contractId = ?`)
|
||||||
.pluck()
|
.pluck()
|
||||||
.get(addForm.workOrderId, addForm.burialSiteContractId);
|
.get(addForm.workOrderId, addForm.contractId);
|
||||||
if (recordDeleteTimeMillis === undefined) {
|
if (recordDeleteTimeMillis === undefined) {
|
||||||
database
|
database
|
||||||
.prepare(`insert into WorkOrderBurialSiteContracts (
|
.prepare(`insert into WorkOrderContracts (
|
||||||
workOrderId, burialSiteContractId,
|
workOrderId, contractId,
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
recordUpdate_userName, recordUpdate_timeMillis)
|
||||||
values (?, ?, ?, ?, ?, ?)`)
|
values (?, ?, ?, ?, ?, ?)`)
|
||||||
.run(addForm.workOrderId, addForm.burialSiteContractId, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
.run(addForm.workOrderId, addForm.contractId, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (recordDeleteTimeMillis !== null) {
|
if (recordDeleteTimeMillis !== null) {
|
||||||
database
|
database
|
||||||
.prepare(`update WorkOrderBurialSiteContracts
|
.prepare(`update WorkOrderContracts
|
||||||
set recordCreate_userName = ?,
|
set recordCreate_userName = ?,
|
||||||
recordCreate_timeMillis = ?,
|
recordCreate_timeMillis = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
|
|
@ -29,8 +29,8 @@ export default async function addWorkOrderBurialSiteContract(addForm, user, conn
|
||||||
recordDelete_userName = null,
|
recordDelete_userName = null,
|
||||||
recordDelete_timeMillis = null
|
recordDelete_timeMillis = null
|
||||||
where workOrderId = ?
|
where workOrderId = ?
|
||||||
and burialSiteContractId = ?`)
|
and contractId = ?`)
|
||||||
.run(user.userName, rightNowMillis, user.userName, rightNowMillis, addForm.workOrderId, addForm.burialSiteContractId);
|
.run(user.userName, rightNowMillis, user.userName, rightNowMillis, addForm.workOrderId, addForm.contractId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
|
|
@ -2,13 +2,13 @@ import type { PoolConnection } from 'better-sqlite-pool'
|
||||||
|
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export interface AddWorkOrderBurialSiteContractOccupancyForm {
|
export interface AddWorkOrderContractOccupancyForm {
|
||||||
workOrderId: number | string
|
workOrderId: number | string
|
||||||
burialSiteContractId: number | string
|
contractId: number | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function addWorkOrderBurialSiteContract(
|
export default async function addWorkOrderContract(
|
||||||
addForm: AddWorkOrderBurialSiteContractOccupancyForm,
|
addForm: AddWorkOrderContractOccupancyForm,
|
||||||
user: User,
|
user: User,
|
||||||
connectedDatabase?: PoolConnection
|
connectedDatabase?: PoolConnection
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
|
@ -19,28 +19,28 @@ export default async function addWorkOrderBurialSiteContract(
|
||||||
const recordDeleteTimeMillis: number | null | undefined = database
|
const recordDeleteTimeMillis: number | null | undefined = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select recordDelete_timeMillis
|
`select recordDelete_timeMillis
|
||||||
from WorkOrderBurialSiteContracts
|
from WorkOrderContracts
|
||||||
where workOrderId = ?
|
where workOrderId = ?
|
||||||
and burialSiteContractId = ?`
|
and contractId = ?`
|
||||||
)
|
)
|
||||||
.pluck()
|
.pluck()
|
||||||
.get(
|
.get(
|
||||||
addForm.workOrderId,
|
addForm.workOrderId,
|
||||||
addForm.burialSiteContractId
|
addForm.contractId
|
||||||
) as number | null | undefined
|
) as number | null | undefined
|
||||||
|
|
||||||
if (recordDeleteTimeMillis === undefined) {
|
if (recordDeleteTimeMillis === undefined) {
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`insert into WorkOrderBurialSiteContracts (
|
`insert into WorkOrderContracts (
|
||||||
workOrderId, burialSiteContractId,
|
workOrderId, contractId,
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
recordUpdate_userName, recordUpdate_timeMillis)
|
||||||
values (?, ?, ?, ?, ?, ?)`
|
values (?, ?, ?, ?, ?, ?)`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
addForm.workOrderId,
|
addForm.workOrderId,
|
||||||
addForm.burialSiteContractId,
|
addForm.contractId,
|
||||||
user.userName,
|
user.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
user.userName,
|
user.userName,
|
||||||
|
|
@ -50,7 +50,7 @@ export default async function addWorkOrderBurialSiteContract(
|
||||||
if (recordDeleteTimeMillis !== null) {
|
if (recordDeleteTimeMillis !== null) {
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrderBurialSiteContracts
|
`update WorkOrderContracts
|
||||||
set recordCreate_userName = ?,
|
set recordCreate_userName = ?,
|
||||||
recordCreate_timeMillis = ?,
|
recordCreate_timeMillis = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
|
|
@ -58,7 +58,7 @@ export default async function addWorkOrderBurialSiteContract(
|
||||||
recordDelete_userName = null,
|
recordDelete_userName = null,
|
||||||
recordDelete_timeMillis = null
|
recordDelete_timeMillis = null
|
||||||
where workOrderId = ?
|
where workOrderId = ?
|
||||||
and burialSiteContractId = ?`
|
and contractId = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
user.userName,
|
user.userName,
|
||||||
|
|
@ -66,7 +66,7 @@ export default async function addWorkOrderBurialSiteContract(
|
||||||
user.userName,
|
user.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
addForm.workOrderId,
|
addForm.workOrderId,
|
||||||
addForm.burialSiteContractId
|
addForm.contractId
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,7 +26,7 @@ export default async function cleanupDatabase(user) {
|
||||||
* Work Order Burial Site Contracts
|
* Work Order Burial Site Contracts
|
||||||
*/
|
*/
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update WorkOrderBurialSiteContracts
|
.prepare(`update WorkOrderContracts
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
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)`)
|
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from WorkOrderBurialSiteContracts where recordDelete_timeMillis <= ?')
|
.prepare('delete from WorkOrderContracts where recordDelete_timeMillis <= ?')
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Work Order Burial Sites
|
* Work Order Burial Sites
|
||||||
|
|
@ -71,7 +71,7 @@ export default async function cleanupDatabase(user) {
|
||||||
.prepare(`delete from WorkOrders
|
.prepare(`delete from WorkOrders
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and workOrderId not in (select workOrderId from WorkOrderComments)
|
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 WorkOrderBurialSites)
|
||||||
and workOrderId not in (select workOrderId from WorkOrderMilestones)`)
|
and workOrderId not in (select workOrderId from WorkOrderMilestones)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
|
|
@ -96,51 +96,51 @@ export default async function cleanupDatabase(user) {
|
||||||
* Burial Site Contract Comments
|
* Burial Site Contract Comments
|
||||||
*/
|
*/
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update BurialSiteContractComments
|
.prepare(`update ContractComments
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and burialSiteContractId in (
|
and contractId in (
|
||||||
select burialSiteContractId from BurialSiteContracts where recordDelete_timeMillis is not null)`)
|
select contractId from Contracts where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from BurialSiteContractComments where recordDelete_timeMillis <= ?')
|
.prepare('delete from ContractComments where recordDelete_timeMillis <= ?')
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Burial Site Contract Fields
|
* Burial Site Contract Fields
|
||||||
*/
|
*/
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update BurialSiteContractFields
|
.prepare(`update ContractFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
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;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from BurialSiteContractFields where recordDelete_timeMillis <= ?')
|
.prepare('delete from ContractFields where recordDelete_timeMillis <= ?')
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Burial Site Contract Fees/Transactions
|
* Burial Site Contract Fees/Transactions
|
||||||
* - Maintain financials, do not delete related.
|
* - Maintain financials, do not delete related.
|
||||||
*/
|
*/
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from BurialSiteContractFees where recordDelete_timeMillis <= ?')
|
.prepare('delete from ContractFees where recordDelete_timeMillis <= ?')
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from BurialSiteContractTransactions where recordDelete_timeMillis <= ?')
|
.prepare('delete from ContractTransactions where recordDelete_timeMillis <= ?')
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Burial Site Contracts
|
* Burial Site Contracts
|
||||||
*/
|
*/
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from BurialSiteContracts
|
.prepare(`delete from Contracts
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractComments)
|
and contractId not in (select contractId from ContractComments)
|
||||||
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractFees)
|
and contractId not in (select contractId from ContractFees)
|
||||||
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractFields)
|
and contractId not in (select contractId from ContractFields)
|
||||||
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractInterments)
|
and contractId not in (select contractId from ContractInterments)
|
||||||
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractTransactions)
|
and contractId not in (select contractId from ContractTransactions)
|
||||||
and burialSiteContractId not in (select burialSiteContractId from WorkOrderBurialSiteContracts)`)
|
and contractId not in (select contractId from WorkOrderContracts)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Fees
|
* Fees
|
||||||
|
|
@ -155,7 +155,7 @@ export default async function cleanupDatabase(user) {
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from Fees
|
.prepare(`delete from Fees
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and feeId not in (select feeId from BurialSiteContractFees)`)
|
and feeId not in (select feeId from ContractFees)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Fee Categories
|
* Fee Categories
|
||||||
|
|
@ -178,7 +178,7 @@ export default async function cleanupDatabase(user) {
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from ContractTypeFields
|
.prepare(`delete from ContractTypeFields
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and contractTypeFieldId not in (select contractTypeFieldId from BurialSiteContractFields)`)
|
and contractTypeFieldId not in (select contractTypeFieldId from ContractFields)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Occupancy Type Prints
|
* Occupancy Type Prints
|
||||||
|
|
@ -201,7 +201,7 @@ export default async function cleanupDatabase(user) {
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and contractTypeId not in (select contractTypeId from ContractTypeFields)
|
and contractTypeId not in (select contractTypeId from ContractTypeFields)
|
||||||
and contractTypeId not in (select contractTypeId from ContractTypePrints)
|
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)`)
|
and contractTypeId not in (select contractTypeId from Fees)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
|
|
@ -245,7 +245,7 @@ export default async function cleanupDatabase(user) {
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and burialSiteId not in (select burialSiteId from BurialSiteComments)
|
and burialSiteId not in (select burialSiteId from BurialSiteComments)
|
||||||
and burialSiteId not in (select burialSiteId from BurialSiteFields)
|
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)`)
|
and burialSiteId not in (select burialSiteId from WorkOrderLots)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ export default async function cleanupDatabase(
|
||||||
|
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrderBurialSiteContracts
|
`update WorkOrderContracts
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
|
|
@ -53,7 +53,7 @@ export default async function cleanupDatabase(
|
||||||
|
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(
|
.prepare(
|
||||||
'delete from WorkOrderBurialSiteContracts where recordDelete_timeMillis <= ?'
|
'delete from WorkOrderContracts where recordDelete_timeMillis <= ?'
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ export default async function cleanupDatabase(
|
||||||
`delete from WorkOrders
|
`delete from WorkOrders
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and workOrderId not in (select workOrderId from WorkOrderComments)
|
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 WorkOrderBurialSites)
|
||||||
and workOrderId not in (select workOrderId from WorkOrderMilestones)`
|
and workOrderId not in (select workOrderId from WorkOrderMilestones)`
|
||||||
)
|
)
|
||||||
|
|
@ -145,18 +145,18 @@ export default async function cleanupDatabase(
|
||||||
|
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSiteContractComments
|
`update ContractComments
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and burialSiteContractId in (
|
and contractId in (
|
||||||
select burialSiteContractId from BurialSiteContracts where recordDelete_timeMillis is not null)`
|
select contractId from Contracts where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(
|
.prepare(
|
||||||
'delete from BurialSiteContractComments where recordDelete_timeMillis <= ?'
|
'delete from ContractComments where recordDelete_timeMillis <= ?'
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -166,17 +166,17 @@ export default async function cleanupDatabase(
|
||||||
|
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSiteContractFields
|
`update ContractFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
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
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(
|
.prepare(
|
||||||
'delete from BurialSiteContractFields where recordDelete_timeMillis <= ?'
|
'delete from ContractFields where recordDelete_timeMillis <= ?'
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -187,13 +187,13 @@ export default async function cleanupDatabase(
|
||||||
|
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(
|
.prepare(
|
||||||
'delete from BurialSiteContractFees where recordDelete_timeMillis <= ?'
|
'delete from ContractFees where recordDelete_timeMillis <= ?'
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(
|
.prepare(
|
||||||
'delete from BurialSiteContractTransactions where recordDelete_timeMillis <= ?'
|
'delete from ContractTransactions where recordDelete_timeMillis <= ?'
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -203,14 +203,14 @@ export default async function cleanupDatabase(
|
||||||
|
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from BurialSiteContracts
|
`delete from Contracts
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractComments)
|
and contractId not in (select contractId from ContractComments)
|
||||||
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractFees)
|
and contractId not in (select contractId from ContractFees)
|
||||||
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractFields)
|
and contractId not in (select contractId from ContractFields)
|
||||||
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractInterments)
|
and contractId not in (select contractId from ContractInterments)
|
||||||
and burialSiteContractId not in (select burialSiteContractId from BurialSiteContractTransactions)
|
and contractId not in (select contractId from ContractTransactions)
|
||||||
and burialSiteContractId not in (select burialSiteContractId from WorkOrderBurialSiteContracts)`
|
and contractId not in (select contractId from WorkOrderContracts)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -232,7 +232,7 @@ export default async function cleanupDatabase(
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from Fees
|
`delete from Fees
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and feeId not in (select feeId from BurialSiteContractFees)`
|
and feeId not in (select feeId from ContractFees)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -266,7 +266,7 @@ export default async function cleanupDatabase(
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from ContractTypeFields
|
`delete from ContractTypeFields
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and contractTypeFieldId not in (select contractTypeFieldId from BurialSiteContractFields)`
|
and contractTypeFieldId not in (select contractTypeFieldId from ContractFields)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -300,7 +300,7 @@ export default async function cleanupDatabase(
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and contractTypeId not in (select contractTypeId from ContractTypeFields)
|
and contractTypeId not in (select contractTypeId from ContractTypeFields)
|
||||||
and contractTypeId not in (select contractTypeId from ContractTypePrints)
|
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)`
|
and contractTypeId not in (select contractTypeId from Fees)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
@ -363,7 +363,7 @@ export default async function cleanupDatabase(
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and burialSiteId not in (select burialSiteId from BurialSiteComments)
|
and burialSiteId not in (select burialSiteId from BurialSiteComments)
|
||||||
and burialSiteId not in (select burialSiteId from BurialSiteFields)
|
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)`
|
and burialSiteId not in (select burialSiteId from WorkOrderLots)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
export default function copyBurialSiteContract(oldBurialSiteContractId: number | string, user: User): Promise<number>;
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
export default function copyContract(oldContractId: number | string, user: User): Promise<number>;
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -1,25 +1,28 @@
|
||||||
import { dateToString } from '@cityssm/utils-datetime'
|
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 addContract from './addContract.js'
|
||||||
import addBurialSiteContractComment from './addBurialSiteContractComment.js'
|
import addContractComment from './addContractComment.js'
|
||||||
// import addBurialSiteContractOccupant from './addBurialSiteContractOccupant.js'
|
// import addContractOccupant from './addContractOccupant.js'
|
||||||
import getBurialSiteContract from './getBurialSiteContract.js'
|
import getContract from './getContract.js'
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export default async function copyBurialSiteContract(
|
export default async function copyContract(
|
||||||
oldBurialSiteContractId: number | string,
|
oldContractId: number | string,
|
||||||
user: User
|
user: User
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const database = await acquireConnection()
|
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 ?? '',
|
burialSiteId: oldContract.burialSiteId ?? '',
|
||||||
contractTypeId: oldBurialSiteContract.contractTypeId,
|
contractTypeId: oldContract.contractTypeId,
|
||||||
contractStartDateString: dateToString(new Date()),
|
contractStartDateString: dateToString(new Date()),
|
||||||
contractEndDateString: ''
|
contractEndDateString: ''
|
||||||
},
|
},
|
||||||
|
|
@ -33,17 +36,17 @@ export default async function copyBurialSiteContract(
|
||||||
|
|
||||||
const rightNowMillis = Date.now()
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
for (const field of oldBurialSiteContract.burialSiteContractFields ?? []) {
|
for (const field of oldContract.contractFields ?? []) {
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`insert into BurialSiteContractFields (
|
`insert into ContractFields (
|
||||||
burialSiteContractId, contractTypeFieldId, fieldValue,
|
contractId, contractTypeFieldId, fieldValue,
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
recordUpdate_userName, recordUpdate_timeMillis)
|
||||||
values (?, ?, ?, ?, ?, ?, ?)`
|
values (?, ?, ?, ?, ?, ?, ?)`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
newBurialSiteContractId,
|
newContractId,
|
||||||
field.contractTypeFieldId,
|
field.contractTypeFieldId,
|
||||||
field.fieldValue,
|
field.fieldValue,
|
||||||
user.userName,
|
user.userName,
|
||||||
|
|
@ -58,10 +61,10 @@ export default async function copyBurialSiteContract(
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for (const occupant of oldBurialSiteContract.burialSiteContractOccupants ?? []) {
|
for (const occupant of oldContract.contractOccupants ?? []) {
|
||||||
await addBurialSiteContractOccupant(
|
await addContractOccupant(
|
||||||
{
|
{
|
||||||
burialSiteContractId: newBurialSiteContractId,
|
contractId: newContractId,
|
||||||
lotOccupantTypeId: occupant.lotOccupantTypeId!,
|
lotOccupantTypeId: occupant.lotOccupantTypeId!,
|
||||||
occupantName: occupant.occupantName!,
|
occupantName: occupant.occupantName!,
|
||||||
occupantFamilyName: occupant.occupantFamilyName!,
|
occupantFamilyName: occupant.occupantFamilyName!,
|
||||||
|
|
@ -83,12 +86,15 @@ export default async function copyBurialSiteContract(
|
||||||
* Add Comment
|
* Add Comment
|
||||||
*/
|
*/
|
||||||
|
|
||||||
await addBurialSiteContractComment({
|
await addContractComment(
|
||||||
burialSiteContractId: newBurialSiteContractId,
|
{
|
||||||
comment: `New record copied from #${oldBurialSiteContractId}.`
|
contractId: newContractId,
|
||||||
}, user)
|
comment: `New record copied from #${oldContractId}.`
|
||||||
|
},
|
||||||
|
user
|
||||||
|
)
|
||||||
|
|
||||||
database.release()
|
database.release()
|
||||||
|
|
||||||
return newBurialSiteContractId
|
return newContractId
|
||||||
}
|
}
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
export default function deleteBurialSiteContractFee(burialSiteContractId: number | string, feeId: number | string, user: User): Promise<boolean>;
|
|
||||||
|
|
@ -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>;
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
export default function deleteBurialSiteContractInterment(burialSiteContractId: number | string, intermentNumber: number | string, user: User): Promise<boolean>;
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
export default function deleteBurialSiteContractTransaction(burialSiteContractId: number | string, transactionIndex: number | string, user: User): Promise<boolean>;
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
export default function deleteContractFee(contractId: number | string, feeId: number | string, user: User): Promise<boolean>;
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { acquireConnection } from './pool.js';
|
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 database = await acquireConnection();
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update BurialSteContractFees
|
.prepare(`update BurialSteContractFees
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and feeId = ?`)
|
and feeId = ?`)
|
||||||
.run(user.userName, Date.now(), burialSiteContractId, feeId);
|
.run(user.userName, Date.now(), contractId, feeId);
|
||||||
database.release();
|
database.release();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export default async function deleteBurialSiteContractFee(
|
export default async function deleteContractFee(
|
||||||
burialSiteContractId: number | string,
|
contractId: number | string,
|
||||||
feeId: number | string,
|
feeId: number | string,
|
||||||
user: User
|
user: User
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
|
@ -12,10 +12,10 @@ export default async function deleteBurialSiteContractFee(
|
||||||
`update BurialSteContractFees
|
`update BurialSteContractFees
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and feeId = ?`
|
and feeId = ?`
|
||||||
)
|
)
|
||||||
.run(user.userName, Date.now(), burialSiteContractId, feeId)
|
.run(user.userName, Date.now(), contractId, feeId)
|
||||||
|
|
||||||
database.release()
|
database.release()
|
||||||
|
|
||||||
|
|
@ -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>;
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { acquireConnection } from './pool.js';
|
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 database = connectedDatabase ?? (await acquireConnection());
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update BurialSiteContractFields
|
.prepare(`update ContractFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and contractTypeFieldId = ?`)
|
and contractTypeFieldId = ?`)
|
||||||
.run(user.userName, Date.now(), burialSiteContractId, contractTypeFieldId);
|
.run(user.userName, Date.now(), contractId, contractTypeFieldId);
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release();
|
database.release();
|
||||||
}
|
}
|
||||||
|
|
@ -2,8 +2,8 @@ import type { PoolConnection } from 'better-sqlite-pool'
|
||||||
|
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export default async function deleteBurialSiteContractField(
|
export default async function deleteContractField(
|
||||||
burialSiteContractId: number | string,
|
contractId: number | string,
|
||||||
contractTypeFieldId: number | string,
|
contractTypeFieldId: number | string,
|
||||||
user: User,
|
user: User,
|
||||||
connectedDatabase?: PoolConnection
|
connectedDatabase?: PoolConnection
|
||||||
|
|
@ -12,13 +12,13 @@ export default async function deleteBurialSiteContractField(
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSiteContractFields
|
`update ContractFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and contractTypeFieldId = ?`
|
and contractTypeFieldId = ?`
|
||||||
)
|
)
|
||||||
.run(user.userName, Date.now(), burialSiteContractId, contractTypeFieldId)
|
.run(user.userName, Date.now(), contractId, contractTypeFieldId)
|
||||||
|
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release()
|
database.release()
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
export default function deleteContractInterment(contractId: number | string, intermentNumber: number | string, user: User): Promise<boolean>;
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { acquireConnection } from './pool.js';
|
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 database = await acquireConnection();
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update BurialSiteContractInterments
|
.prepare(`update ContractInterments
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and intermentNumber = ?`)
|
and intermentNumber = ?`)
|
||||||
.run(user.userName, Date.now(), burialSiteContractId, intermentNumber);
|
.run(user.userName, Date.now(), contractId, intermentNumber);
|
||||||
database.release();
|
database.release();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export default async function deleteBurialSiteContractInterment(
|
export default async function deleteContractInterment(
|
||||||
burialSiteContractId: number | string,
|
contractId: number | string,
|
||||||
intermentNumber: number | string,
|
intermentNumber: number | string,
|
||||||
user: User
|
user: User
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
|
@ -9,13 +9,13 @@ export default async function deleteBurialSiteContractInterment(
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSiteContractInterments
|
`update ContractInterments
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and intermentNumber = ?`
|
and intermentNumber = ?`
|
||||||
)
|
)
|
||||||
.run(user.userName, Date.now(), burialSiteContractId, intermentNumber)
|
.run(user.userName, Date.now(), contractId, intermentNumber)
|
||||||
|
|
||||||
database.release()
|
database.release()
|
||||||
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
export default function deleteContractTransaction(contractId: number | string, transactionIndex: number | string, user: User): Promise<boolean>;
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { acquireConnection } from './pool.js';
|
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 database = await acquireConnection();
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update BurialSiteContractTransactions
|
.prepare(`update ContractTransactions
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and transactionIndex = ?`)
|
and transactionIndex = ?`)
|
||||||
.run(user.userName, Date.now(), burialSiteContractId, transactionIndex);
|
.run(user.userName, Date.now(), contractId, transactionIndex);
|
||||||
database.release();
|
database.release();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export default async function deleteBurialSiteContractTransaction(
|
export default async function deleteContractTransaction(
|
||||||
burialSiteContractId: number | string,
|
contractId: number | string,
|
||||||
transactionIndex: number | string,
|
transactionIndex: number | string,
|
||||||
user: User
|
user: User
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
|
@ -9,13 +9,13 @@ export default async function deleteBurialSiteContractTransaction(
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSiteContractTransactions
|
`update ContractTransactions
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where burialSiteContractId = ?
|
where contractId = ?
|
||||||
and transactionIndex = ?`
|
and transactionIndex = ?`
|
||||||
)
|
)
|
||||||
.run(user.userName, Date.now(), burialSiteContractId, transactionIndex)
|
.run(user.userName, Date.now(), contractId, transactionIndex)
|
||||||
|
|
||||||
database.release()
|
database.release()
|
||||||
|
|
||||||
|
|
@ -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 declare function deleteRecord(recordTable: RecordTable, recordId: number | string, user: User): Promise<boolean>;
|
||||||
export {};
|
export {};
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ recordIdColumns.set('FeeCategories', 'feeCategoryId');
|
||||||
recordIdColumns.set('Fees', 'feeId');
|
recordIdColumns.set('Fees', 'feeId');
|
||||||
recordIdColumns.set('BurialSites', 'burialSiteId');
|
recordIdColumns.set('BurialSites', 'burialSiteId');
|
||||||
recordIdColumns.set('BurialSiteComments', 'burialSiteCommentId');
|
recordIdColumns.set('BurialSiteComments', 'burialSiteCommentId');
|
||||||
recordIdColumns.set('BurialSiteContracts', 'burialSiteContractId');
|
recordIdColumns.set('Contracts', 'contractId');
|
||||||
recordIdColumns.set('BurialSiteContractComments', 'burialSiteContractCommentId');
|
recordIdColumns.set('ContractComments', 'contractCommentId');
|
||||||
recordIdColumns.set('BurialSiteStatuses', 'burialSiteStatusId');
|
recordIdColumns.set('BurialSiteStatuses', 'burialSiteStatusId');
|
||||||
recordIdColumns.set('BurialSiteTypes', 'burialSiteTypeId');
|
recordIdColumns.set('BurialSiteTypes', 'burialSiteTypeId');
|
||||||
recordIdColumns.set('BurialSiteTypeFields', 'burialSiteFieldTypeId');
|
recordIdColumns.set('BurialSiteTypeFields', 'burialSiteFieldTypeId');
|
||||||
|
|
@ -21,9 +21,9 @@ recordIdColumns.set('WorkOrderTypes', 'workOrderTypeId');
|
||||||
const relatedTables = new Map();
|
const relatedTables = new Map();
|
||||||
relatedTables.set('FeeCategories', ['Fees']);
|
relatedTables.set('FeeCategories', ['Fees']);
|
||||||
relatedTables.set('BurialSites', ['BurialSiteFields', 'BurialSiteComments']);
|
relatedTables.set('BurialSites', ['BurialSiteFields', 'BurialSiteComments']);
|
||||||
relatedTables.set('BurialSiteContracts', [
|
relatedTables.set('Contracts', [
|
||||||
'BurialSiteContractFields',
|
'ContractFields',
|
||||||
'BurialSiteContractComments'
|
'ContractComments'
|
||||||
]);
|
]);
|
||||||
relatedTables.set('BurialSiteTypes', ['BurialSiteTypeFields']);
|
relatedTables.set('BurialSiteTypes', ['BurialSiteTypeFields']);
|
||||||
relatedTables.set('Cemeteries', ['BurialSites']);
|
relatedTables.set('Cemeteries', ['BurialSites']);
|
||||||
|
|
@ -31,7 +31,7 @@ relatedTables.set('ContractTypes', ['ContractTypePrints', 'ContractTypeFields'])
|
||||||
relatedTables.set('WorkOrders', [
|
relatedTables.set('WorkOrders', [
|
||||||
'WorkOrderMilestones',
|
'WorkOrderMilestones',
|
||||||
'WorkOrderLots',
|
'WorkOrderLots',
|
||||||
'WorkOrderBurialSiteContracts',
|
'WorkOrderContracts',
|
||||||
'WorkOrderComments'
|
'WorkOrderComments'
|
||||||
]);
|
]);
|
||||||
export async function deleteRecord(recordTable, recordId, user) {
|
export async function deleteRecord(recordTable, recordId, user) {
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ type RecordTable =
|
||||||
| 'Fees'
|
| 'Fees'
|
||||||
| 'BurialSites'
|
| 'BurialSites'
|
||||||
| 'BurialSiteComments'
|
| 'BurialSiteComments'
|
||||||
| 'BurialSiteContracts'
|
| 'Contracts'
|
||||||
| 'BurialSiteContractComments'
|
| 'ContractComments'
|
||||||
| 'BurialSiteStatuses'
|
| 'BurialSiteStatuses'
|
||||||
| 'BurialSiteTypes'
|
| 'BurialSiteTypes'
|
||||||
| 'BurialSiteTypeFields'
|
| 'BurialSiteTypeFields'
|
||||||
|
|
@ -26,8 +26,8 @@ recordIdColumns.set('FeeCategories', 'feeCategoryId')
|
||||||
recordIdColumns.set('Fees', 'feeId')
|
recordIdColumns.set('Fees', 'feeId')
|
||||||
recordIdColumns.set('BurialSites', 'burialSiteId')
|
recordIdColumns.set('BurialSites', 'burialSiteId')
|
||||||
recordIdColumns.set('BurialSiteComments', 'burialSiteCommentId')
|
recordIdColumns.set('BurialSiteComments', 'burialSiteCommentId')
|
||||||
recordIdColumns.set('BurialSiteContracts', 'burialSiteContractId')
|
recordIdColumns.set('Contracts', 'contractId')
|
||||||
recordIdColumns.set('BurialSiteContractComments', 'burialSiteContractCommentId')
|
recordIdColumns.set('ContractComments', 'contractCommentId')
|
||||||
recordIdColumns.set('BurialSiteStatuses', 'burialSiteStatusId')
|
recordIdColumns.set('BurialSiteStatuses', 'burialSiteStatusId')
|
||||||
recordIdColumns.set('BurialSiteTypes', 'burialSiteTypeId')
|
recordIdColumns.set('BurialSiteTypes', 'burialSiteTypeId')
|
||||||
recordIdColumns.set('BurialSiteTypeFields', 'burialSiteFieldTypeId')
|
recordIdColumns.set('BurialSiteTypeFields', 'burialSiteFieldTypeId')
|
||||||
|
|
@ -43,9 +43,9 @@ recordIdColumns.set('WorkOrderTypes', 'workOrderTypeId')
|
||||||
const relatedTables = new Map<RecordTable, string[]>()
|
const relatedTables = new Map<RecordTable, string[]>()
|
||||||
relatedTables.set('FeeCategories', ['Fees'])
|
relatedTables.set('FeeCategories', ['Fees'])
|
||||||
relatedTables.set('BurialSites', ['BurialSiteFields', 'BurialSiteComments'])
|
relatedTables.set('BurialSites', ['BurialSiteFields', 'BurialSiteComments'])
|
||||||
relatedTables.set('BurialSiteContracts', [
|
relatedTables.set('Contracts', [
|
||||||
'BurialSiteContractFields',
|
'ContractFields',
|
||||||
'BurialSiteContractComments'
|
'ContractComments'
|
||||||
])
|
])
|
||||||
relatedTables.set('BurialSiteTypes', ['BurialSiteTypeFields'])
|
relatedTables.set('BurialSiteTypes', ['BurialSiteTypeFields'])
|
||||||
relatedTables.set('Cemeteries', ['BurialSites'])
|
relatedTables.set('Cemeteries', ['BurialSites'])
|
||||||
|
|
@ -53,7 +53,7 @@ relatedTables.set('ContractTypes', ['ContractTypePrints', 'ContractTypeFields'])
|
||||||
relatedTables.set('WorkOrders', [
|
relatedTables.set('WorkOrders', [
|
||||||
'WorkOrderMilestones',
|
'WorkOrderMilestones',
|
||||||
'WorkOrderLots',
|
'WorkOrderLots',
|
||||||
'WorkOrderBurialSiteContracts',
|
'WorkOrderContracts',
|
||||||
'WorkOrderComments'
|
'WorkOrderComments'
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
export default function deleteWorkOrderBurialSiteContract(workOrderId: number | string, burialSiteContractId: number | string, user: User): Promise<boolean>;
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
export default function deleteWorkOrderContract(workOrderId: number | string, contractId: number | string, user: User): Promise<boolean>;
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { acquireConnection } from './pool.js';
|
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 database = await acquireConnection();
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update WorkOrderBurialSiteContracts
|
.prepare(`update WorkOrderContracts
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where workOrderId = ?
|
where workOrderId = ?
|
||||||
and burialSiteContractId = ?`)
|
and contractId = ?`)
|
||||||
.run(user.userName, Date.now(), workOrderId, burialSiteContractId);
|
.run(user.userName, Date.now(), workOrderId, contractId);
|
||||||
database.release();
|
database.release();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1,21 +1,21 @@
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export default async function deleteWorkOrderBurialSiteContract(
|
export default async function deleteWorkOrderContract(
|
||||||
workOrderId: number | string,
|
workOrderId: number | string,
|
||||||
burialSiteContractId: number | string,
|
contractId: number | string,
|
||||||
user: User
|
user: User
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const database = await acquireConnection()
|
const database = await acquireConnection()
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrderBurialSiteContracts
|
`update WorkOrderContracts
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where workOrderId = ?
|
where workOrderId = ?
|
||||||
and burialSiteContractId = ?`
|
and contractId = ?`
|
||||||
)
|
)
|
||||||
.run(user.userName, Date.now(), workOrderId, burialSiteContractId)
|
.run(user.userName, Date.now(), workOrderId, contractId)
|
||||||
|
|
||||||
database.release()
|
database.release()
|
||||||
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import getBurialSiteComments from './getBurialSiteComments.js';
|
import getBurialSiteComments from './getBurialSiteComments.js';
|
||||||
import getBurialSiteInterments from './getBurialSiteContracts.js';
|
import getBurialSiteInterments from './getContracts.js';
|
||||||
import getBurialSiteFields from './getBurialSiteFields.js';
|
import getBurialSiteFields from './getBurialSiteFields.js';
|
||||||
import { acquireConnection } from './pool.js';
|
import { acquireConnection } from './pool.js';
|
||||||
const baseSQL = `select l.burialSiteId,
|
const baseSQL = `select l.burialSiteId,
|
||||||
|
|
@ -24,7 +24,7 @@ async function _getBurialSite(sql, burialSiteIdOrLotName) {
|
||||||
const database = await acquireConnection();
|
const database = await acquireConnection();
|
||||||
const burialSite = database.prepare(sql).get(burialSiteIdOrLotName);
|
const burialSite = database.prepare(sql).get(burialSiteIdOrLotName);
|
||||||
if (burialSite !== undefined) {
|
if (burialSite !== undefined) {
|
||||||
const burialSiteContracts = await getBurialSiteInterments({
|
const contracts = await getBurialSiteInterments({
|
||||||
burialSiteId: burialSite.burialSiteId
|
burialSiteId: burialSite.burialSiteId
|
||||||
}, {
|
}, {
|
||||||
includeInterments: true,
|
includeInterments: true,
|
||||||
|
|
@ -33,7 +33,7 @@ async function _getBurialSite(sql, burialSiteIdOrLotName) {
|
||||||
limit: -1,
|
limit: -1,
|
||||||
offset: 0
|
offset: 0
|
||||||
}, database);
|
}, database);
|
||||||
burialSite.burialSiteContracts = burialSiteContracts.burialSiteContracts;
|
burialSite.contracts = contracts.contracts;
|
||||||
burialSite.burialSiteFields = await getBurialSiteFields(burialSite.burialSiteId, database);
|
burialSite.burialSiteFields = await getBurialSiteFields(burialSite.burialSiteId, database);
|
||||||
burialSite.burialSiteComments = await getBurialSiteComments(burialSite.burialSiteId, database);
|
burialSite.burialSiteComments = await getBurialSiteComments(burialSite.burialSiteId, database);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import type { BurialSite } from '../types/recordTypes.js'
|
import type { BurialSite } from '../types/recordTypes.js'
|
||||||
|
|
||||||
import getBurialSiteComments from './getBurialSiteComments.js'
|
import getBurialSiteComments from './getBurialSiteComments.js'
|
||||||
import getBurialSiteInterments from './getBurialSiteContracts.js'
|
import getBurialSiteInterments from './getContracts.js'
|
||||||
import getBurialSiteFields from './getBurialSiteFields.js'
|
import getBurialSiteFields from './getBurialSiteFields.js'
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@ async function _getBurialSite(
|
||||||
const burialSite = database.prepare(sql).get(burialSiteIdOrLotName) as BurialSite | undefined
|
const burialSite = database.prepare(sql).get(burialSiteIdOrLotName) as BurialSite | undefined
|
||||||
|
|
||||||
if (burialSite !== undefined) {
|
if (burialSite !== undefined) {
|
||||||
const burialSiteContracts = await getBurialSiteInterments(
|
const contracts = await getBurialSiteInterments(
|
||||||
{
|
{
|
||||||
burialSiteId: burialSite.burialSiteId
|
burialSiteId: burialSite.burialSiteId
|
||||||
},
|
},
|
||||||
|
|
@ -47,7 +47,7 @@ async function _getBurialSite(
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
|
|
||||||
burialSite.burialSiteContracts = burialSiteContracts.burialSiteContracts
|
burialSite.contracts = contracts.contracts
|
||||||
|
|
||||||
burialSite.burialSiteFields = await getBurialSiteFields(burialSite.burialSiteId, database)
|
burialSite.burialSiteFields = await getBurialSiteFields(burialSite.burialSiteId, database)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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>;
|
|
||||||
|
|
@ -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[]>;
|
|
||||||
|
|
@ -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[]>;
|
|
||||||
|
|
@ -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[]>;
|
|
||||||
|
|
@ -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[]>;
|
|
||||||
|
|
@ -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[]>;
|
|
||||||
|
|
@ -13,7 +13,7 @@ export interface GetBurialSitesOptions {
|
||||||
/** -1 for no limit */
|
/** -1 for no limit */
|
||||||
limit: number;
|
limit: number;
|
||||||
offset: string | number;
|
offset: string | number;
|
||||||
includeBurialSiteContractCount?: boolean;
|
includeContractCount?: boolean;
|
||||||
}
|
}
|
||||||
export default function getBurialSites(filters: GetBurialSitesFilters, options: GetBurialSitesOptions, connectedDatabase?: PoolConnection): Promise<{
|
export default function getBurialSites(filters: GetBurialSitesFilters, options: GetBurialSitesOptions, connectedDatabase?: PoolConnection): Promise<{
|
||||||
count: number;
|
count: number;
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,11 @@ function buildWhereClause(filters) {
|
||||||
}
|
}
|
||||||
if ((filters.contractStatus ?? '') !== '') {
|
if ((filters.contractStatus ?? '') !== '') {
|
||||||
if (filters.contractStatus === 'occupied') {
|
if (filters.contractStatus === 'occupied') {
|
||||||
sqlWhereClause += ' and burialSiteContractCount > 0';
|
sqlWhereClause += ' and contractCount > 0';
|
||||||
}
|
}
|
||||||
else if (filters.contractStatus === 'unoccupied') {
|
else if (filters.contractStatus === 'unoccupied') {
|
||||||
sqlWhereClause +=
|
sqlWhereClause +=
|
||||||
' and (burialSiteContractCount is null or burialSiteContractCount = 0)';
|
' and (contractCount is null or contractCount = 0)';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((filters.workOrderId ?? '') !== '') {
|
if ((filters.workOrderId ?? '') !== '') {
|
||||||
|
|
@ -48,7 +48,7 @@ export default async function getBurialSites(filters, options, connectedDatabase
|
||||||
.prepare(`select count(*) as recordCount
|
.prepare(`select count(*) as recordCount
|
||||||
from BurialSites l
|
from BurialSites l
|
||||||
left join (
|
left join (
|
||||||
select burialSiteId, count(burialSiteContractId) as burialSiteContractCount from BurialSiteContracts
|
select burialSiteId, count(contractId) as contractCount from Contracts
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractStartDate <= ${currentDate.toString()}
|
and contractStartDate <= ${currentDate.toString()}
|
||||||
and (contractEndDate is null or contractEndDate >= ${currentDate.toString()})
|
and (contractEndDate is null or contractEndDate >= ${currentDate.toString()})
|
||||||
|
|
@ -59,8 +59,8 @@ export default async function getBurialSites(filters, options, connectedDatabase
|
||||||
}
|
}
|
||||||
let burialSites = [];
|
let burialSites = [];
|
||||||
if (options.limit === -1 || count > 0) {
|
if (options.limit === -1 || count > 0) {
|
||||||
const includeBurialSiteContractCount = options.includeBurialSiteContractCount ?? true;
|
const includeContractCount = options.includeContractCount ?? true;
|
||||||
if (includeBurialSiteContractCount) {
|
if (includeContractCount) {
|
||||||
sqlParameters.unshift(currentDate, currentDate);
|
sqlParameters.unshift(currentDate, currentDate);
|
||||||
}
|
}
|
||||||
burialSites = database
|
burialSites = database
|
||||||
|
|
@ -74,17 +74,17 @@ export default async function getBurialSites(filters, options, connectedDatabase
|
||||||
t.burialSiteType,
|
t.burialSiteType,
|
||||||
l.cemeteryId, m.cemeteryName, l.cemeterySvgId,
|
l.cemeteryId, m.cemeteryName, l.cemeterySvgId,
|
||||||
l.burialSiteStatusId, s.burialSiteStatus
|
l.burialSiteStatusId, s.burialSiteStatus
|
||||||
${includeBurialSiteContractCount
|
${includeContractCount
|
||||||
? ', ifnull(o.burialSiteContractCount, 0) as burialSiteContractCount'
|
? ', ifnull(o.contractCount, 0) as contractCount'
|
||||||
: ''}
|
: ''}
|
||||||
from BurialSites l
|
from BurialSites l
|
||||||
left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId
|
left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId
|
||||||
left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId
|
left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
${includeBurialSiteContractCount
|
${includeContractCount
|
||||||
? `left join (
|
? `left join (
|
||||||
select burialSiteId, count(burialSiteContractId) as burialSiteContractCount
|
select burialSiteId, count(contractId) as contractCount
|
||||||
from BurialSiteContracts
|
from Contracts
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractStartDate <= ?
|
and contractStartDate <= ?
|
||||||
and (contractEndDate is null or contractEndDate >= ?)
|
and (contractEndDate is null or contractEndDate >= ?)
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ export interface GetBurialSitesOptions {
|
||||||
/** -1 for no limit */
|
/** -1 for no limit */
|
||||||
limit: number
|
limit: number
|
||||||
offset: string | number
|
offset: string | number
|
||||||
includeBurialSiteContractCount?: boolean
|
includeContractCount?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildWhereClause(filters: GetBurialSitesFilters): {
|
function buildWhereClause(filters: GetBurialSitesFilters): {
|
||||||
|
|
@ -55,10 +55,10 @@ function buildWhereClause(filters: GetBurialSitesFilters): {
|
||||||
|
|
||||||
if ((filters.contractStatus ?? '') !== '') {
|
if ((filters.contractStatus ?? '') !== '') {
|
||||||
if (filters.contractStatus === 'occupied') {
|
if (filters.contractStatus === 'occupied') {
|
||||||
sqlWhereClause += ' and burialSiteContractCount > 0'
|
sqlWhereClause += ' and contractCount > 0'
|
||||||
} else if (filters.contractStatus === 'unoccupied') {
|
} else if (filters.contractStatus === 'unoccupied') {
|
||||||
sqlWhereClause +=
|
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
|
`select count(*) as recordCount
|
||||||
from BurialSites l
|
from BurialSites l
|
||||||
left join (
|
left join (
|
||||||
select burialSiteId, count(burialSiteContractId) as burialSiteContractCount from BurialSiteContracts
|
select burialSiteId, count(contractId) as contractCount from Contracts
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractStartDate <= ${currentDate.toString()}
|
and contractStartDate <= ${currentDate.toString()}
|
||||||
and (contractEndDate is null or contractEndDate >= ${currentDate.toString()})
|
and (contractEndDate is null or contractEndDate >= ${currentDate.toString()})
|
||||||
|
|
@ -109,9 +109,9 @@ export default async function getBurialSites(
|
||||||
let burialSites: BurialSite[] = []
|
let burialSites: BurialSite[] = []
|
||||||
|
|
||||||
if (options.limit === -1 || count > 0) {
|
if (options.limit === -1 || count > 0) {
|
||||||
const includeBurialSiteContractCount = options.includeBurialSiteContractCount ?? true
|
const includeContractCount = options.includeContractCount ?? true
|
||||||
|
|
||||||
if (includeBurialSiteContractCount) {
|
if (includeContractCount) {
|
||||||
sqlParameters.unshift(currentDate, currentDate)
|
sqlParameters.unshift(currentDate, currentDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,8 +128,8 @@ export default async function getBurialSites(
|
||||||
l.cemeteryId, m.cemeteryName, l.cemeterySvgId,
|
l.cemeteryId, m.cemeteryName, l.cemeterySvgId,
|
||||||
l.burialSiteStatusId, s.burialSiteStatus
|
l.burialSiteStatusId, s.burialSiteStatus
|
||||||
${
|
${
|
||||||
includeBurialSiteContractCount
|
includeContractCount
|
||||||
? ', ifnull(o.burialSiteContractCount, 0) as burialSiteContractCount'
|
? ', ifnull(o.contractCount, 0) as contractCount'
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
from BurialSites l
|
from BurialSites l
|
||||||
|
|
@ -137,10 +137,10 @@ export default async function getBurialSites(
|
||||||
left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId
|
left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
${
|
${
|
||||||
includeBurialSiteContractCount
|
includeContractCount
|
||||||
? `left join (
|
? `left join (
|
||||||
select burialSiteId, count(burialSiteContractId) as burialSiteContractCount
|
select burialSiteId, count(contractId) as contractCount
|
||||||
from BurialSiteContracts
|
from Contracts
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractStartDate <= ?
|
and contractStartDate <= ?
|
||||||
and (contractEndDate is null or contractEndDate >= ?)
|
and (contractEndDate is null or contractEndDate >= ?)
|
||||||
|
|
|
||||||
|
|
@ -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>;
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
import { dateIntegerToString } from '@cityssm/utils-datetime';
|
import { dateIntegerToString } from '@cityssm/utils-datetime';
|
||||||
import getBurialSiteContractComments from './getBurialSiteContractComments.js';
|
import getContractComments from './getContractComments.js';
|
||||||
import getBurialSiteContractFees from './getBurialSiteContractFees.js';
|
import getContractFees from './getContractFees.js';
|
||||||
import getBurialSiteContractFields from './getBurialSiteContractFields.js';
|
import getContractFields from './getContractFields.js';
|
||||||
// import getBurialSiteContractOccupants from './getBurialSiteContractOccupants.js'
|
// import getContractOccupants from './getContractOccupants.js'
|
||||||
import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js';
|
import getContractTransactions from './getContractTransactions.js';
|
||||||
import { getWorkOrders } from './getWorkOrders.js';
|
import { getWorkOrders } from './getWorkOrders.js';
|
||||||
import { acquireConnection } from './pool.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());
|
const database = connectedDatabase ?? (await acquireConnection());
|
||||||
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
||||||
const contract = database
|
const contract = database
|
||||||
.prepare(`select o.burialSiteContractId,
|
.prepare(`select o.contractId,
|
||||||
o.contractTypeId, t.contractType,
|
o.contractTypeId, t.contractType,
|
||||||
o.burialSiteId,
|
o.burialSiteId,
|
||||||
l.burialSiteName,
|
l.burialSiteName,
|
||||||
|
|
@ -19,26 +19,26 @@ export default async function getBurialSiteContract(burialSiteContractId, connec
|
||||||
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
||||||
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
||||||
o.recordUpdate_timeMillis
|
o.recordUpdate_timeMillis
|
||||||
from BurialSiteContracts o
|
from Contracts o
|
||||||
left join ContractTypes t on o.contractTypeId = t.contractTypeId
|
left join ContractTypes t on o.contractTypeId = t.contractTypeId
|
||||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||||
left join Maps m on l.cemeteryId = m.cemeteryId
|
left join Maps m on l.cemeteryId = m.cemeteryId
|
||||||
where o.recordDelete_timeMillis is null
|
where o.recordDelete_timeMillis is null
|
||||||
and o.burialSiteContractId = ?`)
|
and o.contractId = ?`)
|
||||||
.get(burialSiteContractId);
|
.get(contractId);
|
||||||
if (contract !== undefined) {
|
if (contract !== undefined) {
|
||||||
contract.burialSiteContractFields = await getBurialSiteContractFields(burialSiteContractId, database);
|
contract.contractFields = await getContractFields(contractId, database);
|
||||||
/*
|
/*
|
||||||
contract.burialSiteContractInterments = await getBurialSiteContractOccupants(
|
contract.contractInterments = await getContractOccupants(
|
||||||
burialSiteContractId,
|
contractId,
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
*/
|
*/
|
||||||
contract.burialSiteContractComments = await getBurialSiteContractComments(burialSiteContractId, database);
|
contract.contractComments = await getContractComments(contractId, database);
|
||||||
contract.burialSiteContractFees = await getBurialSiteContractFees(burialSiteContractId, database);
|
contract.contractFees = await getContractFees(contractId, database);
|
||||||
contract.burialSiteContractTransactions = await getBurialSiteContractTransactions(burialSiteContractId, { includeIntegrations: true }, database);
|
contract.contractTransactions = await getContractTransactions(contractId, { includeIntegrations: true }, database);
|
||||||
const workOrdersResults = await getWorkOrders({
|
const workOrdersResults = await getWorkOrders({
|
||||||
burialSiteContractId
|
contractId
|
||||||
}, {
|
}, {
|
||||||
limit: -1,
|
limit: -1,
|
||||||
offset: 0
|
offset: 0
|
||||||
|
|
@ -1,27 +1,27 @@
|
||||||
import { dateIntegerToString } from '@cityssm/utils-datetime'
|
import { dateIntegerToString } from '@cityssm/utils-datetime'
|
||||||
import type { PoolConnection } from 'better-sqlite-pool'
|
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 getContractComments from './getContractComments.js'
|
||||||
import getBurialSiteContractFees from './getBurialSiteContractFees.js'
|
import getContractFees from './getContractFees.js'
|
||||||
import getBurialSiteContractFields from './getBurialSiteContractFields.js'
|
import getContractFields from './getContractFields.js'
|
||||||
// import getBurialSiteContractOccupants from './getBurialSiteContractOccupants.js'
|
// import getContractOccupants from './getContractOccupants.js'
|
||||||
import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js'
|
import getContractTransactions from './getContractTransactions.js'
|
||||||
import { getWorkOrders } from './getWorkOrders.js'
|
import { getWorkOrders } from './getWorkOrders.js'
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export default async function getBurialSiteContract(
|
export default async function getContract(
|
||||||
burialSiteContractId: number | string,
|
contractId: number | string,
|
||||||
connectedDatabase?: PoolConnection
|
connectedDatabase?: PoolConnection
|
||||||
): Promise<BurialSiteContract | undefined> {
|
): Promise<Contract | undefined> {
|
||||||
const database = connectedDatabase ?? (await acquireConnection())
|
const database = connectedDatabase ?? (await acquireConnection())
|
||||||
|
|
||||||
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
||||||
|
|
||||||
const contract = database
|
const contract = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select o.burialSiteContractId,
|
`select o.contractId,
|
||||||
o.contractTypeId, t.contractType,
|
o.contractTypeId, t.contractType,
|
||||||
o.burialSiteId,
|
o.burialSiteId,
|
||||||
l.burialSiteName,
|
l.burialSiteName,
|
||||||
|
|
@ -30,43 +30,43 @@ export default async function getBurialSiteContract(
|
||||||
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
||||||
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
||||||
o.recordUpdate_timeMillis
|
o.recordUpdate_timeMillis
|
||||||
from BurialSiteContracts o
|
from Contracts o
|
||||||
left join ContractTypes t on o.contractTypeId = t.contractTypeId
|
left join ContractTypes t on o.contractTypeId = t.contractTypeId
|
||||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||||
left join Maps m on l.cemeteryId = m.cemeteryId
|
left join Maps m on l.cemeteryId = m.cemeteryId
|
||||||
where o.recordDelete_timeMillis is null
|
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) {
|
if (contract !== undefined) {
|
||||||
contract.burialSiteContractFields = await getBurialSiteContractFields(
|
contract.contractFields = await getContractFields(
|
||||||
burialSiteContractId,
|
contractId,
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
/*
|
/*
|
||||||
contract.burialSiteContractInterments = await getBurialSiteContractOccupants(
|
contract.contractInterments = await getContractOccupants(
|
||||||
burialSiteContractId,
|
contractId,
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
*/
|
*/
|
||||||
contract.burialSiteContractComments = await getBurialSiteContractComments(
|
contract.contractComments = await getContractComments(
|
||||||
burialSiteContractId,
|
contractId,
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
contract.burialSiteContractFees = await getBurialSiteContractFees(
|
contract.contractFees = await getContractFees(
|
||||||
burialSiteContractId,
|
contractId,
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
contract.burialSiteContractTransactions = await getBurialSiteContractTransactions(
|
contract.contractTransactions = await getContractTransactions(
|
||||||
burialSiteContractId,
|
contractId,
|
||||||
{ includeIntegrations: true },
|
{ includeIntegrations: true },
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
|
|
||||||
const workOrdersResults = await getWorkOrders(
|
const workOrdersResults = await getWorkOrders(
|
||||||
{
|
{
|
||||||
burialSiteContractId
|
contractId
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
limit: -1,
|
limit: -1,
|
||||||
|
|
@ -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[]>;
|
||||||
|
|
@ -1,23 +1,23 @@
|
||||||
import { dateIntegerToString, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime';
|
import { dateIntegerToString, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime';
|
||||||
import { acquireConnection } from './pool.js';
|
import { acquireConnection } from './pool.js';
|
||||||
export default async function getBurialSiteContractComments(burialSiteContractId, connectedDatabase) {
|
export default async function getContractComments(contractId, connectedDatabase) {
|
||||||
const database = connectedDatabase ?? (await acquireConnection());
|
const database = connectedDatabase ?? (await acquireConnection());
|
||||||
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
||||||
database.function('userFn_timeIntegerToString', timeIntegerToString);
|
database.function('userFn_timeIntegerToString', timeIntegerToString);
|
||||||
database.function('userFn_timeIntegerToPeriodString', timeIntegerToPeriodString);
|
database.function('userFn_timeIntegerToPeriodString', timeIntegerToPeriodString);
|
||||||
const comments = database
|
const comments = database
|
||||||
.prepare(`select burialSiteContractCommentId,
|
.prepare(`select contractCommentId,
|
||||||
commentDate, userFn_dateIntegerToString(commentDate) as commentDateString,
|
commentDate, userFn_dateIntegerToString(commentDate) as commentDateString,
|
||||||
commentTime,
|
commentTime,
|
||||||
userFn_timeIntegerToString(commentTime) as commentTimeString,
|
userFn_timeIntegerToString(commentTime) as commentTimeString,
|
||||||
userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString,
|
userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString,
|
||||||
comment,
|
comment,
|
||||||
recordCreate_userName, recordUpdate_userName
|
recordCreate_userName, recordUpdate_userName
|
||||||
from BurialSiteContractComments
|
from ContractComments
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and burialSiteContractId = ?
|
and contractId = ?
|
||||||
order by commentDate desc, commentTime desc, burialSiteContractCommentId desc`)
|
order by commentDate desc, commentTime desc, contractCommentId desc`)
|
||||||
.all(burialSiteContractId);
|
.all(contractId);
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release();
|
database.release();
|
||||||
}
|
}
|
||||||
|
|
@ -5,14 +5,14 @@ import {
|
||||||
} from '@cityssm/utils-datetime'
|
} from '@cityssm/utils-datetime'
|
||||||
import type { PoolConnection } from 'better-sqlite-pool'
|
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'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export default async function getBurialSiteContractComments(
|
export default async function getContractComments(
|
||||||
burialSiteContractId: number | string,
|
contractId: number | string,
|
||||||
connectedDatabase?: PoolConnection
|
connectedDatabase?: PoolConnection
|
||||||
): Promise<BurialSiteContractComment[]> {
|
): Promise<ContractComment[]> {
|
||||||
const database = connectedDatabase ?? (await acquireConnection())
|
const database = connectedDatabase ?? (await acquireConnection())
|
||||||
|
|
||||||
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
||||||
|
|
@ -24,19 +24,19 @@ export default async function getBurialSiteContractComments(
|
||||||
|
|
||||||
const comments = database
|
const comments = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select burialSiteContractCommentId,
|
`select contractCommentId,
|
||||||
commentDate, userFn_dateIntegerToString(commentDate) as commentDateString,
|
commentDate, userFn_dateIntegerToString(commentDate) as commentDateString,
|
||||||
commentTime,
|
commentTime,
|
||||||
userFn_timeIntegerToString(commentTime) as commentTimeString,
|
userFn_timeIntegerToString(commentTime) as commentTimeString,
|
||||||
userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString,
|
userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString,
|
||||||
comment,
|
comment,
|
||||||
recordCreate_userName, recordUpdate_userName
|
recordCreate_userName, recordUpdate_userName
|
||||||
from BurialSiteContractComments
|
from ContractComments
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and burialSiteContractId = ?
|
and contractId = ?
|
||||||
order by commentDate desc, commentTime desc, burialSiteContractCommentId desc`
|
order by commentDate desc, commentTime desc, contractCommentId desc`
|
||||||
)
|
)
|
||||||
.all(burialSiteContractId) as BurialSiteContractComment[]
|
.all(contractId) as ContractComment[]
|
||||||
|
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release()
|
database.release()
|
||||||
|
|
@ -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[]>;
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
import { acquireConnection } from './pool.js';
|
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 database = connectedDatabase ?? (await acquireConnection());
|
||||||
const fees = database
|
const fees = database
|
||||||
.prepare(`select o.burialSiteContractId, o.feeId,
|
.prepare(`select o.contractId, o.feeId,
|
||||||
c.feeCategory, f.feeName,
|
c.feeCategory, f.feeName,
|
||||||
f.includeQuantity, o.feeAmount, o.taxAmount, o.quantity, f.quantityUnit
|
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 Fees f on o.feeId = f.feeId
|
||||||
left join FeeCategories c on f.feeCategoryId = c.feeCategoryId
|
left join FeeCategories c on f.feeCategoryId = c.feeCategoryId
|
||||||
where o.recordDelete_timeMillis is null
|
where o.recordDelete_timeMillis is null
|
||||||
and o.burialSiteContractId = ?
|
and o.contractId = ?
|
||||||
order by o.recordCreate_timeMillis`)
|
order by o.recordCreate_timeMillis`)
|
||||||
.all(burialSiteContractId);
|
.all(contractId);
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release();
|
database.release();
|
||||||
}
|
}
|
||||||
|
|
@ -1,28 +1,28 @@
|
||||||
import type { PoolConnection } from 'better-sqlite-pool'
|
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'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export default async function getBurialSiteContractFees(
|
export default async function getContractFees(
|
||||||
burialSiteContractId: number | string,
|
contractId: number | string,
|
||||||
connectedDatabase?: PoolConnection
|
connectedDatabase?: PoolConnection
|
||||||
): Promise<BurialSiteContractFee[]> {
|
): Promise<ContractFee[]> {
|
||||||
const database = connectedDatabase ?? (await acquireConnection())
|
const database = connectedDatabase ?? (await acquireConnection())
|
||||||
|
|
||||||
const fees = database
|
const fees = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select o.burialSiteContractId, o.feeId,
|
`select o.contractId, o.feeId,
|
||||||
c.feeCategory, f.feeName,
|
c.feeCategory, f.feeName,
|
||||||
f.includeQuantity, o.feeAmount, o.taxAmount, o.quantity, f.quantityUnit
|
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 Fees f on o.feeId = f.feeId
|
||||||
left join FeeCategories c on f.feeCategoryId = c.feeCategoryId
|
left join FeeCategories c on f.feeCategoryId = c.feeCategoryId
|
||||||
where o.recordDelete_timeMillis is null
|
where o.recordDelete_timeMillis is null
|
||||||
and o.burialSiteContractId = ?
|
and o.contractId = ?
|
||||||
order by o.recordCreate_timeMillis`
|
order by o.recordCreate_timeMillis`
|
||||||
)
|
)
|
||||||
.all(burialSiteContractId) as BurialSiteContractFee[]
|
.all(contractId) as ContractFee[]
|
||||||
|
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release()
|
database.release()
|
||||||
|
|
@ -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[]>;
|
||||||
|
|
@ -1,20 +1,20 @@
|
||||||
import { acquireConnection } from './pool.js';
|
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 database = connectedDatabase ?? (await acquireConnection());
|
||||||
const fields = database
|
const fields = database
|
||||||
.prepare(`select o.burialSiteContractId, o.contractTypeFieldId,
|
.prepare(`select o.contractId, o.contractTypeFieldId,
|
||||||
o.fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
|
o.fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
|
||||||
f.isRequired, f.pattern, f.minLength, f.maxLength,
|
f.isRequired, f.pattern, f.minLength, f.maxLength,
|
||||||
f.orderNumber, t.orderNumber as contractTypeOrderNumber
|
f.orderNumber, t.orderNumber as contractTypeOrderNumber
|
||||||
from BurialSiteContractFields o
|
from ContractFields o
|
||||||
left join ContractTypeFields f on o.contractTypeFieldId = f.contractTypeFieldId
|
left join ContractTypeFields f on o.contractTypeFieldId = f.contractTypeFieldId
|
||||||
left join ContractTypes t on f.contractTypeId = t.contractTypeId
|
left join ContractTypes t on f.contractTypeId = t.contractTypeId
|
||||||
where o.recordDelete_timeMillis is null
|
where o.recordDelete_timeMillis is null
|
||||||
and o.burialSiteContractId = ?
|
and o.contractId = ?
|
||||||
|
|
||||||
union
|
union
|
||||||
|
|
||||||
select ? as burialSiteContractId, f.contractTypeFieldId,
|
select ? as contractId, f.contractTypeFieldId,
|
||||||
'' as fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
|
'' as fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
|
||||||
f.isRequired, f.pattern, f.minLength, f.maxLength,
|
f.isRequired, f.pattern, f.minLength, f.maxLength,
|
||||||
f.orderNumber, t.orderNumber as contractTypeOrderNumber
|
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
|
left join ContractTypes t on f.contractTypeId = t.contractTypeId
|
||||||
where f.recordDelete_timeMillis is null and (
|
where f.recordDelete_timeMillis is null and (
|
||||||
f.contractTypeId is null
|
f.contractTypeId is null
|
||||||
or f.contractTypeId in (select contractTypeId from BurialSiteContracts where burialSiteContractId = ?))
|
or f.contractTypeId in (select contractTypeId from Contracts where contractId = ?))
|
||||||
and f.contractTypeFieldId not in (select contractTypeFieldId from BurialSiteContractFields where burialSiteContractId = ? and recordDelete_timeMillis is null)
|
and f.contractTypeFieldId not in (select contractTypeFieldId from ContractFields where contractId = ? and recordDelete_timeMillis is null)
|
||||||
order by contractTypeOrderNumber, f.orderNumber, f.contractTypeField`)
|
order by contractTypeOrderNumber, f.orderNumber, f.contractTypeField`)
|
||||||
.all(burialSiteContractId, burialSiteContractId, burialSiteContractId, burialSiteContractId);
|
.all(contractId, contractId, contractId, contractId);
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release();
|
database.release();
|
||||||
}
|
}
|
||||||
|
|
@ -1,30 +1,30 @@
|
||||||
import type { PoolConnection } from 'better-sqlite-pool'
|
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'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export default async function getBurialSiteContractField(
|
export default async function getContractField(
|
||||||
burialSiteContractId: number | string,
|
contractId: number | string,
|
||||||
connectedDatabase?: PoolConnection
|
connectedDatabase?: PoolConnection
|
||||||
): Promise<BurialSiteContractField[]> {
|
): Promise<ContractField[]> {
|
||||||
const database = connectedDatabase ?? (await acquireConnection())
|
const database = connectedDatabase ?? (await acquireConnection())
|
||||||
|
|
||||||
const fields = database
|
const fields = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select o.burialSiteContractId, o.contractTypeFieldId,
|
`select o.contractId, o.contractTypeFieldId,
|
||||||
o.fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
|
o.fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
|
||||||
f.isRequired, f.pattern, f.minLength, f.maxLength,
|
f.isRequired, f.pattern, f.minLength, f.maxLength,
|
||||||
f.orderNumber, t.orderNumber as contractTypeOrderNumber
|
f.orderNumber, t.orderNumber as contractTypeOrderNumber
|
||||||
from BurialSiteContractFields o
|
from ContractFields o
|
||||||
left join ContractTypeFields f on o.contractTypeFieldId = f.contractTypeFieldId
|
left join ContractTypeFields f on o.contractTypeFieldId = f.contractTypeFieldId
|
||||||
left join ContractTypes t on f.contractTypeId = t.contractTypeId
|
left join ContractTypes t on f.contractTypeId = t.contractTypeId
|
||||||
where o.recordDelete_timeMillis is null
|
where o.recordDelete_timeMillis is null
|
||||||
and o.burialSiteContractId = ?
|
and o.contractId = ?
|
||||||
|
|
||||||
union
|
union
|
||||||
|
|
||||||
select ? as burialSiteContractId, f.contractTypeFieldId,
|
select ? as contractId, f.contractTypeFieldId,
|
||||||
'' as fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
|
'' as fieldValue, f.contractTypeField, f.fieldType, f.fieldValues,
|
||||||
f.isRequired, f.pattern, f.minLength, f.maxLength,
|
f.isRequired, f.pattern, f.minLength, f.maxLength,
|
||||||
f.orderNumber, t.orderNumber as contractTypeOrderNumber
|
f.orderNumber, t.orderNumber as contractTypeOrderNumber
|
||||||
|
|
@ -32,16 +32,16 @@ export default async function getBurialSiteContractField(
|
||||||
left join ContractTypes t on f.contractTypeId = t.contractTypeId
|
left join ContractTypes t on f.contractTypeId = t.contractTypeId
|
||||||
where f.recordDelete_timeMillis is null and (
|
where f.recordDelete_timeMillis is null and (
|
||||||
f.contractTypeId is null
|
f.contractTypeId is null
|
||||||
or f.contractTypeId in (select contractTypeId from BurialSiteContracts where burialSiteContractId = ?))
|
or f.contractTypeId in (select contractTypeId from Contracts where contractId = ?))
|
||||||
and f.contractTypeFieldId not in (select contractTypeFieldId from BurialSiteContractFields where burialSiteContractId = ? and recordDelete_timeMillis is null)
|
and f.contractTypeFieldId not in (select contractTypeFieldId from ContractFields where contractId = ? and recordDelete_timeMillis is null)
|
||||||
order by contractTypeOrderNumber, f.orderNumber, f.contractTypeField`
|
order by contractTypeOrderNumber, f.orderNumber, f.contractTypeField`
|
||||||
)
|
)
|
||||||
.all(
|
.all(
|
||||||
burialSiteContractId,
|
contractId,
|
||||||
burialSiteContractId,
|
contractId,
|
||||||
burialSiteContractId,
|
contractId,
|
||||||
burialSiteContractId
|
contractId
|
||||||
) as BurialSiteContractField[]
|
) as ContractField[]
|
||||||
|
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release()
|
database.release()
|
||||||
|
|
@ -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[]>;
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import { dateIntegerToString, timeIntegerToString } from '@cityssm/utils-datetime';
|
import { dateIntegerToString, timeIntegerToString } from '@cityssm/utils-datetime';
|
||||||
import { acquireConnection } from './pool.js';
|
import { acquireConnection } from './pool.js';
|
||||||
export default async function getBurialSiteContractInterments(burialSiteContractId, connectedDatabase) {
|
export default async function getContractInterments(contractId, connectedDatabase) {
|
||||||
const database = connectedDatabase ?? (await acquireConnection());
|
const database = connectedDatabase ?? (await acquireConnection());
|
||||||
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
||||||
database.function('userFn_timeIntegerToString', timeIntegerToString);
|
database.function('userFn_timeIntegerToString', timeIntegerToString);
|
||||||
const interments = database
|
const interments = database
|
||||||
.prepare(`select o.burialSiteContractId, o.intermentNumber,
|
.prepare(`select o.contractId, o.intermentNumber,
|
||||||
o.isCremated,
|
o.isCremated,
|
||||||
o.deceasedName,
|
o.deceasedName,
|
||||||
birthDate, userFn_dateIntegerToString(birthDate) as birthDateString,
|
birthDate, userFn_dateIntegerToString(birthDate) as birthDateString,
|
||||||
|
|
@ -19,14 +19,14 @@ export default async function getBurialSiteContractInterments(burialSiteContract
|
||||||
intermentContainerTypeId, t.intermentContainerType,
|
intermentContainerTypeId, t.intermentContainerType,
|
||||||
intermentCommittalTypeId, c.intermentCommittalType
|
intermentCommittalTypeId, c.intermentCommittalType
|
||||||
|
|
||||||
from BurialSiteContractInterments o
|
from ContractInterments o
|
||||||
left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId
|
left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId
|
||||||
left join IntermentCommittalTypes c on o.intermentCommittalTypeId = c.intermentCommittalTypeId
|
left join IntermentCommittalTypes c on o.intermentCommittalTypeId = c.intermentCommittalTypeId
|
||||||
|
|
||||||
where o.recordDelete_timeMillis is null
|
where o.recordDelete_timeMillis is null
|
||||||
and o.burialSiteContractId = ?
|
and o.contractId = ?
|
||||||
order by t.orderNumber, o.deceasedName, o.intermentNumber`)
|
order by t.orderNumber, o.deceasedName, o.intermentNumber`)
|
||||||
.all(burialSiteContractId);
|
.all(contractId);
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release();
|
database.release();
|
||||||
}
|
}
|
||||||
|
|
@ -4,14 +4,14 @@ import {
|
||||||
} from '@cityssm/utils-datetime'
|
} from '@cityssm/utils-datetime'
|
||||||
import type { PoolConnection } from 'better-sqlite-pool'
|
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'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export default async function getBurialSiteContractInterments(
|
export default async function getContractInterments(
|
||||||
burialSiteContractId: number | string,
|
contractId: number | string,
|
||||||
connectedDatabase?: PoolConnection
|
connectedDatabase?: PoolConnection
|
||||||
): Promise<BurialSiteContractInterment[]> {
|
): Promise<ContractInterment[]> {
|
||||||
const database = connectedDatabase ?? (await acquireConnection())
|
const database = connectedDatabase ?? (await acquireConnection())
|
||||||
|
|
||||||
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
||||||
|
|
@ -19,7 +19,7 @@ export default async function getBurialSiteContractInterments(
|
||||||
|
|
||||||
const interments = database
|
const interments = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select o.burialSiteContractId, o.intermentNumber,
|
`select o.contractId, o.intermentNumber,
|
||||||
o.isCremated,
|
o.isCremated,
|
||||||
o.deceasedName,
|
o.deceasedName,
|
||||||
birthDate, userFn_dateIntegerToString(birthDate) as birthDateString,
|
birthDate, userFn_dateIntegerToString(birthDate) as birthDateString,
|
||||||
|
|
@ -33,15 +33,15 @@ export default async function getBurialSiteContractInterments(
|
||||||
intermentContainerTypeId, t.intermentContainerType,
|
intermentContainerTypeId, t.intermentContainerType,
|
||||||
intermentCommittalTypeId, c.intermentCommittalType
|
intermentCommittalTypeId, c.intermentCommittalType
|
||||||
|
|
||||||
from BurialSiteContractInterments o
|
from ContractInterments o
|
||||||
left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId
|
left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId
|
||||||
left join IntermentCommittalTypes c on o.intermentCommittalTypeId = c.intermentCommittalTypeId
|
left join IntermentCommittalTypes c on o.intermentCommittalTypeId = c.intermentCommittalTypeId
|
||||||
|
|
||||||
where o.recordDelete_timeMillis is null
|
where o.recordDelete_timeMillis is null
|
||||||
and o.burialSiteContractId = ?
|
and o.contractId = ?
|
||||||
order by t.orderNumber, o.deceasedName, o.intermentNumber`
|
order by t.orderNumber, o.deceasedName, o.intermentNumber`
|
||||||
)
|
)
|
||||||
.all(burialSiteContractId) as BurialSiteContractInterment[]
|
.all(contractId) as ContractInterment[]
|
||||||
|
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release()
|
database.release()
|
||||||
|
|
@ -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[]>;
|
||||||
|
|
@ -2,26 +2,26 @@ import { dateIntegerToString, timeIntegerToString } from '@cityssm/utils-datetim
|
||||||
import { getConfigProperty } from '../helpers/config.helpers.js';
|
import { getConfigProperty } from '../helpers/config.helpers.js';
|
||||||
import { getDynamicsGPDocument } from '../helpers/functions.dynamicsGP.js';
|
import { getDynamicsGPDocument } from '../helpers/functions.dynamicsGP.js';
|
||||||
import { acquireConnection } from './pool.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());
|
const database = connectedDatabase ?? (await acquireConnection());
|
||||||
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
||||||
database.function('userFn_timeIntegerToString', timeIntegerToString);
|
database.function('userFn_timeIntegerToString', timeIntegerToString);
|
||||||
const burialSiteContractTransactions = database
|
const contractTransactions = database
|
||||||
.prepare(`select burialSiteContractId, transactionIndex,
|
.prepare(`select contractId, transactionIndex,
|
||||||
transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString,
|
transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString,
|
||||||
transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString,
|
transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString,
|
||||||
transactionAmount, externalReceiptNumber, transactionNote
|
transactionAmount, externalReceiptNumber, transactionNote
|
||||||
from BurialSiteContractTransactions
|
from ContractTransactions
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and burialSiteContractId = ?
|
and contractId = ?
|
||||||
order by transactionDate, transactionTime, transactionIndex`)
|
order by transactionDate, transactionTime, transactionIndex`)
|
||||||
.all(burialSiteContractId);
|
.all(contractId);
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release();
|
database.release();
|
||||||
}
|
}
|
||||||
if (options.includeIntegrations &&
|
if (options.includeIntegrations &&
|
||||||
getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) {
|
getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) {
|
||||||
for (const transaction of burialSiteContractTransactions) {
|
for (const transaction of contractTransactions) {
|
||||||
if ((transaction.externalReceiptNumber ?? '') !== '') {
|
if ((transaction.externalReceiptNumber ?? '') !== '') {
|
||||||
const gpDocument = await getDynamicsGPDocument(transaction.externalReceiptNumber ?? '');
|
const gpDocument = await getDynamicsGPDocument(transaction.externalReceiptNumber ?? '');
|
||||||
if (gpDocument !== undefined) {
|
if (gpDocument !== undefined) {
|
||||||
|
|
@ -30,5 +30,5 @@ export default async function GetBurialSiteContractTransactions(burialSiteContra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return burialSiteContractTransactions;
|
return contractTransactions;
|
||||||
}
|
}
|
||||||
|
|
@ -6,34 +6,34 @@ import type { PoolConnection } from 'better-sqlite-pool'
|
||||||
|
|
||||||
import { getConfigProperty } from '../helpers/config.helpers.js'
|
import { getConfigProperty } from '../helpers/config.helpers.js'
|
||||||
import { getDynamicsGPDocument } from '../helpers/functions.dynamicsGP.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'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export default async function GetBurialSiteContractTransactions(
|
export default async function GetContractTransactions(
|
||||||
burialSiteContractId: number | string,
|
contractId: number | string,
|
||||||
options: {
|
options: {
|
||||||
includeIntegrations: boolean
|
includeIntegrations: boolean
|
||||||
},
|
},
|
||||||
connectedDatabase?: PoolConnection
|
connectedDatabase?: PoolConnection
|
||||||
): Promise<BurialSiteContractTransaction[]> {
|
): Promise<ContractTransaction[]> {
|
||||||
const database = connectedDatabase ?? (await acquireConnection())
|
const database = connectedDatabase ?? (await acquireConnection())
|
||||||
|
|
||||||
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
||||||
database.function('userFn_timeIntegerToString', timeIntegerToString)
|
database.function('userFn_timeIntegerToString', timeIntegerToString)
|
||||||
|
|
||||||
const burialSiteContractTransactions = database
|
const contractTransactions = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select burialSiteContractId, transactionIndex,
|
`select contractId, transactionIndex,
|
||||||
transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString,
|
transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString,
|
||||||
transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString,
|
transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString,
|
||||||
transactionAmount, externalReceiptNumber, transactionNote
|
transactionAmount, externalReceiptNumber, transactionNote
|
||||||
from BurialSiteContractTransactions
|
from ContractTransactions
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and burialSiteContractId = ?
|
and contractId = ?
|
||||||
order by transactionDate, transactionTime, transactionIndex`
|
order by transactionDate, transactionTime, transactionIndex`
|
||||||
)
|
)
|
||||||
.all(burialSiteContractId) as BurialSiteContractTransaction[]
|
.all(contractId) as ContractTransaction[]
|
||||||
|
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release()
|
database.release()
|
||||||
|
|
@ -43,7 +43,7 @@ export default async function GetBurialSiteContractTransactions(
|
||||||
options.includeIntegrations &&
|
options.includeIntegrations &&
|
||||||
getConfigProperty('settings.dynamicsGP.integrationIsEnabled')
|
getConfigProperty('settings.dynamicsGP.integrationIsEnabled')
|
||||||
) {
|
) {
|
||||||
for (const transaction of burialSiteContractTransactions) {
|
for (const transaction of contractTransactions) {
|
||||||
if ((transaction.externalReceiptNumber ?? '') !== '') {
|
if ((transaction.externalReceiptNumber ?? '') !== '') {
|
||||||
const gpDocument = await getDynamicsGPDocument(
|
const gpDocument = await getDynamicsGPDocument(
|
||||||
transaction.externalReceiptNumber ?? ''
|
transaction.externalReceiptNumber ?? ''
|
||||||
|
|
@ -56,5 +56,5 @@ export default async function GetBurialSiteContractTransactions(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return burialSiteContractTransactions
|
return contractTransactions
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { type DateString } from '@cityssm/utils-datetime';
|
import { type DateString } from '@cityssm/utils-datetime';
|
||||||
import type { PoolConnection } from 'better-sqlite-pool';
|
import type { PoolConnection } from 'better-sqlite-pool';
|
||||||
import type { BurialSiteContract } from '../types/recordTypes.js';
|
import type { Contract } from '../types/recordTypes.js';
|
||||||
export interface GetBurialSiteContractsFilters {
|
export interface GetContractsFilters {
|
||||||
burialSiteId?: number | string;
|
burialSiteId?: number | string;
|
||||||
occupancyTime?: '' | 'past' | 'current' | 'future';
|
occupancyTime?: '' | 'past' | 'current' | 'future';
|
||||||
contractStartDateString?: DateString;
|
contractStartDateString?: DateString;
|
||||||
|
|
@ -15,7 +15,7 @@ export interface GetBurialSiteContractsFilters {
|
||||||
workOrderId?: number | string;
|
workOrderId?: number | string;
|
||||||
notWorkOrderId?: number | string;
|
notWorkOrderId?: number | string;
|
||||||
}
|
}
|
||||||
export interface GetBurialSiteContractsOptions {
|
export interface GetContractsOptions {
|
||||||
/** -1 for no limit */
|
/** -1 for no limit */
|
||||||
limit: number | string;
|
limit: number | string;
|
||||||
offset: number | string;
|
offset: number | string;
|
||||||
|
|
@ -23,7 +23,7 @@ export interface GetBurialSiteContractsOptions {
|
||||||
includeFees: boolean;
|
includeFees: boolean;
|
||||||
includeTransactions: 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;
|
count: number;
|
||||||
burialSiteContracts: BurialSiteContract[];
|
contracts: Contract[];
|
||||||
}>;
|
}>;
|
||||||
|
|
@ -2,9 +2,9 @@ import { dateIntegerToString, dateStringToInteger } from '@cityssm/utils-datetim
|
||||||
import { getConfigProperty } from '../helpers/config.helpers.js';
|
import { getConfigProperty } from '../helpers/config.helpers.js';
|
||||||
import { getContractTypeById } from '../helpers/functions.cache.js';
|
import { getContractTypeById } from '../helpers/functions.cache.js';
|
||||||
import { getBurialSiteNameWhereClause, getOccupancyTimeWhereClause, getOccupantNameWhereClause } from '../helpers/functions.sqlFilters.js';
|
import { getBurialSiteNameWhereClause, getOccupancyTimeWhereClause, getOccupantNameWhereClause } from '../helpers/functions.sqlFilters.js';
|
||||||
import getBurialSiteContractFees from './getBurialSiteContractFees.js';
|
import getContractFees from './getContractFees.js';
|
||||||
// import getBurialSiteContractOccupants from './getBurialSiteContractOccupants.js'
|
// import getContractOccupants from './getContractOccupants.js'
|
||||||
import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js';
|
import getContractTransactions from './getContractTransactions.js';
|
||||||
import { acquireConnection } from './pool.js';
|
import { acquireConnection } from './pool.js';
|
||||||
function buildWhereClause(filters) {
|
function buildWhereClause(filters) {
|
||||||
let sqlWhereClause = ' where o.recordDelete_timeMillis is null';
|
let sqlWhereClause = ' where o.recordDelete_timeMillis is null';
|
||||||
|
|
@ -18,8 +18,8 @@ function buildWhereClause(filters) {
|
||||||
sqlParameters.push(...lotNameFilters.sqlParameters);
|
sqlParameters.push(...lotNameFilters.sqlParameters);
|
||||||
const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, 'o');
|
const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, 'o');
|
||||||
if (occupantNameFilters.sqlParameters.length > 0) {
|
if (occupantNameFilters.sqlParameters.length > 0) {
|
||||||
sqlWhereClause += ` and o.burialSiteContractId in (
|
sqlWhereClause += ` and o.contractId in (
|
||||||
select burialSiteContractId from LotOccupancyOccupants o
|
select contractId from LotOccupancyOccupants o
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
${occupantNameFilters.sqlWhereClause})`;
|
${occupantNameFilters.sqlWhereClause})`;
|
||||||
sqlParameters.push(...occupantNameFilters.sqlParameters);
|
sqlParameters.push(...occupantNameFilters.sqlParameters);
|
||||||
|
|
@ -52,12 +52,12 @@ function buildWhereClause(filters) {
|
||||||
}
|
}
|
||||||
if ((filters.workOrderId ?? '') !== '') {
|
if ((filters.workOrderId ?? '') !== '') {
|
||||||
sqlWhereClause +=
|
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);
|
sqlParameters.push(filters.workOrderId);
|
||||||
}
|
}
|
||||||
if ((filters.notWorkOrderId ?? '') !== '') {
|
if ((filters.notWorkOrderId ?? '') !== '') {
|
||||||
sqlWhereClause +=
|
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);
|
sqlParameters.push(filters.notWorkOrderId);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|
@ -65,26 +65,26 @@ function buildWhereClause(filters) {
|
||||||
sqlParameters
|
sqlParameters
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
async function addInclusions(burialSiteContract, options, database) {
|
async function addInclusions(contract, options, database) {
|
||||||
if (options.includeFees) {
|
if (options.includeFees) {
|
||||||
burialSiteContract.burialSiteContractFees = await getBurialSiteContractFees(burialSiteContract.burialSiteContractId, database);
|
contract.contractFees = await getContractFees(contract.contractId, database);
|
||||||
}
|
}
|
||||||
if (options.includeTransactions) {
|
if (options.includeTransactions) {
|
||||||
burialSiteContract.burialSiteContractTransactions =
|
contract.contractTransactions =
|
||||||
await getBurialSiteContractTransactions(burialSiteContract.burialSiteContractId, { includeIntegrations: false }, database);
|
await getContractTransactions(contract.contractId, { includeIntegrations: false }, database);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if (options.includeInterments) {
|
if (options.includeInterments) {
|
||||||
burialSiteContract.burialSiteContractInterments =
|
contract.contractInterments =
|
||||||
await getBurialSiteContractOccupants(
|
await getContractOccupants(
|
||||||
burialSiteContract.burialSiteContractId,
|
contract.contractId,
|
||||||
database
|
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());
|
const database = connectedDatabase ?? (await acquireConnection());
|
||||||
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
||||||
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
|
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
|
||||||
|
|
@ -95,22 +95,22 @@ export default async function getBurialSiteContracts(filters, options, connected
|
||||||
if (isLimited) {
|
if (isLimited) {
|
||||||
count = database
|
count = database
|
||||||
.prepare(`select count(*) as recordCount
|
.prepare(`select count(*) as recordCount
|
||||||
from BurialSiteContracts o
|
from Contracts o
|
||||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||||
${sqlWhereClause}`)
|
${sqlWhereClause}`)
|
||||||
.get(sqlParameters).recordCount;
|
.get(sqlParameters).recordCount;
|
||||||
}
|
}
|
||||||
let burialSiteContracts = [];
|
let contracts = [];
|
||||||
if (count !== 0) {
|
if (count !== 0) {
|
||||||
burialSiteContracts = database
|
contracts = database
|
||||||
.prepare(`select o.burialSiteContractId,
|
.prepare(`select o.contractId,
|
||||||
o.contractTypeId, t.contractType,
|
o.contractTypeId, t.contractType,
|
||||||
o.burialSiteId, lt.burialSiteType,
|
o.burialSiteId, lt.burialSiteType,
|
||||||
l.burialSiteName,
|
l.burialSiteName,
|
||||||
l.cemeteryId, m.cemeteryName,
|
l.cemeteryId, m.cemeteryName,
|
||||||
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
||||||
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString
|
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 ContractTypes t on o.contractTypeId = t.contractTypeId
|
||||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||||
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
||||||
|
|
@ -122,20 +122,20 @@ export default async function getBurialSiteContracts(filters, options, connected
|
||||||
l.burialSiteNameSegment3,
|
l.burialSiteNameSegment3,
|
||||||
l.burialSiteNameSegment4,
|
l.burialSiteNameSegment4,
|
||||||
l.burialSiteNameSegment5,
|
l.burialSiteNameSegment5,
|
||||||
o.burialSiteId, o.burialSiteContractId desc
|
o.burialSiteId, o.contractId desc
|
||||||
${isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''}`)
|
${isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''}`)
|
||||||
.all(sqlParameters);
|
.all(sqlParameters);
|
||||||
if (!isLimited) {
|
if (!isLimited) {
|
||||||
count = burialSiteContracts.length;
|
count = contracts.length;
|
||||||
}
|
}
|
||||||
for (const burialSiteContract of burialSiteContracts) {
|
for (const contract of contracts) {
|
||||||
const contractType = await getContractTypeById(burialSiteContract.contractTypeId);
|
const contractType = await getContractTypeById(contract.contractTypeId);
|
||||||
if (contractType !== undefined) {
|
if (contractType !== undefined) {
|
||||||
burialSiteContract.printEJS = (contractType.contractTypePrints ?? []).includes('*')
|
contract.printEJS = (contractType.contractTypePrints ?? []).includes('*')
|
||||||
? getConfigProperty('settings.contracts.prints')[0]
|
? getConfigProperty('settings.contracts.prints')[0]
|
||||||
: (contractType.contractTypePrints ?? [])[0];
|
: (contractType.contractTypePrints ?? [])[0];
|
||||||
}
|
}
|
||||||
await addInclusions(burialSiteContract, options, database);
|
await addInclusions(contract, options, database);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
|
|
@ -143,6 +143,6 @@ export default async function getBurialSiteContracts(filters, options, connected
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
count,
|
count,
|
||||||
burialSiteContracts
|
contracts
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -12,14 +12,14 @@ import {
|
||||||
getOccupancyTimeWhereClause,
|
getOccupancyTimeWhereClause,
|
||||||
getOccupantNameWhereClause
|
getOccupantNameWhereClause
|
||||||
} from '../helpers/functions.sqlFilters.js'
|
} 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 getContractFees from './getContractFees.js'
|
||||||
// import getBurialSiteContractOccupants from './getBurialSiteContractOccupants.js'
|
// import getContractOccupants from './getContractOccupants.js'
|
||||||
import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js'
|
import getContractTransactions from './getContractTransactions.js'
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
export interface GetBurialSiteContractsFilters {
|
export interface GetContractsFilters {
|
||||||
burialSiteId?: number | string
|
burialSiteId?: number | string
|
||||||
occupancyTime?: '' | 'past' | 'current' | 'future'
|
occupancyTime?: '' | 'past' | 'current' | 'future'
|
||||||
contractStartDateString?: DateString
|
contractStartDateString?: DateString
|
||||||
|
|
@ -34,7 +34,7 @@ export interface GetBurialSiteContractsFilters {
|
||||||
notWorkOrderId?: number | string
|
notWorkOrderId?: number | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetBurialSiteContractsOptions {
|
export interface GetContractsOptions {
|
||||||
/** -1 for no limit */
|
/** -1 for no limit */
|
||||||
limit: number | string
|
limit: number | string
|
||||||
offset: number | string
|
offset: number | string
|
||||||
|
|
@ -43,7 +43,7 @@ export interface GetBurialSiteContractsOptions {
|
||||||
includeTransactions: boolean
|
includeTransactions: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildWhereClause(filters: GetBurialSiteContractsFilters): {
|
function buildWhereClause(filters: GetContractsFilters): {
|
||||||
sqlWhereClause: string
|
sqlWhereClause: string
|
||||||
sqlParameters: unknown[]
|
sqlParameters: unknown[]
|
||||||
} {
|
} {
|
||||||
|
|
@ -68,8 +68,8 @@ function buildWhereClause(filters: GetBurialSiteContractsFilters): {
|
||||||
'o'
|
'o'
|
||||||
)
|
)
|
||||||
if (occupantNameFilters.sqlParameters.length > 0) {
|
if (occupantNameFilters.sqlParameters.length > 0) {
|
||||||
sqlWhereClause += ` and o.burialSiteContractId in (
|
sqlWhereClause += ` and o.contractId in (
|
||||||
select burialSiteContractId from LotOccupancyOccupants o
|
select contractId from LotOccupancyOccupants o
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
${occupantNameFilters.sqlWhereClause})`
|
${occupantNameFilters.sqlWhereClause})`
|
||||||
sqlParameters.push(...occupantNameFilters.sqlParameters)
|
sqlParameters.push(...occupantNameFilters.sqlParameters)
|
||||||
|
|
@ -117,13 +117,13 @@ function buildWhereClause(filters: GetBurialSiteContractsFilters): {
|
||||||
|
|
||||||
if ((filters.workOrderId ?? '') !== '') {
|
if ((filters.workOrderId ?? '') !== '') {
|
||||||
sqlWhereClause +=
|
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)
|
sqlParameters.push(filters.workOrderId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((filters.notWorkOrderId ?? '') !== '') {
|
if ((filters.notWorkOrderId ?? '') !== '') {
|
||||||
sqlWhereClause +=
|
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)
|
sqlParameters.push(filters.notWorkOrderId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,21 +134,21 @@ function buildWhereClause(filters: GetBurialSiteContractsFilters): {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addInclusions(
|
async function addInclusions(
|
||||||
burialSiteContract: BurialSiteContract,
|
contract: Contract,
|
||||||
options: GetBurialSiteContractsOptions,
|
options: GetContractsOptions,
|
||||||
database: PoolConnection
|
database: PoolConnection
|
||||||
): Promise<BurialSiteContract> {
|
): Promise<Contract> {
|
||||||
if (options.includeFees) {
|
if (options.includeFees) {
|
||||||
burialSiteContract.burialSiteContractFees = await getBurialSiteContractFees(
|
contract.contractFees = await getContractFees(
|
||||||
burialSiteContract.burialSiteContractId,
|
contract.contractId,
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.includeTransactions) {
|
if (options.includeTransactions) {
|
||||||
burialSiteContract.burialSiteContractTransactions =
|
contract.contractTransactions =
|
||||||
await getBurialSiteContractTransactions(
|
await getContractTransactions(
|
||||||
burialSiteContract.burialSiteContractId,
|
contract.contractId,
|
||||||
{ includeIntegrations: false },
|
{ includeIntegrations: false },
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
|
|
@ -156,22 +156,22 @@ async function addInclusions(
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (options.includeInterments) {
|
if (options.includeInterments) {
|
||||||
burialSiteContract.burialSiteContractInterments =
|
contract.contractInterments =
|
||||||
await getBurialSiteContractOccupants(
|
await getContractOccupants(
|
||||||
burialSiteContract.burialSiteContractId,
|
contract.contractId,
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return burialSiteContract
|
return contract
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function getBurialSiteContracts(
|
export default async function getContracts(
|
||||||
filters: GetBurialSiteContractsFilters,
|
filters: GetContractsFilters,
|
||||||
options: GetBurialSiteContractsOptions,
|
options: GetContractsOptions,
|
||||||
connectedDatabase?: PoolConnection
|
connectedDatabase?: PoolConnection
|
||||||
): Promise<{ count: number; burialSiteContracts: BurialSiteContract[] }> {
|
): Promise<{ count: number; contracts: Contract[] }> {
|
||||||
const database = connectedDatabase ?? (await acquireConnection())
|
const database = connectedDatabase ?? (await acquireConnection())
|
||||||
|
|
||||||
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
||||||
|
|
@ -190,7 +190,7 @@ export default async function getBurialSiteContracts(
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select count(*) as recordCount
|
`select count(*) as recordCount
|
||||||
from BurialSiteContracts o
|
from Contracts o
|
||||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||||
${sqlWhereClause}`
|
${sqlWhereClause}`
|
||||||
)
|
)
|
||||||
|
|
@ -198,19 +198,19 @@ export default async function getBurialSiteContracts(
|
||||||
).recordCount
|
).recordCount
|
||||||
}
|
}
|
||||||
|
|
||||||
let burialSiteContracts: BurialSiteContract[] = []
|
let contracts: Contract[] = []
|
||||||
|
|
||||||
if (count !== 0) {
|
if (count !== 0) {
|
||||||
burialSiteContracts = database
|
contracts = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select o.burialSiteContractId,
|
`select o.contractId,
|
||||||
o.contractTypeId, t.contractType,
|
o.contractTypeId, t.contractType,
|
||||||
o.burialSiteId, lt.burialSiteType,
|
o.burialSiteId, lt.burialSiteType,
|
||||||
l.burialSiteName,
|
l.burialSiteName,
|
||||||
l.cemeteryId, m.cemeteryName,
|
l.cemeteryId, m.cemeteryName,
|
||||||
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
||||||
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString
|
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 ContractTypes t on o.contractTypeId = t.contractTypeId
|
||||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||||
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
||||||
|
|
@ -222,31 +222,31 @@ export default async function getBurialSiteContracts(
|
||||||
l.burialSiteNameSegment3,
|
l.burialSiteNameSegment3,
|
||||||
l.burialSiteNameSegment4,
|
l.burialSiteNameSegment4,
|
||||||
l.burialSiteNameSegment5,
|
l.burialSiteNameSegment5,
|
||||||
o.burialSiteId, o.burialSiteContractId desc
|
o.burialSiteId, o.contractId desc
|
||||||
${
|
${
|
||||||
isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''
|
isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
.all(sqlParameters) as BurialSiteContract[]
|
.all(sqlParameters) as Contract[]
|
||||||
|
|
||||||
if (!isLimited) {
|
if (!isLimited) {
|
||||||
count = burialSiteContracts.length
|
count = contracts.length
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const burialSiteContract of burialSiteContracts) {
|
for (const contract of contracts) {
|
||||||
const contractType = await getContractTypeById(
|
const contractType = await getContractTypeById(
|
||||||
burialSiteContract.contractTypeId
|
contract.contractTypeId
|
||||||
)
|
)
|
||||||
|
|
||||||
if (contractType !== undefined) {
|
if (contractType !== undefined) {
|
||||||
burialSiteContract.printEJS = (
|
contract.printEJS = (
|
||||||
contractType.contractTypePrints ?? []
|
contractType.contractTypePrints ?? []
|
||||||
).includes('*')
|
).includes('*')
|
||||||
? getConfigProperty('settings.contracts.prints')[0]
|
? getConfigProperty('settings.contracts.prints')[0]
|
||||||
: (contractType.contractTypePrints ?? [])[0]
|
: (contractType.contractTypePrints ?? [])[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
await addInclusions(burialSiteContract, options, database)
|
await addInclusions(contract, options, database)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -256,6 +256,6 @@ export default async function getBurialSiteContracts(
|
||||||
|
|
||||||
return {
|
return {
|
||||||
count,
|
count,
|
||||||
burialSiteContracts
|
contracts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -24,11 +24,11 @@ export default async function getFees(feeCategoryId, additionalFilters, connecte
|
||||||
f.taxAmount, f.taxPercentage,
|
f.taxAmount, f.taxPercentage,
|
||||||
f.includeQuantity, f.quantityUnit,
|
f.includeQuantity, f.quantityUnit,
|
||||||
f.isRequired, f.orderNumber,
|
f.isRequired, f.orderNumber,
|
||||||
ifnull(lo.burialSiteContractFeeCount, 0) as burialSiteContractFeeCount
|
ifnull(lo.contractFeeCount, 0) as contractFeeCount
|
||||||
from Fees f
|
from Fees f
|
||||||
left join (
|
left join (
|
||||||
select feeId, count(burialSiteContractId) as burialSiteContractFeeCount
|
select feeId, count(contractId) as contractFeeCount
|
||||||
from BurialSiteContractFees
|
from ContractFees
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
group by feeId
|
group by feeId
|
||||||
) lo on f.feeId = lo.feeId
|
) lo on f.feeId = lo.feeId
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,11 @@ export default async function getFees(
|
||||||
f.taxAmount, f.taxPercentage,
|
f.taxAmount, f.taxPercentage,
|
||||||
f.includeQuantity, f.quantityUnit,
|
f.includeQuantity, f.quantityUnit,
|
||||||
f.isRequired, f.orderNumber,
|
f.isRequired, f.orderNumber,
|
||||||
ifnull(lo.burialSiteContractFeeCount, 0) as burialSiteContractFeeCount
|
ifnull(lo.contractFeeCount, 0) as contractFeeCount
|
||||||
from Fees f
|
from Fees f
|
||||||
left join (
|
left join (
|
||||||
select feeId, count(burialSiteContractId) as burialSiteContractFeeCount
|
select feeId, count(contractId) as contractFeeCount
|
||||||
from BurialSiteContractFees
|
from ContractFees
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
group by feeId
|
group by feeId
|
||||||
) lo on f.feeId = lo.feeId
|
) lo on f.feeId = lo.feeId
|
||||||
|
|
|
||||||
|
|
@ -90,12 +90,12 @@ export default async function getReportData(reportName, reportParameters = {}) {
|
||||||
sql = 'select * from BurialSiteFields';
|
sql = 'select * from BurialSiteFields';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'burialSiteContracts-all': {
|
case 'contracts-all': {
|
||||||
sql = 'select * from BurialSiteContracts';
|
sql = 'select * from Contracts';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'burialSiteContracts-current-byCemeteryId': {
|
case 'contracts-current-byCemeteryId': {
|
||||||
sql = `select o.burialSiteContractId,
|
sql = `select o.contractId,
|
||||||
l.burialSiteNameSegment1,
|
l.burialSiteNameSegment1,
|
||||||
l.burialSiteNameSegment2,
|
l.burialSiteNameSegment2,
|
||||||
l.burialSiteNameSegment3,
|
l.burialSiteNameSegment3,
|
||||||
|
|
@ -105,7 +105,7 @@ export default async function getReportData(reportName, reportParameters = {}) {
|
||||||
ot.contractType,
|
ot.contractType,
|
||||||
o.contractStartDate,
|
o.contractStartDate,
|
||||||
o.contractEndDate
|
o.contractEndDate
|
||||||
from BurialSiteContracts o
|
from Contracts o
|
||||||
left join ContractTypes ot on o.contractTypeId = ot.contractTypeId
|
left join ContractTypes ot on o.contractTypeId = ot.contractTypeId
|
||||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
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);
|
sqlParameters.push(dateToInteger(new Date()), reportParameters.cemeteryId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'burialSiteContractComments-all': {
|
case 'contractComments-all': {
|
||||||
sql = 'select * from BurialSiteContractComments';
|
sql = 'select * from ContractComments';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'burialSiteContractFees-all': {
|
case 'contractFees-all': {
|
||||||
sql = 'select * from BurialSiteContractFees';
|
sql = 'select * from ContractFees';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'burialSiteContractFields-all': {
|
case 'contractFields-all': {
|
||||||
sql = 'select * from BurialSiteContractFields';
|
sql = 'select * from ContractFields';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'burialSiteContractTransactions-all': {
|
case 'contractTransactions-all': {
|
||||||
sql = 'select * from BurialSiteContractTransactions';
|
sql = 'select * from ContractTransactions';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'burialSiteContractTransactions-byTransactionDateString': {
|
case 'contractTransactions-byTransactionDateString': {
|
||||||
sql = `select t.burialSiteContractId, t.transactionIndex,
|
sql = `select t.contractId, t.transactionIndex,
|
||||||
t.transactionDate, t.transactionTime,
|
t.transactionDate, t.transactionTime,
|
||||||
t.transactionAmount,
|
t.transactionAmount,
|
||||||
t.externalReceiptNumber, t.transactionNote
|
t.externalReceiptNumber, t.transactionNote
|
||||||
from BurialSiteContractTransactions t
|
from ContractTransactions t
|
||||||
where t.recordDelete_timeMillis is null
|
where t.recordDelete_timeMillis is null
|
||||||
and t.transactionDate = ?`;
|
and t.transactionDate = ?`;
|
||||||
sqlParameters.push(dateStringToInteger(reportParameters.transactionDateString));
|
sqlParameters.push(dateStringToInteger(reportParameters.transactionDateString));
|
||||||
|
|
|
||||||
|
|
@ -119,13 +119,13 @@ export default async function getReportData(
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'burialSiteContracts-all': {
|
case 'contracts-all': {
|
||||||
sql = 'select * from BurialSiteContracts'
|
sql = 'select * from Contracts'
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'burialSiteContracts-current-byCemeteryId': {
|
case 'contracts-current-byCemeteryId': {
|
||||||
sql = `select o.burialSiteContractId,
|
sql = `select o.contractId,
|
||||||
l.burialSiteNameSegment1,
|
l.burialSiteNameSegment1,
|
||||||
l.burialSiteNameSegment2,
|
l.burialSiteNameSegment2,
|
||||||
l.burialSiteNameSegment3,
|
l.burialSiteNameSegment3,
|
||||||
|
|
@ -135,7 +135,7 @@ export default async function getReportData(
|
||||||
ot.contractType,
|
ot.contractType,
|
||||||
o.contractStartDate,
|
o.contractStartDate,
|
||||||
o.contractEndDate
|
o.contractEndDate
|
||||||
from BurialSiteContracts o
|
from Contracts o
|
||||||
left join ContractTypes ot on o.contractTypeId = ot.contractTypeId
|
left join ContractTypes ot on o.contractTypeId = ot.contractTypeId
|
||||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
|
|
@ -148,32 +148,32 @@ export default async function getReportData(
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'burialSiteContractComments-all': {
|
case 'contractComments-all': {
|
||||||
sql = 'select * from BurialSiteContractComments'
|
sql = 'select * from ContractComments'
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'burialSiteContractFees-all': {
|
case 'contractFees-all': {
|
||||||
sql = 'select * from BurialSiteContractFees'
|
sql = 'select * from ContractFees'
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'burialSiteContractFields-all': {
|
case 'contractFields-all': {
|
||||||
sql = 'select * from BurialSiteContractFields'
|
sql = 'select * from ContractFields'
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'burialSiteContractTransactions-all': {
|
case 'contractTransactions-all': {
|
||||||
sql = 'select * from BurialSiteContractTransactions'
|
sql = 'select * from ContractTransactions'
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'burialSiteContractTransactions-byTransactionDateString': {
|
case 'contractTransactions-byTransactionDateString': {
|
||||||
sql = `select t.burialSiteContractId, t.transactionIndex,
|
sql = `select t.contractId, t.transactionIndex,
|
||||||
t.transactionDate, t.transactionTime,
|
t.transactionDate, t.transactionTime,
|
||||||
t.transactionAmount,
|
t.transactionAmount,
|
||||||
t.externalReceiptNumber, t.transactionNote
|
t.externalReceiptNumber, t.transactionNote
|
||||||
from BurialSiteContractTransactions t
|
from ContractTransactions t
|
||||||
where t.recordDelete_timeMillis is null
|
where t.recordDelete_timeMillis is null
|
||||||
and t.transactionDate = ?`
|
and t.transactionDate = ?`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { dateIntegerToString } from '@cityssm/utils-datetime';
|
import { dateIntegerToString } from '@cityssm/utils-datetime';
|
||||||
import getBurialSiteContracts from './getBurialSiteContracts.js';
|
|
||||||
import getBurialSites from './getBurialSites.js';
|
import getBurialSites from './getBurialSites.js';
|
||||||
|
import getContracts from './getContracts.js';
|
||||||
import getWorkOrderComments from './getWorkOrderComments.js';
|
import getWorkOrderComments from './getWorkOrderComments.js';
|
||||||
import getWorkOrderMilestones from './getWorkOrderMilestones.js';
|
import getWorkOrderMilestones from './getWorkOrderMilestones.js';
|
||||||
import { acquireConnection } from './pool.js';
|
import { acquireConnection } from './pool.js';
|
||||||
|
|
@ -24,10 +24,10 @@ async function _getWorkOrder(sql, workOrderIdOrWorkOrderNumber, options, connect
|
||||||
}, {
|
}, {
|
||||||
limit: -1,
|
limit: -1,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
includeBurialSiteContractCount: false
|
includeContractCount: false
|
||||||
}, database);
|
}, database);
|
||||||
workOrder.workOrderBurialSites = burialSiteResults.burialSites;
|
workOrder.workOrderBurialSites = burialSiteResults.burialSites;
|
||||||
const workOrderBurialSiteContractsResults = await getBurialSiteContracts({
|
const workOrderContractsResults = await getContracts({
|
||||||
workOrderId: workOrder.workOrderId
|
workOrderId: workOrder.workOrderId
|
||||||
}, {
|
}, {
|
||||||
limit: -1,
|
limit: -1,
|
||||||
|
|
@ -36,8 +36,8 @@ async function _getWorkOrder(sql, workOrderIdOrWorkOrderNumber, options, connect
|
||||||
includeFees: false,
|
includeFees: false,
|
||||||
includeTransactions: false
|
includeTransactions: false
|
||||||
}, database);
|
}, database);
|
||||||
workOrder.workOrderBurialSiteContracts =
|
workOrder.workOrderContracts =
|
||||||
workOrderBurialSiteContractsResults.burialSiteContracts;
|
workOrderContractsResults.contracts;
|
||||||
}
|
}
|
||||||
if (options.includeComments) {
|
if (options.includeComments) {
|
||||||
workOrder.workOrderComments = await getWorkOrderComments(workOrder.workOrderId, database);
|
workOrder.workOrderComments = await getWorkOrderComments(workOrder.workOrderId, database);
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ import type { PoolConnection } from 'better-sqlite-pool'
|
||||||
|
|
||||||
import type { WorkOrder } from '../types/recordTypes.js'
|
import type { WorkOrder } from '../types/recordTypes.js'
|
||||||
|
|
||||||
import getBurialSiteContracts from './getBurialSiteContracts.js'
|
|
||||||
import getBurialSites from './getBurialSites.js'
|
import getBurialSites from './getBurialSites.js'
|
||||||
|
import getContracts from './getContracts.js'
|
||||||
import getWorkOrderComments from './getWorkOrderComments.js'
|
import getWorkOrderComments from './getWorkOrderComments.js'
|
||||||
import getWorkOrderMilestones from './getWorkOrderMilestones.js'
|
import getWorkOrderMilestones from './getWorkOrderMilestones.js'
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
@ -48,14 +48,14 @@ async function _getWorkOrder(
|
||||||
{
|
{
|
||||||
limit: -1,
|
limit: -1,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
includeBurialSiteContractCount: false
|
includeContractCount: false
|
||||||
},
|
},
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
|
|
||||||
workOrder.workOrderBurialSites = burialSiteResults.burialSites
|
workOrder.workOrderBurialSites = burialSiteResults.burialSites
|
||||||
|
|
||||||
const workOrderBurialSiteContractsResults = await getBurialSiteContracts(
|
const workOrderContractsResults = await getContracts(
|
||||||
{
|
{
|
||||||
workOrderId: workOrder.workOrderId
|
workOrderId: workOrder.workOrderId
|
||||||
},
|
},
|
||||||
|
|
@ -69,8 +69,8 @@ async function _getWorkOrder(
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
|
|
||||||
workOrder.workOrderBurialSiteContracts =
|
workOrder.workOrderContracts =
|
||||||
workOrderBurialSiteContractsResults.burialSiteContracts
|
workOrderContractsResults.contracts
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.includeComments) {
|
if (options.includeComments) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { dateIntegerToString, dateStringToInteger, dateToInteger, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime';
|
import { dateIntegerToString, dateStringToInteger, dateToInteger, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime';
|
||||||
import { getConfigProperty } from '../helpers/config.helpers.js';
|
import { getConfigProperty } from '../helpers/config.helpers.js';
|
||||||
import getBurialSiteContracts from './getBurialSiteContracts.js';
|
import getContracts from './getContracts.js';
|
||||||
import getBurialSites from './getBurialSites.js';
|
import getBurialSites from './getBurialSites.js';
|
||||||
import { acquireConnection } from './pool.js';
|
import { acquireConnection } from './pool.js';
|
||||||
// eslint-disable-next-line security/detect-unsafe-regex
|
// eslint-disable-next-line security/detect-unsafe-regex
|
||||||
|
|
@ -127,10 +127,10 @@ export default async function getWorkOrderMilestones(filters, options, connected
|
||||||
}, {
|
}, {
|
||||||
limit: -1,
|
limit: -1,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
includeBurialSiteContractCount: false
|
includeContractCount: false
|
||||||
}, database);
|
}, database);
|
||||||
workOrderMilestone.workOrderBurialSites = burialSites.burialSites;
|
workOrderMilestone.workOrderBurialSites = burialSites.burialSites;
|
||||||
const burialSiteContracts = await getBurialSiteContracts({
|
const contracts = await getContracts({
|
||||||
workOrderId: workOrderMilestone.workOrderId
|
workOrderId: workOrderMilestone.workOrderId
|
||||||
}, {
|
}, {
|
||||||
limit: -1,
|
limit: -1,
|
||||||
|
|
@ -139,8 +139,8 @@ export default async function getWorkOrderMilestones(filters, options, connected
|
||||||
includeFees: false,
|
includeFees: false,
|
||||||
includeTransactions: false
|
includeTransactions: false
|
||||||
}, database);
|
}, database);
|
||||||
workOrderMilestone.workOrderBurialSiteContracts =
|
workOrderMilestone.workOrderContracts =
|
||||||
burialSiteContracts.burialSiteContracts;
|
contracts.contracts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import type { PoolConnection } from 'better-sqlite-pool'
|
||||||
import { getConfigProperty } from '../helpers/config.helpers.js'
|
import { getConfigProperty } from '../helpers/config.helpers.js'
|
||||||
import type { WorkOrderMilestone } from '../types/recordTypes.js'
|
import type { WorkOrderMilestone } from '../types/recordTypes.js'
|
||||||
|
|
||||||
import getBurialSiteContracts from './getBurialSiteContracts.js'
|
import getContracts from './getContracts.js'
|
||||||
import getBurialSites from './getBurialSites.js'
|
import getBurialSites from './getBurialSites.js'
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
|
|
@ -214,14 +214,14 @@ export default async function getWorkOrderMilestones(
|
||||||
{
|
{
|
||||||
limit: -1,
|
limit: -1,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
includeBurialSiteContractCount: false
|
includeContractCount: false
|
||||||
},
|
},
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
|
|
||||||
workOrderMilestone.workOrderBurialSites = burialSites.burialSites
|
workOrderMilestone.workOrderBurialSites = burialSites.burialSites
|
||||||
|
|
||||||
const burialSiteContracts = await getBurialSiteContracts(
|
const contracts = await getContracts(
|
||||||
{
|
{
|
||||||
workOrderId: workOrderMilestone.workOrderId
|
workOrderId: workOrderMilestone.workOrderId
|
||||||
},
|
},
|
||||||
|
|
@ -235,8 +235,8 @@ export default async function getWorkOrderMilestones(
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
|
|
||||||
workOrderMilestone.workOrderBurialSiteContracts =
|
workOrderMilestone.workOrderContracts =
|
||||||
burialSiteContracts.burialSiteContracts
|
contracts.contracts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue