public static PrintLabelResult GenerateLabel( IUnitOfWork db, ILabelService labelService, IWeightService weightService, IShippingService shippingService, MailViewModel model, DateTime when, long?by) { var shippingMethod = db.ShippingMethods.GetByIdAsDto(model.ShippingMethodSelected.Value); var orderItems = model.Items.Select(i => i.GetItemDto()).ToList() ?? new List <DTOOrderItem>(); //Fill with additional data MailViewModel.FillItemsWithAdditionalInfo(db, weightService, model.OrderID, orderItems); var mailInfo = new MailLabelDTO { FromAddress = model.FromAddress.GetAddressDto(), ToAddress = model.ToAddress.GetAddressDto(), Notes = model.Notes, Instructions = model.Instructions, OrderId = model.OrderID, WeightLb = model.WeightLb, WeightOz = model.WeightOz, PackageHeight = model.PackageHeight, PackageLength = model.PackageLength, PackageWidth = model.PackageWidth, IsAddressSwitched = model.IsAddressSwitched, IsUpdateRequired = model.UpdateAmazon, IsCancelCurrentOrderLabel = model.CancelCurrentOrderLabel, IsInsured = model.IsInsured, IsSignConfirmation = model.IsSignConfirmation, TotalPrice = model.TotalPrice, TotalPriceCurrency = model.TotalPriceCurrency, ShippingMethod = shippingMethod, ShipmentProviderType = shippingMethod.ShipmentProviderType, Items = orderItems, MarketplaceCode = model.MarketplaceCode, Reason = model.ReasonCode ?? 0, BoughtInTheCountry = MarketBaseHelper.GetMarketCountry((MarketType)model.Market, model.MarketplaceId), }; return(labelService.PrintMailLabel(db, shippingService, mailInfo, when, by, AppSettings.LabelDirectory, AppSettings.TemplateDirectory, AppSettings.IsSampleLabels)); }
public static ShippingMethodViewModel GetQuickPrintLabelRate(IUnitOfWork db, IDbFactory dbFactory, IServiceFactory serviceFactory, IShippingService shippingService, CompanyDTO company, ILogService log, ITime time, IWeightService weightService, string orderNumber) { var companyAddress = new CompanyAddressService(company); var model = MailViewModel.GetByOrderId(db, weightService, orderNumber); model.IsAddressSwitched = true; model.FromAddress = model.ToAddress; model.ToAddress = MailViewModel.GetFromAddress(companyAddress.GetReturnAddress(MarketIdentifier.Empty()), MarketplaceType.Amazon); model.ShipmentProviderId = (int)ShipmentProviderType.Stamps; model.ReasonCode = (int)MailLabelReasonCodes.ReturnLabelReasonCode; var rateProvider = serviceFactory.GetShipmentProviderByType((ShipmentProviderType)model.ShipmentProviderId, log, time, dbFactory, weightService, company.ShipmentProviderInfoList, null, null, null, null); var shippingOptionsResult = model.GetShippingOptionsModel(db, time, log, rateProvider, shippingService, weightService); ShippingMethodViewModel chipestRate = null; if (shippingOptionsResult.IsSuccess) { chipestRate = shippingOptionsResult.Data.OrderBy(o => o.Rate).FirstOrDefault(); } return(chipestRate); }
public CallResult <List <ShippingMethodViewModel> > GetShippingOptionsModel(IUnitOfWork db, ITime time, ILogService log, IShipmentApi rateProvider, IShippingService shippingService, IWeightService weightService) { var result = new CallResult <List <ShippingMethodViewModel> >(); if (String.IsNullOrEmpty(OrderID)) { result.Status = CallStatus.Fail; result.Message = "Empty Order Id"; return(result); } var fromAddress = FromAddress.GetAddressDto(); var toAddress = ToAddress.GetAddressDto(); if (AddressHelper.IsEmpty(fromAddress) || AddressHelper.IsEmpty(toAddress)) { result.Status = CallStatus.Fail; result.Message = "Empty from/to address"; } var orders = db.ItemOrderMappings.GetFilteredOrdersWithItems(weightService, new OrderSearchFilter() { Market = MarketType.None, EqualOrderNumber = OrderID, IgnoreBatchFilter = true, IncludeNotify = false, UnmaskReferenceStyles = false, IncludeSourceItems = true, }); if (!orders.Any()) { result.Status = CallStatus.Fail; result.Message = "Cannot find order Id"; return(result); } //NOTE: no need to use Items from model, we always buy label for all items, only needs a custom weight var orderItems = OrderHelper.BuildAndGroupOrderItems(orders.SelectMany(o => o.Items).ToList()); orderItems = OrderHelper.GroupBySourceItemOrderId(orderItems); var sourceOrderItems = OrderHelper.BuildAndGroupOrderItems(orders.SelectMany(o => o.SourceItems).ToList()); sourceOrderItems = OrderHelper.GroupBySourceItemOrderId(sourceOrderItems); var shipDate = db.Dates.GetOrderShippingDate(null); var mainOrder = orders.FirstOrDefault(); result = MailViewModel.GetShippingOptionsWithRate(db, log, time, rateProvider, shippingService, fromAddress, toAddress, shipDate, WeightLb ?? 0, (decimal)(WeightOz ?? 0), new ItemPackageDTO() { PackageLength = PackageLength, PackageWidth = PackageWidth, PackageHeight = PackageHeight, }, 0, new OrderRateInfo() { OrderNumber = mainOrder.OrderId, Items = orderItems, SourceItems = sourceOrderItems, EstimatedShipDate = ShippingUtils.AlignMarketDateByEstDayEnd(mainOrder.LatestShipDate, (MarketType)mainOrder.Market), TotalPrice = orders.Sum(o => o.TotalPrice), Currency = mainOrder.TotalPriceCurrency, }); return(result); }