Пример #1
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var productRewards = rewards.Where(r => r.RewardType == PromotionRewardType.CatalogItemAmountReward && (r.ProductId.IsNullOrEmpty() || r.ProductId.EqualsInvariant(Id)));

            if (productRewards == null)
            {
                return;
            }

            Discounts.Clear();
            Price.DiscountAmount = new Money(Math.Max(0, (Price.ListPrice - Price.SalePrice).Amount), Currency);

            foreach (var reward in productRewards)
            {
                //Initialize tier price discount amount by default values
                var discount = reward.ToDiscountModel(Price.SalePrice);
                foreach (var tierPrice in Price.TierPrices)
                {
                    tierPrice.DiscountAmount = new Money(Math.Max(0, (Price.ListPrice - tierPrice.Price).Amount), Currency);
                }

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                    Price.DiscountAmount += discount.Amount;

                    //apply discount to tier prices
                    foreach (var tierPrice in Price.TierPrices)
                    {
                        discount = reward.ToDiscountModel(tierPrice.Price);
                        tierPrice.DiscountAmount += discount.Amount;
                    }
                }
            }
        }
Пример #2
0
 public virtual void ApplyDiscount(Discount discount)
 {
     // Apply the discount
     PriceEachOverride = discount.Apply(this);
     // Add the discount to this product's list.
     Discounts.Add(discount);
 }
Пример #3
0
        public void AddDiscount(string c, string pdf)
        {
            Discount d = new Discount(c, pdf);

            Discounts.Add(d);
            Company.Discounts.Add(d);
        }
Пример #4
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var productRewards = rewards.Where(r => r.RewardType == PromotionRewardType.CatalogItemAmountReward && (r.ProductId.IsNullOrEmpty() || r.ProductId.EqualsInvariant(Id)));

            if (productRewards == null)
            {
                return;
            }

            Discounts.Clear();

            foreach (var reward in productRewards)
            {
                //Apply discount to main price
                var discount = reward.ToDiscountModel(Price.SalePrice);
                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                    Price.ActiveDiscount = discount;
                    //apply discount to tier prices
                    foreach (var tierPrice in Price.TierPrices)
                    {
                        discount = reward.ToDiscountModel(tierPrice.Price);
                        tierPrice.ActiveDiscount = discount;
                    }
                }
            }
        }
Пример #5
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                foreach (var discount in DiscountData.ReadDiscounts())
                {
                    Discounts.Add(discount);
                }
            }
        }
Пример #6
0
        public void AddDiscount(IDiscount discount)
        {
            if (discount.GetType() == typeof(OfferVoucher))
            {
                AddOfferVoucher((OfferVoucher)discount);
            }

            if (!ErrorInBasket)
            {
                Discounts.Add(discount);
                OnDiscountAdded(EventArgs.Empty);
            }
        }
Пример #7
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            Discount discountSelected = discountsApplied.GetDiscount
                                            (lstDiscounts.SelectedItems[0].Text);

            //return discount to available discounts
            discountsAvailable.Add
                (discountSelected);
            discountsApplied.Delete(discountSelected);

            //unapply discount
            discountsAvailable.GetDiscount
                (discountSelected.DiscountID).ItemAppliedTo = "";
            discountsAvailable.GetDiscount
                (discountSelected.DiscountID).Amount = 0.00M;

            //repopulate
            populateDiscountsList();

            populateTotalDiscount();

            btnRemove.Enabled = false;
        }
