Ejemplo n.º 1
0
 private IEnumerable<Order> GetOrders(PrintJob printJob, Ticket ticket, Func<Order, bool> orderSelector)
 {
     if (printJob.ExcludeTax)
         ticket.TaxIncluded = false;
     IEnumerable<Order> ti;
     switch (printJob.WhatToPrint)
     {
         case (int)WhatToPrintTypes.LastLinesByPrinterLineCount:
             ti = GetLastOrders(ticket, printJob, orderSelector);
             break;
         case (int)WhatToPrintTypes.LastPaidOrders:
             ti = GetLastPaidOrders(ticket);
             break;
         case (int)WhatToPrintTypes.OrdersByQuanity:
             ti = SeparateOrders(ticket, orderSelector).OrderBy(x => x.MenuItemName);
             break;
         case (int)WhatToPrintTypes.SeparatedByQuantity:
             ti = SeparateOrders(ticket, orderSelector).OrderBy(x => x.MenuItemName);
             break;
         default:
             ti = ticket.Orders.Where(orderSelector).OrderBy(x => x.Id).ToList();
             break;
     }
     return ti;
 }
Ejemplo n.º 2
0
 private void InternalPrint(Ticket ticket, PrintJob printJob, Func<Order, bool> orderSelector)
 {
     var tasks = _ticketPrintTaskBuilder.GetPrintTasksForTicket(ticket, printJob, orderSelector);
     foreach (var ticketPrintTask in tasks.Where(x => x != null && x.Printer != null && x.Lines != null))
     {
         PrintJobFactory.CreatePrintJob(ticketPrintTask.Printer, _printerService).DoPrint(ticketPrintTask.Lines);
     }
 }
Ejemplo n.º 3
0
 public void ExecutePrintJob(PrintJob printJob)
 {
     if (printJob.PrinterMaps.Count > 0)
     {
         var printerMap = printJob.PrinterMaps[0];
         var printerTemplate = PrinterTemplates.Single(x => x.Id == printerMap.PrinterTemplateId);
         var content = printerTemplate.Template.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
         PrintJobFactory.CreatePrintJob(PrinterById(printerMap.PrinterId)).DoPrint(content);
     }
 }
Ejemplo n.º 4
0
        public static void PrintOrders(PrintJob printJob, Ticket ticket)
        {
            if (printJob.ExcludeVat)
            {
                ticket = ObjectCloner.Clone(ticket);
                ticket.TicketItems.ToList().ForEach(x => x.VatIncluded = false);
            }

            IEnumerable<TicketItem> ti;
            switch (printJob.WhatToPrint)
            {
                case (int)WhatToPrintTypes.NewLines:
                    ti = ticket.GetUnlockedLines();
                    break;
                case (int)WhatToPrintTypes.GroupedByBarcode:
                    ti = GroupLinesByValue(ticket, x => x.Barcode ?? "", "1", true);
                    break;
                case (int)WhatToPrintTypes.GroupedByGroupCode:
                    ti = GroupLinesByValue(ticket, x => x.GroupCode ?? "", Resources.UndefinedWithBrackets);
                    break;
                case (int)WhatToPrintTypes.GroupedByTag:
                    ti = GroupLinesByValue(ticket, x => x.Tag ?? "", Resources.UndefinedWithBrackets);
                    break;
                case (int)WhatToPrintTypes.LastLinesByPrinterLineCount:
                    ti = GetLastItems(ticket, printJob);
                    break;
                case (int)WhatToPrintTypes.LastPaidItems:
                    ti = GetLastPaidItems(ticket).ToList();
                    ticket = ObjectCloner.Clone(ticket);
                    ticket.TicketItems.Clear();
                    ticket.PaidItems.Clear();
                    ticket.Payments.Clear();
                    ti.ToList().ForEach(x => ticket.TicketItems.Add(x));
                    break;
                default:
                    ti = ticket.TicketItems.OrderBy(x => x.Id).ToList();
                    break;
            }

            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                new Action(
                    delegate
                    {
                        try
                        {
                            InternalPrintOrders(printJob, ticket, ti);
                        }
                        catch (Exception e)
                        {
                            AppServices.LogError(e, string.Format(Resources.PrintingErrorMessage_f, e.Message));
                        }
                    }));
        }
