|
26 | 26 |
|
27 | 27 | - 🔍 Extract invoice/receipt data |
28 | 28 | - 🧠 Choose your AI models (OpenAI, Mistral, Anthropic, Google Gemini, and Ollama) |
| 29 | +- 🇮🇹 **Full FatturaPA support** for Italian e-invoicing (TD01, TD17-TD19) |
29 | 30 | - 🔧 Set AI keys with CLI and environment variables |
30 | 31 | - ⭐ Pretty print the output |
31 | 32 | - 🔄 Pipe output with other CLI |
| 33 | +- 📄 Export to XML/JSON formats |
| 34 | +- 🏛️ Public Administration support (CIG/CUP codes) |
32 | 35 |
|
33 | 36 | ## Usage |
34 | 37 |
|
@@ -117,6 +120,23 @@ export EXTRACTOR_API_KEY=sk-your-openai-key |
117 | 120 | npx ai-invoice-extractor invoice.pdf |
118 | 121 | ``` |
119 | 122 |
|
| 123 | +#### FatturaPA (Italian E-Invoicing) |
| 124 | +```sh |
| 125 | +# Extract FatturaPA data with full Italian e-invoicing support |
| 126 | +npx ai-invoice-extractor -k sk-key -p fattura.pdf |
| 127 | + |
| 128 | +# Export to FatturaPA XML format |
| 129 | +npx ai-invoice-extractor -k sk-key fattura.pdf | node -e " |
| 130 | + const { FatturapaXmlExporter } = require('./dist/exporters'); |
| 131 | + const exporter = new FatturapaXmlExporter(); |
| 132 | + const data = JSON.parse(require('fs').readFileSync(0, 'utf8')); |
| 133 | + console.log(exporter.export(data)); |
| 134 | +" |
| 135 | + |
| 136 | +# Extract cross-border invoice (TD18) |
| 137 | +npx ai-invoice-extractor -k sk-key crossborder-invoice.pdf |
| 138 | +``` |
| 139 | + |
120 | 140 | #### Different AI Vendors |
121 | 141 | ```sh |
122 | 142 | # Mistral AI |
@@ -171,6 +191,236 @@ The CLI provides helpful error messages for common issues: |
171 | 191 | - **Documents:** PDF |
172 | 192 | - **File size:** Up to 20MB (varies by AI provider) |
173 | 193 |
|
| 194 | +## FatturaPA (Italian E-Invoicing) Support |
| 195 | + |
| 196 | +The AI Invoice Extractor provides comprehensive support for FatturaPA, the Italian electronic invoicing standard mandated by the Agenzia delle Entrate (Italian Revenue Agency). |
| 197 | + |
| 198 | +### Supported Document Types |
| 199 | + |
| 200 | +| Code | Description | Support | |
| 201 | +|------|-------------|---------| |
| 202 | +| **TD01** | Domestic invoice | ✅ Full support | |
| 203 | +| **TD17** | Domestic reverse charge integration | ✅ Full support | |
| 204 | +| **TD18** | Intra-EU purchase integration | ✅ Full support | |
| 205 | +| **TD19** | Extra-EU purchase integration | ✅ Full support | |
| 206 | +| **TD20-27** | Specialized invoice types | ✅ Basic support | |
| 207 | + |
| 208 | +### Key Features |
| 209 | + |
| 210 | +- **🏢 Complete Party Data:** Italian VAT IDs, Codice Fiscale, REA registration, PEC addresses |
| 211 | +- **🌍 Cross-Border Support:** Foreign VAT IDs, tax representatives, currency conversion |
| 212 | +- **💰 Tax Compliance:** All Italian VAT rates, nature codes (N1-N7), withholding taxes |
| 213 | +- **🏛️ Public Administration:** CIG/CUP codes, office codes, administrative references |
| 214 | +- **📋 Line Items:** Product codes, service periods, discounts, custom information |
| 215 | +- **💳 Payment Terms:** All Italian payment methods (MP01-MP22), IBAN/BIC, installments |
| 216 | +- **📎 References:** Order numbers, contracts, transport documents |
| 217 | +- **🔧 Export Formats:** SDI-compliant XML, structured JSON, validation format |
| 218 | + |
| 219 | +### Extracted Fields |
| 220 | + |
| 221 | +The extractor captures **300+ fields** including: |
| 222 | + |
| 223 | +#### Document Header |
| 224 | +- Document type code (TD01, TD17-TD19, etc.) |
| 225 | +- Invoice number, issue date, due date |
| 226 | +- Currency code and exchange rates (for cross-border) |
| 227 | +- Transmission format and country codes |
| 228 | + |
| 229 | +#### Party Information (Supplier & Customer) |
| 230 | +- Legal name and form |
| 231 | +- Italian VAT ID (`IT` + 11 digits) and Tax ID (Codice Fiscale) |
| 232 | +- Foreign VAT IDs for cross-border transactions |
| 233 | +- Complete addresses with Italian province codes |
| 234 | +- Contact information (phone, email, PEC) |
| 235 | +- REA registration details (office, number, share capital) |
| 236 | +- Tax representative information (for foreign suppliers) |
| 237 | + |
| 238 | +#### Tax Details |
| 239 | +- Multiple VAT rates and amounts |
| 240 | +- Nature codes for exemptions (N1-N7 with descriptions) |
| 241 | +- Withholding taxes (RT01, RT02 types) |
| 242 | +- Administrative references for PA invoices |
| 243 | + |
| 244 | +#### Line Items |
| 245 | +- Descriptions, quantities, unit prices, totals |
| 246 | +- Discounts and markups (percentage and amount) |
| 247 | +- VAT rates per line item |
| 248 | +- Product codes (EAN, internal, etc.) |
| 249 | +- Service periods (start/end dates) |
| 250 | +- Cross-border customs information |
| 251 | + |
| 252 | +#### Payment Information |
| 253 | +- Payment conditions (TP01-TP03) |
| 254 | +- Payment methods (MP01-MP22) |
| 255 | +- Bank details (IBAN, BIC, bank name) |
| 256 | +- Installment schedules |
| 257 | +- Early payment discounts and late penalties |
| 258 | + |
| 259 | +#### References & Additional Data |
| 260 | +- CIG (tender codes) and CUP (project codes) for PA |
| 261 | +- Order numbers and contract references |
| 262 | +- Transport and delivery information |
| 263 | +- Digital signature details |
| 264 | +- Attachments and notes |
| 265 | + |
| 266 | +### Usage Examples |
| 267 | + |
| 268 | +#### Basic FatturaPA Extraction |
| 269 | +```sh |
| 270 | +# Extract Italian domestic invoice |
| 271 | +npx ai-invoice-extractor -k sk-key fattura-domestica.pdf |
| 272 | + |
| 273 | +# Extract cross-border invoice (German supplier to Italian customer) |
| 274 | +npx ai-invoice-extractor -k sk-key fattura-crossborder.pdf |
| 275 | + |
| 276 | +# Extract with pretty formatting |
| 277 | +npx ai-invoice-extractor -k sk-key -p fattura.pdf |
| 278 | +``` |
| 279 | + |
| 280 | +#### Programmatic Usage |
| 281 | +```javascript |
| 282 | +import { Extractor } from 'ai-invoice-extractor'; |
| 283 | +import { FatturapaXmlExporter, FatturapaJsonExporter } from 'ai-invoice-extractor/exporters'; |
| 284 | + |
| 285 | +// Extract invoice data |
| 286 | +const extractor = Extractor.create({ |
| 287 | + vendor: 'openai', |
| 288 | + model: 'gpt-4o', |
| 289 | + apiKey: 'sk-your-key' |
| 290 | +}); |
| 291 | + |
| 292 | +const invoiceData = await extractor.analyseFile({ |
| 293 | + path: 'fattura.pdf', |
| 294 | + prompt: 'EXTRACT_INVOICE_FATTURAPA', |
| 295 | + output: fatturapaInvoiceSchema |
| 296 | +}); |
| 297 | + |
| 298 | +// Export to XML (SDI-compliant) |
| 299 | +const xmlExporter = new FatturapaXmlExporter({ |
| 300 | + formatOutput: true, |
| 301 | + validateRequired: true |
| 302 | +}); |
| 303 | +const xml = xmlExporter.export(invoiceData); |
| 304 | + |
| 305 | +// Export to JSON (structured) |
| 306 | +const jsonExporter = new FatturapaJsonExporter({ |
| 307 | + includeMetadata: true, |
| 308 | + cleanNullValues: true |
| 309 | +}); |
| 310 | +const json = jsonExporter.export(invoiceData); |
| 311 | + |
| 312 | +// Export for validation |
| 313 | +const validationJson = jsonExporter.exportForValidation(invoiceData); |
| 314 | +``` |
| 315 | + |
| 316 | +#### XML Output Sample |
| 317 | +```xml |
| 318 | +<?xml version="1.0" encoding="UTF-8"?> |
| 319 | +<ns2:FatturaElettronica versione="FPR12" xmlns:ns2="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2"> |
| 320 | + <FatturaElettronicaHeader> |
| 321 | + <DatiTrasmissione> |
| 322 | + <IdTrasmittente> |
| 323 | + <IdPaese>IT</IdPaese> |
| 324 | + <IdCodice>12345678901</IdCodice> |
| 325 | + </IdTrasmittente> |
| 326 | + <FormatoTrasmissione>FPR12</FormatoTrasmissione> |
| 327 | + </DatiTrasmissione> |
| 328 | + <CedentePrestatore> |
| 329 | + <DatiAnagrafici> |
| 330 | + <IdFiscaleIVA> |
| 331 | + <IdPaese>IT</IdPaese> |
| 332 | + <IdCodice>IT12345678901</IdCodice> |
| 333 | + </IdFiscaleIVA> |
| 334 | + <Anagrafica> |
| 335 | + <Denominazione>Tech Solutions S.r.l.</Denominazione> |
| 336 | + </Anagrafica> |
| 337 | + </DatiAnagrafici> |
| 338 | + </CedentePrestatore> |
| 339 | + </FatturaElettronicaHeader> |
| 340 | + <FatturaElettronicaBody> |
| 341 | + <DatiGenerali> |
| 342 | + <DatiGeneraliDocumento> |
| 343 | + <TipoDocumento>TD01</TipoDocumento> |
| 344 | + <Divisa>EUR</Divisa> |
| 345 | + <Data>2024-03-15</Data> |
| 346 | + <Numero>INV-2024-001</Numero> |
| 347 | + </DatiGeneraliDocumento> |
| 348 | + </DatiGenerali> |
| 349 | + <!-- ... more XML content ... --> |
| 350 | + </FatturaElettronicaBody> |
| 351 | +</ns2:FatturaElettronica> |
| 352 | +``` |
| 353 | + |
| 354 | +#### JSON Output Sample |
| 355 | +```json |
| 356 | +{ |
| 357 | + "header": { |
| 358 | + "transmission": { |
| 359 | + "sender_country": "IT", |
| 360 | + "sender_code": "IT12345678901", |
| 361 | + "format": "FPR12" |
| 362 | + }, |
| 363 | + "supplier": { |
| 364 | + "identification": { |
| 365 | + "vat_id": "IT12345678901", |
| 366 | + "tax_id": "12345678901" |
| 367 | + }, |
| 368 | + "legal_info": { |
| 369 | + "name": "Tech Solutions S.r.l." |
| 370 | + }, |
| 371 | + "address": { |
| 372 | + "street": "Via Roma", |
| 373 | + "city": "Milano", |
| 374 | + "postal_code": "20121", |
| 375 | + "province": "MI", |
| 376 | + "country": "IT" |
| 377 | + } |
| 378 | + } |
| 379 | + }, |
| 380 | + "body": { |
| 381 | + "general_data": { |
| 382 | + "document_type": "TD01", |
| 383 | + "currency": { "code": "EUR" }, |
| 384 | + "date": "2024-03-15", |
| 385 | + "number": "INV-2024-001", |
| 386 | + "totals": { |
| 387 | + "taxable_amount": 1000.00, |
| 388 | + "vat_amount": 220.00, |
| 389 | + "total_amount": 1220.00 |
| 390 | + } |
| 391 | + }, |
| 392 | + "line_items": [ |
| 393 | + { |
| 394 | + "line_number": 1, |
| 395 | + "description": "Servizi di consulenza IT", |
| 396 | + "quantity": 1, |
| 397 | + "unit_price": 1000.00, |
| 398 | + "total_price": 1000.00, |
| 399 | + "vat": { |
| 400 | + "rate": 22.00, |
| 401 | + "amount": 220.00 |
| 402 | + } |
| 403 | + } |
| 404 | + ] |
| 405 | + } |
| 406 | +} |
| 407 | +``` |
| 408 | + |
| 409 | +### Validation & Compliance |
| 410 | + |
| 411 | +The XML exporter generates output that is: |
| 412 | +- ✅ **SDI Compliant:** Validates against Italian Sistema di Interscambio |
| 413 | +- ✅ **Schema Valid:** Follows FatturaPA XSD 1.2.1 specification |
| 414 | +- ✅ **Tax Authority Ready:** Can be submitted directly to Agenzia delle Entrate |
| 415 | +- ✅ **Cross-Border Ready:** Handles TD17-TD19 scenarios correctly |
| 416 | + |
| 417 | +### Examples & Testing |
| 418 | + |
| 419 | +The repository includes comprehensive examples: |
| 420 | +- `examples/fatturapa/domestic-invoice-sample.json` - Italian domestic invoice (TD01) |
| 421 | +- `examples/fatturapa/crossborder-invoice-sample.json` - Cross-border invoice (TD18) |
| 422 | +- Complete test suite with 15+ scenarios covering all document types |
| 423 | + |
174 | 424 | ## Contributing |
175 | 425 |
|
176 | 426 | We use [Bun](https://bun.sh/) instead of npm: |
|
0 commit comments