private static void postReleaseLine(ReleaseLine releaseLine, ReleaseHeader releaseHeader) { WarehouseEntry warehouseEntry = new WarehouseEntry(); using (DBContext dBCtx = new DBContext()) { StockKeepUnit stku = dBCtx.StockKeepUnits.Single(x => x.Code == releaseLine.StockKeepUnit); warehouseEntry.ItemID = releaseLine.ItemID; warehouseEntry.DocumentNumber = releaseLine.DocumentID; warehouseEntry.EntryType = EntryType.Release; warehouseEntry.TotalQuantity = -(releaseLine.ReleaseQuantity * stku.QuantityPerUnit); warehouseEntry.Quantity = -(releaseLine.ReleaseQuantity); warehouseEntry.QuantityPerUnit = stku.QuantityPerUnit; warehouseEntry.KeepUnit = releaseLine.StockKeepUnit; warehouseEntry.WarehouseNumber = releaseLine.WarehouseNumber; warehouseEntry.WarehousePlace = releaseLine.WarehousePlace; warehouseEntry.CustomerID = releaseHeader.CustomerID; warehouseEntry.DocumentDate = releaseHeader.ReleaseDate; warehouseEntry.DocumentDescription = releaseHeader.Description; dBCtx.WarehouseEntries.Add(warehouseEntry); ReleaseLine releaseLineUpdate = dBCtx.ReleaseLines.First(x => x.DocumentID == releaseLine.DocumentID && x.PositionNumber == releaseLine.PositionNumber); dBCtx.ReleaseLines.Attach(releaseLineUpdate); releaseLineUpdate.ReleasedQuantity = releaseLineUpdate.ReleasedQuantity + releaseLine.ReleaseQuantity; releaseLineUpdate.ReleaseQuantity = 0.00; dBCtx.SaveChanges(); } }
public static string isReleaseHeaderValid(ReleaseHeader releaseHeader) { string errorMsg = null; if (String.IsNullOrEmpty(releaseHeader.DocumentID)) { errorMsg += "\nPusty ID dokumentu"; } if (String.IsNullOrEmpty(releaseHeader.Description)) { errorMsg += "\nPusty opis"; } if (releaseHeader.ReleaseDate < DateTime.Today) { errorMsg += "\nNieprawidłowa data"; } if (String.IsNullOrEmpty(releaseHeader.CustomerID)) { errorMsg += "\nPusta nazwa klienta"; } return(errorMsg); }
public static string isReleaseHeaderAvaibleToDelete(ReleaseHeader releaseHeader) { string errorMsg = null; using (DBContext dBCtx = new DBContext()) { if (dBCtx.ReleaseLines.Any(x => x.DocumentID == releaseHeader.DocumentID)) { errorMsg = "Nie można usunąć nagłówka wydania, ponieważ istnieją dla niego zdefiniowane linie wydań."; return(errorMsg); } return(errorMsg); } }
//Release public static string postReleaseHeader(ReleaseHeader releaseHeader) { string errorMsg = null; bool isLineToPost = false; List <ReleaseLine> releaseLines; using (DBContext dBCtx = new DBContext()) { if (!dBCtx.ReleaseLines.Any(x => x.DocumentID == releaseHeader.DocumentID)) { return("Dokument nie posiada pozycji"); } releaseLines = dBCtx.ReleaseLines.Where(x => x.DocumentID == releaseHeader.DocumentID).ToList(); foreach (ReleaseLine releaseLine in releaseLines) { errorMsg = chceckReleaseLine(releaseLine); if (!String.IsNullOrEmpty(errorMsg)) { return(errorMsg); } if (chceckQuantityToRelease(releaseLine)) { isLineToPost = true; } if (!String.IsNullOrEmpty(errorMsg)) { return(errorMsg); } } } if (!isLineToPost) { return("Nie uzupełniono ilości do realizacji"); } foreach (ReleaseLine releaseLine in releaseLines) { if (releaseLine.ReleaseQuantity > 0.00) { postReleaseLine(releaseLine, releaseHeader); } } return(""); }