This commit is contained in:
2021-07-16 19:22:13 +00:00
parent dc280f41cd
commit e2526e5498
8 changed files with 44 additions and 10 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": "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\\"

View File

@@ -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 |
| 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) |

View File

@@ -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 |

View File

@@ -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
}
}

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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é",