v1.0.0
This commit is contained in:
@@ -35,7 +35,7 @@ public class TM_U220IITranslated : IPrinter
|
||||
{
|
||||
foreach (var command in commands)
|
||||
{
|
||||
await _printer.SetBiggerFontTM220(command.IsBig);
|
||||
await _printer.SetBiggerFontTM220(command.IsBig, command.IsTall | command.IsBig);
|
||||
await Task.Delay(200);
|
||||
await _printer.SetRedColor(command.IsRed);
|
||||
await Task.Delay(200);
|
||||
|
||||
@@ -9,7 +9,7 @@ public class FinalReceipt
|
||||
public string ReceiptNumber { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public int Guests { get; set; }
|
||||
public List<ReceiptItem> Items { get; set; } = new List<ReceiptItem>();
|
||||
public List<FinalReceiptItem> Items { get; set; } = new List<FinalReceiptItem>();
|
||||
public decimal Total { get; set; }
|
||||
public string Currency { get; set; }
|
||||
public decimal? TotalInAlternateCurrency { get; set; }
|
||||
@@ -28,7 +28,7 @@ public class FinalReceipt
|
||||
public List<PaymentTerminalReceipt> TerminalReceipts { get; set; } = new List<PaymentTerminalReceipt>();
|
||||
}
|
||||
|
||||
public class ReceiptItem
|
||||
public class FinalReceiptItem
|
||||
{
|
||||
public int Quantity { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Inspectron.Epson.PrintServer.Printers.Utils.InvoiceReceipt;
|
||||
|
||||
public class InvoiceReceiptConverter : IReceiptConverter
|
||||
{
|
||||
private readonly int _lineWidth;
|
||||
private readonly int _bigFontLineWidth;
|
||||
|
||||
public InvoiceReceiptConverter(int lineWidth, int bigFontLineWidth)
|
||||
{
|
||||
_lineWidth = lineWidth;
|
||||
_bigFontLineWidth = bigFontLineWidth;
|
||||
}
|
||||
|
||||
public List<PrintCommand> Convert(string jsonContent)
|
||||
{
|
||||
var receipt = JsonSerializer.Deserialize<InvoiceReceipt>(jsonContent);
|
||||
var converter = new ReceiptConverter(_lineWidth, _bigFontLineWidth);
|
||||
return converter.ConvertToPrintCommands(receipt);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Inspectron.Epson.PrintServer.Printers.Utils.InvoiceReceipt;
|
||||
|
||||
public class InvoiceReceipt
|
||||
{
|
||||
public string CompanyName { get; set; }
|
||||
public string Address1 { get; set; }
|
||||
public string Address2 { get; set; }
|
||||
public string Phone { get; set; }
|
||||
public string ReceiptNumber { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public int Guests { get; set; }
|
||||
public List<ReceiptItem> Items { get; set; } = new List<ReceiptItem>();
|
||||
public decimal Total { get; set; }
|
||||
public string Currency { get; set; }
|
||||
}
|
||||
|
||||
public class ReceiptItem
|
||||
{
|
||||
public int Quantity { get; set; }
|
||||
public string Description { get; set; }
|
||||
public decimal UnitPrice { get; set; }
|
||||
public decimal TotalPrice { get; set; }
|
||||
public string TaxCategory { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
namespace Inspectron.Epson.PrintServer.Printers.Utils.InvoiceReceipt;
|
||||
|
||||
public class ReceiptConverter
|
||||
{
|
||||
private readonly int _lineWidth;
|
||||
private readonly int _bigFontLineWidth;
|
||||
|
||||
public ReceiptConverter(int lineWidth = 42, int bigFontLineWidth = 21)
|
||||
{
|
||||
_lineWidth = lineWidth;
|
||||
_bigFontLineWidth = bigFontLineWidth;
|
||||
}
|
||||
|
||||
public List<PrintCommand> ConvertToPrintCommands(InvoiceReceipt invoiceReceipt)
|
||||
{
|
||||
var commands = new List<PrintCommand>();
|
||||
|
||||
// Header - Company info
|
||||
commands.Add(new PrintCommand(Center(invoiceReceipt.CompanyName, false)));
|
||||
commands.Add(new PrintCommand(Center(invoiceReceipt.Address1, false)));
|
||||
commands.Add(new PrintCommand(Center(invoiceReceipt.Address2, false)));
|
||||
commands.Add(new PrintCommand(Center(invoiceReceipt.Phone, false)));
|
||||
commands.Add(new PrintCommand(""));
|
||||
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);
|
||||
commands.Add(new PrintCommand(receiptLine,isBold:true));
|
||||
commands.Add(new PrintCommand($"Guests: {invoiceReceipt.Guests}"));
|
||||
commands.Add(new PrintCommand(""));
|
||||
|
||||
// Items
|
||||
foreach (var item in invoiceReceipt.Items)
|
||||
{
|
||||
string quantityDesc = $"{item.Quantity}x {item.Description}";
|
||||
string prices = $"{item.UnitPrice:F2}"+$"{item.TotalPrice:F2}".PadLeft(7)+$" {item.TaxCategory}";
|
||||
|
||||
// Calculate spacing to align prices to the right
|
||||
int spacesNeeded = _lineWidth - quantityDesc.Length - prices.Length;
|
||||
if (spacesNeeded < 1) spacesNeeded = 1;
|
||||
|
||||
string itemLine = quantityDesc + new string(' ', spacesNeeded) + prices;
|
||||
commands.Add(new PrintCommand(itemLine));
|
||||
}
|
||||
|
||||
commands.Add(new PrintCommand(""));
|
||||
commands.Add(new PrintCommand("---------".PadLeft(_lineWidth)));
|
||||
commands.Add(new PrintCommand(""));
|
||||
|
||||
// Total
|
||||
string totalLine = $"Summe: {invoiceReceipt.Total:F2} {invoiceReceipt.Currency}";
|
||||
commands.Add(new PrintCommand(Center(totalLine, true), true, true));
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
private string Center(string text, bool isBigFont)
|
||||
{
|
||||
int effectiveLineWidth = isBigFont ? _bigFontLineWidth : _lineWidth;
|
||||
|
||||
if (string.IsNullOrEmpty(text) || text.Length >= effectiveLineWidth)
|
||||
return text;
|
||||
|
||||
int totalPadding = effectiveLineWidth - text.Length;
|
||||
int leftPadding = totalPadding / 2;
|
||||
|
||||
return new string(' ', leftPadding) + text;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.InvoiceReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.OrderItems;
|
||||
|
||||
namespace Inspectron.Epson.PrintServer.Printers.Utils;
|
||||
@@ -17,14 +18,17 @@ public class ReceiptConverterFactory : IReceiptConverterFactory
|
||||
},
|
||||
EReceiptType.NextCourse => new KitchenReceipt.KitchenReceiptConverterAdapter(33, 20),
|
||||
EReceiptType.OrdersOverview => new OrderItemsReceiptConverter(48, 24),
|
||||
EReceiptType.Invoice => new InvoiceReceiptConverter(48, 24),
|
||||
_ => throw new ArgumentException($"Unknown receipt type: {receiptType}")
|
||||
};
|
||||
}
|
||||
|
||||
public enum EReceiptType
|
||||
{
|
||||
Receipt,
|
||||
WorkareaTicket,
|
||||
NextCourse,
|
||||
OrdersOverview
|
||||
OrdersOverview,
|
||||
Invoice
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user