// Retrieving the relevant aggregated by dept list for inventory retrieval public List <WCF_TempInventoryRetrieval> GetRelevantListByDept(string itemID, string token) { //Check if user is authorizated to use this method. If is not authorized, it will return a json with -1 in the primary key if (!IsAuthanticateUser(token)) { List <WCF_TempInventoryRetrieval> wcf_UnAuthObj = new List <WCF_TempInventoryRetrieval>(); WCF_TempInventoryRetrieval wcfUnAuth = new WCF_TempInventoryRetrieval(); wcfUnAuth.RequestID = -1; wcf_UnAuthObj.Add(wcfUnAuth); return(wcf_UnAuthObj); } var temp = InventoryLogic.RetrieveTempInventoryList(itemID); List <WCF_TempInventoryRetrieval> wcfList = new List <WCF_TempInventoryRetrieval>(); foreach (var i in temp) { WCF_TempInventoryRetrieval w = WCF_TempInventoryRetrieval.Create(i.RequestID, i.RequestDetailID, i.ItemID, i.DepartmentID, i.RequestedQty, i.ActualQty, i.IsOverride); wcfList.Add(w); } return(wcfList); }
// Creating new entry public string SubmitInventoryRetrieval(List <WCF_TempInventoryRetrieval> tempList, string token) { //Check if user is authorizated to use this method. If is not authorized, it will return a json with -1 in the primary key if (!IsAuthanticateUser(token)) { List <WCF_TempInventoryRetrieval> wcf_UnAuthObj = new List <WCF_TempInventoryRetrieval>(); WCF_TempInventoryRetrieval wcfUnAuth = new WCF_TempInventoryRetrieval(); wcfUnAuth.RequestID = -1; wcf_UnAuthObj.Add(wcfUnAuth); return("Invalid user."); } bool anyErrors1 = false; bool anyErrors2 = true; // Checking against existing quantity in the store currently string itemID = ""; int totalRetrievedQty = 0; foreach (var item in tempList) { itemID = item.ItemID; totalRetrievedQty += item.ActualQty; } int currentQty = InventoryLogic.GetQuantity(itemID); if (totalRetrievedQty > currentQty) { anyErrors1 = true; } bool isEnough = true; // If still no errors, will perform more checks till an error is found. if (!anyErrors1) { foreach (var item in tempList) { InventoryCatalogue ic = InventoryLogic.FindItemByItemID(itemID); //Check if there is insufficient quantity in the inventory if (ic.UnitsInStock < item.RequestedQty || ic.UnitsInStock < item.RequestedQty) { isEnough = false; if (!isEnough && ic.UnitsInStock < item.RequestedQty) { anyErrors1 = true; } } //If inventory is not enough and isOverride is true if (item.IsOverride) { isEnough = false; anyErrors2 = false; } //Check if user is withdrawing more than requested if (item.RequestedQty < item.ActualQty) { anyErrors1 = true; } //Check if user is withdrawing less than requested despite having enough in the inventory if (isEnough && item.RequestedQty > item.ActualQty && !item.IsOverride) { anyErrors1 = true; } if (anyErrors1) { break; } } } // If there is a single error, the process will terminate without updating any of the entries if (anyErrors1 && anyErrors2) { return("Failure."); } else { foreach (WCF_TempInventoryRetrieval item in tempList) { string str = InventoryLogic.CreateNewInventoryRetrievalEntry(item.RequestID, item.RequestDetailID, item.ItemID, item.DepartmentID, item.RequestedQty, item.ActualQty, item.IsOverride); } return("Success."); } }