Beispiel #1
0
        private static PickListItemViewModel ComposeNewGroup(ListingOrderDTO item,
                                                             bool hasColorVariation,
                                                             Style style,
                                                             IList <StyleItemDTO> styleItems,
                                                             DTOOrder order)
        {
            //Add new group
            IList <PickListSizeInfo> allSizes = new List <PickListSizeInfo>();

            //Prepare image
            ///NOTE: Always get from style
            //var image = item.ItemPicture;
            //if (String.IsNullOrEmpty(image))
            var image = item.StyleImage;

            var title = item.Title;

            if (item.SourceStyleString != item.StyleID)        //NOTE: happens when item has linked style OR item style was changed
            {
                if (!String.IsNullOrEmpty(item.StyleImage))
                {
                    image = item.StyleImage;
                }

                if (style != null && !String.IsNullOrEmpty(style.Name))
                {
                    title = style.Name;
                }
            }

            title = SizeHelper.ExcludeSizeInfo(title);

            if (style != null)
            {
                allSizes = styleItems.Where(i => i.StyleId == style.Id)
                           .Select(i => new PickListSizeInfo()
                {
                    StyleSize   = i.Size,
                    StyleItemId = i.StyleItemId,
                    Weight      = i.Weight
                }).ToList();
            }

            var itemPrice = item.ItemPrice;

            if (item.Market == (int)MarketType.Amazon ||
                item.Market == (int)MarketType.AmazonEU ||
                item.Market == (int)MarketType.AmazonAU)
            {
                itemPrice = item.QuantityOrdered != 0 ? item.ItemPrice / item.QuantityOrdered : 0;
            }

            var newGroup = new PickListItemViewModel
            {
                StyleName         = style != null ? style.Name : null,
                StyleId           = style != null ? (long?)style.Id : null,
                Color             = item.Color,
                StyleString       = style != null ? style.StyleID : null,
                ProductName       = title,
                Picture           = image,
                HasColorVariation = hasColorVariation,
                RemovePriceTag    = style != null ? style.RemovePriceTag : false,

                ListingInfoes = new List <ListingInfo>()
                {
                    new ListingInfo()
                    {
                        ASIN           = item.ASIN,
                        ParentASIN     = item.ParentASIN,
                        SourceMarketId = item.SourceMarketId,
                        MarketplaceId  = item.MarketplaceId,
                        Market         = item.Market,
                        Quantity       = item.QuantityOrdered,
                        Rank           = item.Rank,
                    }
                },

                SoldSizes = new List <PickListSizeInfo>
                {
                    new PickListSizeInfo
                    {
                        Quantity = item.QuantityOrdered,
                        Sizes    = new List <string>()
                        {
                            item.Size
                        },
                        StyleSize   = item.StyleSize,
                        StyleItemId = item.StyleItemId,
                        Color       = item.Color,
                        Weight      = item.Weight,
                        Prices      = new List <PriceInfo>()
                        {
                            new PriceInfo()
                            {
                                Price    = itemPrice,
                                Currency = PriceHelper.GetCurrencySymbol((MarketType)item.Market, item.MarketplaceId)
                            }
                        }
                    }
                },
                AllSizes = allSizes,

                //Orders of item
                Orders = new List <OrderInfo>
                {
                    new OrderInfo
                    {
                        OrderId                = order.OrderId,
                        OrderDate              = order.OrderDate,
                        ShippingMethodId       = order.ShippingMethodId,
                        IsPrime                = order.OrderType == (int)OrderTypeEnum.Prime,
                        InitialShippingService = order.InitialServiceType,
                        ShipmentProviderType   = order.ShipmentProviderType,
                    }
                }
            };

            return(newGroup);
        }
