bar receipt
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.KitchenReceipt;
|
||||
|
||||
namespace Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt;
|
||||
|
||||
public class BarReceiptConverter
|
||||
{
|
||||
private readonly int _lineWidth;
|
||||
private readonly int _BigLineWidth;
|
||||
|
||||
public BarReceiptConverter(int lineWidth = 42, int bigLineWidth=22)
|
||||
{
|
||||
_BigLineWidth = bigLineWidth;
|
||||
_lineWidth = lineWidth;
|
||||
}
|
||||
|
||||
public List<PrintCommand> ConvertToPrintCommands(BarReceipt kitchenReceipt)
|
||||
{
|
||||
var commands = new List<PrintCommand>();
|
||||
|
||||
// Header - Restaurant name in red
|
||||
commands.Add(new PrintCommand(Center(kitchenReceipt.Title, true)) { IsRed = true, IsBig = true });
|
||||
commands.Add(new PrintCommand(CreateDashedLine()));
|
||||
commands.Add(new PrintCommand(""));
|
||||
|
||||
// Transaction info
|
||||
string dateTimeLine = $"{kitchenReceipt.TransactionDateTime:dd-MMM-yy HH:mm} Nr.:{kitchenReceipt.ReceiptNumber}";
|
||||
commands.Add(new PrintCommand(Center(dateTimeLine, false)));
|
||||
|
||||
string serverLine = $"{kitchenReceipt.WaiterName}";
|
||||
commands.Add(new PrintCommand(Center(serverLine, false)));
|
||||
|
||||
string serverIdLine = $"{kitchenReceipt.WaiterId}";
|
||||
commands.Add(new PrintCommand(Center(serverIdLine, false)));
|
||||
|
||||
string tableLine = $"Tisch: {kitchenReceipt.TableNumber}";
|
||||
commands.Add(new PrintCommand(Center(tableLine, true), true, true));
|
||||
|
||||
if (!string.IsNullOrEmpty(kitchenReceipt.SpecialInstruction))
|
||||
{
|
||||
commands.Add(new PrintCommand(""));
|
||||
commands.Add(new PrintCommand(Center(kitchenReceipt.SpecialInstruction, true), true, true));
|
||||
commands.Add(new PrintCommand(""));
|
||||
}
|
||||
|
||||
commands.Add(new PrintCommand(CreateDashedLine()));
|
||||
|
||||
|
||||
|
||||
|
||||
// Gangs
|
||||
|
||||
foreach (Gang gang in kitchenReceipt.Gangs)
|
||||
{
|
||||
|
||||
commands.Add(new PrintCommand(Center($"{gang.Id}. {gang.Name}", false)) { IsRed = true });
|
||||
foreach (var dish in gang.Dishes)
|
||||
{
|
||||
PrintDish(dish, commands);
|
||||
}
|
||||
}
|
||||
|
||||
if (kitchenReceipt.Gangs.Count > 0)
|
||||
{
|
||||
commands.Add(new PrintCommand(CreateDashedLine()));
|
||||
}
|
||||
|
||||
foreach (var dish in kitchenReceipt.Dishes)
|
||||
{
|
||||
PrintDish(dish, commands);
|
||||
}
|
||||
|
||||
if (kitchenReceipt.Dishes != null && kitchenReceipt.Dishes.Any())
|
||||
{
|
||||
commands.Add(new PrintCommand(""));
|
||||
commands.Add(new PrintCommand(CreateDashedLine()));
|
||||
commands.Add(new PrintCommand(""));
|
||||
}
|
||||
|
||||
|
||||
//// Additional info section
|
||||
//if (kitchenReceipt.AdditionalInfo != null && kitchenReceipt.AdditionalInfo.Count > 0)
|
||||
//{
|
||||
// commands.Add(new PrintCommand(CreateAsterisksLine()));
|
||||
// commands.Add(new PrintCommand("Info über zugehörige Artikel"));
|
||||
// commands.Add(new PrintCommand(CreateAsterisksLine()));
|
||||
|
||||
// foreach (var info in kitchenReceipt.AdditionalInfo)
|
||||
// {
|
||||
// commands.Add(new PrintCommand(info));
|
||||
// }
|
||||
|
||||
// commands.Add(new PrintCommand(""));
|
||||
//}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
private static void PrintDish(Dish drink, List<PrintCommand> commands)
|
||||
{
|
||||
string drinkLine = $"{drink.Number}x {drink.Name}";
|
||||
commands.Add(new PrintCommand(drinkLine));
|
||||
// Modifications
|
||||
if (drink.Modifications != null && (drink.Modifications.Removed.Any() || drink.Modifications.Added.Any()))
|
||||
{
|
||||
foreach (var removed in drink.Modifications.Removed)
|
||||
{
|
||||
commands.Add(new PrintCommand($" - {removed}", isBold:true));
|
||||
}
|
||||
|
||||
foreach (var added in drink.Modifications.Added)
|
||||
{
|
||||
commands.Add(new PrintCommand($" + {added}", isBold: true));
|
||||
}
|
||||
}
|
||||
|
||||
// SpecialInstruction
|
||||
if (!string.IsNullOrEmpty(drink.Comment))
|
||||
{
|
||||
commands.Add(new PrintCommand($" Comment: {drink.Comment}", isBold: true));
|
||||
}
|
||||
|
||||
commands.Add(new PrintCommand("")); // Extra line between drinks for bar
|
||||
}
|
||||
|
||||
private string Center(string text, bool isBigFont)
|
||||
{
|
||||
var actualLineWidth = isBigFont ? _BigLineWidth : _lineWidth;
|
||||
if (string.IsNullOrEmpty(text) || text.Length >= actualLineWidth)
|
||||
return text;
|
||||
|
||||
int totalPadding = actualLineWidth - text.Length;
|
||||
int leftPadding = totalPadding / 2;
|
||||
|
||||
return new string(' ', leftPadding) + text;
|
||||
}
|
||||
|
||||
private string CreateDashedLine()
|
||||
{
|
||||
return new string('-', _lineWidth);
|
||||
}
|
||||
|
||||
private string CreateAsterisksLine()
|
||||
{
|
||||
return new string('*', _lineWidth);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt;
|
||||
|
||||
public class BarReceiptConverterAdapter : IReceiptConverter
|
||||
{
|
||||
private readonly int _lineWidth;
|
||||
private readonly int _bigFontLineWidth;
|
||||
|
||||
public BarReceiptConverterAdapter(int lineWidth, int bigFontLineWidth)
|
||||
{
|
||||
_lineWidth = lineWidth;
|
||||
_bigFontLineWidth = bigFontLineWidth;
|
||||
}
|
||||
|
||||
public List<PrintCommand> Convert(string jsonContent)
|
||||
{
|
||||
var receipt = JsonSerializer.Deserialize<BarReceipt>(jsonContent);
|
||||
var converter = new BarReceiptConverter(_lineWidth, _bigFontLineWidth);
|
||||
return converter.ConvertToPrintCommands(receipt);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
namespace Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt
|
||||
{
|
||||
|
||||
public class BarReceipt
|
||||
{
|
||||
/// <summary>
|
||||
/// Restaurant name
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date and time of the transaction
|
||||
/// </summary>
|
||||
public DateTime TransactionDateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Receipt number
|
||||
/// </summary>
|
||||
public string ReceiptNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Server/Waiter name
|
||||
/// </summary>
|
||||
public string WaiterName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Server/Waiter ID
|
||||
/// </summary>
|
||||
public string WaiterId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Table number
|
||||
/// </summary>
|
||||
public string TableNumber { get; set; }
|
||||
|
||||
public string SpecialInstruction { get; set; }
|
||||
|
||||
public List<Gang> Gangs { get; set; } = new List<Gang>();
|
||||
|
||||
public List<Dish> Dishes { get; set; } = new List<Dish>();
|
||||
|
||||
|
||||
public BarReceipt()
|
||||
{
|
||||
Gangs = new List<Gang>();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Gang
|
||||
{
|
||||
public Gang(int id, string name)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public List<Dish> Dishes { get; set; } = new List<Dish>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a dish item on the receipt
|
||||
/// </summary>
|
||||
public class Dish
|
||||
{
|
||||
/// <summary>
|
||||
/// Number ordered
|
||||
/// </summary>
|
||||
public int Number { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the dish
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
public Dish() { }
|
||||
|
||||
public Dish(int number, string name)
|
||||
{
|
||||
Number = number;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public DishModifications Modifications { get; set; } = new DishModifications();
|
||||
public string? Comment { get; set; }
|
||||
}
|
||||
|
||||
public class DishModifications
|
||||
{
|
||||
public List<string> Removed { get; set; } = new List<string>();
|
||||
public List<string> Added { get; set; } = new List<string>();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ public class PrintCommand
|
||||
public bool IsBig { get; set; }
|
||||
public bool IsBold { get; set; }
|
||||
public bool IsRed { get; set; }
|
||||
|
||||
public int? SetLineSpacing { get; set; }=null;
|
||||
public PrintCommand(string text, bool isBig = false, bool isBold = false)
|
||||
{
|
||||
Text = text;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.OrderItems;
|
||||
|
||||
namespace Inspectron.Epson.PrintServer.Printers.Utils;
|
||||
@@ -11,7 +12,7 @@ public class ReceiptConverterFactory : IReceiptConverterFactory
|
||||
EReceiptType.Receipt => new FinalReceipt.FinalReceiptConverter(48, 24),
|
||||
EReceiptType.WorkareaTicket => printerId switch
|
||||
{
|
||||
0x01=>new KitchenReceipt.KitchenReceiptConverterAdapter(48, 24),
|
||||
0x01=>new BarReceiptConverterAdapter(48, 24),
|
||||
_=> new KitchenReceipt.KitchenReceiptConverterAdapter(33, 20),
|
||||
},
|
||||
EReceiptType.NextCourse => new KitchenReceipt.KitchenReceiptConverterAdapter(33, 20),
|
||||
|
||||
Reference in New Issue
Block a user