public void ProcessRefundsAddComments() { var orderNumbers = new string[] { "002-4984322-1582658", "115-7133068-0543442", "107-3678266-6682660", "104-9680685-2993855", "114-2903306-3741829", "110-9470669-5336239", "701-4988323-0546632", "108-4618630-0086635", "109-8552981-9073035", "114-6351653-1882624", "111-9932301-2780224", "109-4832961-2930620", "108-4433058-4988231", "701-2615147-4537063", "106-3092827-4661027", "102-6937670-6201809", "702-0464553-4177858" }; using (var db = _dbFactory.GetRWDb()) { var actions = db.SystemActions.GetAll() .Where(a => a.Type == (int)SystemActionType.UpdateOnMarketReturnOrder) .ToList(); foreach (var action in actions) { if (!orderNumbers.Contains(action.Tag)) { continue; } var data = JsonConvert.DeserializeObject <ReturnOrderInput>(action.InputData); var order = db.Orders.GetByOrderNumber(data.OrderNumber); var unsuitableData = false; var unsuitableMessage = ""; var message = String.Format( "System accidently deducted shipping twice from a refund. If client complains, confirm additional refund wasn’t processed yet, and refund ONCE additional {0}{1}", PriceHelper.FormatCurrency(order.TotalPriceCurrency), data.Items.Sum(i => i.DeductShippingPrice)); db.OrderComments.Add(new OrderComment() { OrderId = order.Id, Message = message, Type = (int)CommentType.ReturnExchange, CreateDate = _time.GetAppNowTime(), }); db.Commit(); } } }
public ReturnQuantityItemViewModel(ListingOrderDTO item) { ItemOrderId = item.ItemOrderId; var image = item.ItemPicture; if (String.IsNullOrEmpty(image)) { image = item.StyleImage; } PictureUrl = ImageHelper.GetFirstOrDefaultPicture(image); Market = (MarketType)item.Market; MarketplaceId = item.MarketplaceId; ASIN = item.ASIN; SKU = item.SKU; ParentASIN = item.ParentASIN; StyleString = item.StyleID; ItemTitle = item.Title; Quantity = item.QuantityOrdered; Size = item.Size; DefaultLocation = item.Locations != null && item.Locations.Any() ? item.Locations.OrderByDescending(l => l.IsDefault).First() : null; PriceCurrency = PriceHelper.FormatCurrency(item.ItemPriceCurrency); ItemPrice = item.ItemPrice; ItemTax = item.ItemTax ?? 0; ItemPriceInUSD = PriceHelper.RougeConvertToUSD(PriceCurrency, item.ItemPrice); ShippingPrice = item.ShippingPrice; ShippingDiscount = item.ShippingDiscount ?? 0; ShippingTax = item.ShippingTax ?? 0; Weight = item.Weight ?? 0; StyleId = item.StyleId; StyleItemId = item.StyleItemId; InputQuantity = Quantity; InputDamagedQuantity = 0; }
public static OrderHistoryViewModel GetByOrderId(IUnitOfWork db, ILogService log, IWeightService weightService, string orderId) { DTOOrder order = null; if (!String.IsNullOrEmpty(orderId)) { orderId = orderId.RemoveWhitespaces(); var orderNumber = OrderHelper.RemoveOrderNumberFormat(orderId); var filter = new OrderSearchFilter() { EqualOrderNumber = orderNumber, IncludeMailInfos = true, IncludeNotify = false, UnmaskReferenceStyles = false, }; order = db.ItemOrderMappings .GetFilteredOrdersWithItems(weightService, filter) .FirstOrDefault(); } if (order == null) { return(null); } else { var anotherBuyerOrders = new List <OrderLinkViewModel>(); if (!String.IsNullOrEmpty(order.BuyerEmail)) { anotherBuyerOrders = db.Orders.GetAll().Where(o => o.BuyerEmail == order.BuyerEmail) .ToList() .Where(o => o.Id != order.Id) .OrderByDescending(o => o.OrderDate) .Select(o => new OrderLinkViewModel() { OrderId = o.Id, OrderNumber = o.AmazonIdentifier, OrderDate = o.OrderDate, OrderStatus = o.OrderStatus, Market = o.Market, MarketplaceId = o.MarketplaceId }) .ToList(); } var comments = db.OrderComments.GetByOrderIdDto(order.Id).ToList(); var emails = db.Emails.GetAllWithOrder(new EmailSearchFilter() { OrderId = orderId }).ToList(); var returnRequests = db.ReturnRequests.GetAll() .OrderByDescending(r => r.CreateDate) .Select(r => new ReturnRequestDTO() { OrderNumber = r.OrderNumber, ReceiveDate = r.ReceiveDate, ItemName = r.ItemName, CustomerComments = r.CustomerComments, Details = r.Details, CreateDate = r.CreateDate, Reason = r.Reason }) .Where(r => r.OrderNumber == order.OrderId) .ToList(); var refundRequests = RefundViewModel.GetByOrderId(db, order.OrderId); var labels = order.ShippingInfos .Where(i => !String.IsNullOrEmpty(i.LabelPath) //|| i.LabelPurchaseResult != null //NOTE: in case when bag system shows user issue (keeped twice shippings with labels) ) .ToList(); labels.AddRange(order.MailInfos); var address = order.GetAddressDto(); var changes = db.OrderChangeHistories.GetByOrderIdDto(order.Id) .ToList() .OrderByDescending(ch => ch.ChangeDate) .Select(ch => new OrderChangeViewModel(ch, emails)) .Where(ch => ch.ChangeType != OrderChangeTypes.None) //NOTE: Skipped empty .ToList(); changes.Add(OrderChangeViewModel.BuildCreateOrderChange(order)); changes.AddRange(comments.Select(c => new OrderChangeViewModel(c)).ToList()); changes.AddRange(emails.Select(e => new OrderChangeViewModel(e)).ToList()); changes.AddRange(labels.SelectMany(l => OrderChangeViewModel.BuildChanges(l)).ToList()); changes.AddRange(refundRequests.Select(r => new OrderChangeViewModel(r)).ToList()); changes.AddRange(returnRequests.Select(r => new OrderChangeViewModel(r)).ToList()); return(new OrderHistoryViewModel { //Notes = string.Format("{0} {1}", order.OrderId, itemsNotes), OrderID = order.OrderId, OrderEntityId = order.Id, OrderDate = order.OrderDate, Market = (MarketType)order.Market, MarketplaceId = order.MarketplaceId, WeightLb = (int)Math.Floor(order.WeightD / 16), WeightOz = order.WeightD % 16, TotalPrice = order.TotalPrice, PriceCurrency = PriceHelper.FormatCurrency(order.TotalPriceCurrency), Items = order.Items.Select(i => new OrderItemViewModel(i, false, false)).ToList(), Changes = changes.OrderByDescending(c => c.ChangeDate).ToList(), AnotherOrders = anotherBuyerOrders, ToAddress = new AddressViewModel(address), }); } }
public static OrderQuickSummaryViewModel GetByOrderId(IUnitOfWork db, ILogService log, IWeightService weightService, string orderId) { DTOOrder order = null; if (!String.IsNullOrEmpty(orderId)) { orderId = orderId.RemoveWhitespaces(); var orderNumber = OrderHelper.RemoveOrderNumberFormat(orderId); var filter = new OrderSearchFilter() { EqualOrderNumber = orderNumber, IncludeMailInfos = true, IncludeNotify = false, UnmaskReferenceStyles = false, }; order = db.ItemOrderMappings .GetFilteredOrdersWithItems(weightService, filter) .FirstOrDefault(); } if (order == null) { return(null); } else { var refundRequestList = RefundViewModel.GetByOrderId(db, order.OrderId); var shippingPrice = 0M; var activeShippings = order.ShippingInfos.Where(i => i.IsActive).ToList(); activeShippings.AddRange(order.MailInfos); activeShippings = activeShippings.OrderBy(sh => sh.LabelPurchaseDate).ToList(); //if (order.MailInfos.Any(m => !m.LabelCanceled) // && order.ShippingInfos.All(sh => String.IsNullOrEmpty(sh.LabelPath) || sh.LabelCanceled)) //{ // var mailShipping = order.MailInfos.OrderBy(m => m.LabelPurchaseDate).FirstOrDefault(l => !l.LabelCanceled); // activeShippings = new List<OrderShippingInfoDTO>() { mailShipping }; //} //var mainActiveShipping = activeShippings.FirstOrDefault(); //var shipmentProviderType = mainActiveShipping != null ? mainActiveShipping.ShipmentProviderType : (int)Core.Models.Settings.ShipmentProviderType.Stamps; var address = order.GetAddressDto(); return(new OrderQuickSummaryViewModel() { OrderID = order.OrderId, OrderEntityId = order.Id, OrderDate = order.OrderDate, OrderStatus = order.OrderStatus, Market = (MarketType)order.Market, MarketplaceId = order.MarketplaceId, OrderIsOnHold = order.OnHold, WeightLb = (int)Math.Floor(order.WeightD / 16), WeightOz = order.WeightD % 16, TrackingNumbers = activeShippings.Where(t => !String.IsNullOrEmpty(t.TrackingNumber)).Select(t => new LabelViewModel() { TrackingNumber = t.TrackingNumber, Carrier = t.ShippingMethod.CarrierName, FromType = (LabelFromType)t.LabelFromType, TrackingStatusSource = t.TrackingStateSource, ShippingDate = t.ShippingDate, EstDeliveryDate = t.EstimatedDeliveryDate, ActualDeliveryDate = t.ActualDeliveryDate, LastTrackingStateUpdateDate = t.LastTrackingRequestDate, IsCanceled = t.CancelLabelRequested || t.LabelCanceled, DeliveryStatusMessage = GetDeliveryStatus(order.LatestDeliveryDate, t.ActualDeliveryDate, t.TrackingStateDate, t.DeliveredStatus == (int)DeliveredStatusEnum.DeliveredToSender), ShippingMethodName = t.ShippingMethod != null ? ShippingUtils.PrepareMethodNameToDisplay(t.ShippingMethod.Name, t.DeliveryDaysInfo) : string.Empty, ShippingProviderName = ShipmentProviderHelper.GetName((ShipmentProviderType)t.ShipmentProviderType), }).ToList(), PriceCurrency = PriceHelper.FormatCurrency(order.TotalPriceCurrency), ExpectedShipDate = order.LatestShipDate, ExpectedDeliveryDate = order.LatestDeliveryDate, //ShippingMethodName = mainActiveShipping != null && mainActiveShipping.ShippingMethod != null // ? ShippingUtils.PrepareMethodNameToDisplay(mainActiveShipping.ShippingMethod.Name, mainActiveShipping.DeliveryDaysInfo) : string.Empty, //ShippingProviderName = ShipmentProviderHelper.GetName((ShipmentProviderType)shipmentProviderType), //ShippingDate = activeShippings.Where(i => i.IsActive).Max(i => i.ShippingDate), //DeliveryDate = mainActiveShipping != null ? mainActiveShipping.ActualDeliveryDate : null, //DeliveryStatus = GetDeliveryStatus(order.LatestDeliveryDate, // mainActiveShipping != null ? mainActiveShipping.ActualDeliveryDate : null, // mainActiveShipping != null ? mainActiveShipping.TrackingStateDate : null, // mainActiveShipping != null ? mainActiveShipping.DeliveredStatus == (int)DeliveredStatusEnum.DeliveredToSender : false), Refunds = refundRequestList, Items = order.Items.Select(i => new OrderItemViewModel(i, false, false)).ToList(), ToAddress = address, }); } }