Пример #1
0
        public Order(Cart cart, DateTime?deliveryDate, bool giftwrapping, string shippingStreet, City shippingCity)
            : this()
        {
            if (!cart.CartLines.Any())
            {
                throw new InvalidOperationException("Cannot place order when cart is empty");
            }

            foreach (CartLine line in cart.CartLines)
            {
                OrderLines.Add(new OrderLine
                {
                    Product  = line.Product,
                    Price    = line.Product.Price,
                    Quantity = line.Quantity
                });
            }

            OrderDate      = DateTime.Today;
            DeliveryDate   = deliveryDate;
            Giftwrapping   = giftwrapping;
            ShippingStreet = shippingStreet;
            ShippingCity   = shippingCity;
        }
 private void Apply(OrderLineAdded obj)
 {
     OrderLines.Add(obj.OrderLine);
 }
Пример #3
0
 public void AddOrderLine(OrderLine orderLine)
 {
     OrderLines.Add(orderLine);
 }
Пример #4
0
        public OrderViewModel(IFormatProvider currencyFormat, PurchaseOrderModel order)
            : this(currencyFormat)
        {
            OrderNumber = order.TrackingNumber;
            OrderDate   = order.Created;
            Status      = order.Status;

            TotalLineItemsAmount = order.OrderForms.First().LineItems.Sum(i => i.ExtendedPrice);
            TotalAmount          = order.Total;
            Shipping             = order.ShippingTotal;

            // TODO: Make taxes work as it should, instead of flat hard codet 25% tax
            if (order.TaxTotal == 0 && order.Total > 0)
            {
                order.TaxTotal = ((decimal)0.25) * order.Total;
            }
            Tax = order.TaxTotal;


            Discount = order.OrderForms.First().LineItems.Sum(i => i.LineItemDiscountAmount + i.OrderLevelDiscountAmount) + order.OrderForms.First().Shipments.First().ShippingDiscountAmount;
            if (order.OrderForms.Any() && order.OrderForms.First().Payments.Any())
            {
                PaymentMethod = order.OrderForms.First().Payments.First().PaymentMethodName;
            }

            Email          = order.BillingEmail;
            Phone          = order.BillingPhone;
            BillingAddress = new Address(order.OrderAddresses.FirstOrDefault(a => a.Name == Constants.Order.BillingAddressName));
            var shippingAddress = order.OrderAddresses.FirstOrDefault(a => a.Name == Constants.Order.ShippingAddressName);
            ShippingAddress  = new Address(shippingAddress);
            DeliveryLocation = "";
            if (shippingAddress != null && !string.IsNullOrWhiteSpace(shippingAddress.DeliveryServicePoint))
            {
                DeliveryLocation = shippingAddress.DeliveryServicePoint;
            }

            foreach (var item in order.OrderForms.First().LineItems)
            {
                OrderLines.Add(new OrderLineViewModel(item));
            }

            // discounts
            var discounts = CartService.GetAllDiscounts(order);
            DiscountCodes = discounts.Where(x => !string.IsNullOrEmpty(x.DiscountCode)).Select(x => x.DiscountCode).ToList();

            ShippingTrackingNumber = "";
            if (order.OrderForms.Any() &&
                order.OrderForms.First().Shipments != null &&
                order.OrderForms.First().Shipments.Any())
            {
                ShippingTrackingNumber = order.OrderForms.First().Shipments.First().ShipmentTrackingNumber;
            }

            ErpOrderNumber = order.BackendOrderNumber;

            if (order.TrackingNumber.StartsWith("inv", StringComparison.OrdinalIgnoreCase))
            {
                Frequency      = order.Frequency;
                LatestDelivery = order.LatestDelivery;
            }
        }
Пример #5
0
 public void AddOrderLine(OrderLine ol)
 {
     OrderLines.Add(ol);
 }
