Inheritance: Entity
        public void CanHandleTax()
        {
            var taxTemplate = new TaxTemplate { Name = "Tax", Rate = 10, AccountTransactionType = AccountTransactionType.Default };
            var taxTemplates = new List<TaxTemplate> { taxTemplate };

            var tost = new MenuItem("Tost") { Id = 1 };
            var hamburger = new MenuItem("Hamburger") { Id = 2 };
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default).Build();

            var order = ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", tost, taxTemplates, new MenuItemPortion { Price = 5, Name = "Adet" }, "", null);

            order.Quantity = 2;
            order.PortionCount = 2;
            ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", tost, taxTemplates, new MenuItemPortion { Price = 5, Name = "Adet" }, "", null);
            ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", hamburger, taxTemplates, new MenuItemPortion { Price = 7, Name = "Adet" }, "", null);
            ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", hamburger, taxTemplates, new MenuItemPortion { Price = 6, Name = "Adet" }, "", null);
            ticket.AddCalculation(new CalculationType() { AccountTransactionType = AccountTransactionType.Default, DecreaseAmount = true }, 10);
            ticket.Recalculate();

            var orderSelector = new OrderSelector();
            orderSelector.UpdateTicket(ticket);
            Assert.AreEqual(ticket.GetSum(), orderSelector.Selectors.Sum(x => x.TotalPrice));

            ticket.TaxIncluded = true;
            orderSelector = new OrderSelector();
            orderSelector.UpdateTicket(ticket);
            Assert.AreEqual(ticket.GetSum(), orderSelector.Selectors.Sum(x => x.TotalPrice));

        }        
示例#2
0
 public MenuItem Build()
 {
     var result = new MenuItem(_menuItemName) { Id = _id, GroupCode = _groupCode, Tag = _productTag };
     foreach (var portionData in _portions)
     {
         result.AddPortion(portionData.Name, portionData.Price, "");
     }
     return result;
 }
        private static Ticket SetupTicket()
        {
            var tost = new MenuItem("Tost") { Id = 1 };
            var hamburger = new MenuItem("Hamburger") { Id = 2 };
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default).Build();


            var order = ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", tost, null, new MenuItemPortion { Price = 5, Name = "Adet" }, "", null);

            order.Quantity = 2;
            order.PortionCount = 2;
            ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", tost, null, new MenuItemPortion { Price = 5, Name = "Adet" }, "", null);
            ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", hamburger, null, new MenuItemPortion { Price = 7, Name = "Adet" }, "", null);
            ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", hamburger, null, new MenuItemPortion { Price = 6, Name = "Adet" }, "", null);
            ticket.Recalculate();
            return ticket;
        }
示例#4
0
        public void UpdateMenuItem(int userId, MenuItem menuItem, string portionName, string priceTag, int quantity, string defaultProperties)
        {
            MenuItemId = menuItem.Id;
            MenuItemName = menuItem.Name;
            var portion = menuItem.GetPortion(portionName);
            Debug.Assert(portion != null);
            UpdatePortion(portion, priceTag, menuItem.VatTemplate);
            Quantity = quantity;
            _selectedQuantity = quantity;
            PortionCount = menuItem.Portions.Count;
            CreatingUserId = userId;
            CreatedDateTime = DateTime.Now;

            if (!string.IsNullOrEmpty(defaultProperties))
            {
                foreach (var menuItemPropertyGroup in menuItem.PropertyGroups)
                {
                    var properties = defaultProperties.Split(',');
                    foreach (var defaultProperty in properties)
                    {
                        var property = defaultProperty.Trim();
                        var pQuantity = 1;
                        if (defaultProperty.Contains("*"))
                        {
                            var parts = defaultProperty.Split(new[] { '*' }, 1);
                            if (!string.IsNullOrEmpty(parts[0].Trim()))
                            {
                                property = parts[0];
                                int.TryParse(parts[1], out pQuantity);
                            }
                            else continue;
                        }
                        var defaultValue = menuItemPropertyGroup.Properties.FirstOrDefault(x => x.Name == property);
                        if (defaultValue != null)
                        {
                            for (int i = 0; i < pQuantity; i++)
                            {
                                ToggleProperty(menuItemPropertyGroup, defaultValue);
                            }
                        }
                    }
                }
            }
        }
