update legacy import
parent
3374ec61a4
commit
1113b64025
|
|
@ -5,8 +5,8 @@ import { addOccupancyType } from "./lotOccupancyDB/addOccupancyType.js";
|
|||
import { addOccupancyTypeField } from "./lotOccupancyDB/addOccupancyTypeField.js";
|
||||
import { addLotStatus } from "./lotOccupancyDB/addLotStatus.js";
|
||||
import { addLotOccupantType } from "./lotOccupancyDB/addLotOccupantType.js";
|
||||
import { addFeeCategory } from "./lotOccupancyDB/addFeeCategory.js";
|
||||
import Debug from "debug";
|
||||
import addFeeCategory from "./lotOccupancyDB/addFeeCategory.js";
|
||||
const debug = Debug("lot-occupancy-system:initialize");
|
||||
const session = {
|
||||
user: {
|
||||
|
|
@ -70,6 +70,10 @@ const initializeCemeteryDatabase = () => {
|
|||
lotOccupantType: "Preneed Owner",
|
||||
orderNumber: 2
|
||||
}, session);
|
||||
addLotOccupantType({
|
||||
lotOccupantType: "Arranger",
|
||||
orderNumber: 3
|
||||
}, session);
|
||||
addOccupancyType({
|
||||
occupancyType: "Preneed",
|
||||
orderNumber: 1
|
||||
|
|
|
|||
|
|
@ -26,12 +26,15 @@ import {
|
|||
addLotOccupantType
|
||||
} from "./lotOccupancyDB/addLotOccupantType.js";
|
||||
|
||||
import {
|
||||
addFeeCategory
|
||||
} from "./lotOccupancyDB/addFeeCategory.js";
|
||||
|
||||
import type {
|
||||
PartialSession
|
||||
} from "../types/recordTypes.js";
|
||||
|
||||
import Debug from "debug";
|
||||
import addFeeCategory from "./lotOccupancyDB/addFeeCategory.js";
|
||||
const debug = Debug("lot-occupancy-system:initialize");
|
||||
|
||||
|
||||
|
|
@ -131,6 +134,11 @@ const initializeCemeteryDatabase = () => {
|
|||
orderNumber: 2
|
||||
}, session);
|
||||
|
||||
addLotOccupantType({
|
||||
lotOccupantType: "Arranger",
|
||||
orderNumber: 3
|
||||
}, session);
|
||||
|
||||
/*
|
||||
* Occupancy Types
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import type * as recordTypes from "../../types/recordTypes";
|
||||
interface AddLotOccupancyFeeForm {
|
||||
lotOccupancyId: string;
|
||||
feeId: string;
|
||||
lotOccupancyId: number | string;
|
||||
feeId: number | string;
|
||||
quantity: number | string;
|
||||
feeAmount?: number | string;
|
||||
taxAmount?: number | string;
|
||||
}
|
||||
export declare const addLotOccupancyFee: (lotOccupancyFeeForm: AddLotOccupancyFeeForm, requestSession: recordTypes.PartialSession) => boolean;
|
||||
export default addLotOccupancyFee;
|
||||
|
|
|
|||
|
|
@ -23,10 +23,18 @@ export const addLotOccupancyFee = (lotOccupancyFeeForm, requestSession) => {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
let feeAmount;
|
||||
let taxAmount;
|
||||
if (lotOccupancyFeeForm.feeAmount) {
|
||||
feeAmount = typeof (lotOccupancyFeeForm.feeAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.feeAmount) : feeAmount;
|
||||
taxAmount = typeof (lotOccupancyFeeForm.taxAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.taxAmount) : taxAmount;
|
||||
}
|
||||
else {
|
||||
const lotOccupancy = getLotOccupancy(lotOccupancyFeeForm.lotOccupancyId);
|
||||
const fee = getFee(lotOccupancyFeeForm.feeId);
|
||||
const feeAmount = calculateFeeAmount(fee, lotOccupancy);
|
||||
const taxAmount = calculateTaxAmount(fee, feeAmount);
|
||||
feeAmount = calculateFeeAmount(fee, lotOccupancy);
|
||||
taxAmount = calculateTaxAmount(fee, feeAmount);
|
||||
}
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare("insert into LotOccupancyFees (" +
|
||||
|
|
|
|||
|
|
@ -21,9 +21,11 @@ import type * as recordTypes from "../../types/recordTypes";
|
|||
|
||||
|
||||
interface AddLotOccupancyFeeForm {
|
||||
lotOccupancyId: string;
|
||||
feeId: string;
|
||||
lotOccupancyId: number | string;
|
||||
feeId: number | string;
|
||||
quantity: number | string;
|
||||
feeAmount ? : number | string;
|
||||
taxAmount ? : number | string;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -35,7 +37,7 @@ export const addLotOccupancyFee =
|
|||
// Check if record already exists
|
||||
|
||||
const record: {
|
||||
recordDelete_timeMillis?: number
|
||||
recordDelete_timeMillis ? : number
|
||||
} = database.prepare("select recordDelete_timeMillis" +
|
||||
" from LotOccupancyFees" +
|
||||
" where lotOccupancyId = ?" +
|
||||
|
|
@ -58,11 +60,20 @@ export const addLotOccupancyFee =
|
|||
|
||||
// Create new record
|
||||
|
||||
let feeAmount: number;
|
||||
let taxAmount: number;
|
||||
|
||||
if (lotOccupancyFeeForm.feeAmount) {
|
||||
feeAmount = typeof(lotOccupancyFeeForm.feeAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.feeAmount) : feeAmount;
|
||||
taxAmount = typeof(lotOccupancyFeeForm.taxAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.taxAmount) : taxAmount;
|
||||
} else {
|
||||
|
||||
const lotOccupancy = getLotOccupancy(lotOccupancyFeeForm.lotOccupancyId);
|
||||
const fee = getFee(lotOccupancyFeeForm.feeId);
|
||||
|
||||
const feeAmount = calculateFeeAmount(fee, lotOccupancy);
|
||||
const taxAmount = calculateTaxAmount(fee, feeAmount);
|
||||
feeAmount = calculateFeeAmount(fee, lotOccupancy);
|
||||
taxAmount = calculateTaxAmount(fee, feeAmount);
|
||||
}
|
||||
|
||||
const rightNowMillis = Date.now();
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ export const addLotOccupancyTransaction = (lotOccupancyTransactionForm, requestS
|
|||
if (maxIndexResult) {
|
||||
transactionIndex = maxIndexResult.transactionIndex + 1;
|
||||
}
|
||||
console.log("transactionIndex = " + transactionIndex);
|
||||
const rightNow = new Date();
|
||||
const transactionDate = lotOccupancyTransactionForm.transactionDateString ?
|
||||
dateStringToInteger(lotOccupancyTransactionForm.transactionDateString) :
|
||||
|
|
|
|||
|
|
@ -41,8 +41,6 @@ export const addLotOccupancyTransaction =
|
|||
transactionIndex = maxIndexResult.transactionIndex + 1;
|
||||
}
|
||||
|
||||
console.log("transactionIndex = " + transactionIndex);
|
||||
|
||||
const rightNow = new Date();
|
||||
|
||||
const transactionDate = lotOccupancyTransactionForm.transactionDateString ?
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ export const getFee = (feeId) => {
|
|||
" f.feeName, f.feeDescription," +
|
||||
" f.occupancyTypeId, o.occupancyType," +
|
||||
" f.lotTypeId, l.lotType," +
|
||||
" f.feeAmount, f.feeFunction, f.taxAmount, f.taxPercentage," +
|
||||
" ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction," +
|
||||
" f.taxAmount, f.taxPercentage," +
|
||||
" f.includeQuantity, f.quantityUnit," +
|
||||
" f.isRequired" +
|
||||
" from Fees f" +
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ export const getFee = (feeId: number | string): recordTypes.Fee => {
|
|||
" f.feeName, f.feeDescription," +
|
||||
" f.occupancyTypeId, o.occupancyType," +
|
||||
" f.lotTypeId, l.lotType," +
|
||||
" f.feeAmount, f.feeFunction, f.taxAmount, f.taxPercentage," +
|
||||
" ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction," +
|
||||
" f.taxAmount, f.taxPercentage," +
|
||||
" f.includeQuantity, f.quantityUnit," +
|
||||
" f.isRequired" +
|
||||
" from Fees f" +
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ export const getFeeCategories = (filters, options) => {
|
|||
sql = "select f.feeId, f.feeName, f.feeDescription," +
|
||||
" f.occupancyTypeId, o.occupancyType," +
|
||||
" f.lotTypeId, l.lotType," +
|
||||
" f.feeAmount, f.feeFunction, f.taxAmount, f.taxPercentage," +
|
||||
" ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction," +
|
||||
" f.taxAmount, f.taxPercentage," +
|
||||
" f.includeQuantity, f.quantityUnit," +
|
||||
" f.isRequired" +
|
||||
" from Fees f" +
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ export const getFeeCategories = (filters ? : GetFeeCategoriesFilters, options ?
|
|||
sql = "select f.feeId, f.feeName, f.feeDescription," +
|
||||
" f.occupancyTypeId, o.occupancyType," +
|
||||
" f.lotTypeId, l.lotType," +
|
||||
" f.feeAmount, f.feeFunction, f.taxAmount, f.taxPercentage," +
|
||||
" ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction," +
|
||||
" f.taxAmount, f.taxPercentage," +
|
||||
" f.includeQuantity, f.quantityUnit," +
|
||||
" f.isRequired" +
|
||||
" from Fees f" +
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import type * as recordTypes from "../../types/recordTypes";
|
|||
interface GetLotOccupanciesFilters {
|
||||
lotId?: number | string;
|
||||
occupancyTime?: "" | "past" | "current" | "future";
|
||||
occupancyStartDateString?: string;
|
||||
occupantName?: string;
|
||||
occupancyTypeId?: number | string;
|
||||
mapId?: number | string;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { dateIntegerToString, dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||
import { dateIntegerToString, dateStringToInteger, dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||
import sqlite from "better-sqlite3";
|
||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||
import { getLotOccupancyOccupants } from "./getLotOccupancyOccupants.js";
|
||||
|
|
@ -48,6 +48,10 @@ export const getLotOccupancies = (filters, options, connectedDatabase) => {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (filters.occupancyStartDateString) {
|
||||
sqlWhereClause += " and o.occupancyStartDate = ?";
|
||||
sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString));
|
||||
}
|
||||
if (filters.mapId) {
|
||||
sqlWhereClause += " and l.mapId = ?";
|
||||
sqlParameters.push(filters.mapId);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
dateIntegerToString,
|
||||
dateStringToInteger,
|
||||
dateToInteger
|
||||
} from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||
|
||||
|
|
@ -19,6 +20,7 @@ import type * as recordTypes from "../../types/recordTypes";
|
|||
interface GetLotOccupanciesFilters {
|
||||
lotId ? : number | string;
|
||||
occupancyTime ? : "" | "past" | "current" | "future";
|
||||
occupancyStartDateString?: string;
|
||||
occupantName ? : string;
|
||||
occupancyTypeId ? : number | string;
|
||||
mapId ? : number | string;
|
||||
|
|
@ -100,6 +102,11 @@ export const getLotOccupancies = (filters: GetLotOccupanciesFilters,
|
|||
}
|
||||
}
|
||||
|
||||
if (filters.occupancyStartDateString) {
|
||||
sqlWhereClause += " and o.occupancyStartDate = ?";
|
||||
sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString));
|
||||
}
|
||||
|
||||
if (filters.mapId) {
|
||||
sqlWhereClause += " and l.mapId = ?";
|
||||
sqlParameters.push(filters.mapId);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
"csurf": "^1.11.0",
|
||||
"debug": "^4.3.4",
|
||||
"ejs": "^3.1.8",
|
||||
"exit-hook": "^3.0.0",
|
||||
"exit-hook": "^3.1.0",
|
||||
"express": "^4.18.1",
|
||||
"express-rate-limit": "^6.5.1",
|
||||
"express-session": "^1.17.3",
|
||||
|
|
@ -3701,9 +3701,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/exit-hook": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-3.0.0.tgz",
|
||||
"integrity": "sha512-ElRvnoj3dvOc5WjnQx0CF66rS0xehV6eZdcmqZX17uOLPy3me43frl8UD73Frkx5Aq5kgziMDECjDJR2X1oBFQ==",
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-3.1.0.tgz",
|
||||
"integrity": "sha512-KiF9SiLZsKhSutx4V9sG2InYb0v1+2sfKlGD18et8/aGg2m4ij6MJbUHy/cnqJf4ncE7rWjqchE2SNIi4Lgg4A==",
|
||||
"engines": {
|
||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||
},
|
||||
|
|
@ -13529,9 +13529,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"exit-hook": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-3.0.0.tgz",
|
||||
"integrity": "sha512-ElRvnoj3dvOc5WjnQx0CF66rS0xehV6eZdcmqZX17uOLPy3me43frl8UD73Frkx5Aq5kgziMDECjDJR2X1oBFQ=="
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-3.1.0.tgz",
|
||||
"integrity": "sha512-KiF9SiLZsKhSutx4V9sG2InYb0v1+2sfKlGD18et8/aGg2m4ij6MJbUHy/cnqJf4ncE7rWjqchE2SNIi4Lgg4A=="
|
||||
},
|
||||
"expand-brackets": {
|
||||
"version": "2.1.4",
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
"csurf": "^1.11.0",
|
||||
"debug": "^4.3.4",
|
||||
"ejs": "^3.1.8",
|
||||
"exit-hook": "^3.0.0",
|
||||
"exit-hook": "^3.1.0",
|
||||
"express": "^4.18.1",
|
||||
"express-rate-limit": "^6.5.1",
|
||||
"express-session": "^1.17.3",
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ import { addLotOccupancy } from "../helpers/lotOccupancyDB/addLotOccupancy.js";
|
|||
import { addLotOccupancyOccupant } from "../helpers/lotOccupancyDB/addLotOccupancyOccupant.js";
|
||||
import { addLotOccupancyComment } from "../helpers/lotOccupancyDB/addLotOccupancyComment.js";
|
||||
import { addOrUpdateLotOccupancyField } from "../helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.js";
|
||||
import { getLot } from "../helpers/lotOccupancyDB/getLot.js";
|
||||
import { getLots } from "../helpers/lotOccupancyDB/getLots.js";
|
||||
import { getLotOccupancies } from "../helpers/lotOccupancyDB/getLotOccupancies.js";
|
||||
import { addLotOccupancyFee } from "../helpers/lotOccupancyDB/addLotOccupancyFee.js";
|
||||
import { addLotOccupancyTransaction } from "../helpers/lotOccupancyDB/addLotOccupancyTransaction.js";
|
||||
const user = {
|
||||
user: {
|
||||
userName: "import.unix",
|
||||
|
|
@ -22,6 +27,8 @@ const user = {
|
|||
};
|
||||
function purgeTables() {
|
||||
const database = sqlite(databasePath);
|
||||
database.prepare("delete from LotOccupancyTransactions").run();
|
||||
database.prepare("delete from LotOccupancyFees").run();
|
||||
database.prepare("delete from LotOccupancyFields").run();
|
||||
database.prepare("delete from LotOccupancyComments").run();
|
||||
database.prepare("delete from LotOccupancyOccupants").run();
|
||||
|
|
@ -66,17 +73,17 @@ const cemeteryToMapName = {
|
|||
"WK": "West Korah"
|
||||
};
|
||||
const mapCache = new Map();
|
||||
function getMap(masterRow) {
|
||||
const mapCacheKey = masterRow.CM_CEMETERY;
|
||||
function getMap(dataRow) {
|
||||
const mapCacheKey = dataRow.cemetery;
|
||||
if (mapCache.has(mapCacheKey)) {
|
||||
return mapCache.get(mapCacheKey);
|
||||
}
|
||||
let map = getMapByMapDescription(mapCacheKey);
|
||||
if (!map) {
|
||||
console.log("Creating map: " + masterRow.CM_CEMETERY);
|
||||
console.log("Creating map: " + dataRow.cemetery);
|
||||
const mapId = addMap({
|
||||
mapName: cemeteryToMapName[masterRow.CM_CEMETERY] || masterRow.CM_CEMETERY,
|
||||
mapDescription: masterRow.CM_CEMETERY,
|
||||
mapName: cemeteryToMapName[dataRow.cemetery] || dataRow.cemetery,
|
||||
mapDescription: dataRow.cemetery,
|
||||
mapSVG: "",
|
||||
mapLatitude: "",
|
||||
mapLongitude: "",
|
||||
|
|
@ -92,21 +99,72 @@ function getMap(masterRow) {
|
|||
mapCache.set(mapCacheKey, map);
|
||||
return map;
|
||||
}
|
||||
function importFromCSV() {
|
||||
const feeCache = new Map();
|
||||
function getFeeIdByFeeDescription(feeDescription) {
|
||||
if (feeCache.keys.length === 0) {
|
||||
const database = sqlite(databasePath, {
|
||||
readonly: true
|
||||
});
|
||||
const records = database
|
||||
.prepare("select feeId, feeDescription from Fees" +
|
||||
" where feeDescription like 'CMPP_FEE_%'")
|
||||
.all();
|
||||
for (const record of records) {
|
||||
feeCache.set(record.feeDescription, record.feeId);
|
||||
}
|
||||
database.close();
|
||||
}
|
||||
return feeCache.get(feeDescription);
|
||||
}
|
||||
function buildLotName(lotNamePieces) {
|
||||
return lotNamePieces.cemetery + "-" +
|
||||
(lotNamePieces.block === "" ? "" : lotNamePieces.block + "-") +
|
||||
(lotNamePieces.range1 === "0" && lotNamePieces.range2 === "" ?
|
||||
"" :
|
||||
(lotNamePieces.range1 + lotNamePieces.range2) + "-") +
|
||||
(lotNamePieces.lot1 === "0" && lotNamePieces.lot2 === "" ?
|
||||
"" :
|
||||
lotNamePieces.lot1 + lotNamePieces.lot2 + "-") +
|
||||
lotNamePieces.grave1 + lotNamePieces.grave2 + "-" +
|
||||
lotNamePieces.interment;
|
||||
}
|
||||
const casketLotType = cacheFunctions.getLotTypesByLotType("Casket Grave");
|
||||
const columbariumLotType = cacheFunctions.getLotTypesByLotType("Columbarium");
|
||||
const crematoriumLotType = cacheFunctions.getLotTypesByLotType("Crematorium");
|
||||
const mausoleumLotType = cacheFunctions.getLotTypesByLotType("Mausoleum");
|
||||
const nicheWallLotType = cacheFunctions.getLotTypesByLotType("Niche Wall");
|
||||
const urnGardenLotType = cacheFunctions.getLotTypesByLotType("Urn Garden");
|
||||
function getLotType(dataRow) {
|
||||
switch (dataRow.cemetery) {
|
||||
case "00": {
|
||||
return crematoriumLotType;
|
||||
}
|
||||
case "GC":
|
||||
case "HC": {
|
||||
return columbariumLotType;
|
||||
}
|
||||
case "MA": {
|
||||
return mausoleumLotType;
|
||||
}
|
||||
case "NW": {
|
||||
return nicheWallLotType;
|
||||
}
|
||||
case "UG": {
|
||||
return urnGardenLotType;
|
||||
}
|
||||
}
|
||||
return casketLotType;
|
||||
}
|
||||
const availableLotStatus = cacheFunctions.getLotStatusByLotStatus("Available");
|
||||
const reservedLotStatus = cacheFunctions.getLotStatusByLotStatus("Reserved");
|
||||
const takenLotStatus = cacheFunctions.getLotStatusByLotStatus("Taken");
|
||||
const preneedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Preneed");
|
||||
const deceasedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Interment");
|
||||
const preneedOwnerLotOccupantType = cacheFunctions.getLotOccupantTypesByLotOccupantType("Preneed Owner");
|
||||
const deceasedLotOccupantType = cacheFunctions.getLotOccupantTypesByLotOccupantType("Deceased");
|
||||
const arrangerLotOccupantType = cacheFunctions.getLotOccupantTypesByLotOccupantType("Arranger");
|
||||
function importFromMasterCSV() {
|
||||
let masterRow;
|
||||
const casketLotType = cacheFunctions.getLotTypesByLotType("Casket Grave");
|
||||
const columbariumLotType = cacheFunctions.getLotTypesByLotType("Columbarium");
|
||||
const crematoriumLotType = cacheFunctions.getLotTypesByLotType("Crematorium");
|
||||
const mausoleumLotType = cacheFunctions.getLotTypesByLotType("Mausoleum");
|
||||
const nicheWallLotType = cacheFunctions.getLotTypesByLotType("Niche Wall");
|
||||
const urnGardenLotType = cacheFunctions.getLotTypesByLotType("Urn Garden");
|
||||
const availableLotStatus = cacheFunctions.getLotStatusByLotStatus("Available");
|
||||
const preneedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Preneed");
|
||||
const preneedOwnerLotOccupantType = cacheFunctions.getLotOccupantTypesByLotOccupantType("Preneed Owner");
|
||||
const reservedLotStatus = cacheFunctions.getLotStatusByLotStatus("Reserved");
|
||||
const deceasedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Interment");
|
||||
const deceasedLotOccupantType = cacheFunctions.getLotOccupantTypesByLotOccupantType("Deceased");
|
||||
const takenLotStatus = cacheFunctions.getLotStatusByLotStatus("Taken");
|
||||
const rawData = fs.readFileSync("./temp/CMMASTER.csv").toString();
|
||||
const cmmaster = papa.parse(rawData, {
|
||||
delimiter: ",",
|
||||
|
|
@ -118,41 +176,23 @@ function importFromCSV() {
|
|||
}
|
||||
try {
|
||||
for (masterRow of cmmaster.data) {
|
||||
const map = getMap(masterRow);
|
||||
const lotName = masterRow.CM_CEMETERY + "-" +
|
||||
(masterRow.CM_BLOCK === "" ? "" : masterRow.CM_BLOCK + "-") +
|
||||
(masterRow.CM_RANGE1 === "0" && masterRow.CM_RANGE2 === "" ?
|
||||
"" :
|
||||
(masterRow.CM_RANGE1 + masterRow.CM_RANGE2) + "-") +
|
||||
(masterRow.CM_LOT1 === "0" && masterRow.CM_LOT2 === "" ?
|
||||
"" :
|
||||
masterRow.CM_LOT1 + masterRow.CM_LOT2 + "-") +
|
||||
masterRow.CM_GRAVE1 + masterRow.CM_GRAVE2 + "-" +
|
||||
masterRow.CM_INTERMENT;
|
||||
let lotType = casketLotType;
|
||||
switch (masterRow.CM_CEMETERY) {
|
||||
case "00": {
|
||||
lotType = crematoriumLotType;
|
||||
break;
|
||||
}
|
||||
case "GC":
|
||||
case "HC": {
|
||||
lotType = columbariumLotType;
|
||||
break;
|
||||
}
|
||||
case "MA": {
|
||||
lotType = mausoleumLotType;
|
||||
break;
|
||||
}
|
||||
case "NW": {
|
||||
lotType = nicheWallLotType;
|
||||
break;
|
||||
}
|
||||
case "UG": {
|
||||
lotType = urnGardenLotType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const map = getMap({
|
||||
cemetery: masterRow.CM_CEMETERY
|
||||
});
|
||||
const lotName = buildLotName({
|
||||
cemetery: masterRow.CM_CEMETERY,
|
||||
block: masterRow.CM_BLOCK,
|
||||
range1: masterRow.CM_RANGE1,
|
||||
range2: masterRow.CM_RANGE2,
|
||||
lot1: masterRow.CM_LOT1,
|
||||
lot2: masterRow.CM_LOT2,
|
||||
grave1: masterRow.CM_GRAVE1,
|
||||
grave2: masterRow.CM_GRAVE2,
|
||||
interment: masterRow.CM_INTERMENT
|
||||
});
|
||||
const lotType = getLotType({
|
||||
cemetery: masterRow.CM_CEMETERY
|
||||
});
|
||||
const lotId = addLot({
|
||||
lotName: lotName,
|
||||
lotTypeId: lotType.lotTypeId,
|
||||
|
|
@ -338,6 +378,229 @@ function importFromCSV() {
|
|||
console.log(masterRow);
|
||||
}
|
||||
}
|
||||
function importFromPrepaidCSV() {
|
||||
let prepaidRow;
|
||||
const rawData = fs.readFileSync("./temp/CMPRPAID.csv").toString();
|
||||
const cmprpaid = papa.parse(rawData, {
|
||||
delimiter: ",",
|
||||
header: true,
|
||||
skipEmptyLines: true
|
||||
});
|
||||
for (const parseError of cmprpaid.errors) {
|
||||
console.log(parseError);
|
||||
}
|
||||
try {
|
||||
for (prepaidRow of cmprpaid.data) {
|
||||
if (!prepaidRow.CMPP_PREPAID_FOR_NAME) {
|
||||
continue;
|
||||
}
|
||||
let lot;
|
||||
if (prepaidRow.CMPP_CEMETERY) {
|
||||
const map = getMap({
|
||||
cemetery: prepaidRow.CMPP_CEMETERY
|
||||
});
|
||||
const lotName = buildLotName({
|
||||
cemetery: prepaidRow.CMPP_CEMETERY,
|
||||
block: prepaidRow.CMPP_BLOCK,
|
||||
range1: prepaidRow.CMPP_RANGE1,
|
||||
range2: prepaidRow.CMPP_RANGE2,
|
||||
lot1: prepaidRow.CMPP_LOT1,
|
||||
lot2: prepaidRow.CMPP_LOT2,
|
||||
grave1: prepaidRow.CMPP_GRAVE1,
|
||||
grave2: prepaidRow.CMPP_GRAVE2,
|
||||
interment: prepaidRow.CMPP_INTERMENT
|
||||
});
|
||||
const possibleLots = getLots({
|
||||
mapId: map.mapId,
|
||||
lotName
|
||||
});
|
||||
if (possibleLots.lots.length > 0) {
|
||||
lot = possibleLots.lots[0];
|
||||
}
|
||||
else {
|
||||
const lotType = getLotType({
|
||||
cemetery: prepaidRow.CMPP_CEMETERY
|
||||
});
|
||||
const lotId = addLot({
|
||||
lotName: lotName,
|
||||
lotTypeId: lotType.lotTypeId,
|
||||
lotStatusId: reservedLotStatus.lotStatusId,
|
||||
mapId: map.mapId,
|
||||
mapKey: lotName,
|
||||
lotLatitude: "",
|
||||
lotLongitude: ""
|
||||
}, user);
|
||||
lot = getLot(lotId);
|
||||
}
|
||||
}
|
||||
if (lot && lot.lotStatusId === availableLotStatus.lotStatusId) {
|
||||
updateLotStatus(lot.lotId, reservedLotStatus.lotStatusId, user);
|
||||
}
|
||||
const occupancyStartDateString = formatDateString(prepaidRow.CMPP_PURCH_YR, prepaidRow.CMPP_PURCH_MON, prepaidRow.CMPP_PURCH_DAY);
|
||||
let lotOccupancyId;
|
||||
if (lot) {
|
||||
const possibleLotOccupancies = getLotOccupancies({
|
||||
lotId: lot.lotId,
|
||||
occupancyTypeId: preneedOccupancyType.occupancyTypeId,
|
||||
occupantName: prepaidRow.CMPP_PREPAID_FOR_NAME,
|
||||
occupancyStartDateString
|
||||
}, {
|
||||
includeOccupants: false,
|
||||
limit: -1,
|
||||
offset: 0
|
||||
});
|
||||
if (possibleLotOccupancies.lotOccupancies.length > 0) {
|
||||
lotOccupancyId = possibleLotOccupancies.lotOccupancies[0].lotOccupancyId;
|
||||
}
|
||||
}
|
||||
if (!lotOccupancyId) {
|
||||
lotOccupancyId = addLotOccupancy({
|
||||
lotId: lot ? lot.lotId : "",
|
||||
occupancyTypeId: preneedOccupancyType.occupancyTypeId,
|
||||
occupancyStartDateString,
|
||||
occupancyEndDateString: ""
|
||||
}, user);
|
||||
}
|
||||
addLotOccupancyOccupant({
|
||||
lotOccupancyId,
|
||||
lotOccupantTypeId: preneedOwnerLotOccupantType.lotOccupantTypeId,
|
||||
occupantName: prepaidRow.CMPP_PREPAID_FOR_NAME,
|
||||
occupantAddress1: prepaidRow.CMPP_ADDRESS,
|
||||
occupantAddress2: "",
|
||||
occupantCity: prepaidRow.CMPP_CITY,
|
||||
occupantProvince: prepaidRow.CMPP_PROV.slice(0, 2),
|
||||
occupantPostalCode: prepaidRow.CMPP_POSTAL1 + " " + prepaidRow.CMPP_POSTAL2,
|
||||
occupantPhoneNumber: ""
|
||||
}, user);
|
||||
if (prepaidRow.CMPP_ARRANGED_BY_NAME) {
|
||||
addLotOccupancyOccupant({
|
||||
lotOccupancyId,
|
||||
lotOccupantTypeId: arrangerLotOccupantType.lotOccupantTypeId,
|
||||
occupantName: prepaidRow.CMPP_ARRANGED_BY_NAME,
|
||||
occupantAddress1: "",
|
||||
occupantAddress2: "",
|
||||
occupantCity: "",
|
||||
occupantProvince: "",
|
||||
occupantPostalCode: "",
|
||||
occupantPhoneNumber: ""
|
||||
}, user);
|
||||
}
|
||||
if (prepaidRow.CMPP_FEE_GRAV_SD !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_GRAV_SD"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_GRAV_SD,
|
||||
taxAmount: prepaidRow.CMPP_GST_GRAV_SD
|
||||
}, user);
|
||||
}
|
||||
if (prepaidRow.CMPP_FEE_GRAV_DD !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_GRAV_DD"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_GRAV_DD,
|
||||
taxAmount: prepaidRow.CMPP_GST_GRAV_DD
|
||||
}, user);
|
||||
}
|
||||
if (prepaidRow.CMPP_FEE_CHAP_SD !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_CHAP_SD"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_CHAP_SD,
|
||||
taxAmount: prepaidRow.CMPP_GST_CHAP_SD
|
||||
}, user);
|
||||
}
|
||||
if (prepaidRow.CMPP_FEE_CHAP_DD !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_CHAP_DD"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_CHAP_DD,
|
||||
taxAmount: prepaidRow.CMPP_GST_CHAP_DD
|
||||
}, user);
|
||||
}
|
||||
if (prepaidRow.CMPP_FEE_ENTOMBMENT !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_ENTOMBMENT"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_ENTOMBMENT,
|
||||
taxAmount: prepaidRow.CMPP_GST_ENTOMBMENT
|
||||
}, user);
|
||||
}
|
||||
if (prepaidRow.CMPP_FEE_CREM !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_CREM"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_CREM,
|
||||
taxAmount: prepaidRow.CMPP_GST_CREM
|
||||
}, user);
|
||||
}
|
||||
if (prepaidRow.CMPP_FEE_NICHE !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_NICHE"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_NICHE,
|
||||
taxAmount: prepaidRow.CMPP_GST_NICHE
|
||||
}, user);
|
||||
}
|
||||
if (prepaidRow.CMPP_FEE_DISINTERMENT !== "0.0" && prepaidRow.CMPP_FEE_DISINTERMENT !== "20202.02") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_DISINTERMENT"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_DISINTERMENT,
|
||||
taxAmount: prepaidRow.CMPP_GST_DISINTERMENT
|
||||
}, user);
|
||||
}
|
||||
const transactionAmount = Number.parseFloat(prepaidRow.CMPP_FEE_GRAV_SD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_GRAV_SD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_GRAV_DD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_GRAV_DD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_CHAP_SD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_CHAP_SD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_CHAP_DD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_CHAP_DD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_ENTOMBMENT) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_ENTOMBMENT) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_CREM) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_CREM) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_NICHE) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_NICHE) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_DISINTERMENT === "20202.02" ? "0" : prepaidRow.CMPP_FEE_DISINTERMENT) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_DISINTERMENT === "20202.02" ? "0" : prepaidRow.CMPP_GST_DISINTERMENT);
|
||||
addLotOccupancyTransaction({
|
||||
lotOccupancyId,
|
||||
externalReceiptNumber: prepaidRow.CMPP_ORDER_NO,
|
||||
transactionAmount,
|
||||
transactionDateString: occupancyStartDateString,
|
||||
transactionNote: ""
|
||||
}, user);
|
||||
if (prepaidRow.CMPP_REMARK1) {
|
||||
addLotOccupancyComment({
|
||||
lotOccupancyId,
|
||||
lotOccupancyCommentDateString: occupancyStartDateString,
|
||||
lotOccupancyComment: prepaidRow.CMPP_REMARK1
|
||||
}, user);
|
||||
}
|
||||
if (prepaidRow.CMPP_REMARK2) {
|
||||
addLotOccupancyComment({
|
||||
lotOccupancyId,
|
||||
lotOccupancyCommentDateString: occupancyStartDateString,
|
||||
lotOccupancyComment: prepaidRow.CMPP_REMARK2
|
||||
}, user);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
console.log(prepaidRow);
|
||||
}
|
||||
}
|
||||
purgeTables();
|
||||
purgeConfigTables();
|
||||
importFromCSV();
|
||||
importFromMasterCSV();
|
||||
importFromPrepaidCSV();
|
||||
|
|
|
|||
|
|
@ -40,6 +40,26 @@ import {
|
|||
addOrUpdateLotOccupancyField
|
||||
} from "../helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.js";
|
||||
|
||||
import {
|
||||
getLot
|
||||
} from "../helpers/lotOccupancyDB/getLot.js";
|
||||
|
||||
import {
|
||||
getLots
|
||||
} from "../helpers/lotOccupancyDB/getLots.js";
|
||||
|
||||
import {
|
||||
getLotOccupancies
|
||||
} from "../helpers/lotOccupancyDB/getLotOccupancies.js";
|
||||
|
||||
import {
|
||||
addLotOccupancyFee
|
||||
} from "../helpers/lotOccupancyDB/addLotOccupancyFee.js";
|
||||
|
||||
import {
|
||||
addLotOccupancyTransaction
|
||||
} from "../helpers/lotOccupancyDB/addLotOccupancyTransaction.js";
|
||||
|
||||
import type * as recordTypes from "../types/recordTypes";
|
||||
|
||||
|
||||
|
|
@ -51,7 +71,7 @@ interface MasterRecord {
|
|||
CM_RANGE2: string;
|
||||
CM_LOT1: string;
|
||||
CM_LOT2: string;
|
||||
CM_GRAVE1: number;
|
||||
CM_GRAVE1: string;
|
||||
CM_GRAVE2: string;
|
||||
CM_INTERMENT: string;
|
||||
CM_PRENEED_OWNER: string;
|
||||
|
|
@ -93,6 +113,51 @@ interface MasterRecord {
|
|||
}
|
||||
|
||||
|
||||
interface PrepaidRecord {
|
||||
CMPP_SYSREC: string;
|
||||
CMPP_PREPAID_FOR_NAME: string;
|
||||
CMPP_PREPAID_FOR_SEQ: string;
|
||||
CMPP_ADDRESS: string;
|
||||
CMPP_CITY: string;
|
||||
CMPP_PROV: string;
|
||||
CMPP_POSTAL1: string;
|
||||
CMPP_POSTAL2: string;
|
||||
CMPP_ARRANGED_BY_NAME: string;
|
||||
CMPP_ARRANGED_BY_SEQ: string;
|
||||
CMPP_CEMETERY: string;
|
||||
CMPP_BLOCK: string;
|
||||
CMPP_RANGE1: string;
|
||||
CMPP_RANGE2: string;
|
||||
CMPP_LOT1: string;
|
||||
CMPP_LOT2: string;
|
||||
CMPP_GRAVE1: string;
|
||||
CMPP_GRAVE2: string;
|
||||
CMPP_INTERMENT: string;
|
||||
CMPP_ORDER_NO: string;
|
||||
CMPP_PURCH_YR: string;
|
||||
CMPP_PURCH_MON: string;
|
||||
CMPP_PURCH_DAY: string;
|
||||
CMPP_FEE_GRAV_SD: string;
|
||||
CMPP_GST_GRAV_SD: string;
|
||||
CMPP_FEE_GRAV_DD: string;
|
||||
CMPP_GST_GRAV_DD: string;
|
||||
CMPP_FEE_CHAP_SD: string;
|
||||
CMPP_GST_CHAP_SD: string;
|
||||
CMPP_FEE_CHAP_DD: string;
|
||||
CMPP_GST_CHAP_DD: string;
|
||||
CMPP_FEE_ENTOMBMENT: string;
|
||||
CMPP_GST_ENTOMBMENT: string;
|
||||
CMPP_FEE_CREM: string;
|
||||
CMPP_GST_CREM: string;
|
||||
CMPP_FEE_NICHE: string;
|
||||
CMPP_GST_NICHE: string;
|
||||
CMPP_FEE_DISINTERMENT: string;
|
||||
CMPP_GST_DISINTERMENT: string;
|
||||
CMPP_REMARK1: string;
|
||||
CMPP_REMARK2: string;
|
||||
}
|
||||
|
||||
|
||||
const user: recordTypes.PartialSession = {
|
||||
user: {
|
||||
userName: "import.unix",
|
||||
|
|
@ -106,6 +171,8 @@ const user: recordTypes.PartialSession = {
|
|||
|
||||
function purgeTables() {
|
||||
const database = sqlite(databasePath);
|
||||
database.prepare("delete from LotOccupancyTransactions").run();
|
||||
database.prepare("delete from LotOccupancyFees").run();
|
||||
database.prepare("delete from LotOccupancyFields").run();
|
||||
database.prepare("delete from LotOccupancyComments").run();
|
||||
database.prepare("delete from LotOccupancyOccupants").run();
|
||||
|
|
@ -140,6 +207,7 @@ function getMapByMapDescription(mapDescription: string) {
|
|||
return map;
|
||||
}
|
||||
|
||||
|
||||
function formatDateString(year: string, month: string, day: string) {
|
||||
|
||||
return ("0000" + year).slice(-4) + "-" +
|
||||
|
|
@ -165,9 +233,11 @@ const cemeteryToMapName = {
|
|||
const mapCache: Map < string, recordTypes.Map > = new Map();
|
||||
|
||||
|
||||
function getMap(masterRow: MasterRecord): recordTypes.Map {
|
||||
function getMap(dataRow: {
|
||||
cemetery: string;
|
||||
}): recordTypes.Map {
|
||||
|
||||
const mapCacheKey = masterRow.CM_CEMETERY;
|
||||
const mapCacheKey = dataRow.cemetery;
|
||||
|
||||
/*
|
||||
if (masterRow.CM_CEMETERY === "HS" &&
|
||||
|
|
@ -184,11 +254,11 @@ function getMap(masterRow: MasterRecord): recordTypes.Map {
|
|||
|
||||
if (!map) {
|
||||
|
||||
console.log("Creating map: " + masterRow.CM_CEMETERY);
|
||||
console.log("Creating map: " + dataRow.cemetery);
|
||||
|
||||
const mapId = addMap({
|
||||
mapName: cemeteryToMapName[masterRow.CM_CEMETERY] || masterRow.CM_CEMETERY,
|
||||
mapDescription: masterRow.CM_CEMETERY,
|
||||
mapName: cemeteryToMapName[dataRow.cemetery] || dataRow.cemetery,
|
||||
mapDescription: dataRow.cemetery,
|
||||
mapSVG: "",
|
||||
mapLatitude: "",
|
||||
mapLongitude: "",
|
||||
|
|
@ -209,28 +279,110 @@ function getMap(masterRow: MasterRecord): recordTypes.Map {
|
|||
}
|
||||
|
||||
|
||||
function importFromCSV() {
|
||||
const feeCache: Map < string, number > = new Map();
|
||||
|
||||
|
||||
function getFeeIdByFeeDescription(feeDescription: string) {
|
||||
|
||||
if (feeCache.keys.length === 0) {
|
||||
|
||||
const database = sqlite(databasePath, {
|
||||
readonly: true
|
||||
});
|
||||
|
||||
const records: {
|
||||
feeId: number;feeDescription: string
|
||||
} [] = database
|
||||
.prepare("select feeId, feeDescription from Fees" +
|
||||
" where feeDescription like 'CMPP_FEE_%'")
|
||||
.all();
|
||||
|
||||
for (const record of records) {
|
||||
feeCache.set(record.feeDescription, record.feeId);
|
||||
}
|
||||
|
||||
database.close();
|
||||
}
|
||||
|
||||
return feeCache.get(feeDescription);
|
||||
}
|
||||
|
||||
|
||||
function buildLotName(lotNamePieces: {
|
||||
cemetery: string;
|
||||
block: string;
|
||||
range1: string;
|
||||
range2: string;
|
||||
lot1: string;
|
||||
lot2: string;
|
||||
grave1: string;
|
||||
grave2: string;
|
||||
interment: string;
|
||||
}) {
|
||||
return lotNamePieces.cemetery + "-" +
|
||||
(lotNamePieces.block === "" ? "" : lotNamePieces.block + "-") +
|
||||
(lotNamePieces.range1 === "0" && lotNamePieces.range2 === "" ?
|
||||
"" :
|
||||
(lotNamePieces.range1 + lotNamePieces.range2) + "-") +
|
||||
(lotNamePieces.lot1 === "0" && lotNamePieces.lot2 === "" ?
|
||||
"" :
|
||||
lotNamePieces.lot1 + lotNamePieces.lot2 + "-") +
|
||||
lotNamePieces.grave1 + lotNamePieces.grave2 + "-" +
|
||||
lotNamePieces.interment;
|
||||
}
|
||||
|
||||
|
||||
const casketLotType = cacheFunctions.getLotTypesByLotType("Casket Grave");
|
||||
const columbariumLotType = cacheFunctions.getLotTypesByLotType("Columbarium");
|
||||
const crematoriumLotType = cacheFunctions.getLotTypesByLotType("Crematorium");
|
||||
const mausoleumLotType = cacheFunctions.getLotTypesByLotType("Mausoleum");
|
||||
const nicheWallLotType = cacheFunctions.getLotTypesByLotType("Niche Wall");
|
||||
const urnGardenLotType = cacheFunctions.getLotTypesByLotType("Urn Garden");
|
||||
|
||||
|
||||
function getLotType(dataRow: {
|
||||
cemetery: string;
|
||||
}) {
|
||||
|
||||
switch (dataRow.cemetery) {
|
||||
case "00": {
|
||||
return crematoriumLotType;
|
||||
}
|
||||
case "GC":
|
||||
case "HC": {
|
||||
return columbariumLotType;
|
||||
}
|
||||
case "MA": {
|
||||
return mausoleumLotType;
|
||||
}
|
||||
case "NW": {
|
||||
return nicheWallLotType;
|
||||
}
|
||||
case "UG": {
|
||||
return urnGardenLotType;
|
||||
}
|
||||
}
|
||||
|
||||
return casketLotType;
|
||||
}
|
||||
|
||||
|
||||
const availableLotStatus = cacheFunctions.getLotStatusByLotStatus("Available");
|
||||
const reservedLotStatus = cacheFunctions.getLotStatusByLotStatus("Reserved");
|
||||
const takenLotStatus = cacheFunctions.getLotStatusByLotStatus("Taken");
|
||||
|
||||
const preneedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Preneed");
|
||||
const deceasedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Interment");
|
||||
|
||||
const preneedOwnerLotOccupantType = cacheFunctions.getLotOccupantTypesByLotOccupantType("Preneed Owner");
|
||||
const deceasedLotOccupantType = cacheFunctions.getLotOccupantTypesByLotOccupantType("Deceased");
|
||||
const arrangerLotOccupantType = cacheFunctions.getLotOccupantTypesByLotOccupantType("Arranger");
|
||||
|
||||
|
||||
function importFromMasterCSV() {
|
||||
|
||||
let masterRow: MasterRecord;
|
||||
|
||||
// Load cached values
|
||||
const casketLotType = cacheFunctions.getLotTypesByLotType("Casket Grave");
|
||||
const columbariumLotType = cacheFunctions.getLotTypesByLotType("Columbarium");
|
||||
const crematoriumLotType = cacheFunctions.getLotTypesByLotType("Crematorium");
|
||||
const mausoleumLotType = cacheFunctions.getLotTypesByLotType("Mausoleum");
|
||||
const nicheWallLotType = cacheFunctions.getLotTypesByLotType("Niche Wall");
|
||||
const urnGardenLotType = cacheFunctions.getLotTypesByLotType("Urn Garden");
|
||||
|
||||
const availableLotStatus = cacheFunctions.getLotStatusByLotStatus("Available");
|
||||
|
||||
const preneedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Preneed");
|
||||
const preneedOwnerLotOccupantType = cacheFunctions.getLotOccupantTypesByLotOccupantType("Preneed Owner");
|
||||
const reservedLotStatus = cacheFunctions.getLotStatusByLotStatus("Reserved");
|
||||
|
||||
const deceasedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Interment");
|
||||
const deceasedLotOccupantType = cacheFunctions.getLotOccupantTypesByLotOccupantType("Deceased");
|
||||
const takenLotStatus = cacheFunctions.getLotStatusByLotStatus("Taken");
|
||||
|
||||
const rawData = fs.readFileSync("./temp/CMMASTER.csv").toString();
|
||||
|
||||
const cmmaster: papa.ParseResult < MasterRecord > = papa.parse(rawData, {
|
||||
|
|
@ -246,44 +398,25 @@ function importFromCSV() {
|
|||
try {
|
||||
for (masterRow of cmmaster.data) {
|
||||
|
||||
const map = getMap(masterRow);
|
||||
const map = getMap({
|
||||
cemetery: masterRow.CM_CEMETERY
|
||||
});
|
||||
|
||||
const lotName = masterRow.CM_CEMETERY + "-" +
|
||||
(masterRow.CM_BLOCK === "" ? "" : masterRow.CM_BLOCK + "-") +
|
||||
(masterRow.CM_RANGE1 === "0" && masterRow.CM_RANGE2 === "" ?
|
||||
"" :
|
||||
(masterRow.CM_RANGE1 + masterRow.CM_RANGE2) + "-") +
|
||||
(masterRow.CM_LOT1 === "0" && masterRow.CM_LOT2 === "" ?
|
||||
"" :
|
||||
masterRow.CM_LOT1 + masterRow.CM_LOT2 + "-") +
|
||||
masterRow.CM_GRAVE1 + masterRow.CM_GRAVE2 + "-" +
|
||||
masterRow.CM_INTERMENT;
|
||||
const lotName = buildLotName({
|
||||
cemetery: masterRow.CM_CEMETERY,
|
||||
block: masterRow.CM_BLOCK,
|
||||
range1: masterRow.CM_RANGE1,
|
||||
range2: masterRow.CM_RANGE2,
|
||||
lot1: masterRow.CM_LOT1,
|
||||
lot2: masterRow.CM_LOT2,
|
||||
grave1: masterRow.CM_GRAVE1,
|
||||
grave2: masterRow.CM_GRAVE2,
|
||||
interment: masterRow.CM_INTERMENT
|
||||
});
|
||||
|
||||
let lotType = casketLotType;
|
||||
|
||||
switch (masterRow.CM_CEMETERY) {
|
||||
case "00": {
|
||||
lotType = crematoriumLotType;
|
||||
break;
|
||||
}
|
||||
case "GC":
|
||||
case "HC": {
|
||||
lotType = columbariumLotType;
|
||||
break;
|
||||
}
|
||||
case "MA": {
|
||||
lotType = mausoleumLotType;
|
||||
break;
|
||||
}
|
||||
case "NW": {
|
||||
lotType = nicheWallLotType;
|
||||
break;
|
||||
}
|
||||
case "UG": {
|
||||
lotType = urnGardenLotType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const lotType = getLotType({
|
||||
cemetery: masterRow.CM_CEMETERY
|
||||
});
|
||||
|
||||
const lotId = addLot({
|
||||
lotName: lotName,
|
||||
|
|
@ -529,6 +662,270 @@ function importFromCSV() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function importFromPrepaidCSV() {
|
||||
|
||||
let prepaidRow: PrepaidRecord;
|
||||
|
||||
const rawData = fs.readFileSync("./temp/CMPRPAID.csv").toString();
|
||||
|
||||
const cmprpaid: papa.ParseResult < PrepaidRecord > = papa.parse(rawData, {
|
||||
delimiter: ",",
|
||||
header: true,
|
||||
skipEmptyLines: true
|
||||
});
|
||||
|
||||
for (const parseError of cmprpaid.errors) {
|
||||
console.log(parseError);
|
||||
}
|
||||
|
||||
try {
|
||||
for (prepaidRow of cmprpaid.data) {
|
||||
|
||||
if (!prepaidRow.CMPP_PREPAID_FOR_NAME) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let lot: recordTypes.Lot;
|
||||
|
||||
if (prepaidRow.CMPP_CEMETERY) {
|
||||
|
||||
const map = getMap({
|
||||
cemetery: prepaidRow.CMPP_CEMETERY
|
||||
});
|
||||
|
||||
const lotName = buildLotName({
|
||||
cemetery: prepaidRow.CMPP_CEMETERY,
|
||||
block: prepaidRow.CMPP_BLOCK,
|
||||
range1: prepaidRow.CMPP_RANGE1,
|
||||
range2: prepaidRow.CMPP_RANGE2,
|
||||
lot1: prepaidRow.CMPP_LOT1,
|
||||
lot2: prepaidRow.CMPP_LOT2,
|
||||
grave1: prepaidRow.CMPP_GRAVE1,
|
||||
grave2: prepaidRow.CMPP_GRAVE2,
|
||||
interment: prepaidRow.CMPP_INTERMENT
|
||||
});
|
||||
|
||||
const possibleLots = getLots({
|
||||
mapId: map.mapId,
|
||||
lotName
|
||||
});
|
||||
|
||||
if (possibleLots.lots.length > 0) {
|
||||
lot = possibleLots.lots[0];
|
||||
} else {
|
||||
|
||||
const lotType = getLotType({
|
||||
cemetery: prepaidRow.CMPP_CEMETERY
|
||||
});
|
||||
|
||||
const lotId = addLot({
|
||||
lotName: lotName,
|
||||
lotTypeId: lotType.lotTypeId,
|
||||
lotStatusId: reservedLotStatus.lotStatusId,
|
||||
mapId: map.mapId,
|
||||
mapKey: lotName,
|
||||
lotLatitude: "",
|
||||
lotLongitude: ""
|
||||
}, user);
|
||||
|
||||
lot = getLot(lotId);
|
||||
}
|
||||
}
|
||||
|
||||
if (lot && lot.lotStatusId === availableLotStatus.lotStatusId) {
|
||||
updateLotStatus(lot.lotId, reservedLotStatus.lotStatusId, user);
|
||||
}
|
||||
|
||||
const occupancyStartDateString = formatDateString(prepaidRow.CMPP_PURCH_YR,
|
||||
prepaidRow.CMPP_PURCH_MON,
|
||||
prepaidRow.CMPP_PURCH_DAY);
|
||||
|
||||
let lotOccupancyId: number;
|
||||
|
||||
if (lot) {
|
||||
const possibleLotOccupancies = getLotOccupancies({
|
||||
lotId: lot.lotId,
|
||||
occupancyTypeId: preneedOccupancyType.occupancyTypeId,
|
||||
occupantName: prepaidRow.CMPP_PREPAID_FOR_NAME,
|
||||
occupancyStartDateString
|
||||
}, {
|
||||
includeOccupants: false,
|
||||
limit: -1,
|
||||
offset: 0
|
||||
});
|
||||
|
||||
if (possibleLotOccupancies.lotOccupancies.length > 0) {
|
||||
lotOccupancyId = possibleLotOccupancies.lotOccupancies[0].lotOccupancyId;
|
||||
}
|
||||
}
|
||||
|
||||
if (!lotOccupancyId) {
|
||||
lotOccupancyId = addLotOccupancy({
|
||||
lotId: lot ? lot.lotId : "",
|
||||
occupancyTypeId: preneedOccupancyType.occupancyTypeId,
|
||||
occupancyStartDateString,
|
||||
occupancyEndDateString: ""
|
||||
}, user);
|
||||
}
|
||||
|
||||
addLotOccupancyOccupant({
|
||||
lotOccupancyId,
|
||||
lotOccupantTypeId: preneedOwnerLotOccupantType.lotOccupantTypeId,
|
||||
occupantName: prepaidRow.CMPP_PREPAID_FOR_NAME,
|
||||
occupantAddress1: prepaidRow.CMPP_ADDRESS,
|
||||
occupantAddress2: "",
|
||||
occupantCity: prepaidRow.CMPP_CITY,
|
||||
occupantProvince: prepaidRow.CMPP_PROV.slice(0, 2),
|
||||
occupantPostalCode: prepaidRow.CMPP_POSTAL1 + " " + prepaidRow.CMPP_POSTAL2,
|
||||
occupantPhoneNumber: ""
|
||||
}, user);
|
||||
|
||||
if (prepaidRow.CMPP_ARRANGED_BY_NAME) {
|
||||
addLotOccupancyOccupant({
|
||||
lotOccupancyId,
|
||||
lotOccupantTypeId: arrangerLotOccupantType.lotOccupantTypeId,
|
||||
occupantName: prepaidRow.CMPP_ARRANGED_BY_NAME,
|
||||
occupantAddress1: "",
|
||||
occupantAddress2: "",
|
||||
occupantCity: "",
|
||||
occupantProvince: "",
|
||||
occupantPostalCode: "",
|
||||
occupantPhoneNumber: ""
|
||||
}, user);
|
||||
}
|
||||
|
||||
if (prepaidRow.CMPP_FEE_GRAV_SD !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_GRAV_SD"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_GRAV_SD,
|
||||
taxAmount: prepaidRow.CMPP_GST_GRAV_SD
|
||||
}, user);
|
||||
}
|
||||
|
||||
if (prepaidRow.CMPP_FEE_GRAV_DD !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_GRAV_DD"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_GRAV_DD,
|
||||
taxAmount: prepaidRow.CMPP_GST_GRAV_DD
|
||||
}, user);
|
||||
}
|
||||
|
||||
if (prepaidRow.CMPP_FEE_CHAP_SD !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_CHAP_SD"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_CHAP_SD,
|
||||
taxAmount: prepaidRow.CMPP_GST_CHAP_SD
|
||||
}, user);
|
||||
}
|
||||
|
||||
if (prepaidRow.CMPP_FEE_CHAP_DD !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_CHAP_DD"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_CHAP_DD,
|
||||
taxAmount: prepaidRow.CMPP_GST_CHAP_DD
|
||||
}, user);
|
||||
}
|
||||
|
||||
if (prepaidRow.CMPP_FEE_ENTOMBMENT !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_ENTOMBMENT"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_ENTOMBMENT,
|
||||
taxAmount: prepaidRow.CMPP_GST_ENTOMBMENT
|
||||
}, user);
|
||||
}
|
||||
|
||||
if (prepaidRow.CMPP_FEE_CREM !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_CREM"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_CREM,
|
||||
taxAmount: prepaidRow.CMPP_GST_CREM
|
||||
}, user);
|
||||
}
|
||||
|
||||
if (prepaidRow.CMPP_FEE_NICHE !== "0.0") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_NICHE"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_NICHE,
|
||||
taxAmount: prepaidRow.CMPP_GST_NICHE
|
||||
}, user);
|
||||
}
|
||||
|
||||
if (prepaidRow.CMPP_FEE_DISINTERMENT !== "0.0" && prepaidRow.CMPP_FEE_DISINTERMENT !== "20202.02") {
|
||||
addLotOccupancyFee({
|
||||
lotOccupancyId,
|
||||
feeId: getFeeIdByFeeDescription("CMPP_FEE_DISINTERMENT"),
|
||||
quantity: 1,
|
||||
feeAmount: prepaidRow.CMPP_FEE_DISINTERMENT,
|
||||
taxAmount: prepaidRow.CMPP_GST_DISINTERMENT
|
||||
}, user);
|
||||
}
|
||||
|
||||
const transactionAmount =
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_GRAV_SD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_GRAV_SD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_GRAV_DD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_GRAV_DD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_CHAP_SD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_CHAP_SD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_CHAP_DD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_CHAP_DD) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_ENTOMBMENT) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_ENTOMBMENT) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_CREM) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_CREM) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_NICHE) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_NICHE) +
|
||||
Number.parseFloat(prepaidRow.CMPP_FEE_DISINTERMENT === "20202.02" ? "0" : prepaidRow.CMPP_FEE_DISINTERMENT) +
|
||||
Number.parseFloat(prepaidRow.CMPP_GST_DISINTERMENT === "20202.02" ? "0" : prepaidRow.CMPP_GST_DISINTERMENT);
|
||||
|
||||
addLotOccupancyTransaction({
|
||||
lotOccupancyId,
|
||||
externalReceiptNumber: prepaidRow.CMPP_ORDER_NO,
|
||||
transactionAmount,
|
||||
transactionDateString: occupancyStartDateString,
|
||||
transactionNote: ""
|
||||
}, user);
|
||||
|
||||
if (prepaidRow.CMPP_REMARK1) {
|
||||
addLotOccupancyComment({
|
||||
lotOccupancyId,
|
||||
lotOccupancyCommentDateString: occupancyStartDateString,
|
||||
lotOccupancyComment: prepaidRow.CMPP_REMARK1
|
||||
}, user);
|
||||
}
|
||||
|
||||
if (prepaidRow.CMPP_REMARK2) {
|
||||
addLotOccupancyComment({
|
||||
lotOccupancyId,
|
||||
lotOccupancyCommentDateString: occupancyStartDateString,
|
||||
lotOccupancyComment: prepaidRow.CMPP_REMARK2
|
||||
}, user);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
console.log(prepaidRow);
|
||||
}
|
||||
}
|
||||
|
||||
purgeTables();
|
||||
purgeConfigTables();
|
||||
importFromCSV();
|
||||
// purgeConfigTables();
|
||||
importFromMasterCSV();
|
||||
importFromPrepaidCSV();
|
||||
Loading…
Reference in New Issue