fixes ksef

This commit is contained in:
Ralph Soika 2026-04-28 19:35:32 +02:00
parent 7d426a0dab
commit 0e86783324
4 changed files with 43 additions and 47 deletions

View file

@ -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.
* <p>
* 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;
}
}
}

View file

@ -40,7 +40,7 @@
<AdresL2></AdresL2>
</Adres>
<!---
<!--
Contact information from buyer can be left
<DaneKontaktowe>
<Email></Email>

View file

@ -6,10 +6,9 @@
<Naglowek>
<KodFormularza kodSystemowy="FA (3)" wersjaSchemy="1-0E">FA</KodFormularza>
<WariantFormularza>3</WariantFormularza>
<DataWytworzeniaFa>2026-04-28T18:45:18.527334Z</DataWytworzeniaFa>
<DataWytworzeniaFa>2026-04-28T19:34:07.576916Z</DataWytworzeniaFa>
<SystemInfo>Imixs eInvoice</SystemInfo>
</Naglowek>
<!-- Seller (Your Polish Company - Pre-filled) -->
<Podmiot1>
<PrefiksPodatnika>PL</PrefiksPodatnika>
<DaneIdentyfikacyjne>
@ -24,12 +23,8 @@
<Email>MBudas@alexander-logistics.com</Email>
</DaneKontaktowe>
</Podmiot1>
<!-- Buyer (Customer - Empty, to be filled) -->
<Podmiot2>
<DaneIdentyfikacyjne>
<!-- NIP falls eine PL Ust Vorliegt
ansonsten NrID - geht immer -->
<!-- <Nazwa>#Customer Name#</Nazwa> -->
<NIP>1234567890</NIP>
<Nazwa>Test Sp. z o.o.</Nazwa>
</DaneIdentyfikacyjne>
@ -38,64 +33,36 @@
<AdresL1>ul. Testowa 1</AdresL1>
<AdresL2>00-001 Warszawa</AdresL2>
</Adres>
<!---
Contact information from buyer can be left
<DaneKontaktowe>
<Email></Email>
<Telefon></Telefon>
</DaneKontaktowe>
-->
<NrKlienta>D-12345</NrKlienta>
<JST>2</JST>
<!-- fixed -->
<GV>2</GV>
<!-- fixed -->
</Podmiot2>
<!-- Invoice Data -->
<Fa>
<KodWaluty>PLN</KodWaluty>
<P_1>2025-02-10</P_1>
<!-- Invoice Date -->
<P_1M>Szczecin</P_1M>
<P_2>FV/2025/001</P_2>
<!-- Invoice Number -->
<P_6>2026-04-28</P_6>
<!-- Due Date -->
<!-- ============================================================
VAT summary fields - filled by KSeFInvoiceLineBuilder.
Empty placeholders ensure correct XSD sequence. Unused
placeholders are removed by the builder before serialization.
============================================================ -->
<P_13_1>10000.00</P_13_1>
<P_14_1>2300.00</P_14_1>
<P_15>12300.00</P_15>
<Adnotacje>
<!-- 1 yes - 2 no -->
<P_16>2</P_16>
<!-- Keine Selbstfakturierung -->
<P_17>2</P_17>
<!-- Kein Reverse Charge -->
<P_18>2</P_18>
<!-- Kein Split Payment (Rechnung unter 15.000 PLN/EUR) -->
<P_18A>2</P_18A>
<!-- Keine Steuerbefreiung -->
<Zwolnienie>
<P_19N>1</P_19N>
</Zwolnienie>
<!-- Keine neuen Verkehrsmittel -->
<NoweSrodkiTransportu>
<P_22N>1</P_22N>
</NoweSrodkiTransportu>
<!-- Kein vereinfachtes Verfahren nach Art. 135 -->
<P_23>2</P_23>
<!-- Keine Margenregelung -->
<PMarzy>
<P_PMarzyN>1</P_PMarzyN>
</PMarzy>
</Adnotacje>
<!-- Invoice Type (VAT) -->
<RodzajFaktury>VAT</RodzajFaktury>
<!-- Invoice Positions: FaWiersz -->
<FaWiersz>
<NrWierszaFa>1</NrWierszaFa>
<P_7>Transport Berlin - Warsaw</P_7>
@ -119,21 +86,10 @@
<P_12>23</P_12>
</FaWiersz>
<Platnosc>
<!-- Setzen der Zahlungsart (immer 6)
* 1 Barzahlung
* 2 Karte
* 3 Gutschein
* 4 Scheck
* 5 Kredit
* 6 Überweisung
* 7 Mobilzahlung
-->
<TerminPlatnosci>
<Termin>2025-03-10</Termin>
</TerminPlatnosci>
<FormaPlatnosci>6</FormaPlatnosci>
<!-- BANKEN-->
<RachunekBankowy>
<NrRB>PL79116022020000000654306674</NrRB>
<SWIFT>BIGBPLPWXXX</SWIFT>

View file

@ -40,7 +40,7 @@
<AdresL2></AdresL2>
</Adres>
<!---
<!--
Contact information from buyer can be left
<DaneKontaktowe>
<Email></Email>