예제 #1
0
 public static string[] GetFormattedTicket(Ticket ticket, IEnumerable<Order> lines, PrinterTemplate printerTemplate)
 {
     var orders = printerTemplate.MergeLines ? MergeLines(lines) : lines;
     ticket.Orders.Clear();
     orders.ToList().ForEach(ticket.Orders.Add);
     var content = TicketValueChanger.GetValue(printerTemplate, ticket);
     content = UpdateExpressions(content);
     return content.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
 }
예제 #2
0
        public override void Up()
        {
            var dc = ApplicationContext as DbContext;

            Create.Column("HideZeroBalanceAccounts").OnTable("AccountScreenValues").AsBoolean().WithDefaultValue(false);
            Create.Column("DisplayAsTree").OnTable("AccountScreens").AsBoolean().WithDefaultValue(false);
            
            Create.Column("ReportPrinterId").OnTable("Terminals").AsInt32().WithDefaultValue(0);

            if (dc.Database.Connection.ConnectionString.EndsWith(".sdf"))
            {
                Delete.ForeignKey("FK_dbo.Terminals_dbo.Printers_ReportPrinter_Id").OnTable("Terminals");
                Delete.Index("IX_ReportPrinter_Id").OnTable("Terminals");
            }
            else
                Delete.ForeignKey("Terminal_ReportPrinter").OnTable("Terminals");

            Execute.Sql("Update Terminals set ReportPrinterId = ReportPrinter_Id");
            Delete.Column("ReportPrinter_Id").FromTable("Terminals");
            Create.Column("TransactionPrinterId").OnTable("Terminals").AsInt32().WithDefaultValue(0);
            Execute.Sql("Update Terminals set TransactionPrinterId = ReportPrinterId");
            Create.Column("DocumentTypeId").OnTable("AccountTransactionDocuments").AsInt32().WithDefaultValue(0);
            Create.Column("PrinterTemplateId").OnTable("AccountTransactionDocumentTypes").AsInt32().WithDefaultValue(0);



            if (dc != null)
            {
                if (dc.Set<PrinterTemplate>().Any(x => x.Name == Resources.CustomerReceiptTemplate)) return;

                var customerReceiptTemplate = new PrinterTemplate
                                                  {
                                                      Name = Resources.CustomerReceiptTemplate,
                                                      Template =
                                                          DataCreationService
                                                          .GetDefaultCustomerReceiptTemplate()
                                                  };
                dc.Set<PrinterTemplate>().Add(customerReceiptTemplate);
                dc.SaveChanges();

                var dt1Caption = string.Format(Resources.Customer_f, Resources.Cash);
                var dt2Caption = string.Format(Resources.Customer_f, Resources.CreditCard);

                Execute.Sql(string.Format("Update AccountTransactionDocumentTypes set PrinterTemplateId = {0} where Name = '{1}'", customerReceiptTemplate.Id, dt1Caption));
                Execute.Sql(string.Format("Update AccountTransactionDocumentTypes set PrinterTemplateId = {0} where Name = '{1}'", customerReceiptTemplate.Id, dt2Caption));
            }
        }
예제 #3
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();
        }
 public string[] GetFormattedDocument(AccountTransactionDocument document, PrinterTemplate printerTemplate)
 {
     var content = _valueChanger.GetValue(printerTemplate, document);
     content = UpdateExpressions(content);
     return content.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
 }
 public string[] GetFormattedDocument(object item, PrinterTemplate printerTemplate)
 {
     return GetFormattedDocument(item as AccountTransactionDocument, printerTemplate);
 }
예제 #6
0
 public void PrintObject(object item, Printer printer, PrinterTemplate printerTemplate)
 {
     var formatter = DocumentFormatters.FirstOrDefault(x => x.ObjectType == item.GetType());
     if (formatter != null)
     {
         var lines = formatter.GetFormattedDocument(item, printerTemplate);
         if (lines != null)
         {
             Print(printer, lines);
         }
     }
 }
