public void CountDiscount()
        {
            DiscountList ds = new DiscountList();

            DRule = new DiscountRule {
                Line = _lines, Discountlist = ds.AllDiscount.ToList()
            };
            DRule.ApplyDiscountRule();
        }
        //search
        public void FillSalesRules(string POS, string Category, string ServiceType)
        {
            SalesRulesRepo repo = new SalesRulesRepo();

            salesRules = repo.GetSalesRules(Category, POS, ServiceType);
            for (int i = 0; i < salesRules.MarkupList.Count; i++)
            {
                MarkUp markUp = new MarkUp()
                {
                    CommAmt         = salesRules.MarkupList[i].commAmount,
                    ID              = salesRules.MarkupList[i].ID,
                    MarkupPriority  = salesRules.MarkupList[i].Priority,
                    CommRound       = salesRules.MarkupList[i].commRound,
                    CommRelatedUnit = salesRules.MarkupList[i].commRelatedUnit,
                    CommType        = salesRules.MarkupList[i].commType,
                    markupbase      = salesRules.MarkupList[i].Base,
                    markupname      = salesRules.MarkupList[i].Name,
                };
                markUp.MarkupCriterias = salesRules.MarkupList[i].CriteriaList.Select(a => new MarkupCriteria()
                {
                    criterianame      = a.criteriaName,
                    criteriavalue     = a.value,
                    operation         = a.operation,
                    markupid          = salesRules.MarkupList[i].ID.ToString(),
                    CriteriaValueText = a.textValue
                }).ToList();
                MarkupList.Add(markUp);
            }
            for (int i = 0; i < salesRules.DiscountList.Count; i++)
            {
                Discount discount = new Discount()
                {
                    CommAmt          = salesRules.DiscountList[i].commAmount,
                    ID               = salesRules.DiscountList[i].ID,
                    DiscountPriority = salesRules.DiscountList[i].Priority,
                    commround        = salesRules.DiscountList[i].commRound,
                    commrelatedunit  = salesRules.DiscountList[i].commRelatedUnit,
                    commtype         = salesRules.DiscountList[i].commType,
                    DiscountBase     = salesRules.DiscountList[i].Base,
                    DiscountName     = salesRules.DiscountList[i].Name,
                };
                discount.DiscountCriterias = salesRules.DiscountList[i].CriteriaList.Select(a => new DiscountCriteria()
                {
                    criterianame      = a.criteriaName,
                    criteriavalue     = a.value,
                    operation         = a.operation,
                    DiscountID        = salesRules.DiscountList[i].ID.ToString(),
                    CriteriaValueText = a.textValue
                }).ToList();
                DiscountList.Add(discount);
            }
        }
Exemple #3
0
    /// <summary>
    /// Binds the data.
    /// </summary>
    private void BindData(bool validate)
    {
        // Make sure to check that prices has not changed
        if (!CartHelper.IsEmpty && validate)
        {
            CartHelper.Reset();
            CartHelper.RunWorkflow("CartValidate");

            // If cart is empty, remove it from the database
            if (CartHelper.IsEmpty)
            {
                CartHelper.Delete();
            }

            CartHelper.Cart.AcceptChanges();
        }

        ShoppingCart.DataSource = CartHelper.LineItems;

        // Calculate sub total
        decimal subTotalPrice = 0;

        foreach (LineItem item in CartHelper.LineItems)
        {
            subTotalPrice += item.ExtendedPrice;
        }

        // Bind Order Level Discounts
        if (CartHelper.OrderForm.Discounts.Count > 0)
        {
            DiscountList.DataSource = CartHelper.OrderForm.Discounts;
            DiscountList.DataBind();
            DiscountTr.Visible = true;
            TotalDiscount.Text = CurrencyFormatter.FormatCurrency(CartHelper.OrderForm.DiscountAmount, CartHelper.Cart.BillingCurrency);
        }
        else
        {
            DiscountTr.Visible = false;
        }

        SubTotal.Text = CurrencyFormatter.FormatCurrency(subTotalPrice, CartHelper.Cart.BillingCurrency);

        bool isEmpty = CartHelper.IsEmpty;

        CartSummary.Visible      = !isEmpty;
        UpdateCartButton.Visible = !isEmpty;
        CheckoutButton.Visible   = !isEmpty;
        CouponSummary.Visible    = !isEmpty;

        ShoppingCart.DataBind();
    }
