public void CallUpdateQty(DropShipperApi api) { using (var db = _dbFactory.GetRWDb()) { var service = new DSItemsSync(_log, _time, api, _dbFactory); service.SendInventoryUpdates(); } }
public UpdateDSOrderDataThread(DropShipperApi api, long companyId, ISystemMessageService messageService, TimeSpan?callbackInterval, TimeSpan betweenProcessingInverval) : base("UpdateDropShipper" + api.MarketplaceId + "OrderData", companyId, messageService, callbackInterval) { _api = api; _betweenProcessingInverval = betweenProcessingInverval; }
public UpdateDSListingQtyThread(DropShipperApi api, long userId, ISystemMessageService messageService, TimeSpan?callbackInterval, TimeSpan betweenProcessingInverval) : base("UpdateDSListingQty", userId, messageService, callbackInterval) { _api = api; _betweenProcessingInverval = betweenProcessingInverval; }
public DSItemsSync(ILogService log, ITime time, DropShipperApi api, IDbFactory dbFactory) { _log = log; _time = time; _api = api; _dbFactory = dbFactory; }
public void TestCloseIBCManifest(DropShipperApi api) { var form = new ScanFormInfo() { ScanFormId = "81", CloseoutIds = new List <string>() { "LX118315802US" } }; api.CloseIBCOrders(form); }
public static IList <FedexCloseoutInfoViewModel> GetInfo(IUnitOfWork db, ITime time, DropShipperApi mbgApi) { var fromDate = time.GetAppNowTime().Date; var allFedexShipments = (from sh in db.OrderShippingInfos.GetAll() join o in db.Orders.GetAll() on sh.OrderId equals o.Id join oi in db.OrderItems.GetWithListingInfo() on o.Id equals oi.OrderId join m in db.MailLabelInfos.GetAll() on o.Id equals m.OrderId into withMail from m in withMail.DefaultIfEmpty() where (sh.ShipmentProviderType == (int)ShipmentProviderType.FedexOneRate //|| sh.ShipmentProviderType == (int)ShipmentProviderType.FedexSmartPost || sh.ShippingMethodId == ShippingUtils.AmazonFedEx2DayOneRateEnvelopeShippingMethodId || sh.ShippingMethodId == ShippingUtils.AmazonFedEx2DayOneRatePakShippingMethodId || sh.ShippingMethodId == ShippingUtils.AmazonFedExPriorityOvernight || sh.ShippingMethodId == ShippingUtils.AmazonFedExStandardOvernight || sh.ShippingMethodId == ShippingUtils.AmazonFedExExpressSaverShippingMethodId || sh.ShippingMethodId == ShippingUtils.AmazonFedEx2DayShppingMethodId || sh.ShippingMethodId == ShippingUtils.AmazonFedEx2DayAMShppingMethodId || (sh.ShipmentProviderType == (int)ShipmentProviderType.FedexGeneral && sh.ShippingMethodId != ShippingUtils.FedexGroundShippingMethodId && sh.ShippingMethodId != ShippingUtils.FedexHomeDeliveryShippingMethodId)) && sh.IsActive && (((OrderStatusEnumEx.Shipped == o.OrderStatus || OrderStatusEnumEx.PartiallyShipped == o.OrderStatus) && sh.ShippingDate >= fromDate) || OrderStatusEnumEx.Unshipped == o.OrderStatus) && (m == null || m.LabelCanceled) group new { sh, oi } by sh.Id into byShipment select new { Id = byShipment.Key, Weight = byShipment.Sum(i => i.oi.Weight), HasLabel = byShipment.Any(i => !String.IsNullOrEmpty(i.sh.LabelPath)) }) .ToList(); var allFedexMailings = (from sh in db.MailLabelInfos.GetAll() join o in db.Orders.GetAll() on sh.OrderId equals o.Id where (sh.ShipmentProviderType == (int)ShipmentProviderType.FedexOneRate //|| sh.ShipmentProviderType == (int)ShipmentProviderType.FedexSmartPost || sh.ShippingMethodId == ShippingUtils.AmazonFedEx2DayOneRateEnvelopeShippingMethodId || sh.ShippingMethodId == ShippingUtils.AmazonFedEx2DayOneRatePakShippingMethodId || sh.ShippingMethodId == ShippingUtils.AmazonFedExPriorityOvernight || sh.ShippingMethodId == ShippingUtils.AmazonFedExStandardOvernight || sh.ShippingMethodId == ShippingUtils.AmazonFedExExpressSaverShippingMethodId || sh.ShippingMethodId == ShippingUtils.AmazonFedEx2DayShppingMethodId || sh.ShippingMethodId == ShippingUtils.AmazonFedEx2DayAMShppingMethodId || (sh.ShipmentProviderType == (int)ShipmentProviderType.FedexGeneral && sh.ShippingMethodId != ShippingUtils.FedexGroundShippingMethodId && sh.ShippingMethodId != ShippingUtils.FedexHomeDeliveryShippingMethodId)) && (((OrderStatusEnumEx.Shipped == o.OrderStatus || OrderStatusEnumEx.PartiallyShipped == o.OrderStatus) && sh.ShippingDate >= fromDate) || OrderStatusEnumEx.Unshipped == o.OrderStatus) select new { Id = sh.Id, Weight = sh.WeightLb * 16 + sh.WeightOz, HasLabel = !String.IsNullOrEmpty(sh.LabelPath) }).ToList(); var currentFedex = new FedexCloseoutInfoViewModel() { Name = "PA", IsSuccess = true, FedexOrdersCount = allFedexShipments.Count(sh => !sh.HasLabel) + allFedexMailings.Count(sh => !sh.HasLabel), FedexLabelsCount = allFedexShipments.Count(sh => sh.HasLabel) + allFedexMailings.Count(sh => sh.HasLabel), //FedexOrdersWeight = allFedexShipments.Sum(sh => (decimal)sh.Weight) + allFedexMailings.Sum(sh => (decimal)sh.Weight), }; var results = new List <FedexCloseoutInfoViewModel>() { currentFedex }; if (mbgApi != null) { var mbgFedexInfo = mbgApi.GetFedexOrdersInfo(); results.Add(new FedexCloseoutInfoViewModel() { Name = "MBG", IsSuccess = mbgFedexInfo.IsSuccess, FedexOrdersCount = mbgFedexInfo.Data?.OrdersCount ?? 0, FedexLabelsCount = mbgFedexInfo.Data?.ToCloseoutCount ?? 0, //FedexOrdersWeight = mbgFedexInfo.Data?.OrdersWeight ?? 0, }); } return(results); }
public static IList <FimsCloseoutInfoViewModel> GetInfo(IUnitOfWork db, DropShipperApi mbgApi) { var toCloseoutShipments = db.OrderShippingInfos.GetAll() .Where(sh => sh.ShipmentProviderType == (int)ShipmentProviderType.FIMS && !sh.ScanFormId.HasValue && !sh.CancelLabelRequested && !sh.LabelCanceled && !String.IsNullOrEmpty(sh.StampsTxId)) .Select(sh => new { Id = sh.Id, Weight = sh.UsedWeight ?? 0 }) .ToList(); var toCloseoutMailings = db.MailLabelInfos.GetAll() .Where(sh => sh.ShipmentProviderType == (int)ShipmentProviderType.FIMS && !sh.ScanFormId.HasValue && !sh.CancelLabelRequested && !sh.LabelCanceled && !String.IsNullOrEmpty(sh.StampsTxId)) .Select(sh => new { Id = sh.Id, Weight = sh.WeightLb * 16 + sh.WeightOz }) .ToList(); var allFimsShipments = (from sh in db.OrderShippingInfos.GetAll() join o in db.Orders.GetAll() on sh.OrderId equals o.Id join oi in db.OrderItems.GetWithListingInfo() on o.Id equals oi.OrderId join m in db.MailLabelInfos.GetAll() on o.Id equals m.OrderId into withMail from m in withMail.DefaultIfEmpty() where sh.ShipmentProviderType == (int)ShipmentProviderType.FIMS && !sh.ScanFormId.HasValue && sh.IsActive && OrderStatusEnumEx.AllUnshippedWithShipped.Contains(o.OrderStatus) && (m == null || m.LabelCanceled) && (o.OrderStatus != OrderStatusEnumEx.Canceled && o.OrderStatus != OrderStatusEnumEx.Pending) && sh.LabelPath != "#" //NOTE: External label group new { sh, oi } by sh.Id into byShipment select new { Id = byShipment.Key, Weight = byShipment.Sum(i => i.oi.Weight * i.oi.Quantity) }) .ToList(); var allFimsMailings = (from sh in db.MailLabelInfos.GetAll() join o in db.Orders.GetAll() on sh.OrderId equals o.Id where sh.ShipmentProviderType == (int)ShipmentProviderType.FIMS && !sh.ScanFormId.HasValue && OrderStatusEnumEx.AllUnshippedWithShipped.Contains(o.OrderStatus) select new { Id = sh.Id, Weight = sh.WeightLb * 16 + sh.WeightOz }).ToList(); var currentFims = new FimsCloseoutInfoViewModel() { Name = "PA", IsSuccess = true, ToCloseoutCount = toCloseoutShipments.Count() + toCloseoutMailings.Count(), ToCloseoutWeight = toCloseoutShipments.Sum(sh => (decimal)sh.Weight) + toCloseoutMailings.Sum(sh => (decimal)sh.Weight), IbcOrdersCount = allFimsShipments.Count() + allFimsMailings.Count(), IbcOrdersWeight = allFimsShipments.Sum(sh => (decimal)sh.Weight) + allFimsMailings.Sum(sh => (decimal)sh.Weight), }; var results = new List <FimsCloseoutInfoViewModel>() { currentFims }; //var mbgIBCInfo = mbgApi.GetIBCOrdersToClose(); //results.Add(new IbcCloseoutInfoViewModel() //{ // Name = "MBG", // IsSuccess = mbgIBCInfo.IsSuccess, // IbcOrdersCount = mbgIBCInfo.Data?.OrdersCount ?? 0, // IbcOrdersWeight = mbgIBCInfo.Data?.OrdersWeight ?? 0, // ToCloseoutCount = mbgIBCInfo.Data?.ToCloseoutCount ?? 0, // ToCloseoutWeight = mbgIBCInfo.Data?.ToCloseoutWeight ?? 0, //}); return(results); }
public void SyncStyles(DropShipperApi api) { var styles = api.GetStyles(_log, _sourceMarket, _sourceMarketplaceId); using (var db = _dbFactory.GetRWDb()) { foreach (var incomeStyle in styles) { var existStyle = db.Styles.GetAll().FirstOrDefault(st => (st.StyleID == incomeStyle.StyleID || st.OriginalStyleID.Contains(incomeStyle.StyleID + ";")) && !st.Deleted); if (existStyle == null) { _log.Info("Creating style, StyleId=" + incomeStyle.StyleID); var newStyle = new Style() { StyleID = incomeStyle.StyleID, OriginalStyleID = incomeStyle.OriginalStyleID, Name = incomeStyle.Name, Description = incomeStyle.Description, BulletPoint1 = incomeStyle.BulletPoint1, BulletPoint2 = incomeStyle.BulletPoint2, BulletPoint3 = incomeStyle.BulletPoint3, BulletPoint4 = incomeStyle.BulletPoint4, BulletPoint5 = incomeStyle.BulletPoint5, MSRP = incomeStyle.MSRP, Manufacturer = PrepareManufacture(incomeStyle.Manufacturer), DropShipperId = _dropShipperId,// DSHelper.MBGPAId, Image = incomeStyle.Image, CreateDate = _time.GetAppNowTime(), }; db.Styles.Add(newStyle); db.Commit(); foreach (var featureValue in incomeStyle.StyleFeatures) { var findFeature = db.Features.GetAll().FirstOrDefault(f => f.Name == featureValue.FeatureName); if (findFeature == null) { continue; } if (featureValue.Type == (int)FeatureValuesType.TextBox || featureValue.Type == (int)FeatureValuesType.CheckBox) { db.StyleFeatureTextValues.Add(new StyleFeatureTextValue() { StyleId = newStyle.Id, FeatureId = findFeature.Id, Value = featureValue.Value, CreateDate = _time.GetAppNowTime(), }); } else { var findFeatureValue = db.FeatureValues.GetAll().FirstOrDefault(fv => fv.FeatureId == findFeature.Id && fv.Value == featureValue.Value); if (findFeatureValue != null) { db.StyleFeatureValues.Add(new StyleFeatureValue() { StyleId = newStyle.Id, FeatureId = findFeatureValue.FeatureId, FeatureValueId = findFeatureValue.Id, CreateDate = _time.GetAppNowTime(), }); } } } db.Commit(); foreach (var si in incomeStyle.StyleItems) { var newStyleItem = new StyleItem() { StyleId = newStyle.Id, Size = si.Size, Color = si.Color, Quantity = si.Quantity, QuantitySetDate = si.QuantitySetDate, Weight = si.Weight, CreateDate = _time.GetAppNowTime() }; db.StyleItems.Add(newStyleItem); db.Commit(); if (si.Barcodes != null && si.Barcodes.Any()) { foreach (var bi in si.Barcodes) { db.StyleItemBarcodes.Add(new StyleItemBarcode() { StyleItemId = newStyleItem.Id, Barcode = bi.Barcode, CreateDate = _time.GetAppNowTime(), }); } } db.Commit(); } foreach (var image in incomeStyle.Images) { var newStyleImage = new StyleImage() { StyleId = newStyle.Id, Image = image.Image, SourceImage = image.SourceImage, SourceMarketId = image.SourceMarketId, Type = image.Type, Category = image.Category, IsDefault = image.IsDefault, IsSystem = image.IsSystem, CreateDate = _time.GetAppNowTime() }; db.StyleImages.Add(newStyleImage); } db.Commit(); } else { _log.Info("Already exists: " + incomeStyle.StyleID); _log.Info("Style Name changed: " + existStyle.Name + " => " + incomeStyle.Name); existStyle.Name = incomeStyle.Name; db.Commit(); } } } }
public void SyncItems(DropShipperApi api) { var destMarket = _destMarket; // MarketType.Walmart; var destMarketplaceId = _destMarketplaceId; // ""; var sourceMarketplaceId = _sourceMarketplaceId; // MarketplaceKeeper.DsPAWMCom; var parentItems = api.GetItems(_log, _sourceMarket /* MarketType.DropShipper */, sourceMarketplaceId); using (var db = _dbFactory.GetRWDb()) { foreach (var parentItem in parentItems) { var existParentItem = db.ParentItems.GetAll().FirstOrDefault(pi => pi.ASIN == parentItem.ASIN && pi.Market == (int)destMarket && (String.IsNullOrEmpty(destMarketplaceId) || pi.MarketplaceId == destMarketplaceId)); if (existParentItem == null) { _log.Info("Creating parentItem, ASIN=" + parentItem.ASIN); var newParentItem = new ParentItem() { ASIN = parentItem.ASIN, Market = (int)destMarket, MarketplaceId = destMarketplaceId, SKU = parentItem.SKU, AmazonName = parentItem.AmazonName, BrandName = parentItem.BrandName, BulletPoint1 = parentItem.BulletPoint1, BulletPoint2 = parentItem.BulletPoint2, BulletPoint3 = parentItem.BulletPoint3, BulletPoint4 = parentItem.BulletPoint4, BulletPoint5 = parentItem.BulletPoint5, CreateDate = _time.GetAppNowTime(), }; db.ParentItems.Add(newParentItem); db.Commit(); foreach (var v in parentItem.Variations) { var findStyle = db.Styles.GetAll().FirstOrDefault(st => st.StyleID == v.StyleString && !st.Deleted); StyleItem findStyleItem = null; if (findStyle != null) { findStyleItem = db.StyleItems.GetAll().FirstOrDefault(si => si.StyleId == findStyle.Id && si.Size == v.StyleSize && (String.IsNullOrEmpty(v.StyleColor) || si.Color == v.StyleColor)); } var barcode = v.Barcode; if (string.IsNullOrEmpty(barcode) && !String.IsNullOrEmpty(v.SKU)) { var result = _barcodeService.AssociateBarcodes(v.SKU, _time.GetAppNowTime(), null); if (!String.IsNullOrEmpty(result.Barcode)) { barcode = result.Barcode; } } var newItem = new Item() { ParentASIN = newParentItem.ASIN, Market = (int)destMarket, MarketplaceId = destMarketplaceId, ASIN = v.ASIN, Size = v.Size, Color = v.Color, StyleString = v.StyleString, StyleId = findStyle?.Id, StyleItemId = findStyleItem?.Id, ItemPublishedStatus = (int)PublishedStatuses.New, BrandName = v.BrandName, Title = parentItem.AmazonName, //NOTE: v.Name is empty and always equal parent item Name Barcode = barcode, CreateDate = _time.GetAppNowTime() }; db.Items.Add(newItem); db.Commit(); var isPrime = sourceMarketplaceId == MarketplaceKeeper.DsPAWMCom && destMarket == MarketType.Walmart ? true : false; var newListing = new Listing() { ASIN = v.ASIN, Market = (int)destMarket, MarketplaceId = destMarketplaceId, IsPrime = isPrime, SKU = v.SKU, ListingId = v.ListingId, ItemId = newItem.Id, RealQuantity = 0, CurrentPrice = v.CurrentPrice, }; db.Listings.Add(newListing); db.Commit(); } } else { _log.Info("ParentItem.AmazonName changed: " + existParentItem.AmazonName + " => " + parentItem.AmazonName); existParentItem.AmazonName = parentItem.AmazonName; db.Commit(); foreach (var v in parentItem.Variations) { var item = db.Items.GetAll().FirstOrDefault(i => i.ParentASIN == existParentItem.ASIN && i.Market == (int)destMarket && (String.IsNullOrEmpty(destMarketplaceId) || i.MarketplaceId == destMarketplaceId) && i.Size == v.Size && (i.Color == v.Color || String.IsNullOrEmpty(v.Color))); if (item == null) { var itemsCandidats = db.Items.GetAll() .Where(i => i.ParentASIN == existParentItem.ASIN && i.Market == (int)destMarket && (String.IsNullOrEmpty(destMarketplaceId) || i.MarketplaceId == destMarketplaceId) && i.Size == v.Size) .ToList(); if (itemsCandidats.Count == 1) { item = itemsCandidats[0]; } if (item == null) { continue; throw new Exception("Warning: missing item"); } } if (!v.StyleId.HasValue || !v.StyleItemId.HasValue) { continue; throw new Exception("Warning: missing StyleId"); } if (String.IsNullOrEmpty(item.Barcode)) { if (!String.IsNullOrEmpty(v.Barcode)) { item.Barcode = v.Barcode; } else { var listing = db.Listings.GetAll().FirstOrDefault(l => l.ItemId == item.Id); var result = _barcodeService.AssociateBarcodes(listing?.SKU, _time.GetAppNowTime(), null); if (!String.IsNullOrEmpty(result.Barcode)) { item.Barcode = result.Barcode; } } } _log.Info("Item Name changed: " + item.Title + " => " + parentItem.AmazonName); item.Title = parentItem.AmazonName; db.Commit(); } _log.Info("Already exists: " + parentItem.ASIN); } } } }
public void SyncItems(DropShipperApi api) { var sync = new DSCustomItemsSync(_log, _time, _dbFactory, _barcodeService, DSHelper.MBGPAId, MarketType.Walmart, "", MarketType.DropShipper, MarketplaceKeeper.DsPAWMCom); sync.SyncItems(api); }
public void SyncQty(DropShipperApi api) { var styles = api.GetQuantities(_log, MarketType.DropShipper, MarketplaceKeeper.DsPAWMCom); styles = styles.Where(st => st.StyleID == "WS20052SS").ToList(); using (var db = _dbFactory.GetRWDb()) { foreach (var incomeStyle in styles) { var findStyle = db.Styles.GetAll().FirstOrDefault(st => (st.StyleID == incomeStyle.StyleID || st.OriginalStyleID.Contains(incomeStyle.StyleID + ";")) && !st.Deleted); if (findStyle != null) { var changedStyleItemIds = new List <long>(); foreach (var incomeStyleItem in incomeStyle.StyleItems) { var findStyleItem = db.StyleItems.GetAll().FirstOrDefault(si => si.StyleId == findStyle.Id && si.Size == incomeStyleItem.Size && (si.Color == incomeStyleItem.Color || (String.IsNullOrEmpty(si.Color) && String.IsNullOrEmpty(incomeStyleItem.Color)))); if (findStyleItem != null && (findStyleItem.Quantity != incomeStyleItem.Quantity || findStyleItem.QuantitySetDate != incomeStyleItem.QuantitySetDate)) { _quantityManager.LogStyleItemQuantity(db, findStyleItem.Id, incomeStyleItem.Quantity, findStyleItem.Quantity, QuantityChangeSourceType.SetByAutoQuantity, null, null, null, _time.GetAppNowTime(), null); findStyleItem.Quantity = incomeStyleItem.Quantity; findStyleItem.QuantitySetDate = incomeStyleItem.QuantitySetDate; changedStyleItemIds.Add(incomeStyleItem.StyleItemId); } else { _log.Info("Unable to find style size: " + findStyle.StyleID + " - " + incomeStyleItem.Size + " / " + incomeStyleItem.Color); } } db.Commit(); if (changedStyleItemIds.Any()) { _cacheService.RequestStyleIdUpdates(db, new List <long>() { findStyle.Id }, UpdateCacheMode.IncludeChild, null); SystemActionHelper.RequestQuantityDistribution(db, _actionService, findStyle.Id, null); } } else { _log.Info("Unable to find style: " + incomeStyle.StyleID); } } } }