예제 #7
0
        public void CanFormatTicket()
        {
            WorkspaceFactory.SetDefaultConnectionString("c:\\testData.txt");
            IWorkspace workspace = WorkspaceFactory.Create();
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

            var user = new User("Emre", "1");
            workspace.Add(user);

            var menuItem1 = MenuItem.Create();
            menuItem1.Name = "Kurufasülye";
            menuItem1.Portions[0].Price.Amount = 5;

            var menuItem2 = MenuItem.Create();
            menuItem2.Name = "Pilav";
            menuItem2.Portions[0].Price.Amount = 3;

            menuItem2.AddPortion("Az", 1, "TL");

            workspace.Add(menuItem1);
            workspace.Add(menuItem2);

            var d = new Department();
            var ticket = Ticket.Create(d);

            ticket.AddTicketItem(user.Id, menuItem1, "Normal");
            ticket.AddTicketItem(user.Id, menuItem2, "Normal");
            ticket.Date = new DateTime(2010, 1, 1);
            ticket.AddTicketDiscount(DiscountType.Amount, 1, user.Id);

            var template = new PrinterTemplate();

            template.HeaderTemplate = @"SAMBA
Adisyon Tarihi:{ADİSYON TARİH}
[Müşteri Adı:
{MÜŞTERİ ADI}]";
            template.LineTemplate = @"{MİKTAR} {ÜRÜN} {FİYAT}";
            template.FooterTemplate = @"{VARSA İSKONTO}
[<C>İkram: {TOPLAM İKRAM}, teşekkürler]
[Toplam: {TOPLAM BAKİYE}]";

            var formatResult = TicketFormatter.GetFormattedTicket(ticket, ticket.GetUnlockedLines(), template);

            var expectedResult = @"SAMBA
Adisyon Tarihi:01.01.2010
1 Kurufasülye 5,00
1 Pilav 3,00
Belge TOPLAMI:|8,00
<J>İskonto:|1,00
Toplam: 7,00";

            var result = string.Join("\r\n", formatResult);

            Assert.IsTrue(result == expectedResult);

            template.MergeLines = true;
            formatResult = TicketFormatter.GetFormattedTicket(ticket, ticket.GetUnlockedLines(), template);
            result = string.Join("\r\n", formatResult);
            Assert.AreEqual(expectedResult, result);

            var l1 = ticket.AddTicketItem(user.Id, menuItem1, "Normal");
            l1.Quantity = 5;
            var l2 = ticket.AddTicketItem(user.Id, menuItem2, "Az");
            formatResult = TicketFormatter.GetFormattedTicket(ticket, ticket.GetUnlockedLines(), template);
            result = string.Join("\r\n", formatResult);
            expectedResult = @"SAMBA
Adisyon Tarihi:01.01.2010
1 Pilav 3,00
6 Kurufasülye 5,00
1 Pilav.Az 1,00
Belge TOPLAMI:|34,00
<J>İskonto:|1,00
Toplam: 33,00";

            Assert.AreEqual(expectedResult, result);

            var c = new Customer { Name = "Emre EREN" };
            workspace.Add(c);

            ticket.CustomerId = c.Id;
            ticket.CustomerName = c.Name;

            ticket.AddTicketDiscount(DiscountType.Amount, 0, user.Id);
            formatResult = TicketFormatter.GetFormattedTicket(ticket, ticket.GetUnlockedLines(), template);

            expectedResult = @"SAMBA
Adisyon Tarihi:01.01.2010
Müşteri Adı:
Emre EREN
1 Pilav 3,00
6 Kurufasülye 5,00
1 Pilav.Az 1,00
Toplam: 34,00";

            result = string.Join("\r\n", formatResult);
            Assert.IsTrue(result == expectedResult);

            l2.Gifted = true;
            template.GiftLineTemplate = "{MİKTAR} {ÜRÜN} İKRAM";

            expectedResult = @"SAMBA
Adisyon Tarihi:01.01.2010
Müşteri Adı:
Emre EREN
1 Pilav 3,00
6 Kurufasülye 5,00
1 Pilav.Az İKRAM
<C>İkram: 1,00, teşekkürler
Toplam: 33,00";

            formatResult = TicketFormatter.GetFormattedTicket(ticket, ticket.GetUnlockedLines(), template);
            result = string.Join("\r\n", formatResult);
            Assert.IsTrue(result == expectedResult);
        }
예제 #8
0
 private static bool ShouldSkipPrint(Printer printer, IEnumerable<Order> lns, PrinterTemplate prinerTemplate)
 {
     if (printer == null || string.IsNullOrEmpty(printer.ShareName) || prinerTemplate == null) return true;
     if (printer.IsCustomPrinter) return false;
     return (!lns.Any() && prinerTemplate.Template.Contains("{ORDERS}"));
 }
예제 #9
0
 public string[] GetFormattedDocument(object item, PrinterTemplate printerTemplate)
 {
     return GetFormattedDocument(item as Entity, printerTemplate);
 }
예제 #10
0
 private static string FormatLines(PrinterTemplate template, Order order)
 {
     if (!string.IsNullOrEmpty(template.LineTemplate))
         return template.LineTemplate.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
             .Aggregate("", (current, s) => current + ReplaceLineVars(s, order));
     return "";
 }
