discount
This commit is contained in:
56
Inspectron.Epson/PreconfiguredDiscoveryService.cs
Normal file
56
Inspectron.Epson/PreconfiguredDiscoveryService.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
namespace Inspectron.Epson;
|
||||
|
||||
/// <summary>
|
||||
/// Discovery service that returns preconfigured printers instead of performing network discovery
|
||||
/// </summary>
|
||||
public class PreconfiguredDiscoveryService : IDiscoveryService
|
||||
{
|
||||
private readonly List<DiscoveredPrinter> _printers = new();
|
||||
|
||||
public void AddPrinter(string ipAddress, string? modelName = null, int port = 9100)
|
||||
{
|
||||
_printers.Add(new DiscoveredPrinter
|
||||
{
|
||||
IPAddress = ipAddress,
|
||||
ModelName = modelName ?? "Unknown",
|
||||
Port = port,
|
||||
DiscoveredAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
|
||||
public void RemovePrinter(string ipAddress)
|
||||
{
|
||||
_printers.RemoveAll(p => p.IPAddress == ipAddress);
|
||||
}
|
||||
|
||||
public void ClearPrinters()
|
||||
{
|
||||
_printers.Clear();
|
||||
}
|
||||
|
||||
public Task<List<DiscoveredPrinter>> DiscoverPrintersAsync(
|
||||
TimeSpan? timeout = null,
|
||||
Action<DiscoveredPrinter>? onPrinterDiscovered = null)
|
||||
{
|
||||
var results = _printers.Select(p => new DiscoveredPrinter
|
||||
{
|
||||
IPAddress = p.IPAddress,
|
||||
ModelName = p.ModelName,
|
||||
Port = p.Port,
|
||||
MACAddress = p.MACAddress,
|
||||
ServiceUrl = p.ServiceUrl,
|
||||
ServiceType = p.ServiceType,
|
||||
Lifetime = p.Lifetime,
|
||||
RawResponse = p.RawResponse,
|
||||
DiscoveredAt = DateTime.UtcNow
|
||||
}).ToList();
|
||||
|
||||
if (onPrinterDiscovered != null)
|
||||
{
|
||||
foreach (var printer in results)
|
||||
onPrinterDiscovered(printer);
|
||||
}
|
||||
|
||||
return Task.FromResult(results);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ public class SignalRPrintJobSource: IPrintJobSource
|
||||
|
||||
// Register handlers BEFORE starting connection
|
||||
_connection.On<PrintJobFromSignalR>("PrintJob", OnPrintJobReceived);
|
||||
|
||||
|
||||
_connection.Reconnecting += OnReconnecting;
|
||||
_connection.Reconnected += OnReconnected;
|
||||
|
||||
@@ -98,7 +98,7 @@ public class BarReceiptConverter
|
||||
private static void PrintDish(Dish drink, List<PrintCommand> commands)
|
||||
{
|
||||
string drinkLine = $"{drink.Number}x {drink.Name}";
|
||||
commands.Add(new PrintCommand(drinkLine));
|
||||
commands.Add(new PrintCommand(drinkLine,isBig:true));
|
||||
// Modifications
|
||||
if (drink.Modifications != null && (drink.Modifications.Removed.Any() || drink.Modifications.Added.Any()))
|
||||
{
|
||||
|
||||
@@ -35,8 +35,7 @@ public class DiscountInfo
|
||||
public string Description { get; set; }
|
||||
public decimal Amount { get; set; }
|
||||
public string Currency { get; set; }
|
||||
public decimal? AmountInAlternateCurrency { get; set; }
|
||||
public string AlternateCurrency { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class FinalReceiptItem
|
||||
|
||||
@@ -64,6 +64,8 @@ public class ReceiptConverter
|
||||
commands.Add(new PrintCommand("---------".PadLeft(_lineWidth)));
|
||||
commands.Add(new PrintCommand("")); //Reini
|
||||
|
||||
|
||||
|
||||
// Total
|
||||
string totalLine = $"Summe: {finalReceipt.Total:F2} {finalReceipt.Currency}";
|
||||
commands.Add(new PrintCommand(Center(totalLine, true), true, true));
|
||||
@@ -78,12 +80,12 @@ public class ReceiptConverter
|
||||
}
|
||||
|
||||
// Discount
|
||||
//if (finalReceipt.DiscountInfo != null && finalReceipt.DiscountInfo.Amount > 0)
|
||||
//{
|
||||
|
||||
// commands.Add(new PrintCommand(finalReceipt.DiscountInfo.Description.PadLeft(_lineWidth/2)));
|
||||
// commands.Add(new PrintCommand(""));
|
||||
//}
|
||||
if (finalReceipt.DiscountInfo != null)
|
||||
{
|
||||
|
||||
commands.Add(new PrintCommand(finalReceipt.DiscountInfo.Description.PadRight(_lineWidth / 2) + (finalReceipt.DiscountInfo.Amount.ToString("F2") + " " + finalReceipt.DiscountInfo.Currency).PadLeft(_lineWidth / 2)));
|
||||
commands.Add(new PrintCommand(""));
|
||||
}
|
||||
|
||||
// Split payments
|
||||
if (finalReceipt.SplitPayments != null && finalReceipt.SplitPayments.Count > 0)
|
||||
|
||||
Reference in New Issue
Block a user