From 5491c04da48ee124b828d10984873d5b6d3532c5 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Wed, 13 May 2026 16:23:13 +0200 Subject: [PATCH] korrektur P_18 --- .../einvoice/KSeFInvoiceLineBuilder.java | 8 ++ .../alexanderlogistics/einvoice/TaxCode.java | 26 ++-- .../ksef/api/KSeFAdapterTest.java | 118 ++++++++++++++++++ .../src/test/resources/ksef/ksef.xml | 2 +- .../ksef/output/invoice-eu-service-np.xml | 52 +------- .../ksef/output/invoice-mixed-rates.xml | 48 +------ .../test/resources/ksef/output/invoice-np.xml | 112 +++++++++++++++++ .../resources/ksef/output/invoice-npt.xml | 112 +++++++++++++++++ .../resources/ksef/output/invoice-simple.xml | 4 +- .../ksef/output/test-korrekturrechnung.xml | 54 +------- workflow/pl/e-invoice/templates/ksef.xml | 2 +- 11 files changed, 381 insertions(+), 157 deletions(-) create mode 100644 office-alexander-logistics-app/src/test/resources/ksef/output/invoice-np.xml create mode 100644 office-alexander-logistics-app/src/test/resources/ksef/output/invoice-npt.xml diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/KSeFInvoiceLineBuilder.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/KSeFInvoiceLineBuilder.java index 569e7ce..3c9ce7f 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/KSeFInvoiceLineBuilder.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/KSeFInvoiceLineBuilder.java @@ -286,6 +286,8 @@ public class KSeFInvoiceLineBuilder { Map aggregates, BigDecimal grossTotal) { + Element elementAdnotacje = model.findOrCreateChildNode(elementFa, EInvoiceNS.KSEF, "Adnotacje"); + for (Map.Entry entry : aggregates.entrySet()) { TaxCode taxCode = entry.getKey(); NetVatPair pair = entry.getValue(); @@ -303,6 +305,12 @@ public class KSeFInvoiceLineBuilder { vatElement.setTextContent(format(pair.vat)); logger.info("│ ├── set " + vatField + " = " + format(pair.vat)); } + + // Set P_18 + Element p18Element = model.findOrCreateChildNode(elementAdnotacje, EInvoiceNS.KSEF, "P_18"); + p18Element.setTextContent(taxCode.getP18Value()); + logger.info("│ ├── set P_18 = " + taxCode.getP18Value()); + } // P_15 - gross total of the entire invoice (always present) diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/TaxCode.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/TaxCode.java index 079a043..561f7c8 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/TaxCode.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/TaxCode.java @@ -41,61 +41,63 @@ public enum TaxCode { /** * Domestic 0% rate, services in Polish seaports (Art. 83 sec. 1 no. 9 UStG-PL). */ - CARGO_0("0", "0 KR", "P_13_6_1", null), + CARGO_0("0", "0 KR", "P_13_6_1", null, "2"), /** * Domestic 0% rate, forwarding services for export of goods (Art. 83 sec. 1 no. * 19 UStG-PL). */ - CARGO_0E("0%E", "0 KR", "P_13_6_1", null), + CARGO_0E("0%E", "0 KR", "P_13_6_1", null, "2"), /** * Domestic 0% rate, shipping agency services (Art. 83 sec. 1 no. 17 UStG-PL). */ - CARGO_01("01", "0 KR", "P_13_6_1", null), + CARGO_01("01", "0 KR", "P_13_6_1", null, "2"), /** * Domestic 0% rate, other maritime transport services (Art. 83 sec. 1 no. 17 or * 20 UStG-PL). */ - CARGO_0MR("0MR", "0 KR", "P_13_6_1", null), + CARGO_0MR("0MR", "0 KR", "P_13_6_1", null, "2"), /** Standard tax rate 23% (Art. 41 sec. 1 / Art. 146ef UStG-PL). */ - CARGO_23("23", "23", "P_13_1", "P_14_1"), + CARGO_23("23", "23", "P_13_1", "P_14_1", "2"), /** First reduced tax rate 8% (Art. 41 sec. 2 UStG-PL). */ - CARGO_8("8", "8", "P_13_2", "P_14_2"), + CARGO_8("8", "8", "P_13_2", "P_14_2", "2"), /** * Not subject to Polish VAT, B2B service to an EU taxable person * (Art. 28b + Art. 100 sec. 1 no. 4 UStG-PL). * Reportable in the EU recapitulative statement (VAT-UE / ZM). */ - CARGO_NP("NP", "np II", "P_13_9", null), + CARGO_NP("NP", "np II", "P_13_9", null, "1"), /** * Not subject to Polish VAT, customer outside the EU or transit * (Art. 28b UStG-PL, excluding Art. 100 sec. 1 no. 4). * NOT reportable in VAT-UE. */ - CARGO_NPT("NPT", "np I", "P_13_8", null), + CARGO_NPT("NPT", "np I", "P_13_8", null, "1"), /** * Art. 83 ust. 1 pkt 23 ustawy o VAT — usługi transportu międzynarodowego (z * definicją z ust. 3) */ - CARGO_023("023", "0 KR", "P_13_6_1", null); + CARGO_023("023", "0 KR", "P_13_6_1", null, "2"); private final String cargosoftCode; private final String p12Value; private final String netSummaryField; private final String vatSummaryField; + private final String p18Value; - TaxCode(String cargosoftCode, String p12Value, String netSummaryField, String vatSummaryField) { + TaxCode(String cargosoftCode, String p12Value, String netSummaryField, String vatSummaryField, String p18value) { this.cargosoftCode = cargosoftCode; this.p12Value = p12Value; this.netSummaryField = netSummaryField; this.vatSummaryField = vatSummaryField; + this.p18Value = p18value; } /** @@ -129,6 +131,10 @@ public enum TaxCode { return vatSummaryField; } + public String getP18Value() { + return p18Value; + } + /** * @return {@code true} if this code carries a non-zero VAT amount * (i.e. a VAT summary field exists); {@code false} otherwise diff --git a/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/ksef/api/KSeFAdapterTest.java b/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/ksef/api/KSeFAdapterTest.java index 32eaeba..a502738 100644 --- a/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/ksef/api/KSeFAdapterTest.java +++ b/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/ksef/api/KSeFAdapterTest.java @@ -145,6 +145,124 @@ public class KSeFAdapterTest { writeOutputToResources(xmlTemplate, "invoice-simple.xml"); } + /** + * Simple PLN invoice with one tax rate (23%). + * Expected: P_13_1, P_14_1, P_15. + */ + @Test + @DisplayName("Test NPT Invoice (PLN, NPT)") + public void testNPTInvoice() throws Exception { + logger.info("==> Test: Simple Invoice"); + + ItemCollection workitem = new ItemCollection(); + workitem.setItemValue("invoice.number", "FV/2025/001"); + workitem.setItemValue("invoice.date", LocalDate.of(2025, 2, 10)); + workitem.setItemValue("invoice.duedate", LocalDate.of(2025, 3, 10)); + workitem.setItemValue("invoice.currency", "PLN"); + workitem.setItemValue("invoice.total.net", 10000.00); + workitem.setItemValue("invoice.total.tax", 23.0); + workitem.setItemValue("invoice.total", 12300.00); + workitem.setItemValue("invoice.correction", "false"); + workitem.setItemValue("invoice.CorrectionInvoiceNumber", ""); + workitem.setItemValue("partner.id", "BP-001"); + workitem.setItemValue("partner.vat", "PL1234567890"); + workitem.setItemValue("invoice.performancedate", new Date()); + + // Prepare child items (invoice line items) + List childItems = new ArrayList<>(); + + ItemCollection lineItem1 = new ItemCollection(); + lineItem1.setItemValue("numpos", "1"); + lineItem1.setItemValue("datev.text", "Transport Berlin - Warsaw"); + lineItem1.setItemValue("billingtext", "Transport Berlin - Warsaw"); + lineItem1.setItemValue("datev.umsatz", 6000.00); + lineItem1.setItemValue("datev.vatrate", 0.0); + lineItem1.setItemValue("cargosoft.vat.code", "NPT"); + childItems.add(lineItem1.getAllItems()); + + ItemCollection lineItem2 = new ItemCollection(); + lineItem2.setItemValue("numpos", "2"); + lineItem2.setItemValue("datev.text", "Customs handling"); + lineItem2.setItemValue("billingtext", "Customs handling"); + lineItem2.setItemValue("datev.umsatz", 4000.00); + lineItem2.setItemValue("datev.vatrate", 0.0); + lineItem2.setItemValue("cargosoft.vat.code", "NPT"); + childItems.add(lineItem2.getAllItems()); + + workitem.setItemValue("_childitems", childItems); + + when(businessPartnerService.getBusinessPartnerByID("BP-001")) + .thenReturn(businessPartner); + + FileData xmlTemplate = loadTemplateFromResources(TEMPLATE_FILE); + + adapter.updateEInvoice(xmlTemplate, workitem); + + assertNotNull(xmlTemplate.getContent(), "XML content should not be null after update"); + assertTrue(xmlTemplate.getContent().length > 0, "XML content should not be empty"); + + writeOutputToResources(xmlTemplate, "invoice-npt.xml"); + } + + /** + * Simple PLN invoice with one tax rate (23%). + * Expected: P_13_1, P_14_1, P_15. + */ + @Test + @DisplayName("Test NPT Invoice (PLN, NPT)") + public void testNPInvoice() throws Exception { + logger.info("==> Test: Simple Invoice"); + + ItemCollection workitem = new ItemCollection(); + workitem.setItemValue("invoice.number", "FV/2025/001"); + workitem.setItemValue("invoice.date", LocalDate.of(2025, 2, 10)); + workitem.setItemValue("invoice.duedate", LocalDate.of(2025, 3, 10)); + workitem.setItemValue("invoice.currency", "PLN"); + workitem.setItemValue("invoice.total.net", 10000.00); + workitem.setItemValue("invoice.total.tax", 23.0); + workitem.setItemValue("invoice.total", 12300.00); + workitem.setItemValue("invoice.correction", "false"); + workitem.setItemValue("invoice.CorrectionInvoiceNumber", ""); + workitem.setItemValue("partner.id", "BP-001"); + workitem.setItemValue("partner.vat", "PL1234567890"); + workitem.setItemValue("invoice.performancedate", new Date()); + + // Prepare child items (invoice line items) + List childItems = new ArrayList<>(); + + ItemCollection lineItem1 = new ItemCollection(); + lineItem1.setItemValue("numpos", "1"); + lineItem1.setItemValue("datev.text", "Transport Berlin - Warsaw"); + lineItem1.setItemValue("billingtext", "Transport Berlin - Warsaw"); + lineItem1.setItemValue("datev.umsatz", 6000.00); + lineItem1.setItemValue("datev.vatrate", 0.0); + lineItem1.setItemValue("cargosoft.vat.code", "NP"); + childItems.add(lineItem1.getAllItems()); + + ItemCollection lineItem2 = new ItemCollection(); + lineItem2.setItemValue("numpos", "2"); + lineItem2.setItemValue("datev.text", "Customs handling"); + lineItem2.setItemValue("billingtext", "Customs handling"); + lineItem2.setItemValue("datev.umsatz", 4000.00); + lineItem2.setItemValue("datev.vatrate", 0.0); + lineItem2.setItemValue("cargosoft.vat.code", "NP"); + childItems.add(lineItem2.getAllItems()); + + workitem.setItemValue("_childitems", childItems); + + when(businessPartnerService.getBusinessPartnerByID("BP-001")) + .thenReturn(businessPartner); + + FileData xmlTemplate = loadTemplateFromResources(TEMPLATE_FILE); + + adapter.updateEInvoice(xmlTemplate, workitem); + + assertNotNull(xmlTemplate.getContent(), "XML content should not be null after update"); + assertTrue(xmlTemplate.getContent().length > 0, "XML content should not be empty"); + + writeOutputToResources(xmlTemplate, "invoice-np.xml"); + } + /** * Correction invoice (KOR) in EUR with 23% tax rate. * Expected: KOR header data, P_13_1, P_14_1, P_14_1W, KursWalutyZ. diff --git a/office-alexander-logistics-app/src/test/resources/ksef/ksef.xml b/office-alexander-logistics-app/src/test/resources/ksef/ksef.xml index 6e7da29..7a4dd4e 100644 --- a/office-alexander-logistics-app/src/test/resources/ksef/ksef.xml +++ b/office-alexander-logistics-app/src/test/resources/ksef/ksef.xml @@ -92,7 +92,7 @@ Means we change the value from 2 to 1 --> - 1 + 2 2 diff --git a/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-eu-service-np.xml b/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-eu-service-np.xml index 147065f..d1e2876 100644 --- a/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-eu-service-np.xml +++ b/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-eu-service-np.xml @@ -6,10 +6,9 @@ FA 3 - 2026-04-28T18:50:52.375962Z + 2026-05-13T15:43:22.241612Z Imixs eInvoice - PL @@ -24,12 +23,8 @@ MBudas@alexander-logistics.com - - - DE310968950 Muster GmbH @@ -38,64 +33,36 @@ Museumstr. 2-6 28195 Bremen - D-18804 2 - 2 - - EUR 2025-02-10 - Szczecin FV/2025/7470 - - 2026-04-28 - - + 2026-05-13 4620.00 4620.00 - 4.3 + 0.2326 - 2 - 2 - - 2 - + 1 2 - 1 - 1 - 2 - 1 - VAT - 1 International transport service Germany - Poland @@ -108,21 +75,10 @@ np II - - 2025-03-10 6 - PL79116022020000000654306674 BIGBPLPWXXX diff --git a/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-mixed-rates.xml b/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-mixed-rates.xml index d71127a..9f155ae 100644 --- a/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-mixed-rates.xml +++ b/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-mixed-rates.xml @@ -6,10 +6,9 @@ FA 3 - 2026-04-28T18:47:03.533669Z + 2026-05-13T16:16:33.813835Z Imixs eInvoice - PL @@ -24,12 +23,8 @@ MBudas@alexander-logistics.com - - - 1234567890 Test Sp. z o.o. @@ -38,65 +33,37 @@ ul. Testowa 1 00-001 Warszawa - D-12345 2 - 2 - - PLN 2025-02-10 - Szczecin FV/2025/7471 - - 2026-04-28 - - + 2026-05-13 3960.00 910.80 14040.00 18910.80 - 2 - 2 - 2 - 2 - 1 - 1 - 2 - 1 - VAT - 1 Forwarding service for export shipment @@ -120,21 +87,10 @@ 23 - - 2025-03-10 6 - PL79116022020000000654306674 BIGBPLPWXXX diff --git a/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-np.xml b/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-np.xml new file mode 100644 index 0000000..928c3e2 --- /dev/null +++ b/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-np.xml @@ -0,0 +1,112 @@ + + + + FA + 3 + 2026-05-13T16:21:25.551812Z + Imixs eInvoice + + + PL + + 9552521552 + ALEXANDER GLOBAL LOGISTICS POLAND sp. z o.o. + + + PL + ul. Gdańska 36, 70-660 Szczecin + + + MBudas@alexander-logistics.com + + + + + 1234567890 + Test Sp. z o.o. + + + PL + ul. Testowa 1 + 00-001 Warszawa + + D-12345 + 2 + 2 + + + PLN + 2025-02-10 + Szczecin + FV/2025/001 + 2026-05-13 + 10000.00 + 10000.00 + + 2 + 2 + 1 + 2 + + 1 + + + 1 + + 2 + + 1 + + + VAT + + 1 + Transport Berlin - Warsaw + szt. + 1.00 + 6000.00 + 6000.00 + 6000.00 + 0.00 + np II + + + 2 + Customs handling + szt. + 1.00 + 4000.00 + 4000.00 + 4000.00 + 0.00 + np II + + + + 2025-03-10 + + 6 + + PL79116022020000000654306674 + BIGBPLPWXXX + Bank Millennium S.A. + Konto PLN + + + PL16116022020000000654910469 + BIGBPLPWXXX + Bank Millennium S.A. + Konto EUR + + + PL72116022020000000654911595 + BIGBPLPWXXX + Bank Millennium S.A. + Konto USD + + + + diff --git a/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-npt.xml b/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-npt.xml new file mode 100644 index 0000000..f541add --- /dev/null +++ b/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-npt.xml @@ -0,0 +1,112 @@ + + + + FA + 3 + 2026-05-13T16:19:55.031750Z + Imixs eInvoice + + + PL + + 9552521552 + ALEXANDER GLOBAL LOGISTICS POLAND sp. z o.o. + + + PL + ul. Gdańska 36, 70-660 Szczecin + + + MBudas@alexander-logistics.com + + + + + 1234567890 + Test Sp. z o.o. + + + PL + ul. Testowa 1 + 00-001 Warszawa + + D-12345 + 2 + 2 + + + PLN + 2025-02-10 + Szczecin + FV/2025/001 + 2026-05-13 + 10000.00 + 10000.00 + + 2 + 2 + 1 + 2 + + 1 + + + 1 + + 2 + + 1 + + + VAT + + 1 + Transport Berlin - Warsaw + szt. + 1.00 + 6000.00 + 6000.00 + 6000.00 + 0.00 + np I + + + 2 + Customs handling + szt. + 1.00 + 4000.00 + 4000.00 + 4000.00 + 0.00 + np I + + + + 2025-03-10 + + 6 + + PL79116022020000000654306674 + BIGBPLPWXXX + Bank Millennium S.A. + Konto PLN + + + PL16116022020000000654910469 + BIGBPLPWXXX + Bank Millennium S.A. + Konto EUR + + + PL72116022020000000654911595 + BIGBPLPWXXX + Bank Millennium S.A. + Konto USD + + + + diff --git a/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-simple.xml b/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-simple.xml index ea18328..78fc3fb 100644 --- a/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-simple.xml +++ b/office-alexander-logistics-app/src/test/resources/ksef/output/invoice-simple.xml @@ -6,7 +6,7 @@ FA 3 - 2026-04-28T19:34:07.576916Z + 2026-05-13T16:14:40.127715Z Imixs eInvoice @@ -42,7 +42,7 @@ 2025-02-10 Szczecin FV/2025/001 - 2026-04-28 + 2026-05-13 10000.00 2300.00 12300.00 diff --git a/office-alexander-logistics-app/src/test/resources/ksef/output/test-korrekturrechnung.xml b/office-alexander-logistics-app/src/test/resources/ksef/output/test-korrekturrechnung.xml index 0eeeaee..3fe9b47 100644 --- a/office-alexander-logistics-app/src/test/resources/ksef/output/test-korrekturrechnung.xml +++ b/office-alexander-logistics-app/src/test/resources/ksef/output/test-korrekturrechnung.xml @@ -6,10 +6,9 @@ FA 3 - 2026-04-28T18:46:09.787442Z + 2026-05-13T15:41:50.791480Z Imixs eInvoice - PL @@ -24,12 +23,8 @@ MBudas@alexander-logistics.com - - - 1234567890 Test Sp. z o.o. @@ -38,66 +33,38 @@ ul. Testowa 1 00-001 Warszawa - D-12345 2 - 2 - - EUR 2025-02-10 - Szczecin FV/2025/001 - - 2026-04-28 - - + 2026-05-13 -900.00 -207.00 - -890.10 + -48.15 -1107.00 - 4.3 + 0.2326 - 2 - 2 - - 2 - + 1 2 - 1 - 1 - 2 - 1 - KOR - 2025-02-10 6551 @@ -115,21 +82,10 @@ 23 - - 2025-03-10 6 - PL79116022020000000654306674 BIGBPLPWXXX diff --git a/workflow/pl/e-invoice/templates/ksef.xml b/workflow/pl/e-invoice/templates/ksef.xml index 6e7da29..7a4dd4e 100644 --- a/workflow/pl/e-invoice/templates/ksef.xml +++ b/workflow/pl/e-invoice/templates/ksef.xml @@ -92,7 +92,7 @@ Means we change the value from 2 to 1 --> - 1 + 2 2