示例#5
0
        public static IEnumerable<MenuItemSellInfo> CalculatePortionsItems(IEnumerable<Ticket> tickets, MenuItem menuItem)
        {
            var menuItems = new List<MenuItem> {menuItem};

            var menuItemSellInfos =
                                   from c in tickets.SelectMany(x => x.Orders
                                                                      .Where(y => y.DecreaseInventory && y.MenuItemName== menuItem.Name)
                                                                      .Select(y => new { Ticket = x, Order = y }))
                                   join menuI in menuItems on c.Order.MenuItemId equals menuI.Id
                                   group c by c.Order.PortionName
                                   into grp select new MenuItemSellInfo
                                   {
                                       Name = "\t." + grp.Key,
                                       Quantity = grp.Sum(y => y.Order.Quantity),
                                       Amount = grp.Sum(y => CalculateOrderTotal(y.Ticket, y.Order))
                                   };
               var result = menuItemSellInfos.ToList().OrderByDescending(x => x.Quantity);

            return result;
        }
 public bool ContainsMenuItem(MenuItem item)
 {
     return ScreenMenuItems.Where(x => x.MenuItemId == item.Id).Count() > 0;
 }
示例#7
0
        public Order AddOrder(AccountTransactionType template, Department department, string userName, MenuItem menuItem, IList<TaxTemplate> taxTemplates, MenuItemPortion portion, string priceTag, ProductTimer timer)
        {
            UnLock();
            var order = OrderBuilder.Create()
                                    .WithDepartment(department)
                                    .ForMenuItem(menuItem)
                                    .WithUserName(userName)
                                    .WithTaxTemplates(taxTemplates)
                                    .WithPortion(portion)
                                    .WithPriceTag(priceTag)
                                    .WithAccountTransactionType(template)
                                    .WithProductTimer(timer)
                                    .Build();

            AddOrder(order, taxTemplates, template, userName);
            return order;
        }
示例#8
0
        public Order AddOrder(AccountTransactionTemplate template, string userName, MenuItem menuItem, MenuItemPortion portion, string priceTag)
        {
            Locked = false;
            var tif = new Order();
            tif.UpdateMenuItem(userName, menuItem, portion, priceTag, 1);
            tif.AccountTransactionTemplateId = template.Id;
            if (AccountTransactions.AccountTransactions.SingleOrDefault(x => x.AccountTransactionTemplateId == template.Id) == null)
            {
                var transaction = AccountTransaction.Create(template);
                transaction.UpdateAccounts(AccountTemplateId, AccountId);
                AccountTransactions.AccountTransactions.Add(transaction);
            }

            if (tif.AccountTransactionTaxTemplateId > 0
                && AccountTransactions.AccountTransactions
                    .SingleOrDefault(x => x.AccountTransactionTemplateId == tif.AccountTransactionTaxTemplateId) == null)
            {
                var transaction = AccountTransaction.Create(menuItem.TaxTemplate.AccountTransactionTemplate);
                transaction.UpdateAccounts(AccountTemplateId, AccountId);
                AccountTransactions.AccountTransactions.Add(transaction);
            }
            Orders.Add(tif);
            return tif;
        }
示例#9
0
 public void UpdateMenuItem(string userName, MenuItem menuItem, MenuItemPortion portion, string priceTag, int quantity)
 {
     MenuItemId = menuItem.Id;
     MenuItemName = menuItem.Name;
     Debug.Assert(portion != null);
     UpdatePortion(portion, priceTag, menuItem.TaxTemplate);
     Quantity = quantity;
     _selectedQuantity = quantity;
     PortionCount = menuItem.Portions.Count;
     CreatingUserName = userName;
     CreatedDateTime = DateTime.Now;
 }