Пример #6
0
        public OrderViewModel(PurchaseOrder order)
            : this()
        {
            OrderNumber = order.TrackingNumber;
            OrderDate   = order.Created;
            Status      = order.Status;

            TotalLineItemsAmount = order.OrderForms[0].LineItems.Sum(i => i.ExtendedPrice);
            TotalAmount          = order.Total;
            Shipping             = order.ShippingTotal;

            // TODO: Make taxes work as it should, instead of flat hard codet 25% tax
            if (order.TaxTotal == 0 && order.Total > 0)
            {
                order.TaxTotal = ((decimal)0.25) * order.Total;
            }
            Tax = order.TaxTotal;


            Discount = order.OrderForms[0].LineItems.Sum(i => i.LineItemDiscountAmount + i.OrderLevelDiscountAmount) + order.OrderForms[0].Shipments[0].ShippingDiscountAmount;
            if (order.OrderForms.Count > 0 && order.OrderForms[0].Payments.Count > 0)
            {
                PaymentMethod = order.OrderForms[0].Payments[0].PaymentMethodName;
            }

            try
            {
                Email = order.GetBillingEmail();
                Phone = order.GetBillingPhone();
            }
            catch (Exception ex)
            {
                // TODO: Inspect this, do we need a try catch here?
                _log.Error("Error getting email and/or phone for customer", ex);
            }

            BillingAddress = new Address(order.OrderAddresses.FirstOrDefault(a => a.Name == Constants.Order.BillingAddressName));
            var shippingAddress = order.OrderAddresses.FirstOrDefault(a => a.Name == Constants.Order.ShippingAddressName);

            ShippingAddress  = new Address(shippingAddress);
            DeliveryLocation = "";
            if (!string.IsNullOrWhiteSpace((string)shippingAddress[Constants.Metadata.Address.DeliveryServicePoint]))
            {
                try
                {
                    var deliveryServicePoint =
                        JsonConvert.DeserializeObject <ServicePoint>(
                            (string)shippingAddress[Constants.Metadata.Address.DeliveryServicePoint]);
                    DeliveryLocation = deliveryServicePoint.Name;
                }
                catch (Exception ex)
                {
                    // Todo: Move to method with more documentation about why this can fail
                    _log.Error("Error during deserializing delivery location", ex);
                }
            }

            foreach (Mediachase.Commerce.Orders.LineItem item in order.OrderForms[0].LineItems)
            {
                OrderLines.Add(new OrderLineViewModel(item));
            }

            // discounts
            var discounts = CartService.GetAllDiscounts(order);

            DiscountCodes = discounts.Where(x => !string.IsNullOrEmpty(x.DiscountCode)).Select(x => x.DiscountCode).ToList();


            ShippingTrackingNumber = "";
            if (order.OrderForms.Count > 0 &&
                order.OrderForms[0].Shipments != null &&
                order.OrderForms[0].Shipments.Count > 0)
            {
                ShippingTrackingNumber = order.OrderForms[0].Shipments[0].ShipmentTrackingNumber;
            }

            ErpOrderNumber = order.GetStringValue(Constants.Metadata.PurchaseOrder.BackendOrderNumber);
        }
Пример #7
0
        protected void ButtonAddMaterial_Click(object sender, EventArgs e)
        {
            bool NotAddedYet = true;

            LoadOrderLines();

            // create the new Ria rental type
            ModelTMSContainer          ControlObjectContext = new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session);
            RentalItemActivityListItem ria = new RentalItemActivityListItem();

            ria.RentalTypeId          = new Guid(ComboBoxMaterialType.SelectedValue);
            ria.RentalType            = ComboBoxMaterialType.SelectedItem.Text;
            ria.TreatAsAdvancePayment = CheckBoxTreatAsAdvancePayment.Checked;

            if (RadioButtonListSpecificOrAmount.SelectedValue == "Specific")
            {
                ria.RentalItemId = new Guid(ComboBoxMaterials.SelectedValue);
                ria.RentalItem   = ComboBoxMaterials.SelectedItem.Text;

                RentalItem ri = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.RentalItemSet", "Id", ria.RentalItemId)) as RentalItem;
                ria.BailPrice = ri.BailPrice;
                ri.CalculateRentForPeriod(StartRentDate, EndRentDate, out ria.RentPrice, out ria.Vat, out ria.TotalRentPrice);
            }
            else
            {
                try { ria.RentalItemAmount = Convert.ToInt32(TextBoxAmount.Text); }
                catch { }
            }

            if (ComboBoxCustomerLocation.SelectedValue != "")
            {
                ria.CustomerLocation   = ComboBoxCustomerLocation.SelectedItem.Text;
                ria.CustomerLocationId = new Guid(ComboBoxCustomerLocation.SelectedValue);
            }

            try { ria.DiscountPercentage = Convert.ToDouble(TextBoxDiscountPercentage.Text); }
            catch { };

            // check if this material has not been added yet
            foreach (RentalItemActivityListItem riali in OrderLines)
            {
                if (ria.RentalItemId != Guid.Empty)
                {
                    // checking for specific material
                    if ((ria.RentalItemId == riali.RentalItemId) && (ria.RentalTypeId == riali.RentalTypeId))
                    {
                        NotAddedYet = false;
                        break;
                    }
                    // checking for specific material group
                    if ((ria.RentalTypeId == riali.RentalTypeId) && (riali.RentalItemId == Guid.Empty))
                    {
                        NotAddedYet = false;
                        break;
                    }
                }
                else
                {
                    // checking for specific material group
                    if (ria.RentalTypeId == riali.RentalTypeId)
                    {
                        NotAddedYet = false;
                        break;
                    }
                }
            }

            // add the material if not added yet, otherwise inform the user
            if (NotAddedYet)
            {
                OrderLines.Add(ria);

                SaveOrderLines();
            }
            else
            {
                Common.InformUser(Page, "U heeft dit materiaal al aan deze verhuring toegevoegd.");
            }
        }
