Ejemplo n.º 1
0
        public Order AddOrder(Ticket ticket, int menuItemId, decimal quantity, string portionName)
        {
            if (ticket.IsLocked && !_userService.IsUserPermittedFor(PermissionNames.AddItemsToLockedTickets))
            {
                return(null);
            }
            if (!ticket.CanSubmit)
            {
                return(null);
            }
            var menuItem = _cacheService.GetMenuItem(x => x.Id == menuItemId);
            var portion  = _cacheService.GetMenuItemPortion(menuItemId, portionName);

            if (portion == null)
            {
                return(null);
            }
            var priceTag     = _applicationState.CurrentDepartment.PriceTag;
            var productTimer = _applicationState.GetProductTimer(menuItemId);

            var order = ticket.AddOrder(
                _applicationState.CurrentTicketType.SaleTransactionType,
                _applicationState.CurrentDepartment.Model,
                _applicationState.CurrentLoggedInUser.Name, menuItem,
                _applicationState.GetTaxTemplates(menuItem.Id).ToList(), portion, priceTag, productTimer);

            order.Quantity = quantity > 9 ? decimal.Round(quantity / portion.Multiplier, 3, MidpointRounding.AwayFromZero) : quantity;
            RecalculateTicket(ticket);
            _applicationState.NotifyEvent(RuleEventNames.OrderAdded, new { Ticket = ticket, Order = order, MenuItemName = order.MenuItemName, MenuItemTag = menuItem.Tag, MenuItemGroupCode = menuItem.GroupCode });
            return(order);
        }