private tblMove GetOrCreateOldContextOrder(InventoryShipmentOrder order, bool createdNew, out bool commitNewContext) { commitNewContext = false; if (createdNew || order.MoveNum == null) { commitNewContext = true; var tblMove = new tblMove { MoveNum = (order.MoveNum = GetNextMoveNum(order.DateCreated.Year)).Value, TTypeID = (int)order.OrderType.ToTransType(), EntryDate = DateTime.UtcNow.ConvertUTCToLocal(), tblMoveOrderDetails = new EntityCollection <tblMoveOrderDetail>(), tblMoveDetails = new EntityCollection <tblMoveDetail>(), Status = (int?)tblOrderStatus.Scheduled }; OldContext.tblMoves.AddObject(tblMove); return(tblMove); } return(OldContext.tblMoves .Where(m => m.MoveNum == order.MoveNum.Value) .Select(m => new { move = m, m.tblMoveOrderDetails, m.tblMoveDetails }) .ToList() .Select(m => m.move).Single()); }
private void SyncMove(InventoryShipmentOrder order) { var tblMove = OldContext.tblMoves .Where(m => m.MoveNum == order.MoveNum) .Select(o => new { order = o, details = o.tblMoveDetails }) .FirstOrDefault(); if (tblMove == null) { throw new Exception(string.Format("Could not find tblMove[{0}]", order.MoveNum)); } var tblMoveDetails = tblMove.details.ToDictionary(d => d.MDetail); foreach (var item in order.PickedInventory.Items) { if (item.DetailID == null) { throw new Exception(string.Format("Missing DetailID on PicedInventoryItem for order with MoveNum[{0}]", order.MoveNum)); } var detail = tblMoveDetails[item.DetailID.Value]; detail.LocID = item.CurrentLocation.LocID.Value; detail.Move2 = null; OldContext.tblOutgoings.AddObject(CreateOutgoing(order, item, item.FromLocation, item.Quantity, true)); OldContext.tblOutgoings.AddObject(CreateOutgoing(order, item, item.CurrentLocation, -item.Quantity, true)); } tblMove.order.Status = (int?)tblOrderStatus.Shipped; }
internal static void SetHeaderParameters(this InventoryShipmentOrder order, ISetOrderHeaderParameters parameters) { order.PurchaseOrderNumber = parameters.CustomerPurchaseOrderNumber; order.DateReceived = parameters.DateOrderReceived; order.RequestedBy = parameters.OrderRequestedBy; order.TakenBy = parameters.OrderTakenBy; }
public static void SetOrderShipment(InventoryShipmentOrder newOrder, tblMove oldOrder) { oldOrder.PalletOR = (decimal?)newOrder.ShipmentInformation.PalletWeight; oldOrder.PalletQty = newOrder.ShipmentInformation.PalletQuantity; oldOrder.FreightBillType = newOrder.ShipmentInformation.FreightBillType; oldOrder.ShipVia = newOrder.ShipmentInformation.ShipmentMethod; oldOrder.Driver = newOrder.ShipmentInformation.DriverName; oldOrder.Carrier = newOrder.ShipmentInformation.CarrierName; oldOrder.TrlNbr = newOrder.ShipmentInformation.TrailerLicenseNumber; oldOrder.ContSeal = newOrder.ShipmentInformation.ContainerSeal; oldOrder.InternalNotes = newOrder.ShipmentInformation.InternalNotes; oldOrder.ExternalNotes = newOrder.ShipmentInformation.ExternalNotes; oldOrder.SpclInstr = newOrder.ShipmentInformation.SpecialInstructions; oldOrder.PONbr = newOrder.PurchaseOrderNumber; oldOrder.DateRecd = newOrder.DateReceived; oldOrder.From = newOrder.RequestedBy; oldOrder.TakenBy = newOrder.TakenBy; oldOrder.DelDueDate = newOrder.ShipmentInformation.RequiredDeliveryDate; oldOrder.SchdShipDate = newOrder.ShipmentInformation.ShipmentDate; oldOrder.Date = newOrder.ShipmentInformation.ShipmentDate; oldOrder.CCompany = newOrder.ShipmentInformation.ShipFrom.Name; //oldOrder.CPhone = newOrder.ShipmentInformation.ShipFrom.Phone; //oldOrder.CEmail = newOrder.ShipmentInformation.ShipFrom.EMail; //oldOrder.CFax = newOrder.ShipmentInformation.ShipFrom.Fax; oldOrder.CAddress1 = newOrder.ShipmentInformation.ShipFrom.Address.AddressLine1; oldOrder.CAddress2 = newOrder.ShipmentInformation.ShipFrom.Address.AddressLine2; oldOrder.CAddress3 = newOrder.ShipmentInformation.ShipFrom.Address.AddressLine3; oldOrder.CCity = newOrder.ShipmentInformation.ShipFrom.Address.City; oldOrder.CState = newOrder.ShipmentInformation.ShipFrom.Address.State; oldOrder.CZip = newOrder.ShipmentInformation.ShipFrom.Address.PostalCode; oldOrder.CCountry = newOrder.ShipmentInformation.ShipFrom.Address.Country; oldOrder.SCompany = newOrder.ShipmentInformation.ShipTo.Name; oldOrder.SPhone = newOrder.ShipmentInformation.ShipTo.Phone; //oldOrder.SEmail = newOrder.ShipmentInformation.ShipTo.EMail; //oldOrder.SFax = newOrder.ShipmentInformation.ShipTo.Fax; oldOrder.SAddress1 = newOrder.ShipmentInformation.ShipTo.Address.AddressLine1; oldOrder.SAddress2 = newOrder.ShipmentInformation.ShipTo.Address.AddressLine2; oldOrder.SAddress3 = newOrder.ShipmentInformation.ShipTo.Address.AddressLine3; oldOrder.SCity = newOrder.ShipmentInformation.ShipTo.Address.City; oldOrder.SState = newOrder.ShipmentInformation.ShipTo.Address.State; oldOrder.SZip = newOrder.ShipmentInformation.ShipTo.Address.PostalCode; oldOrder.SCountry = newOrder.ShipmentInformation.ShipTo.Address.Country; oldOrder.Company = newOrder.ShipmentInformation.FreightBill.Name; oldOrder.Phone = newOrder.ShipmentInformation.FreightBill.Phone; oldOrder.Email = newOrder.ShipmentInformation.FreightBill.EMail; oldOrder.Fax = newOrder.ShipmentInformation.FreightBill.Fax; oldOrder.Address1 = newOrder.ShipmentInformation.FreightBill.Address.AddressLine1; oldOrder.Address2 = newOrder.ShipmentInformation.FreightBill.Address.AddressLine2; oldOrder.Address3 = newOrder.ShipmentInformation.FreightBill.Address.AddressLine3; oldOrder.City = newOrder.ShipmentInformation.FreightBill.Address.City; oldOrder.State = newOrder.ShipmentInformation.FreightBill.Address.State; oldOrder.Zip = newOrder.ShipmentInformation.FreightBill.Address.PostalCode; oldOrder.Country = newOrder.ShipmentInformation.FreightBill.Address.Country; }
private IResult ValidateModifyPickedInventoryItems(InventoryShipmentOrder order, IEnumerable <ModifyPickedInventoryItemParameters> items) { var validator = PickedInventoryValidator.ForInterWarehouseOrder(order.SourceFacility); var orderItems = order.InventoryPickOrder.Items.ToDictionary(i => i.ToInventoryPickOrderItemKey()); foreach (var item in items) { InventoryPickOrderItem orderItem = null; if (item.OrderItemKey != null && !orderItems.TryGetValue(item.OrderItemKey, out orderItem)) { return(new InvalidResult(string.Format(UserMessages.CannotPickForOrderItem_DoesNotExist, item.OrderItemKey))); } if (item.NewQuantity > item.OriginalQuantity) { Dictionary <string, Inventory> inventory; var validResult = validator.ValidateItems(_inventoryShipmentUnitOfWork.InventoryRepository, new[] { item.InventoryKey }, out inventory); IChileProductKey chileProduct; if (orderItem != null) { chileProduct = ChileProductKey.FromProductKey(orderItem.Product); } else { var lotKey = inventory.Single().Value.ToLotKey(); chileProduct = _inventoryShipmentUnitOfWork.ChileLotRepository.FindByKey(lotKey); if (chileProduct == null) { return(new InvalidResult(string.Format(UserMessages.ChileLotNotFound, lotKey))); } } IDictionary <AttributeNameKey, ChileProductAttributeRange> productSpec; IDictionary <AttributeNameKey, CustomerProductAttributeRange> customerSpec; var specResult = new GetProductSpecCommand(_inventoryShipmentUnitOfWork).Execute(chileProduct, orderItem == null ? null : orderItem.Customer, out productSpec, out customerSpec); if (!specResult.Success) { return(specResult); } var inventoryItem = inventory.Values.Single(); var context = new PickingValidatorContext(productSpec, customerSpec, null, null, orderItem == null ? null : orderItem.Customer); var pickable = new PickingValidator(inventoryItem.Lot); var pickableResult = pickable.ValidForPicking(context); if (!validResult.Success || !pickableResult.Success) { return(new InvalidResult(new[] { validResult, pickableResult }.CombineMessages())); } } } return(new SuccessResult()); }
private void SetMoveShipment(InventoryShipmentOrder newOrder) { var oldOrder = OldContext.tblMoves.FirstOrDefault(m => m.MoveNum == newOrder.MoveNum.Value); if (oldOrder == null) { throw new Exception(string.Format("Could not find tblMove[{0}].", newOrder.MoveNum.Value)); } SetOrderShipment(newOrder, oldOrder); }
protected InventoryShipmentOrder SetOrderProperties(InventoryShipmentOrder newOrder, MovementOrderDTO oldOrder) { newOrder.OrderType = GetOrderType(oldOrder.TTypeID); newOrder.MoveNum = oldOrder.MoveNum; newOrder.PurchaseOrderNumber = oldOrder.PONbr; newOrder.DateReceived = oldOrder.DateRecd; newOrder.RequestedBy = oldOrder.From; newOrder.TakenBy = oldOrder.TakenBy; newOrder.OrderStatus = GetOrderStatus(oldOrder.Status.ToTblOrderStatus()); return newOrder; }
internal static InventoryShipmentOrder SetSourceFacility(this InventoryShipmentOrder order, IFacilityKey facilityKey) { if (order == null) { throw new ArgumentNullException("order"); } order.SourceFacility = null; order.SourceFacilityId = facilityKey.FacilityKey_Id; return(order); }
protected override IResult <IInventoryValidator> GetInventoryValidator(InventoryShipmentOrder order) { var predicate = TreatmentOrderPredicates.ByInventoryShipmentOrder(order); var treatmentOrder = UnitOfWork.TreatmentOrderRepository.Filter(predicate).FirstOrDefault(); if (treatmentOrder == null) { return(new InvalidResult <IInventoryValidator>(null, string.Format(UserMessages.TreatmentOrderNotFound, new InventoryShipmentOrderKey(order)))); } treatmentOrder.InventoryShipmentOrder = order; return(new SuccessResult <IInventoryValidator>(PickedInventoryValidator.ForTreatmentOrder(treatmentOrder.InventoryShipmentOrder.SourceFacility, treatmentOrder, UnitOfWork))); }
private void SetPickedInventory(InventoryShipmentOrder newOrder, tblMove oldOrder, ref bool commitNewContext) { var MDetail = OldContext.tblMoveDetails.Any() ? OldContext.tblMoveDetails.Max(m => m.MDetail).AddSeconds(1) : DateTime.UtcNow.ConvertUTCToLocal(); var oldDetailsToRemove = oldOrder.tblMoveDetails.ToList(); foreach (var newItem in newOrder.PickedInventory.Items) { var oldItem = oldDetailsToRemove.FirstOrDefault(d => d.MDetail == newItem.DetailID) ?? oldDetailsToRemove.FirstOrDefault(); if (oldItem == null) { oldItem = new tblMoveDetail { MDetail = MDetail }; OldContext.tblMoveDetails.AddObject(oldItem); MDetail = MDetail.AddSeconds(1); } else { oldDetailsToRemove.Remove(oldItem); } oldItem.MoveNum = newOrder.MoveNum.Value; oldItem.Lot = LotNumberParser.BuildLotNumber(newItem); oldItem.TTypeID = (int?)newOrder.OrderType.ToTransType(); oldItem.PkgID = OldContextHelper.GetPackaging(newItem.PackagingProduct).PkgID; oldItem.Quantity = newItem.Quantity; oldItem.NetWgt = (decimal?)newItem.PackagingProduct.Weight; oldItem.TtlWgt = (decimal?)(newItem.Quantity * newItem.PackagingProduct.Weight); oldItem.LocID = newItem.FromLocation.LocID.Value; oldItem.Move2 = newItem.CurrentLocation.LocID.Value; oldItem.TrtmtID = OldContextHelper.GetTreatment(newItem).TrtmtID; oldItem.EmployeeID = newOrder.PickedInventory.EmployeeId; oldItem.CustProductCode = newItem.CustomerProductCode; oldItem.CustLot = newItem.CustomerLotCode; if (newItem.DetailID != oldItem.MDetail) { commitNewContext = true; newItem.DetailID = oldItem.MDetail; } } foreach (var o in oldDetailsToRemove) { OldContext.tblMoveDetails.DeleteObject(o); } }
internal static SetOrderHeaderParameters ToOrderHeaderParameters(this InventoryShipmentOrder order, Action <SetOrderHeaderParameters> initialize = null) { var parameters = new SetOrderHeaderParameters { CustomerPurchaseOrderNumber = order.PurchaseOrderNumber, DateOrderReceived = order.DateReceived, OrderTakenBy = order.TakenBy }; if (initialize != null) { initialize(parameters); } return(parameters); }
protected IResult <InventoryShipmentOrder> SetPickedItemCodes(InventoryShipmentOrder inventoryShipmentOrder, IEnumerable <SetPickedInventoryItemCodesParameters> setItemCodesParameters) { if (setItemCodesParameters != null) { foreach (var setItem in setItemCodesParameters) { var item = inventoryShipmentOrder.PickedInventory.Items.FirstOrDefault(setItem.PickedInventoryItemKey.FindByPredicate.Compile()); if (item == null) { return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.PickedInventoryItemNotFound, setItem.PickedInventoryItemKey))); } item.CustomerProductCode = setItem.Parameters.CustomerProductCode; item.CustomerLotCode = setItem.Parameters.CustomerLotCode; } } return(new SuccessResult <InventoryShipmentOrder>(inventoryShipmentOrder)); }
private void SetOrderShipment(InventoryShipmentOrder newOrder) { var customerOrder = UnitOfWork.SalesOrderRepository .Filter(o => o.InventoryShipmentOrder.DateCreated == newOrder.DateCreated && o.InventoryShipmentOrder.Sequence == newOrder.Sequence) .FirstOrDefault(); if (customerOrder.InventoryShipmentOrder == null) { customerOrder.InventoryShipmentOrder = newOrder; } var oldOrder = OldContext.tblOrders.FirstOrDefault(m => m.OrderNum == newOrder.MoveNum.Value); if (oldOrder == null) { throw new Exception(string.Format("Could not find tblOrder[{0}].", newOrder.MoveNum.Value)); } oldOrder.SetShippingInformation(customerOrder); }
private void SetPickOrder(InventoryShipmentOrder newOrder, tblMove oldOrder) { var MOrderDetail = OldContext.tblMoveOrderDetails.Any() ? OldContext.tblMoveOrderDetails.Max(m => m.MOrderDetail).AddSeconds(1) : DateTime.UtcNow.ConvertUTCToLocal(); var oldDetailsToRemove = oldOrder.tblMoveOrderDetails.ToList(); foreach (var newItem in newOrder.InventoryPickOrder.Items) { var oldItem = oldDetailsToRemove.FirstOrDefault(); if (oldItem == null) { oldItem = new tblMoveOrderDetail { MOrderDetail = MOrderDetail }; OldContext.tblMoveOrderDetails.AddObject(oldItem); MOrderDetail = MOrderDetail.AddSeconds(1); } else { oldDetailsToRemove.Remove(oldItem); } oldItem.MoveNum = newOrder.MoveNum.Value; oldItem.Quantity = newItem.Quantity; oldItem.ProdID = OldContextHelper.GetProduct(newItem.Product.ProductCode).ProdID; oldItem.PkgID = OldContextHelper.GetPackaging(newItem.PackagingProduct).PkgID; oldItem.NetWgt = (decimal?)newItem.PackagingProduct.Weight; oldItem.TtlWgt = (decimal?)(newItem.PackagingProduct.Weight * newItem.Quantity); oldItem.TrtmtID = OldContextHelper.GetTreatment(newItem).TrtmtID; oldItem.EmployeeID = null; oldItem.CustProductCode = newItem.CustomerProductCode; oldItem.CustLot = newItem.CustomerLotCode; oldItem.CustomerID = newItem.Customer != null ? newItem.Customer.Company.Name : null; } foreach (var o in oldDetailsToRemove) { OldContext.tblMoveOrderDetails.DeleteObject(o); } }
private void SyncOrder(InventoryShipmentOrder order) { var tblOrder = OldContext.tblOrders .Where(o => o.OrderNum == order.MoveNum) .Select(o => new { order = o, details = o.tblOrderDetails.Select(d => new { d, staged = d.tblStagedFGs }) }) .FirstOrDefault(); if (tblOrder == null) { throw new Exception(string.Format("Could not find tblOrder[{0}]", order.MoveNum)); } var tblStagedFGs = tblOrder.order.tblOrderDetails.SelectMany(d => d.tblStagedFGs) .ToDictionary(f => f.EntryDate); foreach (var item in order.PickedInventory.Items) { if (item.DetailID == null) { throw new Exception(string.Format("Missing DetailID on PickedInventoryItem for order with MoveNum[{0}]", order.MoveNum)); } var detail = tblStagedFGs[item.DetailID.Value]; detail.LocID = item.CurrentLocation.LocID.Value; OldContext.tblOutgoings.AddObject(CreateOutgoing(order, item, item.FromLocation, item.Quantity, false)); } tblOrder.order.Status = (int?)tblOrderStatus.Shipped; }
internal static InventoryShipmentOrder EmptyItems(this InventoryShipmentOrder order) { if (order == null) { throw new ArgumentNullException("order "); } if (order.InventoryPickOrder != null) { order.InventoryPickOrder.EmptyItems(); if (order.InventoryPickOrder.PickedInventory != null) { order.InventoryPickOrder.PickedInventory.EmptyItems(); } } if (order.PickedInventory != null) { order.PickedInventory.EmptyItems(); } return(order); }
protected IResult DeleteInventoryShipmentOrder(InventoryShipmentOrder inventoryShipmentOrder) { if (inventoryShipmentOrder == null) { throw new ArgumentNullException("inventoryShipmentOrder"); } if (inventoryShipmentOrder.OrderStatus == OrderStatus.Fulfilled) { return(new InvalidResult(UserMessages.CannotDeleteFulfilledShipmentOrder)); } if (inventoryShipmentOrder.ShipmentInformation.Status == ShipmentStatus.Shipped) { return(new InvalidResult(UserMessages.CannotDeleteShippedShipmentOrder)); } var removePickedItems = UpdatePickedInventory(null, null, DateTime.UtcNow, inventoryShipmentOrder.PickedInventory, null); if (!removePickedItems.Success) { return(removePickedItems); } var removePickOrderItems = new DeleteInventoryPickOrderItems(UnitOfWork).Execute(inventoryShipmentOrder.InventoryPickOrder); if (!removePickOrderItems.Success) { return(removePickOrderItems); } UnitOfWork.PickedInventoryRepository.Remove(inventoryShipmentOrder.PickedInventory); UnitOfWork.InventoryShipmentOrderRepository.Remove(inventoryShipmentOrder); return(new SuccessResult()); }
private tblOutgoing CreateOutgoing(InventoryShipmentOrder order, PickedInventoryItem item, Location location, int quantity, bool forMove) { return(new tblOutgoing { EntryDate = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL(), Lot = LotNumberParser.BuildLotNumber(item), TTypeID = (int?)order.OrderType.ToTransType(), PkgID = OldContextHelper.GetPackaging(item.PackagingProduct).PkgID, Tote = item.ToteKey, Quantity = quantity, NetWgt = (decimal?)item.PackagingProduct.Weight, TtlWgt = (decimal?)(quantity * item.PackagingProduct.Weight), LocID = (int)location.LocID, TrtmtID = OldContextHelper.GetTreatment(item).TrtmtID, EmployeeID = order.EmployeeId, BOMID = 0, BatchLot = 0, MoveNum = forMove ? order.MoveNum : null, MDetail = forMove ? item.DetailID : null, OrderNum = !forMove ? order.MoveNum : null, ODetail = !forMove ? item.DetailID : null, CustProductCode = item.CustomerProductCode }); }
internal IResult <InventoryShipmentOrder> Update <TParams>(InventoryShipmentOrder inventoryShipmentOrder, DateTime timeStamp, SetInventoryShipmentOrderConductorParameters <TParams> parameters) where TParams : ISetOrderParameters { return(SetOrder(inventoryShipmentOrder, timeStamp, parameters)); }
internal IResult <InventoryShipmentOrder> Create <TParams>(DateTime timestamp, SetInventoryShipmentOrderConductorParameters <TParams> parameters) where TParams : ISetOrderParameters { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_interWarehouseOrderUnitOfWork).GetEmployee(parameters.Params); if (!employeeResult.Success) { return(employeeResult.ConvertTo <InventoryShipmentOrder>()); } var pickedInventoryResult = new CreatePickedInventoryCommand(_interWarehouseOrderUnitOfWork).Execute(new CreatePickedInventoryCommandParameters { EmployeeKey = new EmployeeKey(employeeResult.ResultingObject), TimeStamp = timestamp, PickedReason = PickedReason.InterWarehouseMovement }); if (!pickedInventoryResult.Success) { return(pickedInventoryResult.ConvertTo <InventoryShipmentOrder>()); } var pickedOrderResult = new CreateInventoryPickOrderCommand(_interWarehouseOrderUnitOfWork).Execute(pickedInventoryResult.ResultingObject); if (!pickedOrderResult.Success) { return(pickedOrderResult.ConvertTo <InventoryShipmentOrder>()); } var shipmentInfoResult = new CreateShipmentInformationCommand(_interWarehouseOrderUnitOfWork).Execute(timestamp, parameters.Params.SetShipmentInformation); if (!shipmentInfoResult.Success) { return(shipmentInfoResult.ConvertTo <InventoryShipmentOrder>()); } var order = new InventoryShipmentOrder { OrderType = InventoryShipmentOrderTypeEnum.InterWarehouseOrder, OrderStatus = OrderStatus.Scheduled, DateCreated = pickedInventoryResult.ResultingObject.DateCreated, Sequence = pickedInventoryResult.ResultingObject.Sequence, PickedInventory = pickedInventoryResult.ResultingObject, InventoryPickOrder = pickedOrderResult.ResultingObject, ShipmentInformation = shipmentInfoResult.ResultingObject, ShipmentInfoDateCreated = shipmentInfoResult.ResultingObject.DateCreated, ShipmentInfoSequence = shipmentInfoResult.ResultingObject.Sequence, MoveNum = new GetMoveNum(_interWarehouseOrderUnitOfWork.InventoryShipmentOrderRepository).Get(pickedInventoryResult.ResultingObject.DateCreated.Year) }; if (parameters.Params.HeaderParameters != null) { order.SetHeaderParameters(parameters.Params.HeaderParameters); } order = _interWarehouseOrderUnitOfWork.InventoryShipmentOrderRepository.Add(order); return(new UpdateInterWarehouseOrderConductor(_interWarehouseOrderUnitOfWork).Update(order, timestamp, parameters)); }
public void SetOrder(InventoryShipmentOrder order) { order.EmployeeId = Identifiable.EmployeeKey.EmployeeKeyId; order.TimeStamp = Identifiable.TimeStamp; }
public SerializableMove(InventoryShipmentOrder order) { Identifiable = new SerializableEmployeeIdentifiable(order); }
public static string Serialize(InventoryShipmentOrder order) { return(JsonConvert.SerializeObject(new SerializableMove(order), Formatting.None)); }
protected abstract IResult <IInventoryValidator> GetInventoryValidator(InventoryShipmentOrder order);
protected IResult <InventoryShipmentOrder> SetOrder <TParams>(InventoryShipmentOrder inventoryShipmentOrder, DateTime timeStamp, SetInventoryShipmentOrderConductorParameters <TParams> parameters) where TParams : ISetOrderParameters { if (inventoryShipmentOrder == null) { throw new ArgumentNullException("inventoryShipmentOrder"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(UnitOfWork).GetEmployee(parameters.Params); if (!employeeResult.Success) { return(employeeResult.ConvertTo <InventoryShipmentOrder>()); } inventoryShipmentOrder.EmployeeId = employeeResult.ResultingObject.EmployeeId; inventoryShipmentOrder.TimeStamp = timeStamp; if (parameters.Params.HeaderParameters != null) { inventoryShipmentOrder.SetHeaderParameters(parameters.Params.HeaderParameters); } if (parameters.DestinationFacilityKey != null) { var destinationFacility = UnitOfWork.FacilityRepository.FindByKey(parameters.DestinationFacilityKey, f => f.Locations); if (destinationFacility == null) { return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.FacilityNotFound, parameters.DestinationFacilityKey))); } var validateFacility = ValidateDestinationFacility(destinationFacility); if (!validateFacility.Success) { return(validateFacility.ConvertTo <InventoryShipmentOrder>()); } inventoryShipmentOrder.DestinationFacility = destinationFacility; inventoryShipmentOrder.DestinationFacilityId = destinationFacility.Id; } if (parameters.SourceFacilityKey != null) { var sourceFacility = UnitOfWork.FacilityRepository.FindByKey(parameters.SourceFacilityKey, f => f.Locations); if (sourceFacility == null) { return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.FacilityNotFound, parameters.SourceFacilityKey))); } var currentKeys = inventoryShipmentOrder.PickedInventory.Items.Select(i => new LocationKey(i.FromLocation)).ToList(); if (currentKeys.Any(l => sourceFacility.Locations.All(c => !l.Equals(c)))) { return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.SourceLocationMustBelongToFacility, parameters.SourceFacilityKey))); } inventoryShipmentOrder.SourceFacility = sourceFacility; inventoryShipmentOrder.SourceFacilityId = sourceFacility.Id; } if (parameters.Params.SetShipmentInformation != null) { inventoryShipmentOrder.ShipmentInformation.SetShipmentInformation(parameters.Params.SetShipmentInformation); } if (parameters.Params.InventoryPickOrderItems != null) { var pickOrderResult = new InventoryPickOrderCommand(UnitOfWork).Execute(inventoryShipmentOrder.InventoryPickOrder, parameters.PickOrderItems); if (!pickOrderResult.Success) { return(pickOrderResult.ConvertTo <InventoryShipmentOrder>()); } } return(new SuccessResult <InventoryShipmentOrder>(inventoryShipmentOrder)); }
private static IResult <List <ModifyInventoryParameters> > PostOrder(Parameters parameters, InventoryShipmentOrder order, IEmployeeKey employee) { if (order == null) { throw new ArgumentNullException("order"); } if (employee == null) { throw new ArgumentNullException("order"); } if (order.OrderStatus == OrderStatus.Fulfilled) { switch (order.OrderType) { case InventoryShipmentOrderTypeEnum.InterWarehouseOrder: return(new InvalidResult <List <ModifyInventoryParameters> >(null, string.Format(UserMessages.InterWarehouseOrderAlreadyFulfilled, order.ToInventoryShipmentOrderKey()))); case InventoryShipmentOrderTypeEnum.TreatmentOrder: return(new InvalidResult <List <ModifyInventoryParameters> >(null, string.Format(UserMessages.TreatmentOrderAlreadyFulfilled, order.ToInventoryShipmentOrderKey()))); case InventoryShipmentOrderTypeEnum.SalesOrder: case InventoryShipmentOrderTypeEnum.MiscellaneousOrder: return(new InvalidResult <List <ModifyInventoryParameters> >(null, string.Format(UserMessages.SalesOrderAlreadyFulfilled, order.ToInventoryShipmentOrderKey()))); default: throw new ArgumentOutOfRangeException("order.OrderType"); } } if (order.ShipmentInformation.Status == ShipmentStatus.Shipped) { return(new InvalidResult <List <ModifyInventoryParameters> >(null, string.Format(UserMessages.ShipmentStatusCannotPost, order.ShipmentInformation.Status))); } var inventoryModifications = new List <ModifyInventoryParameters>(); foreach (var item in order.PickedInventory.Items) { var pickedItemKey = new PickedInventoryItemKey(item); var itemParameters = parameters.ItemParams.FirstOrDefault(i => i.ItemKey.Equals(pickedItemKey)); if (itemParameters == null) { if (order.DestinationFacility != null) { return(new InvalidResult <List <ModifyInventoryParameters> >(null, string.Format(UserMessages.DestinationLocationRequiredForPicked, pickedItemKey))); } } else if (itemParameters.DestinationKey != null) { if (order.DestinationFacility != null && !order.DestinationFacility.Locations.Any(l => itemParameters.DestinationKey.Equals(l))) { return(new InvalidResult <List <ModifyInventoryParameters> >(null, string.Format(UserMessages.DestinationLocationMustBelongToFacility, new FacilityKey(order.DestinationFacility)))); } item.CurrentLocationId = itemParameters.DestinationKey.LocationKey_Id; inventoryModifications.Add(item.ToModifyInventoryDestinationParameters(itemParameters.DestinationKey)); } } order.ShipmentInformation.Status = ShipmentStatus.Shipped; order.EmployeeId = employee.EmployeeKey_Id; return(new SuccessResult <List <ModifyInventoryParameters> >(inventoryModifications)); }