show funeral home upcoming contracts
parent
7371be711a
commit
39dc10369f
|
|
@ -13,6 +13,7 @@ export interface GetContractsFilters {
|
||||||
burialSiteNameSearchType?: '' | 'endsWith' | 'startsWith';
|
burialSiteNameSearchType?: '' | 'endsWith' | 'startsWith';
|
||||||
burialSiteTypeId?: number | string;
|
burialSiteTypeId?: number | string;
|
||||||
funeralHomeId?: number | string;
|
funeralHomeId?: number | string;
|
||||||
|
funeralTime?: '' | 'upcoming';
|
||||||
notWorkOrderId?: number | string;
|
notWorkOrderId?: number | string;
|
||||||
workOrderId?: number | string;
|
workOrderId?: number | string;
|
||||||
}
|
}
|
||||||
|
|
@ -20,6 +21,7 @@ export interface GetContractsOptions {
|
||||||
/** -1 for no limit */
|
/** -1 for no limit */
|
||||||
limit: number | string;
|
limit: number | string;
|
||||||
offset: number | string;
|
offset: number | string;
|
||||||
|
orderBy?: string;
|
||||||
includeFees: boolean;
|
includeFees: boolean;
|
||||||
includeInterments: boolean;
|
includeInterments: boolean;
|
||||||
includeTransactions: boolean;
|
includeTransactions: boolean;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { dateIntegerToString, dateStringToInteger, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime';
|
import { dateIntegerToString, dateStringToInteger, dateToInteger, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime';
|
||||||
import sqlite from 'better-sqlite3';
|
import sqlite from 'better-sqlite3';
|
||||||
import { getConfigProperty } from '../helpers/config.helpers.js';
|
import { getConfigProperty } from '../helpers/config.helpers.js';
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||||
|
|
@ -20,49 +20,51 @@ export default async function getContracts(filters, options, connectedDatabase)
|
||||||
if (isLimited) {
|
if (isLimited) {
|
||||||
count = database
|
count = database
|
||||||
.prepare(`select count(*) as recordCount
|
.prepare(`select count(*) as recordCount
|
||||||
from Contracts o
|
from Contracts c
|
||||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
left join BurialSites l on c.burialSiteId = l.burialSiteId
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
${sqlWhereClause}`)
|
${sqlWhereClause}`)
|
||||||
.get(sqlParameters).recordCount;
|
.get(sqlParameters).recordCount;
|
||||||
}
|
}
|
||||||
let contracts = [];
|
let contracts = [];
|
||||||
if (count !== 0) {
|
if (count !== 0) {
|
||||||
contracts = database
|
contracts = database
|
||||||
.prepare(`select o.contractId,
|
.prepare(`select c.contractId,
|
||||||
o.contractTypeId, t.contractType, t.isPreneed,
|
c.contractTypeId, t.contractType, t.isPreneed,
|
||||||
o.burialSiteId, lt.burialSiteType, l.burialSiteName,
|
c.burialSiteId, lt.burialSiteType, l.burialSiteName,
|
||||||
case when l.recordDelete_timeMillis is null then 1 else 0 end as burialSiteIsActive,
|
case when l.recordDelete_timeMillis is null then 1 else 0 end as burialSiteIsActive,
|
||||||
l.cemeteryId, m.cemeteryName,
|
l.cemeteryId, m.cemeteryName,
|
||||||
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
c.contractStartDate, userFn_dateIntegerToString(c.contractStartDate) as contractStartDateString,
|
||||||
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
c.contractEndDate, userFn_dateIntegerToString(c.contractEndDate) as contractEndDateString,
|
||||||
o.purchaserName, o.purchaserAddress1, o.purchaserAddress2,
|
c.purchaserName, c.purchaserAddress1, c.purchaserAddress2,
|
||||||
o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode,
|
c.purchaserCity, c.purchaserProvince, c.purchaserPostalCode,
|
||||||
o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship,
|
c.purchaserPhoneNumber, c.purchaserEmail, c.purchaserRelationship,
|
||||||
o.funeralHomeId, o.funeralDirectorName, f.funeralHomeName,
|
c.funeralHomeId, c.funeralDirectorName, f.funeralHomeName,
|
||||||
|
|
||||||
o.funeralDate, userFn_dateIntegerToString(o.funeralDate) as funeralDateString,
|
c.funeralDate, userFn_dateIntegerToString(c.funeralDate) as funeralDateString,
|
||||||
o.funeralTime,
|
c.funeralTime,
|
||||||
userFn_timeIntegerToString(o.funeralTime) as funeralTimeString,
|
userFn_timeIntegerToString(c.funeralTime) as funeralTimeString,
|
||||||
userFn_timeIntegerToPeriodString(o.funeralTime) as funeralTimePeriodString,
|
userFn_timeIntegerToPeriodString(c.funeralTime) as funeralTimePeriodString,
|
||||||
o.directionOfArrival,
|
c.directionOfArrival,
|
||||||
o.committalTypeId, c.committalType
|
c.committalTypeId, cm.committalType
|
||||||
from Contracts o
|
from Contracts c
|
||||||
left join ContractTypes t on o.contractTypeId = t.contractTypeId
|
left join ContractTypes t on c.contractTypeId = t.contractTypeId
|
||||||
left join CommittalTypes c on o.committalTypeId = c.committalTypeId
|
left join CommittalTypes cm on c.committalTypeId = cm.committalTypeId
|
||||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
left join BurialSites l on c.burialSiteId = l.burialSiteId
|
||||||
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
left join FuneralHomes f on o.funeralHomeId = f.funeralHomeId
|
left join FuneralHomes f on c.funeralHomeId = f.funeralHomeId
|
||||||
${sqlWhereClause}
|
${sqlWhereClause}
|
||||||
order by o.contractStartDate desc, ifnull(o.contractEndDate, 99999999) desc,
|
${options.orderBy !== undefined && options.orderBy !== ''
|
||||||
l.burialSiteNameSegment1,
|
? ` order by ${options.orderBy}`
|
||||||
l.burialSiteNameSegment2,
|
: `order by c.contractStartDate desc, ifnull(c.contractEndDate, 99999999) desc,
|
||||||
l.burialSiteNameSegment3,
|
l.burialSiteNameSegment1,
|
||||||
l.burialSiteNameSegment4,
|
l.burialSiteNameSegment2,
|
||||||
l.burialSiteNameSegment5,
|
l.burialSiteNameSegment3,
|
||||||
o.burialSiteId, o.contractId desc
|
l.burialSiteNameSegment4,
|
||||||
${isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''}`)
|
l.burialSiteNameSegment5,
|
||||||
|
c.burialSiteId, c.contractId desc`}
|
||||||
|
${isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''}`)
|
||||||
.all(sqlParameters);
|
.all(sqlParameters);
|
||||||
if (!isLimited) {
|
if (!isLimited) {
|
||||||
count = contracts.length;
|
count = contracts.length;
|
||||||
|
|
@ -99,38 +101,38 @@ async function addInclusions(contract, options, database) {
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line complexity
|
// eslint-disable-next-line complexity
|
||||||
function buildWhereClause(filters) {
|
function buildWhereClause(filters) {
|
||||||
let sqlWhereClause = ' where o.recordDelete_timeMillis is null';
|
let sqlWhereClause = ' where c.recordDelete_timeMillis is null';
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
if ((filters.burialSiteId ?? '') !== '') {
|
if ((filters.burialSiteId ?? '') !== '') {
|
||||||
sqlWhereClause += ' and o.burialSiteId = ?';
|
sqlWhereClause += ' and c.burialSiteId = ?';
|
||||||
sqlParameters.push(filters.burialSiteId);
|
sqlParameters.push(filters.burialSiteId);
|
||||||
}
|
}
|
||||||
const burialSiteNameFilters = getBurialSiteNameWhereClause(filters.burialSiteName, filters.burialSiteNameSearchType ?? '', 'l');
|
const burialSiteNameFilters = getBurialSiteNameWhereClause(filters.burialSiteName, filters.burialSiteNameSearchType ?? '', 'l');
|
||||||
sqlWhereClause += burialSiteNameFilters.sqlWhereClause;
|
sqlWhereClause += burialSiteNameFilters.sqlWhereClause;
|
||||||
sqlParameters.push(...burialSiteNameFilters.sqlParameters);
|
sqlParameters.push(...burialSiteNameFilters.sqlParameters);
|
||||||
const deceasedNameFilters = getDeceasedNameWhereClause(filters.deceasedName, 'o');
|
const deceasedNameFilters = getDeceasedNameWhereClause(filters.deceasedName, 'c');
|
||||||
if (deceasedNameFilters.sqlParameters.length > 0) {
|
if (deceasedNameFilters.sqlParameters.length > 0) {
|
||||||
sqlWhereClause += ` and o.contractId in (
|
sqlWhereClause += ` and c.contractId in (
|
||||||
select contractId from ContractInterments o
|
select contractId from ContractInterments c
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
${deceasedNameFilters.sqlWhereClause})`;
|
${deceasedNameFilters.sqlWhereClause})`;
|
||||||
sqlParameters.push(...deceasedNameFilters.sqlParameters);
|
sqlParameters.push(...deceasedNameFilters.sqlParameters);
|
||||||
}
|
}
|
||||||
if ((filters.contractTypeId ?? '') !== '') {
|
if ((filters.contractTypeId ?? '') !== '') {
|
||||||
sqlWhereClause += ' and o.contractTypeId = ?';
|
sqlWhereClause += ' and c.contractTypeId = ?';
|
||||||
sqlParameters.push(filters.contractTypeId);
|
sqlParameters.push(filters.contractTypeId);
|
||||||
}
|
}
|
||||||
const contractTimeFilters = getContractTimeWhereClause(filters.contractTime ?? '', 'o');
|
const contractTimeFilters = getContractTimeWhereClause(filters.contractTime ?? '', 'c');
|
||||||
sqlWhereClause += contractTimeFilters.sqlWhereClause;
|
sqlWhereClause += contractTimeFilters.sqlWhereClause;
|
||||||
sqlParameters.push(...contractTimeFilters.sqlParameters);
|
sqlParameters.push(...contractTimeFilters.sqlParameters);
|
||||||
if ((filters.contractStartDateString ?? '') !== '') {
|
if ((filters.contractStartDateString ?? '') !== '') {
|
||||||
sqlWhereClause += ' and o.contractStartDate = ?';
|
sqlWhereClause += ' and c.contractStartDate = ?';
|
||||||
sqlParameters.push(dateStringToInteger(filters.contractStartDateString));
|
sqlParameters.push(dateStringToInteger(filters.contractStartDateString));
|
||||||
}
|
}
|
||||||
if ((filters.contractEffectiveDateString ?? '') !== '') {
|
if ((filters.contractEffectiveDateString ?? '') !== '') {
|
||||||
sqlWhereClause += ` and (
|
sqlWhereClause += ` and (
|
||||||
o.contractEndDate is null
|
c.contractEndDate is null
|
||||||
or (o.contractStartDate <= ? and o.contractEndDate >= ?)
|
or (c.contractStartDate <= ? and c.contractEndDate >= ?)
|
||||||
)`;
|
)`;
|
||||||
sqlParameters.push(dateStringToInteger(filters.contractEffectiveDateString), dateStringToInteger(filters.contractEffectiveDateString));
|
sqlParameters.push(dateStringToInteger(filters.contractEffectiveDateString), dateStringToInteger(filters.contractEffectiveDateString));
|
||||||
}
|
}
|
||||||
|
|
@ -143,17 +145,21 @@ function buildWhereClause(filters) {
|
||||||
sqlParameters.push(filters.burialSiteTypeId);
|
sqlParameters.push(filters.burialSiteTypeId);
|
||||||
}
|
}
|
||||||
if ((filters.funeralHomeId ?? '') !== '') {
|
if ((filters.funeralHomeId ?? '') !== '') {
|
||||||
sqlWhereClause += ' and o.funeralHomeId = ?';
|
sqlWhereClause += ' and c.funeralHomeId = ?';
|
||||||
sqlParameters.push(filters.funeralHomeId);
|
sqlParameters.push(filters.funeralHomeId);
|
||||||
}
|
}
|
||||||
|
if ((filters.funeralTime ?? '') === 'upcoming') {
|
||||||
|
sqlWhereClause += ' and c.funeralDate >= ?';
|
||||||
|
sqlParameters.push(dateToInteger(new Date()));
|
||||||
|
}
|
||||||
if ((filters.workOrderId ?? '') !== '') {
|
if ((filters.workOrderId ?? '') !== '') {
|
||||||
sqlWhereClause +=
|
sqlWhereClause +=
|
||||||
' and o.contractId in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)';
|
' and c.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.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)';
|
' and c.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)';
|
||||||
sqlParameters.push(filters.notWorkOrderId);
|
sqlParameters.push(filters.notWorkOrderId);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {
|
||||||
type DateString,
|
type DateString,
|
||||||
dateIntegerToString,
|
dateIntegerToString,
|
||||||
dateStringToInteger,
|
dateStringToInteger,
|
||||||
|
dateToInteger,
|
||||||
timeIntegerToPeriodString,
|
timeIntegerToPeriodString,
|
||||||
timeIntegerToString
|
timeIntegerToString
|
||||||
} from '@cityssm/utils-datetime'
|
} from '@cityssm/utils-datetime'
|
||||||
|
|
@ -36,7 +37,9 @@ export interface GetContractsFilters {
|
||||||
burialSiteNameSearchType?: '' | 'endsWith' | 'startsWith'
|
burialSiteNameSearchType?: '' | 'endsWith' | 'startsWith'
|
||||||
|
|
||||||
burialSiteTypeId?: number | string
|
burialSiteTypeId?: number | string
|
||||||
|
|
||||||
funeralHomeId?: number | string
|
funeralHomeId?: number | string
|
||||||
|
funeralTime?: '' | 'upcoming'
|
||||||
|
|
||||||
notWorkOrderId?: number | string
|
notWorkOrderId?: number | string
|
||||||
workOrderId?: number | string
|
workOrderId?: number | string
|
||||||
|
|
@ -47,6 +50,8 @@ export interface GetContractsOptions {
|
||||||
limit: number | string
|
limit: number | string
|
||||||
offset: number | string
|
offset: number | string
|
||||||
|
|
||||||
|
orderBy?: string
|
||||||
|
|
||||||
includeFees: boolean
|
includeFees: boolean
|
||||||
includeInterments: boolean
|
includeInterments: boolean
|
||||||
includeTransactions: boolean
|
includeTransactions: boolean
|
||||||
|
|
@ -62,7 +67,9 @@ export default async function getContracts(
|
||||||
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
||||||
database.function('userFn_timeIntegerToString', timeIntegerToString)
|
database.function('userFn_timeIntegerToString', timeIntegerToString)
|
||||||
database.function(
|
database.function(
|
||||||
'userFn_timeIntegerToPeriodString', timeIntegerToPeriodString)
|
'userFn_timeIntegerToPeriodString',
|
||||||
|
timeIntegerToPeriodString
|
||||||
|
)
|
||||||
|
|
||||||
const { sqlParameters, sqlWhereClause } = buildWhereClause(filters)
|
const { sqlParameters, sqlWhereClause } = buildWhereClause(filters)
|
||||||
|
|
||||||
|
|
@ -78,10 +85,10 @@ export default async function getContracts(
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select count(*) as recordCount
|
`select count(*) as recordCount
|
||||||
from Contracts o
|
from Contracts c
|
||||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
left join BurialSites l on c.burialSiteId = l.burialSiteId
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
${sqlWhereClause}`
|
${sqlWhereClause}`
|
||||||
)
|
)
|
||||||
.get(sqlParameters) as { recordCount: number }
|
.get(sqlParameters) as { recordCount: number }
|
||||||
).recordCount
|
).recordCount
|
||||||
|
|
@ -92,42 +99,44 @@ export default async function getContracts(
|
||||||
if (count !== 0) {
|
if (count !== 0) {
|
||||||
contracts = database
|
contracts = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select o.contractId,
|
`select c.contractId,
|
||||||
o.contractTypeId, t.contractType, t.isPreneed,
|
c.contractTypeId, t.contractType, t.isPreneed,
|
||||||
o.burialSiteId, lt.burialSiteType, l.burialSiteName,
|
c.burialSiteId, lt.burialSiteType, l.burialSiteName,
|
||||||
case when l.recordDelete_timeMillis is null then 1 else 0 end as burialSiteIsActive,
|
case when l.recordDelete_timeMillis is null then 1 else 0 end as burialSiteIsActive,
|
||||||
l.cemeteryId, m.cemeteryName,
|
l.cemeteryId, m.cemeteryName,
|
||||||
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
c.contractStartDate, userFn_dateIntegerToString(c.contractStartDate) as contractStartDateString,
|
||||||
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
c.contractEndDate, userFn_dateIntegerToString(c.contractEndDate) as contractEndDateString,
|
||||||
o.purchaserName, o.purchaserAddress1, o.purchaserAddress2,
|
c.purchaserName, c.purchaserAddress1, c.purchaserAddress2,
|
||||||
o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode,
|
c.purchaserCity, c.purchaserProvince, c.purchaserPostalCode,
|
||||||
o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship,
|
c.purchaserPhoneNumber, c.purchaserEmail, c.purchaserRelationship,
|
||||||
o.funeralHomeId, o.funeralDirectorName, f.funeralHomeName,
|
c.funeralHomeId, c.funeralDirectorName, f.funeralHomeName,
|
||||||
|
|
||||||
o.funeralDate, userFn_dateIntegerToString(o.funeralDate) as funeralDateString,
|
c.funeralDate, userFn_dateIntegerToString(c.funeralDate) as funeralDateString,
|
||||||
o.funeralTime,
|
c.funeralTime,
|
||||||
userFn_timeIntegerToString(o.funeralTime) as funeralTimeString,
|
userFn_timeIntegerToString(c.funeralTime) as funeralTimeString,
|
||||||
userFn_timeIntegerToPeriodString(o.funeralTime) as funeralTimePeriodString,
|
userFn_timeIntegerToPeriodString(c.funeralTime) as funeralTimePeriodString,
|
||||||
o.directionOfArrival,
|
c.directionOfArrival,
|
||||||
o.committalTypeId, c.committalType
|
c.committalTypeId, cm.committalType
|
||||||
from Contracts o
|
from Contracts c
|
||||||
left join ContractTypes t on o.contractTypeId = t.contractTypeId
|
left join ContractTypes t on c.contractTypeId = t.contractTypeId
|
||||||
left join CommittalTypes c on o.committalTypeId = c.committalTypeId
|
left join CommittalTypes cm on c.committalTypeId = cm.committalTypeId
|
||||||
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
left join BurialSites l on c.burialSiteId = l.burialSiteId
|
||||||
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
left join FuneralHomes f on o.funeralHomeId = f.funeralHomeId
|
left join FuneralHomes f on c.funeralHomeId = f.funeralHomeId
|
||||||
${sqlWhereClause}
|
${sqlWhereClause}
|
||||||
order by o.contractStartDate desc, ifnull(o.contractEndDate, 99999999) desc,
|
${
|
||||||
l.burialSiteNameSegment1,
|
options.orderBy !== undefined && options.orderBy !== ''
|
||||||
l.burialSiteNameSegment2,
|
? ` order by ${options.orderBy}`
|
||||||
l.burialSiteNameSegment3,
|
: `order by c.contractStartDate desc, ifnull(c.contractEndDate, 99999999) desc,
|
||||||
l.burialSiteNameSegment4,
|
l.burialSiteNameSegment1,
|
||||||
l.burialSiteNameSegment5,
|
l.burialSiteNameSegment2,
|
||||||
o.burialSiteId, o.contractId desc
|
l.burialSiteNameSegment3,
|
||||||
${
|
l.burialSiteNameSegment4,
|
||||||
isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''
|
l.burialSiteNameSegment5,
|
||||||
}`
|
c.burialSiteId, c.contractId desc`
|
||||||
|
}
|
||||||
|
${isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''}`
|
||||||
)
|
)
|
||||||
.all(sqlParameters) as Contract[]
|
.all(sqlParameters) as Contract[]
|
||||||
|
|
||||||
|
|
@ -192,11 +201,11 @@ function buildWhereClause(filters: GetContractsFilters): {
|
||||||
sqlParameters: unknown[]
|
sqlParameters: unknown[]
|
||||||
sqlWhereClause: string
|
sqlWhereClause: string
|
||||||
} {
|
} {
|
||||||
let sqlWhereClause = ' where o.recordDelete_timeMillis is null'
|
let sqlWhereClause = ' where c.recordDelete_timeMillis is null'
|
||||||
const sqlParameters: unknown[] = []
|
const sqlParameters: unknown[] = []
|
||||||
|
|
||||||
if ((filters.burialSiteId ?? '') !== '') {
|
if ((filters.burialSiteId ?? '') !== '') {
|
||||||
sqlWhereClause += ' and o.burialSiteId = ?'
|
sqlWhereClause += ' and c.burialSiteId = ?'
|
||||||
sqlParameters.push(filters.burialSiteId)
|
sqlParameters.push(filters.burialSiteId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,30 +219,30 @@ function buildWhereClause(filters: GetContractsFilters): {
|
||||||
|
|
||||||
const deceasedNameFilters = getDeceasedNameWhereClause(
|
const deceasedNameFilters = getDeceasedNameWhereClause(
|
||||||
filters.deceasedName,
|
filters.deceasedName,
|
||||||
'o'
|
'c'
|
||||||
)
|
)
|
||||||
if (deceasedNameFilters.sqlParameters.length > 0) {
|
if (deceasedNameFilters.sqlParameters.length > 0) {
|
||||||
sqlWhereClause += ` and o.contractId in (
|
sqlWhereClause += ` and c.contractId in (
|
||||||
select contractId from ContractInterments o
|
select contractId from ContractInterments c
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
${deceasedNameFilters.sqlWhereClause})`
|
${deceasedNameFilters.sqlWhereClause})`
|
||||||
sqlParameters.push(...deceasedNameFilters.sqlParameters)
|
sqlParameters.push(...deceasedNameFilters.sqlParameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((filters.contractTypeId ?? '') !== '') {
|
if ((filters.contractTypeId ?? '') !== '') {
|
||||||
sqlWhereClause += ' and o.contractTypeId = ?'
|
sqlWhereClause += ' and c.contractTypeId = ?'
|
||||||
sqlParameters.push(filters.contractTypeId)
|
sqlParameters.push(filters.contractTypeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
const contractTimeFilters = getContractTimeWhereClause(
|
const contractTimeFilters = getContractTimeWhereClause(
|
||||||
filters.contractTime ?? '',
|
filters.contractTime ?? '',
|
||||||
'o'
|
'c'
|
||||||
)
|
)
|
||||||
sqlWhereClause += contractTimeFilters.sqlWhereClause
|
sqlWhereClause += contractTimeFilters.sqlWhereClause
|
||||||
sqlParameters.push(...contractTimeFilters.sqlParameters)
|
sqlParameters.push(...contractTimeFilters.sqlParameters)
|
||||||
|
|
||||||
if ((filters.contractStartDateString ?? '') !== '') {
|
if ((filters.contractStartDateString ?? '') !== '') {
|
||||||
sqlWhereClause += ' and o.contractStartDate = ?'
|
sqlWhereClause += ' and c.contractStartDate = ?'
|
||||||
sqlParameters.push(
|
sqlParameters.push(
|
||||||
dateStringToInteger(filters.contractStartDateString as DateString)
|
dateStringToInteger(filters.contractStartDateString as DateString)
|
||||||
)
|
)
|
||||||
|
|
@ -241,8 +250,8 @@ function buildWhereClause(filters: GetContractsFilters): {
|
||||||
|
|
||||||
if ((filters.contractEffectiveDateString ?? '') !== '') {
|
if ((filters.contractEffectiveDateString ?? '') !== '') {
|
||||||
sqlWhereClause += ` and (
|
sqlWhereClause += ` and (
|
||||||
o.contractEndDate is null
|
c.contractEndDate is null
|
||||||
or (o.contractStartDate <= ? and o.contractEndDate >= ?)
|
or (c.contractStartDate <= ? and c.contractEndDate >= ?)
|
||||||
)`
|
)`
|
||||||
sqlParameters.push(
|
sqlParameters.push(
|
||||||
dateStringToInteger(filters.contractEffectiveDateString as DateString),
|
dateStringToInteger(filters.contractEffectiveDateString as DateString),
|
||||||
|
|
@ -261,19 +270,24 @@ function buildWhereClause(filters: GetContractsFilters): {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((filters.funeralHomeId ?? '') !== '') {
|
if ((filters.funeralHomeId ?? '') !== '') {
|
||||||
sqlWhereClause += ' and o.funeralHomeId = ?'
|
sqlWhereClause += ' and c.funeralHomeId = ?'
|
||||||
sqlParameters.push(filters.funeralHomeId)
|
sqlParameters.push(filters.funeralHomeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((filters.funeralTime ?? '') === 'upcoming') {
|
||||||
|
sqlWhereClause += ' and c.funeralDate >= ?'
|
||||||
|
sqlParameters.push(dateToInteger(new Date()))
|
||||||
|
}
|
||||||
|
|
||||||
if ((filters.workOrderId ?? '') !== '') {
|
if ((filters.workOrderId ?? '') !== '') {
|
||||||
sqlWhereClause +=
|
sqlWhereClause +=
|
||||||
' and o.contractId in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)'
|
' and c.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.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)'
|
' and c.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)'
|
||||||
sqlParameters.push(filters.notWorkOrderId)
|
sqlParameters.push(filters.notWorkOrderId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
import type { Request, Response } from 'express';
|
import type { Request, Response } from 'express';
|
||||||
export default function handler(request: Request, response: Response): void;
|
export default function handler(request: Request, response: Response): Promise<void>;
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,26 @@
|
||||||
|
import getContracts from '../../database/getContracts.js';
|
||||||
import getFuneralHome from '../../database/getFuneralHome.js';
|
import getFuneralHome from '../../database/getFuneralHome.js';
|
||||||
import { getConfigProperty } from '../../helpers/config.helpers.js';
|
import { getConfigProperty } from '../../helpers/config.helpers.js';
|
||||||
export default function handler(request, response) {
|
export default async function handler(request, response) {
|
||||||
const funeralHome = getFuneralHome(request.params.funeralHomeId);
|
const funeralHome = getFuneralHome(request.params.funeralHomeId);
|
||||||
if (funeralHome === undefined) {
|
if (funeralHome === undefined) {
|
||||||
response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/funeralHomes/?error=funeralHomeIdNotFound`);
|
response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/funeralHomes/?error=funeralHomeIdNotFound`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const contracts = await getContracts({
|
||||||
|
funeralHomeId: funeralHome.funeralHomeId,
|
||||||
|
funeralTime: 'upcoming'
|
||||||
|
}, {
|
||||||
|
limit: -1,
|
||||||
|
offset: 0,
|
||||||
|
orderBy: 'c.funeralDate, c.funeralTime, c.contractId',
|
||||||
|
includeFees: false,
|
||||||
|
includeInterments: true,
|
||||||
|
includeTransactions: false
|
||||||
|
});
|
||||||
response.render('funeralHome-view', {
|
response.render('funeralHome-view', {
|
||||||
headTitle: funeralHome.funeralHomeName,
|
headTitle: funeralHome.funeralHomeName,
|
||||||
funeralHome
|
funeralHome,
|
||||||
|
contracts: contracts.contracts,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import type { Request, Response } from 'express'
|
import type { Request, Response } from 'express'
|
||||||
|
|
||||||
|
import getContracts from '../../database/getContracts.js'
|
||||||
import getFuneralHome from '../../database/getFuneralHome.js'
|
import getFuneralHome from '../../database/getFuneralHome.js'
|
||||||
import { getConfigProperty } from '../../helpers/config.helpers.js'
|
import { getConfigProperty } from '../../helpers/config.helpers.js'
|
||||||
|
|
||||||
export default function handler(request: Request, response: Response): void {
|
export default async function handler(request: Request, response: Response): Promise<void> {
|
||||||
const funeralHome = getFuneralHome(request.params.funeralHomeId)
|
const funeralHome = getFuneralHome(request.params.funeralHomeId)
|
||||||
|
|
||||||
if (funeralHome === undefined) {
|
if (funeralHome === undefined) {
|
||||||
|
|
@ -13,9 +14,28 @@ export default function handler(request: Request, response: Response): void {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const contracts = await getContracts(
|
||||||
|
{
|
||||||
|
funeralHomeId: funeralHome.funeralHomeId,
|
||||||
|
funeralTime: 'upcoming'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
limit: -1,
|
||||||
|
offset: 0,
|
||||||
|
|
||||||
|
orderBy: 'c.funeralDate, c.funeralTime, c.contractId',
|
||||||
|
|
||||||
|
includeFees: false,
|
||||||
|
includeInterments: true,
|
||||||
|
includeTransactions: false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
response.render('funeralHome-view', {
|
response.render('funeralHome-view', {
|
||||||
headTitle: funeralHome.funeralHomeName,
|
headTitle: funeralHome.funeralHomeName,
|
||||||
|
|
||||||
funeralHome
|
funeralHome,
|
||||||
|
|
||||||
|
contracts: contracts.contracts,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,73 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="panel">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<div class="level is-mobile">
|
||||||
|
<div class="level-left">
|
||||||
|
<h2 class="has-text-weight-bold">Contracts with Upcoming Funerals</h2>
|
||||||
|
</div>
|
||||||
|
<div class="level-right">
|
||||||
|
<i class="fas fa-file-contract" aria-hidden="true"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="panel-block is-block">
|
||||||
|
<% if (contracts.length === 0) { %>
|
||||||
|
<div class="message is-info">
|
||||||
|
<div class="message-body">
|
||||||
|
<p>No contracts with upcoming funerals.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% } else { %>
|
||||||
|
<table class="table is-striped is-fullwidth">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Contract Type</th>
|
||||||
|
<th>Funeral Date</th>
|
||||||
|
<th>Interments</th>
|
||||||
|
<th>Funeral Director</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="burialSite--contractsTbody">
|
||||||
|
<% for (const contract of contracts) { %>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a class="has-text-weight-bold"
|
||||||
|
href="<%= urlPrefix %>/contracts/<%= contract.contractId %>">
|
||||||
|
<%= contract.contractType %>
|
||||||
|
</a><br />
|
||||||
|
<span class="is-size-7">#<%= contract.contractId %></span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= contract.funeralDateString %>
|
||||||
|
<%= contract.funeralTime === null || contract.funeralTime === 0 ? '' : contract.funeralTimeString %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<% if (contract.contractInterments.length === 0) { %>
|
||||||
|
<span class="has-text-grey">(No Interments)</span>
|
||||||
|
<% } else { %>
|
||||||
|
<ul class="fa-ul ml-5">
|
||||||
|
<% for (const interment of contract.contractInterments) { %>
|
||||||
|
<li>
|
||||||
|
<span class="fa-li"><i class="fas fa-user"></i></span>
|
||||||
|
<%= interment.deceasedName %>
|
||||||
|
</li>
|
||||||
|
<% } %>
|
||||||
|
</ul>
|
||||||
|
<% } %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= contract.funeralDirectorName %><br />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% } %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<% } %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<%- include('_footerA'); -%>
|
<%- include('_footerA'); -%>
|
||||||
|
|
||||||
<%- include('_footerB'); -%>
|
<%- include('_footerB'); -%>
|
||||||
Loading…
Reference in New Issue