예제 #1
0
        public OrderPackage Clone()
        {
            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            formatter.Serialize(memoryStream, this);
            memoryStream.Position = 0;
            OrderPackage newPackage = (OrderPackage)formatter.Deserialize(memoryStream);

            return(newPackage);
        }
예제 #2
0
        private OrderPackage ShipItems(Order o, string trackingNumber, string serviceProvider, string serviceCode, bool dontShip)
        {
            OrderPackage p = new OrderPackage();

            p.ShipDateUtc = DateTime.UtcNow;
            p.TrackingNumber = trackingNumber;
            p.ShippingProviderId = serviceProvider;
            p.ShippingProviderServiceCode = serviceCode;
            foreach (GridViewRow gvr in this.ItemsGridView.Rows)
            {
                if (gvr.RowType == DataControlRowType.DataRow)
                {
                    LineItem li = o.GetLineItem((long)this.ItemsGridView.DataKeys[gvr.RowIndex].Value);
                    if (li != null)
                    {

                        int qty = 0;
                        TextBox QtyToShip = (TextBox)gvr.FindControl("QtyToShip");
                        if (QtyToShip != null)
                        {
                            if (!int.TryParse(QtyToShip.Text, out qty))
                            {
                                qty = 0;
                            }
                        }
                        p.Items.Add(new OrderPackageItem(li.ProductId, li.Id, qty));
                        p.Weight += (li.ProductShippingWeight * qty);
                    }
                }
            }
            p.WeightUnits = WebAppSettings.ApplicationWeightUnits;

            o.Packages.Add(p);            
            if (!dontShip)
            {
                MTApp.OrdersShipPackage(p, o);
            }
            MTApp.OrderServices.Orders.Update(o);

            return p;
        }
예제 #3
0
        private ActionResult UpdateOrderDelimited()
        {            
            string orderNumber = Request["ordernumber"] ?? string.Empty;
            string orderStatus = Request["orderstatus"] ?? string.Empty;
            string stoneEdgeNumber = Request["refnumber"] ?? string.Empty;
            string notes = Request["orderdetail"] ?? string.Empty;

            List<StoneEdgeTrackingData> trackingData = new List<StoneEdgeTrackingData>();

            try
            {
                string trackingCount = Request["trackcount"] ?? string.Empty;
                int count = 0;
                int.TryParse(trackingCount, out count);

                // Parse Package Data
                if (count == 1)
                {
                    StoneEdgeTrackingData t = new StoneEdgeTrackingData();
                    t.TrackingNumber = Request["tracknum"] ?? string.Empty;
                    t.Carrier = Request["trackcarrier"] ?? string.Empty;
                    string trackingPickupDate = Request["trackpickupdate"] ?? string.Empty;
                    DateTime temp = new DateTime();
                    if (DateTime.TryParse(trackingPickupDate, out temp))
                    {
                        t.PickUpDate = temp;
                    }
                    trackingData.Add(t);
                }
                else
                {
                    for (int i = 1; i <= count; i++)
                    {
                        StoneEdgeTrackingData t = new StoneEdgeTrackingData();
                        t.TrackingNumber = Request["tracknum" + i] ?? string.Empty;
                        t.Carrier = Request["trackcarrier" + 1] ?? string.Empty;
                        string trackingPickupDate = Request["trackpickupdate" + 1] ?? string.Empty;
                        DateTime temp = new DateTime();
                        if (DateTime.TryParse(trackingPickupDate, out temp))
                        {
                            t.PickUpDate = temp;
                        }
                        trackingData.Add(t);
                    }
                }

                // Find Order
                var o = MTApp.OrderServices.Orders.FindByOrderNumber(orderNumber);
                if (o == null)
                {
                    return Content("SETIResponse: update=False;Notes=Order " + orderNumber + " could not be found", "text/plain");
                }

                // Update Status
                var statusMatch = OrderStatusCode.FindAll().Where(y => y.StatusName.ToUpperInvariant() == orderStatus.ToUpperInvariant()).FirstOrDefault();
                if (statusMatch != null)
                {
                    o.StatusCode = statusMatch.Bvin;
                    o.StatusName = statusMatch.StatusName;

                }

                // Packages                
                foreach (var data in trackingData)
                {
                    OrderPackage pak = new OrderPackage();
                    pak.Description = "Carrier: " + data.Carrier + " | Imported from Stone Edge Ref:# " + stoneEdgeNumber + " at " + DateTime.Now;
                    pak.HasShipped = true;
                    pak.OrderId = o.bvin;
                    if (data.PickUpDate.HasValue)
                    {
                        pak.ShipDateUtc = TimeZoneInfo.ConvertTimeToUtc(data.PickUpDate.Value, MTApp.CurrentStore.Settings.TimeZone);
                    }
                    else
                    {
                        pak.ShipDateUtc = DateTime.UtcNow;
                    }
                    pak.ShippingMethodId = data.Carrier;
                    pak.ShippingProviderId = data.Carrier;
                    pak.TrackingNumber = data.TrackingNumber;                    
                    o.Packages.Add(pak);
                }

                if (MTApp.OrderServices.Orders.Update(o))
                {
                    return Content("SETIResponse: update=OK;Notes=", "text/plain");
                }
                return Content("SETIResponse: update=false;Notes=Error While Saving Order", "text/plain");
            }
            catch (Exception ex)
            {
                return Content("SETIResponse: update=False;Notes=Exception:" + ex.Message, "text/plain");
            }            
        }