Exemple #4
0
        private bool SameDiscounts(DiscountList list, int[] discounts)
        {
            int i = 0;

            foreach (var item in list.Discounts)
            {
                if (item.Id != discounts[i])
                {
                    return(false);
                }
                i++;
            }
            return(true);
        }
Exemple #5
0
        public virtual double GetPrice(double price, string webSite)
        {
            var DiscountsList = DiscountList.ReadDiscountList(@"C:\Users\skumarsekar\Documents\Pet Projects\Scrape items to buy\Scrape items to buy\Files\Discounts.txt");

            foreach (var discount in DiscountsList)
            {
                if (discount.Website.ToLower().Equals(webSite))
                {
                    price = price * (100 - discount.DiscountPercent) / 100;
                    price = price - discount.DiscountAmount;
                }
            }

            return(price);
        }
Exemple #6
0
        private void ClearAll()
        {
            var panel = OrderTableLayoutPanel;

            for (int i = 1; i < panel.RowCount; i++)
            {
                for (int j = 0; j < panel.ColumnCount; j++)
                {
                    var control = panel.GetControlFromPosition(j, i);
                    panel.Controls.Remove(control);
                }
            }
            panel.RowCount = 1;

            for (int i = 0; i < DiscountList.Items.Count; i++)
            {
                DiscountList.SetItemCheckState(i, CheckState.Indeterminate);
            }

            UpdateSumTextBox();
        }
Exemple #7
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            var     panel    = OrderTableLayoutPanel;
            int     rowIndex = OrderTableLayoutPanel.GetPositionFromControl((Button)sender).Row;
            Product product  = orderProducts.Find(x => x.Name == panel.GetControlFromPosition(0, rowIndex).Text);

            orderProducts.Remove(product);

            for (int i = 0; i < DiscountList.Items.Count; i++)
            {
                Discount discount     = (Discount)DiscountList.Items[i];
                bool     containsFlag = false;
                if (discount.Products.Any(m => m.Id == product.Id))
                {
                    foreach (var pr in discount.Products)
                    {
                        if (orderProducts.Any(m => m.Id == pr.Id))
                        {
                            containsFlag = true;
                            break;
                        }
                    }

                    if (containsFlag)
                    {
                        var tuple = productsDiscountAmount.FirstOrDefault(x => x.Key.Item1.Id == product.Id && x.Key.Item2.Id == discount.Id);
                        if (tuple.Key != null)
                        {
                            productsDiscountAmount.Remove(tuple.Key);
                        }
                    }
                    else
                    {
                        DiscountList.SetItemCheckState(i, CheckState.Indeterminate);
                        var tuple = productsDiscountAmount.FirstOrDefault(x => x.Key.Item1.Id == product.Id && x.Key.Item2.Id == discount.Id);
                        if (tuple.Key != null)
                        {
                            productsDiscountAmount.Remove(tuple.Key);
                        }
                    }
                }
            }

            // delete all controls of row that we want to delete
            for (int i = 0; i < panel.ColumnCount; i++)
            {
                var control = panel.GetControlFromPosition(i, rowIndex);
                panel.Controls.Remove(control);
            }

            // move up row controls that comes after row we want to remove
            for (int i = rowIndex + 1; i < panel.RowCount; i++)
            {
                for (int j = 0; j < panel.ColumnCount; j++)
                {
                    var control = panel.GetControlFromPosition(j, i);
                    if (control != null)
                    {
                        panel.SetRow(control, i - 1);
                    }
                }
            }

            var removeStyle = panel.RowCount - 1;

            if (panel.RowStyles.Count > removeStyle)
            {
                panel.RowStyles.RemoveAt(removeStyle);
            }

            panel.RowCount--;
            UpdateSumTextBox();
        }
