Beispiel #1
0
        private List <IOrderItem> GetAllOrderItems(IPurchaseOrder order)
        {
            var items = new List <IOrderItem>(order.Items.Count() * 2);

            foreach (var orderItem in order.Items)
            {
                var kitItems = m_kitProductRepository.GetKitForOrderItem(order, orderItem).ToList();

                if (!kitItems.Any())
                {
                    items.Add(orderItem);
                    continue;
                }

                foreach (var child in orderItem.KitChildren)
                {
                    items.Add(child);
                }

                foreach (var kitItem in kitItems)
                {
                    if (kitItem.SelectedItem != null)
                    {
                        if (items.All(i => i.Id != kitItem.SelectedItem.Id))
                        {
                            items.Add(kitItem.SelectedItem);
                        }
                    }
                }
            }
            return(items);
        }
Beispiel #2
0
        private PackingOrderModel MapOrder(IPurchaseOrder entity, Tuple <long, BatchKey, decimal> orderItemBatchPreference = null)
        {
            entity = m_ordersFacade.ResolveSingleItemKitSelection(entity);

            var batchAssignments = m_batchFacade.TryResolveBatchAssignments(entity, orderItemBatchPreference).ToList();

            var orderModel = new PackingOrderModel
            {
                OrderId       = entity.Id,
                OrderNumber   = entity.OrderNumber,
                CustomerEmail = entity.CustomerEmail,
                CustomerName  = entity.CustomerName,
                CustomerNote  = entity.CustomerNote,
                InternalNote  = entity.InternalNote,
                ErpName       = entity.Erp?.Description,
                DiscountsText = entity.DiscountsText,
                Price         = $"{StringUtil.FormatDecimal(entity.PriceWithVat)} {entity.Currency.Symbol}"
            };

            foreach (var sourceItem in entity.Items.OrderBy(i => i.Id))
            {
                var item = new PackingOrderItemModel
                {
                    ProductName     = sourceItem.PlacedName,
                    ItemId          = sourceItem.Id,
                    Quantity        = StringUtil.FormatDecimal(sourceItem.Quantity),
                    NumericQuantity = sourceItem.Quantity
                };

                var kitItems = new List <KitItemsCollectionModel>();

                foreach (var sourceKitItem in m_kitProductRepository.GetKitForOrderItem(entity, sourceItem).OrderBy(ki => ki.KitItemIndex))
                {
                    var model = new KitItemsCollectionModel(sourceKitItem);

                    if (sourceKitItem.SelectedItem != null)
                    {
                        var selitem = new PackingOrderItemModel
                        {
                            ProductName     = sourceKitItem.SelectedItem.PlacedName,
                            ItemId          = sourceKitItem.SelectedItem.Id,
                            Quantity        = StringUtil.FormatDecimal(sourceKitItem.SelectedItem.Quantity),
                            NumericQuantity = sourceKitItem.SelectedItem.Quantity
                        };
                        SetupBatchAssignment(selitem, batchAssignments.Where(a => a.OrderItemId == sourceKitItem.SelectedItem.Id));
                        model.SelectedItemModel = selitem;
                    }

                    kitItems.Add(model);
                }

                item.KitItems.AddRange(kitItems);
                SetupBatchAssignment(item, batchAssignments.Where(a => a.OrderItemId == sourceItem.Id));
                orderModel.Items.Add(item);
            }

            return(orderModel);
        }
Beispiel #3
0
        public IEnumerable <IOrderItem> GetAllConcreteOrderItems(IPurchaseOrder order)
        {
            foreach (var item in order.Items)
            {
                var kitItems = m_kitProductRepository.GetKitForOrderItem(order, item).ToList();

                if (!kitItems.Any())
                {
                    yield return(item);

                    continue;
                }

                foreach (var kitItem in kitItems.Where(k => k.SelectedItem != null))
                {
                    yield return(kitItem.SelectedItem);
                }
            }
        }