new receipt formats

This commit is contained in:
EugeneTes
2026-01-26 14:29:37 +01:00
parent 53cf40c5e3
commit 1125222cbe
13 changed files with 132 additions and 68 deletions

View File

@@ -394,7 +394,7 @@ public class EpsonPrinter : IEpsonPrinter
await SendRawAsync(EpsonCommands.FeedLines((byte)lines));
}
public async Task CutAsync()
public async Task CutAsync(bool fullCut=true)
{
_logger?.LogInformation("Cutting paper");
await SendRawAsync(EpsonCommands.CutPaperFull);

View File

@@ -322,11 +322,17 @@ public class HtmlPrinter : IEpsonPrinter
}
/// <inheritdoc />
public Task CutAsync()
public Task CutAsync(bool fullCut = true)
{
EnsureConnected();
_logger?.LogInformation("HtmlPrinter: Cutting paper");
WriteHtmlFile();
if(fullCut)
WriteHtmlFile();
else
{
// add scissors icon for partial cut
_content.AppendLine("<div class=\"cut\"><span class=\"scissors\">✂️</span></div>");
}
return Task.CompletedTask;
}

View File

@@ -122,7 +122,7 @@ public interface IEpsonPrinter : IAsyncDisposable
/// <summary>
/// Cut the paper
/// </summary>
Task CutAsync();
Task CutAsync(bool fullCut=true);
/// <summary>
/// Load an image from a file path into the printer buffer

View File

@@ -35,6 +35,12 @@ public class TM_U220IITranslated : IPrinter
{
foreach (var command in commands)
{
if (command.IsCut)
{
await _printer.CutAsync(false);
await Task.Delay(200);
continue;
}
await _printer.SetBiggerFontTM220(command.IsBig, command.IsTall | command.IsBig);
await Task.Delay(200);
await _printer.SetRedColor(command.IsRed);

View File

@@ -6,7 +6,7 @@ public class FinalReceipt
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Phone { get; set; }
public string ReceiptNumber { get; set; }
public string? ReceiptNumber { get; set; }
public DateTime DateTime { get; set; }
public int Guests { get; set; }
public List<FinalReceiptItem> Items { get; set; } = new List<FinalReceiptItem>();

View File

@@ -27,7 +27,12 @@ public class ReceiptConverter
commands.Add(new PrintCommand("Debitorenrechnung"));
}
// FinalReceipt info
string receiptLine = $"Rechnung Nr. {finalReceipt.ReceiptNumber}".PadRight(_lineWidth/2)+$"{finalReceipt.DateTime:HH:mm dd.MM.yyyy}".PadLeft(_lineWidth/2);
string receiptLine = "";
if (finalReceipt.ReceiptNumber != null)
receiptLine += $"Rechnung Nr. {finalReceipt.ReceiptNumber}".PadRight(_lineWidth / 2);
else
receiptLine += $"".PadRight(_lineWidth / 2);
receiptLine += $"{finalReceipt.DateTime:HH:mm dd.MM.yyyy}".PadLeft(_lineWidth / 2);
commands.Add(new PrintCommand(receiptLine,isBold:true));
commands.Add(new PrintCommand($"Guests: {finalReceipt.Guests}"));
commands.Add(new PrintCommand(""));

View File

@@ -12,6 +12,8 @@ public class InvoiceReceipt
public List<ReceiptItem> Items { get; set; } = new List<ReceiptItem>();
public decimal Total { get; set; }
public string Currency { get; set; }
public string TableNumber { get; set; }
public string ThankYouMessage { get; set; }
}
public class ReceiptItem

View File

@@ -1,3 +1,5 @@
using Inspectron.Epson.PrintServer.Printers.Utils.FinalRecipe;
namespace Inspectron.Epson.PrintServer.Printers.Utils.InvoiceReceipt;
public class ReceiptConverter
@@ -24,7 +26,13 @@ public class ReceiptConverter
commands.Add(new PrintCommand(""));
// InvoiceReceipt info
string receiptLine = $"Rechnung Nr. {invoiceReceipt.ReceiptNumber}".PadRight(_lineWidth/2)+$"{invoiceReceipt.DateTime:HH:mm dd.MM.yyyy}".PadLeft(_lineWidth/2);
string receiptLine = "";
if (invoiceReceipt.ReceiptNumber != null)
receiptLine += $"Rechnung Nr. {invoiceReceipt.ReceiptNumber}".PadRight(_lineWidth / 2);
else
receiptLine += $"".PadRight(_lineWidth / 2);
receiptLine += $"{invoiceReceipt.DateTime:HH:mm dd.MM.yyyy}".PadLeft(_lineWidth / 2);
commands.Add(new PrintCommand(receiptLine,isBold:true));
commands.Add(new PrintCommand($"Guests: {invoiceReceipt.Guests}"));
commands.Add(new PrintCommand(""));
@@ -59,6 +67,8 @@ public class ReceiptConverter
// Total
string totalLine = $"Summe: {invoiceReceipt.Total:F2} {invoiceReceipt.Currency}";
commands.Add(new PrintCommand(Center(totalLine, true), true, true));
commands.Add(new PrintCommand(Center($"Tisch: {invoiceReceipt.TableNumber}",false), false));
commands.Add(new PrintCommand(Center(invoiceReceipt.ThankYouMessage, false)));
return commands;
}

View File

@@ -46,7 +46,7 @@ public class KitchenReceiptConverter
// Gangs
foreach (Gang gang in kitchenReceipt.Gangs)
{
@@ -55,6 +55,13 @@ public class KitchenReceiptConverter
{
PrintDish(dish, commands);
}
if (gang != kitchenReceipt.Gangs.Last())
{
commands.Add(new PrintCommand(""){IsCut = true});
commands.Add(new PrintCommand(""));
commands.Add(new PrintCommand(""));
}
}
if (kitchenReceipt.Gangs.Count > 0)
@@ -96,7 +103,11 @@ public class KitchenReceiptConverter
private static void PrintDish(Dish dish, List<PrintCommand> commands)
{
string dishLine = $"{dish.Number}x {dish.Name}";
commands.Add(new PrintCommand(dishLine){IsTall = true});
string guestInfo = dish.GuestId.HasValue ? $"{dish.GuestId.Value} " : "";
//todo: add word wrap if guest id is present and guestInfo + dish line too long. add spaces in front of continued lines to align with dish name start position
commands.Add(new PrintCommand(guestInfo+dishLine) {IsTall = true});
// Modifications
if (dish.Modifications != null && (dish.Modifications.Removed.Any() || dish.Modifications.Added.Any()))
{

View File

@@ -80,6 +80,8 @@
public Dish(){}
public int? GuestId { get; set; }
public Dish(int number, string name)
{
Number = number;

View File

@@ -8,6 +8,7 @@ public class PrintCommand
public bool IsBold { get; set; }
public bool IsRed { get; set; }
public int? SetLineSpacing { get; set; }=null;
public bool IsCut { get; set; }
public PrintCommand(string text, bool isBig = false, bool isBold = false)
{
Text = text;