Beispiel #1
0
        public ActionResult Edit(DiscountModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
            {
                return(AccessDeniedView());
            }

            var discount = _discountService.GetDiscountById(model.Id);

            if (discount == null)
            {
                //No discount found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                discount = model.ToEntity(discount);
                _discountService.UpdateDiscount(discount);

                //related Item Ids
                model.RelatedItemIds = model.RelatedItemIds == null ? "" : model.RelatedItemIds;
                var relatedItemIds = model.RelatedItemIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x)).ToList();
                if (relatedItemIds.Count > 0)
                {
                    switch (discount.DiscountType)
                    {
                    case DiscountType.AssignedToManufacturers:

                        //apply discount all manufacturers except related ones
                        if (model.ExludeRelatedItems)
                        {
                            var manufacturers = _manufacturerService.GetAllManufacturers();
                            relatedItemIds = manufacturers.Select(x => x.Id).Except(relatedItemIds).ToList();
                        }

                        List <Manufacturer> itemsToBoRemoved = new List <Manufacturer>();
                        foreach (var manufacturer in discount.AppliedToManufacturers)
                        {
                            if (relatedItemIds.Where(x => x == manufacturer.Id).Count() == 0)
                            {
                                itemsToBoRemoved.Add(manufacturer);
                            }
                        }
                        foreach (var item in itemsToBoRemoved)
                        {
                            discount.AppliedToManufacturers.Remove(item);
                        }

                        foreach (var id in relatedItemIds)
                        {
                            var manufacturer = _manufacturerService.GetManufacturerById(id);
                            if (manufacturer == null)
                            {
                                continue;
                            }
                            if (manufacturer.AppliedDiscounts.Where(d => d.Id == discount.Id).Count() == 0)
                            {
                                discount.AppliedToManufacturers.Add(manufacturer);
                            }
                            //manufacturer.AppliedDiscounts.Add(discount);
                        }
                        break;

                    case DiscountType.AssignedToSkus:

                        break;

                    case DiscountType.AssignedToCategories:

                        break;
                    }
                }

                _discountService.UpdateDiscount(discount);

                //activity log
                _customerActivityService.InsertActivity("EditDiscount", _localizationService.GetResource("ActivityLog.EditDiscount"), discount.Name);

                SuccessNotification(_localizationService.GetResource("Admin.Promotions.Discounts.Updated"));
                return(continueEditing ? RedirectToAction("Edit", discount.Id) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareDiscountModel(model, discount);
            return(View(model));
        }
Beispiel #2
0
 public async Task <CommonResponse> AddDiscounts(DiscountModel discountModel)
 {
     return(await _discountRepository.AddDiscounts(discountModel));
 }
Beispiel #3
0
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            List <ServiceMadeModel> serviceMade = new List <ServiceMadeModel>();
            ClientModel             cm          = dgvClient.SelectedItem as ClientModel;

            if (cm != null)
            {
                int id = Convert.ToInt32(cm.ID1);

                if (id != 0)
                {
                    string servMode = cm.ServiceMode;
                    cm               = getClientDetails(id);
                    cm.ID1           = id.ToString();
                    cm.ServiceMode   = servMode;
                    cm.IfViewDetails = false;
                    cm.IfEditDetails = false;
                    cm.IfPrintWaiver = false;

                    //cm.ServiceMode = row.Cells[3].Value.ToString();
                    serviceMade = getServiceMade(id);

                    //cm.LstServiceTypeModel = getServiceType(serviceMade);
                    //cm.LstServiceTypeModel.AddRange(getServicesFromPromo(cm));
                    serviceMade.AddRange(getServicesFromPromo(cm));
                    cm.lstProductsBought = getProductsBoughtForClient(id);

                    //DISCOUNTED LSTSERVICE TYPE
                    List <ServiceTypeModel> discountedServiceType = new List <ServiceTypeModel>();
                    ServiceTypeModel        discServiceType       = new ServiceTypeModel();

                    foreach (ServiceMadeModel smmm in serviceMade)
                    {
                        //discServiceType = stm;
                        DiscountModel dm = getDiscountedRate(Convert.ToInt32(smmm.Discounted));

                        double price           = Convert.ToDouble(smmm.Price);
                        double discount        = Convert.ToInt32(dm.Discount);
                        double discountedPrice = (price * (discount / 100));

                        price = price - discountedPrice;
                        discServiceType.Price       = price.ToString();
                        discServiceType.ServiceType = smmm.ServiceType;
                        discountedServiceType.Add(discServiceType);
                        discServiceType = new ServiceTypeModel();
                    }

                    cm.LstServiceTypeModel = discountedServiceType;

                    cm.LstTherapistModel = getTherapistServed(id);
                    conDB.writeLogFile("GENERATE REPORT: CLIENT FORM FOR: " + cm.ID1);

                    ReportForm rf = new ReportForm(this, cm);
                    rf.ShowDialog();
                }
            }
            else
            {
                System.Windows.MessageBox.Show("No record selected!");
            }
        }
        public SaleViewModel()
        {
            ShowOpenButton       = true;
            CurrentTicket        = new ObservableCollection <OrderItemModel>();
            CurrentTotalDiscount = new DiscountModel();
            Quantity             = 1;
            AllMenu = new List <MenuModel>();
            SetItemMenu();
            foreach (var category in AllMenu)
            {
                var grid = new Grid()
                {
                    ColumnSpacing     = 10,
                    RowSpacing        = 10,
                    ColumnDefinitions = new ColumnDefinitionCollection()
                    {
                        new ColumnDefinition()
                        {
                            Width = GridLength.Star
                        },
                        new ColumnDefinition()
                        {
                            Width = GridLength.Star
                        },
                        new ColumnDefinition()
                        {
                            Width = GridLength.Star
                        },
                        new ColumnDefinition()
                        {
                            Width = GridLength.Star
                        },
                    },
                    RowDefinitions = new RowDefinitionCollection()
                    {
                        new RowDefinition()
                        {
                            Height = GridLength.Star
                        },
                        new RowDefinition()
                        {
                            Height = GridLength.Star
                        },
                        new RowDefinition()
                        {
                            Height = GridLength.Star
                        },
                        new RowDefinition()
                        {
                            Height = GridLength.Star
                        },
                    }
                };

                int row = 0;
                int col = 0;
                if (category != null || category.Items.Count > 0)
                {
                    foreach (var item in category.Items)
                    {
                        if (col % 4 == 0 && col != 0)
                        {
                            row++;
                            col = 0;
                        }

                        var button = new Button();
                        button.Text              = item.Name;
                        button.HeightRequest     = 150;
                        button.WidthRequest      = 150;
                        button.BorderColor       = Color.Gray;
                        button.BorderWidth       = 2;
                        button.CornerRadius      = 10;
                        button.HorizontalOptions = LayoutOptions.Center;
                        button.VerticalOptions   = LayoutOptions.Center;
                        button.Command           = new Command <ItemModel>((itemModel) => OpenOption(itemModel));
                        button.CommandParameter  = item;
                        button.BackgroundColor   = Color.FromHex(item.Color);
                        grid.Children.Add(button, col, row);
                        col++;
                    }
                }

                var scrollView = new ScrollView()
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    Content           = grid
                };
                ViewChildren.Add(scrollView);
                TabChildren.Add(new TabItem(category.CategoryName, scrollView));
            }
            ;
            QuantityChangeCommand = new Command <string>((change) => QuantityChange(change));
            SaveItemCommand       = new Command(SaveItemToTicket);
            SaveTicketCommand     = new Command(SaveTicket);
            OpenTicketListCommand = new Command(OpenTicketList);
            OpenTicketCommand     = new Command <int>((ticketNumber) => OpenTicket(ticketNumber));
            ChargeCommand         = new Command(Charge);
            DeleteItemCommand     = new Command <OrderItemModel>(DeleteItem);
            CloudsyncClickCommand = new Command(CloudsyncClick);
            GetDiscount();
        }
 public static Discount ToEntity(this DiscountModel model)
 {
     return(Mapper.Map <DiscountModel, Discount>(model));
 }
