klinglers special
This commit is contained in:
@@ -99,6 +99,7 @@ public class KitchenReceiptConverterKlinglers
|
||||
if (!string.IsNullOrEmpty(dish.Size)) return false;
|
||||
if (!string.IsNullOrEmpty(dish.Comment)) return false;
|
||||
if (dish.Modifications != null && (dish.Modifications.Removed.Any() || dish.Modifications.Added.Any())) return false;
|
||||
if (dish.Price != null) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -117,11 +118,11 @@ public class KitchenReceiptConverterKlinglers
|
||||
int totalQuantity = group.Sum(d => d.Number);
|
||||
var guestIds = group
|
||||
.Where(d => d.GuestId.HasValue)
|
||||
.Select(d => d.GuestId.Value)
|
||||
.SelectMany(d => Enumerable.Repeat(d.GuestId!.Value, d.Number))
|
||||
.OrderBy(id => id)
|
||||
.ToList();
|
||||
|
||||
PrintDishLine($"{totalQuantity}x ", group.Key, null, commands);
|
||||
PrintDishLine($"{totalQuantity}x ", group.Key, null, null, commands);
|
||||
|
||||
if (guestIds.Any())
|
||||
{
|
||||
@@ -133,7 +134,7 @@ public class KitchenReceiptConverterKlinglers
|
||||
// Print individual dishes (have size, modifications, or comment)
|
||||
foreach (var dish in individual)
|
||||
{
|
||||
PrintDishLine($"{dish.Number}x ", dish.Name, dish.Size, commands);
|
||||
PrintDishLine($"{dish.Number}x ", dish.Name, dish.Size, dish.Price, commands);
|
||||
|
||||
if (dish.GuestId.HasValue)
|
||||
{
|
||||
@@ -160,67 +161,88 @@ public class KitchenReceiptConverterKlinglers
|
||||
}
|
||||
}
|
||||
|
||||
private void PrintDishLine(string quantityPrefix, string dishName, string? size, List<PrintCommand> commands)
|
||||
private void PrintDishLine(string quantityPrefix, string dishName, string? size, decimal? price, List<PrintCommand> commands)
|
||||
{
|
||||
string fullLine = quantityPrefix + dishName;
|
||||
string? priceStr = price != null ? price.Value.ToString("0.00") : null;
|
||||
|
||||
string nameWithSize = dishName;
|
||||
if (!string.IsNullOrEmpty(size))
|
||||
{
|
||||
fullLine += $" ({size})";
|
||||
nameWithSize += $" ({size})";
|
||||
}
|
||||
|
||||
if (fullLine.Length <= _lineWidth || string.IsNullOrEmpty(dishName))
|
||||
int firstLineNameWidth = _lineWidth - quantityPrefix.Length - 6;
|
||||
if (priceStr != null)
|
||||
{
|
||||
commands.Add(new PrintCommand(fullLine) { IsTall = true });
|
||||
firstLineNameWidth -= priceStr.Length + 1;
|
||||
}
|
||||
else
|
||||
int continuationNameWidth = _lineWidth - quantityPrefix.Length - 6;
|
||||
|
||||
// Simple case: name fits on first line
|
||||
if (nameWithSize.Length <= firstLineNameWidth || string.IsNullOrEmpty(dishName))
|
||||
{
|
||||
int availableWidth = _lineWidth - quantityPrefix.Length;
|
||||
if (availableWidth <= 0)
|
||||
string line = quantityPrefix + nameWithSize;
|
||||
if (priceStr != null)
|
||||
{
|
||||
commands.Add(new PrintCommand(fullLine) { IsTall = true });
|
||||
int padding = _lineWidth - line.Length - priceStr.Length;
|
||||
line += new string(' ', Math.Max(1, padding)) + priceStr;
|
||||
}
|
||||
commands.Add(new PrintCommand(line) { IsTall = true });
|
||||
return;
|
||||
}
|
||||
|
||||
if (firstLineNameWidth <= 0)
|
||||
{
|
||||
string line = quantityPrefix + nameWithSize;
|
||||
if (priceStr != null) line += " " + priceStr;
|
||||
commands.Add(new PrintCommand(line) { IsTall = true });
|
||||
return;
|
||||
}
|
||||
|
||||
// Word wrap
|
||||
var words = nameWithSize.Split(' ');
|
||||
var lines = new List<string>();
|
||||
string currentLine = "";
|
||||
int currentMaxWidth = firstLineNameWidth;
|
||||
|
||||
foreach (var word in words)
|
||||
{
|
||||
if (currentLine.Length == 0)
|
||||
{
|
||||
currentLine = word;
|
||||
}
|
||||
else if (currentLine.Length + 1 + word.Length <= currentMaxWidth)
|
||||
{
|
||||
currentLine += " " + word;
|
||||
}
|
||||
else
|
||||
{
|
||||
string nameWithSize = dishName;
|
||||
if (!string.IsNullOrEmpty(size))
|
||||
{
|
||||
nameWithSize += $" ({size})";
|
||||
}
|
||||
var words = nameWithSize.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 <= availableWidth)
|
||||
{
|
||||
currentLine += " " + word;
|
||||
}
|
||||
else
|
||||
{
|
||||
lines.Add(currentLine);
|
||||
currentLine = word;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentLine.Length > 0)
|
||||
{
|
||||
lines.Add(currentLine);
|
||||
}
|
||||
|
||||
commands.Add(new PrintCommand(quantityPrefix + lines[0]) { IsTall = true });
|
||||
string indent = new string(' ', quantityPrefix.Length);
|
||||
for (int i = 1; i < lines.Count; i++)
|
||||
{
|
||||
commands.Add(new PrintCommand(indent + lines[i]) { IsTall = true });
|
||||
}
|
||||
lines.Add(currentLine);
|
||||
currentLine = word;
|
||||
currentMaxWidth = continuationNameWidth;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentLine.Length > 0)
|
||||
{
|
||||
lines.Add(currentLine);
|
||||
}
|
||||
|
||||
// First line with prefix and optional right-aligned price
|
||||
string firstLine = quantityPrefix + lines[0];
|
||||
if (priceStr != null)
|
||||
{
|
||||
int padding = _lineWidth - firstLine.Length - priceStr.Length;
|
||||
firstLine += new string(' ', Math.Max(1, padding)) + priceStr;
|
||||
}
|
||||
commands.Add(new PrintCommand(firstLine) { IsTall = true });
|
||||
|
||||
// Continuation lines
|
||||
string indent = new string(' ', quantityPrefix.Length);
|
||||
for (int i = 1; i < lines.Count; i++)
|
||||
{
|
||||
commands.Add(new PrintCommand(indent + lines[i]) { IsTall = true });
|
||||
}
|
||||
}
|
||||
|
||||
private string Center(string text, bool isBigFont)
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
|
||||
public DishModifications Modifications { get; set; } = new DishModifications();
|
||||
public string? Comment { get; set; }
|
||||
public decimal? Price { get; set; }
|
||||
}
|
||||
|
||||
public class DishModifications
|
||||
|
||||
Reference in New Issue
Block a user