Пример #8
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            Discounts.Clear();

            var cartRewards = rewards.Where(r => r.RewardType == PromotionRewardType.CartSubtotalReward);

            foreach (var reward in cartRewards)
            {
                var discount = reward.ToDiscountModel(SubTotal.Amount, Currency);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                }
            }

            var lineItemRewards = rewards.Where(r => r.RewardType == PromotionRewardType.CatalogItemAmountReward);

            foreach (var lineItem in Items)
            {
                lineItem.ApplyRewards(lineItemRewards);
            }

            var shipmentRewards = rewards.Where(r => r.RewardType == PromotionRewardType.ShipmentReward);

            foreach (var shipment in Shipments)
            {
                shipment.ApplyRewards(shipmentRewards);
            }

            if (Coupon != null && !string.IsNullOrEmpty(Coupon.Code))
            {
                var couponRewards = rewards.Where(r => r.Promotion.Coupons != null && r.Promotion.Coupons.Any());
                if (!couponRewards.Any())
                {
                    Coupon.AppliedSuccessfully = false;
                    Coupon.ErrorCode           = "InvalidCouponCode";
                }
                foreach (var reward in couponRewards)
                {
                    var couponCode = reward.Promotion.Coupons.FirstOrDefault(c => c == Coupon.Code);
                    if (!string.IsNullOrEmpty(couponCode))
                    {
                        Coupon.AppliedSuccessfully = reward.IsValid;
                        Coupon.Description         = reward.Promotion.Description;
                    }
                }
            }
        }
Пример #9
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            Discounts.Clear();
            DiscountAmount = new Money(Currency);

            var cartRewards = rewards.Where(x => x.RewardType == PromotionRewardType.CartSubtotalReward);

            foreach (var reward in cartRewards)
            {
                //When a discount is applied to the cart subtotal, the tax calculation has already been applied, and is reflected in the tax subtotal.
                //Therefore, a discount applying to the cart subtotal will occur after tax.
                //For instance, if the cart subtotal is $100, and $15 is the tax subtotal, a cart - wide discount of 10 % will yield a total of $105($100 subtotal – $10 discount + $15 tax on the original $100).

                var discount = reward.ToDiscountModel(ExtendedPriceTotal);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                }
                DiscountAmount = discount.Amount;
            }

            var lineItemRewards = rewards.Where(x => x.RewardType == PromotionRewardType.CatalogItemAmountReward);

            foreach (var lineItem in Items)
            {
                lineItem.ApplyRewards(lineItemRewards);
            }

            var shipmentRewards = rewards.Where(x => x.RewardType == PromotionRewardType.ShipmentReward);

            foreach (var shipment in Shipments)
            {
                shipment.ApplyRewards(shipmentRewards);
            }

            var paymentRewards = rewards.Where(x => x.RewardType == PromotionRewardType.PaymentReward);

            foreach (var payment in Payments)
            {
                payment.ApplyRewards(paymentRewards);
            }

            if (Coupon != null && !string.IsNullOrEmpty(Coupon.Code))
            {
                Coupon.AppliedSuccessfully = rewards.Any(x => x.IsValid && x.Coupon != null);
            }
        }
Пример #10
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var shipmentRewards = rewards.Where(r => r.RewardType == PromotionRewardType.ShipmentReward && r.ShippingMethodCode == ShipmentMethodCode);

            Discounts.Clear();

            foreach (var reward in shipmentRewards)
            {
                var discount = reward.ToDiscountModel(ShippingPrice.Amount, Currency);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Populates collections within table. The tables used will be removed from
        /// the table collection.
        /// Override this method to populate your custom collection objects.
        /// </summary>
        /// <param name="tables">The tables.</param>
        /// <param name="filter">The filter.</param>
        protected override void PopulateCollections(DataTableCollection tables, string filter)
        {
            filter = String.Format("ShipmentId = '{0}'", this.ShipmentId.ToString());
            base.PopulateCollections(tables, filter);

            // Populate object collections
            DataView view = DataHelper.CreateDataView(tables["ShipmentDiscount"], filter);

            // Read until we are done, since this is a collection
            foreach (DataRowView row in view)
            {
                ShipmentDiscount discount = new ShipmentDiscount();
                discount.Load(row);
                Discounts.Add(discount);
            }
        }
Пример #12
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var shipmentRewards = rewards.Where(r => r.RewardType == PromotionRewardType.ShipmentReward && (r.ShippingMethodCode.IsNullOrEmpty() || r.ShippingMethodCode.EqualsInvariant(ShipmentMethodCode)));

            Discounts.Clear();

            foreach (var reward in shipmentRewards)
            {
                var discount = reward.ToDiscountModel(ShippingPrice, ShippingPriceWithTax);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                }
            }
        }
