From 239d6746600ed273c4cb53dec8c02beca838678d Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 5 Mar 2021 00:52:04 +0000 Subject: [PATCH] --- server/AyaNova/biz/ContractOverrideType.cs | 12 +++++ server/AyaNova/models/Contract.cs | 39 +++++++++++----- server/AyaNova/models/ContractPartOverride.cs | 32 ++++++++++++++ server/AyaNova/models/ContractServiceRate.cs | 21 +++++++++ .../models/ContractServiceRateOverride.cs | 32 ++++++++++++++ server/AyaNova/models/ContractTravelRate.cs | 21 +++++++++ .../models/ContractTravelRateOverride.cs | 32 ++++++++++++++ server/AyaNova/util/AySchema.cs | 44 ++++++++++++------- 8 files changed, 208 insertions(+), 25 deletions(-) create mode 100644 server/AyaNova/biz/ContractOverrideType.cs create mode 100644 server/AyaNova/models/ContractPartOverride.cs create mode 100644 server/AyaNova/models/ContractServiceRate.cs create mode 100644 server/AyaNova/models/ContractServiceRateOverride.cs create mode 100644 server/AyaNova/models/ContractTravelRate.cs create mode 100644 server/AyaNova/models/ContractTravelRateOverride.cs diff --git a/server/AyaNova/biz/ContractOverrideType.cs b/server/AyaNova/biz/ContractOverrideType.cs new file mode 100644 index 00000000..94c3c799 --- /dev/null +++ b/server/AyaNova/biz/ContractOverrideType.cs @@ -0,0 +1,12 @@ +namespace AyaNova.Biz +{ + /// + /// Contract override types for contract discounts / markup + /// + public enum ContractOverrideType : int + { + NotSet = 0, + PriceDiscount = 1, + CostMarkup = 2 + } +}//eons diff --git a/server/AyaNova/models/Contract.cs b/server/AyaNova/models/Contract.cs index be036649..151db836 100644 --- a/server/AyaNova/models/Contract.cs +++ b/server/AyaNova/models/Contract.cs @@ -3,11 +3,11 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using AyaNova.Biz; using Newtonsoft.Json; +using System; namespace AyaNova.Models { - //NOTE: Any non required field (nullable in DB) sb nullable here, i.e. decimal? not decimal, - //otherwise the server will call it an invalid record if the field isn't sent from client + public class Contract : ICoreBizObjectModel { @@ -22,12 +22,31 @@ namespace AyaNova.Models public string CustomFields { get; set; } public List Tags { get; set; } -//new for v8 -//response -//discountservicerate (all service rates) -//discounttravelrate (all travel) + //any optional ones here sb zero to indicate not set (or equivalent to zero) + [Required] + public TimeSpan ResponseTime { get; set; } + [Required] + public bool ContractRatesOnly { get; set; } + [Required] + public decimal PartsOverride { get; set; } + [Required] + public ContractOverrideType PartsOverrideType { get; set; } + [Required] + public decimal ServiceRatesOverride { get; set; } + [Required] + public ContractOverrideType ServiceRatesOverrideType { get; set; } + [Required] + public decimal TravelRatesOverride { get; set; } + [Required] + public ContractOverrideType TravelRatesOverrideType { get; set; } + public string AlertNotes { get; set; }//alert on workorder etc + public List ServiceRateItems { get; set; } = new List(); + public List TravelRateItems { get; set; } = new List(); + public List ContractPartOverrideItems { get; set; } = new List(); + public List ContractTravelRateOverrideItems { get; set; } = new List(); + public List ContractServiceRateOverrideItems { get; set; } = new List(); public Contract() { @@ -48,7 +67,7 @@ CREATE TABLE [dbo].[ACONTRACT]( [AMODIFIER] [uniqueidentifier] NULL, [ACREATED] [datetime] NULL, [AMODIFIED] [datetime] NULL, - [ADISCOUNTPARTS] [decimal](19, 5) NULL, + [ADISCOUNTPARTS] [decimal](19, 5) NULL,//rename PartsOverride [ANAME] [nvarchar](255) NULL, [AACTIVE] [bit] NOT NULL, [ANOTES] [ntext] NULL, @@ -69,7 +88,7 @@ CREATE TABLE [dbo].[ACONTRACT]( CHILDREN ContractRate - specific contract rates available to contract holding entities only ContractTravel - specific contract travel rates only '' - ContractRateTagOverride - tags and discount / markup to apply collection - ContractTravelTagOverride - '' - ContractPartTagOverride - '' + ContractRateOverride - tags and discount / markup to apply collection + ContractTravelOverride - '' + ContractPartOverride - '' */ \ No newline at end of file diff --git a/server/AyaNova/models/ContractPartOverride.cs b/server/AyaNova/models/ContractPartOverride.cs new file mode 100644 index 00000000..93f0332b --- /dev/null +++ b/server/AyaNova/models/ContractPartOverride.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using AyaNova.Biz; +using Newtonsoft.Json; + +namespace AyaNova.Models +{ + public class ContractPartOverride + { + public long Id { get; set; } + public uint Concurrency { get; set; } + + [Required] + public long ContractId { get; set; } + [Required] + public decimal Override { get; set; } + [Required] + public ContractOverrideType OverrideType { get; set; } + [Required] + public List Tags { get; set; } + + + [JsonIgnore] + public Contract Contract { get; set; } + public ContractPartOverride() + { + Tags = new List(); + } + + }//eoc + +}//eons diff --git a/server/AyaNova/models/ContractServiceRate.cs b/server/AyaNova/models/ContractServiceRate.cs new file mode 100644 index 00000000..77c9744f --- /dev/null +++ b/server/AyaNova/models/ContractServiceRate.cs @@ -0,0 +1,21 @@ +using System.ComponentModel.DataAnnotations; +using Newtonsoft.Json; + +namespace AyaNova.Models +{ + public class ContractServiceRate + { + public long Id { get; set; } + public uint Concurrency { get; set; } + + [Required] + public long ContractId { get; set; } + [Required] + public long ServiceRateId { get; set; } + + [JsonIgnore] + public Contract Contract { get; set; } + + }//eoc + +}//eons diff --git a/server/AyaNova/models/ContractServiceRateOverride.cs b/server/AyaNova/models/ContractServiceRateOverride.cs new file mode 100644 index 00000000..6e9c8059 --- /dev/null +++ b/server/AyaNova/models/ContractServiceRateOverride.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using AyaNova.Biz; +using Newtonsoft.Json; + +namespace AyaNova.Models +{ + public class ContractServiceRateOverride + { + public long Id { get; set; } + public uint Concurrency { get; set; } + + [Required] + public long ContractId { get; set; } + [Required] + public decimal Override { get; set; } + [Required] + public ContractOverrideType OverrideType { get; set; } + [Required] + public List Tags { get; set; } + + + [JsonIgnore] + public Contract Contract { get; set; } + public ContractServiceRateOverride() + { + Tags = new List(); + } + + }//eoc + +}//eons diff --git a/server/AyaNova/models/ContractTravelRate.cs b/server/AyaNova/models/ContractTravelRate.cs new file mode 100644 index 00000000..ab7c7294 --- /dev/null +++ b/server/AyaNova/models/ContractTravelRate.cs @@ -0,0 +1,21 @@ +using System.ComponentModel.DataAnnotations; +using Newtonsoft.Json; + +namespace AyaNova.Models +{ + public class ContractTravelRate + { + public long Id { get; set; } + public uint Concurrency { get; set; } + + [Required] + public long ContractId { get; set; } + [Required] + public long TravelRateId { get; set; } + + [JsonIgnore] + public Contract Contract { get; set; } + + }//eoc + +}//eons diff --git a/server/AyaNova/models/ContractTravelRateOverride.cs b/server/AyaNova/models/ContractTravelRateOverride.cs new file mode 100644 index 00000000..5cc0a622 --- /dev/null +++ b/server/AyaNova/models/ContractTravelRateOverride.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using AyaNova.Biz; +using Newtonsoft.Json; + +namespace AyaNova.Models +{ + public class ContractTravelRateOverride + { + public long Id { get; set; } + public uint Concurrency { get; set; } + + [Required] + public long ContractId { get; set; } + [Required] + public decimal Override { get; set; } + [Required] + public ContractOverrideType OverrideType { get; set; } + [Required] + public List Tags { get; set; } + + + [JsonIgnore] + public Contract Contract { get; set; } + public ContractTravelRateOverride() + { + Tags = new List(); + } + + }//eoc + +}//eons diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index 6ce70ad0..ba4b7c64 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -37,7 +37,17 @@ namespace AyaNova.Util /* MAXIMUM POSTGRES OBJECT NAME LENGTH: 63 CHARACTERS - CURRENCY: use DECIMAL(19,4) + + 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) + + + + //DATA TYPES .net to postgres map //http://www.npgsql.org/doc/types/basic.html @@ -466,7 +476,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); //Add widget table //id, TEXT, longtext, boolean, currency, await ExecQueryAsync("CREATE TABLE awidget (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL UNIQUE, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL," - + "startdate TIMESTAMP, enddate TIMESTAMP, dollaramount DECIMAL(19,4), active BOOL NOT NULL, usertype int4, count INTEGER," + + "startdate TIMESTAMP, enddate TIMESTAMP, dollaramount DECIMAL(38,18), active BOOL NOT NULL, usertype int4, count INTEGER," + "notes TEXT, userid BIGINT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)"); await SetSchemaLevelAsync(++currentSchema); @@ -573,17 +583,17 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); //SERVICERATE await ExecQueryAsync("CREATE TABLE aservicerate (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, " - + "accountnumber TEXT, unit TEXT, contractonly BOOL NOT NULL, cost DECIMAL(19,4) NOT NULL default 0, charge DECIMAL(19,4) NOT NULL default 0)"); + + "accountnumber TEXT, unit TEXT, contractonly BOOL NOT NULL, cost DECIMAL(38,18) NOT NULL default 0, charge DECIMAL(38,18) NOT NULL default 0)"); //TRAVELRATE await ExecQueryAsync("CREATE TABLE atravelrate (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, " - + "accountnumber TEXT, unit TEXT, contractonly BOOL NOT NULL, cost DECIMAL(19,4) NOT NULL default 0, charge DECIMAL(19,4) NOT NULL default 0)"); + + "accountnumber TEXT, unit TEXT, contractonly BOOL NOT NULL, cost DECIMAL(38,18) NOT NULL default 0, charge DECIMAL(38,18) NOT NULL default 0)"); //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(19,4) NOT NULL default 0, taxb DECIMAL(19,4) NOT NULL default 0, taxontax BOOL NOT NULL default false)"); + + "taxa DECIMAL(5,5) NOT NULL default 0, taxb DECIMAL(5,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, " @@ -616,7 +626,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); 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, " - + "currency DECIMAL(19,4) NOT NULL, currencybalance DECIMAL(19,4) NOT NULL, lastcurrencybalance DECIMAL(19,4) 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, " + "CONSTRAINT unq_servicebank UNIQUE (entrydate, objectid, objecttype, incidentsbalance, hoursbalance, currencybalance), " + "CONSTRAINT unq_servicebank_previous_values UNIQUE (lastentrydate, objectid, objecttype, lastincidentsbalance, lasthoursbalance, lastcurrencybalance), " @@ -646,7 +656,11 @@ $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 )"); + + "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, " + + "responsetime INTERVAL NOT NULL, contractratesonly 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, " + +"alertnotes text " + + ")"); await ExecQueryAsync("ALTER TABLE acustomer ADD column contractid BIGINT NULL REFERENCES acontract"); @@ -674,7 +688,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); + "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, " + "partnumber TEXT NOT NULL UNIQUE, manufacturerid BIGINT REFERENCES avendor, manufacturernumber TEXT, " + "wholesalerid BIGINT REFERENCES avendor, wholesalernumber TEXT, alternativewholesalerid BIGINT REFERENCES avendor, alternativewholesalernumber TEXT, " - + "cost DECIMAL(19,4) NOT NULL, retail DECIMAL(19,4) NOT NULL, unitofmeasure TEXT, upc TEXT " + + "cost DECIMAL(38,18) NOT NULL, retail DECIMAL(38,18) NOT NULL, unitofmeasure TEXT, upc TEXT " + " )"); //PARTWAREHOUSE @@ -743,7 +757,7 @@ $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(19,4) NOT NULL default 0, receivedcost 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, " + "receiveddate TIMESTAMP, partrequestedbyid BIGINT REFERENCES auser, purchasetaxcodeid BIGINT REFERENCES ataxcode, vendorpartnumber TEXT, serials TEXT " + ")"); @@ -772,7 +786,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); await ExecQueryAsync("CREATE TABLE aloanunit (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, " + "serial TEXT, unitid BIGINT NULL REFERENCES aunit(id), defaultrate INTEGER NOT NULL, " - + "ratehour DECIMAL(19,4) NOT NULL, ratehalfday DECIMAL(19,4) NOT NULL, rateday DECIMAL(19,4) NOT NULL, rateweek DECIMAL(19,4) NOT NULL, ratemonth DECIMAL(19,4) NOT NULL, rateyear DECIMAL(19,4) NOT NULL " + + "ratehour DECIMAL(38,18) NOT NULL, ratehalfday DECIMAL(38,18) NOT NULL, rateday DECIMAL(38,18) NOT NULL, rateweek DECIMAL(38,18) NOT NULL, ratemonth DECIMAL(38,18) NOT NULL, rateyear DECIMAL(38,18) NOT NULL " + ")"); @@ -901,8 +915,8 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); LogUpdateMessage(log); await ExecQueryAsync("CREATE TABLE anotifysubscription (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " - + "userid BIGINT NOT NULL REFERENCES auser (id), ayatype INTEGER NOT NULL, eventtype INTEGER NOT NULL, advancenotice interval NOT NULL, " - + "idvalue BIGINT NOT NULL, decvalue DECIMAL(19,4) NOT NULL, agevalue interval NOT NULL, deliverymethod INTEGER NOT NULL, " + + "userid BIGINT NOT NULL REFERENCES auser (id), ayatype INTEGER NOT NULL, eventtype INTEGER NOT NULL, advancenotice INTERVAL NOT NULL, " + + "idvalue BIGINT NOT NULL, decvalue DECIMAL(38,18) NOT NULL, agevalue INTERVAL NOT NULL, deliverymethod INTEGER NOT NULL, " + "deliveryaddress TEXT, linkreportid BIGINT NOT NULL, tags VARCHAR(255) ARRAY)"); await ExecQueryAsync("CREATE TABLE anotifyevent (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, created TIMESTAMP NOT NULL, " @@ -910,7 +924,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); + "userid BIGINT NOT NULL REFERENCES auser (id), eventdate TIMESTAMP NOT NULL, message TEXT)"); //these fields were in here but seem to not be required so commented out for now, see notifyevent model for deets but //basically remove this comment once certain don't need these fields (close to release or after) - //idvalue BIGINT NOT NULL, decvalue DECIMAL(19,4) NOT NULL, + //idvalue BIGINT NOT NULL, decvalue DECIMAL(38,18) NOT NULL, await ExecQueryAsync("CREATE TABLE anotification (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, userid BIGINT NOT NULL REFERENCES auser (id), " @@ -919,7 +933,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); await ExecQueryAsync("CREATE TABLE anotifydeliverylog (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, processed TIMESTAMP NOT NULL, " + "ayatype INTEGER NOT NULL, objectid BIGINT NOT NULL, eventtype INTEGER NOT NULL, notifysubscriptionid BIGINT NOT NULL, idvalue BIGINT NOT NULL, " - + "decvalue DECIMAL(19,4) NOT NULL, userid BIGINT NOT NULL REFERENCES auser (id), deliverymethod INTEGER NOT NULL, fail BOOL NOT NULL, error TEXT)"); + + "decvalue DECIMAL(38,18) NOT NULL, userid BIGINT NOT NULL REFERENCES auser (id), deliverymethod INTEGER NOT NULL, fail BOOL NOT NULL, error TEXT)"); await SetSchemaLevelAsync(++currentSchema); } @@ -944,7 +958,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(19,4) )"); + + "marginoptionsleft TEXT, marginoptionsright TEXT, marginoptionstop TEXT, pageranges TEXT, prefercsspagesize BOOL, printbackground BOOL, scale DECIMAL(5,5) )"); await SetSchemaLevelAsync(++currentSchema); //Load the stock REPORT TEMPLATES