Ejemplo n.º 5
0
 private static bool ShouldAutoPrint(Ticket ticket, PrintJob customPrinter)
 {
     if (customPrinter.WhenToPrint == (int)WhenToPrintTypes.Manual) return false;
     if (customPrinter.WhenToPrint == (int)WhenToPrintTypes.Paid)
     {
         if (ticket.DidPrintJobExecuted(customPrinter.Id)) return false;
         if (!ticket.IsPaid) return false;
         if (!customPrinter.AutoPrintIfCash && !customPrinter.AutoPrintIfCreditCard && !customPrinter.AutoPrintIfTicket) return false;
         if (customPrinter.AutoPrintIfCash && ticket.Payments.Count(x => x.PaymentType == (int)PaymentType.Cash) > 0) return true;
         if (customPrinter.AutoPrintIfCreditCard && ticket.Payments.Count(x => x.PaymentType == (int)PaymentType.CreditCard) > 0) return true;
         if (customPrinter.AutoPrintIfTicket && ticket.Payments.Count(x => x.PaymentType == (int)PaymentType.Ticket) > 0) return true;
     }
     if (customPrinter.WhenToPrint == (int)WhenToPrintTypes.NewLinesAdded && ticket.GetUnlockedLines().Count() > 0) return true;
     return false;
 }
Ejemplo n.º 6
0
 public void ExecutePrintJob(PrintJob printJob)
 {
     Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
         new Action(
             delegate
             {
                 try
                 {
                     LocalSettings.UpdateThreadLanguage();
                     InternalExecutePrintJob(printJob);
                 }
                 catch (Exception e)
                 {
                     _logService.LogError(e, Resources.PrintErrorMessage + e.Message);
                 }
             }));
 }
Ejemplo n.º 7
0
        public void PrintOrders(PrintJob printJob, Ticket ticket, Func<Order, bool> orderSelector)
        {
            ticket = ObjectCloner.Clone2(ticket);
            if (printJob.ExcludeTax)
                ticket.TaxIncluded = false;
            IEnumerable<Order> ti;
            switch (printJob.WhatToPrint)
            {
                case (int)WhatToPrintTypes.NewLines:
                    ti = ticket.GetUnlockedOrders();
                    break;
                case (int)WhatToPrintTypes.GroupedByBarcode:
                    ti = GroupLinesByValue(ticket, x => x.Barcode ?? "", "1", true);
                    break;
                case (int)WhatToPrintTypes.GroupedByGroupCode:
                    ti = GroupLinesByValue(ticket, x => x.GroupCode ?? "", Resources.UndefinedWithBrackets);
                    break;
                case (int)WhatToPrintTypes.GroupedByTag:
                    ti = GroupLinesByValue(ticket, x => x.Tag ?? "", Resources.UndefinedWithBrackets);
                    break;
                case (int)WhatToPrintTypes.LastLinesByPrinterLineCount:
                    ti = GetLastOrders(ticket, printJob);
                    break;
                case (int)WhatToPrintTypes.LastPaidOrders:
                    ti = GetLastPaidOrders(ticket);
                    break;
                default:
                    ti = ticket.Orders.Where(orderSelector).OrderBy(x => x.Id).ToList();
                    break;
            }

            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                new Action(
                    delegate
                    {
                        try
                        {
                            InternalPrintOrders(printJob, ticket, ti);
                        }
                        catch (Exception e)
                        {
                            _logService.LogError(e, Resources.PrintErrorMessage + e.Message);
                        }
                    }));
        }
Ejemplo n.º 8
0
        public static void ExecutePrintJob(PrintJob printJob)
        {
            if (printJob.PrinterMaps.Count > 0)
            {
                var printerMap = printJob.PrinterMaps[0];
                var content = printerMap
                    .PrinterTemplate
                    .HeaderTemplate
                    .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

                if (!string.IsNullOrEmpty(printerMap.Printer.ShareName))
                {
                    try
                    {
                        PrintJobFactory.CreatePrintJob(printerMap.Printer).DoPrint(content);
                    }
                    catch (Exception e)
                    {
                        AppServices.LogError(e, string.Format(Resources.PrintingErrorMessage_f, e.Message));
                    }
                }
            }
        }
