custom lot name sort name function
parent
b85a3a9ba5
commit
c2ae19f4a6
|
|
@ -1,5 +1,26 @@
|
|||
import { config as cemeteryConfig } from "./config.cemetery.ontario.js";
|
||||
export const config = Object.assign({}, cemeteryConfig);
|
||||
config.settings.lot = {
|
||||
lotNameSortNameFunction: (lotName) => {
|
||||
const numericPadding = "00000";
|
||||
const lotNameSplit = lotName.toUpperCase().split("-");
|
||||
const cleanLotNamePieces = [];
|
||||
for (const lotNamePiece of lotNameSplit) {
|
||||
let numericPiece = numericPadding;
|
||||
let letterPiece = "";
|
||||
for (const letter of lotNamePiece) {
|
||||
if (letterPiece === "" && "0123456789".includes(letter)) {
|
||||
numericPiece += letter;
|
||||
}
|
||||
else {
|
||||
letterPiece += letter;
|
||||
}
|
||||
}
|
||||
cleanLotNamePieces.push(numericPiece.slice(-1 * numericPadding.length) + letterPiece);
|
||||
}
|
||||
return cleanLotNamePieces.join("-");
|
||||
}
|
||||
};
|
||||
config.settings.lotOccupancy.occupantCityDefault = "Sault Ste. Marie";
|
||||
config.settings.map.mapCityDefault = "Sault Ste. Marie";
|
||||
config.aliases.externalReceiptNumber = "GP Receipt Number";
|
||||
|
|
|
|||
|
|
@ -1,7 +1,39 @@
|
|||
import { config as cemeteryConfig } from "./config.cemetery.ontario.js";
|
||||
import {
|
||||
config as cemeteryConfig
|
||||
} from "./config.cemetery.ontario.js";
|
||||
|
||||
export const config = Object.assign({}, cemeteryConfig);
|
||||
|
||||
config.settings.lot = {
|
||||
lotNameSortNameFunction: (lotName) => {
|
||||
|
||||
const numericPadding = "00000";
|
||||
|
||||
const lotNameSplit = lotName.toUpperCase().split("-");
|
||||
|
||||
const cleanLotNamePieces: string[] = [];
|
||||
|
||||
for (const lotNamePiece of lotNameSplit) {
|
||||
|
||||
let numericPiece = numericPadding;
|
||||
let letterPiece = "";
|
||||
|
||||
for (const letter of lotNamePiece) {
|
||||
|
||||
if (letterPiece === "" && "0123456789".includes(letter)) {
|
||||
numericPiece += letter;
|
||||
} else {
|
||||
letterPiece += letter;
|
||||
}
|
||||
}
|
||||
|
||||
cleanLotNamePieces.push(numericPiece.slice(-1 * numericPadding.length) + letterPiece);
|
||||
}
|
||||
|
||||
return cleanLotNamePieces.join("-");
|
||||
}
|
||||
};
|
||||
|
||||
config.settings.lotOccupancy.occupantCityDefault = "Sault Ste. Marie";
|
||||
config.settings.map.mapCityDefault = "Sault Ste. Marie";
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ export declare function getProperty(propertyName: "aliases.occupants"): string;
|
|||
export declare function getProperty(propertyName: "aliases.externalReceiptNumber"): string;
|
||||
export declare function getProperty(propertyName: "settings.map.mapCityDefault"): string;
|
||||
export declare function getProperty(propertyName: "settings.map.mapProvinceDefault"): string;
|
||||
export declare function getProperty(propertyName: "settings.lot.lotNameSortNameFunction"): (lotName: string) => string;
|
||||
export declare function getProperty(propertyName: "settings.lotOccupancy.occupancyEndDateIsRequired"): boolean;
|
||||
export declare function getProperty(propertyName: "settings.lotOccupancy.occupantCityDefault"): string;
|
||||
export declare function getProperty(propertyName: "settings.lotOccupancy.occupantProvinceDefault"): string;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ configFallbackValues.set("aliases.occupants", "Occupants");
|
|||
configFallbackValues.set("aliases.externalReceiptNumber", "External Receipt Number");
|
||||
configFallbackValues.set("settings.map.mapCityDefault", "");
|
||||
configFallbackValues.set("settings.map.mapProvinceDefault", "");
|
||||
configFallbackValues.set("settings.lot.lotNameSortNameFunction", (lotName) => lotName);
|
||||
configFallbackValues.set("settings.lotOccupancy.occupancyEndDateIsRequired", true);
|
||||
configFallbackValues.set("settings.lotOccupancy.occupantCityDefault", "");
|
||||
configFallbackValues.set("settings.lotOccupancy.occupantProvinceDefault", "");
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ configFallbackValues.set("aliases.externalReceiptNumber", "External Receipt Numb
|
|||
configFallbackValues.set("settings.map.mapCityDefault", "");
|
||||
configFallbackValues.set("settings.map.mapProvinceDefault", "");
|
||||
|
||||
configFallbackValues.set("settings.lot.lotNameSortNameFunction", (lotName: string) => lotName);
|
||||
|
||||
configFallbackValues.set("settings.lotOccupancy.occupancyEndDateIsRequired", true);
|
||||
configFallbackValues.set("settings.lotOccupancy.occupantCityDefault", "");
|
||||
configFallbackValues.set("settings.lotOccupancy.occupantProvinceDefault", "");
|
||||
|
|
@ -91,6 +93,8 @@ export function getProperty(propertyName: "aliases.externalReceiptNumber"): stri
|
|||
export function getProperty(propertyName: "settings.map.mapCityDefault"): string;
|
||||
export function getProperty(propertyName: "settings.map.mapProvinceDefault"): string;
|
||||
|
||||
export function getProperty(propertyName: "settings.lot.lotNameSortNameFunction"): (lotName: string) => string;
|
||||
|
||||
export function getProperty(propertyName: "settings.lotOccupancy.occupancyEndDateIsRequired"): boolean;
|
||||
export function getProperty(propertyName: "settings.lotOccupancy.occupantCityDefault"): string;
|
||||
export function getProperty(propertyName: "settings.lotOccupancy.occupantProvinceDefault"): string;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import sqlite from "better-sqlite3";
|
||||
import type * as recordTypes from "../../types/recordTypes";
|
||||
interface GetLotsFilters {
|
||||
lotName?: string;
|
||||
|
|
@ -10,7 +11,7 @@ interface GetLotsOptions {
|
|||
limit: number;
|
||||
offset: number;
|
||||
}
|
||||
export declare const getLots: (filters?: GetLotsFilters, options?: GetLotsOptions) => {
|
||||
export declare const getLots: (filters: GetLotsFilters, options: GetLotsOptions, connectedDatabase?: sqlite.Database) => {
|
||||
count: number;
|
||||
lots: recordTypes.Lot[];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import sqlite from "better-sqlite3";
|
||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||
import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||
export const getLots = (filters, options) => {
|
||||
const database = sqlite(databasePath, {
|
||||
import * as configFunctions from "../functions.config.js";
|
||||
export const getLots = (filters, options, connectedDatabase) => {
|
||||
const database = connectedDatabase || sqlite(databasePath, {
|
||||
readonly: true
|
||||
});
|
||||
let sqlWhereClause = " where l.recordDelete_timeMillis is null";
|
||||
|
|
@ -50,6 +51,7 @@ export const getLots = (filters, options) => {
|
|||
.recordCount;
|
||||
let lots = [];
|
||||
if (count > 0) {
|
||||
database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction"));
|
||||
lots = database
|
||||
.prepare("select l.lotId, l.lotName," +
|
||||
" t.lotType," +
|
||||
|
|
@ -69,13 +71,15 @@ export const getLots = (filters, options) => {
|
|||
" group by lotId" +
|
||||
") o on l.lotId = o.lotId") +
|
||||
sqlWhereClause +
|
||||
" order by l.lotName, l.lotId" +
|
||||
" order by userFn_lotNameSortName(l.lotName), l.lotId" +
|
||||
(options ?
|
||||
" limit " + options.limit + " offset " + options.offset :
|
||||
""))
|
||||
.all(sqlParameters);
|
||||
}
|
||||
if (!connectedDatabase) {
|
||||
database.close();
|
||||
}
|
||||
return {
|
||||
count,
|
||||
lots
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import {
|
|||
dateToInteger
|
||||
} from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||
|
||||
import * as configFunctions from "../functions.config.js";
|
||||
|
||||
import type * as recordTypes from "../../types/recordTypes";
|
||||
|
||||
|
||||
|
|
@ -25,12 +27,14 @@ interface GetLotsOptions {
|
|||
}
|
||||
|
||||
|
||||
export const getLots = (filters ? : GetLotsFilters, options ? : GetLotsOptions): {
|
||||
export const getLots = (filters: GetLotsFilters,
|
||||
options: GetLotsOptions,
|
||||
connectedDatabase ? : sqlite.Database): {
|
||||
count: number;
|
||||
lots: recordTypes.Lot[];
|
||||
} => {
|
||||
|
||||
const database = sqlite(databasePath, {
|
||||
const database = connectedDatabase || sqlite(databasePath, {
|
||||
readonly: true
|
||||
});
|
||||
|
||||
|
|
@ -88,6 +92,8 @@ export const getLots = (filters ? : GetLotsFilters, options ? : GetLotsOptions):
|
|||
|
||||
if (count > 0) {
|
||||
|
||||
database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction"));
|
||||
|
||||
lots = database
|
||||
.prepare("select l.lotId, l.lotName," +
|
||||
" t.lotType," +
|
||||
|
|
@ -107,14 +113,16 @@ export const getLots = (filters ? : GetLotsFilters, options ? : GetLotsOptions):
|
|||
" group by lotId" +
|
||||
") o on l.lotId = o.lotId") +
|
||||
sqlWhereClause +
|
||||
" order by l.lotName, l.lotId" +
|
||||
" order by userFn_lotNameSortName(l.lotName), l.lotId" +
|
||||
(options ?
|
||||
" limit " + options.limit + " offset " + options.offset :
|
||||
""))
|
||||
.all(sqlParameters);
|
||||
}
|
||||
|
||||
if (!connectedDatabase) {
|
||||
database.close();
|
||||
}
|
||||
|
||||
return {
|
||||
count,
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
import sqlite from "better-sqlite3";
|
||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||
import * as configFunctions from "../functions.config.js";
|
||||
export const getNextLotId = (lotId) => {
|
||||
const database = sqlite(databasePath, {
|
||||
readonly: true
|
||||
});
|
||||
database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction"));
|
||||
const result = database
|
||||
.prepare("select lotId from Lots" +
|
||||
" where recordDelete_timeMillis is null" +
|
||||
" and lotName > (select lotName from Lots where lotId = ?)" +
|
||||
" order by lotName" +
|
||||
" and userFn_lotNameSortName(lotName) > (select userFn_lotNameSortName(lotName) from Lots where lotId = ?)" +
|
||||
" order by userFn_lotNameSortName(lotName)" +
|
||||
" limit 1")
|
||||
.get(lotId);
|
||||
database.close();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import {
|
|||
lotOccupancyDB as databasePath
|
||||
} from "../../data/databasePaths.js";
|
||||
|
||||
import * as configFunctions from "../functions.config.js";
|
||||
|
||||
|
||||
export const getNextLotId = (lotId: number | string): number => {
|
||||
|
||||
|
|
@ -11,13 +13,15 @@ export const getNextLotId = (lotId: number | string): number => {
|
|||
readonly: true
|
||||
});
|
||||
|
||||
database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction"));
|
||||
|
||||
const result: {
|
||||
lotId: number
|
||||
} = database
|
||||
.prepare("select lotId from Lots" +
|
||||
" where recordDelete_timeMillis is null" +
|
||||
" and lotName > (select lotName from Lots where lotId = ?)" +
|
||||
" order by lotName" +
|
||||
" and userFn_lotNameSortName(lotName) > (select userFn_lotNameSortName(lotName) from Lots where lotId = ?)" +
|
||||
" order by userFn_lotNameSortName(lotName)" +
|
||||
" limit 1")
|
||||
.get(lotId);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
import sqlite from "better-sqlite3";
|
||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||
import * as configFunctions from "../functions.config.js";
|
||||
export const getPreviousLotId = (lotId) => {
|
||||
const database = sqlite(databasePath, {
|
||||
readonly: true
|
||||
});
|
||||
database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction"));
|
||||
const result = database
|
||||
.prepare("select lotId from Lots" +
|
||||
" where recordDelete_timeMillis is null" +
|
||||
" and lotName < (select lotName from Lots where lotId = ?)" +
|
||||
" order by lotName desc" +
|
||||
" and userFn_lotNameSortName(lotName) < (select userFn_lotNameSortName(lotName) from Lots where lotId = ?)" +
|
||||
" order by userFn_lotNameSortName(lotName) desc" +
|
||||
" limit 1")
|
||||
.get(lotId);
|
||||
database.close();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import {
|
|||
lotOccupancyDB as databasePath
|
||||
} from "../../data/databasePaths.js";
|
||||
|
||||
import * as configFunctions from "../functions.config.js";
|
||||
|
||||
|
||||
export const getPreviousLotId = (lotId: number | string): number => {
|
||||
|
||||
|
|
@ -11,13 +13,15 @@ export const getPreviousLotId = (lotId: number | string): number => {
|
|||
readonly: true
|
||||
});
|
||||
|
||||
database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction"));
|
||||
|
||||
const result: {
|
||||
lotId: number
|
||||
} = database
|
||||
.prepare("select lotId from Lots" +
|
||||
" where recordDelete_timeMillis is null" +
|
||||
" and lotName < (select lotName from Lots where lotId = ?)" +
|
||||
" order by lotName desc" +
|
||||
" and userFn_lotNameSortName(lotName) < (select userFn_lotNameSortName(lotName) from Lots where lotId = ?)" +
|
||||
" order by userFn_lotNameSortName(lotName) desc" +
|
||||
" limit 1")
|
||||
.get(lotId);
|
||||
|
||||
|
|
|
|||
|
|
@ -459,6 +459,9 @@ function importFromPrepaidCSV() {
|
|||
const possibleLots = getLots({
|
||||
mapId: map.mapId,
|
||||
lotName
|
||||
}, {
|
||||
limit: -1,
|
||||
offset: 0
|
||||
});
|
||||
if (possibleLots.lots.length > 0) {
|
||||
lot = possibleLots.lots[0];
|
||||
|
|
|
|||
|
|
@ -777,7 +777,10 @@ function importFromPrepaidCSV() {
|
|||
const possibleLots = getLots({
|
||||
mapId: map.mapId,
|
||||
lotName
|
||||
});
|
||||
}, {
|
||||
limit: -1,
|
||||
offset: 0
|
||||
};
|
||||
|
||||
if (possibleLots.lots.length > 0) {
|
||||
lot = possibleLots.lots[0];
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ export interface Config {
|
|||
mapCityDefault?: string;
|
||||
mapProvinceDefault?: string;
|
||||
};
|
||||
lot?: {
|
||||
lotNameSortNameFunction?: (lotName: string) => string;
|
||||
};
|
||||
lotOccupancy?: {
|
||||
lotIdIsRequired?: boolean;
|
||||
occupancyEndDateIsRequired?: boolean;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ export interface Config {
|
|||
mapCityDefault ? : string;
|
||||
mapProvinceDefault ? : string;
|
||||
};
|
||||
lot ? : {
|
||||
lotNameSortNameFunction ? : (lotName: string) => string;
|
||||
};
|
||||
lotOccupancy ? : {
|
||||
lotIdIsRequired ? : boolean;
|
||||
occupancyEndDateIsRequired ? : boolean;
|
||||
|
|
|
|||
Loading…
Reference in New Issue