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());
        }
Example #2
0
        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 IResult ValidateModifyPickedInventoryItems(SalesOrder salesOrder, IEnumerable <ModifySalesOrderPickedInventoryItemParameters> items)
        {
            var validator  = PickedInventoryValidator.ForSalesOrder(salesOrder.InventoryShipmentOrder.SourceFacility);
            var orderItems = salesOrder.SalesOrderItems.ToDictionary(i => i.ToSalesOrderItemKey());

            foreach (var item in items)
            {
                SalesOrderItem orderItem;
                if (!orderItems.TryGetValue(item.SalesOrderItemKey, out orderItem))
                {
                    return(new InvalidResult(string.Format(UserMessages.CannotPickForCustomerOrderItem_DoesNotExist, item.SalesOrderItemKey.KeyValue)));
                }

                if (item.NewQuantity > item.OriginalQuantity)
                {
                    IDictionary <AttributeNameKey, ChileProductAttributeRange>    productSpec;
                    IDictionary <AttributeNameKey, CustomerProductAttributeRange> customerSpec;
                    var specResult = new GetProductSpecCommand(_salesUnitOfWork).Execute(ChileProductKey.FromProductKey(orderItem.InventoryPickOrderItem),
                                                                                         orderItem.Order, out productSpec, out customerSpec);
                    if (!specResult.Success)
                    {
                        return(specResult);
                    }

                    Dictionary <string, Inventory> inventory;
                    var validResult    = validator.ValidateItems(_salesUnitOfWork.InventoryRepository, new[] { item.InventoryKey }, out inventory);
                    var inventoryItem  = inventory.Values.Single();
                    var context        = new PickingValidatorContext(productSpec, customerSpec, orderItem.ContractItem, orderItem, orderItem.Order);
                    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());
        }
Example #4
0
        public IResult <IPickableInventoryReturn> GetInventoryItemsToPickTreatmentOrder(FilterInventoryForShipmentOrderParameters parameters)
        {
            parameters = parameters ?? new FilterInventoryForShipmentOrderParameters();

            InventoryShipmentOrderKey orderKey;
            InventoryPickOrderItemKey orderItemKey;
            var filterResults = parameters.ParseToPredicateBuilderFilters(out orderKey, out orderItemKey);

            if (!filterResults.Success)
            {
                return(filterResults.ConvertTo <IPickableInventoryReturn>());
            }

            var treatmentOrderKey = new TreatmentOrderKey(orderKey);
            var treatmentOrder    = _inventoryShipmentOrderUnitOfWork.TreatmentOrderRepository.FindByKey(treatmentOrderKey, o => o.InventoryShipmentOrder.SourceFacility);

            if (treatmentOrder == null)
            {
                return(new InvalidResult <IPickableInventoryReturn>(null, string.Format(UserMessages.TreatmentOrderNotFound, treatmentOrderKey)));
            }
            var facilityKey = treatmentOrder.InventoryShipmentOrder.SourceFacility.ToFacilityKey();

            var itemsResult = new GetPickableInventoryCommand(_inventoryShipmentOrderUnitOfWork).Execute(filterResults.ResultingObject, _timeStamper.CurrentTimeStamp,
                                                                                                         PickedInventoryValidator.ForTreatmentOrder(facilityKey, treatmentOrder, _inventoryShipmentOrderUnitOfWork), false);

            return(itemsResult);
        }
Example #5
0
        public IResult <IPickableInventoryReturn> GetInventoryToPickForOrder(FilterInventoryForShipmentOrderParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            InventoryShipmentOrderKey orderKey;
            InventoryPickOrderItemKey orderItemKey;
            var filterResults = parameters.ParseToPredicateBuilderFilters(out orderKey, out orderItemKey);

            if (!filterResults.Success)
            {
                return(filterResults.ConvertTo <IPickableInventoryReturn>());
            }
            var salesOrderKey     = new SalesOrderKey(orderKey);
            var salesOrderItemKey = orderItemKey == null ? null : new SalesOrderItemKey(orderItemKey);

            var salesOrder = _inventoryShipmentOrderUnitOfWork.SalesOrderRepository.FindByKey(salesOrderKey,
                                                                                              o => o.InventoryShipmentOrder.SourceFacility,
                                                                                              o => o.SalesOrderItems.Select(i => i.ContractItem),
                                                                                              o => o.SalesOrderItems.Select(i => i.InventoryPickOrderItem));

            if (salesOrder == null)
            {
                return(new InvalidResult <IPickableInventoryReturn>(null, string.Format(UserMessages.SalesOrderNotFound, orderKey.KeyValue)));
            }

            IDictionary <AttributeNameKey, ChileProductAttributeRange>    productSpec  = null;
            IDictionary <AttributeNameKey, CustomerProductAttributeRange> customerSpec = null;
            SalesOrderItem orderItem = null;

            if (salesOrderItemKey != null)
            {
                var item = salesOrder.SalesOrderItems.FirstOrDefault(salesOrderItemKey.FindByPredicate.Compile());
                if (item == null)
                {
                    return(new InvalidResult <IPickableInventoryReturn>(null, string.Format(UserMessages.SalesOrderItemNotFound, salesOrderItemKey)));
                }
                orderItem = item;

                var specResult = new GetProductSpecCommand(_inventoryShipmentOrderUnitOfWork).Execute(ChileProductKey.FromProductKey(item.InventoryPickOrderItem),
                                                                                                      item.Order, out productSpec, out customerSpec);
                if (!specResult.Success)
                {
                    return(specResult.ConvertTo <IPickableInventoryReturn>());
                }
            }

            var itemsResult = new GetPickableInventoryCommand(_inventoryShipmentOrderUnitOfWork).Execute(filterResults.ResultingObject, _timeStamper.CurrentTimeStamp,
                                                                                                         PickedInventoryValidator.ForSalesOrder(salesOrder.InventoryShipmentOrder.SourceFacility), true);

            if (itemsResult.Success)
            {
                itemsResult.ResultingObject.Initializer = new ValidPickingForOrder(new PickingValidatorContext(productSpec, customerSpec, orderItem == null ? null : orderItem.ContractItem, salesOrder, salesOrder));
            }

            return(itemsResult);
        }
        public IResult <IPickableInventoryReturn> GetInventoryItemsToPickWarehouseOrder(FilterInventoryForShipmentOrderParameters parameters)
        {
            parameters = parameters ?? new FilterInventoryForShipmentOrderParameters();

            InventoryShipmentOrderKey orderKey;
            InventoryPickOrderItemKey orderItemKey;
            var filterResults = parameters.ParseToPredicateBuilderFilters(out orderKey, out orderItemKey);

            if (!filterResults.Success)
            {
                return(filterResults.ConvertTo <IPickableInventoryReturn>());
            }

            var order = _inventoryShipmentOrderUnitOfWork.InventoryShipmentOrderRepository.FindByKey(orderKey,
                                                                                                     o => o.SourceFacility,
                                                                                                     o => o.InventoryPickOrder.Items.Select(i => i.Customer));

            if (order == null)
            {
                return(new InvalidResult <IPickableInventoryReturn>(null, string.Format(UserMessages.InterWarehouseOrderNotFound, orderKey)));
            }
            var facilityKey = order.SourceFacility.ToFacilityKey();

            IDictionary <AttributeNameKey, ChileProductAttributeRange>    productSpec  = null;
            IDictionary <AttributeNameKey, CustomerProductAttributeRange> customerSpec = null;
            Customer customer = null;

            if (orderItemKey != null)
            {
                var item = order.InventoryPickOrder.Items.FirstOrDefault(orderItemKey.FindByPredicate.Compile());
                if (item == null)
                {
                    return(new InvalidResult <IPickableInventoryReturn>(null, string.Format(UserMessages.InventoryPickOrderItemNotFound, orderItemKey)));
                }
                customer = item.Customer;

                var specResult = new GetProductSpecCommand(_inventoryShipmentOrderUnitOfWork).Execute(ChileProductKey.FromProductKey(item),
                                                                                                      customer, out productSpec, out customerSpec);
                if (!specResult.Success)
                {
                    return(specResult.ConvertTo <IPickableInventoryReturn>());
                }
            }

            var itemsResult = new GetPickableInventoryCommand(_inventoryShipmentOrderUnitOfWork).Execute(filterResults.ResultingObject, _timeStamper.CurrentTimeStamp,
                                                                                                         PickedInventoryValidator.ForInterWarehouseOrder(facilityKey), true);

            return(itemsResult);
        }