Ejemplo n.º 9
0
 public void PrintTicket(Ticket ticket, PrintJob customPrinter, Func<Order, bool> orderSelector)
 {
     Debug.Assert(!string.IsNullOrEmpty(ticket.TicketNumber));
     PrintOrders(customPrinter, ticket, orderSelector);
 }
Ejemplo n.º 10
0
        private void OnPrintJobExecute(PrintJob printJob)
        {
            var message = SelectedTicket.GetPrintError();

            if (!string.IsNullOrEmpty(message))
            {
                MainWindowViewModel.ShowFeedback(message);
                return;
            }

            if (SelectedTicket.Id == 0)
            {
                var result = DataContext.CloseSelectedTicket();
                DataContext.OpenTicket(result.TicketId);
            }
            AppServices.PrintService.ManualPrintTicket(SelectedTicket.Model, printJob);
            InvokeCloseTicketRequested(EventArgs.Empty);
        }
Ejemplo n.º 11
0
 public void ExecutePrintJob(PrintJob printJob)
 {
     TicketPrinter.ExecutePrintJob(printJob);
 }
Ejemplo n.º 12
0
 public static void ManualPrintTicket(Ticket ticket, PrintJob customPrinter)
 {
     if (customPrinter.LocksTicket) ticket.RequestLock();
     ticket.AddPrintJob(customPrinter.Id);
     PrintOrders(customPrinter, ticket);
 }
Ejemplo n.º 13
0
 public void ManualPrintTicket(Ticket ticket, PrintJob printer)
 {
     AppServices.MainDataContext.UpdateTicketNumber(ticket);
     if (printer != null) TicketPrinter.ManualPrintTicket(ticket, printer);
 }
Ejemplo n.º 14
0
 public PrintJobButton(PrintJob model, Ticket ticket)
 {
     Model = model;
     Ticket = ticket;
 }
Ejemplo n.º 15
0
        private void OnPrintJobExecute(PrintJob printJob)
        {
            var message = SelectedTicket.GetPrintError();

            if (!string.IsNullOrEmpty(message))
            {
                InteractionService.UserIntraction.GiveFeedback(message);
                return;
            }

            SaveTicketIfNew();

            AppServices.PrintService.ManualPrintTicket(SelectedTicket.Model, printJob);

            if (printJob.WhenToPrint == (int)WhenToPrintTypes.Paid && !SelectedTicket.IsPaid)
                MakePaymentCommand.Execute("");
            else if (printJob.CloseTicket)
                CloseTicket();
        }
Ejemplo n.º 16
0
 private IEnumerable<Order> GetLastOrders(Ticket ticket, PrintJob printJob)
 {
     if (ticket.Orders.Count > 1)
     {
         var printMap = printJob.PrinterMaps.Count == 1 ? printJob.PrinterMaps[0]
             : GetPrinterMapForItem(printJob.PrinterMaps, ticket.Orders.Last().MenuItemId);
         var result = ticket.Orders.OrderByDescending(x => x.CreatedDateTime).ToList();
         var printer = PrinterById(printMap.PrinterId);
         if (printer.PageHeight > 0)
             result = result.Take(printer.PageHeight).ToList();
         return result;
     }
     return ticket.Orders.ToList();
 }
Ejemplo n.º 17
0
 private bool CanManualPrint(PrintJob arg)
 {
     return arg != null && SelectedTicket != null && (!SelectedTicket.Locked || SelectedTicket.GetPrintCount(arg.Id) == 0);
 }