예제 #4
0
        private ActionResult UpdateOrderXml(string data)
        {
            try
            {
                XElement xml = XElement.Parse(data);
                foreach (XElement order in xml.Elements("Order"))
                {
                    string orderNumber = order.TryGetElementValue("OrderNumber", "");
                    string stoneEdgeNumber = order.TryGetElementValue("ReferenceNumber", "");
                    string orderStatus = order.TryGetElementValue("Status", "");
                    string notes = order.TryGetElementValue("Notes", "");
                    string comments = order.TryGetElementValue("Comments", "");
                    string stringChangeDate = order.TryGetElementValue("ChangeDateTime", "");

                    // Find Order
                    var o = MTApp.OrderServices.Orders.FindByOrderNumber(orderNumber);
                    if (o == null)
                    {
                        return Content("SETIResponse: update=False;Notes=Order " + orderNumber + " could not be found", "text/plain");
                    }


                    List<OrderPackage> packages = new List<OrderPackage>();
                    XElement xpackages = order.Element("Packages");
                    if (xpackages != null)
                    {
                        foreach (var xpak in xpackages.Elements("Package"))
                        {
                            OrderPackage pak = new OrderPackage();

                            pak.ThirdPartyId = xpak.TryGetElementValue("PackageID", "");
                            pak.TrackingNumber = xpak.TryGetElementValue("TrackingID", "");
                            string trackingPickupDate = xpak.TryGetElementValue("PickupDate", "");
                            DateTime temp = new DateTime();
                            if (DateTime.TryParse(trackingPickupDate, out temp))
                            {
                                pak.ShipDateUtc = TimeZoneInfo.ConvertTimeToUtc(temp, MTApp.CurrentStore.Settings.TimeZone);
                            }
                            else
                            {
                                pak.ShipDateUtc = DateTime.UtcNow;
                            }
                            pak.ShippingProviderId = xpak.TryGetElementValue("Shipper", "Unknown");
                            pak.ShippingMethodId = xpak.TryGetElementValue("Method", "Unknown");                            
                            pak.Description = "Carrier: " + pak.ShippingProviderId + " | Imported from Stone Edge Ref:# " + stoneEdgeNumber + " at " + DateTime.Now;
                            pak.HasShipped = true;                            
                                                                                  
                            packages.Add(pak);
                        }
                    }

                    // Line Item Details
                    if (packages.Count > 0)
                    {
                        XElement xitems = order.Element("Items");
                        if (xitems != null)
                        {
                            foreach (XElement xitem in xitems.Elements("Item"))
                            {
                                long lineItemId = xitem.TryGetElementValueAsLong("ItemNumber", 0);
                                string stoneEdgeItemId = xitem.TryGetElementValue("RefNumber", "");
                                string status = xitem.TryGetElementValue("Status", "");
                                int CountOrdered = xitem.TryGetElementValueAsInt("Ordered", 0);
                                int CountShipped = xitem.TryGetElementValueAsInt("Shipped", 0);
                                int CountNeeded = xitem.TryGetElementValueAsInt("Needed", 0);
                                string note = xitem.TryGetElementValue("Notes", "");

                                XElement itemPackages = xitem.Element("Packages");
                                if (itemPackages != null)
                                {
                                    foreach (var itemPackage in itemPackages.Elements("Package"))
                                    {
                                        string packageId = itemPackage.TryGetElementValue("PackageID", "");
                                        int quantity = itemPackage.TryGetElementValueAsInt("Quantity", 0);

                                        if (packageId.Trim().Length > 0 && quantity > 0)
                                        {
                                            // Update the Package with line item quantity
                                            var thePak = packages.Where(y => y.ThirdPartyId == packageId).FirstOrDefault();
                                            if (thePak != null)
                                            {
                                                // Get Product Bvin from Line Item
                                                string pid = string.Empty;
                                                var li = o.Items.Where(y => y.Id == lineItemId).FirstOrDefault();
                                                if (li != null) pid = li.ProductId;
                                                
                                                thePak.Items.Add(new OrderPackageItem()
                                                {
                                                    LineItemId = lineItemId,
                                                    ProductBvin = pid,
                                                    Quantity = quantity
                                                });
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    

                    // Update Status
                    var statusMatch = OrderStatusCode.FindAll().Where(y => y.StatusName.ToUpperInvariant() == orderStatus.ToUpperInvariant()).FirstOrDefault();
                    if (statusMatch != null)
                    {
                        o.StatusCode = statusMatch.Bvin;
                        o.StatusName = statusMatch.StatusName;

                    }

                    // Add Packages
                    if (packages.Count > 0)
                    {
                        o.Packages.AddRange(packages);   
                    }

                    if (!MTApp.OrderServices.Orders.Update(o))
                    {
                        return Content("SETIResponse: update=false;Notes=Error While Saving Order", "text/plain");
                    }

                    if (packages.Count > 0)
                    {
                        foreach (var p in packages)
                        {
                            MTApp.OrdersShipPackage(p, o);
                        }
                        MTApp.OrderServices.Orders.Update(o);
                    }
                    
                }
                
                return Content("SETIResponse: update=OK;Notes=", "text/plain");
            }
            catch (Exception ex)
            {
                return Content("SETIResponse: update=False;Notes=Exception:" + ex.Message, "text/plain");
            }            
        }
        public decimal OrderPackagesFindDeclaredValue(OrderPackage p, Order o)
        {
            decimal result = 0m;
            if (o != null)
            {
                foreach (OrderPackageItem pi in p.Items)
                {
                    foreach (Orders.LineItem li in o.Items)
                    {
                        if (li.Id == pi.LineItemId)
                        {
                            decimal lineValue = 0m;
                            lineValue = li.AdjustedPricePerItem * pi.Quantity;
                            result += lineValue;
                            break;
                        }
                    }
                }
            }

            return result;
        }
        private bool OrdersUnshipItems(OrderPackage p, Order o)
        {
            bool result = true;

            if (p.Items.Count > 0)
            {
                if (o != null)
                {
                    if (o.bvin != string.Empty)
                    {
                        foreach (OrderPackageItem pi in p.Items)
                        {
                            if (pi.LineItemId > 0)
                            {
                                Orders.LineItem li = o.GetLineItem(pi.LineItemId);
                                if (li != null)
                                {
                                    int quantityToUnship = 0;
                                    if (li.QuantityShipped < pi.Quantity)
                                    {
                                        quantityToUnship = li.QuantityShipped;
                                    }
                                    else
                                    {
                                        quantityToUnship = pi.Quantity;
                                    }
                                    CatalogServices.InventoryLineItemUnShipQuantity(li, quantityToUnship);
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }
        private bool OrdersShipItems(OrderPackage p, Order o)
        {
            bool result = true;

            if (p.Items.Count > 0)
            {
                if (o != null)
                {
                    if (o.bvin != string.Empty)
                    {
                        foreach (OrderPackageItem pi in p.Items)
                        {
                            if (pi.LineItemId > 0)
                            {
                                Orders.LineItem li = o.GetLineItem(pi.LineItemId);
                                if (li != null)
                                {
                                    if (pi.Quantity > (li.Quantity - li.QuantityShipped))
                                    {
                                        pi.Quantity = li.Quantity - li.QuantityShipped;
                                    }

                                    if (pi.Quantity <= 0)
                                    {
                                        pi.Quantity = 0;
                                    }
                                    else
                                    {
                                        CatalogServices.InventoryLineItemShipQuantity(li, pi.Quantity);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }
 public bool OrdersShipPackage(OrderPackage p, Order o)
 {
     p.HasShipped = true;
     OrdersShipItems(p, o);
     BusinessRules.OrderTaskContext c = new BusinessRules.OrderTaskContext(this);
     c.Order = o;
     c.UserId = this.CurrentCustomerId;
     if (!BusinessRules.Workflow.RunByName(c, BusinessRules.WorkflowNames.PackageShipped))
     {
         EventLog.LogEvent("PackageShippedWorkflow", "Package Shipped Workflow Failed", EventLogSeverity.Debug);
         foreach (BusinessRules.WorkflowMessage item in c.Errors)
         {
             EventLog.LogEvent("PackageShippedWorkflow", item.Description, EventLogSeverity.Debug);
         }
     }
     return true;
 }
예제 #9
0
        public void FromDTO(OrderDTO dto)
        {
            if (dto == null) return;

            this.AffiliateID = dto.AffiliateID ?? string.Empty;
            this.BillingAddress.FromDto(dto.BillingAddress);
            this.bvin = dto.Bvin ?? string.Empty;
            this.Coupons.Clear();
            if (dto.Coupons != null)
            {
                foreach (OrderCouponDTO c in dto.Coupons)
                {
                    OrderCoupon cp = new OrderCoupon();
                    cp.FromDto(c);
                    this.Coupons.Add(cp);
                }
            }
            this.CustomProperties.Clear();
            if (dto.CustomProperties != null)
            {
                foreach (CustomPropertyDTO prop in dto.CustomProperties)
                {
                    CustomProperty p = new CustomProperty();
                    p.FromDto(prop);
                    this.CustomProperties.Add(p);
                }
            }
            this.FraudScore = dto.FraudScore;
            this.Id = dto.Id;
            this.Instructions = dto.Instructions ?? string.Empty;
            this.IsPlaced = dto.IsPlaced;
            this.Items.Clear();
            if (dto.Items != null)
            {
                foreach (LineItemDTO li in dto.Items)
                {
                    LineItem l = new LineItem();
                    l.FromDto(li);
                    this.Items.Add(l);
                }
            }
            this.LastUpdatedUtc = dto.LastUpdatedUtc;
            this.Notes.Clear();
            if (dto.Notes != null)
            {
                foreach (OrderNoteDTO n in dto.Notes)
                {
                    OrderNote nn = new OrderNote();
                    nn.FromDto(n);
                    this.Notes.Add(nn);
                }
            }
            this.OrderDiscountDetails.Clear();
            if (dto.OrderDiscountDetails != null)
            {
                foreach (DiscountDetailDTO d in dto.OrderDiscountDetails)
                {
                    Marketing.DiscountDetail m = new Marketing.DiscountDetail();
                    m.FromDto(d);
                    this.OrderDiscountDetails.Add(m);
                }
            }
            this.OrderNumber = dto.OrderNumber ?? string.Empty;
            this.Packages.Clear();
            if (dto.Packages != null)
            {
                foreach (OrderPackageDTO pak in dto.Packages)
                {
                    OrderPackage pak2 = new OrderPackage();
                    pak2.FromDto(pak);
                    this.Packages.Add(pak2);
                }
            }
            this.PaymentStatus = (OrderPaymentStatus)((int)dto.PaymentStatus);
            this.ShippingAddress.FromDto(dto.ShippingAddress);
            this.ShippingDiscountDetails.Clear();
            if (dto.ShippingDiscountDetails != null)
            {
                foreach (DiscountDetailDTO sd in dto.ShippingDiscountDetails)
                {
                    Marketing.DiscountDetail sdd = new Marketing.DiscountDetail();
                    sdd.FromDto(sd);
                    this.ShippingDiscountDetails.Add(sdd);
                }
            }
            this.ShippingMethodDisplayName = dto.ShippingMethodDisplayName ?? string.Empty;
            this.ShippingMethodId = dto.ShippingMethodId ?? string.Empty;
            this.ShippingProviderId = dto.ShippingProviderId ?? string.Empty;
            this.ShippingProviderServiceCode = dto.ShippingProviderServiceCode ?? string.Empty;
            this.ShippingStatus = (OrderShippingStatus)((int)dto.ShippingStatus);
            this.StatusCode = dto.StatusCode ?? string.Empty;
            this.StatusName = dto.StatusName ?? string.Empty;
            this.StoreId = dto.StoreId;
            this.ThirdPartyOrderId = dto.ThirdPartyOrderId ?? string.Empty;
            this.TimeOfOrderUtc = dto.TimeOfOrderUtc;
            this.TotalHandling = dto.TotalHandling;
            this.TotalShippingBeforeDiscounts = dto.TotalShippingBeforeDiscounts;
            this.TotalTax = dto.TotalTax;
            this.TotalTax2 = dto.TotalTax2;
            this.UserEmail = dto.UserEmail ?? string.Empty;
            this.UserID = dto.UserID ?? string.Empty;
        }