Пример #8
0
        public void ExpandOrderLines()
        {
            // if there are orderlines with multiple amounts of the same general material type then expand those lines into specific materials
            // raise an exception if there are insufficient materials available
            RentalItemActivityListItem[] OldOrderList = OrderLines.ToArray <RentalItemActivityListItem>();
            bool Success = true;

            LoadOrderLines();

            try
            {
                foreach (RentalItemActivityListItem ria in OrderLines.ToArray <RentalItemActivityListItem>())
                {
                    if (ria.RentalItemId == Guid.Empty)
                    {
                        string            Query = EntityDataSourceMaterials.CommandText;
                        ModelTMSContainer ControlObjectContext = new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session);

                        Query = Query.Substring(0, Query.ToLower().IndexOf("order by"));
                        Query = Query.Substring(Query.ToLower().IndexOf("from"));
                        Query = "select value it " + Query + " order by it.BaseRentalPrice, it.Description";

                        ObjectQuery <RentalItem> oq = new ObjectQuery <RentalItem>(Query, ControlObjectContext);

                        oq.Parameters.Add(new ObjectParameter("StartDate", StartRentDate));
                        oq.Parameters.Add(new ObjectParameter("EndDate", EndRentDate));
                        oq.Parameters.Add(new ObjectParameter("BorderEndDate", Common.ReturnEntitySQLDateTimeString(new DateTime(2099, 12, 31))));
                        oq.Parameters.Add(new ObjectParameter("LocationId", LocationID));
                        oq.Parameters.Add(new ObjectParameter("RentalType", ria.RentalTypeId));

                        RentalItem[] RIs = oq.ToArray <RentalItem>();

                        int AmountToAdd = ria.RentalItemAmount;
                        if (RIs.Count() >= ria.RentalItemAmount)
                        {
                            // remove the orderline and expand with the specific material
                            OrderLines.Remove(ria);

                            foreach (RentalItem ri in RIs)
                            {
                                // and add the line for this item
                                RentalItemActivityListItem NewRia = new RentalItemActivityListItem();
                                NewRia.RentalItemId          = ri.Id;
                                NewRia.RentalItem            = ri.Description;
                                NewRia.RentalItemAmount      = 1;
                                NewRia.RentalType            = ri.RentalType.Description;
                                NewRia.RentalTypeId          = ri.RentalType.Id;
                                NewRia.TreatAsAdvancePayment = ria.TreatAsAdvancePayment;

                                ri.CalculateRentForPeriod(StartRentDate, EndRentDate, out NewRia.RentPrice, out NewRia.Vat, out NewRia.TotalRentPrice);
                                NewRia.BailPrice = ri.BailPrice;

                                OrderLines.Add(NewRia);

                                // need to add more ?
                                AmountToAdd--;
                                if (AmountToAdd <= 0)
                                {
                                    break;
                                }
                            }

                            Success = true;
                        }
                        else
                        {
                            Success = false;
                            throw new Exception(string.Format("Het aantal beschikbare materialen van {0} is onvoldoende om deze verhuring te kunnen uitleveren.", ria.RentalType));
                        }
                    }
                }
            }
            finally
            {
//                if (!Success)
//                {
//                    OrderLines.Clear();
//                    foreach(RentalItemActivityListItem OldRia in OldOrderList)
//                    {
//                        OrderLines.Add(OldRia);
//                    }
//                }
            }

            if (Success)
            {
                SaveOrderLines();
            }
        }