private EDIXmlSegment get_begin_segment(OrderShippingInfo orderShippingInfo) { var begin = new EDIXmlSegment("BSN", _ediXmlBuildValues); begin.Add(new EDIXmlElement("BSN01", "00", _ediXmlBuildValues)); begin.Add(new EDIXmlElement("BSN02", orderShippingInfo.BOL, _ediXmlBuildValues)); begin.Add(new EDIXmlElement("BSN03", DateTime.Today.ToString("yyyyMMdd"), _ediXmlBuildValues)); begin.Add(new EDIXmlElement("BSN04", DateTime.Now.ToString("HHmmss"), _ediXmlBuildValues)); return(begin); }
public ActionResult Send(EnterShippingDetailsViewModel viewModel, Cart cart) { if (!ModelState.IsValid || viewModel.DeliverType == DeliverType.NULL || viewModel.PaymentType == PaymentType.NULL) { if (viewModel.DeliverType == DeliverType.NULL) { ModelState.AddModelError("DeliverType", "Выберите способ доставки"); } if (viewModel.PaymentType == PaymentType.NULL) { ModelState.AddModelError("PaymentType", "Выберите способ оплаты"); } return(View("EnterShippingDetails", new EnterShippingDetailsViewModel() { Contact = ContactViewModel.From(CurrentUser().Contact), Cart = cart, User = CurrentUser(), DeliverPrices = daoTemplate.FindAll <DeliverPrices>()[0], DeliverType = viewModel.DeliverType, Comment = viewModel.Comment })); } OrderShippingInfo info = OrderShippingInfo.From(viewModel); AddOrderResult result = orderService.AddOrder(cart, CurrentUser(), info); var message = MailService.RenderViewToString("~/Views/MailTemplates/NewOrder.aspx", result.Order, this.ControllerContext); BillViewModel model = new BillViewModel() { Price = result.Order.SummWithDiscount, Address = result.Order.ShippingDetails.AddressBill(), Uid = result.Order.Uid, UserName = result.Order.ShippingDetails.FullName }; var attachment = ""; if (result.Order.PaymentType == PaymentType.Bank) { attachment = MailService.RenderViewToString("~/Views/Order/Bill.aspx", model, this.ControllerContext); } MailService.Send("Новый заказ - Elfam.ru", message, result.Order.User.Email, attachment, null); message = MailService.RenderViewToString("~/Views/MailTemplates/NewOrderAdmin.aspx", result.Order, this.ControllerContext); // MailService.Send("Новый заказ № " + result.Order.Uid, message, "*****@*****.**"); mailService.SendCcAdmins("Новый заказ № " + result.Order.Uid, message, "*****@*****.**"); cart.Items.Clear(); return(RedirectToAction("DetailsUser", "Order", new { id = result.Order.Uid })); }
public AddOrderResult AddOrder(Cart cart, User user, OrderShippingInfo orderInfo) { if (cart == null) { throw new ArgumentException("cart is null"); } if (cart.Items == null) { throw new ArgumentException("cart items is null"); } if (user == null) { throw new ArgumentException("user is null"); } if (orderInfo == null) { throw new ArgumentException("orderInfo is null"); } // construct order var orderLines = new List <OrderLine>(); var orderOutcomes = new List <Outcome>(); foreach (CartItem item in cart.Items) { IList <Income> incomes = FindOldestIncomesForProduct(item.Product, item.Quantity); int quantity = item.Quantity; var outcomes = new List <Outcome>(); foreach (Income income in incomes) { int n = Math.Min(quantity, income.QuantityCurrent); income.QuantityCurrent -= n; _daoTemplate.Save(income); Outcome outcome = new Outcome(item.Product.Price, n, income, user.Discount + cart.CurrentDiscount()); quantity -= n; outcomes.Add(outcome); } orderOutcomes.AddRange(outcomes); orderLines.Add(new OrderLine(item.Product, item.Quantity, outcomes)); } Order order = new Order(orderOutcomes, orderLines); order.Comment = orderInfo.Comment ?? ""; DeliverPrices prices = _daoTemplate.FindAll <DeliverPrices>()[0]; if (orderInfo.PaymentType == PaymentType.OnPost) { order.DeliverPrice = prices.PostWhenReceived(cart.SummDiscount()); } else { order.DeliverPrice = GetPrice(orderInfo.DeliverType); } order.CopyFrom(orderInfo); order.User = user; order.Discount = user.Discount + cart.CurrentDiscount(); _daoTemplate.Save(order); order.Uid = _daoTemplate.FindByID <UniqueId>(order.Id).Uid; _daoTemplate.Save(order); return(new AddOrderResult() { Order = order }); }
public void SetUp() { _product = new Product() { Id = 1 }; _incomesForProduct = new List <Income> { new Income() { BuyPrice = 10, Date = new DateTime(2000, 6, 28), Id = 1, Product = _product, QuantityCurrent = 10, QuantityInital = 10 }, new Income() { BuyPrice = 20, Date = new DateTime(2000, 5, 28), Id = 2, Product = _product, QuantityCurrent = 10, QuantityInital = 10 }, new Income() { BuyPrice = 30, Date = new DateTime(2000, 4, 28), Id = 3, Product = _product, QuantityCurrent = 10, QuantityInital = 10 }, new Income() { BuyPrice = 40, Date = new DateTime(2000, 3, 28), Id = 4, Product = _product, QuantityCurrent = 10, QuantityInital = 10 }, new Income() { BuyPrice = 50, Date = new DateTime(2000, 2, 28), Id = 5, Product = _product, QuantityCurrent = 10, QuantityInital = 10 }, }; _emptyIncome = new Income() { BuyPrice = 50, Date = new DateTime(1980, 2, 28), Id = 6, Product = _product, QuantityCurrent = 0, QuantityInital = 0 }; _incomesForProduct.Add(_emptyIncome); _product.Incomes = _incomesForProduct; _cartItems = new List <CartItem> { new CartItem() { Product = _product, Quantity = 33 } }; _user = new User() { }; _shippingInfo = new OrderShippingInfo() { }; _daoTemplate = new Mock <IDaoTemplate>(); _daoTemplate.Setup(x => x.FindByID <Product>(1)).Returns(_product); _daoTemplate.Setup(x => x.FindByID <UniqueId>(0)).Returns(new UniqueId() { Uid = 123 }); _orderService = new OrderService(); _orderService.DaoTemplate = _daoTemplate.Object; }
protected EDIXmlTransactionSet CreateTransactionSet(OrderShippingInfo message) { if (message.Lines.Count() == 0) { throw new Exception("Shipped order contains no line items!"); } var originalDoc = _docsRepo.GetByDocumentControlNumberAndPartnerID(message.ControlNumber.CastToInt(), BusinessPartner.Initech.Number); if (originalDoc == null) { throw new Exception(string.Format("Control number {0} not found for business partner {1}.", message.ControlNumber, message.BusinessPartnerNumber)); } var orderTypeElement = originalDoc.ResponseElements.Find(e => e.ElementName == "REF02" && (e.Qualifier == Qualifier.MutuallyAssignedCode.Value)); var priorityElement = originalDoc.ResponseElements.Find(e => e.ElementName == "REF02" && (e.Qualifier == Qualifier.ServiceLevelNumber.Value)); var doc = new EDIXmlTransactionSet(_segmentFactory) { ISA = _repo.GetNextISA(GroupTypeConstants.AdvanceShipNotice, BusinessPartner.Initech.Number) }; var docDef = _repo.GetNextDocument(doc.ISA, 856); doc.SetHeader("856", docDef.ControlNumber); docDef.ERPID = message.BOL; _repo.Save(docDef.ISAEntity); doc.AddSegment(get_begin_segment(message)); if (message.MaxDateShipped() > DateTime.MinValue) { doc.AddSegment(_segmentFactory.GetDateTimeSegment(EDIDateQualifiers.Shipped, message.MaxDateShipped())); } var hl = HierarchicalLevelLoopWrapper.BuildWrapper("O", _segmentFactory, true); hl.AddSegment(_segmentFactory.GetPurchaseOrderReference(message.CustomerPO.Trim())); if (orderTypeElement != null) { hl.AddSegment(_segmentFactory.GetReferenceIDSegment(orderTypeElement.Qualifier, orderTypeElement.Value)); } if (priorityElement != null) { hl.AddSegment(_segmentFactory.GetReferenceIDSegment(priorityElement.Qualifier, priorityElement.Value)); } var addrs = new AddressLoop(_segmentFactory); if (message.ShipToAddress.AddressName.IsNullOrEmpty()) { message.ShipToAddress.AddressName = "FEDERAL EXPRESS"; } addrs.AddAddress(message.ShipToAddress, Qualifier.EmptyQualifier); addrs.AddAddress(message.ShipFromAddress, Qualifier.EmptyQualifier); hl.AddLoop(addrs); message.Lines.ForEach(l => add_line(hl, l, originalDoc.LineItems)); hl.AddTo(doc); doc.AddSegment(_segmentFactory.GetTransactionTotal(message.Lines.Count())); doc.SetFooter(); return(doc); }
public static IList <MessageString> CancelCurrentOrderLabels( ILogService log, IUnitOfWork db, ILabelService labelService, ITime time, long orderId, bool sampleMode) { var cancelTrackings = GetOrdersToCancel(db, orderId); var results = new List <MessageString>(); foreach (var tracking in cancelTrackings) { MailLabelInfo mailInfo = null; OrderShippingInfo shippingInfo = null; if (tracking.LabelFromType == (int)LabelFromType.Mail) { mailInfo = db.MailLabelInfos.Get(tracking.Id); if (mailInfo != null) { mailInfo.CancelLabelRequested = true; } } else { shippingInfo = db.OrderShippingInfos.Get(tracking.Id); if (shippingInfo != null) { shippingInfo.CancelLabelRequested = true; } } try { string shipmentIdentifier = tracking.StampsTxId; if (tracking.ShipmentProviderType == (int)ShipmentProviderType.Stamps || tracking.ShipmentProviderType == (int)ShipmentProviderType.StampsPriority) { shipmentIdentifier = tracking.TrackingNumber; } var result = labelService.CancelLabel((ShipmentProviderType)tracking.ShipmentProviderType, shipmentIdentifier, sampleMode); if (result.IsSuccess) { results.Add(MessageString.Success(tracking.TrackingNumber + " (cancelled)" + ", OrderId=" + orderId)); if (tracking.LabelFromType == (int)LabelFromType.Mail) { if (mailInfo != null) { mailInfo.LabelCanceled = true; mailInfo.LabelCanceledDate = time.GetAppNowTime(); } } else { if (shippingInfo != null) { shippingInfo.LabelCanceled = true; shippingInfo.LabelCanceledDate = time.GetAppNowTime(); } } } else { results.Add(MessageString.Error(tracking.TrackingNumber + " (cancellation was failed with error: " + result.Message + ")")); } } catch (Exception ex) { results.Add(MessageString.Error(tracking.TrackingNumber + " (cancellation was failed with error: " + ExceptionHelper.GetMostDeeperException(ex) + ")")); } } db.Commit(); if (!cancelTrackings.Any()) { results.Add(MessageString.Success("No tracking numbers to cancel")); } return(results); }