diff --git a/docs/8.0/ayanova/docs/api-error-codes.md b/docs/8.0/ayanova/docs/api-error-codes.md index 56cfeff2..2990cdd4 100644 --- a/docs/8.0/ayanova/docs/api-error-codes.md +++ b/docs/8.0/ayanova/docs/api-error-codes.md @@ -20,6 +20,7 @@ Here are all the API level error codes that can be returned by the API server: | 2010 | Object not found - API could not find the object requested | | 2020 | PUT Id mismatch - object Id does not match route Id | | 2030 | Invalid operation - operation could not be completed, not valid, details in message property | +| 2040 | Not enough inventory - too few parts in stock to complete operation | | 2200 | Validation error - general issue with object overall not valid, specifics in "details" property | | 2201 | Validation error - Field is required but is empty or null | | 2202 | Validation error - Field length exceeded. The limit will be returned in the `message` property of the validation error | diff --git a/server/AyaNova/biz/ApiErrorCode.cs b/server/AyaNova/biz/ApiErrorCode.cs index 51fa4f5a..45c24651 100644 --- a/server/AyaNova/biz/ApiErrorCode.cs +++ b/server/AyaNova/biz/ApiErrorCode.cs @@ -19,6 +19,7 @@ namespace AyaNova.Biz NOT_FOUND = 2010, PUT_ID_MISMATCH = 2020, INVALID_OPERATION = 2030, + INSUFFICIENT_INVENTORY = 2040, VALIDATION_FAILED = 2200, VALIDATION_REQUIRED = 2201, VALIDATION_LENGTH_EXCEEDED = 2202, diff --git a/server/AyaNova/biz/PartInventoryBiz.cs b/server/AyaNova/biz/PartInventoryBiz.cs index b2189a08..6fc0138b 100644 --- a/server/AyaNova/biz/PartInventoryBiz.cs +++ b/server/AyaNova/biz/PartInventoryBiz.cs @@ -4,12 +4,9 @@ using Microsoft.EntityFrameworkCore; using System.Linq; using AyaNova.Util; using AyaNova.Api.ControllerHelpers; -using Microsoft.Extensions.Logging; using AyaNova.Models; using Newtonsoft.Json.Linq; using System.Collections.Generic; -using Newtonsoft.Json; -using Microsoft.EntityFrameworkCore.Storage; namespace AyaNova.Biz { @@ -237,14 +234,18 @@ namespace AyaNova.Biz return; } - //Balance must not be negative - if (proposedObj.Balance < 0 ) + //Balance must not be negative + //return the current balance + if (proposedObj.Balance < 0) { - AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Balance", "Transaction would result in a negative balance (not enough inventory to process this transaction)"); + string currentBalance = "0"; + if (proposedObj.LastBalance != null) + currentBalance = proposedObj.LastBalance.ToString(); + AddError(ApiErrorCode.INSUFFICIENT_INVENTORY, "Balance", $"available:{currentBalance}"); return; } - + //date is newer than last entry date? if (proposedObj.LastEntryDate != null && proposedObj.LastEntryDate > proposedObj.EntryDate) { diff --git a/server/AyaNova/resource/de.json b/server/AyaNova/resource/de.json index 04a512cd..76a76985 100644 --- a/server/AyaNova/resource/de.json +++ b/server/AyaNova/resource/de.json @@ -1727,6 +1727,7 @@ "ErrorAPI2010": "Objekt nicht gefunden", "ErrorAPI2020": "Die Routen-ID stimmt nicht mit der Objectid überein", "ErrorAPI2030": "Ungültiger Vorgang", + "ErrorAPI2040": "Nicht genügend Inventar", "ErrorAPI2200": "Validierungsfehler", "ErrorAPI2201": "Fehlendes Pflichtfeld", "ErrorAPI2202": "Maximale Länge überschritten", diff --git a/server/AyaNova/resource/en.json b/server/AyaNova/resource/en.json index eca33edf..2f5051d0 100644 --- a/server/AyaNova/resource/en.json +++ b/server/AyaNova/resource/en.json @@ -1727,6 +1727,7 @@ "ErrorAPI2010": "Object not found", "ErrorAPI2020": "Route id doesn't match object id", "ErrorAPI2030": "Invalid operation", + "ErrorAPI2040": "Not enough inventory", "ErrorAPI2200": "Validation error", "ErrorAPI2201": "Required field", "ErrorAPI2202": "Length exceeded", diff --git a/server/AyaNova/resource/es.json b/server/AyaNova/resource/es.json index a27ec560..59190567 100644 --- a/server/AyaNova/resource/es.json +++ b/server/AyaNova/resource/es.json @@ -1727,6 +1727,7 @@ "ErrorAPI2010": "Objeto no encontrado", "ErrorAPI2020": "La ID de ruta no coincide con la ID de objeto", "ErrorAPI2030": "Operación no válida", + "ErrorAPI2040": "No hay suficiente inventario", "ErrorAPI2200": "Error de validación", "ErrorAPI2201": "Campo requerido", "ErrorAPI2202": "Longitud excedida", diff --git a/server/AyaNova/resource/fr.json b/server/AyaNova/resource/fr.json index afff32d7..7226680c 100644 --- a/server/AyaNova/resource/fr.json +++ b/server/AyaNova/resource/fr.json @@ -1727,6 +1727,7 @@ "ErrorAPI2010": "Objet introuvable", "ErrorAPI2020": "L'ID de route ne correspond pas à l'ID d'objet", "ErrorAPI2030": "Opération non valide", + "ErrorAPI2040": "Pas assez d'inventaire", "ErrorAPI2200": "Erreur de validation", "ErrorAPI2201": "Champ obligatoire", "ErrorAPI2202": "Longueur maximale dépassée",