Beispiel #6
0
 public void Do(ShoppingCartModel cart)
 {
     _lastDiscount = cart.Discount;
     cart.Discount = _discount;
 }
Beispiel #7
0
        public virtual async Task PrepareDiscountModel(DiscountModel model, Discount discount)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            model.AvailableDiscountRequirementRules.Add(new SelectListItem {
                Text = _translationService.GetResource("admin.marketing.discounts.Requirements.DiscountRequirementType.Select"), Value = ""
            });
            var discountPlugins = _discountService.LoadAllDiscountProviders();

            foreach (var discountPlugin in discountPlugins)
            {
                foreach (var discountRule in discountPlugin.GetRequirementRules())
                {
                    model.AvailableDiscountRequirementRules.Add(new SelectListItem {
                        Text = discountRule.FriendlyName, Value = discountRule.SystemName
                    });
                }
            }
            var currencies = await _currencyService.GetAllCurrencies();

            foreach (var item in currencies)
            {
                model.AvailableCurrencies.Add(new SelectListItem()
                {
                    Text = item.Name, Value = item.CurrencyCode
                });
            }
            //discount amount providers
            foreach (var item in _discountService.LoadDiscountAmountProviders())
            {
                model.AvailableDiscountAmountProviders.Add(new SelectListItem()
                {
                    Value = item.SystemName, Text = item.FriendlyName
                });
            }

            if (discount != null)
            {
                //requirements
                foreach (var dr in discount.DiscountRules.OrderBy(dr => dr.Id))
                {
                    var discountPlugin      = _discountService.LoadDiscountProviderBySystemName(dr.DiscountRequirementRuleSystemName);
                    var discountRequirement = discountPlugin.GetRequirementRules().Single(x => x.SystemName == dr.DiscountRequirementRuleSystemName);
                    {
                        if (discountPlugin != null)
                        {
                            model.DiscountRequirementMetaInfos.Add(new DiscountModel.DiscountRequirementMetaInfo
                            {
                                DiscountRequirementId = dr.Id,
                                RuleName         = discountRequirement.FriendlyName,
                                ConfigurationUrl = GetRequirementUrlInternal(discountRequirement, discount, dr.Id)
                            });
                        }
                    }
                }
            }
            else
            {
                model.IsEnabled = true;
            }
        }
        private void PrepareDiscountModel(DiscountModel model, Discount discount)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
            model.AvailableDiscountRequirementRules.Add(new SelectListItem()
            {
                Text = _localizationService.GetResource("Admin.Promotions.Discounts.Requirements.DiscountRequirementType.Select"), Value = ""
            });
            var discountRules = _discountService.LoadAllDiscountRequirementRules();

            foreach (var discountRule in discountRules)
            {
                model.AvailableDiscountRequirementRules.Add(new SelectListItem()
                {
                    Text  = discountRule.PluginDescriptor.GetLocalizedValue(_localizationService, "FriendlyName"),
                    Value = discountRule.PluginDescriptor.SystemName
                });
            }

            if (discount != null)
            {
                //applied to categories
                foreach (var category in discount.AppliedToCategories)
                {
                    if (category != null && !category.Deleted)
                    {
                        model.AppliedToCategoryModels.Add(new DiscountModel.AppliedToCategoryModel()
                        {
                            CategoryId = category.Id,
                            Name       = category.Name
                        });
                    }
                }

                //applied to products
                foreach (var product in discount.AppliedToProducts)
                {
                    if (product != null && !product.Deleted)
                    {
                        var appliedToProductModel = new DiscountModel.AppliedToProductModel()
                        {
                            ProductId   = product.Id,
                            ProductName = product.Name
                        };
                        model.AppliedToProductModels.Add(appliedToProductModel);
                    }
                }

                //requirements
                foreach (var dr in discount.DiscountRequirements.OrderBy(dr => dr.Id))
                {
                    var drr = _discountService.LoadDiscountRequirementRuleBySystemName(dr.DiscountRequirementRuleSystemName);
                    if (drr != null)
                    {
                        model.DiscountRequirementMetaInfos.Add(new DiscountModel.DiscountRequirementMetaInfo()
                        {
                            DiscountRequirementId = dr.Id,
                            RuleName         = drr.PluginDescriptor.GetLocalizedValue(_localizationService, "FriendlyName"),
                            ConfigurationUrl = GetRequirementUrlInternal(drr, discount, dr.Id)
                        });
                    }
                }
            }
        }
        public ActionResult Edit(DiscountModel model, bool continueEditing)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageDiscounts))
            {
                return(AccessDeniedView());
            }

            var discount = _discountService.GetDiscountById(model.Id);

            if (discount == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var prevDiscountType = discount.DiscountType;
                discount = model.ToEntity(discount);
                _discountService.UpdateDiscount(discount);

                //clean up old references (if changed) and update "HasDiscountsApplied" properties
                if (prevDiscountType == DiscountType.AssignedToCategories && discount.DiscountType != DiscountType.AssignedToCategories)
                {
                    //applied to categories
                    var categories = discount.AppliedToCategories.ToList();
                    discount.AppliedToCategories.Clear();
                    _discountService.UpdateDiscount(discount);

                    categories.Each(x => _categoryService.UpdateHasDiscountsApplied(x));
                }

                if (prevDiscountType == DiscountType.AssignedToManufacturers && discount.DiscountType != DiscountType.AssignedToManufacturers)
                {
                    var manufacturers = discount.AppliedToManufacturers.ToList();
                    discount.AppliedToManufacturers.Clear();
                    _discountService.UpdateDiscount(discount);

                    manufacturers.Each(x => _manufacturerService.UpdateHasDiscountsApplied(x));
                }

                if (prevDiscountType == DiscountType.AssignedToSkus && discount.DiscountType != DiscountType.AssignedToSkus)
                {
                    //applied to products
                    var products = discount.AppliedToProducts.ToList();
                    discount.AppliedToProducts.Clear();
                    _discountService.UpdateDiscount(discount);

                    products.Each(x => _productService.UpdateHasDiscountsApplied(x));
                }

                //activity log
                _customerActivityService.InsertActivity("EditDiscount", _services.Localization.GetResource("ActivityLog.EditDiscount"), discount.Name);

                NotifySuccess(_services.Localization.GetResource("Admin.Promotions.Discounts.Updated"));
                return(continueEditing ? RedirectToAction("Edit", discount.Id) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareDiscountModel(model, discount);
            return(View(model));
        }
Beispiel #10
0
        private static decimal ApplyDiscountToBasketItems(BasketItemModel basketItem, DiscountModel discount)
        {
            int basketQuantity = basketItem.ItemQuantity;

            if (basketQuantity >= discount.ThresholdQuantity)
            {
                basketItem.Discount = discount;
                while (basketQuantity >= discount.ThresholdQuantity)
                {
                    discount.TotalDiscountAmount += discount.DiscountAmount;
                    basketQuantity -= discount.ThresholdQuantity;
                }
            }

            return(discount.TotalDiscountAmount);
        }
Beispiel #11
0
 public static Discount ToEntity(this DiscountModel model, Discount entity)
 {
     MapperFactory.Map(model, entity);
     return(entity);
 }
 public DiscountDetails(DiscountWindow df, DiscountModel dm)
 {
     discountForm = df;
     discount     = dm;
     InitializeComponent();
 }
Beispiel #13
0
 public DiscountModel UpdateDiscountModel(DiscountModel entity)
 {
     return(Manager.UpdateDiscountModel(entity));
 }
Beispiel #14
0
 public DiscountModel InsertDiscountModel(DiscountModel entity)
 {
     return(Manager.InsertDiscountModel(entity));
 }
Beispiel #15
0
 public static Discount ToEntity(this DiscountModel model)
 {
     return(model.MapTo <DiscountModel, Discount>());
 }
        private void PrepareDiscountModel(DiscountModel model, Discount discount)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var language = _services.WorkContext.WorkingLanguage;

            model.PrimaryStoreCurrencyCode = _services.StoreContext.CurrentStore.PrimaryStoreCurrency.CurrencyCode;
            model.AvailableDiscountRequirementRules.Add(
                new SelectListItem {
                Text = _services.Localization.GetResource("Admin.Promotions.Discounts.Requirements.DiscountRequirementType.Select"), Value = ""
            }
                );

            var discountRules = _discountService.LoadAllDiscountRequirementRules();

            foreach (var discountRule in discountRules)
            {
                model.AvailableDiscountRequirementRules.Add(new SelectListItem
                {
                    Text  = _pluginMediator.GetLocalizedFriendlyName(discountRule.Metadata),
                    Value = discountRule.Metadata.SystemName
                });
            }

            if (discount != null)
            {
                // applied to categories
                model.AppliedToCategoryModels = discount.AppliedToCategories
                                                .Where(x => x != null && !x.Deleted)
                                                .Select(x => new DiscountModel.AppliedToCategoryModel {
                    CategoryId = x.Id, Name = x.GetLocalized(y => y.Name, language.Id)
                })
                                                .ToList();

                // applied to manufacturers
                model.AppliedToManufacturerModels = discount.AppliedToManufacturers
                                                    .Where(x => x != null && !x.Deleted)
                                                    .Select(x => new DiscountModel.AppliedToManufacturerModel {
                    ManufacturerId = x.Id, ManufacturerName = x.GetLocalized(y => y.Name, language.Id)
                })
                                                    .ToList();

                // applied to products
                model.AppliedToProductModels = discount.AppliedToProducts
                                               .Where(x => x != null && !x.Deleted)
                                               .Select(x => new DiscountModel.AppliedToProductModel {
                    ProductId = x.Id, ProductName = x.GetLocalized(y => y.Name, language.Id)
                })
                                               .ToList();

                // requirements
                foreach (var dr in discount.DiscountRequirements.OrderBy(dr => dr.Id))
                {
                    var drr = _discountService.LoadDiscountRequirementRuleBySystemName(dr.DiscountRequirementRuleSystemName);
                    if (drr != null)
                    {
                        model.DiscountRequirementMetaInfos.Add(new DiscountModel.DiscountRequirementMetaInfo
                        {
                            DiscountRequirementId = dr.Id,
                            RuleName         = _pluginMediator.GetLocalizedFriendlyName(drr.Metadata),
                            ConfigurationUrl = GetRequirementUrlInternal(drr.Value, discount, dr.Id)
                        });
                    }
                }
            }
        }