Ejemplo n.º 18
0
        public void PrintTicket(Ticket ticket, PrintJob printJob, Func<Order, bool> orderSelector)
        {
            ticket = ObjectCloner.Clone2(ticket);

            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                    new Action(
                        delegate
                        {
                            try
                            {
                                LocalSettings.UpdateThreadLanguage();
                                var tasks = _ticketPrintTaskBuilder.GetPrintTasksForTicket(ticket, printJob, orderSelector);
                                foreach (var ticketPrintTask in tasks.Where(x => x != null && x.Printer != null && x.Lines != null))
                                {
                                    Print(ticketPrintTask.Printer, ticketPrintTask.Lines);
                                }
                            }
                            catch (Exception e)
                            {
                                _logService.LogError(e, Resources.PrintErrorMessage + e.Message);
                            }
                        }));
        }
Ejemplo n.º 19
0
 public static PrintJobExecutor For(PrintJob printJob)
 {
     return new PrintJobExecutor(printJob);
 }
Ejemplo n.º 20
0
 private PrintJobExecutor(PrintJob printJob)
 {
     _printJob = printJob;
 }
Ejemplo n.º 21
0
        private void OnPrintJobExecute(PrintJob printJob)
        {
            var message = SelectedTicket.GetPrintError();

            if (!string.IsNullOrEmpty(message))
            {
                InteractionService.UserIntraction.GiveFeedback(message);
                return;
            }

            SaveTicketIfNew();

            _ticketService.UpdateTicketNumber(SelectedTicket.Model, _applicationState.CurrentDepartment.TicketTemplate.TicketNumerator);
            _printerService.ManualPrintTicket(SelectedTicket.Model, printJob);

            if (printJob.WhenToPrint == (int)WhenToPrintTypes.Paid && !SelectedTicket.IsPaid)
                MakePaymentCommand.Execute("");
            else CloseTicket();
        }
Ejemplo n.º 22
0
 private void OnManualPrint(PrintJob obj)
 {
     _ticketService.UpdateTicketNumber(SelectedTicket, _applicationState.CurrentDepartment.TicketTemplate.TicketNumerator);
     _printerService.ManualPrintTicket(SelectedTicket, obj);
 }
Ejemplo n.º 23
0
        private void InternalPrintOrders(PrintJob printJob, Ticket ticket, IEnumerable<Order> orders)
        {
            if (printJob.PrinterMaps.Count == 1
                && printJob.PrinterMaps[0].MenuItemId == 0
                && printJob.PrinterMaps[0].MenuItemGroupCode == null)
            {
                PrintOrderLines(ticket, orders, printJob.PrinterMaps[0]);
                return;
            }

            var ordersCache = new Dictionary<PrinterMap, IList<Order>>();

            foreach (var item in orders)
            {
                var p = GetPrinterMapForItem(printJob.PrinterMaps, item.MenuItemId);
                if (p != null)
                {
                    var lmap = p;
                    var pmap = ordersCache.SingleOrDefault(
                            x => x.Key.PrinterId == lmap.PrinterId && x.Key.PrinterTemplateId == lmap.PrinterTemplateId).Key;
                    if (pmap == null)
                        ordersCache.Add(p, new List<Order>());
                    else p = pmap;
                    ordersCache[p].Add(item);
                }
            }

            foreach (var order in ordersCache)
            {
                PrintOrderLines(ticket, order.Value, order.Key);
            }
        }
Ejemplo n.º 24
0
        private IEnumerable<TicketPrintTask> GetPrintTasks(PrintJob printJob, Ticket ticket, IEnumerable<Order> orders)
        {
            var result = new List<TicketPrintTask>();

            if (printJob.PrinterMaps.Count == 1
                && printJob.WhatToPrint != 3
                && printJob.WhatToPrint != 4
                && printJob.PrinterMaps[0].MenuItemId == 0
                && printJob.PrinterMaps[0].MenuItemGroupCode == null)
            {
                result.Add(GetPrintTask(ticket, orders, printJob.PrinterMaps[0]));
                return result;
            }

            var ordersCache = new Dictionary<PrinterMap, IList<Order>>();

            foreach (var item in orders)
            {
                var p = GetPrinterMapForItem(printJob.PrinterMaps, item.MenuItemId);
                if (p != null)
                {
                    var lmap = p;
                    var pmap = ordersCache.SingleOrDefault(
                            x => x.Key.PrinterId == lmap.PrinterId && x.Key.PrinterTemplateId == lmap.PrinterTemplateId).Key;
                    if (pmap == null)
                        ordersCache.Add(p, new List<Order>());
                    else p = pmap;
                    ordersCache[p].Add(item);
                }
            }
            switch (printJob.WhatToPrintType)
            {
                case WhatToPrintTypes.SeparatedByQuantity: result.AddRange(GenerateSeparatedTasks(ticket, ordersCache));
                    break;
                default:
                    result.AddRange(ordersCache.Select(order => GetPrintTask(ticket, order.Value, order.Key)));
                    break;
            }
            return result;
        }