Exemple #8
0
        private void ProductsListView_DoubleClick(object sender, EventArgs e)
        {
            var item = ProductsListView.SelectedItems[0];

            if (!OrderContains(item.Text))
            {
                Button delButton = new DeleteButtonClass().DeleteButton;
                delButton.Click += new System.EventHandler(this.DeleteButton_Click);
                Button plusButton = new PlusButtonClass().PlusButton;
                plusButton.Click += new System.EventHandler(this.PlusButton_Click);
                Button minusButton = new MinusButtonClass().MinusButton;
                minusButton.Click += new System.EventHandler(this.MinusButton_Click);

                this.OrderTableLayoutPanel.RowCount += 1;
                this.OrderTableLayoutPanel.Controls.Add(new Label()
                {
                    Width = 200, Font = new Font("Century Gothic", 14), Text = item.SubItems[0].Text
                }, 0, this.OrderTableLayoutPanel.RowCount - 1);
                this.OrderTableLayoutPanel.Controls.Add(new Label()
                {
                    Font = new Font("Century Gothic", 14), Text = "1"
                }, 1, this.OrderTableLayoutPanel.RowCount - 1);
                this.OrderTableLayoutPanel.Controls.Add(new Label()
                {
                    Font = new Font("Century Gothic", 14), Text = item.SubItems[1].Text
                }, 2, this.OrderTableLayoutPanel.RowCount - 1);
                this.OrderTableLayoutPanel.Controls.Add(minusButton, 3, this.OrderTableLayoutPanel.RowCount - 1);
                this.OrderTableLayoutPanel.Controls.Add(plusButton, 4, this.OrderTableLayoutPanel.RowCount - 1);
                this.OrderTableLayoutPanel.Controls.Add(delButton, 5, this.OrderTableLayoutPanel.RowCount - 1);

                var product = products.Find(x => x.Name.Equals(item.Text));
                orderProducts.Add(new Product(product.Id, product.Name, 1));

                foreach (var discount in discounts)
                {
                    foreach (var p in discount.Products)
                    {
                        if (p.Id == product.Id)
                        {
                            int index = DiscountList.Items.IndexOf(discount);
                            DiscountList.SetItemCheckState(index, CheckState.Unchecked);
                        }
                    }
                }
            }
            else
            {
                for (int rowIndex = 1; rowIndex < OrderTableLayoutPanel.RowCount; rowIndex++)
                {
                    if (OrderTableLayoutPanel.GetControlFromPosition(0, rowIndex).Text == item.Text)
                    {
                        var product = products.Find(x => x.Name.Equals(item.Text));
                        var price   = product.Price;

                        if (productsDiscountAmount.Keys.Any(m => m.Item1.Id == product.Id))
                        {
                            for (int i = 0; i < productsDiscountAmount.Count; i++)
                            {
                                var discount = productsDiscountAmount.ElementAt(i);
                                if (discount.Key.Item1.Id == product.Id)
                                {
                                    var disc = discount.Value / (Int32.Parse(OrderTableLayoutPanel.GetControlFromPosition(1, rowIndex).Text));
                                    OrderTableLayoutPanel.GetControlFromPosition(2, rowIndex).Text = (Convert.ToDouble(OrderTableLayoutPanel.GetControlFromPosition(2, rowIndex).Text, nfi) + price - disc).ToString(nfi);
                                    productsDiscountAmount[discount.Key] += disc;
                                    OrderTableLayoutPanel.GetControlFromPosition(1, rowIndex).Text = (Int32.Parse(OrderTableLayoutPanel.GetControlFromPosition(1, rowIndex).Text) + 1).ToString();
                                }
                            }
                        }
                        else
                        {
                            OrderTableLayoutPanel.GetControlFromPosition(1, rowIndex).Text = (Int32.Parse(OrderTableLayoutPanel.GetControlFromPosition(1, rowIndex).Text) + 1).ToString();
                            OrderTableLayoutPanel.GetControlFromPosition(2, rowIndex).Text = (Double.Parse(OrderTableLayoutPanel.GetControlFromPosition(1, rowIndex).Text, nfi) * product.Price).ToString(nfi);
                        }

                        orderProducts.Find(x => x.Name.Equals(item.Text)).Count++;
                    }
                }
            }
            UpdateSumTextBox();
        }
