From efd876c3235260d5e3a9a42d279ea1093a4598a0 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 12 May 2021 16:37:41 +0000 Subject: [PATCH] --- server/AyaNova/biz/ContractBiz.cs | 2 ++ server/AyaNova/biz/WorkOrderBiz.cs | 32 ++++++++++++++++++++++++------ server/AyaNova/models/WorkOrder.cs | 11 ++++++---- server/AyaNova/util/AySchema.cs | 2 +- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/server/AyaNova/biz/ContractBiz.cs b/server/AyaNova/biz/ContractBiz.cs index 44527b32..75ca37c2 100644 --- a/server/AyaNova/biz/ContractBiz.cs +++ b/server/AyaNova/biz/ContractBiz.cs @@ -466,6 +466,8 @@ MULTIPLE discount / markup ITEMS AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("HeadOffice")); if (await ct.Unit.AnyAsync(m => m.ContractId == inObj.Id)) AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("Unit")); + if (await ct.WorkOrder.AnyAsync(m => m.ContractId == inObj.Id)) + AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("WorkOrder")); } diff --git a/server/AyaNova/biz/WorkOrderBiz.cs b/server/AyaNova/biz/WorkOrderBiz.cs index 16a6aa5b..0f500b76 100644 --- a/server/AyaNova/biz/WorkOrderBiz.cs +++ b/server/AyaNova/biz/WorkOrderBiz.cs @@ -681,9 +681,6 @@ namespace AyaNova.Biz - - - //////////////////////////////////////////////////////////////////////////////////////////////// // NOTIFICATION PROCESSING // @@ -706,10 +703,12 @@ namespace AyaNova.Biz }//end of process notifications + #endregion workorder level + /* ███████╗████████╗ █████╗ ████████╗███████╗███████╗ @@ -1724,7 +1723,7 @@ namespace AyaNova.Biz { //automatic actions on record change, called AFTER validation - + var Contract = GetCurrentWorkOrderContractFromRelatedAsync(AyaType.WorkOrderItem, newObj.WorkOrderItemId); switch (ayaEvent) { @@ -1765,8 +1764,8 @@ namespace AyaNova.Biz } //Contract - todo: need to have a bombproof way to get the effective contract and statically hold it here in wobiz until processing finished because other objects in tree may also need it - figure out if there will only ever be ONE effective contract or multiple and then can determine how to handle here + // todo: need to have a bombproof way to get the effective contract and statically hold it here in wobiz until processing finished because other objects in tree may also need it + // figure out if there will only ever be ONE effective contract or multiple and then can determine how to handle here //Yes precedence is Unit->Customer->headoffice. //it's not permitted to have more than one contracted unit on a workorder //if a unit has a contract on workorder it applies to *entire* workorder so they must use one unit under contract and it's the entirety of the work performed @@ -4083,6 +4082,27 @@ namespace AyaNova.Biz + //////////////////////////////////////////////////////////////////////////////////////////////// + //GET CONTRACT FOR WORKORDER FROM RELATIVE + // + internal async Task GetCurrentWorkOrderContractFromRelatedAsync(AyaType ayaType, long id) + { + //instantiated method to save adding the context + return await GetCurrentWorkOrderContractFromRelatedAsync(ayaType, id, ct); + } + internal static async Task GetCurrentWorkOrderContractFromRelatedAsync(AyaType ayaType, long id, AyContext ct) + { + //static method + long WoId = await GetWorkOrderIdFromRelativeAsync(ayaType, id, ct); + var WoContractId = await ct.WorkOrder.AsNoTracking().Where(z => z.Id == WoId).Select(z => z.ContractId).FirstOrDefaultAsync(); + if (WoContractId == null) + { + return null; + } + return await ct.Contract.AsNoTracking().FirstOrDefaultAsync(z => z.Id == WoContractId); + } + + //////////////////////////////////////////////////////////////////////////////////////////////// //GET CURRENT STATUS FOR WORKORDER FROM RELATIVE // diff --git a/server/AyaNova/models/WorkOrder.cs b/server/AyaNova/models/WorkOrder.cs index 1706a1f4..4a896559 100644 --- a/server/AyaNova/models/WorkOrder.cs +++ b/server/AyaNova/models/WorkOrder.cs @@ -31,7 +31,7 @@ namespace AyaNova.Models [Required] public long CustomerId { get; set; } public long? ProjectId { get; set; } - [NotMapped] + [NotMapped] public string ProjectViz { get; set; } public string InternalReferenceNumber { get; set; } public string CustomerReferenceNumber { get; set; } @@ -49,9 +49,12 @@ namespace AyaNova.Models public string TechSignature { get; set; } public string TechSignatureName { get; set; } public DateTime? TechSignatureCaptured { get; set; } - public bool Onsite {get;set;} - public string Contract { get; set; } - + public bool Onsite { get; set; } + public long? ContractId { get; set; } + [NotMapped] + public string ContractViz { get; set; } + + //POSTAL ADDRESS / "BILLING ADDRESS" public string PostAddress { get; set; } public string PostCity { get; set; } diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index c3d57156..cbac596a 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -758,7 +758,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); //WORKORDER await ExecQueryAsync("CREATE TABLE aworkorder (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, " + "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, customerid BIGINT NOT NULL REFERENCES acustomer (id), " - + "projectid BIGINT REFERENCES aproject, internalreferencenumber text, customerreferencenumber text, customercontactname text, " + + "projectid BIGINT REFERENCES aproject, contractid BIGINT NULL REFERENCES acontract, internalreferencenumber text, customerreferencenumber text, customercontactname text, " + "servicedate TIMESTAMP, completebydate TIMESTAMP, invoicenumber TEXT, customersignature TEXT, customersignaturename TEXT, customersignaturecaptured TIMESTAMP, " + "techsignature TEXT, techsignaturename TEXT, techsignaturecaptured TIMESTAMP, durationtocompleted INTERVAL NOT NULL, onsite BOOL NOT NULL, contract TEXT, " + "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) "