ability to add multiple fees as a group
alter table FeeCategories add isGroupedFee bit not null default 0deepsource-autofix-76c6eb20
parent
86b82d80de
commit
f384ce75df
|
|
@ -0,0 +1,6 @@
|
|||
export interface AddFeeCategoryForm {
|
||||
feeCategory: string;
|
||||
isGroupedFee?: '1';
|
||||
orderNumber?: number;
|
||||
}
|
||||
export default function addFeeCategory(feeCategoryForm: AddFeeCategoryForm, user: User): Promise<number>;
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function addFeeCategory(feeCategoryForm, user) {
|
||||
const database = await acquireConnection();
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare(`insert into FeeCategories (
|
||||
feeCategory,
|
||||
isGroupedFee, orderNumber,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(feeCategoryForm.feeCategory, (feeCategoryForm.isGroupedFee ?? '') === '1' ? 1 : 0, feeCategoryForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
database.release();
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddFeeCategoryForm {
|
||||
feeCategory: string
|
||||
isGroupedFee?: '1'
|
||||
orderNumber?: number
|
||||
}
|
||||
|
||||
export default async function addFeeCategory(
|
||||
feeCategoryForm: AddFeeCategoryForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
const result = database
|
||||
.prepare(
|
||||
`insert into FeeCategories (
|
||||
feeCategory,
|
||||
isGroupedFee, orderNumber,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?)`
|
||||
)
|
||||
.run(
|
||||
feeCategoryForm.feeCategory,
|
||||
(feeCategoryForm.isGroupedFee ?? '') === '1' ? 1 : 0,
|
||||
feeCategoryForm.orderNumber ?? -1,
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
user.userName,
|
||||
rightNowMillis
|
||||
)
|
||||
|
||||
database.release()
|
||||
|
||||
return result.lastInsertRowid as number
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import { type PoolConnection } from 'better-sqlite-pool';
|
||||
export interface AddLotOccupancyFeeForm {
|
||||
lotOccupancyId: number | string;
|
||||
feeId: number | string;
|
||||
|
|
@ -5,4 +6,4 @@ export interface AddLotOccupancyFeeForm {
|
|||
feeAmount?: number | string;
|
||||
taxAmount?: number | string;
|
||||
}
|
||||
export default function addLotOccupancyFee(lotOccupancyFeeForm: AddLotOccupancyFeeForm, user: User): Promise<boolean>;
|
||||
export default function addLotOccupancyFee(lotOccupancyFeeForm: AddLotOccupancyFeeForm, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import { calculateFeeAmount, calculateTaxAmount } from '../helpers/functions.fee
|
|||
import getFee from './getFee.js';
|
||||
import getLotOccupancy from './getLotOccupancy.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addLotOccupancyFee(lotOccupancyFeeForm, user) {
|
||||
const database = await acquireConnection();
|
||||
export default async function addLotOccupancyFee(lotOccupancyFeeForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
const rightNowMillis = Date.now();
|
||||
// Calculate fee and tax (if not set)
|
||||
let feeAmount;
|
||||
|
|
@ -24,62 +24,66 @@ export default async function addLotOccupancyFee(lotOccupancyFeeForm, user) {
|
|||
? Number.parseFloat(lotOccupancyFeeForm.taxAmount)
|
||||
: 0;
|
||||
}
|
||||
// Check if record already exists
|
||||
const record = database
|
||||
.prepare(`select feeAmount, taxAmount, recordDelete_timeMillis
|
||||
from LotOccupancyFees
|
||||
where lotOccupancyId = ?
|
||||
and feeId = ?`)
|
||||
.get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||
if (record) {
|
||||
if (record.recordDelete_timeMillis) {
|
||||
database
|
||||
.prepare(`delete from LotOccupancyFees
|
||||
where recordDelete_timeMillis is not null
|
||||
and lotOccupancyId = ?
|
||||
and feeId = ?`)
|
||||
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||
try {
|
||||
// Check if record already exists
|
||||
const record = database
|
||||
.prepare(`select feeAmount, taxAmount, recordDelete_timeMillis
|
||||
from LotOccupancyFees
|
||||
where lotOccupancyId = ?
|
||||
and feeId = ?`)
|
||||
.get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||
if (record) {
|
||||
if (record.recordDelete_timeMillis) {
|
||||
database
|
||||
.prepare(`delete from LotOccupancyFees
|
||||
where recordDelete_timeMillis is not null
|
||||
and lotOccupancyId = ?
|
||||
and feeId = ?`)
|
||||
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||
}
|
||||
else if (record.feeAmount === feeAmount &&
|
||||
record.taxAmount === taxAmount) {
|
||||
database
|
||||
.prepare(`update LotOccupancyFees
|
||||
set quantity = quantity + ?,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where lotOccupancyId = ?
|
||||
and feeId = ?`)
|
||||
.run(lotOccupancyFeeForm.quantity, user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
const quantity = typeof lotOccupancyFeeForm.quantity === 'string'
|
||||
? Number.parseFloat(lotOccupancyFeeForm.quantity)
|
||||
: lotOccupancyFeeForm.quantity;
|
||||
database
|
||||
.prepare(`update LotOccupancyFees
|
||||
set feeAmount = (feeAmount * quantity) + ?,
|
||||
taxAmount = (taxAmount * quantity) + ?,
|
||||
quantity = 1,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where lotOccupancyId = ?
|
||||
and feeId = ?`)
|
||||
.run(feeAmount * quantity, taxAmount * quantity, user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (record.feeAmount === feeAmount &&
|
||||
record.taxAmount === taxAmount) {
|
||||
database
|
||||
.prepare(`update LotOccupancyFees
|
||||
set quantity = quantity + ?,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where lotOccupancyId = ?
|
||||
and feeId = ?`)
|
||||
.run(lotOccupancyFeeForm.quantity, user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||
// Create new record
|
||||
const result = database
|
||||
.prepare(`insert into LotOccupancyFees (
|
||||
lotOccupancyId, feeId,
|
||||
quantity, feeAmount, taxAmount,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId, lotOccupancyFeeForm.quantity, feeAmount, taxAmount, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
return result.changes > 0;
|
||||
}
|
||||
finally {
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
const quantity = typeof lotOccupancyFeeForm.quantity === 'string'
|
||||
? Number.parseFloat(lotOccupancyFeeForm.quantity)
|
||||
: lotOccupancyFeeForm.quantity;
|
||||
database
|
||||
.prepare(`update LotOccupancyFees
|
||||
set feeAmount = (feeAmount * quantity) + ?,
|
||||
taxAmount = (taxAmount * quantity) + ?,
|
||||
quantity = 1,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where lotOccupancyId = ?
|
||||
and feeId = ?`)
|
||||
.run(feeAmount * quantity, taxAmount * quantity, user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||
database.release();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Create new record
|
||||
const result = database
|
||||
.prepare(`insert into LotOccupancyFees (
|
||||
lotOccupancyId, feeId,
|
||||
quantity, feeAmount, taxAmount,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId, lotOccupancyFeeForm.quantity, feeAmount, taxAmount, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
database.release();
|
||||
return result.changes > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { type PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import {
|
||||
calculateFeeAmount,
|
||||
calculateTaxAmount
|
||||
|
|
@ -18,9 +20,10 @@ export interface AddLotOccupancyFeeForm {
|
|||
|
||||
export default async function addLotOccupancyFee(
|
||||
lotOccupancyFeeForm: AddLotOccupancyFeeForm,
|
||||
user: User
|
||||
user: User,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<boolean> {
|
||||
const database = await acquireConnection()
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -48,109 +51,109 @@ export default async function addLotOccupancyFee(
|
|||
: 0
|
||||
}
|
||||
|
||||
// Check if record already exists
|
||||
const record = database
|
||||
.prepare(
|
||||
`select feeAmount, taxAmount, recordDelete_timeMillis
|
||||
from LotOccupancyFees
|
||||
where lotOccupancyId = ?
|
||||
and feeId = ?`
|
||||
)
|
||||
.get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId) as {
|
||||
feeAmount?: number
|
||||
taxAmount?: number
|
||||
recordDelete_timeMillis?: number
|
||||
}
|
||||
try {
|
||||
// Check if record already exists
|
||||
const record = database
|
||||
.prepare(
|
||||
`select feeAmount, taxAmount, recordDelete_timeMillis
|
||||
from LotOccupancyFees
|
||||
where lotOccupancyId = ?
|
||||
and feeId = ?`
|
||||
)
|
||||
.get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId) as {
|
||||
feeAmount?: number
|
||||
taxAmount?: number
|
||||
recordDelete_timeMillis?: number
|
||||
}
|
||||
|
||||
if (record) {
|
||||
if (record.recordDelete_timeMillis) {
|
||||
database
|
||||
.prepare(
|
||||
`delete from LotOccupancyFees
|
||||
where recordDelete_timeMillis is not null
|
||||
and lotOccupancyId = ?
|
||||
and feeId = ?`
|
||||
)
|
||||
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId)
|
||||
} else if (
|
||||
record.feeAmount === feeAmount &&
|
||||
record.taxAmount === taxAmount
|
||||
) {
|
||||
database
|
||||
.prepare(
|
||||
`update LotOccupancyFees
|
||||
set quantity = quantity + ?,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where lotOccupancyId = ?
|
||||
and feeId = ?`
|
||||
)
|
||||
.run(
|
||||
lotOccupancyFeeForm.quantity,
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
lotOccupancyFeeForm.lotOccupancyId,
|
||||
lotOccupancyFeeForm.feeId
|
||||
)
|
||||
if (record) {
|
||||
if (record.recordDelete_timeMillis) {
|
||||
database
|
||||
.prepare(
|
||||
`delete from LotOccupancyFees
|
||||
where recordDelete_timeMillis is not null
|
||||
and lotOccupancyId = ?
|
||||
and feeId = ?`
|
||||
)
|
||||
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId)
|
||||
} else if (
|
||||
record.feeAmount === feeAmount &&
|
||||
record.taxAmount === taxAmount
|
||||
) {
|
||||
database
|
||||
.prepare(
|
||||
`update LotOccupancyFees
|
||||
set quantity = quantity + ?,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where lotOccupancyId = ?
|
||||
and feeId = ?`
|
||||
)
|
||||
.run(
|
||||
lotOccupancyFeeForm.quantity,
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
lotOccupancyFeeForm.lotOccupancyId,
|
||||
lotOccupancyFeeForm.feeId
|
||||
)
|
||||
|
||||
return true
|
||||
} else {
|
||||
const quantity =
|
||||
typeof lotOccupancyFeeForm.quantity === 'string'
|
||||
? Number.parseFloat(lotOccupancyFeeForm.quantity)
|
||||
: lotOccupancyFeeForm.quantity
|
||||
|
||||
database
|
||||
.prepare(
|
||||
`update LotOccupancyFees
|
||||
set feeAmount = (feeAmount * quantity) + ?,
|
||||
taxAmount = (taxAmount * quantity) + ?,
|
||||
quantity = 1,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where lotOccupancyId = ?
|
||||
and feeId = ?`
|
||||
)
|
||||
.run(
|
||||
feeAmount * quantity,
|
||||
taxAmount * quantity,
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
lotOccupancyFeeForm.lotOccupancyId,
|
||||
lotOccupancyFeeForm.feeId
|
||||
)
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Create new record
|
||||
const result = database
|
||||
.prepare(
|
||||
`insert into LotOccupancyFees (
|
||||
lotOccupancyId, feeId,
|
||||
quantity, feeAmount, taxAmount,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
)
|
||||
.run(
|
||||
lotOccupancyFeeForm.lotOccupancyId,
|
||||
lotOccupancyFeeForm.feeId,
|
||||
lotOccupancyFeeForm.quantity,
|
||||
feeAmount,
|
||||
taxAmount,
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
user.userName,
|
||||
rightNowMillis
|
||||
)
|
||||
|
||||
return result.changes > 0
|
||||
} finally {
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
|
||||
return true
|
||||
} else {
|
||||
const quantity =
|
||||
typeof lotOccupancyFeeForm.quantity === 'string'
|
||||
? Number.parseFloat(lotOccupancyFeeForm.quantity)
|
||||
: lotOccupancyFeeForm.quantity
|
||||
|
||||
database
|
||||
.prepare(
|
||||
`update LotOccupancyFees
|
||||
set feeAmount = (feeAmount * quantity) + ?,
|
||||
taxAmount = (taxAmount * quantity) + ?,
|
||||
quantity = 1,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where lotOccupancyId = ?
|
||||
and feeId = ?`
|
||||
)
|
||||
.run(
|
||||
feeAmount * quantity,
|
||||
taxAmount * quantity,
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
lotOccupancyFeeForm.lotOccupancyId,
|
||||
lotOccupancyFeeForm.feeId
|
||||
)
|
||||
|
||||
database.release()
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Create new record
|
||||
const result = database
|
||||
.prepare(
|
||||
`insert into LotOccupancyFees (
|
||||
lotOccupancyId, feeId,
|
||||
quantity, feeAmount, taxAmount,
|
||||
recordCreate_userName, recordCreate_timeMillis,
|
||||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
)
|
||||
.run(
|
||||
lotOccupancyFeeForm.lotOccupancyId,
|
||||
lotOccupancyFeeForm.feeId,
|
||||
lotOccupancyFeeForm.quantity,
|
||||
feeAmount,
|
||||
taxAmount,
|
||||
user.userName,
|
||||
rightNowMillis,
|
||||
user.userName,
|
||||
rightNowMillis
|
||||
)
|
||||
|
||||
database.release()
|
||||
|
||||
return result.changes > 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
export interface AddLotOccupancyFeeCategoryForm {
|
||||
lotOccupancyId: number | string;
|
||||
feeCategoryId: number | string;
|
||||
}
|
||||
export default function addLotOccupancyFeeCategory(lotOccupancyFeeCategoryForm: AddLotOccupancyFeeCategoryForm, user: User): Promise<number>;
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import addLotOccupancyFee from './addLotOccupancyFee.js';
|
||||
import { getFeeCategory } from './getFeeCategories.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addLotOccupancyFeeCategory(lotOccupancyFeeCategoryForm, user) {
|
||||
const database = await acquireConnection();
|
||||
const feeCategory = await getFeeCategory(lotOccupancyFeeCategoryForm.feeCategoryId, database);
|
||||
let addedFeeCount = 0;
|
||||
for (const fee of feeCategory?.fees ?? []) {
|
||||
const success = await addLotOccupancyFee({
|
||||
lotOccupancyId: lotOccupancyFeeCategoryForm.lotOccupancyId,
|
||||
feeId: fee.feeId,
|
||||
quantity: 1
|
||||
}, user, database);
|
||||
if (success) {
|
||||
addedFeeCount += 1;
|
||||
}
|
||||
}
|
||||
database.release();
|
||||
return addedFeeCount;
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
import addLotOccupancyFee from './addLotOccupancyFee.js'
|
||||
import { getFeeCategory } from './getFeeCategories.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddLotOccupancyFeeCategoryForm {
|
||||
lotOccupancyId: number | string
|
||||
feeCategoryId: number | string
|
||||
}
|
||||
|
||||
export default async function addLotOccupancyFeeCategory(
|
||||
lotOccupancyFeeCategoryForm: AddLotOccupancyFeeCategoryForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
|
||||
const feeCategory = await getFeeCategory(
|
||||
lotOccupancyFeeCategoryForm.feeCategoryId,
|
||||
database
|
||||
)
|
||||
|
||||
let addedFeeCount = 0
|
||||
|
||||
for (const fee of feeCategory?.fees ?? []) {
|
||||
const success = await addLotOccupancyFee(
|
||||
{
|
||||
lotOccupancyId: lotOccupancyFeeCategoryForm.lotOccupancyId,
|
||||
feeId: fee.feeId,
|
||||
quantity: 1
|
||||
},
|
||||
user,
|
||||
database
|
||||
)
|
||||
|
||||
if (success) {
|
||||
addedFeeCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
database.release()
|
||||
|
||||
return addedFeeCount
|
||||
}
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
type RecordTable = 'FeeCategories' | 'LotStatuses' | 'LotTypes' | 'OccupancyTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes';
|
||||
type RecordTable = 'LotStatuses' | 'LotTypes' | 'OccupancyTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes';
|
||||
export declare function addRecord(recordTable: RecordTable, recordName: string, orderNumber: number | string, user: User): Promise<number>;
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { clearCacheByTableName } from '../helpers/functions.cache.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
const recordNameColumns = new Map();
|
||||
recordNameColumns.set('FeeCategories', 'feeCategory');
|
||||
recordNameColumns.set('LotStatuses', 'lotStatus');
|
||||
recordNameColumns.set('LotTypes', 'lotType');
|
||||
recordNameColumns.set('OccupancyTypes', 'occupancyType');
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
|||
import { acquireConnection } from './pool.js'
|
||||
|
||||
type RecordTable =
|
||||
| 'FeeCategories'
|
||||
| 'LotStatuses'
|
||||
| 'LotTypes'
|
||||
| 'OccupancyTypes'
|
||||
|
|
@ -11,7 +10,6 @@ type RecordTable =
|
|||
| 'WorkOrderTypes'
|
||||
|
||||
const recordNameColumns = new Map<RecordTable, string>()
|
||||
recordNameColumns.set('FeeCategories', 'feeCategory')
|
||||
recordNameColumns.set('LotStatuses', 'lotStatus')
|
||||
recordNameColumns.set('LotTypes', 'lotType')
|
||||
recordNameColumns.set('OccupancyTypes', 'occupancyType')
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
import { type PoolConnection } from 'better-sqlite-pool';
|
||||
import type { FeeCategory } from '../types/recordTypes.js';
|
||||
interface GetFeeCategoriesFilters {
|
||||
occupancyTypeId?: number | string;
|
||||
lotTypeId?: number | string;
|
||||
feeCategoryId?: number | string;
|
||||
}
|
||||
interface GetFeeCategoriesOptions {
|
||||
includeFees?: boolean;
|
||||
}
|
||||
export default function getFeeCategories(filters: GetFeeCategoriesFilters, options: GetFeeCategoriesOptions): Promise<FeeCategory[]>;
|
||||
export default function getFeeCategories(filters: GetFeeCategoriesFilters, options: GetFeeCategoriesOptions, connectedDatabase?: PoolConnection): Promise<FeeCategory[]>;
|
||||
export declare function getFeeCategory(feeCategoryId: number | string, connectedDatabase?: PoolConnection): Promise<FeeCategory | undefined>;
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import getFees from './getFees.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
||||
export default async function getFeeCategories(filters, options) {
|
||||
export default async function getFeeCategories(filters, options, connectedDatabase) {
|
||||
const updateOrderNumbers = !(filters.lotTypeId || filters.occupancyTypeId) && options.includeFees;
|
||||
const database = await acquireConnection();
|
||||
let sqlWhereClause = ' where recordDelete_timeMillis is null';
|
||||
|
|
@ -17,7 +17,7 @@ export default async function getFeeCategories(filters, options) {
|
|||
sqlParameters.push(filters.lotTypeId);
|
||||
}
|
||||
const feeCategories = database
|
||||
.prepare(`select feeCategoryId, feeCategory, orderNumber
|
||||
.prepare(`select feeCategoryId, feeCategory, isGroupedFee, orderNumber
|
||||
from FeeCategories
|
||||
${sqlWhereClause}
|
||||
order by orderNumber, feeCategory`)
|
||||
|
|
@ -34,6 +34,19 @@ export default async function getFeeCategories(filters, options) {
|
|||
feeCategory.fees = await getFees(feeCategory.feeCategoryId, filters, database);
|
||||
}
|
||||
}
|
||||
database.release();
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
}
|
||||
return feeCategories;
|
||||
}
|
||||
export async function getFeeCategory(feeCategoryId, connectedDatabase) {
|
||||
const feeCategories = await getFeeCategories({
|
||||
feeCategoryId
|
||||
}, {
|
||||
includeFees: true
|
||||
}, connectedDatabase);
|
||||
if (feeCategories.length > 0) {
|
||||
return feeCategories[0];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { type PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import type { FeeCategory } from '../types/recordTypes.js'
|
||||
|
||||
import getFees from './getFees.js'
|
||||
|
|
@ -7,6 +9,7 @@ import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
|||
interface GetFeeCategoriesFilters {
|
||||
occupancyTypeId?: number | string
|
||||
lotTypeId?: number | string
|
||||
feeCategoryId?: number | string
|
||||
}
|
||||
|
||||
interface GetFeeCategoriesOptions {
|
||||
|
|
@ -15,7 +18,8 @@ interface GetFeeCategoriesOptions {
|
|||
|
||||
export default async function getFeeCategories(
|
||||
filters: GetFeeCategoriesFilters,
|
||||
options: GetFeeCategoriesOptions
|
||||
options: GetFeeCategoriesOptions,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<FeeCategory[]> {
|
||||
const updateOrderNumbers =
|
||||
!(filters.lotTypeId || filters.occupancyTypeId) && options.includeFees
|
||||
|
|
@ -42,7 +46,7 @@ export default async function getFeeCategories(
|
|||
|
||||
const feeCategories = database
|
||||
.prepare(
|
||||
`select feeCategoryId, feeCategory, orderNumber
|
||||
`select feeCategoryId, feeCategory, isGroupedFee, orderNumber
|
||||
from FeeCategories
|
||||
${sqlWhereClause}
|
||||
order by orderNumber, feeCategory`
|
||||
|
|
@ -77,7 +81,30 @@ export default async function getFeeCategories(
|
|||
}
|
||||
}
|
||||
|
||||
database.release()
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
}
|
||||
|
||||
return feeCategories
|
||||
}
|
||||
|
||||
export async function getFeeCategory(
|
||||
feeCategoryId: number | string,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<FeeCategory | undefined> {
|
||||
const feeCategories = await getFeeCategories(
|
||||
{
|
||||
feeCategoryId
|
||||
},
|
||||
{
|
||||
includeFees: true
|
||||
},
|
||||
connectedDatabase
|
||||
)
|
||||
|
||||
if (feeCategories.length > 0) {
|
||||
return feeCategories[0]
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
export interface UpdateFeeCategoryForm {
|
||||
feeCategoryId: number | string;
|
||||
feeCategory: string;
|
||||
isGroupedFee?: '1';
|
||||
}
|
||||
export default function updateFeeCategory(feeCategoryForm: UpdateFeeCategoryForm, user: User): Promise<boolean>;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,15 @@
|
|||
import { updateRecord } from './updateRecord.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function updateFeeCategory(feeCategoryForm, user) {
|
||||
return await updateRecord('FeeCategories', feeCategoryForm.feeCategoryId, feeCategoryForm.feeCategory, user);
|
||||
const database = await acquireConnection();
|
||||
const result = database
|
||||
.prepare(`update FeeCategories
|
||||
set feeCategory = ?,
|
||||
isGroupedFee = ?,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where recordDelete_timeMillis is null
|
||||
and feeCategoryId = ?`)
|
||||
.run(feeCategoryForm.feeCategory, (feeCategoryForm.isGroupedFee ?? '') === '1' ? 1 : 0, user.userName, Date.now(), feeCategoryForm.feeCategoryId);
|
||||
database.release();
|
||||
return result.changes > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,36 @@
|
|||
import { updateRecord } from './updateRecord.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface UpdateFeeCategoryForm {
|
||||
feeCategoryId: number | string
|
||||
feeCategory: string
|
||||
isGroupedFee?: '1'
|
||||
}
|
||||
|
||||
export default async function updateFeeCategory(
|
||||
feeCategoryForm: UpdateFeeCategoryForm,
|
||||
user: User
|
||||
): Promise<boolean> {
|
||||
return await updateRecord(
|
||||
'FeeCategories',
|
||||
feeCategoryForm.feeCategoryId,
|
||||
feeCategoryForm.feeCategory,
|
||||
user
|
||||
)
|
||||
const database = await acquireConnection()
|
||||
|
||||
const result = database
|
||||
.prepare(
|
||||
`update FeeCategories
|
||||
set feeCategory = ?,
|
||||
isGroupedFee = ?,
|
||||
recordUpdate_userName = ?,
|
||||
recordUpdate_timeMillis = ?
|
||||
where recordDelete_timeMillis is null
|
||||
and feeCategoryId = ?`
|
||||
)
|
||||
.run(
|
||||
feeCategoryForm.feeCategory,
|
||||
(feeCategoryForm.isGroupedFee ?? '') === '1' ? 1 : 0,
|
||||
user.userName,
|
||||
Date.now(),
|
||||
feeCategoryForm.feeCategoryId
|
||||
)
|
||||
|
||||
database.release()
|
||||
|
||||
return result.changes > 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
type RecordTable = 'FeeCategories' | 'LotStatuses' | 'LotTypes' | 'OccupancyTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes';
|
||||
type RecordTable = 'LotStatuses' | 'LotTypes' | 'OccupancyTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes';
|
||||
export declare function updateRecord(recordTable: RecordTable, recordId: number | string, recordName: string, user: User): Promise<boolean>;
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { clearCacheByTableName } from '../helpers/functions.cache.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
const recordNameIdColumns = new Map();
|
||||
recordNameIdColumns.set('FeeCategories', ['feeCategory', 'feeCategoryId']);
|
||||
recordNameIdColumns.set('LotStatuses', ['lotStatus', 'lotStatusId']);
|
||||
recordNameIdColumns.set('LotTypes', ['lotType', 'lotTypeId']);
|
||||
recordNameIdColumns.set('OccupancyTypes', ['occupancyType', 'occupancyTypeId']);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
|||
import { acquireConnection } from './pool.js'
|
||||
|
||||
type RecordTable =
|
||||
| 'FeeCategories'
|
||||
| 'LotStatuses'
|
||||
| 'LotTypes'
|
||||
| 'OccupancyTypes'
|
||||
|
|
@ -11,7 +10,6 @@ type RecordTable =
|
|||
| 'WorkOrderTypes'
|
||||
|
||||
const recordNameIdColumns = new Map<RecordTable, string[]>()
|
||||
recordNameIdColumns.set('FeeCategories', ['feeCategory', 'feeCategoryId'])
|
||||
recordNameIdColumns.set('LotStatuses', ['lotStatus', 'lotStatusId'])
|
||||
recordNameIdColumns.set('LotTypes', ['lotType', 'lotTypeId'])
|
||||
recordNameIdColumns.set('OccupancyTypes', ['occupancyType', 'occupancyTypeId'])
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { addRecord } from '../../database/addRecord.js';
|
||||
import addFeeCategory from '../../database/addFeeCategory.js';
|
||||
import getFeeCategories from '../../database/getFeeCategories.js';
|
||||
export default async function handler(request, response) {
|
||||
const feeCategoryId = await addRecord('FeeCategories', request.body.feeCategory, request.body.orderNumber ?? -1, request.session.user);
|
||||
const feeCategoryId = await addFeeCategory(request.body, request.session.user);
|
||||
const feeCategories = await getFeeCategories({}, {
|
||||
includeFees: true
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
import type { Request, Response } from 'express'
|
||||
|
||||
import { addRecord } from '../../database/addRecord.js'
|
||||
import addFeeCategory, {
|
||||
type AddFeeCategoryForm
|
||||
} from '../../database/addFeeCategory.js'
|
||||
import getFeeCategories from '../../database/getFeeCategories.js'
|
||||
|
||||
export default async function handler(
|
||||
request: Request,
|
||||
response: Response
|
||||
): Promise<void> {
|
||||
const feeCategoryId = await addRecord(
|
||||
'FeeCategories',
|
||||
request.body.feeCategory,
|
||||
request.body.orderNumber ?? -1,
|
||||
const feeCategoryId = await addFeeCategory(
|
||||
request.body as AddFeeCategoryForm,
|
||||
request.session.user as User
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export default async function handler(
|
|||
)
|
||||
|
||||
const lotOccupancyFees = await getLotOccupancyFees(
|
||||
request.body.lotOccupancyId
|
||||
request.body.lotOccupancyId as string
|
||||
)
|
||||
|
||||
response.json({
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
/// <reference types="cookie-parser" />
|
||||
import type { Request, Response } from 'express';
|
||||
export default function handler(request: Request, response: Response): Promise<void>;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import addLotOccupancyFeeCategory from '../../database/addLotOccupancyFeeCategory.js';
|
||||
import getLotOccupancyFees from '../../database/getLotOccupancyFees.js';
|
||||
export default async function handler(request, response) {
|
||||
await addLotOccupancyFeeCategory(request.body, request.session.user);
|
||||
const lotOccupancyFees = await getLotOccupancyFees(request.body.lotOccupancyId);
|
||||
response.json({
|
||||
success: true,
|
||||
lotOccupancyFees
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
import type { Request, Response } from 'express'
|
||||
|
||||
import addLotOccupancyFeeCategory, {
|
||||
type AddLotOccupancyFeeCategoryForm
|
||||
} from '../../database/addLotOccupancyFeeCategory.js'
|
||||
import getLotOccupancyFees from '../../database/getLotOccupancyFees.js'
|
||||
|
||||
export default async function handler(
|
||||
request: Request,
|
||||
response: Response
|
||||
): Promise<void> {
|
||||
await addLotOccupancyFeeCategory(
|
||||
request.body as AddLotOccupancyFeeCategoryForm,
|
||||
request.session.user as User
|
||||
)
|
||||
|
||||
const lotOccupancyFees = await getLotOccupancyFees(
|
||||
request.body.lotOccupancyId as string
|
||||
)
|
||||
|
||||
response.json({
|
||||
success: true,
|
||||
lotOccupancyFees
|
||||
})
|
||||
}
|
||||
|
|
@ -56,7 +56,12 @@ const createStatements = [
|
|||
/*
|
||||
* Fees and Transactions
|
||||
*/
|
||||
`create table if not exists FeeCategories (feeCategoryId integer not null primary key autoincrement, feeCategory varchar(100) not null, orderNumber smallint not null default 0, ${recordColumns})`,
|
||||
`create table if not exists FeeCategories (
|
||||
feeCategoryId integer not null primary key autoincrement,
|
||||
feeCategory varchar(100) not null,
|
||||
isGroupedFee bit not null default 0,
|
||||
orderNumber smallint not null default 0,
|
||||
${recordColumns})`,
|
||||
`create table if not exists Fees (
|
||||
feeId integer not null primary key autoincrement,
|
||||
feeCategoryId integer not null,
|
||||
|
|
|
|||
|
|
@ -69,7 +69,13 @@ const createStatements = [
|
|||
* Fees and Transactions
|
||||
*/
|
||||
|
||||
`create table if not exists FeeCategories (feeCategoryId integer not null primary key autoincrement, feeCategory varchar(100) not null, orderNumber smallint not null default 0, ${recordColumns})`,
|
||||
`create table if not exists FeeCategories (
|
||||
feeCategoryId integer not null primary key autoincrement,
|
||||
feeCategory varchar(100) not null,
|
||||
isGroupedFee bit not null default 0,
|
||||
orderNumber smallint not null default 0,
|
||||
${recordColumns})`,
|
||||
|
||||
`create table if not exists Fees (
|
||||
feeId integer not null primary key autoincrement,
|
||||
feeCategoryId integer not null,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
feeCategoryContainerElement.innerHTML = `<div class="panel-heading">
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<h2 class="title is-4">${cityssm.escapeHTML((_a = feeCategory.feeCategory) !== null && _a !== void 0 ? _a : '')}</h2>
|
||||
<h2 class="title is-4 mb-2">${cityssm.escapeHTML((_a = feeCategory.feeCategory) !== null && _a !== void 0 ? _a : '')}</h2>
|
||||
${feeCategory.isGroupedFee
|
||||
? '<span class="tag">Grouped Fee</span>'
|
||||
: ''}
|
||||
</div>
|
||||
<div class="column is-narrow">
|
||||
<div class="field is-grouped is-justify-content-end">
|
||||
|
|
@ -82,7 +85,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
<p>
|
||||
<a class="has-text-weight-bold" href="#">${cityssm.escapeHTML((_e = fee.feeName) !== null && _e !== void 0 ? _e : '')}</a><br />
|
||||
<small>
|
||||
${cityssm
|
||||
${
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
cityssm
|
||||
.escapeHTML((_f = fee.feeDescription) !== null && _f !== void 0 ? _f : '')
|
||||
.replaceAll('\n', '<br />')}
|
||||
</small>
|
||||
|
|
@ -220,6 +225,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
;
|
||||
modalElement.querySelector('#feeCategoryEdit--feeCategoryId').value = feeCategory.feeCategoryId.toString();
|
||||
modalElement.querySelector('#feeCategoryEdit--feeCategory').value = feeCategory.feeCategory;
|
||||
if (feeCategory.isGroupedFee) {
|
||||
;
|
||||
modalElement.querySelector('#feeCategoryEdit--isGroupedFee').checked = true;
|
||||
}
|
||||
},
|
||||
onshown(modalElement, closeModalFunction) {
|
||||
var _a;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,12 @@ declare const exports: Record<string, unknown>
|
|||
feeCategoryContainerElement.innerHTML = `<div class="panel-heading">
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<h2 class="title is-4">${cityssm.escapeHTML(feeCategory.feeCategory ?? '')}</h2>
|
||||
<h2 class="title is-4 mb-2">${cityssm.escapeHTML(feeCategory.feeCategory ?? '')}</h2>
|
||||
${
|
||||
feeCategory.isGroupedFee
|
||||
? '<span class="tag">Grouped Fee</span>'
|
||||
: ''
|
||||
}
|
||||
</div>
|
||||
<div class="column is-narrow">
|
||||
<div class="field is-grouped is-justify-content-end">
|
||||
|
|
@ -131,9 +136,12 @@ declare const exports: Record<string, unknown>
|
|||
<p>
|
||||
<a class="has-text-weight-bold" href="#">${cityssm.escapeHTML(fee.feeName ?? '')}</a><br />
|
||||
<small>
|
||||
${cityssm
|
||||
${
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
cityssm
|
||||
.escapeHTML(fee.feeDescription ?? '')
|
||||
.replaceAll('\n', '<br />')}
|
||||
.replaceAll('\n', '<br />')
|
||||
}
|
||||
</small>
|
||||
</p>
|
||||
${
|
||||
|
|
@ -350,6 +358,14 @@ declare const exports: Record<string, unknown>
|
|||
'#feeCategoryEdit--feeCategory'
|
||||
) as HTMLInputElement
|
||||
).value = feeCategory.feeCategory
|
||||
|
||||
if (feeCategory.isGroupedFee) {
|
||||
;(
|
||||
modalElement.querySelector(
|
||||
'#feeCategoryEdit--isGroupedFee'
|
||||
) as HTMLInputElement
|
||||
).checked = true
|
||||
}
|
||||
},
|
||||
onshown(modalElement, closeModalFunction) {
|
||||
bulmaJS.toggleHtmlClipped()
|
||||
|
|
|
|||
|
|
@ -1265,6 +1265,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
let feeCategories;
|
||||
let feeFilterElement;
|
||||
let feeFilterResultsElement;
|
||||
function doAddFeeCategory(clickEvent) {
|
||||
var _a;
|
||||
clickEvent.preventDefault();
|
||||
const feeCategoryId = Number.parseInt((_a = clickEvent.currentTarget.dataset.feeCategoryId) !== null && _a !== void 0 ? _a : '', 10);
|
||||
cityssm.postJSON(`${los.urlPrefix}/lotOccupancies/doAddLotOccupancyFeeCategory`, {
|
||||
lotOccupancyId,
|
||||
feeCategoryId
|
||||
}, (rawResponseJSON) => {
|
||||
var _a;
|
||||
const responseJSON = rawResponseJSON;
|
||||
if (responseJSON.success) {
|
||||
lotOccupancyFees = responseJSON.lotOccupancyFees;
|
||||
renderLotOccupancyFees();
|
||||
bulmaJS.alert({
|
||||
message: 'Fee Group Added Successfully',
|
||||
contextualColorName: 'success'
|
||||
});
|
||||
}
|
||||
else {
|
||||
bulmaJS.alert({
|
||||
title: 'Error Adding Fee',
|
||||
message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '',
|
||||
contextualColorName: 'danger'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
function doAddFee(feeId, quantity = 1) {
|
||||
cityssm.postJSON(`${los.urlPrefix}/lotOccupancies/doAddLotOccupancyFee`, {
|
||||
lotOccupancyId,
|
||||
|
|
@ -1329,7 +1356,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
}
|
||||
}
|
||||
function filterFees() {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h;
|
||||
const filterStringPieces = feeFilterElement.value
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
|
|
@ -1340,10 +1367,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
categoryContainerElement.className = 'container--feeCategory';
|
||||
categoryContainerElement.dataset.feeCategoryId =
|
||||
feeCategory.feeCategoryId.toString();
|
||||
categoryContainerElement.innerHTML = `<h4 class="title is-5 mt-2">
|
||||
${cityssm.escapeHTML((_a = feeCategory.feeCategory) !== null && _a !== void 0 ? _a : '')}
|
||||
</h4>
|
||||
categoryContainerElement.innerHTML = `<div class="columns is-vcentered">
|
||||
<div class="column">
|
||||
<h4 class="title is-5">
|
||||
${cityssm.escapeHTML((_a = feeCategory.feeCategory) !== null && _a !== void 0 ? _a : '')}
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel mb-5"></div>`;
|
||||
if (feeCategory.isGroupedFee) {
|
||||
// eslint-disable-next-line no-unsanitized/method
|
||||
(_b = categoryContainerElement.querySelector('.columns')) === null || _b === void 0 ? void 0 : _b.insertAdjacentHTML('beforeend', `<div class="column is-narrow has-text-right">
|
||||
<button class="button is-small is-success" type="button" data-fee-category-id="${feeCategory.feeCategoryId}">
|
||||
<span class="icon is-small"><i class="fas fa-plus" aria-hidden="true"></i></span>
|
||||
<span>Add Fee Group</span>
|
||||
</button>
|
||||
</div>`);
|
||||
(_c = categoryContainerElement.querySelector('button')) === null || _c === void 0 ? void 0 : _c.addEventListener('click', doAddFeeCategory);
|
||||
}
|
||||
let hasFees = false;
|
||||
for (const fee of feeCategory.fees) {
|
||||
// Don't include already applied fees that limit quantity
|
||||
|
|
@ -1351,7 +1392,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
continue;
|
||||
}
|
||||
let includeFee = true;
|
||||
const feeSearchString = `${(_b = feeCategory.feeCategory) !== null && _b !== void 0 ? _b : ''} ${(_c = fee.feeName) !== null && _c !== void 0 ? _c : ''} ${(_d = fee.feeDescription) !== null && _d !== void 0 ? _d : ''}`.toLowerCase();
|
||||
const feeSearchString = `${(_d = feeCategory.feeCategory) !== null && _d !== void 0 ? _d : ''} ${(_e = fee.feeName) !== null && _e !== void 0 ? _e : ''} ${(_f = fee.feeDescription) !== null && _f !== void 0 ? _f : ''}`.toLowerCase();
|
||||
for (const filterStringPiece of filterStringPieces) {
|
||||
if (!feeSearchString.includes(filterStringPiece)) {
|
||||
includeFee = false;
|
||||
|
|
@ -1362,20 +1403,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
continue;
|
||||
}
|
||||
hasFees = true;
|
||||
const panelBlockElement = document.createElement('a');
|
||||
const panelBlockElement = document.createElement(feeCategory.isGroupedFee ? 'div' : 'a');
|
||||
panelBlockElement.className = 'panel-block is-block container--fee';
|
||||
panelBlockElement.dataset.feeId = fee.feeId.toString();
|
||||
panelBlockElement.dataset.feeCategoryId =
|
||||
feeCategory.feeCategoryId.toString();
|
||||
panelBlockElement.href = '#';
|
||||
// eslint-disable-next-line no-unsanitized/property
|
||||
panelBlockElement.innerHTML = `<strong>${cityssm.escapeHTML((_e = fee.feeName) !== null && _e !== void 0 ? _e : '')}</strong><br />
|
||||
panelBlockElement.innerHTML = `<strong>${cityssm.escapeHTML((_g = fee.feeName) !== null && _g !== void 0 ? _g : '')}</strong><br />
|
||||
<small>
|
||||
${cityssm
|
||||
.escapeHTML((_f = fee.feeDescription) !== null && _f !== void 0 ? _f : '')
|
||||
${
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
cityssm
|
||||
.escapeHTML((_h = fee.feeDescription) !== null && _h !== void 0 ? _h : '')
|
||||
.replaceAll('\n', '<br />')}
|
||||
</small>`;
|
||||
panelBlockElement.addEventListener('click', tryAddFee);
|
||||
if (!feeCategory.isGroupedFee) {
|
||||
;
|
||||
panelBlockElement.href = '#';
|
||||
panelBlockElement.addEventListener('click', tryAddFee);
|
||||
}
|
||||
;
|
||||
categoryContainerElement.querySelector('.panel').append(panelBlockElement);
|
||||
}
|
||||
if (hasFees) {
|
||||
|
|
|
|||
|
|
@ -194,6 +194,33 @@ addFeeButtonElement.addEventListener('click', () => {
|
|||
let feeCategories;
|
||||
let feeFilterElement;
|
||||
let feeFilterResultsElement;
|
||||
function doAddFeeCategory(clickEvent) {
|
||||
var _a;
|
||||
clickEvent.preventDefault();
|
||||
const feeCategoryId = Number.parseInt((_a = clickEvent.currentTarget.dataset.feeCategoryId) !== null && _a !== void 0 ? _a : '', 10);
|
||||
cityssm.postJSON(`${los.urlPrefix}/lotOccupancies/doAddLotOccupancyFeeCategory`, {
|
||||
lotOccupancyId,
|
||||
feeCategoryId
|
||||
}, (rawResponseJSON) => {
|
||||
var _a;
|
||||
const responseJSON = rawResponseJSON;
|
||||
if (responseJSON.success) {
|
||||
lotOccupancyFees = responseJSON.lotOccupancyFees;
|
||||
renderLotOccupancyFees();
|
||||
bulmaJS.alert({
|
||||
message: 'Fee Group Added Successfully',
|
||||
contextualColorName: 'success'
|
||||
});
|
||||
}
|
||||
else {
|
||||
bulmaJS.alert({
|
||||
title: 'Error Adding Fee',
|
||||
message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '',
|
||||
contextualColorName: 'danger'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
function doAddFee(feeId, quantity = 1) {
|
||||
cityssm.postJSON(`${los.urlPrefix}/lotOccupancies/doAddLotOccupancyFee`, {
|
||||
lotOccupancyId,
|
||||
|
|
@ -258,7 +285,7 @@ addFeeButtonElement.addEventListener('click', () => {
|
|||
}
|
||||
}
|
||||
function filterFees() {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h;
|
||||
const filterStringPieces = feeFilterElement.value
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
|
|
@ -269,10 +296,24 @@ addFeeButtonElement.addEventListener('click', () => {
|
|||
categoryContainerElement.className = 'container--feeCategory';
|
||||
categoryContainerElement.dataset.feeCategoryId =
|
||||
feeCategory.feeCategoryId.toString();
|
||||
categoryContainerElement.innerHTML = `<h4 class="title is-5 mt-2">
|
||||
${cityssm.escapeHTML((_a = feeCategory.feeCategory) !== null && _a !== void 0 ? _a : '')}
|
||||
</h4>
|
||||
categoryContainerElement.innerHTML = `<div class="columns is-vcentered">
|
||||
<div class="column">
|
||||
<h4 class="title is-5">
|
||||
${cityssm.escapeHTML((_a = feeCategory.feeCategory) !== null && _a !== void 0 ? _a : '')}
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel mb-5"></div>`;
|
||||
if (feeCategory.isGroupedFee) {
|
||||
// eslint-disable-next-line no-unsanitized/method
|
||||
(_b = categoryContainerElement.querySelector('.columns')) === null || _b === void 0 ? void 0 : _b.insertAdjacentHTML('beforeend', `<div class="column is-narrow has-text-right">
|
||||
<button class="button is-small is-success" type="button" data-fee-category-id="${feeCategory.feeCategoryId}">
|
||||
<span class="icon is-small"><i class="fas fa-plus" aria-hidden="true"></i></span>
|
||||
<span>Add Fee Group</span>
|
||||
</button>
|
||||
</div>`);
|
||||
(_c = categoryContainerElement.querySelector('button')) === null || _c === void 0 ? void 0 : _c.addEventListener('click', doAddFeeCategory);
|
||||
}
|
||||
let hasFees = false;
|
||||
for (const fee of feeCategory.fees) {
|
||||
// Don't include already applied fees that limit quantity
|
||||
|
|
@ -280,7 +321,7 @@ addFeeButtonElement.addEventListener('click', () => {
|
|||
continue;
|
||||
}
|
||||
let includeFee = true;
|
||||
const feeSearchString = `${(_b = feeCategory.feeCategory) !== null && _b !== void 0 ? _b : ''} ${(_c = fee.feeName) !== null && _c !== void 0 ? _c : ''} ${(_d = fee.feeDescription) !== null && _d !== void 0 ? _d : ''}`.toLowerCase();
|
||||
const feeSearchString = `${(_d = feeCategory.feeCategory) !== null && _d !== void 0 ? _d : ''} ${(_e = fee.feeName) !== null && _e !== void 0 ? _e : ''} ${(_f = fee.feeDescription) !== null && _f !== void 0 ? _f : ''}`.toLowerCase();
|
||||
for (const filterStringPiece of filterStringPieces) {
|
||||
if (!feeSearchString.includes(filterStringPiece)) {
|
||||
includeFee = false;
|
||||
|
|
@ -291,20 +332,26 @@ addFeeButtonElement.addEventListener('click', () => {
|
|||
continue;
|
||||
}
|
||||
hasFees = true;
|
||||
const panelBlockElement = document.createElement('a');
|
||||
const panelBlockElement = document.createElement(feeCategory.isGroupedFee ? 'div' : 'a');
|
||||
panelBlockElement.className = 'panel-block is-block container--fee';
|
||||
panelBlockElement.dataset.feeId = fee.feeId.toString();
|
||||
panelBlockElement.dataset.feeCategoryId =
|
||||
feeCategory.feeCategoryId.toString();
|
||||
panelBlockElement.href = '#';
|
||||
// eslint-disable-next-line no-unsanitized/property
|
||||
panelBlockElement.innerHTML = `<strong>${cityssm.escapeHTML((_e = fee.feeName) !== null && _e !== void 0 ? _e : '')}</strong><br />
|
||||
panelBlockElement.innerHTML = `<strong>${cityssm.escapeHTML((_g = fee.feeName) !== null && _g !== void 0 ? _g : '')}</strong><br />
|
||||
<small>
|
||||
${cityssm
|
||||
.escapeHTML((_f = fee.feeDescription) !== null && _f !== void 0 ? _f : '')
|
||||
${
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
cityssm
|
||||
.escapeHTML((_h = fee.feeDescription) !== null && _h !== void 0 ? _h : '')
|
||||
.replaceAll('\n', '<br />')}
|
||||
</small>`;
|
||||
panelBlockElement.addEventListener('click', tryAddFee);
|
||||
if (!feeCategory.isGroupedFee) {
|
||||
;
|
||||
panelBlockElement.href = '#';
|
||||
panelBlockElement.addEventListener('click', tryAddFee);
|
||||
}
|
||||
;
|
||||
categoryContainerElement.querySelector('.panel').append(panelBlockElement);
|
||||
}
|
||||
if (hasFees) {
|
||||
|
|
|
|||
|
|
@ -307,6 +307,47 @@ addFeeButtonElement.addEventListener('click', () => {
|
|||
let feeFilterElement: HTMLInputElement
|
||||
let feeFilterResultsElement: HTMLElement
|
||||
|
||||
function doAddFeeCategory(clickEvent: Event): void {
|
||||
clickEvent.preventDefault()
|
||||
|
||||
const feeCategoryId = Number.parseInt(
|
||||
(clickEvent.currentTarget as HTMLElement).dataset.feeCategoryId ?? '',
|
||||
10
|
||||
)
|
||||
|
||||
cityssm.postJSON(
|
||||
`${los.urlPrefix}/lotOccupancies/doAddLotOccupancyFeeCategory`,
|
||||
{
|
||||
lotOccupancyId,
|
||||
feeCategoryId
|
||||
},
|
||||
(rawResponseJSON) => {
|
||||
const responseJSON = rawResponseJSON as {
|
||||
success: boolean
|
||||
errorMessage?: string
|
||||
lotOccupancyFees: LotOccupancyFee[]
|
||||
}
|
||||
|
||||
if (responseJSON.success) {
|
||||
lotOccupancyFees = responseJSON.lotOccupancyFees
|
||||
renderLotOccupancyFees()
|
||||
|
||||
bulmaJS.alert({
|
||||
message: 'Fee Group Added Successfully',
|
||||
contextualColorName: 'success'
|
||||
})
|
||||
|
||||
} else {
|
||||
bulmaJS.alert({
|
||||
title: 'Error Adding Fee',
|
||||
message: responseJSON.errorMessage ?? '',
|
||||
contextualColorName: 'danger'
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function doAddFee(feeId: number, quantity: number | string = 1): void {
|
||||
cityssm.postJSON(
|
||||
`${los.urlPrefix}/lotOccupancies/doAddLotOccupancyFee`,
|
||||
|
|
@ -412,11 +453,30 @@ addFeeButtonElement.addEventListener('click', () => {
|
|||
categoryContainerElement.dataset.feeCategoryId =
|
||||
feeCategory.feeCategoryId.toString()
|
||||
|
||||
categoryContainerElement.innerHTML = `<h4 class="title is-5 mt-2">
|
||||
${cityssm.escapeHTML(feeCategory.feeCategory ?? '')}
|
||||
</h4>
|
||||
categoryContainerElement.innerHTML = `<div class="columns is-vcentered">
|
||||
<div class="column">
|
||||
<h4 class="title is-5">
|
||||
${cityssm.escapeHTML(feeCategory.feeCategory ?? '')}
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel mb-5"></div>`
|
||||
|
||||
if (feeCategory.isGroupedFee) {
|
||||
// eslint-disable-next-line no-unsanitized/method
|
||||
categoryContainerElement.querySelector('.columns')?.insertAdjacentHTML(
|
||||
'beforeend',
|
||||
`<div class="column is-narrow has-text-right">
|
||||
<button class="button is-small is-success" type="button" data-fee-category-id="${feeCategory.feeCategoryId}">
|
||||
<span class="icon is-small"><i class="fas fa-plus" aria-hidden="true"></i></span>
|
||||
<span>Add Fee Group</span>
|
||||
</button>
|
||||
</div>`
|
||||
)
|
||||
|
||||
categoryContainerElement.querySelector('button')?.addEventListener('click', doAddFeeCategory)
|
||||
}
|
||||
|
||||
let hasFees = false
|
||||
|
||||
for (const fee of feeCategory.fees) {
|
||||
|
|
@ -447,22 +507,29 @@ addFeeButtonElement.addEventListener('click', () => {
|
|||
|
||||
hasFees = true
|
||||
|
||||
const panelBlockElement = document.createElement('a')
|
||||
const panelBlockElement = document.createElement(
|
||||
feeCategory.isGroupedFee ? 'div' : 'a'
|
||||
)
|
||||
panelBlockElement.className = 'panel-block is-block container--fee'
|
||||
panelBlockElement.dataset.feeId = fee.feeId.toString()
|
||||
panelBlockElement.dataset.feeCategoryId =
|
||||
feeCategory.feeCategoryId.toString()
|
||||
panelBlockElement.href = '#'
|
||||
|
||||
// eslint-disable-next-line no-unsanitized/property
|
||||
panelBlockElement.innerHTML = `<strong>${cityssm.escapeHTML(fee.feeName ?? '')}</strong><br />
|
||||
<small>
|
||||
${cityssm
|
||||
.escapeHTML(fee.feeDescription ?? '')
|
||||
.replaceAll('\n', '<br />')}
|
||||
${
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
cityssm
|
||||
.escapeHTML(fee.feeDescription ?? '')
|
||||
.replaceAll('\n', '<br />')
|
||||
}
|
||||
</small>`
|
||||
|
||||
panelBlockElement.addEventListener('click', tryAddFee)
|
||||
if (!feeCategory.isGroupedFee) {
|
||||
;(panelBlockElement as HTMLAnchorElement).href = '#'
|
||||
panelBlockElement.addEventListener('click', tryAddFee)
|
||||
}
|
||||
;(
|
||||
categoryContainerElement.querySelector('.panel') as HTMLElement
|
||||
).append(panelBlockElement)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@
|
|||
/>
|
||||
</div>
|
||||
</div>
|
||||
<label class="checkbox is-block">
|
||||
<input id="feeCategoryAdd--isGroupedFee" name="isGroupedFee" type="checkbox" value="1" />
|
||||
Treat Category as a Group of Fees
|
||||
</label>
|
||||
</form>
|
||||
</section>
|
||||
<div class="modal-card-foot justify-right">
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@
|
|||
/>
|
||||
</div>
|
||||
</div>
|
||||
<label class="checkbox is-block">
|
||||
<input id="feeCategoryEdit--isGroupedFee" name="isGroupedFee" type="checkbox" value="1" />
|
||||
Treat Category as a Group of Fees
|
||||
</label>
|
||||
</form>
|
||||
</section>
|
||||
<footer class="modal-card-foot justify-right">
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -5,6 +5,7 @@ import handler_search from '../handlers/lotOccupancies-get/search.js';
|
|||
import handler_view from '../handlers/lotOccupancies-get/view.js';
|
||||
import handler_doAddLotOccupancyComment from '../handlers/lotOccupancies-post/doAddLotOccupancyComment.js';
|
||||
import handler_doAddLotOccupancyFee from '../handlers/lotOccupancies-post/doAddLotOccupancyFee.js';
|
||||
import handler_doAddLotOccupancyFeeCategory from '../handlers/lotOccupancies-post/doAddLotOccupancyFeeCategory.js';
|
||||
import handler_doAddLotOccupancyOccupant from '../handlers/lotOccupancies-post/doAddLotOccupancyOccupant.js';
|
||||
import handler_doAddLotOccupancyTransaction from '../handlers/lotOccupancies-post/doAddLotOccupancyTransaction.js';
|
||||
import handler_doCopyLotOccupancy from '../handlers/lotOccupancies-post/doCopyLotOccupancy.js';
|
||||
|
|
@ -53,6 +54,7 @@ router.post('/doDeleteLotOccupancyComment', updatePostHandler, handler_doDeleteL
|
|||
// Fees
|
||||
router.post('/doGetFees', updatePostHandler, handler_doGetFees);
|
||||
router.post('/doAddLotOccupancyFee', updatePostHandler, handler_doAddLotOccupancyFee);
|
||||
router.post('/doAddLotOccupancyFeeCategory', updatePostHandler, handler_doAddLotOccupancyFeeCategory);
|
||||
router.post('/doUpdateLotOccupancyFeeQuantity', updatePostHandler, handler_doUpdateLotOccupancyFeeQuantity);
|
||||
router.post('/doDeleteLotOccupancyFee', updatePostHandler, handler_doDeleteLotOccupancyFee);
|
||||
// Transactions
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import handler_search from '../handlers/lotOccupancies-get/search.js'
|
|||
import handler_view from '../handlers/lotOccupancies-get/view.js'
|
||||
import handler_doAddLotOccupancyComment from '../handlers/lotOccupancies-post/doAddLotOccupancyComment.js'
|
||||
import handler_doAddLotOccupancyFee from '../handlers/lotOccupancies-post/doAddLotOccupancyFee.js'
|
||||
import handler_doAddLotOccupancyFeeCategory from '../handlers/lotOccupancies-post/doAddLotOccupancyFeeCategory.js'
|
||||
import handler_doAddLotOccupancyOccupant from '../handlers/lotOccupancies-post/doAddLotOccupancyOccupant.js'
|
||||
import handler_doAddLotOccupancyTransaction from '../handlers/lotOccupancies-post/doAddLotOccupancyTransaction.js'
|
||||
import handler_doCopyLotOccupancy from '../handlers/lotOccupancies-post/doCopyLotOccupancy.js'
|
||||
|
|
@ -145,6 +146,12 @@ router.post(
|
|||
handler_doAddLotOccupancyFee as RequestHandler
|
||||
)
|
||||
|
||||
router.post(
|
||||
'/doAddLotOccupancyFeeCategory',
|
||||
updatePostHandler,
|
||||
handler_doAddLotOccupancyFeeCategory as RequestHandler
|
||||
)
|
||||
|
||||
router.post(
|
||||
'/doUpdateLotOccupancyFeeQuantity',
|
||||
updatePostHandler,
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ export interface FeeCategory extends Record {
|
|||
feeCategoryId: number;
|
||||
feeCategory: string;
|
||||
fees: Fee[];
|
||||
isGroupedFee: boolean;
|
||||
orderNumber?: number;
|
||||
}
|
||||
export interface Fee extends Record {
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ export interface FeeCategory extends Record {
|
|||
feeCategoryId: number
|
||||
feeCategory: string
|
||||
fees: Fee[]
|
||||
isGroupedFee: boolean
|
||||
orderNumber?: number
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue