kitchen receipt + html printer

This commit is contained in:
EugeneTes
2026-01-14 11:47:43 +01:00
parent 011978136d
commit 147265358f
16 changed files with 1346 additions and 178 deletions

View File

@@ -2,6 +2,7 @@
using Inspectron.Epson.PrintServer.Printers.Utils;
using Inspectron.Epson.PrintServer.Printers.Utils.FinalRecipe;
using Inspectron.Epson.PrintServer.PrintServices;
using FinalReceipt = Inspectron.Epson.PrintServer.Printers.Utils.FinalRecipe.FinalReceipt;
namespace Inspectron.Epson.PrintServer.Printers;
@@ -35,10 +36,10 @@ public class TM_T30IIITranslated:IPrinter
public async Task PrintTextAsync(string text)
{
Receipt? receipt;
FinalReceipt? receipt;
try
{
receipt = JsonSerializer.Deserialize<Receipt>(text);
receipt = JsonSerializer.Deserialize<FinalReceipt>(text);
}
catch
{
@@ -84,7 +85,7 @@ public class TM_T30IIITranslated:IPrinter
ReceiptTranslator translator = new ReceiptTranslator();
var ast = translator.ParseReceipt(text);
KitchenReceiptPrinter printer = new KitchenReceiptPrinter(lineWidth: 33, 21);
var commands = printer.ConvertToCommands((KitchenReceipt)ast);
var commands = printer.ConvertToCommands((TranslatedKitchenReceipt)ast);
foreach (KitchenPrintCommand command in commands)
{
if (command.IsBig)

View File

@@ -37,7 +37,7 @@ public class TM_U220IITranslated:IPrinter
ReceiptTranslator translator = new ReceiptTranslator();
var ast = translator.ParseReceipt(text);
KitchenReceiptPrinter printer = new KitchenReceiptPrinter(lineWidth:33,21);
var commands = printer.ConvertToCommands((KitchenReceipt)ast);
var commands = printer.ConvertToCommands((TranslatedKitchenReceipt)ast);
foreach (KitchenPrintCommand command in commands)
{
await _printer.SetBiggerFontTM220(command.IsBig);

View File

@@ -1,6 +1,6 @@
namespace Inspectron.Epson.PrintServer.Printers.Utils.FinalRecipe;
public class Receipt
public class FinalReceipt
{
public string CompanyName { get; set; }
public string Address1 { get; set; }
@@ -17,7 +17,7 @@ public class Receipt
public string PaymentMethod { get; set; }
public decimal PaymentAmount { get; set; }
public List<TaxInfo> TaxBreakdown { get; set; } = new List<TaxInfo>();
public string ServerName { get; set; }
public string WaiterName { get; set; }
public string Terminal { get; set; }
public string TableNumber { get; set; }
public string VatNumber { get; set; }
@@ -43,18 +43,4 @@ public class TaxInfo
public decimal Net { get; set; }
public decimal TaxAmount { get; set; }
public string Currency { get; set; }
}
public class PrintCommand
{
public string Text { get; set; }
public bool IsBig { get; set; }
public bool IsBold { get; set; }
public PrintCommand(string text, bool isBig = false, bool isBold = false)
{
Text = text;
IsBig = isBig;
IsBold = isBold;
}
}

View File

@@ -11,26 +11,26 @@ public class ReceiptConverter
_bigFontLineWidth = bigFontLineWidth;
}
public List<PrintCommand> ConvertToPrintCommands(Receipt receipt)
public List<PrintCommand> ConvertToPrintCommands(FinalReceipt finalReceipt)
{
var commands = new List<PrintCommand>();
// Header - Company info
commands.Add(new PrintCommand(Center(receipt.CompanyName, false)));
commands.Add(new PrintCommand(Center(receipt.Address1, false)));
commands.Add(new PrintCommand(Center(receipt.Address2, false)));
commands.Add(new PrintCommand(Center(receipt.Phone, false)));
commands.Add(new PrintCommand(Center(finalReceipt.CompanyName, false)));
commands.Add(new PrintCommand(Center(finalReceipt.Address1, false)));
commands.Add(new PrintCommand(Center(finalReceipt.Address2, false)));
commands.Add(new PrintCommand(Center(finalReceipt.Phone, false)));
commands.Add(new PrintCommand(""));
commands.Add(new PrintCommand(""));
// Receipt info
string receiptLine = $"Rechnung Nr. {receipt.ReceiptNumber}".PadRight(_lineWidth/2)+$"{receipt.DateTime:HH:mm dd.MM.yyyy}".PadLeft(_lineWidth/2);
// FinalReceipt info
string receiptLine = $"Rechnung Nr. {finalReceipt.ReceiptNumber}".PadRight(_lineWidth/2)+$"{finalReceipt.DateTime:HH:mm dd.MM.yyyy}".PadLeft(_lineWidth/2);
commands.Add(new PrintCommand(receiptLine,isBold:true));
commands.Add(new PrintCommand($"Guests: {receipt.Guests}"));
commands.Add(new PrintCommand($"Guests: {finalReceipt.Guests}"));
commands.Add(new PrintCommand(""));
// Items
foreach (var item in receipt.Items)
foreach (var item in finalReceipt.Items)
{
string quantityDesc = $"{item.Quantity}x {item.Description}";
string prices = $"{item.UnitPrice:F2}"+$"{item.TotalPrice:F2}".PadLeft(7)+$" {item.TaxCategory}";
@@ -48,31 +48,31 @@ public class ReceiptConverter
commands.Add(new PrintCommand("")); //Reini
// Total
string totalLine = $"Summe: {receipt.Total:F2} {receipt.Currency}";
string totalLine = $"Summe: {finalReceipt.Total:F2} {finalReceipt.Currency}";
commands.Add(new PrintCommand(Center(totalLine, true), true, true));
commands.Add(new PrintCommand(""));
// Alternate currency
if (receipt.TotalInAlternateCurrency.HasValue)
if (finalReceipt.TotalInAlternateCurrency.HasValue)
{
string altCurrencyLine = $"{receipt.TotalInAlternateCurrency:F2} {receipt.AlternateCurrency}";
string altCurrencyLine = $"{finalReceipt.TotalInAlternateCurrency:F2} {finalReceipt.AlternateCurrency}";
commands.Add(new PrintCommand(altCurrencyLine.PadLeft(_lineWidth)));
commands.Add(new PrintCommand(""));
}
// Payment method
string paymentLine = $"{receipt.PaymentMethod}";
string paymentAmount = $"{receipt.PaymentAmount:F2} {receipt.Currency}";
string paymentLine = $"{finalReceipt.PaymentMethod}";
string paymentAmount = $"{finalReceipt.PaymentAmount:F2} {finalReceipt.Currency}";
int paymentSpaces = _lineWidth - paymentLine.Length - paymentAmount.Length;
if (paymentSpaces < 1) paymentSpaces = 1;
commands.Add(new PrintCommand(paymentLine + new string(' ', paymentSpaces) + paymentAmount,isBold:true));
commands.Add(new PrintCommand(""));
// Tax breakdown
foreach (var tax in receipt.TaxBreakdown)
foreach (var tax in finalReceipt.TaxBreakdown)
{
string taxLine = "MwSt %".PadRight(_lineWidth/4)+" Brutto".PadRight(_lineWidth / 4) + " Netto".PadRight(_lineWidth / 4) + "MwSt".PadLeft(_lineWidth / 4);
if (receipt.TaxBreakdown.IndexOf(tax) == 0)
if (finalReceipt.TaxBreakdown.IndexOf(tax) == 0)
{
commands.Add(new PrintCommand(taxLine));
}
@@ -83,22 +83,22 @@ public class ReceiptConverter
commands.Add(new PrintCommand(""));
// Footer info
//commands.Add(new PrintCommand(Center($"Bedient von: {receipt.ServerName}", false)));
//commands.Add(new PrintCommand(Center($"Terminal: {receipt.Terminal}", false)));
//commands.Add(new PrintCommand(Center($"Tisch: {receipt.TableNumber}", false)));
commands.Add(new PrintCommand($"Bedient von:".PadLeft(_lineWidth / 2) + $" {receipt.ServerName}"));
commands.Add(new PrintCommand($"Terminal:".PadLeft(_lineWidth / 2) + $" {receipt.Terminal}"));
commands.Add(new PrintCommand($"Tisch:".PadLeft(_lineWidth / 2)+$" {receipt.TableNumber}"));
//commands.Add(new PrintCommand(Center($"Bedient von: {finalReceipt.WaiterName}", false)));
//commands.Add(new PrintCommand(Center($"Terminal: {finalReceipt.Terminal}", false)));
//commands.Add(new PrintCommand(Center($"Tisch: {finalReceipt.TableNumber}", false)));
commands.Add(new PrintCommand($"Bedient von:".PadLeft(_lineWidth / 2) + $" {finalReceipt.WaiterName}"));
commands.Add(new PrintCommand($"Terminal:".PadLeft(_lineWidth / 2) + $" {finalReceipt.Terminal}"));
commands.Add(new PrintCommand($"Tisch:".PadLeft(_lineWidth / 2)+$" {finalReceipt.TableNumber}"));
commands.Add(new PrintCommand(""));
commands.Add(new PrintCommand(""));
// VAT number
commands.Add(new PrintCommand(Center(receipt.VatNumber, false)));
commands.Add(new PrintCommand(Center(finalReceipt.VatNumber, false)));
// Thank you message
commands.Add(new PrintCommand(Center(receipt.ThankYouMessage, false)));
commands.Add(new PrintCommand(Center(receipt.GoodbyeMessageLine1, false)));
commands.Add(new PrintCommand(Center(receipt.GoodbyeMessageLine2, false)));
commands.Add(new PrintCommand(Center(finalReceipt.ThankYouMessage, false)));
commands.Add(new PrintCommand(Center(finalReceipt.GoodbyeMessageLine1, false)));
commands.Add(new PrintCommand(Center(finalReceipt.GoodbyeMessageLine2, false)));
return commands;
}

View File

@@ -0,0 +1,109 @@
namespace Inspectron.Epson.PrintServer.Printers.Utils.KitchenReceipt;
public class KitchenReceiptConverter
{
private readonly int _lineWidth;
private readonly int _BigLineWidth;
public KitchenReceiptConverter(int lineWidth = 42, int bigLineWidth=22)
{
_BigLineWidth = bigLineWidth;
_lineWidth = lineWidth;
}
public List<PrintCommand> ConvertToPrintCommands(KitchenReceipt kitchenReceipt)
{
var commands = new List<PrintCommand>();
// 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));
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)
{
string dishLine = $"{dish.Number}x {dish.Name}";
commands.Add(new PrintCommand(dishLine));
}
}
if (kitchenReceipt.Gangs.Count > 0)
{
commands.Add(new PrintCommand(CreateDashedLine()));
}
foreach (var dish in kitchenReceipt.Dishes)
{
string dishLine = $"{dish.Number}x {dish.Name}";
commands.Add(new PrintCommand(dishLine));
}
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 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);
}
}

View File

@@ -0,0 +1,92 @@
namespace Inspectron.Epson.PrintServer.Printers.Utils.KitchenReceipt
{
/// <summary>
/// Represents a restaurant receipt from Warme Küche
/// </summary>
public class KitchenReceipt
{
/// <summary>
/// Restaurant name
/// </summary>
public string Title { get; set; }
/// <summary>
/// Date and time of the transaction
/// </summary>
public DateTime TransactionDateTime { get; set; }
/// <summary>
/// Receipt number
/// </summary>
public string ReceiptNumber { get; set; }
/// <summary>
/// Server/Waiter name
/// </summary>
public string WaiterName { get; set; }
/// <summary>
/// Server/Waiter ID
/// </summary>
public string WaiterId { get; set; }
/// <summary>
/// Table number
/// </summary>
public int TableNumber { get; set; }
public List<Gang> Gangs { get; set; } = new List<Gang>();
public List<Dish> Dishes { get; set; } = new List<Dish>();
/// <summary>
/// Additional items or notes (e.g., "Amuse Bouche")
/// </summary>
public List<string> AdditionalInfo { get; set; }
public KitchenReceipt()
{
Gangs = new List<Gang>();
AdditionalInfo = new List<string>();
}
}
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<Dish> Dishes { get; set; } = new List<Dish>();
}
/// <summary>
/// Represents a dish item on the receipt
/// </summary>
public class Dish
{
/// <summary>
/// Number ordered
/// </summary>
public int Number { get; set; }
/// <summary>
/// Name of the dish
/// </summary>
public string Name { get; set; }
public Dish(int number, string name)
{
Number = number;
Name = name;
}
}
}

View File

@@ -11,7 +11,7 @@ public class KitchenReceiptPrinter
_bigFontLineWidth = bigFontLineWidth;
}
public List<KitchenPrintCommand> ConvertToCommands(KitchenReceipt receipt)
public List<KitchenPrintCommand> ConvertToCommands(TranslatedKitchenReceipt receipt)
{
var commands = new List<KitchenPrintCommand>();

View File

@@ -0,0 +1,16 @@
namespace Inspectron.Epson.PrintServer.Printers.Utils;
public class PrintCommand
{
public string Text { get; set; }
public bool IsBig { get; set; }
public bool IsBold { get; set; }
public bool IsRed { get; set; }
public PrintCommand(string text, bool isBig = false, bool isBold = false)
{
Text = text;
IsBig = isBig;
IsBold = isBold;
}
}

View File

@@ -1,7 +1,7 @@
namespace Inspectron.Epson.PrintServer.Printers.Utils;
public record KitchenReceipt(string Location, string Date, string Owner, string Tisch, List<KitchenItem> items) :ASTNode;
public record TranslatedKitchenReceipt(string Location, string Date, string Owner, string Tisch, List<KitchenItem> items) :ASTNode;
public record KitchenItem(string Name) : ASTNode;
public record KitchenProduct(int Amount, string Name) : KitchenItem(Name);
public record KitchenGang(string Name) : KitchenItem(Name);
@@ -112,7 +112,7 @@ public class ReceiptTranslator
return new FinalReceipt(location, phone, url, date, items, total, mwst, comment, thanks);
}
public static KitchenReceipt ParseKitchenReceipt(string receiptText)
public static TranslatedKitchenReceipt ParseKitchenReceipt(string receiptText)
{
var lines = receiptText.Split('\n', StringSplitOptions.RemoveEmptyEntries)
.Select(l => l.Trim())
@@ -198,7 +198,7 @@ public class ReceiptTranslator
currentIndex++;
}
return new KitchenReceipt(location, date, owner, tisch, items);
return new TranslatedKitchenReceipt(location, date, owner, tisch, items);
}

View File

@@ -21,7 +21,7 @@ public class JamesWorkAreaSource: IWorkAreasSource
response.Add(new WorkArea()
{
Id = "print-receipt",
Name = "Receipt"
Name = "FinalReceipt"
});
return response!;
}