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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.FinalRecipe;
|
||||
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;
|
||||
|
||||
namespace EpsonTest;
|
||||
@@ -462,6 +463,66 @@ public static class TestHelpers
|
||||
};
|
||||
}
|
||||
|
||||
// Mirrors money_return_receipt_data.json plus the credit-note specific fields
|
||||
// shown in money_return_receipt.jpg (original invoice reference, refund type, tip).
|
||||
public static MoneyReturnReceipt BuildSampleMoneyReturnReceipt()
|
||||
{
|
||||
var receipt = new MoneyReturnReceipt
|
||||
{
|
||||
CompanyName = "Big Mac Bistro",
|
||||
Address1 = "Zelena 186",
|
||||
Address2 = "79000 Lviv",
|
||||
Phone = "080 039 47 69",
|
||||
ReceiptNumber = "25",
|
||||
DateTime = new DateTime(2026, 7, 4, 11, 8, 13),
|
||||
Guests = 1,
|
||||
Total = 20.00m,
|
||||
Currency = "CHF",
|
||||
PaymentMethod = "Cash",
|
||||
PaymentAmount = 13.00m,
|
||||
WaiterName = "Ronald McDonald",
|
||||
VatNumber = " MWST",
|
||||
ThankYouMessage = "Thank you for your order!",
|
||||
GoodbyeMessageLine1 = "Auf Wiedersehen.",
|
||||
GoodbyeMessageLine2 = "Powered by James",
|
||||
// Credit-note specific fields
|
||||
OriginalInvoiceNumber = "773",
|
||||
OriginalDateTime = new DateTime(2026, 7, 4, 11, 7, 0),
|
||||
RefundType = "Full refund",
|
||||
Tip = 7.00m
|
||||
};
|
||||
|
||||
receipt.Items.Add(new MoneyReturnReceiptItem
|
||||
{
|
||||
Quantity = 1,
|
||||
Description = "Cloudy Bay Sauvignon Blanc 2024",
|
||||
UnitPrice = 13.00m,
|
||||
TotalPrice = 13.00m,
|
||||
TaxCategory = "D"
|
||||
});
|
||||
|
||||
receipt.Items.Add(new MoneyReturnReceiptItem
|
||||
{
|
||||
Quantity = 1,
|
||||
Description = "Trinkgeld",
|
||||
UnitPrice = 7.00m,
|
||||
TotalPrice = 7.00m,
|
||||
TaxCategory = "D"
|
||||
});
|
||||
|
||||
receipt.TaxBreakdown.Add(new MoneyReturnTaxInfo
|
||||
{
|
||||
Category = "D",
|
||||
Rate = 0m,
|
||||
Gross = 20.00m,
|
||||
Net = 20.00m,
|
||||
TaxAmount = 0.00m,
|
||||
Currency = "CHF"
|
||||
});
|
||||
|
||||
return receipt;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Print Helpers
|
||||
|
||||
Reference in New Issue
Block a user