Exemple #9
0
        public IActionResult TicketPurchaseCreate(int seat, int[] discounts)
        {
            TicketPurchase ticketPurchase;

            if ((int)TempData["buyForm"] == 0)
            {
                ticketPurchase = new PhysicalTicketPurchase
                {
                    BatchScheduleStartTime = (DateTime)TempData["start"],
                    BatchScheduleEndTime   = (DateTime)TempData["end"],
                    CinemaId    = (int)TempData["cinema"],
                    SeatId      = seat,
                    Code        = (string)TempData["codeSeats"],
                    TimeReserve = DateTime.Now
                };
            }
            else
            {
                ticketPurchase = new OnlineTicketPurchase
                {
                    BatchScheduleStartTime = (DateTime)TempData["start"],
                    BatchScheduleEndTime   = (DateTime)TempData["end"],
                    CinemaId    = (int)TempData["cinema"],
                    SeatId      = seat,
                    Code        = (string)TempData["codeSeats"],
                    TimeReserve = DateTime.Now
                };
            }

            if (TempData["code"] != null)
            {
                ticketPurchase.AppUserId = TempData["code"].ToString();
            }

            var   batch = _context.Batch.Find(ticketPurchase.CinemaId, ticketPurchase.BatchScheduleStartTime, ticketPurchase.BatchScheduleEndTime);
            float price = batch.TicketPrice;

            int[] aux   = (int[])TempData["seats"];
            int[] seats = new int[aux.Length];
            aux.CopyTo(seats, 0);

            IEnumerable <DiscountList> listDiscountList = _context.DiscountList.Include(m => m.Discounts).ToList();
            var  discountList = new DiscountList();
            bool find         = false;

            foreach (var item in listDiscountList)
            {
                if (item.Discounts.Count != discounts.Length)
                {
                    continue;
                }
                else
                {
                    if (SameDiscounts(item, discounts))
                    {
                        discountList = item;
                        find         = true;
                        break;
                    }
                }
            }

            if (discountList.Discounts.Count == 0)
            {
                foreach (var item in discounts)
                {
                    var discount = _context.Discount.Find(item);
                    discountList.TotalDiscounted += discount.DiscountedMoney;
                    discount.DiscountLists.Add(discountList);
                    discountList.Discounts.Add(discount);
                }
            }

            if (!find)
            {
                _context.DiscountList.Add(discountList);
                _context.SaveChanges();
            }

            price -= discountList.TotalDiscounted;

            if (price < 0)
            {
                price = 0;
            }

            ticketPurchase.Price = price;

            float temp = float.Parse((string)TempData["totalPrice"]);
            float tp   = temp + ticketPurchase.Price;

            TempData["totalPrice"] = tp.ToString();

            temp = float.Parse((string)TempData["totalPoints"]);
            tp   = temp + batch.TicketPoints;
            TempData["totalPoints"] = tp.ToString();

            ticketPurchase.DiscountListId = discountList.Id;

            _context.TicketPurchase.Add(ticketPurchase);
            _context.SaveChanges();

            return(RedirectToAction("DiscountLists"));
        }