Beispiel #17
0
 public static Discount ToEntity(this DiscountModel model, Discount destination)
 {
     return(model.MapTo(destination));
 }
Beispiel #18
0
 public void InvitePassenger(DiscountModel model, Invite ui, int userid)
 {
     throw new NotImplementedException();
 }
Beispiel #19
0
 public AddDiscountCommand(DiscountModel discount)
 {
     _discount = discount;
 }
Beispiel #20
0
 public void FreeSeat(DiscountModel model, Discount dc, int userid)
 {
     throw new NotImplementedException();
 }
        public void SaveItemToTicket()
        {
            ShowOpenButton = false;
            try
            {
                decimal       optionPrice     = OptionList[CurrentSelectedOptionIndex].Price;
                bool          isDiscount      = true;
                DiscountModel currentDiscount = new DiscountModel();
                if (Discount1)
                {
                    currentDiscount = new DiscountModel {
                        DiscountName = Discounts[0].DiscountName, Amount = Discounts[0].Amount, IsPercentage = Discounts[0].IsPercentage
                    }
                }
                ;
                else if (Discount2)
                {
                    currentDiscount = new DiscountModel {
                        DiscountName = Discounts[1].DiscountName, Amount = Discounts[1].Amount, IsPercentage = Discounts[1].IsPercentage
                    }
                }
                ;
                else if (Discount3)
                {
                    currentDiscount = new DiscountModel {
                        DiscountName = Discounts[2].DiscountName, Amount = Discounts[2].Amount, IsPercentage = Discounts[2].IsPercentage
                    }
                }
                ;
                else if (Discount4)
                {
                    currentDiscount = new DiscountModel {
                        DiscountName = Discounts[3].DiscountName, Amount = Discounts[3].Amount, IsPercentage = Discounts[3].IsPercentage
                    }
                }
                ;
                else
                {
                    isDiscount = false;
                }
                decimal discountedAmount = (currentDiscount.IsPercentage) ?
                                           (currentDiscount.Amount / 100 * (CurrentItem.Price + optionPrice) * Quantity)
                    : ((currentDiscount.Amount < (CurrentItem.Price + optionPrice) * Quantity) ? currentDiscount.Amount : (CurrentItem.Price + optionPrice) * Quantity);

                CurrentTicket.Add(new OrderItemModel
                {
                    ItemName             = CurrentItem.Name,
                    IsDiscounted         = isDiscount,
                    ItemPrice            = (CurrentItem.Price + optionPrice) * Quantity,
                    Quantity             = Quantity,
                    OptionName           = OptionList[CurrentSelectedOptionIndex].OptionName,
                    OptionPrice          = OptionList[CurrentSelectedOptionIndex].Price,
                    DiscountName         = CurrentTotalDiscount.DiscountName,
                    DiscountedPrice      = (CurrentItem.Price + optionPrice) * Quantity - discountedAmount,
                    IsDiscountPercentage = currentDiscount.IsPercentage,
                    ItemDiscount         = currentDiscount.Amount
                });

                CalculateTotalAmount();

                Discount1 = false;
                Discount2 = false;
                Discount3 = false;
                Discount4 = false;
            }
            catch (Exception e)
            {
                Application.Current.MainPage.DisplayAlert("Error", "Cannot add item to ticket", "Ok");
            }

            CurrentTicket = CurrentTicket;
            if (PopupNavigation.Instance.PopupStack.Any())
            {
                PopupNavigation.PopAllAsync();
            }
            CurrentItem   = new ItemModel();
            CurrentOption = new List <string>();
            CurrentSelectedOptionIndex = 0;
            Quantity = 1;
        }
