From fe18db26428196d56263ce9a8838960f3070d78e Mon Sep 17 00:00:00 2001 From: EugeneTes Date: Wed, 21 Jan 2026 09:19:12 +0100 Subject: [PATCH] bar receipt --- .../Utils/BarReceipt/BarReceiptConverter.cs | 146 ++++++++++++++++++ .../BarReceipt/BarReceiptConverterAdapter.cs | 22 +++ .../Printers/Utils/BarReceipt/Models.cs | 97 ++++++++++++ .../Printers/Utils/PrintCommand.cs | 2 +- .../Printers/Utils/ReceiptConverterFactory.cs | 3 +- 5 files changed, 268 insertions(+), 2 deletions(-) create mode 100644 Inspectron.Epson/PrintServer/Printers/Utils/BarReceipt/BarReceiptConverter.cs create mode 100644 Inspectron.Epson/PrintServer/Printers/Utils/BarReceipt/BarReceiptConverterAdapter.cs create mode 100644 Inspectron.Epson/PrintServer/Printers/Utils/BarReceipt/Models.cs diff --git a/Inspectron.Epson/PrintServer/Printers/Utils/BarReceipt/BarReceiptConverter.cs b/Inspectron.Epson/PrintServer/Printers/Utils/BarReceipt/BarReceiptConverter.cs new file mode 100644 index 0000000..f78238e --- /dev/null +++ b/Inspectron.Epson/PrintServer/Printers/Utils/BarReceipt/BarReceiptConverter.cs @@ -0,0 +1,146 @@ +using Inspectron.Epson.PrintServer.Printers.Utils.KitchenReceipt; + +namespace Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt; + +public class BarReceiptConverter +{ + private readonly int _lineWidth; + private readonly int _BigLineWidth; + + public BarReceiptConverter(int lineWidth = 42, int bigLineWidth=22) + { + _BigLineWidth = bigLineWidth; + _lineWidth = lineWidth; + } + + public List ConvertToPrintCommands(BarReceipt kitchenReceipt) + { + var commands = new List(); + + // Header - Restaurant name in red + commands.Add(new PrintCommand(Center(kitchenReceipt.Title, true)) { IsRed = true, IsBig = true }); + commands.Add(new PrintCommand(CreateDashedLine())); + commands.Add(new PrintCommand("")); + + // Transaction info + string dateTimeLine = $"{kitchenReceipt.TransactionDateTime:dd-MMM-yy HH:mm} Nr.:{kitchenReceipt.ReceiptNumber}"; + commands.Add(new PrintCommand(Center(dateTimeLine, false))); + + string serverLine = $"{kitchenReceipt.WaiterName}"; + commands.Add(new PrintCommand(Center(serverLine, false))); + + string serverIdLine = $"{kitchenReceipt.WaiterId}"; + commands.Add(new PrintCommand(Center(serverIdLine, false))); + + string tableLine = $"Tisch: {kitchenReceipt.TableNumber}"; + commands.Add(new PrintCommand(Center(tableLine, true), true, true)); + + if (!string.IsNullOrEmpty(kitchenReceipt.SpecialInstruction)) + { + commands.Add(new PrintCommand("")); + commands.Add(new PrintCommand(Center(kitchenReceipt.SpecialInstruction, true), true, true)); + commands.Add(new PrintCommand("")); + } + + commands.Add(new PrintCommand(CreateDashedLine())); + + + + + // Gangs + + foreach (Gang gang in kitchenReceipt.Gangs) + { + + commands.Add(new PrintCommand(Center($"{gang.Id}. {gang.Name}", false)) { IsRed = true }); + foreach (var dish in gang.Dishes) + { + PrintDish(dish, commands); + } + } + + if (kitchenReceipt.Gangs.Count > 0) + { + commands.Add(new PrintCommand(CreateDashedLine())); + } + + foreach (var dish in kitchenReceipt.Dishes) + { + PrintDish(dish, commands); + } + + if (kitchenReceipt.Dishes != null && kitchenReceipt.Dishes.Any()) + { + commands.Add(new PrintCommand("")); + commands.Add(new PrintCommand(CreateDashedLine())); + commands.Add(new PrintCommand("")); + } + + + //// Additional info section + //if (kitchenReceipt.AdditionalInfo != null && kitchenReceipt.AdditionalInfo.Count > 0) + //{ + // commands.Add(new PrintCommand(CreateAsterisksLine())); + // commands.Add(new PrintCommand("Info über zugehörige Artikel")); + // commands.Add(new PrintCommand(CreateAsterisksLine())); + + // foreach (var info in kitchenReceipt.AdditionalInfo) + // { + // commands.Add(new PrintCommand(info)); + // } + + // commands.Add(new PrintCommand("")); + //} + + return commands; + } + + private static void PrintDish(Dish drink, List commands) + { + string drinkLine = $"{drink.Number}x {drink.Name}"; + commands.Add(new PrintCommand(drinkLine)); + // Modifications + if (drink.Modifications != null && (drink.Modifications.Removed.Any() || drink.Modifications.Added.Any())) + { + foreach (var removed in drink.Modifications.Removed) + { + commands.Add(new PrintCommand($" - {removed}", isBold:true)); + } + + foreach (var added in drink.Modifications.Added) + { + commands.Add(new PrintCommand($" + {added}", isBold: true)); + } + } + + // SpecialInstruction + if (!string.IsNullOrEmpty(drink.Comment)) + { + commands.Add(new PrintCommand($" Comment: {drink.Comment}", isBold: true)); + } + + commands.Add(new PrintCommand("")); // Extra line between drinks for bar + } + + private string Center(string text, bool isBigFont) + { + var actualLineWidth = isBigFont ? _BigLineWidth : _lineWidth; + if (string.IsNullOrEmpty(text) || text.Length >= actualLineWidth) + return text; + + int totalPadding = actualLineWidth - text.Length; + int leftPadding = totalPadding / 2; + + return new string(' ', leftPadding) + text; + } + + private string CreateDashedLine() + { + return new string('-', _lineWidth); + } + + private string CreateAsterisksLine() + { + return new string('*', _lineWidth); + } +} diff --git a/Inspectron.Epson/PrintServer/Printers/Utils/BarReceipt/BarReceiptConverterAdapter.cs b/Inspectron.Epson/PrintServer/Printers/Utils/BarReceipt/BarReceiptConverterAdapter.cs new file mode 100644 index 0000000..8aa3c4e --- /dev/null +++ b/Inspectron.Epson/PrintServer/Printers/Utils/BarReceipt/BarReceiptConverterAdapter.cs @@ -0,0 +1,22 @@ +using System.Text.Json; + +namespace Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt; + +public class BarReceiptConverterAdapter : IReceiptConverter +{ + private readonly int _lineWidth; + private readonly int _bigFontLineWidth; + + public BarReceiptConverterAdapter(int lineWidth, int bigFontLineWidth) + { + _lineWidth = lineWidth; + _bigFontLineWidth = bigFontLineWidth; + } + + public List Convert(string jsonContent) + { + var receipt = JsonSerializer.Deserialize(jsonContent); + var converter = new BarReceiptConverter(_lineWidth, _bigFontLineWidth); + return converter.ConvertToPrintCommands(receipt); + } +} diff --git a/Inspectron.Epson/PrintServer/Printers/Utils/BarReceipt/Models.cs b/Inspectron.Epson/PrintServer/Printers/Utils/BarReceipt/Models.cs new file mode 100644 index 0000000..0744f5d --- /dev/null +++ b/Inspectron.Epson/PrintServer/Printers/Utils/BarReceipt/Models.cs @@ -0,0 +1,97 @@ +namespace Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt +{ + + public class BarReceipt + { + /// + /// Restaurant name + /// + public string Title { get; set; } + + /// + /// Date and time of the transaction + /// + public DateTime TransactionDateTime { get; set; } + + /// + /// Receipt number + /// + public string ReceiptNumber { get; set; } + + /// + /// Server/Waiter name + /// + public string WaiterName { get; set; } + + /// + /// Server/Waiter ID + /// + public string WaiterId { get; set; } + + /// + /// Table number + /// + public string TableNumber { get; set; } + + public string SpecialInstruction { get; set; } + + public List Gangs { get; set; } = new List(); + + public List Dishes { get; set; } = new List(); + + + public BarReceipt() + { + Gangs = new List(); + + } + } + + + public class Gang + { + public Gang(int id, string name) + { + Id = id; + Name = name; + } + + public int Id { get; set; } + public string Name { get; set; } + public List Dishes { get; set; } = new List(); + } + + /// + /// Represents a dish item on the receipt + /// + public class Dish + { + /// + /// Number ordered + /// + public int Number { get; set; } + + /// + /// Name of the dish + /// + public string Name { get; set; } + + public Dish() { } + + public Dish(int number, string name) + { + Number = number; + Name = name; + } + + public DishModifications Modifications { get; set; } = new DishModifications(); + public string? Comment { get; set; } + } + + public class DishModifications + { + public List Removed { get; set; } = new List(); + public List Added { get; set; } = new List(); + } + +} diff --git a/Inspectron.Epson/PrintServer/Printers/Utils/PrintCommand.cs b/Inspectron.Epson/PrintServer/Printers/Utils/PrintCommand.cs index 0424012..6c5848f 100644 --- a/Inspectron.Epson/PrintServer/Printers/Utils/PrintCommand.cs +++ b/Inspectron.Epson/PrintServer/Printers/Utils/PrintCommand.cs @@ -6,7 +6,7 @@ public class PrintCommand public bool IsBig { get; set; } public bool IsBold { get; set; } public bool IsRed { get; set; } - + public int? SetLineSpacing { get; set; }=null; public PrintCommand(string text, bool isBig = false, bool isBold = false) { Text = text; diff --git a/Inspectron.Epson/PrintServer/Printers/Utils/ReceiptConverterFactory.cs b/Inspectron.Epson/PrintServer/Printers/Utils/ReceiptConverterFactory.cs index 3ae8e1f..085ae5e 100644 --- a/Inspectron.Epson/PrintServer/Printers/Utils/ReceiptConverterFactory.cs +++ b/Inspectron.Epson/PrintServer/Printers/Utils/ReceiptConverterFactory.cs @@ -1,3 +1,4 @@ +using Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt; using Inspectron.Epson.PrintServer.Printers.Utils.OrderItems; namespace Inspectron.Epson.PrintServer.Printers.Utils; @@ -11,7 +12,7 @@ public class ReceiptConverterFactory : IReceiptConverterFactory EReceiptType.Receipt => new FinalReceipt.FinalReceiptConverter(48, 24), EReceiptType.WorkareaTicket => printerId switch { - 0x01=>new KitchenReceipt.KitchenReceiptConverterAdapter(48, 24), + 0x01=>new BarReceiptConverterAdapter(48, 24), _=> new KitchenReceipt.KitchenReceiptConverterAdapter(33, 20), }, EReceiptType.NextCourse => new KitchenReceipt.KitchenReceiptConverterAdapter(33, 20),