PHPackages                             oixan/php-e-invoice-it - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. oixan/php-e-invoice-it

ActiveLibrary

oixan/php-e-invoice-it
======================

A PHP package for managing italian e-invoice and notice XML formats

v0.2.0(5y ago)034GPL-3.0-or-laterPHPPHP ^7

Since Dec 18Pushed 4y agoCompare

[ Source](https://github.com/oixan/php-e-invoice-it)[ Packagist](https://packagist.org/packages/oixan/php-e-invoice-it)[ RSS](/packages/oixan-php-e-invoice-it/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (2)Versions (12)Used By (0)

PHP E-invoice It
================

[](#php-e-invoice-it)

A PHP package for managing italian e-invoice and notice XML formats:

- XML management through `DOMDocument` and `DOMXPath`
- full `FatturaElettronica` (FatturaPA) XML skeleton
- smart simplified xpath strings for getting/setting values (and for adding/getting/removing elements if needed)
- multiple bodies (invoice lot)
- multiple line items (`DettaglioLinee`)
- multiple generic elements with `setElementCount()`
- XML normalization: remove empty elements and automatically split `Causale` in chunks if &gt; 200 characters
- optional `FatturaElettronica` validation thanks to [Slamdunk/php-validatore-fattura-elettronica](https://github.com/Slamdunk/php-validatore-fattura-elettronica)

*(Pacchetto PHP per gestire il formato XML di fatture e notifiche come richiesto dal SdI).*

*([Qui](README.it.org) la documentazione aggiornata in italiano).*

Please refer to

- [PHP SdICoop - Server](https://github.com/taocomp/php-sdicoop-server) for implementing web services required by the Italian Exchange System (aka “SdI”)
- [PHP SdICoop - Client](https://github.com/taocomp/php-sdicoop-client) to connect to SdI web services

See [Forum Italia - Fatturazione Elettronica](https://forum.italia.it/c/fattura-pa) for server configuration, interoperability tests, etc. In particular:

 Apache configuration[Accreditamento SDICoop: configurazione SSL su Apache - Fatturazione Elettroni…](https://forum.italia.it/t/accreditamento-sdicoop-configurazione-ssl-su-apache/3314) Interoperability tests[Test Interoperabilità Soluzioni - Fatturazione Elettronica - Forum Italia](https://forum.italia.it/t/test-interoperabilita-soluzioni/4370)Quickstart
==========

[](#quickstart)

Dependencies
------------

[](#dependencies)

- `php-xml`
- tested for PHP 8+ should work on PHP 5.5 too

Installation
------------

[](#installation)

### Composer

[](#composer)

`composer require taocomp/php-e-invoice-it`

### Manually

[](#manually)

- Clone/download the repository
- `require_once('/path/to/php-e-invoice-it/vendor/autoload.php');`

Invoice
-------

[](#invoice)

### Create a new invoice

[](#create-a-new-invoice)

Create a new FPA12 invoice:

```
$invoice = new FatturaElettronica('FPA12');
```

Create a new FPR12 invoice:

```
$invoice = new FatturaElettronica('FPR12');
```

Create a new invoice from file

```
$invoice = new FatturaElettronica('/path/to/invoice.xml');
```

### Create a custom template invoice to be used later

[](#create-a-custom-template-invoice-to-be-used-later)

```
$prefixPath = __DIR__ . '/tmpfiles';
$filename = 'my-custom-template.xml';
$invoice = new FatturaElettronica('FPR12');
$invoice->setValue('IdTrasmittente/IdCodice', '00011122233');
$invoice->setValue('IdTrasmittente/IdPaese', 'IT');
$invoice->setFilename($filename);
$invoice->setPrefixPath($prefixPath)->save();
```

### Invoice lot and line items

[](#invoice-lot-and-line-items)

Set 3 bodies:

```
$invoice->addBody(2);
// or
$invoice->setBodyCount(3);
```

Set 4 line items for second body:

```
$invoice->addLineItem(3, 2);
// or
$invoice->setLineItemCount(4, 2);
```

### Get/Set values

[](#getset-values)

In general, you can get/set values (and add/get/remove elements) by using a tag/path and an optional *context*.

Please note that:

- an absolute path is relative to the root element: `/FatturaElettronicaHeader` means `/p:FatturaElettronica/FatturaElettronicaHeader`
- tags and relative paths are prefixed with `(.)//`
- xpath predicates are allowed: `$invoice->getValue('DettaglioLinee[2]/NumeroLinea');`

Get a value:

```
$invoice->getValue('ModalitaPagamento');
```

Get a value with a *context*:

```
$invoice->getValue('NumItem', 'DatiContratto');
```

Invalid queries (they return more than one element):

```
$invoice->getValue('IdPaese');
$invoice->getValue('Sede/Indirizzo', 'FatturaElettronicaHeader');
```

Set a value for a specific element:

```
$invoice->setValue('ProgressivoInvio', 10001);
```

Set many single values at once:

```
$invoice->setValues('IdTrasmittente', array(
    'IdCodice' => '09876543210',
    'IdPaese' => 'IT'
));
```

```
$invoice->setValues('CedentePrestatore/Sede', array(
    'Indirizzo' => 'VIA UNIVERSO 1'
));
```

```
$invoice->setValues('CessionarioCommittente', array(
    // CessionarioCommittente/DatiAnagrafici/CodiceFiscale
    'DatiAnagrafici/CodiceFiscale' => '01234567890',
    // Denominazione, somewhere inside CessionarioCommittente
    'Denominazione' => 'BETA SRL'
));
```

```
// Set values for second body
$body2 = $invoice->getBody(2);
$invoice->setValue('Numero', 44, $body2);
$invoice->setValue('Data', '2018-12-12', $body2);
```

Set values to multiple elements at once:

```
$invoice->setValuesToAll('DatiGenerali', array(
    // All "RiferimentoNumeroLinea" somewhere inside DatiGenerali
    'RiferimentoNumeroLinea' => 1,
    // All "IdDocumento" somewhere inside DatiGenerali
    'IdDocumento' => 4455,
    // All "NumItem" somewhere inside DatiGenerali
    'NumItem' => 1
));
```

Set values from an assoc array:

```
$array =  array(
    'DatiAnagraficiVettore' => array(
        'IdFiscaleIVA' => array(
            'IdPaese' => 'IT',
            'IdCodice' => '09876543210'
        ),
        'Anagrafica' => array(
            'Denominazione' => 'TRASPORTO SRLS'
        ),
        'NumeroLicenzaGuida' => 'AA090909'
    ),
    'MezzoTrasporto' => 'Mezzo',
    'CausaleTrasporto' => 'La causale del traporto',
    'NumeroColli' => '1',
    'Descrizione' => 'La descrizione'
);

$invoice->setValuesFromArray('DatiTrasporto', $array);
```

All but `setValueToAll` and `setValuesToAll` methods will throw an exception if `$expr/$context` don’t return just one element.

### Set/Unset stylesheet

[](#setunset-stylesheet)

Set:

```
$invoice->setStylesheet('/path/to/xsl');
```

Unset:

```
$invoice->unsetStylesheet();
```

### Validate invoice

[](#validate-invoice)

You need [Slamdunk/php-validatore-fattura-elettronica](https://github.com/Slamdunk/php-validatore-fattura-elettronica). If you install `php-e-invoice-it` via-composer, you got it as dependency; otherwise you must download and require it manually.

```
$invoice->validate();
```

An exception is thrown (with a message) if the XML is not valid, for example:

```
DOMDocument::schemaValidateSource(): Element 'DatiTrasmissione': Missing child element(s). Expected is ( CodiceDestinatario ).
```

### Save invoice

[](#save-invoice)

Set an optional default destination dir for all invoices:

```
FatturaElettronica::setDefaultPrefixPath('path/to/dir');
```

Set an optional destination dir for current invoice:

```
$invoice->setPrefixPath('path/to/another/dir');
```

Save invoice:

```
$invoice->save();
```

Specify a custom filename:

```
$invoice->setFilename('my-invoice.xml')->save();
```

### Send invoice to SdI

[](#send-invoice-to-sdi)

Setup a `\Taocomp\Einvoicing\SdicoopClient\Client` object (for connecting to webservice SdIRiceviFile):

```
use \Taocomp\Einvoicing\SdicoopClient\Client;
use \Taocomp\Einvoicing\SdicoopClient\FileSdIBase;
use \Taocomp\Einvoicing\SdicoopClient\RispostaSdIRiceviFile;

Client::setPrivateKey('/path/to/client.key');
Client::setClientCert('/path/to/client.pem');
Client::setCaCert('/path/to/ca.pem');

$client = new Client(array(
    'endpoint' => 'https://testservizi.fatturapa.it/ricevi_file',
    'wsdl'     => '/path/to/wsdl/SdIRiceviFile_v1.0.wsdl'
));
```

Send invoice:

```
$fileSdI = new FileSdIBase();
$fileSdI->load($invoice);
$response = new RispostaSdIRiceviFile($client->RiceviFile($fileSdI));
```

Notices
-------

[](#notices)

### Create a new notice

[](#create-a-new-notice)

NotificaEsitoCommittente:

```
$notice = new EsitoCommittente();
```

### Load a notice from file

[](#load-a-notice-from-file)

### Set values

[](#set-values)

```
// Set some values from invoice, second body:
$notice->setValuesFromInvoice($invoice, 2);

// Set values
$notice->setValue('IdentificativoSdI', 1234567);
$notice->setValue('Esito', EsitoCommittente::EC01);
```

### Set/Unset stylesheet

[](#setunset-stylesheet-1)

Set:

```
$notice->setStylesheet('/path/to/xsl');
```

Unset:

```
$notice->unsetStylesheet();
```

### Save notice

[](#save-notice)

```
// Set filename from invoice
$notice->setFilenameFromInvoice($invoice, '_EC_001');

// Save notice
$notice->save();
```

### Send notice to SdI

[](#send-notice-to-sdi)

Setup a `\Taocomp\Einvoicing\SdicoopClient\Client` object (for connecting to webservice SdIRiceviNotifica):

```
use \Taocomp\Einvoicing\SdicoopClient\Client;
use \Taocomp\Einvoicing\SdicoopClient\FileSdI;
use \Taocomp\Einvoicing\SdicoopClient\RispostaSdINotificaEsito;

Client::setPrivateKey('/path/to/client.key');
Client::setClientCert('/path/to/client.pem');
Client::setCaCert('/path/to/ca.pem');

$client = new Client(array(
    'endpoint' => 'https://testservizi.fatturapa.it/ricevi_notifica',
    'wsdl'     => __DIR__ . '/../wsdl/SdIRiceviNotifica_v1.0.wsdl'
));
```

Send notice:

```
$fileSdI = new FileSdI();
$fileSdI->load($notice);
$response = new RispostaSdINotificaEsito($client->NotificaEsito($fileSdI));
```

Tests
=====

[](#tests)

From inside the project root dir: `./vendor/bin/phpunit --testdox tests`

Credits
=======

[](#credits)

We want to thank all contributors of [Forum Italia - Fatturazione Elettronica](https://forum.italia.it/c/fattura-pa) who have shared their snippets and any available info.

Thanks to @Slamdunk for [Slamdunk/php-validatore-fattura-elettronica](https://github.com/Slamdunk/php-validatore-fattura-elettronica)!

License
=======

[](#license)

GPLv3.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~75 days

Recently: every ~185 days

Total

11

Last Release

1957d ago

PHP version history (2 changes)0.1PHP ^7.2

v0.1.8PHP ^7

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/22665235?v=4)[oixan](/maintainers/oixan)[@oixan](https://github.com/oixan)

---

Top Contributors

[![oixan](https://avatars.githubusercontent.com/u/22665235?v=4)](https://github.com/oixan "oixan (6 commits)")[![Slamdunk](https://avatars.githubusercontent.com/u/152236?v=4)](https://github.com/Slamdunk "Slamdunk (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/oixan-php-e-invoice-it/health.svg)

```
[![Health](https://phpackages.com/badges/oixan-php-e-invoice-it/health.svg)](https://phpackages.com/packages/oixan-php-e-invoice-it)
```

###  Alternatives

[taocomp/php-e-invoice-it

A PHP package for managing italian e-invoice and notice XML formats

7318.9k](/packages/taocomp-php-e-invoice-it)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