Пример #13
0
        public void AddTicketDiscount(DiscountType type, decimal amount, int userId)
        {
            var c = Discounts.SingleOrDefault(x => x.DiscountType == (int)type);

            if (c == null)
            {
                c = new Discount {
                    DiscountType = (int)type, Amount = amount
                };
                Discounts.Add(c);
            }
            if (amount == 0)
            {
                Discounts.Remove(c);
            }
            c.UserId = userId;
            c.Amount = amount;
        }
Пример #14
0
        /// <summary>
        /// Populates collections within table. The tables used will be removed from
        /// the table collection.
        /// Override this method to populate your custom collection objects.
        /// </summary>
        /// <param name="tables">The tables.</param>
        /// <param name="filter">The filter.</param>
        protected override void PopulateCollections(DataTableCollection tables, string filter)
        {
            filter = String.Format("OrderFormId = '{0}'", this.OrderFormId.ToString());

            base.PopulateCollections(tables, filter);

            // Populate object collections
            DataView view = DataHelper.CreateDataView(tables["Shipment"], filter);

            // Read until we are done, since this is a collection
            foreach (DataRowView row in view)
            {
                Shipment orderShipment = (Shipment)OrderContext.Current.ShipmentClassInfo.CreateInstance();
                orderShipment.Load(row);
                orderShipment.PopulateCollectionsInternal(tables, filter);
                Shipments.Add(orderShipment);
            }

            view = DataHelper.CreateDataView(tables["LineItem"], filter);

            // Read until we are done, since this is a collection
            foreach (DataRowView row in view)
            {
                LineItem lineItem = (LineItem)OrderContext.Current.LineItemClassInfo.CreateInstance();
                lineItem.Load(row);
                lineItem.PopulateCollectionsInternal(tables, filter);
                LineItems.Add(lineItem);
            }

            // Populate object collections
            // Populates payments collection
            LoadPayments(tables, filter);

            // Load discounts
            view = DataHelper.CreateDataView(tables["OrderFormDiscount"], filter);

            // Read until we are done, since this is a collection
            foreach (DataRowView row in view)
            {
                OrderFormDiscount discount = new OrderFormDiscount();
                discount.Load(row);
                Discounts.Add(discount);
            }
        }
Пример #15
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var shipmentRewards = rewards.Where(r => r.RewardType == PromotionRewardType.ShipmentReward && (string.IsNullOrEmpty(r.ShippingMethodCode) || r.ShippingMethodCode.EqualsInvariant(ShipmentMethodCode)));

            Discounts.Clear();

            DiscountAmount = new Money(0m, Currency);

            foreach (var reward in shipmentRewards)
            {
                var discount = reward.ToDiscountModel(Price - DiscountAmount);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                    DiscountAmount += discount.Amount;
                }
            }
        }
Пример #16
0
        public Discounts GetAssessmentDiscountsByDocID(string transactionNo, Transaction_Type type)
        {
            Discounts discounts = new Discounts();

            try
            {
                using (SqlConnection conn = new SqlConnection(connString))
                    using (SqlCommand comm = new SqlCommand("usp_GetAssessmentDiscountsByDocID", conn))
                    {
                        comm.CommandType = CommandType.StoredProcedure;

                        comm.Parameters.Clear();
                        comm.Parameters.Add(new SqlParameter("@Assessment_No", transactionNo));
                        comm.Parameters.Add(new SqlParameter("@SOPType", (int)type));

                        conn.Open();

                        using (SqlDataReader dr = comm.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                Discount d = new Discount();
                                d.DiscountID          = dr["Discount ID"].ToString();
                                d.DiscountDescription = dr["Discount Description"].ToString();
                                d.Percent             = decimal.Round(Convert.ToDecimal((dr["Percent"]).ToString()), 2);
                                d.DiscountType        = (Discount_Type)Convert.ToInt32(dr["Discount Type"].ToString());
                                d.Amount        = decimal.Round(Convert.ToDecimal((dr["Discount Amount"]).ToString()), 2);
                                d.ItemAppliedTo = dr["Applied To"].ToString();
                                d.Computed      = true;

                                discounts.Add(d);
                            }
                        }
                    }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
            return(discounts);
        }