Beispiel #2
0
        private static void ItemPostProcessing(PickListItemViewModel item,
                                               IList <StyleLocationDTO> locations,
                                               IList <SoldSizeInfo> remainingQtyes,
                                               IList <SoldSizeInfo> pendingAndNoBatchSoldQtyes,
                                               IList <StyleFeatureValueDTO> stylesValues)
        {
            if (item.StyleId != null)
            {
                //Set Locations
                item.Locations = ComposeLocations(locations, item.StyleId.Value);

                //Set Remaining Quantity from inventory
                foreach (var size in item.AllSizes)
                {
                    var remainingQty = remainingQtyes.FirstOrDefault(r => r.StyleItemId == size.StyleItemId);
                    if (remainingQty != null)
                    {
                        size.Quantity = Math.Max(0, remainingQty.TotalQuantity ?? 0);
                    }
                }

                item.SoldQuantity = item.SoldSizes.Sum(s => s.Quantity);
            }

            //Sort sizes
            item.SoldSizes = item.SoldSizes.OrderBy(s => s.SizeIndex).ThenBy(s => s.StyleSize).ThenBy(s => s.Color).ToList();
            item.AllSizes  = item.AllSizes.OrderBy(s => s.SizeIndex).ThenBy(s => s.StyleSize).ThenBy(s => s.Color).ToList();

            //Fill pending items
            foreach (var size in item.AllSizes)
            {
                var pendingAndNoBatchSoldQuery = pendingAndNoBatchSoldQtyes.Where(s => s.StyleItemId == size.StyleItemId);

                //if (item.HasColorVariation)
                //    pendingAndNoBatchSoldQuery = pendingAndNoBatchSoldQuery.Where(s => s.Color == item.Color);

                size.PendingQuantity = pendingAndNoBatchSoldQuery.Sum(s => s.SoldQuantity) ?? 0;
                var soldItem = item.SoldSizes.FirstOrDefault(i => i.StyleItemId == size.StyleItemId);
                size.OrderedQuantity = soldItem != null ? soldItem.Quantity : 0;
            }


            //Fill feature fields
            StyleFeatureValueDTO mainLicenseValue = null;
            StyleFeatureValueDTO subLicenseValue  = null;
            StyleFeatureValueDTO genderValue      = null;

            if (item.StyleId != null)
            {
                genderValue      = stylesValues.FirstOrDefault(v => v.StyleId == item.StyleId && v.FeatureId == StyleFeatureHelper.GENDER);
                mainLicenseValue = stylesValues.FirstOrDefault(v => v.StyleId == item.StyleId && v.FeatureId == StyleFeatureHelper.MAIN_LICENSE);
                subLicenseValue  = stylesValues.FirstOrDefault(v => v.StyleId == item.StyleId && v.FeatureId == StyleFeatureHelper.SUB_LICENSE1);
            }
            item.Gender      = genderValue != null ? genderValue.Value : "";
            item.MainLicense = mainLicenseValue != null ? mainLicenseValue.Value : null;
            item.SubLicense1 = subLicenseValue != null ? subLicenseValue.Value : null;


            //Keep only sold items for record w/o styles
            if (String.IsNullOrEmpty(item.StyleString))
            {
                item.AllSizes = item.AllSizes.Where(s => item.SoldSizes.Any(ss => ss.StyleSize == s.StyleSize)).ToList();
                //Replace null value
                item.StyleString = item.StyleString ?? "-";
            }
        }
Beispiel #3
0
        private static void UpdateExistGroup(PickListItemViewModel existGroup,
                                             bool hasColorVariation,
                                             ListingOrderDTO item,
                                             DTOOrder order)
        {
            //This group always has appropriate color, only check size
            PickListSizeInfo existSize = null;

            if (hasColorVariation)
            {
                existSize = existGroup.SoldSizes.FirstOrDefault(s => (s.StyleSize == item.StyleSize && s.Color == item.Color) || s.StyleItemId == item.StyleItemId);
            }
            else
            {
                existSize = existGroup.SoldSizes.FirstOrDefault(s => s.StyleSize == item.StyleSize);
            }

            var currency  = PriceHelper.GetCurrencySymbol((MarketType)item.Market, item.MarketplaceId);
            var itemPrice = item.ItemPrice;

            if (item.Market == (int)MarketType.Amazon ||
                item.Market == (int)MarketType.AmazonEU ||
                item.Market == (int)MarketType.AmazonAU)
            {
                itemPrice = item.QuantityOrdered != 0 ? item.ItemPrice / item.QuantityOrdered : 0;
            }

            if (existSize != null)
            {
                existSize.Quantity += item.QuantityOrdered;

                if (!existSize.Prices.Any(p => p.Currency == currency && Math.Abs(p.Price - itemPrice) <= 0.1M))
                {
                    existSize.Prices.Add(new PriceInfo()
                    {
                        Price    = itemPrice,
                        Currency = currency
                    });
                }

                if (existSize.Sizes.All(s => s != item.Size))
                {
                    existSize.Sizes.Add(item.Size);
                }
            }
            else
            {
                existGroup.SoldSizes.Add(new PickListSizeInfo
                {
                    Quantity = item.QuantityOrdered,
                    Sizes    = new List <string>()
                    {
                        item.Size
                    },
                    StyleSize   = item.StyleSize,
                    StyleItemId = item.StyleItemId,
                    Color       = item.Color,
                    Weight      = item.Weight,
                    Prices      = new List <PriceInfo>()
                    {
                        new PriceInfo()
                        {
                            Price    = itemPrice,
                            Currency = currency,
                        }
                    }
                });
            }

            //Orders of item
            existGroup.Orders.Add(new OrderInfo
            {
                OrderDate              = order.OrderDate,
                OrderId                = order.OrderId,
                ShippingMethodId       = order.ShippingMethodId,
                IsPrime                = order.OrderType == (int)OrderTypeEnum.Prime,
                InitialShippingService = order.InitialServiceType,
                ShipmentProviderType   = order.ShipmentProviderType,
            });

            var existListing = existGroup.ListingInfoes.FirstOrDefault(l => l.ASIN == item.ASIN &&
                                                                       l.Market == item.Market &&
                                                                       l.MarketplaceId == item.MarketplaceId);

            if (existListing == null)
            {
                existGroup.ListingInfoes.Add(new ListingInfo()
                {
                    ASIN           = item.ASIN,
                    ParentASIN     = item.ParentASIN,
                    SourceMarketId = item.SourceMarketId,
                    MarketplaceId  = item.MarketplaceId,
                    Market         = item.Market,
                    Quantity       = item.QuantityOrdered,
                    Rank           = item.Rank,
                });
            }
            else
            {
                existListing.Quantity += item.QuantityOrdered;
            }
        }