コード例 #1
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);
        }
コード例 #2
0
        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);
        }