Invoice Type (RodzajFaktury) -> VAT | KOR

This commit is contained in:
Ralph Soika 2025-11-24 23:20:18 +01:00
parent 6b6957e1ab
commit dd70091057
6 changed files with 350 additions and 111 deletions

View file

@ -193,3 +193,106 @@ or to manual test a xml run:
$ xmllint --noout --schema 'schemat-FA(3)-v1-0E.xsd' example-invoice-01.xml
example-invoice-01.xml validates
```
# KSeF FA(3) Invoice Types: VAT vs. KOR
This section explains the key differences between regular invoices (VAT) and correction invoices (KOR) in the Polish KSeF system using FA(3) structure.
## Invoice Types
### VAT - Regular Invoice
Standard invoice documenting a sale or service delivery.
### KOR - Correction Invoice
Invoice that corrects a previously issued invoice (VAT, ZAL, or ROZ).
---
## Key Differences
| Element | VAT Invoice | KOR Invoice |
| ------------------------- | -------------------------- | --------------------------------------------- |
| **RodzajFaktury** | `VAT` | `KOR` |
| **P_2 (Invoice Number)** | `216525` | `216525-KOR` (with suffix) |
| **P_1 (Invoice Date)** | Original date (2024-04-03) | Correction date (2024-04-15) |
| **Amount Fields** | Absolute values | **Difference values** (negative or positive) |
| **DaneFaKorygowanej** | ❌ Not present | ✅ **Required** - references original invoice |
| **FaWiersz (Line Items)** | Original values | **New/corrected values** |
---
## Critical: Amount Fields in KOR
**KOR invoices show DIFFERENCES, not absolute amounts!**
### Example: Correction from 4128.00 → 3500.00 EUR
```xml
<!-- VAT Invoice -->
<P_13_1>4128.00</P_13_1> <!-- Total Net -->
<P_14_1>0.00</P_14_1> <!-- Total VAT -->
<P_15>4128.00</P_15> <!-- Total Gross -->
```
```xml
<!-- KOR Invoice -->
<P_13_6_1>-628.00</P_13_6_1> <!-- Difference: 3500 - 4128 = -628 -->
<P_15>-628.00</P_15> <!-- Difference in Total -->
```
⚠️ **Important:**
- KOR uses different P_13/P_14 fields than VAT
- `P_13_1`, `P_14_1` → Used in VAT invoices
- `P_13_6_1`, `P_13_7`, etc. → Used in KOR invoices (for 0% rate, exempt, etc.)
---
## DaneFaKorygowanej Element
**Required in KOR invoices** - Must appear AFTER `<RodzajFaktury>KOR</RodzajFaktury>`
```xml
<DaneFaKorygowanej>
<DataWystFaKorygowanej>2024-04-03</DataWystFaKorygowanej>
<NrFaKorygowanej>216525</NrFaKorygowanej>
<NrKSeF>1</NrKSeF>
<NrKSeFFaKorygowanej>9552521552-20240403-ABCDEF-123456-AB</NrKSeFFaKorygowanej>
</DaneFaKorygowanej>
```
| Field | Description |
| ----------------------- | --------------------------------------------------------- |
| `DataWystFaKorygowanej` | Date of **original** invoice |
| `NrFaKorygowanej` | Number of **original** invoice |
| `NrKSeF` | Flag: `1` = original was in KSeF |
| `NrKSeFFaKorygowanej` | KSeF number of original invoice (mandatory if `NrKSeF=1`) |
⚠️ **Critical:** The KSeF number must be saved when uploading the original VAT invoice!
---
## FaWiersz in KOR
**Line items show the NEW/CORRECTED values**, not differences:
```xml
<!-- VAT Invoice -->
<FaWiersz>
<P_9A>4128.00</P_9A> <!-- Unit price -->
<P_11>4128.00</P_11> <!-- Net value -->
</FaWiersz>
```
```xml
<!-- KOR Invoice -->
<FaWiersz>
<P_9A>3500.00</P_9A> <!-- NEW unit price -->
<P_11>3500.00</P_11> <!-- NEW net value -->
<P_12>0 KR</P_12> <!-- Tax rate (0% for exempted) -->
</FaWiersz>
```
---

View file

@ -117,7 +117,7 @@ public class KSeFAdapter implements SignalAdapter {
updateEInvoice(xmlFileData, workitem);
// append XML document
logger.info("│ ├── export KSeF e-invoice");
logger.info("│ ├── attach KSeF e-invoice...");
workitem.addFileData(xmlFileData);
} catch (PluginException e) {
@ -153,6 +153,17 @@ public class KSeFAdapter implements SignalAdapter {
TradeParty billingAddress = buildAddress(workitem.getItemValueString("partner.id"), "buyer", model);
model.setTradeParty(billingAddress);
// Update Invoice Type (RodzajFaktury) -> VAT | KOR
Element elementFa = model.findOrCreateChildNode(model.getRoot(), EInvoiceNS.KSEF, "Fa");
if (isKorrekturRechnung(workitem)) {
model.updateElementValue(elementFa, EInvoiceNS.KSEF, "RodzajFaktury", "KOR");
logger.info("│ ├── invoice type=KOR");
} else {
// normale rechnung
model.updateElementValue(elementFa, EInvoiceNS.KSEF, "RodzajFaktury", "VAT");
logger.info("│ ├── invoice type=VAT");
}
// Update Rechnungssummen...
if (workitem.getItemValueDouble("invoice.total.tax") > 0) {
// wir haben eine Steuer!
@ -162,8 +173,7 @@ public class KSeFAdapter implements SignalAdapter {
}
// set currency
Element fa = model.findOrCreateChildNode(model.getRoot(), EInvoiceNS.KSEF, "Fa");
model.updateElementValue(fa, EInvoiceNS.KSEF, "KodWaluty",
model.updateElementValue(elementFa, EInvoiceNS.KSEF, "KodWaluty",
workitem.getItemValueString("invoice.currency"));
// Update Invoice Items
@ -179,9 +189,6 @@ public class KSeFAdapter implements SignalAdapter {
model.setNetTotalAmount(workitem.getItemValueDouble("invoice.total"));
model.setGrandTotalAmount(workitem.getItemValueDouble("invoice.total"));
// References><Reference type="cs">AB230321</Reference>
// model.setOrderReferenceId(workitem.getItemValueString("order.number"));
// finally update the template file
fileDataXMLTemplate.setContent(model.getContent());
@ -191,6 +198,21 @@ public class KSeFAdapter implements SignalAdapter {
}
/**
* Gibt True zurück wenn es eine korrektur rechnung ist
*
* InvoiceHeader/Correction=true
* InvoiceHeader/CorrectionInvoiceNumber !empty
*
*
* @param workitem
* @return
*/
private boolean isKorrekturRechnung(ItemCollection workitem) {
return ("true".equals(workitem.getItemValueString("invoice.correction"))
&& !workitem.getItemValueString("invoice.CorrectionInvoiceNumber").isEmpty());
}
/**
* Erstellt ein TradeParty Objekt aus einer Liste von Adresszeilen.
*

View file

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<Faktura xmlns="http://crd.gov.pl/wzor/2025/06/25/13775/"
xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2022/01/05/eD/DefinicjeTypy/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Naglowek>
<KodFormularza kodSystemowy="FA (3)" wersjaSchemy="1-0E">FA</KodFormularza>
<WariantFormularza>3</WariantFormularza>
<DataWytworzeniaFa>2025-11-25T10:30:00Z</DataWytworzeniaFa>
<SystemInfo>Imixs eInvoice</SystemInfo>
</Naglowek>
<Podmiot1>
<DaneIdentyfikacyjne>
<NIP>9552521552</NIP>
<Nazwa>Alexander Global Logistics GmbH</Nazwa>
</DaneIdentyfikacyjne>
<Adres>
<KodKraju>PL</KodKraju>
<AdresL1>Museumstr. 2-6</AdresL1>
<AdresL2>28195 Bremen</AdresL2>
</Adres>
<DaneKontaktowe>
<Email>MBudas@alexander-logistics.com</Email>
</DaneKontaktowe>
</Podmiot1>
<Podmiot2>
<DaneIdentyfikacyjne>
<NIP>6621004747</NIP>
<Nazwa>REGESTA Spolka Akcyjna</Nazwa>
</DaneIdentyfikacyjne>
<Adres>
<KodKraju>PL</KodKraju>
<AdresL1>ul. Nowowiejska 52a</AdresL1>
<AdresL2>28-400 Pinczow</AdresL2>
</Adres>
<NrKlienta>D15231</NrKlienta>
<JST>2</JST>
<GV>2</GV>
</Podmiot2>
<Fa>
<KodWaluty>PLN</KodWaluty>
<!-- Invoice Date -->
<P_1>2024-04-15</P_1>
<!-- Invoice Number -->
<P_2>216525-KOR</P_2>
<!-- Due Date -->
<P_6>2024-06-02</P_6>
<!-- the amount of the difference : -628.00 EUR bei 0% rate -->
<P_13_6_1>-628.00</P_13_6_1>
<!-- Gesamtbetrag: Differenz -->
<P_15>-628.00</P_15>
<Adnotacje>
<P_16>2</P_16>
<P_17>2</P_17>
<P_18>2</P_18>
<P_18A>2</P_18A>
<Zwolnienie>
<P_19N>1</P_19N>
</Zwolnienie>
<NoweSrodkiTransportu>
<P_22N>1</P_22N>
</NoweSrodkiTransportu>
<P_23>2</P_23>
<PMarzy>
<P_PMarzyN>1</P_PMarzyN>
</PMarzy>
</Adnotacje>
<RodzajFaktury>KOR</RodzajFaktury>
<!-- Optional -->
<DaneFaKorygowanej>
<DataWystFaKorygowanej>2024-04-03</DataWystFaKorygowanej>
<NrFaKorygowanej>216525</NrFaKorygowanej>
<NrKSeF>1</NrKSeF>
<NrKSeFFaKorygowanej>9552521552-20240403-ABCDEF-123456-AB</NrKSeFFaKorygowanej>
</DaneFaKorygowanej>
<!-- Line Items zeigen die NEUEN Werte (nach Korrektur) -->
<FaWiersz>
<NrWierszaFa>1</NrWierszaFa>
<UU_ID>8a8458dc-5b4f-462c-a964-8848d089a0f9</UU_ID>
<P_7>R IM-ZEL-2403-259</P_7>
<P_8A>szt.</P_8A>
<P_8B>1</P_8B>
<P_9A>3500.00</P_9A>
<P_11>3500.00</P_11>
<P_12>0 KR</P_12>
</FaWiersz>
</Fa>
</Faktura>

View file

@ -8,7 +8,7 @@
<KodFormularza kodSystemowy="FA (3)" wersjaSchemy="1-0E">FA</KodFormularza>
<WariantFormularza>3</WariantFormularza>
<DataWytworzeniaFa>2026-06-05T02:45:33.422866Z</DataWytworzeniaFa>
<SystemInfo>Generator danych</SystemInfo>
<SystemInfo>Imixs eInvoice</SystemInfo>
</Naglowek>
<Podmiot1>
<DaneIdentyfikacyjne>
@ -21,37 +21,46 @@
<AdresL2>28195 Bremen</AdresL2>
</Adres>
<DaneKontaktowe>
<Email>Lucja17@example.net</Email>
<Telefon>86-588-03-5531</Telefon>
<Email>MBudas@alexander-logistics.com</Email>
</DaneKontaktowe>
</Podmiot1>
<Podmiot2>
<DaneIdentyfikacyjne>
<NIP>3861610227</NIP>
<Nazwa>Błaszczak - Lenart</Nazwa>
<NIP>6621004747</NIP>
<Nazwa>REGESTA Spolka Akcyjna</Nazwa>
</DaneIdentyfikacyjne>
<Adres>
<KodKraju>PL</KodKraju>
<AdresL1>al. Szewczyk 7247</AdresL1>
<AdresL2>84-642 Żelechów</AdresL2>
<AdresL1>ul. Nowowiejska 52a</AdresL1>
<AdresL2>28-400 Pinczow</AdresL2>
</Adres>
<DaneKontaktowe>
<Email>Jakubina82@gmail.com</Email>
<Telefon>75-461-31-12</Telefon>
</DaneKontaktowe>
<NrKlienta>KL-2936</NrKlienta>
<NrKlienta>D15231</NrKlienta>
<JST>2</JST>
<GV>2</GV>
</Podmiot2>
<Fa>
<KodWaluty>PLN</KodWaluty>
<!-- Invoice Date -->
<P_1>2025-07-17</P_1>
<P_1M>Lidzbark</P_1M>
<!-- Invoice Number -->
<P_2>FA/GRQMB-#invoice_number#/05/2025</P_2>
<!-- Due Date -->
<P_6>2025-07-11</P_6>
<!-- The total net sales value -->
<P_13_1>10652.38</P_13_1>
<!-- The amount of tax on the total net sales value -->
<P_14_1>2450.05</P_14_1>
<!-- Total amount due. In the case of advance invoices - the amount of payment -->
<P_15>13102.43</P_15>
<Adnotacje>
<P_16>2</P_16>
<P_17>2</P_17>

View file

@ -1,105 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<Faktura xmlns="http://crd.gov.pl/wzor/2025/06/25/13775/" xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2022/01/05/eD/DefinicjeTypy/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Naglowek>
<KodFormularza kodSystemowy="FA (3)" wersjaSchemy="1-0E">FA</KodFormularza>
<WariantFormularza>3</WariantFormularza>
<DataWytworzeniaFa>2025-11-24T18:45:31.387561092Z</DataWytworzeniaFa>
<SystemInfo>Imixs eInvoice</SystemInfo>
</Naglowek>
<!-- Seller (Your Polish Company - Pre-filled) -->
<Podmiot1>
<DaneIdentyfikacyjne>
<NIP>9552521552</NIP>
<Nazwa>Alexander Global Logistics</Nazwa>
</DaneIdentyfikacyjne>
<Adres>
<KodKraju>PL</KodKraju>
<AdresL1>Gdanska 36</AdresL1>
<AdresL2>70-660 Szczecin</AdresL2>
</Adres>
<DaneKontaktowe>
<Email>MBudas@alexander-logistics.com</Email>
</DaneKontaktowe>
</Podmiot1>
<!-- Buyer (Customer - Empty, to be filled) -->
<Podmiot2>
<DaneIdentyfikacyjne>
<Faktura xmlns="http://crd.gov.pl/wzor/2025/06/25/13775/"
xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2022/01/05/eD/DefinicjeTypy/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Naglowek>
<KodFormularza kodSystemowy="FA (3)" wersjaSchemy="1-0E">FA</KodFormularza>
<WariantFormularza>3</WariantFormularza>
<DataWytworzeniaFa>2025-11-24T18:45:31.387561092Z</DataWytworzeniaFa>
<SystemInfo>Imixs eInvoice</SystemInfo>
</Naglowek>
<!-- Seller (Your Polish Company - Pre-filled) -->
<Podmiot1>
<DaneIdentyfikacyjne>
<NIP>9552521552</NIP>
<Nazwa>Alexander Global Logistics</Nazwa>
</DaneIdentyfikacyjne>
<Adres>
<KodKraju>PL</KodKraju>
<AdresL1>Gdanska 36</AdresL1>
<AdresL2>70-660 Szczecin</AdresL2>
</Adres>
<DaneKontaktowe>
<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 -->
<!-- <NIP></NIP> -->
<!-- <Nazwa>#Customer Name#</Nazwa> -->
<NIP>6621004747</NIP>
<Nazwa>REGESTA Spolka Akcyjna</Nazwa>
</DaneIdentyfikacyjne>
<Adres>
<KodKraju>PL</KodKraju>
<AdresL1>ul. Nowowiejska 52a</AdresL1>
<AdresL2>28-400 Pinczow</AdresL2>
</Adres>
<!---
<NIP>6621004747</NIP>
<Nazwa>REGESTA Spolka Akcyjna</Nazwa>
</DaneIdentyfikacyjne>
<Adres>
<KodKraju>PL</KodKraju>
<AdresL1>ul. Nowowiejska 52a</AdresL1>
<AdresL2>28-400 Pinczow</AdresL2>
</Adres>
<!---
Contact information from buyer can be left
<DaneKontaktowe>
<Email></Email>
<Telefon></Telefon>
</DaneKontaktowe>
-->
<NrKlienta>D15231</NrKlienta>
<JST>2</JST>
<!-- fixed -->
<GV>2</GV>
<!-- fixed -->
</Podmiot2>
<!-- Invoice Data -->
<Fa>
<KodWaluty>EUR</KodWaluty>
<P_1>2024-04-03</P_1>
<!-- Invoice Date -->
<P_2>216525</P_2>
<!-- Invoice Number -->
<P_6>2024-06-02</P_6>
<!-- Due Date -->
<!-- Totals -->
<P_13_1>4128.00</P_13_1>
<!-- Total Net -->
<P_14_1>0.00</P_14_1>
<!-- Total VAT -->
<P_15>4128.00</P_15>
<!-- Total Gross -->
<Adnotacje>
<NrKlienta>D15231</NrKlienta>
<JST>2</JST>
<!-- fixed -->
<GV>2</GV>
<!-- fixed -->
</Podmiot2>
<!-- Invoice Data -->
<Fa>
<KodWaluty>EUR</KodWaluty>
<P_1>2024-04-03</P_1>
<!-- Invoice Date -->
<P_2>216525</P_2>
<!-- Invoice Number -->
<P_6>2024-06-02</P_6>
<!-- Due Date -->
<!-- Totals -->
<P_13_1>4128.00</P_13_1>
<!-- Total Net -->
<P_14_1>0.00</P_14_1>
<!-- Total VAT -->
<P_15>4128.00</P_15>
<!-- Total Gross -->
<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>
<UU_ID>8a8458dc-5b4f-462c-a964-8848d089a0f9</UU_ID>
<P_7>R IM-ZEL-2403-259</P_7>
<P_8A>szt.</P_8A>
<P_8B>1</P_8B>
<P_9A>4128.00</P_9A>
<P_11>4128.00</P_11>
</FaWiersz>
</Fa>
<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>
<UU_ID>8a8458dc-5b4f-462c-a964-8848d089a0f9</UU_ID>
<P_7>R IM-ZEL-2403-259</P_7>
<P_8A>szt.</P_8A>
<P_8B>1</P_8B>
<P_9A>4128.00</P_9A>
<P_11>4128.00</P_11>
</FaWiersz>
</Fa>
</Faktura>

View file

@ -55,9 +55,11 @@
<!-- Invoice Data -->
<Fa>
<KodWaluty>#CURRENCY#</KodWaluty>
<P_1></P_1> <!-- Invoice Date -->
<P_2></P_2> <!-- Invoice Number -->
<P_6></P_6> <!-- Due Date -->
<!-- Totals -->
<P_13_1>0.00</P_13_1> <!-- Total Net -->
<P_14_1>0.00</P_14_1> <!-- Total VAT -->