Exemple #10
0
        public Discounts GetDiscountValidByCode(GetDiscountValidByCodeParams param, out bool isLimit)
        {
            isLimit = false;

            // Products
            var discount = (from p1 in DiscountProductList
                            join p in DiscountList on p1.DiscountId equals p.Id
                            where p.Code.ToLower() == param.Code.Trim().ToLower() &&
                            !p.IsDelete &&
                            p1.ProductId == param.ProductId &&
                            p.StartDate.HasValue &&
                            p.EndDate.HasValue &&
                            (param.IsAdmin || (p.StartDate.Value.Date <= DateTime.UtcNow.ToLosAngerlesTimeWithTimeZone(param.TimezoneId).Date &&
                                               p.EndDate.Value.Date >= DateTime.UtcNow.ToLosAngerlesTimeWithTimeZone(param.TimezoneId).Date))
                            select p).FirstOrDefault();

            // Subscription
            if (param.SubscriptionId > 0)
            {
                discount = (from ds in DiscountSubscriptionList
                            join d in DiscountOfSubscriptionList on ds.DiscountId equals d.Id
                            where d.Code.ToLower() == param.Code.Trim().ToLower() &&
                            !d.IsDelete &&
                            ds.SubscriptionId == param.SubscriptionId &&
                            d.StartDate.HasValue &&
                            d.EndDate.HasValue &&
                            d.StartDate.Value.Date <= DateTime.UtcNow.ToLosAngerlesTimeWithTimeZone(param.TimezoneId).Date &&
                            d.EndDate.Value.Date >= DateTime.UtcNow.ToLosAngerlesTimeWithTimeZone(param.TimezoneId).Date
                            select d).FirstOrDefault();

                if (discount == null)
                {
                    discount = (from ds in DiscountSubscriptionList
                                join d in DiscountList on ds.DiscountId equals d.Id
                                where d.Code.ToLower() == param.Code.Trim().ToLower() &&
                                !d.IsDelete &&
                                ds.SubscriptionId == param.SubscriptionId &&
                                d.StartDate.HasValue &&
                                d.EndDate.HasValue &&
                                d.StartDate.Value.Date <= DateTime.UtcNow.ToLosAngerlesTimeWithTimeZone(param.TimezoneId).Date &&
                                d.EndDate.Value.Date >= DateTime.UtcNow.ToLosAngerlesTimeWithTimeZone(param.TimezoneId).Date
                                select d).FirstOrDefault();
                }
            }

            // Discount AllProduct with Code Required
            if (discount == null)
            {
                discount = DiscountList.FirstOrDefault(x => x.IsAllProducts &&
                                                       x.Code.ToLower() == param.Code.Trim().ToLower() &&
                                                       x.CodeRequired &&
                                                       !x.IsDelete &&
                                                       x.StartDate.HasValue &&
                                                       x.EndDate.HasValue &&
                                                       (param.IsAdmin || (x.StartDate.Value.Date <= DateTime.UtcNow.ToLosAngerlesTimeWithTimeZone(param.TimezoneId).Date &&
                                                                          x.EndDate.Value.Date >= DateTime.UtcNow.ToLosAngerlesTimeWithTimeZone(param.TimezoneId).Date)));
            }

            // Discount AllProduct with Code Not Required
            if (discount == null)
            {
                discount = DiscountList.FirstOrDefault(x => x.IsAllProducts &&
                                                       x.Code.ToLower() == param.Code.Trim().ToLower() &&
                                                       !x.IsDelete &&
                                                       x.StartDate.HasValue &&
                                                       x.EndDate.HasValue &&
                                                       (param.IsAdmin || (x.StartDate.Value.Date <= DateTime.UtcNow.ToLosAngerlesTimeWithTimeZone(param.TimezoneId).Date &&
                                                                          x.EndDate.Value.Date >= DateTime.UtcNow.ToLosAngerlesTimeWithTimeZone(param.TimezoneId).Date)));
            }

            if (discount != null && param.CustomerId > 0)
            {
                var bookings = (from b in BookingList
                                join db in DiscountBookingList on b.BookingId equals db.BookingId
                                join ci in CustomerInfoList on b.CustomerId equals ci.CustomerId
                                where ci.CustomerId == param.CustomerId && db.DiscountId == discount.Id &&
                                b.PassStatus != (int)Enums.BookingStatus.Refunded &&
                                b.BookingId != param.BookingId
                                select b).Count();

                if (discount.MaxPurchases != 0 && discount.MaxPurchases > bookings)
                {
                    return(discount);
                }
                isLimit = true;
                return(null);
            }

            return(discount);
        }
 private void btnShowDiscount_Click(object sender, EventArgs e)
 {
     lbDiscount.DisplayMember = "maDiscount";
     lbDiscount.ValueMember   = "soTienDuocGiam";
     lbDiscount.DataSource    = DiscountList.GetListDiscountByAge(DateTime.Now.Year - dpkNamSinh.Value.Year);
 }