Ejemplo n.º 25
0
 private void OnManualPrint(PrintJob obj)
 {
     AppServices.PrintService.ManualPrintTicket(SelectedTicket.Model, obj);
     SelectedTicket.PrintJobButtons.Where(x => x.Model.UseFromPaymentScreen).ToList().ForEach(
         x => CommandButtons.First(u => u.Parameter == x.Model).Caption = x.Caption);
 }
Ejemplo n.º 26
0
 public IEnumerable<TicketPrintTask> GetPrintTasksForTicket(Ticket ticket, PrintJob printJob,
                                                            Func<Order, bool> orderSelector)
 {
     var orders = GetOrders(printJob, ticket, orderSelector);
     return GetPrintTasks(printJob, ticket, orders);
 }
Ejemplo n.º 27
0
        public void CreateData()
        {
            CreateDefaultCurrenciesIfNeeded();

            if (!ShouldCreateData()) return;

            var screen = new ScreenMenu();
            _workspace.Add(screen);

            var ticketNumerator = new Numerator { Name = Resources.TicketNumerator };
            _workspace.Add(ticketNumerator);

            var orderNumerator = new Numerator { Name = Resources.OrderNumerator };
            _workspace.Add(orderNumerator);

            _workspace.CommitChanges();

            var department = new Department
            {
                Name = Resources.Restaurant,
                ScreenMenuId = screen.Id,
                TicketNumerator = ticketNumerator,
                OrderNumerator = orderNumerator,
                IsAlaCarte = true
            };

            _workspace.Add(department);

            var role = new UserRole("Admin") { IsAdmin = true, DepartmentId = 1 };
            _workspace.Add(role);

            var u = new User("Administrator", "1234") { UserRole = role };
            _workspace.Add(u);

            var ticketTemplate = new PrinterTemplate();
            ticketTemplate.Name = Resources.TicketTemplate;
            ticketTemplate.HeaderTemplate = Resources.TicketTemplateHeaderValue;
            ticketTemplate.LineTemplate = Resources.TicketTempleteLineTemplateValue;
            ticketTemplate.GiftLineTemplate = Resources.TicketTemplateGiftedLineTemplateValue;
            ticketTemplate.FooterTemplate = Resources.TicketTemplateFooterValue;

            var kitchenTemplate = new PrinterTemplate();
            kitchenTemplate.Name = Resources.KitchenOrderTemplate;
            kitchenTemplate.HeaderTemplate = Resources.KitchenTemplateHeaderValue;

            kitchenTemplate.LineTemplate = Resources.KitchenTemplateLineTemplateValue;
            kitchenTemplate.GiftLineTemplate = Resources.KitchenTemplateLineTemplateValue;
            kitchenTemplate.VoidedLineTemplate = Resources.KitchenTemplateVoidedLineTemplateValue;

            kitchenTemplate.FooterTemplate = "<F>-";

            var invoiceTemplate = new PrinterTemplate();
            invoiceTemplate.Name = Resources.InvoicePrinterTemplate;
            invoiceTemplate.HeaderTemplate = Resources.InvoiceTemplateHeaderValue;
            invoiceTemplate.LineTemplate = Resources.InvoiceTemplateLineTemplateValue;
            invoiceTemplate.VoidedLineTemplate = "";
            invoiceTemplate.FooterTemplate = "<F>-";

            _workspace.Add(ticketTemplate);
            _workspace.Add(kitchenTemplate);
            _workspace.Add(invoiceTemplate);

            var printer1 = new Printer { Name = Resources.TicketPrinter };
            var printer2 = new Printer { Name = Resources.KitchenPrinter };
            var printer3 = new Printer { Name = Resources.InvoicePrinter };

            _workspace.Add(printer1);
            _workspace.Add(printer2);
            _workspace.Add(printer3);

            var t = new Terminal
            {
                IsDefault = true,
                Name = Resources.Server,
                SlipReportPrinter = printer1,
            };

            var pm1 = new PrinterMap { Printer = printer1, PrinterTemplate = ticketTemplate };
            _workspace.Add(pm1);

            var pj1 = new PrintJob
            {
                Name = Resources.PrintBill,
                ButtonText = Resources.PrintBill,
                LocksTicket = true,
                Order = 0,
                UseFromPaymentScreen = true,
                UseFromTerminal = true,
                UseFromPos = true,
                WhatToPrint = (int)WhatToPrintTypes.Everything,
                WhenToPrint = (int)WhenToPrintTypes.Manual
            };
            pj1.PrinterMaps.Add(pm1);


            _workspace.Add(pj1);

            var pm2 = new PrinterMap { Printer = printer2, PrinterTemplate = kitchenTemplate };
            var pj2 = new PrintJob
            {
                Name = Resources.PrintOrdersToKitchenPrinter,
                ButtonText = "",
                Order = 1,
                WhatToPrint = (int)WhatToPrintTypes.NewLines,
                WhenToPrint = (int)WhenToPrintTypes.NewLinesAdded
            };
            pj2.PrinterMaps.Add(pm2);

            _workspace.Add(pj2);

            t.PrintJobs.Add(pj1);
            t.PrintJobs.Add(pj2);
            _workspace.Add(t);

            ImportMenus(screen);
            ImportTables(department);

            _workspace.CommitChanges();
            _workspace.Dispose();
        }
