示例#1
0
 protected void txtDeliveryMethod_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (txtDeliveryMethod.SelectedValue == "1")
     {
         Branch branch = entities.Branches.Where(b => b.BranchID == BranchId).FirstOrDefault();
         if (branch != null)
         {
             if (SessionUserOrder != null)
             {
                 BusinessEntities.PromotionCodes promotionCode = null;
                 Double deduction = 0, Tip = 0;
                 if (!String.IsNullOrEmpty(txtPromotionCode.Text))
                 {
                     promotionCode = promoManager.GetPromotionCodeByCode(txtPromotionCode.Text.Trim());
                     if (promotionCode != null)
                     {
                         if ((promotionCode.StartDate == null ||
                              (promotionCode.StartDate != null &&
                               promotionCode.StartDate.Value.Subtract(DateTime.Now).Days >= 0))
                             &&
                             (promotionCode.EndDate == null ||
                              (promotionCode.EndDate != null &&
                               promotionCode.EndDate.Value.Subtract(DateTime.Now).Days <= 0)))
                         {
                             if (promotionCode.TypeOfPromotion == BusinessEntities.PromotionType.Money)
                             {
                                 deduction = promotionCode.PromotionValue;
                             }
                             else
                             {
                                 deduction = (SessionUserOrder.OrderTotal * promotionCode.PromotionValue) / 100;
                             }
                         }
                     }
                 }
                 txtPrice.Text                 = Math.Round(SessionUserOrder.OrderTotal - deduction, 2).ToString();
                 txtTax.Text                   = "" + Math.Round((decimal)branch.TaxPercentage, 0);
                 txtDeliveryCharges.Text       = Math.Round((decimal)branch.DeliveryCharges, 2).ToString();
                 hdTotalChargesBeforeTax.Value = Convert.ToDecimal(Math.Round(SessionUserOrder.OrderTotal - deduction, 2)).ToString();
                 decimal tax = ((Convert.ToDecimal(SessionUserOrder.OrderTotal - deduction) + Math.Round((decimal)branch.DeliveryCharges, 2)) * Math.Round((decimal)branch.TaxPercentage, 0)) / 100;
                 txtTaxAmount.Text = Math.Round(tax, 2).ToString();
                 Double.TryParse(txtTip.Text, out Tip);
                 txtTotal.Text = "" + Math.Round((Math.Round(Convert.ToDecimal(SessionUserOrder.OrderTotal - deduction + Tip), 2) + Math.Round(tax, 2) + Math.Round((decimal)branch.DeliveryCharges, 2)), 2);
             }
         }
     }
     else
     {
         Branch branch = entities.Branches.Where(b => b.BranchID == BranchId).FirstOrDefault();
         if (branch != null)
         {
             if (SessionUserOrder != null)
             {
                 BusinessEntities.PromotionCodes promotionCode = null;
                 Double deduction = 0, Tip = 0;
                 if (!String.IsNullOrEmpty(txtPromotionCode.Text))
                 {
                     promotionCode = promoManager.GetPromotionCodeByCode(txtPromotionCode.Text.Trim());
                     if (promotionCode != null)
                     {
                         if (promotionCode.TypeOfPromotion == BusinessEntities.PromotionType.Money)
                         {
                             deduction = promotionCode.PromotionValue;
                         }
                         else
                         {
                             deduction = (SessionUserOrder.OrderTotal * promotionCode.PromotionValue) / 100;
                         }
                     }
                 }
                 txtPrice.Text           = Math.Round(SessionUserOrder.OrderTotal - deduction, 2).ToString();
                 txtDeliveryCharges.Text = "0.00";
                 decimal tax = (Convert.ToDecimal(SessionUserOrder.OrderTotal - deduction) * Math.Round((decimal)branch.TaxPercentage, 0)) / 100;
                 txtTax.Text       = "" + Math.Round((decimal)branch.TaxPercentage, 0);
                 txtTaxAmount.Text = Math.Round(tax, 2).ToString();
                 Double.TryParse(txtTip.Text, out Tip);
                 txtTotal.Text = "" + Math.Round((Convert.ToDecimal(SessionUserOrder.OrderTotal - deduction + Tip) + tax), 2);
             }
         }
     }
 }
