Skip to content

Commit 8b3c20b

Browse files
committed
Update Readme and unsupported fields
1 parent 17dfa13 commit 8b3c20b

File tree

2 files changed

+89
-81
lines changed

2 files changed

+89
-81
lines changed

README.md

Lines changed: 74 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,61 @@ Bidirectional conversion between GOBL and the Polish FA_VAT XML format (KSeF).
1313

1414
Copyright [Invopop Ltd.](https://invopop.com) 2023. Released publicly under the [Apache License Version 2.0](LICENSE). For commercial licenses please contact the [dev team at invopop](mailto:dev@invopop.com). In order to accept contributions to this library we will require transferring copyrights to Invopop Ltd.
1515

16-
## Project Development Objectives
17-
18-
The following list the steps to follow through on in order to accomplish the goal of using GOBL to submit electronic invoices to the Polish authorities:
19-
20-
1. Add the PL (`pl`) tax regime to [GOBL](https://github.com/invopop/gobl). Figure out local taxes, tax ID validation rules, and any "extensions" that may be required to be defined in GOBL, and send in a PR. For examples of existing regimes, see the [regimes](https://github.com/invopop/gobl/tree/main/regimes) directory. Key Concerns:
21-
- Basic B2B invoices support.
22-
- Tax ID validation as per local rules.
23-
- Support for "simplified" invoices.
24-
- Requirements for credit-notes or "rectified" invoices and the correction options definition for the tax regime.
25-
- Any additional fields that need to be validated, like payment terms.
26-
2. Convert GOBL into FA_VAT format in library. A couple of good examples: [gobl.cfdi for Mexico](https://github.com/invopop/gobl.cfdi) and [gobl.verifactu for Spain](https://github.com/invopop/gobl.verifactu). Library would just be able to run tests in the first version.
27-
3. Build a CLI (copy from gobl.cfdi and gobl.verifactu projects) to convert GOBL JSON documents into FA_VAT XML.
28-
4. Build a second part of this project that allows documents to be sent directly to the KSeF. A partial example of this can be found in the [gobl.ticketbai project](https://github.com/invopop/gobl.ticketbai/tree/refactor/internal/gateways). It'd probably be useful to be able to upload via the CLI too.
16+
## Supported Features
17+
18+
The converter handles the following invoice types and features:
19+
20+
**Invoice types (GOBL → KSeF):**
21+
- `VAT` - Standard invoices
22+
- `ZAL` - Advance/prepayment invoices (tag: `partial`)
23+
- `ROZ` - Settlement invoices (tag: `settlement`)
24+
- `UPR` - Simplified invoices (tag: `simplified`)
25+
- `KOR` - Correction invoices (credit notes)
26+
- `KOR_ZAL` - Correction of advance invoices
27+
- `KOR_ROZ` - Correction of settlement invoices
28+
29+
**Parties:**
30+
- Seller (Podmiot1) with Polish NIP, address, contact details, and EU VAT prefix
31+
- Buyer (Podmiot2) with Polish NIP, EU VAT number, or non-EU tax ID
32+
- Third parties (Podmiot3) for JST (local government units) and Group VAT scenarios
33+
34+
**Tax rates:**
35+
- Standard (23%), reduced (8%), super-reduced (5%), and other percentage rates
36+
- Zero-rated (0 KR), intra-community (0 WDT), export (0 EX)
37+
- Tax exempt (zw), outside scope (np I), reverse charge (np II), domestic reverse charge (oo)
38+
- OSS (One Stop Shop) rates
39+
- Margin scheme rates
40+
41+
**Annotations:**
42+
- Cash accounting, self-billing, reverse charge, split payment mechanism
43+
- Tax exemption with legal basis (Polish law, EU directive, or other)
44+
- Margin scheme (travel agency, used goods, art works, collectibles/antiques)
45+
46+
**Other features:**
47+
- Line item discounts
48+
- Invoice periods (P_6_Od / P_6_Do)
49+
- Correction/credit note references with KSeF numbers
50+
- Payment details: means of payment, bank accounts, due dates, advance payments
51+
- Additional description lines (DodatkowyOpis)
52+
- Ordering data with order references and order lines (Zamowienie / WarunkiTransakcji)
53+
- Rounding adjustments to reconcile KSeF and GOBL totals
54+
- Gross pricing (P_9B) support in KSeF → GOBL direction
55+
- Credit notes with before/after correction lines (StanPrzed)
56+
- Prepayment invoices without line items (bypass mode with totals from tax summaries)
57+
58+
## CLI
59+
60+
The `gobl.ksef` CLI provides two commands:
61+
62+
- **`convert`** - Convert a GOBL JSON envelope into a FA_VAT XML document:
63+
```bash
64+
gobl.ksef convert input.json output.xml
65+
```
66+
67+
- **`send`** - Convert and send a GOBL JSON envelope to the KSeF API:
68+
```bash
69+
gobl.ksef send input.json [nip] [token] [keyPath]
70+
```
2971

3072
## Testing
3173

@@ -80,40 +122,37 @@ FA_VAT is the Polish electronic invoice format. The format uses XML.
80122

81123
## Parsing (KSeF → GOBL)
82124

83-
The parsing functionality converts KSeF FA_VAT XML documents back into GOBL format. The current implementation includes:
125+
The parsing functionality converts KSeF FA_VAT XML documents back into GOBL format. The implementation includes:
84126

85127
- **Party conversion**: Converts seller (Podmiot1), buyer (Podmiot2), and third parties (Podmiot3) to GOBL parties
86-
- **Invoice data**: Parses invoice metadata including codes, dates, and currency
87-
- **Line items**: Converts FA_VAT line items to GOBL invoice lines
88-
- **Payment terms**: Extracts payment information and terms
89-
- **Rounding adjustments**: Handles rounding differences to ensure totals match
90-
- **Round-trip validation**: All conversions are validated through round-trip tests (GOBL → KSeF → GOBL)
91-
92-
**Note**: The parsing is functional but may not handle all edge cases. Some complex scenarios from the tax agency might require special handling, particularly invoices without line items, which would need synthetic lines created.
128+
- **Invoice data**: Parses invoice metadata including type, codes, dates, currency, and annotations
129+
- **Line items**: Converts FA_VAT line items (FaWiersz) to GOBL invoice lines, including discounts and tax combos
130+
- **Credit notes**: Handles line inversion for correction invoices, including before/after correction lines (StanPrzed)
131+
- **Gross pricing**: Supports invoices using gross unit prices (P_9B) by setting `PricesInclude = VAT`
132+
- **Ordering data**: Maps Zamowienie (order) and WarunkiTransakcji (transaction conditions) to GOBL ordering purchases
133+
- **Payment details**: Extracts payment means, bank accounts, due dates, and advance payments
134+
- **Prepayment invoices**: Handles advance invoices without line items (ZAL/KOR_ZAL) using bypass mode with totals from tax summary fields
135+
- **Rounding adjustments**: Handles rounding differences between KSeF and GOBL calculation methods
136+
- **Round-trip validation**: All GOBL → KSeF conversions are validated through round-trip tests (GOBL → KSeF → GOBL)
93137

94138
## KSeF API
95139

96-
KSeF is the Polish system for submitting electronic invoices to the Polish authorities.
140+
KSeF is the Polish system for submitting electronic invoices to the Polish authorities. The system uses API version 2.0, which introduced JWT-based authentication, mandatory invoice encryption, and a unified session model.
97141

98142
Useful links:
99143

100144
- [National e-Invoice System](https://ksef.mf.gov.pl/) - for details on system in general (English translation available - language picker is in the top right corner)
101-
- [KSeF Test Zone](https://ksef-test.mf.gov.pl/) - as above, but for testing
102-
- [API documentation](https://ksef-test.mf.gov.pl/docs/v2/index.html) for the test environment (in Polish)
103-
104-
KSeF provide three environments:
105-
106-
1. [Test Environment](https://ksef-test.mf.gov.pl/) for application development with fictitious data.
107-
2. [Pre-production "demo"](https://ksef-demo.mf.gov.pl/) area with production data, but not officially declared.
108-
3. [Production](https://ksef.mf.gov.pl)
145+
- [KSeF 2.0 Integrator's Guide](./docs/ksef-docs-en/README.md) - translated documentation with detailed integration instructions
109146

110-
A translation of the Interface Specification 1.5 is available in the [docs](./docs) folder.
147+
KSeF provides three environments:
111148

112-
OpenAPI documentation is available for three specific interfaces:
149+
| Environment | Description | API Documentation |
150+
| ----------- | ----------- | ----------------- |
151+
| **Test** (Release Candidate) | For testing integration, contains RC versions | [api-test.ksef.mf.gov.pl](https://api-test.ksef.mf.gov.pl/docs/v2) |
152+
| **Demo** (Pre-production) | Matches production configuration, for final validation | [api-demo.ksef.mf.gov.pl](https://api-demo.ksef.mf.gov.pl/docs/v2) |
153+
| **Production** | Full legal validity, production data | [api.ksef.mf.gov.pl](https://api.ksef.mf.gov.pl/docs/v2) |
113154

114-
1. Batches ([test openapi 'batch' spec](https://ksef-test.mf.gov.pl/openapi/gtw/svc/api/KSeF-batch.yaml)) - for sending multiple documents at the same time.
115-
2. Common ([test openapi 'common' spec](https://ksef-test.mf.gov.pl/openapi/gtw/svc/api/KSeF-common.yaml)) - general operations that don't require authentication.
116-
3. Interactive ([test openapi 'online' spec](https://ksef-test.mf.gov.pl/openapi/gtw/svc/api/KSeF-online.yaml)) - sending a single document in each request.
155+
The OpenAPI specification is available at each environment's `/docs/v2/openapi.json` endpoint.
117156

118157
## Authentication
119158

unsupported-fields.md

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,9 @@ Here are features not supported by the converter.
1010
| `KodFormularza@kodSystemowy` (attribute) | `FormCode.SystemCode` | `FA (3)` | |
1111
| `KodFormularza@wersjaSchemy` (attribute) | `FormCode.SchemaVersion` | `1-0E` | |
1212
| `WariantFormularza` | `FormVariant` | `3` | |
13-
| `SystemInfo` | `SystemInfo` | `GOBL.KSEF` | |
14-
| `Podmiot2>JST` | `JST` | `2` | Jednostka Samorządu Terytorialnego = local government unit, special case where the buyer is a local government unit |
15-
| `Podmiot2>GV` | `GV` | `2` | Grupa VAT = VAT group, special case |
16-
| `Fa>P_16` | `CashAccounting` | `2` | |
17-
| `Fa>P_18` | `ReverseCharge` | `2` | |
18-
| `Fa>P_18A` | `SplitPaymentMechanism` | `2` | |
19-
| `Fa>Adnotacje>Zwolnienie>P_19N` | `NoTaxExemptGoods` | `1` | For tax exempt goods, set `P_19` to 1, otherwise set `P_19N` to 1 |
13+
| `SystemInfo` | `SystemInfo` | `Invopop` | |
2014
| `Fa>NoweSrodkiTransportu>P_22N` | `NoNewTransportIntraCommunitySupply` | `1` | For new transport intra-community supply, set `P_22` to 1 (rare special case), otherwise set `P_22N` to 1 |
2115
| `Fa>P_23` | `SimplifiedProcedureBySecondTaxpayer` | `2` | For simplified procedure by second taxpayer (for three-party transactions inside the European Union), set `P_23` to 1, otherwise set `P_23` to 2 |
22-
| `Fa>PMarzy>P_PMarzyN` | `NoMarginProcedures` | `1` | For margin procedure (applies to specific types of goods and services), set `P_PMarzy` to 1, otherwise set `P_PMarzyN` to 1 |
2316
| `Fa>Platnosc>RachunekBankowyFaktora` | `FactorBankAccounts` | `[]` | Bank account of the factor (third party) |
2417

2518
## Not mapped
@@ -67,8 +60,7 @@ The following fields are now present in the structs but are not currently being
6760
### Invoice (Fa)
6861
| XML field | Struct field | Notes |
6962
| --------- | ------------ | ----- |
70-
| `Fa>P1_M` | `Issue Place` | |
71-
| `Fa>P_6` | `Completion date` | The date of delivery or completion of the delivery of goods or services or the date of receipt of payment, referred to in Art. 106b sec. 1(4) of the Act, if such date is specified and differs from the date of issue of the invoice.|
63+
| `Fa>P_6` | `CompletionDate` | The date of delivery or completion of the delivery of goods or services or the date of receipt of payment, referred to in Art. 106b sec. 1(4) of the Act, if such date is specified and differs from the date of issue of the invoice.|
7264
| `Fa>WZ` | `WarehouseDocuments` | Warehouse document numbers (0-1000) |
7365
| `Fa>KursWalutyZ` | `CurrencyRateForTax` | Exchange rate for tax calculation |
7466
| `Fa>P_15ZK` | `AmountBeforeCorrection` | Amount before correction (for KOR_ZAL and other corrections) |
@@ -99,19 +91,19 @@ The following fields are now present in the structs but are not currently being
9991
| `Fa>Rozliczenie>DoZaplaty` | `AmountToPay` | Final amount to pay |
10092
| `Fa>Rozliczenie>DoRozliczenia` | `AmountToSettle` | Overpaid amount to settle/refund |
10193

102-
### Transaction Conditions (WarunkiTransakcji) - COMPLETE STRUCTURE NOT MAPPED
94+
### Transaction Conditions (WarunkiTransakcji) - PARTIALLY MAPPED
10395
| XML field | Struct field | Notes |
10496
| --------- | ------------ | ----- |
105-
| `Fa>WarunkiTransakcji` | `TransactionConditions` | Complete transaction conditions structure |
10697
| `Fa>WarunkiTransakcji>Umowy` | `Contracts` | Contract references (date & number, 0-100) |
107-
| `Fa>WarunkiTransakcji>Zamowienia` | `Orders` | Order references (date & number, 0-100) |
10898
| `Fa>WarunkiTransakcji>NrPartiiTowaru` | `BatchNumbers` | Product batch numbers (0-1000) |
10999
| `Fa>WarunkiTransakcji>WarunkiDostawy` | `DeliveryTerms` | Incoterms delivery conditions |
110100
| `Fa>WarunkiTransakcji>KursUmowny` | `ContractRate` | Contract exchange rate |
111101
| `Fa>WarunkiTransakcji>WalutaUmowna` | `ContractCurrency` | Contract currency |
112102
| `Fa>WarunkiTransakcji>Transport` | `Transport` | Transport/shipping details (0-20) |
113103
| `Fa>WarunkiTransakcji>PodmiotPosredniczacy` | `IntermediaryParty` | Intermediary entity marker |
114104

105+
**Note**: `Fa>WarunkiTransakcji>Zamowienia` (order references) is now mapped bidirectionally via `Ordering.Purchases`. The first order reference date and number are converted. Other WarunkiTransakcji fields remain unmapped.
106+
115107
### Transport - COMPLETE STRUCTURE NOT MAPPED
116108
| XML field | Struct field | Notes |
117109
| --------- | ------------ | ----- |
@@ -130,13 +122,6 @@ The following fields are now present in the structs but are not currently being
130122
| `Transport>WysylkaPrzez` | `ShipVia` | Intermediate shipping addresses (0-20) |
131123
| `Transport>WysylkaDo` | `ShipTo` | Shipping to address |
132124

133-
### Order (Zamowienie) - STRUCTURE PRESENT BUT NOT FULLY MAPPED
134-
| XML field | Struct field | Notes |
135-
| --------- | ------------ | ----- |
136-
| `Fa>Zamowienie` | `Order` | Order information for ZAL/KOR_ZAL type invoices |
137-
| `Fa>Zamowienie>WartoscZamowienia` | `OrderAmount` | Total order value including tax |
138-
| `Fa>Zamowienie>ZamowienieWiersz` | `LineItems` | Order line items (1-10000) |
139-
140125
### Annotations - Extended Fields
141126
| XML field | Struct field | Notes |
142127
| --------- | ------------ | ----- |
@@ -148,17 +133,14 @@ The following fields are now present in the structs but are not currently being
148133
### Line Items (FaWiersz) - Extended Fields
149134
| XML field | Struct field | Notes |
150135
| --------- | ------------ | ----- |
151-
| `FaWiersz>UU_ID` | `UniqueID` | Universal unique line ID (max 50 chars) |
152136
| `FaWiersz>P_6A` | `CompletionDate` | Completion date for this specific line |
153137
| `FaWiersz>Indeks` | `InternalCode` | Internal product code (max 50 chars) |
154138
| `FaWiersz>GTIN` | `GTIN` | Global Trade Item Number (max 20 chars) |
155139
| `FaWiersz>PKWiU` | `PKWiU` | Polish Classification of Products and Services |
156140
| `FaWiersz>CN` | `CN` | Combined Nomenclature code |
157141
| `FaWiersz>PKOB` | `PKOB` | Polish Classification of Construction Objects |
158-
| `FaWiersz>P_9B` | `GrossUnitPrice` | Gross unit price (for art. 106e ust. 7-8) |
159142
| `FaWiersz>P_11A` | `GrossPriceTotal` | Gross total price (for art. 106e ust. 7-8) |
160143
| `FaWiersz>P_11Vat` | `VATAmount` | VAT amount (for art. 106e ust. 10) |
161-
| `FaWiersz>P_12_XII` | `OSSTaxRate` | OSS (One Stop Shop) VAT rate percentage |
162144
| `FaWiersz>P_12_Zal_15` | `Attachment15GoodsMarker` | Split payment marker (value: 1) |
163145
| `FaWiersz>KursWaluty` | `CurrencyRate` | Currency exchange rate for this line |
164146

@@ -187,36 +169,23 @@ The following fields are now present in the structs but are not currently being
187169
| `Stopka` | Footer information - not required in schema, identifies parties in national databases |
188170
| `Zalacznik` | Attachment structure for custom data (key-value pairs or tables) - not required |
189171

190-
`WarunkiTransakcji` (transaction conditions) may contain (taken from example 4):
191-
- `Umowy` - contract(s) date and number
192-
- `Zamowienia` - order(s) date and number
193-
- `NrPartiiTowaru` - product batch number
194-
- `WarunkiDostawy` - conditions of delivery
195-
- `Transport` - how the goods will be transported (contains many nested fields specifying e.g. transport company, destination address, etc.)
196-
197172
## Unset fields
198173

199-
The following fields are present in the struct to be converted to XML, but are not set anywhere in our code:
174+
The following fields are present in the struct to be converted to XML, but are not set anywhere in the GOBL → KSeF direction:
200175

201176
| XML field | Struct field | Notes |
202177
| --------- | ------------ | ----- |
203-
| `Fa>P_2` | `IssuePlace` | issue place - not required in schema |
204-
| `Fa>P_14_1W` | `StandardRateTaxConvertedToPln` |
205-
| `Fa>P_14_2W` | `ReducedRateTaxConvertedToPln` |
206-
| `Fa>P_14_3W` | `SuperReducedRateTaxConvertedToPln` |
178+
| `Fa>P_1M` | `IssuePlace` | issue place - not required in schema |
179+
| `Fa>P_14_1W` | `StandardRateTaxConvertedToPln` | for foreign currency invoices |
180+
| `Fa>P_14_2W` | `ReducedRateTaxConvertedToPln` | for foreign currency invoices |
181+
| `Fa>P_14_3W` | `SuperReducedRateTaxConvertedToPln` | for foreign currency invoices |
207182
| `Fa>FP` | `FP` | indicates a case where an invoice is issued in addition to a regular receipt - not required in schema |
208-
| `Fa>FaWiersz>StanPrzed` | `BeforeCorrectionMarker` | in a correction invoice, indicates that the line describes the state before the correction |
209-
| `Fa>P_13_11` | `MarginNetSale` |
210-
| `Fa>FaWiersz>GTU` | `SpecialGoodsCode` | Code identifying certain classes of goods and services (01 = alcoholic beverages, 02 = vehicle fuels...), values GTU_01 to GTU_13
211-
| `Fa>P_6_Od` | Start of the invoice period |
212-
| `Fa>P_6_Do` | End of the invoice period |
213-
| `Fa>P_13_6_1` | `ZeroTaxExceptIntraCommunityNetSale` | Tax-exempt sale amount other than intra-EU supply and export |
214-
| `Fa>P_13_6_2` | `IntraCommunityNetSale` | Intra-EU supply, tax-exempt sale amount |
215-
| `Fa>P_13_6_3` | `ExportNetSale` | Export tax-exempt sale amount |
183+
| `Fa>FaWiersz>StanPrzed` | `BeforeCorrectionMarker` | in a correction invoice, indicates that the line describes the state before the correction. Used during KSeF → GOBL parsing but not set during GOBL → KSeF building. |
184+
| `Fa>FaWiersz>GTU` | `SpecialGoodsCode` | Code identifying certain classes of goods and services (01 = alcoholic beverages, 02 = vehicle fuels...), values GTU_01 to GTU_13 |
216185

217-
## Other cases
186+
## Other cases
218187

219-
- `P_12` in our code always contains a number, but in the examples 22 and 23 the field contains text `0 WDT` and `0 EX` respectively.
188+
- `P_12` now handles both numeric rates (e.g. `23`, `8`) and text values (`0 WDT`, `0 EX`, `zw`, `np I`, `np II`, `oo`, `0 KR`) for zero-rated, exempt, and special tax categories.
220189

221190
## How the listing is done
222191

@@ -277,4 +246,4 @@ When should `P_23` be used:
277246
- https://sip.lex.pl/akty-prawne/dzu-dziennik-ustaw/podatek-od-towarow-i-uslug-17086198/dz-12-roz-8
278247

279248
When should `P_15ZK` be used (art. 106f ust. 3) for remaining amount to pay before correction:
280-
https://sip.lex.pl/akty-prawne/dzu-dziennik-ustaw/podatek-od-towarow-i-uslug-17086198/art-106-f
249+
https://sip.lex.pl/akty-prawne/dzu-dziennik-ustaw/podatek-od-towarow-i-uslug-17086198/art-106-f

0 commit comments

Comments
 (0)