From e2526e5498854f0923d9f5668bea8716792ff130 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 16 Jul 2021 19:22:13 +0000 Subject: [PATCH] --- .vscode/launch.json | 2 +- docs/8.0/ayanova/docs/api-error-codes.md | 4 ++- server/AyaNova/biz/ApiErrorCode.cs | 3 +- server/AyaNova/biz/WorkOrderBiz.cs | 41 ++++++++++++++++++++---- server/AyaNova/resource/de.json | 1 + server/AyaNova/resource/en.json | 1 + server/AyaNova/resource/es.json | 1 + server/AyaNova/resource/fr.json | 1 + 8 files changed, 44 insertions(+), 10 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index fcc80a75..b77f3b95 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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": "true", + "AYANOVA_SERVER_TEST_MODE": "false", "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small", "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7", "AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\" diff --git a/docs/8.0/ayanova/docs/api-error-codes.md b/docs/8.0/ayanova/docs/api-error-codes.md index 2990cdd4..81e865cc 100644 --- a/docs/8.0/ayanova/docs/api-error-codes.md +++ b/docs/8.0/ayanova/docs/api-error-codes.md @@ -31,4 +31,6 @@ Here are all the API level error codes that can be returned by the API server: | 2207 | Validation error - The start date must be earlier than the end date | | 2208 | Validation error - Modifying the object (usually a delete) would break the link to other records in the database and operation was disallowed to preserve data integrity | | 2209 | Validation error - Indicates the attempted property change is invalid because the value is fixed and cannot be changed | -| 2210 | Child object error - Indicates the attempted operation resulted in errors in linked child object | \ No newline at end of file +| 2210 | Child object error - Indicates the attempted operation resulted in errors in linked child object | +| 2211 | Validation error - Field set required by customization is empty or null | +| 2212 | Validation error - Attempt to set multiple contracted Units on work order (only one allowed per work order) | \ No newline at end of file diff --git a/server/AyaNova/biz/ApiErrorCode.cs b/server/AyaNova/biz/ApiErrorCode.cs index 45c24651..76dd62e5 100644 --- a/server/AyaNova/biz/ApiErrorCode.cs +++ b/server/AyaNova/biz/ApiErrorCode.cs @@ -31,7 +31,8 @@ namespace AyaNova.Biz VALIDATION_REFERENTIAL_INTEGRITY = 2208, VALIDATION_NOT_CHANGEABLE = 2209, CHILD_OBJECT_ERROR = 2210, - VALIDATION_REQUIRED_CUSTOM = 2211 + VALIDATION_REQUIRED_CUSTOM = 2211, + VALIDATION_WO_MULTIPLE_CONTRACTED_UNITS = 2212, /* | 2000 | API closed - Server is running but access to the API has been closed to all users | diff --git a/server/AyaNova/biz/WorkOrderBiz.cs b/server/AyaNova/biz/WorkOrderBiz.cs index d8045a15..e10af8cf 100644 --- a/server/AyaNova/biz/WorkOrderBiz.cs +++ b/server/AyaNova/biz/WorkOrderBiz.cs @@ -6183,16 +6183,17 @@ namespace AyaNova.Biz - //Contracted unit? Only one per work order is allowed + //Contracted unit? Only one per work order is allowed if (isNew || proposedObj.UnitId != currentObj.UnitId) { + bool AlreadyHasAContractedUnit = false; //See if this unit has a contract, if so then see if the contract is active, if so then iterate workorder graph and check all other units for same //if any found then reject this - var proposedContractInfo = await ct.Unit.AsNoTracking().Where(x => x.Id == proposedObj.Id).Select(x => new { x.ContractExpires, x.ContractId }).FirstOrDefaultAsync(); - if (proposedContractInfo.ContractId != null && proposedContractInfo.ContractExpires > DateTime.UtcNow) + var proposedUnitInfo = await ct.Unit.AsNoTracking().Where(x => x.Id == proposedObj.UnitId).Select(x => new { x.ContractExpires, x.ContractId }).FirstOrDefaultAsync(); + if (proposedUnitInfo.ContractId != null && proposedUnitInfo.ContractExpires > DateTime.UtcNow) { //added woitemunit has a contract and apparently unexpired so need to check if contract is still active - currentUnitContract = await GetFullyPopulatedContractGraphFromIdAsync(proposedContractInfo.ContractId); + currentUnitContract = await GetFullyPopulatedContractGraphFromIdAsync(proposedUnitInfo.ContractId); if (currentUnitContract != null && currentUnitContract.Active) { //iterate work order and check for other contracted unit @@ -6200,14 +6201,40 @@ namespace AyaNova.Biz var w = await WorkOrderGetFullAsync(woId.WorkOrderId); //iterate, look for *other* woitemunit records, are they contracted already? + foreach (WorkOrderItem wi in w.Items) + { + if (AlreadyHasAContractedUnit) continue; + foreach (WorkOrderItemUnit wiu in wi.Units) + { + if (isNew || wiu.Id != currentObj.Id) + { + var existingUnitInfo = await ct.Unit.AsNoTracking().Where(x => x.Id == wiu.UnitId).Select(x => new { x.ContractExpires, x.ContractId }).FirstOrDefaultAsync(); + if (existingUnitInfo != null) + { + if (existingUnitInfo.ContractId != null && existingUnitInfo.ContractId != proposedUnitInfo.ContractId && existingUnitInfo.ContractExpires > DateTime.UtcNow) + { + //Ok, we have a pre-existing contract, is it active? + if (await ct.Contract.AsNoTracking().Where(x => x.Id == existingUnitInfo.ContractId).Select(x => x.Active).FirstOrDefaultAsync()) + { + AlreadyHasAContractedUnit = true; + continue; + } + } + } + } + } + } + if (AlreadyHasAContractedUnit) + { + AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "UnitId", await Translate("ErrorOneContractedUnitPerWorkOrderOnly")); + return;//this is a completely disqualifying error + } } else { currentUnitContract = null;//just in case it's non active but present so later biz actions don't process it } - } - - //check if there is another contracted unit already on this work order + } } diff --git a/server/AyaNova/resource/de.json b/server/AyaNova/resource/de.json index 102732b4..96b39751 100644 --- a/server/AyaNova/resource/de.json +++ b/server/AyaNova/resource/de.json @@ -1743,6 +1743,7 @@ "ErrorAPI2208": "Dieses Objekt ist mit anderen verknüpft und kann auf diese Weise nicht geändert werden", "ErrorAPI2209": "Dieser Wert kann nicht geändert werden", "ErrorAPI2210": "Untergeordneter Objektfehler", + "ErrorAPI2212": "Pro Arbeitsauftrag ist nur eine vertraglich vereinbarte Einheit zulässig", "ErrorServerUnresponsive": "Der Server reagiert nicht (E17)", "ErrorUserNotAuthenticated": "Nicht authentifiziert (E16)", "ErrorUserNotAuthorized": "Nicht autorisiert", diff --git a/server/AyaNova/resource/en.json b/server/AyaNova/resource/en.json index 2f5565ef..c4650ec1 100644 --- a/server/AyaNova/resource/en.json +++ b/server/AyaNova/resource/en.json @@ -1743,6 +1743,7 @@ "ErrorAPI2208": "This object is linked to others and can not be changed this way", "ErrorAPI2209": "This value cannot be changed", "ErrorAPI2210": "Child object error", + "ErrorAPI2212": "Only one Contracted Unit allowed per work order", "ErrorServerUnresponsive": "Server not responding (E17)", "ErrorUserNotAuthenticated": "Not authenticated (E16)", "ErrorUserNotAuthorized": "Not authorized", diff --git a/server/AyaNova/resource/es.json b/server/AyaNova/resource/es.json index b32db0c2..59c14a07 100644 --- a/server/AyaNova/resource/es.json +++ b/server/AyaNova/resource/es.json @@ -1743,6 +1743,7 @@ "ErrorAPI2208": "Este objeto está vinculado a otros y no puede ser cambiado de esta manera", "ErrorAPI2209": "Este valor no puede ser cambiado", "ErrorAPI2210": "Error de objeto secundario", + "ErrorAPI2212": "Solo se permite una unidad contratada por orden de trabajo", "ErrorServerUnresponsive": "El servidor no responde (E17)", "ErrorUserNotAuthenticated": "No autenticado (E16)", "ErrorUserNotAuthorized": "No autorizado", diff --git a/server/AyaNova/resource/fr.json b/server/AyaNova/resource/fr.json index 5f4ebf17..1de0ab22 100644 --- a/server/AyaNova/resource/fr.json +++ b/server/AyaNova/resource/fr.json @@ -1743,6 +1743,7 @@ "ErrorAPI2208": "Cet objet est lié à d'autres et ne peut pas être modifié de cette façon", "ErrorAPI2209": "Cette valeur ne peut pas être changée", "ErrorAPI2210": "Erreur d'objet enfant", + "ErrorAPI2212": "Une seule unité sous contrat autorisée par bon de travail", "ErrorServerUnresponsive": "Le serveur ne répond pas (E17)", "ErrorUserNotAuthenticated": "Non authentifié (E16)", "ErrorUserNotAuthorized": "Non autorisé",