public bool InsertDetails(Session session, int shippingID, int?itemID, string lot, int?quantity, int?units, float?pallets, string reason, DateTime?expirationDate) { SPG.ShippingReturnDetailsDataTable details = new SPG.ShippingReturnDetailsDataTable(); SPG.ShippingReturnDetailsRow returnDetail = details.NewShippingReturnDetailsRow(); returnDetail.ShipMainID = shippingID; returnDetail.ReturnDetItemID = itemID.Value; if (string.IsNullOrEmpty(lot)) { returnDetail.SetReturnDetLotNull(); } else { returnDetail.ReturnDetLot = lot; } returnDetail.ReturnDetQty = quantity.Value; returnDetail.intUnits = units.Value; if (!pallets.HasValue) { returnDetail.SetsngPalletsNull(); } else { returnDetail.sngPallets = pallets.Value; } if (string.IsNullOrEmpty(reason)) { returnDetail.SetReasonNull(); } else { returnDetail.Reason = reason; } if (expirationDate.HasValue) { returnDetail.ExpirationDate = expirationDate.Value; } else { returnDetail.SetExpirationDateNull(); } details.AddShippingReturnDetailsRow(returnDetail); int rowsAffected = Adapter.Update(details); if (rowsAffected == 1) { ItemsBLL items = new ItemsBLL(); items.UpdateStock(session, itemID.Value, units.Value * -1, false, session.GetObjectByKey <Shipping>(shippingID).ShippingLocation.Oid); } return(rowsAffected == 1); }
public bool UpdateShippingReturnDetails(Session session, int?detailID, int receivingID, int?itemID, string lot, int?quantity, int?units, float?pallets, string reason, DateTime?expirationDate) { if (!itemID.HasValue) { throw new ApplicationException("You must provide return item."); } if (!quantity.HasValue || !units.HasValue) { throw new ApplicationException("You must provide the Quantity\\Units returned."); } SPG.ShippingReturnDetailsDataTable details = Adapter.GetShippingReturnDetailByID(detailID.Value); if (details.Count() == 0) { //It is a new Detail return(InsertDetails(session, receivingID, itemID, lot, quantity, units, pallets, reason, expirationDate)); } SPG.ShippingReturnDetailsRow returnDetail = details[0]; int originalItem = 0; int originalQuantity = 0; int newQuantity = 0; bool itemChanged = false; object[] originalRecord = returnDetail.ItemArray; originalItem = returnDetail.ReturnDetItemID; if (itemID.HasValue && originalItem != itemID.Value) { itemChanged = true; } returnDetail.ReturnDetItemID = itemID.Value; if (string.IsNullOrEmpty(lot)) { returnDetail.SetReturnDetLotNull(); } else { returnDetail.ReturnDetLot = lot; } returnDetail.ReturnDetQty = quantity.Value; originalQuantity = returnDetail.intUnits; newQuantity = returnDetail.intUnits - units.Value; returnDetail.intUnits = units.Value; if (!pallets.HasValue) { returnDetail.SetsngPalletsNull(); } else { returnDetail.sngPallets = pallets.Value; } if (string.IsNullOrEmpty(reason)) { returnDetail.SetReasonNull(); } else { returnDetail.Reason = reason; } if (expirationDate.HasValue) { returnDetail.ExpirationDate = expirationDate.Value; } else { returnDetail.SetExpirationDateNull(); } if (!(originalRecord == null)) { UpdateAuditTrail(returnDetail, originalRecord); } int rowsAffected = Adapter.Update(returnDetail); if (rowsAffected == 1) { ItemsBLL items = new ItemsBLL(); int locationID = session.GetObjectByKey <Shipping>(receivingID).ShippingLocation.Oid; if (itemChanged == true) { items.UpdateStock(session, originalItem, originalQuantity, false, locationID); items.UpdateStock(session, itemID.Value, units.Value * -1, false, locationID); } else { if (newQuantity != 0) { items.UpdateStock(session, itemID.Value, newQuantity, false, locationID); } } } return(rowsAffected == 1); }