Esempio n. 1
0
        private KitchenOrderModel GetKitchenTableModel(Int32 tableId)
        {
            KitchenOrderModel model = new KitchenOrderModel();

            Services.Item   item, itemMenu;
            List <LineItem> subItems;
            CheckPrint      orderModel;

            try {
                model.Table      = _orderService.GetTable(tableId);
                model.TableOrder = _orderService.GetTableOrder(tableId);
                model.Table.Name = model.Table.Name;

                if (model.TableOrder != null && model.TableOrder.Checks != null)
                {
                    model.Checks = new List <CheckPrint>();
                    IEnumerable <Services.Check> checks = model.TableOrder.Checks.Where(m => m.Status == (Int32)CommonUnit.CheckStatus.Ordered);
                    foreach (Services.Check checkItem in checks)
                    {
                        orderModel       = new CheckPrint();
                        orderModel.Check = checkItem;
                        orderModel.Items = new List <LineItem>();

                        // If no printers - webSocket not running, or no connection to webSocket
                        if (SessionData.printers != null)
                        {
                            orderModel.PrinterPOSWidth = SessionData.printerPOSWidth;
                        }

                        List <Services.ChecksMenu> menus = _orderService.GetMenuItems(checkItem.id);
                        List <ChecksMenuProduct>   products;

                        foreach (Services.ChecksMenu menuItem in menus)
                        {
                            itemMenu = _itemService.GetItem(menuItem.MenuId);
                            products = _orderService.GetProducts(menuItem.id);
                            subItems = new List <LineItem>();
                            if (products.Any())
                            {
                                foreach (Services.ChecksMenuProduct productItem in products)
                                {
                                    foreach (Services.ChecksMenuProductItem associatedItem in productItem.ChecksMenuProductItems)
                                    {
                                        item = _itemService.GetItemProductAssosiationsById(associatedItem.ItemId);
                                        if (item != null)
                                        {
                                            subItems.Add(new LineItem()
                                            {
                                                Description = item.Name
                                            });
                                        }
                                    }
                                }
                            }
                            orderModel.Items.Add(new LineItem()
                            {
                                Description = itemMenu.Name, id = itemMenu.id, Alerted = menuItem.Alerts.Any(m => m.CheckMenuId == menuItem.id), CheckMenuId = menuItem.id, SubItems = subItems
                            });
                        }
                        model.Checks.Add(orderModel);
                    }
                }
                return(model);
            }
            catch (Exception ex) {
                base.Log(ex);
            }
            finally {
            }
            return(null);
        }
Esempio n. 2
0
        private CheckPrint GetCheckPrintModel(Int32 checkId, String type, Int32 split, Decimal adjustment)
        {
            Services.Item   item, itemMenu;
            CheckPrint      model;
            Decimal         tax = SessionData.customer.Tax.HasValue ? (Decimal)SessionData.customer.Tax / 100 : 0;
            Decimal         price = 0, menuPrice = 0;
            List <LineItem> subItems;

            try {
                model             = new CheckPrint();
                model.Items       = new List <LineItem>();
                model.Check       = _orderService.GetCheck(checkId);
                model.CreatedDate = model.Check.DateCreated;

                // If no printers - webSocket not running, or no connection to webSocket
                if (SessionData.printers != null)
                {
                    model.PrinterPOSWidth = SessionData.printerPOSWidth;
                }

                List <Services.ChecksMenu> menus = _orderService.GetMenuItems(checkId);
                List <ChecksMenuProduct>   products;
                model.Summary = 0;
                model.Split   = split;
                foreach (Services.ChecksMenu menuItem in menus)
                {
                    itemMenu       = _itemService.GetItem(menuItem.MenuId);
                    menuPrice      = (Decimal)itemMenu.ItemPrices.OrderByDescending(m => m.DateCreated).Take(1).Select(m => m.Price).FirstOrDefault();
                    model.Summary += menuPrice;
                    products       = _orderService.GetProducts(menuItem.id);
                    subItems       = new List <LineItem>();
                    foreach (Services.ChecksMenuProduct productItem in products)
                    {
                        foreach (Services.ChecksMenuProductItem associatedItem in productItem.ChecksMenuProductItems)
                        {
                            item = _itemService.GetItemProductAssosiationsById(associatedItem.ItemId);
                            if (item != null)
                            {
                                price          = (Decimal)item.ItemPrices.OrderByDescending(m => m.DateCreated).Take(1).Select(m => m.Price).FirstOrDefault();
                                model.Summary += price;
                                subItems.Add(new LineItem()
                                {
                                    Description = item.Name, Price = price, id = item.id
                                });
                            }
                        }
                    }
                    model.Items.Add(new LineItem()
                    {
                        Description = itemMenu.Name, Price = menuPrice, id = itemMenu.id, SubItems = subItems
                    });
                }

                model.TaxPercent = 0;
                if (EnumHelper <CommonUnit.CheckType> .Parse(type) == CommonUnit.CheckType.Guest)
                {
                    model.TaxPercent = tax;
                }
                model.Tax = Math.Round(model.Summary * model.TaxPercent, 2);

                model.AdjustmentPercent = adjustment / 100;
                model.Adjustment        = Math.Round(model.Summary * model.AdjustmentPercent, 2);
                model.Subtotal          = model.Summary + model.Adjustment;
                model.Total             = Math.Round(model.Summary + model.Tax + model.Adjustment, 2);
                model.SplitValues       = Utility.SplitAmount(model.Total, model.Split);
            }
            catch (Exception ex) {
                base.Log(ex);
                return(null);
            }
            finally {
            }
            return(model);
        }