private IResult <SalesOrder> GetSalesOrder(ISalesOrderKey salesOrderKey)
        {
            var orderKey   = salesOrderKey.ToSalesOrderKey();
            var salesOrder = _salesUnitOfWork.SalesOrderRepository.FindByKey(orderKey,
                                                                             o => o.SalesOrderPickedItems.Select(i => i.PickedInventoryItem),
                                                                             o => o.SalesOrderItems.Select(i => i.ContractItem),
                                                                             o => o.SalesOrderItems.Select(i => i.InventoryPickOrderItem));

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

            if (salesOrder.OrderStatus == SalesOrderStatus.Invoiced)
            {
                return(new InvalidResult <SalesOrder>(null, string.Format(UserMessages.CannotPickInvoicedCustomerOrder, salesOrderKey)));
            }

            salesOrder.InventoryShipmentOrder = _salesUnitOfWork.InventoryShipmentOrderRepository.FindByKey(salesOrder.ToInventoryShipmentOrderKey(),
                                                                                                            i => i.PickedInventory.Items.Select(n => n.CurrentLocation),
                                                                                                            i => i.SourceFacility.Locations,
                                                                                                            i => i.DestinationFacility.Locations);

            if (salesOrder.InventoryShipmentOrder.OrderStatus == OrderStatus.Void)
            {
                return(new InvalidResult <SalesOrder>(null, string.Format(UserMessages.CannotPickVoidedCustomerOrder, salesOrderKey)));
            }

            return(new SuccessResult <SalesOrder>(salesOrder));
        }
Пример #2
0
        internal IResult Execute(ISalesOrderKey key, out int?orderNum)
        {
            orderNum = null;
            var orderKey = key.ToSalesOrderKey();
            var order    = UnitOfWork.SalesOrderRepository.FindByKey(orderKey,
                                                                     c => c.InventoryShipmentOrder.ShipmentInformation,
                                                                     c => c.LotAllowances,
                                                                     c => c.SalesOrderItems,
                                                                     c => c.SalesOrderPickedItems,
                                                                     c => c.InventoryShipmentOrder.PickedInventory.Items.Select(i => i.CurrentLocation));

            if (order == null)
            {
                return(new InvalidResult(string.Format(UserMessages.SalesOrderNotFound, orderKey)));
            }

            if (order.InventoryShipmentOrder.ShipmentInformation.Status == ShipmentStatus.Shipped)
            {
                return(new InvalidResult(string.Format(UserMessages.CannotDeleteShippedShipmentOrder)));
            }

            var removePickedItemsResult = UpdatePickedInventory(null, null, DateTime.UtcNow, order.InventoryShipmentOrder.PickedInventory, null);

            if (!removePickedItemsResult.Success)
            {
                return(removePickedItemsResult);
            }

            orderNum = order.InventoryShipmentOrder.MoveNum;

            UnitOfWork.SalesOrderRepository.Remove(order);
            return(new SuccessResult());
        }
        internal IResult <ISalesOrderInvoice> Get(ISalesOrderKey orderKey)
        {
            var customerOrderKey = orderKey.ToSalesOrderKey();
            var predicate        = customerOrderKey.FindByPredicate;
            var select           = SalesOrderProjectors.SelectCustomerOrderInvoice();

            var invoice = _inventoryShipmentOrderUnitOfWork.SalesOrderRepository
                          .Filter(predicate)
                          .AsExpandable()
                          .Select(select)
                          .FirstOrDefault();

            if (invoice == null)
            {
                return(new InvalidResult <ISalesOrderInvoice>(null, string.Format(UserMessages.SalesOrderNotFound, customerOrderKey)));
            }

            invoice.Initialize();

            return(new SuccessResult <ISalesOrderInvoice>(invoice));
        }
Пример #4
0
        public PickingValidatorContext(IDictionary <AttributeNameKey, ChileProductAttributeRange> productSpec,
                                       IDictionary <AttributeNameKey, CustomerProductAttributeRange> customerSpec,
                                       IContractKey contractKey, ISalesOrderKey salesOrderKey, ICustomerKey customerKey)
        {
            if (contractKey != null)
            {
                ContractKey = contractKey.ToContractKey();
            }

            if (salesOrderKey != null)
            {
                CustomerOrderKey = salesOrderKey.ToSalesOrderKey();
            }

            if (customerKey != null)
            {
                CustomerKey = customerKey.ToCustomerKey();
            }

            var productSpecRanges  = productSpec == null ? new Dictionary <string, IAttributeRange>() : productSpec.To().Dictionary <string, IAttributeRange>(p => p.Key, p => p.Value);
            var customerSpecRanges = customerSpec == null ? new Dictionary <string, IAttributeRange>() : customerSpec.To().Dictionary <string, IAttributeRange>(p => p.Key, p => p.Value);

            foreach (var prodSpec in productSpecRanges)
            {
                IAttributeRange custRange;
                if (customerSpecRanges.TryGetValue(prodSpec.Key, out custRange))
                {
                    customerSpecRanges.Remove(prodSpec.Key);
                }

                AttributeSpecs.Add(prodSpec.Key, new PickingValidatorAttributeSpec(prodSpec.Value, custRange));
            }

            foreach (var custSpec in customerSpecRanges)
            {
                AttributeSpecs.Add(custSpec.Key, new PickingValidatorAttributeSpec(null, custSpec.Value));
            }
        }