From 4e2bfd08f3b08dcc7a31223b115d8450de55c07e Mon Sep 17 00:00:00 2001 From: Stefan Kert Date: Mon, 27 May 2024 13:57:34 +0200 Subject: [PATCH] Support for negative articles --- .../Utilities/EpsonCommandFactory.cs | 13 +++- .../ITSSCDTests.cs | 36 +++++++++++ .../ReceiptExamples.cs | 14 +++++ .../0x0001_Cash_WithNegativeAmount.json | 59 +++++++++++++++++++ .../0x0001_Cash_WithNegativeAmount_Void.json | 59 +++++++++++++++++++ 5 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ReceiptRequests/PosReceipts/0x0001_Cash_WithNegativeAmount.json create mode 100644 scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ReceiptRequests/PosReceipts/0x0001_Cash_WithNegativeAmount_Void.json diff --git a/scu-it/src/fiskaltrust.Middleware.SCU.IT.EpsonRTPrinter/Utilities/EpsonCommandFactory.cs b/scu-it/src/fiskaltrust.Middleware.SCU.IT.EpsonRTPrinter/Utilities/EpsonCommandFactory.cs index 022e8ed70..4f1c91700 100644 --- a/scu-it/src/fiskaltrust.Middleware.SCU.IT.EpsonRTPrinter/Utilities/EpsonCommandFactory.cs +++ b/scu-it/src/fiskaltrust.Middleware.SCU.IT.EpsonRTPrinter/Utilities/EpsonCommandFactory.cs @@ -331,7 +331,7 @@ private static void GenerateItems(List itemAndMessages, ChargeIt itemAndMessages.Add(new() { PrintRecItem = printRecItem, PrintRecMessage = printRecMessage }); } else if (i.IsSingleUseVoucher() && i.Amount < 0) - { + { var printRecItemAdjustment = new PrintRecItemAdjustment { Description = i.Description, @@ -352,6 +352,17 @@ private static void GenerateItems(List itemAndMessages, ChargeIt }; itemAndMessages.Add(new() { PrintRecItem = printRecItem }); } + else if (i.Amount < 0) + { + var printRecItemAdjustment = new PrintRecItemAdjustment + { + Description = i.Description, + Amount = Math.Abs(i.Amount), + AdjustmentType = 3, + Department = i.GetVatGroup(), + }; + itemAndMessages.Add(new() { PrintRecItemAdjustment = printRecItemAdjustment }); + } else { var printRecItem = new PrintRecItem diff --git a/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ITSSCDTests.cs b/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ITSSCDTests.cs index 4a0a23f93..baa954acb 100644 --- a/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ITSSCDTests.cs +++ b/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ITSSCDTests.cs @@ -472,6 +472,42 @@ public async Task ProcessPosReceipt_0x4954_2000_0000_0001_SingleUseVoucher_Redee result.ReceiptResponse.ftSignatures.Should().Contain(x => x.ftSignatureType == (ITConstants.BASE_STATE | (long) SignatureTypesIT.RTDocumentType)); } + [Fact] + public async Task ProcessPosReceipt_0x4954_2000_0000_0001_Cash_WithNegativeAmount() + { + var itsscd = GetSUT(); + var result = await itsscd.ProcessReceiptAsync(new ProcessRequest + { + ReceiptRequest = ReceiptExamples.Cash_WithNegativeAmount(), + ReceiptResponse = _receiptResponse + }); + + using var scope = new AssertionScope(); + result.ReceiptResponse.ftSignatures.Should().Contain(x => x.ftSignatureType == (ITConstants.BASE_STATE | (long) SignatureTypesIT.RTSerialNumber)); + result.ReceiptResponse.ftSignatures.Should().Contain(x => x.ftSignatureType == (ITConstants.BASE_STATE | (long) SignatureTypesIT.RTZNumber)); + result.ReceiptResponse.ftSignatures.Should().Contain(x => x.ftSignatureType == (ITConstants.BASE_STATE | (long) SignatureTypesIT.RTDocumentNumber)); + result.ReceiptResponse.ftSignatures.Should().Contain(x => x.ftSignatureType == (ITConstants.BASE_STATE | (long) SignatureTypesIT.RTDocumentMoment)); + result.ReceiptResponse.ftSignatures.Should().Contain(x => x.ftSignatureType == (ITConstants.BASE_STATE | (long) SignatureTypesIT.RTDocumentType)); + } + + [Fact] + public async Task ProcessPosReceipt_0x4954_2000_0000_0001_Cash_WithNegativeAmount_Void() + { + var itsscd = GetSUT(); + var result = await itsscd.ProcessReceiptAsync(new ProcessRequest + { + ReceiptRequest = ReceiptExamples.Cash_WithNegativeAmount_Void(), + ReceiptResponse = _receiptResponse + }); + + using var scope = new AssertionScope(); + result.ReceiptResponse.ftSignatures.Should().Contain(x => x.ftSignatureType == (ITConstants.BASE_STATE | (long) SignatureTypesIT.RTSerialNumber)); + result.ReceiptResponse.ftSignatures.Should().Contain(x => x.ftSignatureType == (ITConstants.BASE_STATE | (long) SignatureTypesIT.RTZNumber)); + result.ReceiptResponse.ftSignatures.Should().Contain(x => x.ftSignatureType == (ITConstants.BASE_STATE | (long) SignatureTypesIT.RTDocumentNumber)); + result.ReceiptResponse.ftSignatures.Should().Contain(x => x.ftSignatureType == (ITConstants.BASE_STATE | (long) SignatureTypesIT.RTDocumentMoment)); + result.ReceiptResponse.ftSignatures.Should().Contain(x => x.ftSignatureType == (ITConstants.BASE_STATE | (long) SignatureTypesIT.RTDocumentType)); + } + [Fact] public async Task ProcessPosReceipt_0x4954_2000_0000_0001_SingleUseVoucher_Redeem_MultipleVatRates() { diff --git a/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ReceiptExamples.cs b/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ReceiptExamples.cs index 003e32ccc..70ef10106 100644 --- a/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ReceiptExamples.cs +++ b/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ReceiptExamples.cs @@ -75,6 +75,20 @@ public static ReceiptRequest CashWithSingleUseVoucherRedeem() return JsonConvert.DeserializeObject(receipt); } + public static ReceiptRequest Cash_WithNegativeAmount() + { + var current_moment = DateTime.UtcNow.ToString("o"); + var receipt = File.ReadAllText(Path.Combine("ReceiptRequests", "PosReceipts", "0x0001_Cash_WithNegativeAmount.json")).Replace("{{current_moment}}", current_moment); + return JsonConvert.DeserializeObject(receipt); + } + + public static ReceiptRequest Cash_WithNegativeAmount_Void() + { + var current_moment = DateTime.UtcNow.ToString("o"); + var receipt = File.ReadAllText(Path.Combine("ReceiptRequests", "PosReceipts", "0x0001_Cash_WithNegativeAmount_Void.json")).Replace("{{current_moment}}", current_moment); + return JsonConvert.DeserializeObject(receipt); + } + public static ReceiptRequest CashWithSingleUseVoucherPurchase() { var current_moment = DateTime.UtcNow.ToString("o"); diff --git a/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ReceiptRequests/PosReceipts/0x0001_Cash_WithNegativeAmount.json b/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ReceiptRequests/PosReceipts/0x0001_Cash_WithNegativeAmount.json new file mode 100644 index 000000000..79da81ce3 --- /dev/null +++ b/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ReceiptRequests/PosReceipts/0x0001_Cash_WithNegativeAmount.json @@ -0,0 +1,59 @@ +{ + "ftCashBoxID": "4038ca6d-fe63-46d0-95d6-a1fce0f98258", + "ftQueueID": "910347dc-a5fc-44bf-9ef0-2ec5fda824ca", + "ftPosSystemId": "e0c014d5-44de-4eec-886f-02dde5ec2d3a", + "cbTerminalID": "1", + "cbReceiptReference": "926804fa-f185-4d48-809c-b73c6b3297e1", + "cbReceiptMoment": "2024-05-09T10:03:22.7Z", + "cbChargeItems": [ + { + "Position": 100, + "Quantity": 1.0000, + "Description": "Felsenkeller", + "Amount": 4.80000000000000000000000000, + "VATRate": 10.0000, + "ftChargeItemCase": 5283883447184523281, + "ftChargeItemCaseData": "", + "VATAmount": 0.4363636363636363636363636364, + "CostCenter": "4", + "ProductGroup": "Biere", + "ProductNumber": "5009", + "ProductBarcode": "", + "Unit": "Stk", + "Moment": "2024-05-09T10:03:11.233Z" + }, + { + + "Position": 200, + "Quantity": 1.0000, + "Description": "Klein", + "Amount": -2.00000000000000000000000000, + "VATRate": 10.0000, + "ftChargeItemCase": 5283883447184523281, + "ftChargeItemCaseData": "", + "VATAmount": -0.1818181818181818181818181818, + "CostCenter": "4", + "ProductGroup": "Pizza", + "ProductNumber": "40041", + "ProductBarcode": "", + "Unit": "Stk", + "Moment": "2024-05-09T10:03:17.173Z" + } + ], + "cbPayItems": [ + { + "Quantity": 1.0, + "Description": "Bar", + "Amount": 2.8000, + "ftPayItemCase": 5283883447184523265, + "ftPayItemCaseData": "", + "CostCenter": "4", + "MoneyGroup": "1", + "MoneyNumber": "" + } + ], + "ftReceiptCase": 5283883447318740993, + "cbReceiptAmount": 2.80, + "cbUser": "Chef", + "cbArea": "53" +} \ No newline at end of file diff --git a/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ReceiptRequests/PosReceipts/0x0001_Cash_WithNegativeAmount_Void.json b/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ReceiptRequests/PosReceipts/0x0001_Cash_WithNegativeAmount_Void.json new file mode 100644 index 000000000..f58078eb5 --- /dev/null +++ b/scu-it/test/fiskaltrust.Middleware.SCU.IT.AcceptanceTests/ReceiptRequests/PosReceipts/0x0001_Cash_WithNegativeAmount_Void.json @@ -0,0 +1,59 @@ +{ + "ftCashBoxID": "4038ca6d-fe63-46d0-95d6-a1fce0f98258", + "ftQueueID": "910347dc-a5fc-44bf-9ef0-2ec5fda824ca", + "ftPosSystemId": "e0c014d5-44de-4eec-886f-02dde5ec2d3a", + "cbTerminalID": "1", + "cbReceiptReference": "926804fa-f185-4d48-809c-b73c6b3297e1", + "cbReceiptMoment": "2024-05-09T10:03:22.7Z", + "cbChargeItems": [ + { + "Position": 100, + "Quantity": -1.0000, + "Description": "Felsenkeller", + "Amount": -4.80000000000000000000000000, + "VATRate": 10.0000, + "ftChargeItemCase": 5283883447184523281, + "ftChargeItemCaseData": "", + "VATAmount": -0.4363636363636363636363636364, + "CostCenter": "4", + "ProductGroup": "Biere", + "ProductNumber": "5009", + "ProductBarcode": "", + "Unit": "Stk", + "Moment": "2024-05-09T10:03:11.233Z" + }, + { + + "Position": 200, + "Quantity": 1.0000, + "Description": "Klein", + "Amount": 2.00000000000000000000000000, + "VATRate": 10.0000, + "ftChargeItemCase": 5283883447184523281, + "ftChargeItemCaseData": "", + "VATAmount": 0.1818181818181818181818181818, + "CostCenter": "4", + "ProductGroup": "Pizza", + "ProductNumber": "40041", + "ProductBarcode": "", + "Unit": "Stk", + "Moment": "2024-05-09T10:03:17.173Z" + } + ], + "cbPayItems": [ + { + "Quantity": 1.0, + "Description": "Bar", + "Amount": -2.8000, + "ftPayItemCase": 5283883447184523265, + "ftPayItemCaseData": "", + "CostCenter": "4", + "MoneyGroup": "1", + "MoneyNumber": "" + } + ], + "ftReceiptCase": 5283883447318740993, + "cbReceiptAmount": -2.80, + "cbUser": "Chef", + "cbArea": "53" +} \ No newline at end of file