示例#2
0
    protected void OrderNow_Click(object sender, EventArgs e)
    {
        if (SessionUserOrder != null)
        {
            Double deduction = 0, Tip = 0;
            BusinessEntities.PromotionCodes promotionCode = null;
            BusinessEntities.Orders         order         = SessionUserOrder;


            if (!String.IsNullOrEmpty(txtPromotionCode.Text))
            {
                if (SessionPreOrderPromo != null)
                {
                    deduction += SessionPreOrderPromo.PreOrderPromoValue;
                }

                promotionCode = promoManager.GetPromotionCodeByCode(txtPromotionCode.Text.Trim());
                if (promotionCode != null)
                {
                    if (promotionCode.TypeOfPromotion == BusinessEntities.PromotionType.Money)
                    {
                        deduction = promotionCode.PromotionValue;
                    }
                    else if (promotionCode.TypeOfPromotion == BusinessEntities.PromotionType.EGiftCard) // in case of E-Gift, keep track of PromotionValueUsed...
                    {
                        if ((promotionCode.PromotionValue - promotionCode.PromoValueUsed) > 0)
                        {
                            if (order.OrderTotal < (promotionCode.PromotionValue - promotionCode.PromoValueUsed))
                            {
                                promotionCode.PromoValueUsed += deduction = order.OrderTotal;
                            }
                            else
                            {
                                promotionCode.PromoValueUsed +=
                                    deduction = (promotionCode.PromotionValue - promotionCode.PromoValueUsed);
                            }
                        }
                    }
                    else
                    {
                        deduction = (SessionUserOrder.OrderTotal * promotionCode.PromotionValue) / 100;
                    }

                    order.PromotionCodeId = promotionCode.PromotionCodeId;

                    order.PromotionValueUsed = (promotionCode.PromoValueUsed == 0.0)
                                                   ? (double)0.0
                                                   : promotionCode.PromoValueUsed;
                }
            }

            if (order.ContactInfoId == 0)
            {
                order.ContactInfoId = SessionUserContactInfoId;
            }
            order.BranchID      = Convert.ToInt32(ConfigurationManager.AppSettings["BranchId"]);
            order.OrderTypeID   = (BusinessEntities.OrderType)Convert.ToInt16(txtDeliveryMethod.SelectedValue);
            order.PaymentMethod = (BusinessEntities.PaymentType)Convert.ToInt16(txtPaymentMethod.SelectedValue);
            order.TaxPercentage = Convert.ToDouble(txtTax.Text);
            if (!String.IsNullOrEmpty(txtTip.Text) && Double.TryParse(txtTip.Text, out Tip))
            {
                order.LineTip = Double.Parse(txtTip.Text);
            }
            if (order.OrderTypeID == BusinessEntities.OrderType.Deliver)
            {
                order.OrderTypeID     = BusinessEntities.OrderType.Deliver;
                order.DeliveryCharges = Convert.ToDouble(txtDeliveryCharges.Text);
                order.DeliveryAddress = txtAddress.Text + " <br /> " + txtCity.Text + " " + txtZipCode.Text + "<br /> " + txtState.Text;
                order.OrderTotal      = (order.OrderTotal + order.DeliveryCharges) + order.LineTip + (((order.OrderTotal + order.DeliveryCharges) * order.TaxPercentage) / 100);
                order.OrderTotal      = order.OrderTotal - deduction;
            }
            else
            {
                order.OrderTypeID = BusinessEntities.OrderType.SelfPickup;
                order.OrderTotal  = order.OrderTotal + order.LineTip + ((order.OrderTotal * order.TaxPercentage) / 100);
                order.OrderTotal  = order.OrderTotal - deduction;
            }
            Int64 result = orderManager.AddOrder(order, SessionOrderDetailOptionList, SessionOrderAdonList);

            string sessionID     = HttpContext.Current.Session.SessionID;
            string categoryName  = string.Empty;
            string sizes         = string.Empty;
            string adons         = string.Empty;
            double price         = order.OrderTotal;
            string recepientName = order.CustomerName;
            string userName      = SessionUserFullName;

            foreach (var currentOrder in order.OrderDetailsList)
            {
                if (!categoryName.Contains(currentOrder.CategoryName))
                {
                    categoryName += currentOrder.CategoryName;
                }
                if (currentOrder.OrderDetailSubProducts != null)
                {
                    foreach (var product in currentOrder.OrderDetailSubProducts)
                    {
                        sizes += product.ProductName + ": ";
                        foreach (var p in product.OrderDetailSubProductOptions)
                        {
                            sizes += p.ProductOptionName + ",";
                        }
                        foreach (var adon in product.OrderDetailSubProductAdons)
                        {
                            adons += adon.AdOnId + ",";
                        }
                    }
                }
            }

            sizes = sizes.Trim(',');
            adons = adons.TrimEnd(',');

            sizes = sizes == "" ? null : sizes;
            adons = adons == "" ? null : adons;
            // get log message to pass to db
            string message = Common.ConfirmOrderLogMessage(categoryName, price,
                                                           adons, sizes, recepientName, SessionUserFullName);

            // Log order details
            LogManager log = new LogManager();
            log.SaveLogData(sessionID, LogLevel.INFO.ToString(), Logger.ConfirmOrder.ToString(), message, null);


            if (result > 0)
            {
                order.OrderID = result;
                SendMail(order);
                SendFax(order);
                if (Tip > 0)
                {
                    message = Common.LineTipLogMessage(Tip.ToString(), result.ToString());
                    log.SaveLogData(sessionID, LogLevel.INFO.ToString(), Logger.ConfirmOrder.ToString(), message, null);
                }
                if (order.OrderTypeID == BusinessEntities.OrderType.Deliver)
                {
                    SessionMessage = "Thank you for ordering at pizzaness. Your order has been successfully placed. We will process and dispatch your order to you as soon as possible. An order detail email has been sent at your registered email.";
                }
                else
                {
                    SessionMessage = "Thank you for ordering at pizzaness. Your order has been successfully placed. An order detail email has been sent at your registered email.";
                }
                if (order.PaymentMethod == BusinessEntities.PaymentType.CashPayment)
                {
                    SessionUserOrder      = null;
                    SessionPreOrderPromo  = null;
                    SessionUserOrderTotal = 0;
                    Response.Redirect("~/Default.aspx");
                }
                SessionOrderId        = result;
                SessionUserOrderTotal = order.OrderTotal;

                Response.Redirect("~/ProcessPayment.aspx");
            }
        }
    }