diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/KSeFAdapter.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/KSeFAdapter.java index cccf00b..934ba2b 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/KSeFAdapter.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/KSeFAdapter.java @@ -246,6 +246,12 @@ public class KSeFAdapter implements SignalAdapter { // Due date - written at the end of the XML tree model.setDueDateTime(workitem.getItemValueLocalDate("invoice.duedate")); + // Strip all XML comments from the document. The template comments + // are useful for template maintainers but should not appear in + // the final invoice that is submitted to KSeF or reviewed by + // tax advisors. + stripComments(model.getRoot().getOwnerDocument()); + // Persist the modified template fileDataXMLTemplate.setContent(model.getContent()); @@ -537,4 +543,38 @@ public class KSeFAdapter implements SignalAdapter { return null; } + + /** + * Removes all XML comment nodes from the given document. + *

+ * The KSeF template carries comments to help template maintainers + * (field explanations, fixed-value markers, business rules). These + * comments must not appear in the final invoice that is submitted + * to KSeF or reviewed by the tax advisor - they only add noise. + */ + private void stripComments(Document doc) { + if (doc == null) { + return; + } + removeCommentsRecursive(doc); + } + + /** + * Recursively walks a node and removes every direct child that is an + * XML comment. Iterates from the last child backwards so that + * removing a node does not affect the index of the still-to-visit + * children. + */ + private void removeCommentsRecursive(Node node) { + Node child = node.getLastChild(); + while (child != null) { + Node previous = child.getPreviousSibling(); + if (child.getNodeType() == Node.COMMENT_NODE) { + node.removeChild(child); + } else if (child.hasChildNodes()) { + removeCommentsRecursive(child); + } + child = previous; + } + } } \ No newline at end of file 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 5901954..6970861 100644 --- a/office-alexander-logistics-app/src/test/resources/ksef/ksef.xml +++ b/office-alexander-logistics-app/src/test/resources/ksef/ksef.xml @@ -40,7 +40,7 @@ - PL @@ -24,12 +23,8 @@ MBudas@alexander-logistics.com - - - 1234567890 Test Sp. z o.o. @@ -38,64 +33,36 @@ ul. Testowa 1 00-001 Warszawa - D-12345 2 - 2 - - PLN 2025-02-10 - Szczecin FV/2025/001 - 2026-04-28 - - 10000.00 2300.00 12300.00 - 2 - 2 - 2 - 2 - 1 - 1 - 2 - 1 - VAT - 1 Transport Berlin - Warsaw @@ -119,21 +86,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 5901954..6970861 100644 --- a/workflow/pl/e-invoice/templates/ksef.xml +++ b/workflow/pl/e-invoice/templates/ksef.xml @@ -40,7 +40,7 @@ -