print server with new concept
This commit is contained in:
@@ -8,6 +8,7 @@ using SixLabors.ImageSharp.PixelFormats;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Xml.Linq;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.OrderItems;
|
||||
using FinalReceipt = Inspectron.Epson.PrintServer.Printers.Utils.FinalRecipe.FinalReceipt;
|
||||
|
||||
|
||||
@@ -58,159 +59,178 @@ using FinalReceipt = Inspectron.Epson.PrintServer.Printers.Utils.FinalRecipe.Fin
|
||||
//Console.ReadLine();
|
||||
|
||||
|
||||
var receipt = new FinalReceipt
|
||||
{
|
||||
CompanyName = "Klingler Gastro AG",
|
||||
Address1 = "Münzplatz 3",
|
||||
Address2 = "CH-8001 Zürich",
|
||||
Phone = "043 321 22 22",
|
||||
ReceiptNumber = "1-81-202",
|
||||
DateTime = new DateTime(2025, 12, 16, 14, 58, 0),
|
||||
Guests = 2,
|
||||
Total = 160.00m,
|
||||
Currency = "CHF",
|
||||
TotalInAlternateCurrency = 172.80m,
|
||||
AlternateCurrency = "EUR",
|
||||
PaymentMethod = "MASTER",
|
||||
PaymentAmount = 160.00m,
|
||||
WaiterName = "Yves",
|
||||
Terminal = "Hauptkasse ZH",
|
||||
TableNumber = "12",
|
||||
VatNumber = "CHE-449.635.880 MWST",
|
||||
ThankYouMessage = "Das Team bedankt sich herzlich für Ihren",
|
||||
GoodbyeMessageLine1 = "Besuch.",
|
||||
GoodbyeMessageLine2 = "Auf Wiedersehen."
|
||||
};
|
||||
//var receipt = new FinalReceipt
|
||||
//{
|
||||
// CompanyName = "Klingler Gastro AG",
|
||||
// Address1 = "Münzplatz 3",
|
||||
// Address2 = "CH-8001 Zürich",
|
||||
// Phone = "043 321 22 22",
|
||||
// ReceiptNumber = "1-81-202",
|
||||
// DateTime = new DateTime(2025, 12, 16, 14, 58, 0),
|
||||
// Guests = 2,
|
||||
// Total = 160.00m,
|
||||
// Currency = "CHF",
|
||||
// TotalInAlternateCurrency = 172.80m,
|
||||
// AlternateCurrency = "EUR",
|
||||
// PaymentMethod = "MASTER",
|
||||
// PaymentAmount = 160.00m,
|
||||
// WaiterName = "Yves",
|
||||
// Terminal = "Hauptkasse ZH",
|
||||
// TableNumber = "12",
|
||||
// VatNumber = "CHE-449.635.880 MWST",
|
||||
// ThankYouMessage = "Das Team bedankt sich herzlich für Ihren",
|
||||
// GoodbyeMessageLine1 = "Besuch.",
|
||||
// GoodbyeMessageLine2 = "Auf Wiedersehen.",
|
||||
// TerminalReceipt = new PaymentTerminalReceipt
|
||||
// {
|
||||
// ReceiptType = "*** Kundenbeleg ***",
|
||||
// BookingType = "Buchung",
|
||||
// PaymentSystem = "TWINT",
|
||||
// TransactionNumber = "XXXXXXXXXXXXXXX1494",
|
||||
// TransactionDateTime = new DateTime(2025, 11, 11, 12, 34, 49),
|
||||
// TerminalId = "31108834",
|
||||
// AID = "A0000015749E",
|
||||
// TransactionSeqCount = "6127",
|
||||
// TransactionRefNo = "99036644599",
|
||||
// AuthCode = "0d3396",
|
||||
// AcquirerId = "2",
|
||||
// EftAmount = 67.00m,
|
||||
// TipAmount = 6.70m,
|
||||
// TotalEftAmount = 73.70m,
|
||||
// Currency = "CHF"
|
||||
// }
|
||||
//};
|
||||
|
||||
// Add items
|
||||
receipt.Items.Add(new ReceiptItem
|
||||
{
|
||||
Quantity = 1,
|
||||
Description = "San Pellegrino 50cl",
|
||||
UnitPrice = 6.50m,
|
||||
TotalPrice = 6.50m,
|
||||
TaxCategory = "A"
|
||||
});
|
||||
//// Add items
|
||||
//receipt.Items.Add(new ReceiptItem
|
||||
//{
|
||||
// Quantity = 1,
|
||||
// Description = "San Pellegrino 50cl",
|
||||
// UnitPrice = 6.50m,
|
||||
// TotalPrice = 6.50m,
|
||||
// TaxCategory = "A"
|
||||
//});
|
||||
|
||||
receipt.Items.Add(new ReceiptItem
|
||||
{
|
||||
Quantity = 1,
|
||||
Description = "Panna 50cl",
|
||||
UnitPrice = 6.50m,
|
||||
TotalPrice = 6.50m,
|
||||
TaxCategory = "A"
|
||||
});
|
||||
//receipt.Items.Add(new ReceiptItem
|
||||
//{
|
||||
// Quantity = 1,
|
||||
// Description = "Panna 50cl",
|
||||
// UnitPrice = 6.50m,
|
||||
// TotalPrice = 6.50m,
|
||||
// TaxCategory = "A"
|
||||
//});
|
||||
|
||||
receipt.Items.Add(new ReceiptItem
|
||||
{
|
||||
Quantity = 1,
|
||||
Description = "Granini Tomatensaft",
|
||||
UnitPrice = 5.50m,
|
||||
TotalPrice = 5.50m,
|
||||
TaxCategory = "A"
|
||||
});
|
||||
//receipt.Items.Add(new ReceiptItem
|
||||
//{
|
||||
// Quantity = 1,
|
||||
// Description = "Granini Tomatensaft",
|
||||
// UnitPrice = 5.50m,
|
||||
// TotalPrice = 5.50m,
|
||||
// TaxCategory = "A"
|
||||
//});
|
||||
|
||||
receipt.Items.Add(new ReceiptItem
|
||||
{
|
||||
Quantity = 2,
|
||||
Description = "Business Lunch Menu Seco",
|
||||
UnitPrice = 44.00m,
|
||||
TotalPrice = 88.00m,
|
||||
TaxCategory = "A"
|
||||
});
|
||||
//receipt.Items.Add(new ReceiptItem
|
||||
//{
|
||||
// Quantity = 2,
|
||||
// Description = "Business Lunch Menu Seco",
|
||||
// UnitPrice = 44.00m,
|
||||
// TotalPrice = 88.00m,
|
||||
// TaxCategory = "A"
|
||||
//});
|
||||
|
||||
receipt.Items.Add(new ReceiptItem
|
||||
{
|
||||
Quantity = 2,
|
||||
Description = "Brunello di Montalcino 1",
|
||||
UnitPrice = 16.00m,
|
||||
TotalPrice = 32.00m,
|
||||
TaxCategory = "A"
|
||||
});
|
||||
//receipt.Items.Add(new ReceiptItem
|
||||
//{
|
||||
// Quantity = 2,
|
||||
// Description = "Brunello di Montalcino 1",
|
||||
// UnitPrice = 16.00m,
|
||||
// TotalPrice = 32.00m,
|
||||
// TaxCategory = "A"
|
||||
//});
|
||||
|
||||
receipt.Items.Add(new ReceiptItem
|
||||
{
|
||||
Quantity = 2,
|
||||
Description = "Espresso",
|
||||
UnitPrice = 5.50m,
|
||||
TotalPrice = 11.00m,
|
||||
TaxCategory = "A"
|
||||
});
|
||||
//receipt.Items.Add(new ReceiptItem
|
||||
//{
|
||||
// Quantity = 2,
|
||||
// Description = "Espresso",
|
||||
// UnitPrice = 5.50m,
|
||||
// TotalPrice = 11.00m,
|
||||
// TaxCategory = "A"
|
||||
//});
|
||||
|
||||
receipt.Items.Add(new ReceiptItem
|
||||
{
|
||||
Quantity = 1,
|
||||
Description = "Tip",
|
||||
UnitPrice = 10.50m,
|
||||
TotalPrice = 10.50m,
|
||||
TaxCategory = "B"
|
||||
});
|
||||
//receipt.Items.Add(new ReceiptItem
|
||||
//{
|
||||
// Quantity = 1,
|
||||
// Description = "Tip",
|
||||
// UnitPrice = 10.50m,
|
||||
// TotalPrice = 10.50m,
|
||||
// TaxCategory = "B"
|
||||
//});
|
||||
|
||||
// Add tax breakdown
|
||||
receipt.TaxBreakdown.Add(new TaxInfo
|
||||
{
|
||||
Category = "A",
|
||||
Rate = 8.1m,
|
||||
Gross = 149.50m,
|
||||
Net = 138.30m,
|
||||
TaxAmount = 11.20m,
|
||||
Currency = "CHF"
|
||||
});
|
||||
//// Add tax breakdown
|
||||
//receipt.TaxBreakdown.Add(new TaxInfo
|
||||
//{
|
||||
// Category = "A",
|
||||
// Rate = 8.1m,
|
||||
// Gross = 149.50m,
|
||||
// Net = 138.30m,
|
||||
// TaxAmount = 11.20m,
|
||||
// Currency = "CHF"
|
||||
//});
|
||||
|
||||
receipt.TaxBreakdown.Add(new TaxInfo
|
||||
{
|
||||
Category = "B",
|
||||
Rate = 0m,
|
||||
Gross = 10.50m,
|
||||
Net = 10.50m,
|
||||
TaxAmount = 0.00m,
|
||||
Currency = "CHF"
|
||||
});
|
||||
//receipt.TaxBreakdown.Add(new TaxInfo
|
||||
//{
|
||||
// Category = "B",
|
||||
// Rate = 0m,
|
||||
// Gross = 10.50m,
|
||||
// Net = 10.50m,
|
||||
// TaxAmount = 0.00m,
|
||||
// Currency = "CHF"
|
||||
//});
|
||||
|
||||
|
||||
// Convert to print commands
|
||||
var converter = new ReceiptConverter(lineWidth: 48, bigFontLineWidth: 24);
|
||||
var printCommands = converter.ConvertToPrintCommands(receipt);
|
||||
//var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
//var deserializedReceipt = JsonSerializer.Deserialize<FinalReceipt>(serializedReceipt);
|
||||
//// Convert to print commands
|
||||
//var converter = new ReceiptConverter(lineWidth: 48, bigFontLineWidth: 24);
|
||||
//var printCommands = converter.ConvertToPrintCommands(deserializedReceipt);
|
||||
|
||||
|
||||
|
||||
|
||||
// Print the commands
|
||||
Console.WriteLine("=== PRINT COMMANDS ===\n");
|
||||
var printer = new HtmlPrinter(@".\test.html", paperWidth: 384);
|
||||
await printer.ConnectAsync("");
|
||||
await printer.SetAbsolutePrintPosition(97);
|
||||
await printer.LoadImageAsync("ristorante-klinglers.ch-logo_white_bg.png", 390);
|
||||
await printer.SetAbsolutePrintPosition(0);
|
||||
await printer.PrintLoadedImage();
|
||||
await Task.Delay(200);
|
||||
await printer.FeedLinesAsync(1);
|
||||
await printer.SetCustomLineSpacing(22);
|
||||
foreach (var command in printCommands)
|
||||
{
|
||||
string attributes = "";
|
||||
if (command.IsBig) attributes += "[BIG] ";
|
||||
if (command.IsBold) attributes += "[BOLD] ";
|
||||
//// Print the commands
|
||||
//Console.WriteLine("=== PRINT COMMANDS ===\n");
|
||||
//var printer = new HtmlPrinter(@".\test.html", paperWidth: 384);
|
||||
//await printer.ConnectAsync("");
|
||||
//await printer.SetAbsolutePrintPosition(42);
|
||||
//await printer.LoadImageAsync("ristorante-klinglers.ch-logo_white_bg.png", 300);
|
||||
//await printer.PrintLoadedImage();
|
||||
//await printer.SetAbsolutePrintPosition(0);
|
||||
//await Task.Delay(200);
|
||||
////await printer.FeedLinesAsync(1);
|
||||
//await printer.SetCustomLineSpacing(22);
|
||||
//foreach (var command in printCommands)
|
||||
//{
|
||||
// string attributes = "";
|
||||
// if (command.IsBig) attributes += "[BIG] ";
|
||||
// if (command.IsBold) attributes += "[BOLD] ";
|
||||
|
||||
Console.WriteLine($"{attributes}{command.Text}");
|
||||
// Console.WriteLine($"{attributes}{command.Text}");
|
||||
|
||||
if (command.IsBig)
|
||||
{
|
||||
await printer.SetFontSizeAsync(2, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
await printer.SetFontSizeAsync(1, 1);
|
||||
}
|
||||
//await Task.Delay(200);
|
||||
// if (command.IsBig)
|
||||
// {
|
||||
// await printer.SetFontSizeAsync(2, 1);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// await printer.SetFontSizeAsync(1, 1);
|
||||
// }
|
||||
// //await Task.Delay(200);
|
||||
|
||||
await printer.SetEmphasized(command.IsBold);
|
||||
//await Task.Delay(200);
|
||||
// await printer.SetEmphasized(command.IsBold);
|
||||
// //await Task.Delay(200);
|
||||
|
||||
await printer.PrintTextAsync(command.Text + "\n");
|
||||
//await Task.Delay(200);
|
||||
// await printer.PrintTextAsync(command.Text + "\n");
|
||||
// //await Task.Delay(200);
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
|
||||
//var receipt = new KitchenReceipt
|
||||
@@ -246,10 +266,11 @@ foreach (var command in printCommands)
|
||||
|
||||
|
||||
//// Add additional info
|
||||
//receipt.AdditionalInfo.Add("1 x Amuse Bouche");
|
||||
|
||||
//KitchenReceiptConverter converter = new KitchenReceiptConverter(bigLineWidth: 20, lineWidth:33);
|
||||
//var printCommands = converter.ConvertToPrintCommands(receipt);
|
||||
//var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
//var deserializedReceipt = JsonSerializer.Deserialize<KitchenReceipt>(serializedReceipt);
|
||||
//KitchenReceiptConverter converter = new KitchenReceiptConverter(bigLineWidth: 20, lineWidth: 33);
|
||||
//var printCommands = converter.ConvertToPrintCommands(deserializedReceipt);
|
||||
|
||||
//Console.WriteLine("=== PRINT COMMANDS ===\n");
|
||||
//var printer = new HtmlPrinter(@".\test.html", paperWidth: 258);
|
||||
@@ -291,8 +312,83 @@ foreach (var command in printCommands)
|
||||
//await printer.PrintTextAsync(
|
||||
// "1x San Pellegrino 50cl 6.50 6.50 A\n1x Panna 50cl 6.50 6.50 A");
|
||||
|
||||
// Order Items Receipt Test
|
||||
//var orderItemsReceipt = new OrderItemsReceipt
|
||||
//{
|
||||
// OrderNumber = "1",
|
||||
// QRInfo = "Margherita Pizza Classic longer text",
|
||||
// DateTime = new DateTime(2026, 1, 14, 14, 35, 47),
|
||||
// ClientNotes = "Some main note",
|
||||
// Items = new List<OrderItem>
|
||||
// {
|
||||
// new OrderItem
|
||||
// {
|
||||
// Number = 1,
|
||||
// Name = "pappara",
|
||||
// Quantity = 1,
|
||||
// SubItems = new List<string> { "pizza", "cola" },
|
||||
// Comment = "Cola zero please"
|
||||
// },
|
||||
// new OrderItem
|
||||
// {
|
||||
// Number = 2,
|
||||
// Name = "Classic Beef Burger",
|
||||
// Quantity = 1,
|
||||
// Modifications = new ItemModifications
|
||||
// {
|
||||
// Removed = new List<string> { "Onion" },
|
||||
// Added = new List<string> { "butter" }
|
||||
// },
|
||||
// Comment = "Medium rare please"
|
||||
// },
|
||||
// new OrderItem
|
||||
// {
|
||||
// Number = 3,
|
||||
// Name = "Margherita Pizza Classic",
|
||||
// Quantity = 2,
|
||||
// Size = "L"
|
||||
// }
|
||||
// }
|
||||
//};
|
||||
|
||||
//var serializedOrderItems = JsonSerializer.Serialize(orderItemsReceipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
//Console.WriteLine(serializedOrderItems);
|
||||
//var deserializedOrderItems = JsonSerializer.Deserialize<OrderItemsReceipt>(serializedOrderItems);
|
||||
|
||||
//var orderItemsConverter = new Inspectron.Epson.PrintServer.Printers.Utils.OrderItems.ReceiptConverter(lineWidth: 50, bigFontLineWidth: 21);
|
||||
//var printCommands = orderItemsConverter.ConvertToPrintCommands(deserializedOrderItems);
|
||||
|
||||
//Console.WriteLine("=== PRINT COMMANDS ===\n");
|
||||
//var printer = new HtmlPrinter(@".\order_items.html", paperWidth: 384);
|
||||
//await printer.ConnectAsync("");
|
||||
//await Task.Delay(200);
|
||||
////await printer.FeedLinesAsync(1);
|
||||
//await printer.SetCustomLineSpacing(22);
|
||||
//foreach (var command in printCommands)
|
||||
//{
|
||||
// string attributes = "";
|
||||
// if (command.IsBig) attributes += "[BIG] ";
|
||||
// if (command.IsBold) attributes += "[BOLD] ";
|
||||
|
||||
// Console.WriteLine($"{attributes}{command.Text}");
|
||||
|
||||
// if (command.IsBig)
|
||||
// {
|
||||
// await printer.SetFontSizeAsync(2, 1);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// await printer.SetFontSizeAsync(1, 1);
|
||||
// }
|
||||
// //await Task.Delay(200);
|
||||
|
||||
// await printer.SetEmphasized(command.IsBold);
|
||||
// //await Task.Delay(200);
|
||||
|
||||
// await printer.PrintTextAsync(command.Text + "\n");
|
||||
// //await Task.Delay(200);
|
||||
|
||||
//}
|
||||
|
||||
|
||||
|
||||
@@ -417,7 +513,10 @@ foreach (var command in printCommands)
|
||||
//await Task.Delay(2000);
|
||||
//await printer.PrintBuffer();
|
||||
|
||||
//await printer.SendRawCommandAsync([0x1b,0x21,0x10+0x21]);
|
||||
//var printer = new EpsonPrinter();
|
||||
//await printer.ConnectAsync("127.0.0.1", 8888);
|
||||
//await printer.InitAsync();
|
||||
|
||||
//await printer.PrintTextAsync("Hello!");
|
||||
//await printer.FeedLinesAsync(5);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user