예제 #11
0
        public static string[] GetFormattedTicket(Ticket ticket, IEnumerable<Order> lines, PrinterTemplate template)
        {
            _settingReplacer = SettingService.GetSettingReplacer();
            if (template.MergeLines) lines = MergeLines(lines);
            var orderNo = lines.Count() > 0 ? lines.ElementAt(0).OrderNumber : 0;
            var userNo = lines.Count() > 0 ? lines.ElementAt(0).CreatingUserName : "";
            var header = ReplaceDocumentVars(template.HeaderTemplate, ticket, orderNo, userNo);
            var footer = ReplaceDocumentVars(template.FooterTemplate, ticket, orderNo, userNo);
            var lns = lines.SelectMany(x => FormatLines(template, x).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)).ToArray();

            var result = header.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            result.AddRange(lns);
            result.AddRange(footer.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));

            return result.ToArray();
        }
예제 #12
0
        private static IEnumerable<string> GetFormattedLines(IEnumerable<TicketItem> lines, PrinterTemplate template)
        {
            if (!string.IsNullOrEmpty(template.GroupTemplate))
            {
                if (template.GroupTemplate.Contains("{PRODUCT GROUP}"))
                {
                    var groups = lines.GroupBy(GetMenuItemGroup);
                    var result = new List<string>();
                    foreach (var grp in groups)
                    {
                        var grpSep = template.GroupTemplate.Replace("{PRODUCT GROUP}", grp.Key);
                        result.AddRange(grpSep.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
                        result.AddRange(grp.SelectMany(x => FormatLines(template, x).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)));
                    }
                    return result;
                }

                if (template.GroupTemplate.Contains("{PRODUCT TAG}"))
                {
                    var groups = lines.GroupBy(GetMenuItemTag);
                    var result = new List<string>();
                    foreach (var grp in groups)
                    {
                        var grpSep = template.GroupTemplate.Replace("{PRODUCT TAG}", grp.Key);
                        result.AddRange(grpSep.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
                        result.AddRange(grp.SelectMany(x => FormatLines(template, x).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)));
                    }
                    return result;
                }

                if (template.GroupTemplate.Contains("{ITEM TAG}"))
                {
                    var groups = lines.GroupBy(x => (x.Tag ?? "").Split('|')[0]);
                    var result = new List<string>();
                    foreach (var grp in groups)
                    {
                        var grpSep = template.GroupTemplate.Replace("{ITEM TAG}", grp.Key);
                        result.AddRange(grpSep.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
                        result.AddRange(grp.SelectMany(x => FormatLines(template, x).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)));
                    }
                    return result;
                }

                if (template.GroupTemplate.Contains("{ORDER NO}"))
                {
                    var groups = lines.GroupBy(x => x.OrderNumber);
                    var result = new List<string>();
                    foreach (var grp in groups)
                    {
                        var grpSep = template.GroupTemplate.Replace("{ORDER NO}", grp.Key.ToString());
                        result.AddRange(grpSep.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
                        result.AddRange(grp.SelectMany(x => FormatLines(template, x).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)));
                    }
                    return result;
                }
            }
            return lines.SelectMany(x => FormatLines(template, x).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)).ToArray();
        }
예제 #13
0
        private static string FormatLines(PrinterTemplate template, TicketItem ticketItem)
        {
            if (ticketItem.Gifted)
            {
                if (!string.IsNullOrEmpty(template.GiftLineTemplate))
                {
                    return template.GiftLineTemplate.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                        .Aggregate("", (current, s) => current + ReplaceLineVars(s, ticketItem));
                }
                return "";
            }

            if (ticketItem.Voided)
            {
                if (!string.IsNullOrEmpty(template.VoidedLineTemplate))
                {
                    return template.VoidedLineTemplate.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                        .Aggregate("", (current, s) => current + ReplaceLineVars(s, ticketItem));
                }
                return "";
            }

            if (!string.IsNullOrEmpty(template.LineTemplate))
                return template.LineTemplate.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                    .Aggregate("", (current, s) => current + ReplaceLineVars(s, ticketItem));
            return "";
        }
예제 #14
0
        public static string[] GetFormattedTicket(Ticket ticket, IEnumerable<TicketItem> lines, PrinterTemplate template)
        {
            if (template.MergeLines) lines = MergeLines(lines);
            var orderNo = lines.Count() > 0 ? lines.ElementAt(0).OrderNumber : 0;
            var userNo = lines.Count() > 0 ? lines.ElementAt(0).CreatingUserId : 0;
            var departmentNo = lines.Count() > 0 ? lines.ElementAt(0).DepartmentId : ticket.DepartmentId;
            var header = ReplaceDocumentVars(template.HeaderTemplate, ticket, orderNo, userNo, departmentNo);
            var footer = ReplaceDocumentVars(template.FooterTemplate, ticket, orderNo, userNo, departmentNo);
            var lns = GetFormattedLines(lines, template);

            var result = header.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            result.AddRange(lns);
            result.AddRange(footer.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));

            return result.ToArray();
        }