klinglers special
This commit is contained in:
@@ -43,24 +43,7 @@ public class ReceiptConverter
|
||||
// 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));
|
||||
|
||||
// SubItems
|
||||
if (item.SubItems != null)
|
||||
{
|
||||
foreach (var subItem in item.SubItems)
|
||||
{
|
||||
commands.Add(new PrintCommand($" - {subItem}"));
|
||||
}
|
||||
}
|
||||
PrintItem(item, commands);
|
||||
}
|
||||
|
||||
commands.Add(new PrintCommand(""));
|
||||
@@ -70,12 +53,96 @@ 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(""));
|
||||
commands.Add(new PrintCommand(Center($"Tisch: {invoiceReceipt.TableNumber}",false), false));
|
||||
commands.Add(new PrintCommand(Center(invoiceReceipt.ThankYouMessage, false)));
|
||||
commands.Add(new PrintCommand(""));
|
||||
commands.Add(new PrintCommand(Center("Zwischenrechnung", false),isBold:true));
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
private void PrintItem(ReceiptItem item, List<PrintCommand> commands)
|
||||
{
|
||||
string quantityPrefix = $"{item.Quantity}x ";
|
||||
string prices = $"{item.UnitPrice:F2}" + $"{item.TotalPrice:F2}".PadLeft(7) + $" {item.TaxCategory}";
|
||||
string fullLine = quantityPrefix + item.Description;
|
||||
|
||||
int spacesNeeded = _lineWidth - fullLine.Length - prices.Length;
|
||||
|
||||
if (spacesNeeded >= 1 || string.IsNullOrEmpty(item.Description))
|
||||
{
|
||||
if (spacesNeeded < 1) spacesNeeded = 1;
|
||||
commands.Add(new PrintCommand(fullLine + new string(' ', spacesNeeded) + prices));
|
||||
}
|
||||
else
|
||||
{
|
||||
int descriptionAvailable = _lineWidth - quantityPrefix.Length - prices.Length - 1;
|
||||
|
||||
if (descriptionAvailable <= 0)
|
||||
{
|
||||
commands.Add(new PrintCommand(fullLine));
|
||||
}
|
||||
else
|
||||
{
|
||||
var words = item.Description.Split(' ');
|
||||
var lines = new List<string>();
|
||||
string currentLine = "";
|
||||
|
||||
foreach (var word in words)
|
||||
{
|
||||
if (currentLine.Length == 0)
|
||||
{
|
||||
currentLine = word;
|
||||
}
|
||||
else if (currentLine.Length + 1 + word.Length <= descriptionAvailable)
|
||||
{
|
||||
currentLine += " " + word;
|
||||
}
|
||||
else
|
||||
{
|
||||
lines.Add(currentLine);
|
||||
currentLine = word;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentLine.Length > 0)
|
||||
{
|
||||
lines.Add(currentLine);
|
||||
}
|
||||
|
||||
// First line with prefix and right-aligned prices
|
||||
string firstLineText = quantityPrefix + lines[0];
|
||||
int firstSpaces = _lineWidth - firstLineText.Length - prices.Length;
|
||||
if (firstSpaces >= 1)
|
||||
{
|
||||
commands.Add(new PrintCommand(firstLineText + new string(' ', firstSpaces) + prices));
|
||||
}
|
||||
else
|
||||
{
|
||||
commands.Add(new PrintCommand(firstLineText));
|
||||
commands.Add(new PrintCommand(prices.PadLeft(_lineWidth)));
|
||||
}
|
||||
|
||||
// Continuation lines indented to align with description
|
||||
string continuationIndent = new string(' ', quantityPrefix.Length);
|
||||
for (int i = 1; i < lines.Count; i++)
|
||||
{
|
||||
commands.Add(new PrintCommand(continuationIndent + lines[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SubItems
|
||||
if (item.SubItems != null)
|
||||
{
|
||||
foreach (var subItem in item.SubItems)
|
||||
{
|
||||
commands.Add(new PrintCommand($" - {subItem}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string Center(string text, bool isBigFont)
|
||||
{
|
||||
int effectiveLineWidth = isBigFont ? _bigFontLineWidth : _lineWidth;
|
||||
|
||||
Reference in New Issue
Block a user