add money return / credit note receipt type with HTML test
This commit is contained in:
@@ -3,9 +3,28 @@ using Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.FinalReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.InvoiceReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.KitchenReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.MoneyReturnReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.OrderItems;
|
||||
using System.Text.Json;
|
||||
|
||||
// Non-interactive mode: `dotnet run -- <receiptType> [html|epson]`
|
||||
// receiptType: kitchen | final | invoice | bar | orderitems | moneyreturn (or 0-5)
|
||||
if (args.Length > 0)
|
||||
{
|
||||
int rt = ParseReceiptTypeArg(args[0]);
|
||||
if (rt < 0)
|
||||
{
|
||||
Console.WriteLine($"Unknown receipt type: {args[0]}");
|
||||
return;
|
||||
}
|
||||
|
||||
int pt = args.Length > 1 && args[1].Equals("epson", StringComparison.OrdinalIgnoreCase) ? 1 : 0;
|
||||
Console.WriteLine($"Running {GetReceiptTypeName(rt)} on {(pt == 0 ? "HTML" : "Epson")} printer...\n");
|
||||
await RunTest(rt, pt);
|
||||
Console.WriteLine("\nDone.");
|
||||
return;
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
Console.Clear();
|
||||
@@ -18,10 +37,11 @@ while (true)
|
||||
"InvoiceReceipt",
|
||||
"BarReceipt",
|
||||
"OrderItems",
|
||||
"MoneyReturnReceipt",
|
||||
"Exit"
|
||||
});
|
||||
|
||||
if (receiptType == 5) break;
|
||||
if (receiptType == 6) break;
|
||||
|
||||
var printerTarget = ShowMenu("Select printer target:", new[]
|
||||
{
|
||||
@@ -96,9 +116,21 @@ static string GetReceiptTypeName(int index) => index switch
|
||||
2 => "InvoiceReceipt",
|
||||
3 => "BarReceipt",
|
||||
4 => "OrderItems",
|
||||
5 => "MoneyReturnReceipt",
|
||||
_ => "Unknown"
|
||||
};
|
||||
|
||||
static int ParseReceiptTypeArg(string arg) => arg.ToLowerInvariant() switch
|
||||
{
|
||||
"0" or "kitchen" or "kitchenreceipt" => 0,
|
||||
"1" or "final" or "finalreceipt" => 1,
|
||||
"2" or "invoice" or "invoicereceipt" => 2,
|
||||
"3" or "bar" or "barreceipt" => 3,
|
||||
"4" or "orderitems" => 4,
|
||||
"5" or "moneyreturn" or "moneyreturnreceipt" or "refund" or "creditnote" => 5,
|
||||
_ => -1
|
||||
};
|
||||
|
||||
static async Task RunTest(int receiptType, int printerTarget)
|
||||
{
|
||||
switch (receiptType)
|
||||
@@ -108,6 +140,7 @@ static async Task RunTest(int receiptType, int printerTarget)
|
||||
case 2: await RunInvoiceReceiptTest(printerTarget); break;
|
||||
case 3: await RunBarReceiptTest(printerTarget); break;
|
||||
case 4: await RunOrderItemsTest(printerTarget); break;
|
||||
case 5: await RunMoneyReturnReceiptTest(printerTarget); break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,3 +268,29 @@ static async Task RunOrderItemsTest(int printerTarget)
|
||||
await TestHelpers.PrintCommandsToEpsonPrinterAsync(printer, printCommands);
|
||||
}
|
||||
}
|
||||
|
||||
static async Task RunMoneyReturnReceiptTest(int printerTarget)
|
||||
{
|
||||
var receipt = TestHelpers.BuildSampleMoneyReturnReceipt();
|
||||
var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
|
||||
var converter = new MoneyReturnReceiptConverter(lineWidth: 48, bigFontLineWidth: 24);
|
||||
var printCommands = converter.Convert(serializedReceipt);
|
||||
|
||||
TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
|
||||
if (printerTarget == 0)
|
||||
{
|
||||
var printer = await TestHelpers.CreateHtmlPrinterAsync(path: @".\money_return_test.html");
|
||||
await TestHelpers.PrintCommandsToHtmlPrinterAsync(
|
||||
printer,
|
||||
printCommands,
|
||||
logoPath: "ristorante-klinglers.ch-logo_white_bg.png");
|
||||
Console.WriteLine("Output written to: money_return_test.html");
|
||||
}
|
||||
else
|
||||
{
|
||||
var printer = await TestHelpers.CreateEpsonPrinterAsync();
|
||||
await TestHelpers.PrintCommandsToEpsonPrinterAsync(printer, printCommands);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user