示例#10
0
 private static MenuItem CreateMenuItem(int id, string name, decimal price)
 {
     var result = new MenuItem(name) { Id = id };
     result.Portions.Add(new MenuItemPortion { Price = price });
     return result;
 }
示例#11
0
 public static MenuItemPortion AddDefaultMenuPortion(MenuItem item)
 {
     return item.AddPortion("Normal", 0, LocalSettings.CurrencySymbol);
 }
 public bool ContainsMenuItem(MenuItem item)
 {
     return ScreenMenuItems.Any(x => x.MenuItemId == item.Id);
 }
示例#13
0
 public static MenuItemPortion AddDefaultMenuPortion(MenuItem item)
 {
     return item.AddPortion(Localization.Properties.Resources.DefaultMenuPortion ?? "Normal", 0, LocalSettings.CurrencySymbol);
 }
示例#14
0
        public void CanAddTicketDiscounts()
        {
            var mi = new MenuItem("Elma");
            mi.AddPortion("Test", 10, "TL");
            var mi2 = new MenuItem("Armut");
            mi2.AddPortion("Test", 15, "TL");

            var ticket = new Ticket();
            ticket.AddTicketItem(0, mi, "Test");
            ticket.AddTicketItem(0, mi2, "Test");

            Assert.IsTrue(ticket.GetSum() == 25);

            ticket.AddTicketDiscount(DiscountType.Percent, 10, 0);
            Assert.IsTrue(ticket.GetSum() == 22.5m);

            ticket.AddTicketDiscount(DiscountType.Percent, 20, 0);

            Assert.IsTrue(ticket.GetSum() == 20.0m);

            ticket.AddTicketDiscount(DiscountType.Amount, 10, 0);
            Assert.IsTrue(ticket.GetSum() == 10);

            Assert.IsTrue(ticket.GetDiscountAndRoundingTotal() == 15);

            ticket.AddTicketDiscount(DiscountType.Amount, 5, 0);

            Assert.IsTrue(ticket.GetSum() == 15);
            Assert.IsTrue(ticket.GetDiscountAndRoundingTotal() == 10);

            ticket.AddTicketDiscount(DiscountType.Percent, 0, 0);
            ticket.AddTicketDiscount(DiscountType.Amount, 0, 0);

            Assert.IsTrue(ticket.GetSum() == 25);
            Assert.IsTrue(ticket.GetDiscountAndRoundingTotal() == 0);
            Assert.IsTrue(ticket.Discounts.Count == 0);

            ticket.AddTicketDiscount(DiscountType.Percent, 50, 0);
            Assert.IsTrue(ticket.GetSum() == 12.5m);
            Assert.IsTrue(ticket.Discounts.Count == 1);

            ticket.AddTicketDiscount(DiscountType.Percent, 0, 0);
            Assert.IsTrue(ticket.Discounts.Count == 0);
            Assert.IsTrue(ticket.GetSum() == 25);

            ticket.TicketItems[0].Gifted = true;
            Assert.IsTrue(ticket.GetSum() == 15);

            ticket.AddTicketDiscount(DiscountType.Percent, 10, 0);
            Assert.IsTrue(ticket.GetSum() == 13.5m);
            Assert.IsTrue(ticket.GetDiscountAndRoundingTotal() == 1.5m);

            ticket.TicketItems[0].Voided = true;
            Assert.IsTrue(ticket.GetSum() == 13.5m);

            ticket.AddTicketDiscount(DiscountType.Percent, 10, 0);
            Assert.AreEqual(13.5m, ticket.GetSum());
            Assert.AreEqual(1.5m, ticket.GetDiscountAndRoundingTotal());

            ticket.AddTicketDiscount(DiscountType.Amount, 0.5m, 0);
            Assert.AreEqual(13m, ticket.GetSum());

            ticket.Discounts.Clear();
            Assert.AreEqual(15m, ticket.GetSum());
            var t = new VatTemplate { Rate = 10 };

            var mix = new MenuItem("TestItem2") { VatTemplate = t };
            mix.AddPortion("Adet", 10, "TL");
            ticket.AddTicketItem(0, mix, "Adet");

            Assert.AreEqual(26m, ticket.GetSum());

            ticket.AddTicketDiscount(DiscountType.Percent, 10, 0);
            Assert.AreEqual(23.4m, ticket.GetSum());
            ticket.AddTicketDiscount(DiscountType.Amount, 0.4m, 0);
            Assert.AreEqual(23m, ticket.GetSum());
        }