Ejemplo n.º 28
0
 private static IEnumerable<TicketItem> GetLastItems(Ticket ticket, PrintJob printJob)
 {
     if (ticket.TicketItems.Count > 1)
     {
         var printer = printJob.PrinterMaps.Count == 1 ? printJob.PrinterMaps[0]
             : GetPrinterMapForItem(printJob.PrinterMaps, ticket, ticket.TicketItems.Last());
         var result = ticket.TicketItems.OrderByDescending(x => x.CreatedDateTime).ToList();
         if (printer.Printer.PageHeight > 0)
             result = result.Take(printer.Printer.PageHeight).ToList();
         return result;
     }
     return ticket.TicketItems.ToList();
 }
Ejemplo n.º 29
0
 private bool CanExecutePrintJob(PrintJob arg)
 {
     return arg != null && SelectedTicket != null && (!SelectedTicket.IsLocked || SelectedTicket.Model.GetPrintCount(arg.Id) == 0);
 }
Ejemplo n.º 30
0
        private static void InternalPrintOrders(PrintJob printJob, Ticket ticket, IEnumerable<TicketItem> ticketItems)
        {
            if (printJob.PrinterMaps.Count == 1
                && printJob.PrinterMaps[0].TicketTag == null
                && printJob.PrinterMaps[0].MenuItem == null
                && printJob.PrinterMaps[0].MenuItemGroupCode == null
                && printJob.PrinterMaps[0].Department == null)
            {
                PrintOrderLines(ticket, ticketItems, printJob.PrinterMaps[0]);
                return;
            }

            var ordersCache = new Dictionary<PrinterMap, IList<TicketItem>>();

            foreach (var item in ticketItems)
            {
                var p = GetPrinterMapForItem(printJob.PrinterMaps, ticket, item);
                if (p != null)
                {
                    var lmap = p;
                    var pmap = ordersCache.SingleOrDefault(
                            x => x.Key.Printer == lmap.Printer && x.Key.PrinterTemplate == lmap.PrinterTemplate).Key;
                    if (pmap == null)
                        ordersCache.Add(p, new List<TicketItem>());
                    else p = pmap;
                    ordersCache[p].Add(item);
                }
            }

            foreach (var order in ordersCache)
            {
                PrintOrderLines(ticket, order.Value, order.Key);
            }
        }