Beispiel #22
0
        public virtual IActionResult Edit(DiscountModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
                return AccessDeniedView();

            //try to get a discount with the specified id
            var discount = _discountService.GetDiscountById(model.Id);
            if (discount == null)
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                var prevDiscountType = discount.DiscountType;
                discount = model.ToEntity(discount);
                _discountService.UpdateDiscount(discount);

                //clean up old references (if changed) and update "HasDiscountsApplied" properties
                if (prevDiscountType == DiscountType.AssignedToCategories && discount.DiscountType != DiscountType.AssignedToCategories)
                {
                    //applied to categories
                    discount.DiscountCategoryMappings.Clear();
                    _discountService.UpdateDiscount(discount);
                }

                if (prevDiscountType == DiscountType.AssignedToManufacturers && discount.DiscountType != DiscountType.AssignedToManufacturers)
                {
                    //applied to manufacturers
                    discount.DiscountManufacturerMappings.Clear();
                    _discountService.UpdateDiscount(discount);
                }

                if (prevDiscountType == DiscountType.AssignedToSkus && discount.DiscountType != DiscountType.AssignedToSkus)
                {
                    //applied to products
                    var products = _discountService.GetProductsWithAppliedDiscount(discount.Id, true);

                    discount.DiscountProductMappings.Clear();
                    _discountService.UpdateDiscount(discount);

                    //update "HasDiscountsApplied" property
                    foreach (var p in products)
                        _productService.UpdateHasDiscountsApplied(p);
                }

                //activity log
                _customerActivityService.InsertActivity("EditDiscount",
                    string.Format(_localizationService.GetResource("ActivityLog.EditDiscount"), discount.Name), discount);

                _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Promotions.Discounts.Updated"));

                if (!continueEditing)
                    return RedirectToAction("List");

                //selected tab
                SaveSelectedTabName();

                return RedirectToAction("Edit", new { id = discount.Id });
            }

            //prepare model
            model = _discountModelFactory.PrepareDiscountModel(model, discount, true);

            //if we got this far, something failed, redisplay form
            return View(model);
        }
        void SetTotalDiscount()
        {
            DiscountModel currentDiscount = new DiscountModel();

            if (TotalDiscount1)
            {
                currentDiscount = new DiscountModel {
                    DiscountName = Discounts[0].DiscountName, Amount = Discounts[0].Amount, IsPercentage = Discounts[0].IsPercentage
                }
            }
            ;
            else if (TotalDiscount2)
            {
                currentDiscount = new DiscountModel {
                    DiscountName = Discounts[1].DiscountName, Amount = Discounts[1].Amount, IsPercentage = Discounts[1].IsPercentage
                }
            }
            ;
            else if (TotalDiscount3)
            {
                currentDiscount = new DiscountModel {
                    DiscountName = Discounts[2].DiscountName, Amount = Discounts[2].Amount, IsPercentage = Discounts[2].IsPercentage
                }
            }
            ;
            else if (TotalDiscount4)
            {
                currentDiscount = new DiscountModel {
                    DiscountName = Discounts[3].DiscountName, Amount = Discounts[3].Amount, IsPercentage = Discounts[3].IsPercentage
                }
            }
            ;
            CurrentTotalDiscount = currentDiscount;
        }

        void OpenOption(ItemModel item)
        {
            CurrentItem   = item;
            CurrentOption = new List <string>();
            OptionList    = new List <ItemOptionModel>();

            if (!string.IsNullOrEmpty(item.Option1))
            {
                OptionList.Add(new ItemOptionModel()
                {
                    OptionName = item.Option1, Price = item.Option1Price
                });
            }

            if (!string.IsNullOrEmpty(item.Option2))
            {
                OptionList.Add(new ItemOptionModel()
                {
                    OptionName = item.Option2, Price = item.Option2Price
                });
            }

            if (!string.IsNullOrEmpty(item.Option3))
            {
                OptionList.Add(new ItemOptionModel()
                {
                    OptionName = item.Option3, Price = item.Option3Price
                });
            }

            if (!string.IsNullOrEmpty(item.Option4))
            {
                OptionList.Add(new ItemOptionModel()
                {
                    OptionName = item.Option4, Price = item.Option4Price
                });
            }

            foreach (var option in OptionList)
            {
                CurrentOption.Add(option.OptionName + "  ( +" + option.Price.ToString("#,0.00") + " )");
            }

            CurrentItemPrice = item.Price;

            if (item.Option2 == null && item.Option3 == null && item.Option4 == null)
            {
                if (!string.IsNullOrEmpty(item.Option1))
                {
                    OptionList.Add(new ItemOptionModel()
                    {
                        OptionName = item.Option1, Price = item.Option1Price
                    });
                }
                CurrentSelectedOptionIndex = 0;
                CurrentItemPrice           = item.Price;
                SaveItemToTicket();
            }
            else
            {
                PopupNavigation.PushAsync(new ItemPopup(this));
            }
        }

        void SetItemMenu()
        {
            if (App.ListCategoryModels == null)
            {
                var getCate = _service.GetAllCategories();

                if (!getCate.Result.IsError)
                {
                    CategoriesList         = getCate.Result.Categories;
                    App.ListCategoryModels = CategoriesList;
                }
            }
            else
            {
                CategoriesList = App.ListCategoryModels;
            }
            if (CategoriesList == null)
            {
                CategoriesList = new List <CategoryModel>();

                foreach (var category in CategoriesList)
                {
                    AllMenu.Add(new MenuModel()
                    {
                        CategoryName = category.Name,
                        Items        = new ObservableCollection <ItemModel>()
                    });
                }
            }
            ItemsViewModel items;

            if (App.ItemsManuViewModel == null || App.ItemsManuViewModel.Items.Count == 0)
            {
                items = _service.GetItems();
                App.ItemsManuViewModel = items;
            }
            else
            {
                items = App.ItemsManuViewModel;
            }
            if (items.Items == null || items.Items.Count == 0)
            {
                //Application.Current.MainPage.DisplayAlert("", "ไม่พบรายการอาหารในระบบ", "OK");
                //PopupNavigation.PushAsync(new Error(new ErrorViewModel("ไม่พบรายการอาหารในระบบ")));
                return;
            }

            foreach (var item in items.Items)
            {
                var isCatExist = AllMenu.Where(a => a.CategoryName == item.CategoryName).FirstOrDefault();
                if (isCatExist == null)
                {
                    AllMenu.Add(new MenuModel()
                    {
                        CategoryName = item.CategoryName,
                        Items        = new ObservableCollection <ItemModel>()
                    });;
                }
                if (item.Color == null)
                {
                    item.Color = "DDDDDD";
                }
                AllMenu.Where(a => a.CategoryName == item.CategoryName).FirstOrDefault().Items.Add(item);
            }
        }

        void SaveTicket()
        {
            var maxNumber = 0;

            try
            {
                maxNumber = App.TicketList.Max(t => t.TicketNumber);
            }
            catch (Exception e)
            {
            }
            ReceiptViewModel receipt = new ReceiptViewModel()
            {
                ItemList       = CurrentTicket.ToList(),
                Total          = TotalPrice,
                TicketNumber   = maxNumber + 1,
                CreateDateTime = DateTime.Now,
            };

            App.TicketList.Add(receipt);
            ClearTicket();
        }

        void OpenTicketList()
        {
            ClearTicket();
            PopupNavigation.PushAsync(new OpenTicketsPopup(this));
            TicketList = App.TicketList;
        }

        void ClearTicket()
        {
            CurrentTicket         = new ObservableCollection <OrderItemModel>();
            Quantity              = 1;
            QuantityChangeCommand = new Command <string>((change) => QuantityChange(change));
            SaveItemCommand       = new Command(SaveItemToTicket);
            CurrentTicket         = new ObservableCollection <OrderItemModel>();
            CurrentTotalDiscount  = new DiscountModel();
            CurrentDiscountAmount = 0;
            TotalPrice            = 0;
            ShowOpenButton        = true;
        }

        void OpenTicket(int ticketNumber)
        {
            var ticket = App.TicketList.Where(t => t.TicketNumber == ticketNumber).FirstOrDefault();

            if (ticket.ItemList == null || ticket.ItemList.Count == 0)
            {
                return;
            }
            foreach (var item in ticket.ItemList)
            {
                CurrentTicket.Add(item);
                TotalPrice += item.DiscountedPrice;
            }
            App.TicketList.Remove(ticket);
            PopupNavigation.PopAllAsync();
        }

        void Charge()
        {
            if (CurrentTicket == null || CurrentTicket.Count == 0)
            {
                PopupNavigation.PushAsync(new Error(new ErrorViewModel("Please add item to ticket before proceeding")));
                return;
            }
            decimal totalDiscount = 0;

            foreach (var item in CurrentTicket)
            {
                totalDiscount += item.ItemDiscount;
            }
            ReceiptViewModel receipt = new ReceiptViewModel()
            {
                ItemList       = CurrentTicket.ToList(),
                Total          = TotalPrice,
                CreateDateTime = DateTime.Now,
                TotalDiscount  = totalDiscount + CurrentDiscountAmount,
                Discount       = CurrentDiscountAmount,
            };

            Application.Current.MainPage.Navigation.PushAsync(new ChargePage(receipt));
        }

        void GetDiscount()
        {
            var discountVM = _service.GetDiscounts();

            Discounts = discountVM.Discounts;
            if (Discounts.Count > 0)
            {
                DiscountName1 = Discounts[0].DiscountName;
                HasDiscount1  = true;
                Discount1     = false;
            }

            if (Discounts.Count > 1)
            {
                DiscountName2 = Discounts[1].DiscountName;
                HasDiscount2  = true;
                Discount2     = false;
            }

            if (Discounts.Count > 2)
            {
                DiscountName3 = Discounts[2].DiscountName;
                HasDiscount3  = true;
                Discount3     = false;
            }

            if (Discounts.Count > 3)
            {
                DiscountName4 = Discounts[3].DiscountName;
                HasDiscount4  = true;
                Discount4     = false;
            }
        }

        void DeleteItem(OrderItemModel model)
        {
            CurrentTicket.Remove(model);
            CalculateTotalAmount();
        }

        void CloudsyncClick()
        {
            IsLoadding = true;
            var getCate = _service.GetAllCategories();

            if (!getCate.Result.IsError)
            {
                CategoriesList         = getCate.Result.Categories;
                App.ListCategoryModels = CategoriesList;
            }


            var items = _service.GetItems();


            if (items.Items == null || items.Items.Count == 0)
            {
                //Application.Current.MainPage.DisplayAlert("", "ไม่พบรายการอาหารในระบบ", "OK");
                //PopupNavigation.PushAsync(new Error(new ErrorViewModel("ไม่พบรายการอาหารในระบบ")));
                return;
            }
            App.ItemsManuViewModel       = items;
            Application.Current.MainPage = new NavigationPage(new Views.SaleView());
        }
 public DiscountedSeatModel ApplyDiscount(DiscountModel discountModel)
 {
     return(Context.Discount.ApplyDiscount(discountModel));
 }
 public static Discount ToEntity(this DiscountModel model, Discount destination)
 {
     return(Mapper.Map(model, destination));
 }
        public virtual IActionResult Edit(DiscountModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
            {
                return(AccessDeniedView());
            }

            //try to get a discount with the specified id
            var discount = _discountService.GetDiscountById(model.Id);

            if (discount == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var prevDiscountType = discount.DiscountType;
                discount = model.ToEntity(discount);
                _discountService.UpdateDiscount(discount);

                //clean up old references (if changed)
                if (prevDiscountType != discount.DiscountType)
                {
                    switch (prevDiscountType)
                    {
                    case DiscountType.AssignedToSkus:
                        _productService.ClearDiscountProductMapping(discount);
                        break;

                    case DiscountType.AssignedToCategories:
                        _categoryService.ClearDiscountCategoryMapping(discount);
                        break;

                    case DiscountType.AssignedToManufacturers:
                        _manufacturerService.ClearDiscountManufacturerMapping(discount);
                        break;

                    default:
                        break;
                    }
                }

                //activity log
                _customerActivityService.InsertActivity("EditDiscount",
                                                        string.Format(_localizationService.GetResource("ActivityLog.EditDiscount"), discount.Name), discount);

                _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Promotions.Discounts.Updated"));

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                return(RedirectToAction("Edit", new { id = discount.Id }));
            }

            //prepare model
            model = _discountModelFactory.PrepareDiscountModel(model, discount, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #27
0
        /// <summary>
        /// Prepare discount model
        /// </summary>
        /// <param name="model">Discount model</param>
        /// <param name="discount">Discount</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Discount model</returns>
        public virtual DiscountModel PrepareDiscountModel(DiscountModel model, Discount discount, bool excludeProperties = false)
        {
            if (discount != null)
            {
                //fill in model values from the entity
                model = model ?? discount.ToModel <DiscountModel>();

                //prepare available discount requirement rules
                var discountRules = _discountService.LoadAllDiscountRequirementRules();
                foreach (var discountRule in discountRules)
                {
                    model.AvailableDiscountRequirementRules.Add(new SelectListItem
                    {
                        Text  = discountRule.PluginDescriptor.FriendlyName,
                        Value = discountRule.PluginDescriptor.SystemName
                    });
                }

                model.AvailableDiscountRequirementRules.Insert(0, new SelectListItem
                {
                    Text  = _localizationService.GetResource("Admin.Promotions.Discounts.Requirements.DiscountRequirementType.AddGroup"),
                    Value = "AddGroup"
                });

                model.AvailableDiscountRequirementRules.Insert(0, new SelectListItem
                {
                    Text  = _localizationService.GetResource("Admin.Promotions.Discounts.Requirements.DiscountRequirementType.Select"),
                    Value = string.Empty
                });

                //prepare available requirement groups
                var requirementGroups = discount.DiscountRequirements.Where(requirement => requirement.IsGroup);
                model.AvailableRequirementGroups = requirementGroups.Select(requirement =>
                                                                            new SelectListItem {
                    Value = requirement.Id.ToString(), Text = requirement.DiscountRequirementRuleSystemName
                }).ToList();

                //prepare nested search models
                PrepareDiscountUsageHistorySearchModel(model.DiscountUsageHistorySearchModel, discount);
                PrepareDiscountProductSearchModel(model.DiscountProductSearchModel, discount);
                PrepareDiscountCategorySearchModel(model.DiscountCategorySearchModel, discount);
                PrepareDiscountManufacturerSearchModel(model.DiscountManufacturerSearchModel, discount);
            }

            model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;

            //get URL of discount with coupon code
            if (model.RequiresCouponCode && !string.IsNullOrEmpty(model.CouponCode))
            {
                model.DiscountUrl = QueryHelpers.AddQueryString(_webHelper.GetStoreLocation().TrimEnd('/'),
                                                                NopDiscountDefaults.DiscountCouponQueryParameter, model.CouponCode);
            }

            //set default values for the new model
            if (discount == null)
            {
                model.LimitationTimes = 1;
            }

            return(model);
        }
Beispiel #28
0
        protected void PrepareDiscountModel(DiscountModel model, Discount discount)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
            model.AvailableDiscountRequirementRules.Add(new SelectListItem()
            {
                Text = _localizationService.GetResource("Admin.Promotions.Discounts.Requirements.DiscountRequirementType.Select"), Value = ""
            });
            var discountRules = _discountService.LoadAllDiscountRequirementRules();

            foreach (var discountRule in discountRules)
            {
                model.AvailableDiscountRequirementRules.Add(new SelectListItem()
                {
                    Text = discountRule.PluginDescriptor.FriendlyName, Value = discountRule.PluginDescriptor.SystemName
                });
            }

            if (discount != null)
            {
                //applied to categories
                foreach (var category in discount.AppliedToCategories)
                {
                    if (category != null && !category.Deleted)
                    {
                        model.AppliedToCategoryModels.Add(new DiscountModel.AppliedToCategoryModel()
                        {
                            CategoryId = category.Id,
                            Name       = category.Name
                        });
                    }
                }

                //applied to product variants
                foreach (var pv in discount.AppliedToProductVariants)
                {
                    if (pv != null && !pv.Deleted)
                    {
                        var appliedToProductVariantModel = new DiscountModel.AppliedToProductVariantModel()
                        {
                            ProductVariantId = pv.Id,
                        };
                        //full product name
                        if (!String.IsNullOrEmpty(pv.Name))
                        {
                            appliedToProductVariantModel.FullProductName = string.Format("{0} ({1})", pv.Product.Name, pv.Name);
                        }
                        else
                        {
                            appliedToProductVariantModel.FullProductName = pv.Product.Name;
                        }

                        model.AppliedToProductVariantModels.Add(appliedToProductVariantModel);
                    }
                }

                //requirements
                foreach (var dr in discount.DiscountRequirements.OrderBy(dr => dr.Id))
                {
                    var drr = _discountService.LoadDiscountRequirementRuleBySystemName(dr.DiscountRequirementRuleSystemName);
                    if (drr != null)
                    {
                        model.DiscountRequirementMetaInfos.Add(new DiscountModel.DiscountRequirementMetaInfo()
                        {
                            DiscountRequirementId = dr.Id,
                            RuleName         = drr.PluginDescriptor.FriendlyName,
                            ConfigurationUrl = GetRequirementUrlInternal(drr, discount, dr.Id)
                        });
                    }
                }
            }
        }
Beispiel #29
0
        public virtual IActionResult Edit(DiscountModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
            {
                return(AccessDeniedView());
            }

            var discount = _discountService.GetDiscountById(model.Id);

            if (discount == null)
            {
                //No discount found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var prevDiscountType = discount.DiscountType;
                discount = model.ToEntity(discount);
                _discountService.UpdateDiscount(discount);

                //clean up old references (if changed) and update "HasDiscountsApplied" properties
                if (prevDiscountType == DiscountType.AssignedToCategories &&
                    discount.DiscountType != DiscountType.AssignedToCategories)
                {
                    //applied to categories
                    discount.AppliedToCategories.Clear();
                    _discountService.UpdateDiscount(discount);
                }
                if (prevDiscountType == DiscountType.AssignedToManufacturers &&
                    discount.DiscountType != DiscountType.AssignedToManufacturers)
                {
                    //applied to manufacturers
                    discount.AppliedToManufacturers.Clear();
                    _discountService.UpdateDiscount(discount);
                }
                if (prevDiscountType == DiscountType.AssignedToSkus &&
                    discount.DiscountType != DiscountType.AssignedToSkus)
                {
                    //applied to products
                    var products = discount.AppliedToProducts.ToList();
                    discount.AppliedToProducts.Clear();
                    _discountService.UpdateDiscount(discount);
                    //update "HasDiscountsApplied" property
                    foreach (var p in products)
                    {
                        _productService.UpdateHasDiscountsApplied(p);
                    }
                }

                //activity log
                _customerActivityService.InsertActivity("EditDiscount", _localizationService.GetResource("ActivityLog.EditDiscount"), discount.Name);

                SuccessNotification(_localizationService.GetResource("Admin.Promotions.Discounts.Updated"));

                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();

                    return(RedirectToAction("Edit", new { id = discount.Id }));
                }
                return(RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareDiscountModel(model, discount);
            return(View(model));
        }
        public void RehydrateOrderItem(OrderItemModel model)
        {
            currentOrderItemId     = model.Id;
            quantityButton.Enabled = false;

            positions.Clear();
            components.Clear();

            variationId = model.VariationId;

            FragmentRoute route = svc.SelectVariation(model.VariationId);

            if (route == FragmentRoute.Components)
            {
                foreach (OrderItemComponentModel component in model.ComponentModels)
                {
                    components.Add(component.ComponentId, component);

                    if (component.HasComponents)
                    {
                        editedComponents.Add(component);
                    }
                }

                positions.Add(new VariationPosition()
                {
                    PosType = PositionType.Components, Id = model.VariationId
                });
            }

            VariationModel newModel = new VariationModel(model.VariationId);
            int            parentId = newModel.ParentId;

            while (newModel.ParentId != 0)
            {
                positions.Insert(0, new VariationPosition()
                {
                    PosType = PositionType.Variations, Id = newModel.ParentId
                });
                newModel = new VariationModel(newModel.ParentId);
            }

            thisPosition = positions.Count - 1;

            if (route == FragmentRoute.Components)
            {
                DisplayComponents(model.VariationId, true, ComponentListMode.Variation);
            }
            else
            {
                confirmButton.Visibility = ViewStates.Visible;
                DisplayVariations(parentId);
            }

            currentDiscountId = model.DiscountId;

            DiscountModel discountModel = svc.GetDiscountModel(currentDiscountId);

            discountText.Text = discountModel.Description;

            currentInOutId = model.InOutStatus;

            if (currentInOutId == 1)
            {
                inOutText.Text = "Eat In";
            }
            else
            {
                inOutText.Text = "Take Away";
            }

            Show();
        }