示例#15
0
文件: Ticket.cs 项目: basio/veropos
 public TicketItem AddTicketItem(int userId, MenuItem menuItem, string portionName)
 {
     // Only for tests
     return AddTicketItem(userId, 0, menuItem, portionName, "", "");
 }
示例#16
0
文件: Ticket.cs 项目: basio/veropos
 public TicketItem AddTicketItem(int userId, int departmentId, MenuItem menuItem, string portionName, string priceTag, string defaultProperties)
 {
     Locked = false;
     var tif = new TicketItem { DepartmentId = departmentId };
     tif.UpdateMenuItem(userId, menuItem, portionName, priceTag, 1, defaultProperties);
     TicketItems.Add(tif);
     return tif;
 }
示例#17
0
 public void AddMenuItem(MenuItem menuItem)
 {
     var smi = new ScreenMenuItem { MenuItemId = menuItem.Id, Name = menuItem.Name };
     ScreenMenuItems.Add(smi);
 }
示例#18
0
 public static MenuItem Create()
 {
     var result = new MenuItem();
     AddDefaultMenuPortion(result);
     return result;
 }
示例#19
0
 public CostItemViewModel(CostItem model,MenuItem menuItem)
 {
     Model = model;
     _menuItem = menuItem;
 }
示例#20
0
        public Order AddOrder(AccountTransactionType template, string userName, MenuItem menuItem, MenuItemPortion portion, string priceTag, ProductTimer timer)
        {
            Locked = false;
            var order = new Order();
            order.UpdateMenuItem(userName, menuItem, portion, priceTag, 1);
            order.AccountTransactionTypeId = template.Id;

            TransactionDocument.AddSingletonTransaction(template.Id, template, AccountTypeId, AccountId);

            if (menuItem.TaxTemplate != null)
            {
                TransactionDocument.AddSingletonTransaction(order.TaxTempleteAccountTransactionTypeId,
                                                               menuItem.TaxTemplate.AccountTransactionType,
                                                               AccountTypeId, AccountId);
            }

            order.UpdateProductTimer(timer);
            Orders.Add(order);
            return order;
        }
示例#21
0
        public Order AddOrder(AccountTransactionType template, Department department, string userName, MenuItem menuItem, IList<TaxTemplate> taxTemplates, MenuItemPortion portion, string priceTag, ProductTimer timer)
        {
            UnLock();
            var order = new Order();
            order.UpdateMenuItem(userName, menuItem, taxTemplates, portion, priceTag, 1);
            order.AccountTransactionTypeId = template.Id;
            order.WarehouseId = department.WarehouseId;
            order.DepartmentId = department.Id;
            TransactionDocument.AddSingletonTransaction(template.Id, template, GetTicketAccounts());

            if (taxTemplates != null)
            {
                foreach (var taxTemplate in taxTemplates)
                {
                    TransactionDocument.AddSingletonTransaction(taxTemplate.AccountTransactionType.Id,
                                               taxTemplate.AccountTransactionType,
                                               GetTicketAccounts());
                }
            }

            order.UpdateProductTimer(timer);
            Orders.Add(order);
            return order;
        }