This commit is contained in:
2021-03-06 19:10:31 +00:00
parent 2ecfb25f94
commit d451374f7b
2 changed files with 26 additions and 23 deletions

2
.vscode/launch.json vendored
View File

@@ -53,7 +53,7 @@
"AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles",
"AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles",
"AYANOVA_FOLDER_TEMPORARY_SERVER_FILES": "c:\\temp\\RavenTestData\\tempfiles",
"AYANOVA_SERVER_TEST_MODE": "false",
"AYANOVA_SERVER_TEST_MODE": "true",
"AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small",
"AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7",
"AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\"

View File

@@ -40,11 +40,14 @@ namespace AyaNova.Util
DECIMALS:
=-=-=-=--
CURRENCY: was use DECIMAL(19,4) (18 bytes) however with cryptocurrencies now potentially being used
and the fact that it doesn't practically take up much room or speed to go wider I'm settling on largest Etherium value DECIMAL(38,18) (36bytes)
TAX/PERCENTAGES/PDF PAGE SCALE: DECIMAL(5,5) largest tax I could find would fit in this
Inventory/incidents general numbers (19,4)
DECIMAL(PRECISION,SCALE)
DECIMAL([MAXIMUM DIGITS TOTAL],[DIGITS TO THE RIGHT OF DECIMAL POINT])
(left digits max is precision minus scale)
CURRENCY: DECIMAL(38,18) (to support potential of cryptocurrencies) largest Etherium value fits in this (36bytes)
TAX/PERCENTAGES/PDF PAGE SCALE: DECIMAL(8,5) largest tax I could find would fit in this, that's 3 digits to left and 5 to right
Inventory/incidents general numbers (19,5)
Latitude/longitude 9,6
@@ -593,7 +596,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
//TAXCODE
await ExecQueryAsync("CREATE TABLE ataxcode (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL UNIQUE, active BOOL NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, "
+ "taxa DECIMAL(5,5) NOT NULL default 0, taxb DECIMAL(5,5) NOT NULL default 0, taxontax BOOL NOT NULL default false)");
+ "taxa DECIMAL(8,5) NOT NULL default 0, taxb DECIMAL(8,5) NOT NULL default 0, taxontax BOOL NOT NULL default false)");
//MEMO
await ExecQueryAsync("CREATE TABLE amemo (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL, "
@@ -625,9 +628,9 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
//Note: I'm allowing negative balances so this code differs slightly from the example it was drawn from https://dba.stackexchange.com/a/19368
await ExecQueryAsync("CREATE TABLE aservicebank (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL, "
+ "entrydate TIMESTAMP NOT NULL, lastentrydate TIMESTAMP NULL, objecttype INTEGER NOT NULL, objectid BIGINT NOT NULL, sourcetype INTEGER NOT NULL, sourceid BIGINT NOT NULL, "
+ "incidents DECIMAL(19,4) NOT NULL, incidentsbalance DECIMAL(19,4) NOT NULL, lastincidentsbalance DECIMAL(19,4) NULL, "
+ "incidents DECIMAL(19,5) NOT NULL, incidentsbalance DECIMAL(19,5) NOT NULL, lastincidentsbalance DECIMAL(19,5) NULL, "
+ "currency DECIMAL(38,18) NOT NULL, currencybalance DECIMAL(38,18) NOT NULL, lastcurrencybalance DECIMAL(38,18) NULL, "
+ "hours DECIMAL(19,4) NOT NULL, hoursbalance DECIMAL(19,4) NOT NULL, lasthoursbalance DECIMAL(19,4) NULL, "
+ "hours DECIMAL(19,5) NOT NULL, hoursbalance DECIMAL(19,5) NOT NULL, lasthoursbalance DECIMAL(19,5) NULL, "
+ "CONSTRAINT unq_servicebank UNIQUE (entrydate, objectid, objecttype, incidentsbalance, hoursbalance, currencybalance), "
+ "CONSTRAINT unq_servicebank_previous_values UNIQUE (lastentrydate, objectid, objecttype, lastincidentsbalance, lasthoursbalance, lastcurrencybalance), "
+ "CONSTRAINT fk_servicebank_self FOREIGN KEY (lastentrydate, objectid, objecttype, lastincidentsbalance, lasthoursbalance, lastcurrencybalance) REFERENCES aservicebank(entrydate, objectid, objecttype, incidentsbalance, hoursbalance, currencybalance), "
@@ -645,7 +648,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, "
+ "webaddress TEXT, popupnotes TEXT, billheadoffice BOOL, technotes TEXT, accountnumber TEXT, usesbanking BOOL, contractexpires TIMESTAMP NULL, "
+ "phone1 TEXT, phone2 TEXT, phone3 TEXT, phone4 TEXT, phone5 TEXT, emailaddress TEXT, "
+ "postaddress TEXT, postcity TEXT, postregion TEXT, postcountry TEXT, postcode TEXT, address TEXT, city TEXT, region TEXT, country TEXT, latitude DECIMAL(8,6), longitude DECIMAL(9,6))");
+ "postaddress TEXT, postcity TEXT, postregion TEXT, postcountry TEXT, postcode TEXT, address TEXT, city TEXT, region TEXT, country TEXT, latitude DECIMAL(9,6), longitude DECIMAL(9,6))");
await ExecQueryAsync("ALTER TABLE auser ADD FOREIGN KEY (customerid) REFERENCES acustomer(id)");
@@ -657,8 +660,8 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
//CONTRACT
await ExecQueryAsync("CREATE TABLE acontract (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL UNIQUE, active BOOL NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, "
+ "responsetime INTERVAL NOT NULL, contractserviceratesonly BOOL NOT NULL, contracttravelratesonly BOOL NOT NULL, partsoverride DECIMAL(5,5) NOT NULL, partsoverridetype INTEGER NOT NULL, "
+ "serviceratesoverride DECIMAL(5,5) NOT NULL, serviceratesoverridetype INTEGER NOT NULL, travelratesoverride DECIMAL(5,5) NOT NULL, travelratesoverridetype INTEGER NOT NULL, "
+ "responsetime INTERVAL NOT NULL, contractserviceratesonly BOOL NOT NULL, contracttravelratesonly BOOL NOT NULL, partsoverride DECIMAL(8,5) NOT NULL, partsoverridetype INTEGER NOT NULL, "
+ "serviceratesoverride DECIMAL(8,5) NOT NULL, serviceratesoverridetype INTEGER NOT NULL, travelratesoverride DECIMAL(8,5) NOT NULL, travelratesoverridetype INTEGER NOT NULL, "
+ "alertnotes text "
+ ")");
await ExecQueryAsync("ALTER TABLE acustomer ADD column contractid BIGINT NULL REFERENCES acontract");
@@ -675,15 +678,15 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
//CONTRACTPARTOVERRIDE
await ExecQueryAsync("CREATE TABLE acontractpartoverride (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, contractid BIGINT NOT NULL REFERENCES acontract ON DELETE CASCADE, "
+ " override DECIMAL(5,5) NOT NULL, overridetype INTEGER NOT NULL, tags VARCHAR(255) ARRAY)");
+ " override DECIMAL(8,5) NOT NULL, overridetype INTEGER NOT NULL, tags VARCHAR(255) ARRAY)");
//CONTRACTSERVICERATEOVERRIDE
await ExecQueryAsync("CREATE TABLE acontractservicerateoverride (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, contractid BIGINT NOT NULL REFERENCES acontract ON DELETE CASCADE, "
+ " override DECIMAL(5,5) NOT NULL, overridetype INTEGER NOT NULL, tags VARCHAR(255) ARRAY)");
+ " override DECIMAL(8,5) NOT NULL, overridetype INTEGER NOT NULL, tags VARCHAR(255) ARRAY)");
//CONTRACTTRAVELRATEOVERRIDE
await ExecQueryAsync("CREATE TABLE acontracttravelrateoverride (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, contractid BIGINT NOT NULL REFERENCES acontract ON DELETE CASCADE, "
+ " override DECIMAL(5,5) NOT NULL, overridetype INTEGER NOT NULL, tags VARCHAR(255) ARRAY)");
+ " override DECIMAL(8,5) NOT NULL, overridetype INTEGER NOT NULL, tags VARCHAR(255) ARRAY)");
//HEADOFFICE
@@ -691,7 +694,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY,"
+ "webaddress TEXT, accountnumber TEXT, usesbanking BOOL, contractexpires TIMESTAMP NULL, contractid BIGINT NULL REFERENCES acontract(id), "
+ "phone1 TEXT, phone2 TEXT, phone3 TEXT, phone4 TEXT, phone5 TEXT, emailaddress TEXT, "
+ "postaddress TEXT, postcity TEXT, postregion TEXT, postcountry TEXT, postcode TEXT, address TEXT, city TEXT, region TEXT, country TEXT, latitude DECIMAL(8,6), longitude DECIMAL(9,6)"
+ "postaddress TEXT, postcity TEXT, postregion TEXT, postcountry TEXT, postcode TEXT, address TEXT, city TEXT, region TEXT, country TEXT, latitude DECIMAL(9,6), longitude DECIMAL(9,6)"
+ " )");
await ExecQueryAsync("ALTER TABLE acustomer ADD column headofficeid BIGINT NULL REFERENCES aheadoffice");
await ExecQueryAsync("ALTER TABLE auser ADD FOREIGN KEY (headofficeid) REFERENCES aheadoffice(id)");
@@ -701,7 +704,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
await ExecQueryAsync("CREATE TABLE avendor (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL UNIQUE, active BOOL NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, webaddress TEXT, popupnotes TEXT, accountnumber TEXT, "
+ "contact TEXT, contactnotes TEXT, phone1 TEXT, phone2 TEXT, phone3 TEXT, phone4 TEXT, phone5 TEXT, emailaddress TEXT, "
+ "postaddress TEXT, postcity TEXT, postregion TEXT, postcountry TEXT, postcode TEXT, address TEXT, city TEXT, region TEXT, country TEXT, latitude DECIMAL(8,6), longitude DECIMAL(9,6))");
+ "postaddress TEXT, postcity TEXT, postregion TEXT, postcountry TEXT, postcode TEXT, address TEXT, city TEXT, region TEXT, country TEXT, latitude DECIMAL(9,6), longitude DECIMAL(9,6))");
await ExecQueryAsync("ALTER TABLE auser ADD FOREIGN KEY (vendorid) REFERENCES avendor(id)");
@@ -728,7 +731,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
//PARTASSEMBLYITEM
await ExecQueryAsync("CREATE TABLE apartassemblyitem (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, partassemblyid BIGINT NOT NULL REFERENCES apartassembly ON DELETE CASCADE, "
+ "partid BIGINT NOT NULL REFERENCES apart ON DELETE CASCADE, quantity DECIMAL(19,4) NOT NULL default 1, "
+ "partid BIGINT NOT NULL REFERENCES apart ON DELETE CASCADE, quantity DECIMAL(19,5) NOT NULL default 1, "
+ "CONSTRAINT unq_partassemblypart UNIQUE (partid, partassemblyid) "
+ ")");
// await ExecQueryAsync("CREATE INDEX idx_apartassemblyitem_partid ON apartassemblyitem(partid)");
@@ -738,7 +741,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
await ExecQueryAsync("CREATE TABLE apartinventory (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, description TEXT NOT NULL, "
+ "entrydate TIMESTAMP NOT NULL, lastentrydate TIMESTAMP NULL, partid BIGINT NOT NULL REFERENCES apart, partwarehouseid BIGINT NOT NULL REFERENCES apartwarehouse, "
+ "sourcetype INTEGER, sourceid BIGINT, "
+ "quantity DECIMAL(19,4) NOT NULL, balance DECIMAL(19,4) NOT NULL, lastbalance DECIMAL(19,4) NULL, "
+ "quantity DECIMAL(19,5) NOT NULL, balance DECIMAL(19,5) NOT NULL, lastbalance DECIMAL(19,5) NULL, "
+ "CONSTRAINT unq_partinventory UNIQUE (partid, partwarehouseid, entrydate, balance), "
+ "CONSTRAINT unq_partinventory_previous_values UNIQUE (partid, partwarehouseid, lastentrydate, lastbalance), "
+ "CONSTRAINT fk_partinventory_self FOREIGN KEY (partid, partwarehouseid, lastentrydate, lastbalance) REFERENCES apartinventory(partid, partwarehouseid, entrydate, balance), "
@@ -758,7 +761,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
//PARTSTOCKLEVEL
await ExecQueryAsync("CREATE TABLE apartstocklevel (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, partwarehouseid BIGINT NOT NULL REFERENCES apartwarehouse ON DELETE CASCADE, "
+ "partid BIGINT NOT NULL REFERENCES apart ON DELETE CASCADE, minimumquantity DECIMAL(19,4) NOT NULL default 1, "
+ "partid BIGINT NOT NULL REFERENCES apart ON DELETE CASCADE, minimumquantity DECIMAL(19,5) NOT NULL default 1, "
+ "CONSTRAINT unq_partstocklevel_part_warehouse UNIQUE (partid, partwarehouseid) "//ensure no duplicates
+ ")");
@@ -778,8 +781,8 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
//PURCHASEORDERITEM
await ExecQueryAsync("CREATE TABLE apurchaseorderitem (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, purchaseorderid BIGINT NOT NULL REFERENCES apurchaseorder ON DELETE CASCADE, "
+ "partid BIGINT NOT NULL REFERENCES apart, partwarehouseid BIGINT NOT NULL REFERENCES apartwarehouse, quantityordered DECIMAL(19,4) NOT NULL default 0, "
+ "quantityreceived DECIMAL(19,4) NOT NULL default 0, purchaseordercost DECIMAL(38,18) NOT NULL default 0, receivedcost DECIMAL(38,18) NOT NULL default 0, "
+ "partid BIGINT NOT NULL REFERENCES apart, partwarehouseid BIGINT NOT NULL REFERENCES apartwarehouse, quantityordered DECIMAL(19,5) NOT NULL default 0, "
+ "quantityreceived DECIMAL(19,5) NOT NULL default 0, purchaseordercost DECIMAL(38,18) NOT NULL default 0, receivedcost DECIMAL(38,18) NOT NULL default 0, "
+ "receiveddate TIMESTAMP, partrequestedbyid BIGINT REFERENCES auser, purchasetaxcodeid BIGINT REFERENCES ataxcode, vendorpartnumber TEXT, serials TEXT "
+ ")");
@@ -800,7 +803,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
+ "receipt TEXT NULL, purchaseddate TIMESTAMP NULL, description TEXT NULL, replacedbyunitid BIGINT NULL REFERENCES aunit(id), "
+ "overridemodelwarranty BOOL, warrantylength INTEGER NULL, warrantyterms TEXT NULL, contractid BIGINT NULL REFERENCES acontract, "
+ "contractexpires TIMESTAMP NULL, usesbanking BOOL, metered BOOL, lifetimewarranty BOOL, "
+ "text1 TEXT NULL, text2 TEXT NULL, text3 TEXT NULL, text4 TEXT NULL, address TEXT NULL, city TEXT NULL, region TEXT NULL, country TEXT NULL, latitude DECIMAL(8,6) NULL, longitude DECIMAL(9,6) NULL, "
+ "text1 TEXT NULL, text2 TEXT NULL, text3 TEXT NULL, text4 TEXT NULL, address TEXT NULL, city TEXT NULL, region TEXT NULL, country TEXT NULL, latitude DECIMAL(9,6) NULL, longitude DECIMAL(9,6) NULL, "
+ "CONSTRAINT unq_unitserialmodelid UNIQUE (serial, unitmodelid) "
+ " )");
@@ -981,7 +984,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
await ExecQueryAsync("CREATE TABLE areport (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL UNIQUE, active BOOL NOT NULL, "
+ "notes TEXT, roles INTEGER NOT NULL, objecttype INTEGER NOT NULL, template TEXT, style TEXT, jsprerender TEXT, jshelpers TEXT, rendertype INTEGER NOT NULL, "
+ "headertemplate TEXT, footertemplate TEXT, displayheaderfooter BOOL, paperformat INTEGER NOT NULL, landscape BOOL, marginoptionsbottom TEXT, "
+ "marginoptionsleft TEXT, marginoptionsright TEXT, marginoptionstop TEXT, pageranges TEXT, prefercsspagesize BOOL, printbackground BOOL, scale DECIMAL(4,3) )");
+ "marginoptionsleft TEXT, marginoptionsright TEXT, marginoptionstop TEXT, pageranges TEXT, prefercsspagesize BOOL, printbackground BOOL, scale DECIMAL(8,5) )");
await SetSchemaLevelAsync(++currentSchema);
//Load the stock REPORT TEMPLATES