Пример #17
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var lineItemRewards = rewards.Where(r => r.RewardType == PromotionRewardType.CatalogItemAmountReward && r.ProductId == ProductId);

            if (lineItemRewards == null)
            {
                return;
            }

            Discounts.Clear();

            foreach (var reward in lineItemRewards)
            {
                var discount = reward.ToDiscountModel(SalePrice.Amount, Currency);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                }
            }
        }
Пример #18
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var productRewards = rewards.Where(r => r.RewardType == PromotionRewardType.CatalogItemAmountReward && r.ProductId == Id);

            if (productRewards == null)
            {
                return;
            }

            Discounts.Clear();

            foreach (var reward in productRewards)
            {
                var discount = reward.ToDiscountModel(Price.SalePrice);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                    Price.ActiveDiscount = discount;
                }
            }
        }
Пример #19
0
        public Discounts GetCustomerDiscounts(string customerNo)
        {
            Discounts discounts = new Discounts();

            try
            {
                using (SqlConnection conn = new SqlConnection(connString))
                    using (SqlCommand comm = new SqlCommand("usp_GetCustomerDiscounts", conn))
                    {
                        comm.CommandType = CommandType.StoredProcedure;

                        comm.Parameters.Clear();
                        comm.Parameters.Add(new SqlParameter("@Customer_ID", customerNo));

                        conn.Open();

                        using (SqlDataReader dr = comm.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                Discount d = new Discount();
                                d.DiscountID          = dr["Discount ID"].ToString();
                                d.DiscountDescription = dr["Discount Description"].ToString();
                                d.Percent             = decimal.Round(Convert.ToDecimal(dr["Discount Percentage"].ToString()), 2);
                                d.DiscountType        = (Discount_Type)Convert.ToInt32(dr["Discount Type"].ToString());
                                d.Computed            = false;

                                discounts.Add(d);
                            }
                        }
                    }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
            return(discounts);
        }
Пример #20
0
        private void btnInsert_Click(object sender, EventArgs e)
        {
            Discount discountSelected = discountsAvailable.GetDiscount
                                            (discountID);

            //save discount
            try
            {
                discountsAvailable.GetDiscount(txtDiscountID.Text).Percent = Convert.ToDecimal(txtPercentage.Text);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                Prompt.ShowError(ex.Message);
            }

            if (chkValidate.Checked == true)
            {
                if (isDiscountValid(discountSelected))
                {
                    if (discountsApplied.Count <= DiscountAdapter.Instance.GetDiscountLimit() - 1)
                    {
                        discountSelected.ItemAppliedTo = cboItemsToApplyTo.Text;
                        //add discount to applied discounts
                        discountsApplied.Add
                            (discountSelected);
                        //remove discount to available discounts
                        discountsAvailable.Delete(discountSelected);
                    }
                    else
                    {
                        Prompt.ShowError("Maximum number of applicable discounts is reached.");
                    }
                }
                else
                {
                    Prompt.ShowError("This discount is not applicable.");
                }
            }
            else
            {
                //if validation is disabled
                discountSelected.ItemAppliedTo = cboItemsToApplyTo.Text;
                //add discount to applied discounts
                discountsApplied.Add
                    (discountSelected);
                //remove discount to available discounts
                discountsAvailable.Delete(discountSelected);
            }

            //repopulate
            populateDiscountsList();

            populateTotalDiscount();

            //clear edit fields
            txtDiscountID.Clear();
            txtDiscountDescription.Clear();
            txtPercentage.Clear();

            txtPercentage.ReadOnly = true;

            btnInsert.Enabled = false;

            //disable application
            disableDiscountApplication();
        }