コード例 #1
0
ファイル: Program.cs プロジェクト: WhiteHingeLtd/SkuGenCore
        public static SkuBundleData GetSkuBundleInfo(this NewWhlSku item, whldataContext context, Whlnew baseData, bool isNewSku = false)
        {
            if (!item.ExtendedData.IsBundle)
            {
                return(new SkuBundleData());                                                       //It's not a bundle return a default collection
            }
            var compositionSkus = context.SkuComposition.Where(x => x.BundleSku == item.ShortSku); //Find all the skus in the bundle

            var returnable = new SkuBundleData();

            bool.TryParse(baseData.SplitBundle, out returnable.SplitBundle);

            var locData = new List <LocationData>();

            locData.AddRange(item.Locations);

            foreach (var sku in compositionSkus)
            {
                returnable.CompositionSkus.Add(sku.ChildSku);

                var data            = context.Whlnew.First(x => x.Sku == sku.ChildSku);
                var recursiveSearch = !context.SkuComposition.Any(x => x.BundleSku == sku.ChildSku.Substring(0, 7));

                var newItem = CreateSku(data, new List <WarehouseIssueLog>(), recursiveSearch).Result;

                foreach (var barcode in newItem.Barcodes)
                {
                    returnable.CompositionBarcodes.Add(barcode);
                }

                foreach (var keyword in newItem.SearchKeywords)
                {
                    returnable.CompositionSearchKeywords.Add(keyword);
                }

                locData.AddRange(newItem.Locations);
            }
            if (isNewSku)
            {
                item.Locations.Clear();
                item.Locations.AddRange(locData);
            }
            return(returnable);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: WhiteHingeLtd/SkuGenCore
        public static async Task <NewWhlSku> CreateSku(Whlnew mySqlData, List <WarehouseIssueLog> issueLog, bool skipBundles = false)
        {
            await Task.Delay(0);

            var newSku = new NewWhlSku
            {
                Sku              = mySqlData.Sku,
                Packsize         = Convert.ToInt32(mySqlData.Packsize),
                RetailPrice      = Convert.ToDecimal(mySqlData.Retail),
                DistinguishTitle = mySqlData.Ext35,
                NoteData         = new SkuNoteData
                {
                    DeliveryNote  = mySqlData.Deliverynote,
                    PickNote      = mySqlData.PickNote,
                    KnowledgeNote = mySqlData.KnowledgeNote
                },
                PriceData = new SkuPriceData
                {
                    Gross  = Convert.ToDecimal(mySqlData.Gross),
                    Net    = Convert.ToDecimal(mySqlData.Net),
                    Retail = Convert.ToDecimal(mySqlData.Retail)
                },
                Titles = new SkuExtendedTitles
                {
                    Invoice     = mySqlData.Itemtitle,
                    Label       = mySqlData.Labelshort,
                    Linnworks   = mySqlData.Linnshort,
                    Distinguish = mySqlData.Ext35,
                    NewItem     = mySqlData.NewDescription
                },
                ItemData = new ItemProfile
                {
                    Brand       = mySqlData.NewBrand,
                    Description = mySqlData.NewDescription,
                    Finish      = mySqlData.NewFinish,
                    Category    = mySqlData.Ext33,
                    Size        = mySqlData.NewSize,
                    Note        = mySqlData.NewNote,
                    Box         = mySqlData.NewTransferBox,
                },
                ExtendedData = new SkuExtendedData
                {
                    Envelope   = mySqlData.Envelope,
                    LabourCode = mySqlData.Labour,
                    Status     = mySqlData.NewStatus
                },
                NewData = new NewSkuData
                {
                    GS1Barcode = mySqlData.Gs1
                },
                CostData      = new SkuCostData(),
                BundleData    = new SkuBundleData(),
                LinnworksInfo = new SkuLinnworksInfo()
            };

            if (newSku.NewData.GS1Barcode == null)
            {
                newSku.NewData.GS1Barcode = "";
            }
            newSku.Packsize = Convert.ToInt32(mySqlData.Packsize);
            //Item Profile
            int.TryParse(mySqlData.Parts, out newSku.ItemData.Parts);
            int.TryParse(mySqlData.Pieces, out newSku.ItemData.Pieces);
            int.TryParse(mySqlData.Screws, out newSku.ItemData.Screws);
            decimal.TryParse(mySqlData.Weight.ToString(), out newSku.ItemData.Weight);
            //ExtendedData
            bool.TryParse(mySqlData.IsPair, out newSku.ExtendedData.IsPair);
            bool.TryParse(mySqlData.IsListed, out newSku.ExtendedData.IsListed);
            bool.TryParse(mySqlData.HasBeenListed, out newSku.ExtendedData.HasBeenListed);
            bool.TryParse(mySqlData.Courier, out newSku.ExtendedData.Courier);
            bool.TryParse(mySqlData.OversizedItem, out newSku.ExtendedData.Oversized);
            bool.TryParse(mySqlData.IsBundle, out newSku.ExtendedData.IsBundle);
            //Pricing Data
            decimal.TryParse(mySqlData.Profit, out newSku.PriceData.Profit);
            decimal.TryParse(mySqlData.Margin, out newSku.PriceData.Margin);
            //Cost Data
            decimal.TryParse(mySqlData.Packingcost, out newSku.CostData.Packing);
            decimal.TryParse(mySqlData.Postagecost, out newSku.CostData.Postage);
            decimal.TryParse(mySqlData.Envcost, out newSku.CostData.Envelope);
            decimal.TryParse(mySqlData.Feescost, out newSku.CostData.Fees);
            decimal.TryParse(mySqlData.Labourcost, out newSku.CostData.Labour);
            decimal.TryParse(mySqlData.Vatcost, out newSku.CostData.Vat);
            decimal.TryParse(mySqlData.Totalcost, out newSku.CostData.Total);
            //Linnworks Data
            int.TryParse(mySqlData.Initiallevel, out newSku.LinnworksInfo.InitialLevel);
            int.TryParse(mySqlData.Initialquantity, out newSku.LinnworksInfo.InitialStock);
            int.TryParse(mySqlData.InitMinimum, out newSku.LinnworksInfo.InitialMinimum);
            int.TryParse(mySqlData.ListPriority, out newSku.LinnworksInfo.ListPriority);



            var inv = GetStockLevels(mySqlData.Sku);

            newSku.StockData = new SkuStockData();
            int.TryParse(inv.Stock, out newSku.StockData.Level);
            int.TryParse(inv.Stockminimum, out newSku.StockData.Minimum);
            using (var context = new whldataContext())
            {
                newSku.Locations = newSku.GetShortSkuLocations(context);

                newSku.Suppliers = newSku.GetSuppliers(context);

                newSku.SalesData   = newSku.GetSkuSalesData(context);
                newSku.PrepackInfo = newSku.GetSkuPrepackInfo(context);

                //newSku.UpdateOrderwiseData(context);
                if (issueLog.Count != 0)
                {
                    newSku.GetMissedPicksAndIssues(issueLog);
                }
                else
                {
                    newSku.NewData.MissedPicks = new MispickStatistic();
                }

                if (newSku.ExtendedData.IsBundle && !skipBundles)
                {
                    newSku.BundleData = newSku.GetSkuBundleInfo(context, mySqlData, true);
                }
            }
            newSku.Barcodes       = newSku.GetSkuBarcodes();
            newSku.SearchKeywords = newSku.GetSearchKeywords();

            return(newSku);
        }