├── CONTRIBUTING.md ├── src ├── XmlBlock.php ├── XmlSerializableInterface.php ├── helpers.php ├── Codifiche │ ├── TipoDocumentoCorrelato.php │ ├── TipoCessionePrestazione.php │ ├── TipoDocumento.php │ ├── ModalitaPagamento.php │ ├── RegimeFiscale.php │ ├── TipoCassa.php │ └── Natura.php ├── IntermediarioInterface.php ├── Traits │ ├── CodificaTrait.php │ └── MagicFieldsTrait.php ├── FatturaElettronicaInterface.php ├── XmlFactory.php ├── FatturaElettronica │ ├── FatturaElettronicaHeader │ │ ├── DatiTrasmissione │ │ │ └── IdTrasmittente.php │ │ ├── CessionarioCommittente.php │ │ ├── Common │ │ │ ├── Sede.php │ │ │ └── DatiAnagrafici.php │ │ ├── CedentePrestatore │ │ │ └── IscrizioneRea.php │ │ ├── CedentePrestatore.php │ │ └── DatiTrasmissione.php │ ├── FatturaElettronicaBody │ │ ├── DatiVeicoli.php │ │ ├── DatiGenerali │ │ │ ├── DatiBollo.php │ │ │ ├── DatiRitenuta.php │ │ │ ├── ScontoMaggiorazione.php │ │ │ ├── DatiConvenzione.php │ │ │ ├── DatiCassaPrevidenziale.php │ │ │ ├── DatiSal.php │ │ │ ├── DatiContratto.php │ │ │ ├── DatiDdt.php │ │ │ └── DatiDocumentoCorrelato.php │ │ ├── DatiBeniServizi │ │ │ ├── AltriDatiGestionali.php │ │ │ ├── ScontoMaggiorazione.php │ │ │ ├── DettaglioLinee.php │ │ │ ├── DatiRiepilogo.php │ │ │ └── Linea.php │ │ ├── DatiBeniServizi.php │ │ ├── Allegato.php │ │ ├── DatiPagamento.php │ │ └── DatiGenerali.php │ ├── FatturaElettronicaBody.php │ └── FatturaElettronicaHeader.php ├── XmlRepeatedBlock.php ├── Enum │ └── NaturaIvaType.php ├── FatturaInterface.php ├── XmlValidator.php ├── FatturaElettronica.php ├── FatturaAdapter.php └── FatturaElettronicaFactory.php ├── composer.json ├── LICENSE ├── README.md ├── CODE_OF_CONDUCT.md ├── CHANGELOG.md └── xsd └── xmldsig-core-schema.xsd /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Puoi contribuire al progetto segnalando eventuali bug o proponendo nuove feature. 2 | Grazie! 3 | -------------------------------------------------------------------------------- /src/XmlBlock.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | 16 | abstract class XmlBlock implements XmlSerializableInterface 17 | { 18 | use MagicFieldsTrait; 19 | } 20 | -------------------------------------------------------------------------------- /src/XmlSerializableInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica; 13 | 14 | interface XmlSerializableInterface 15 | { 16 | /** 17 | * @param \XMLWriter $writer 18 | * @return \XMLWriter 19 | */ 20 | public function toXmlBlock(\XMLWriter $writer); 21 | } 22 | -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | * 11 | */ 12 | 13 | if (! function_exists('fe_number_format')) { 14 | /** 15 | * @param float $number 16 | * @param int $decimals 17 | * @return string 18 | */ 19 | function fe_number_format($number, $decimals = 2) { 20 | return number_format($number, $decimals, '.', ''); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Codifiche/TipoDocumentoCorrelato.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\Codifiche; 13 | 14 | 15 | abstract class TipoDocumentoCorrelato 16 | { 17 | const OrdineAcquisto = 'DatiOrdineAcquisto'; 18 | const Contratto = 'DatiContratto'; 19 | const Convenzione = 'DatiConvenzione'; 20 | const Ricezione = 'DatiRicezione'; 21 | const FattureCollegate = 'DatiFattureCollegate'; 22 | } 23 | -------------------------------------------------------------------------------- /src/Codifiche/TipoCessionePrestazione.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\Codifiche; 13 | 14 | use Deved\FatturaElettronica\Traits\CodificaTrait; 15 | 16 | abstract class TipoCessionePrestazione 17 | { 18 | use CodificaTrait; 19 | 20 | const Abbuono = 'AB'; 21 | const SpesaAccessoria = 'AC'; 22 | const Premio = 'PR'; 23 | const Sconto = 'SC'; 24 | 25 | protected static $codifiche = array( 26 | 'AB' => 'Abbuono', 27 | 'AC' => 'Spesa accessoria', 28 | 'PR' => 'Premio', 29 | 'SC' => 'Sconto' 30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /src/IntermediarioInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica; 13 | 14 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\Common\DatiAnagrafici; 15 | 16 | interface IntermediarioInterface 17 | { 18 | /** 19 | * Restituisce i dati anagrafici dell'intermediario 20 | * 21 | * @return DatiAnagrafici 22 | */ 23 | public function getAnagraficaIntermediario(); 24 | 25 | /** 26 | * Restituisce 'TZ' o 'CC' 27 | * 28 | * @return string 29 | */ 30 | public function getSoggettoEmittente(); 31 | } 32 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "deved/fattura-elettronica", 3 | "description": "la libreria definitiva per la creazione delle fatture elettroniche italiane", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Salvatore Guarino", 9 | "email": "sg@deved.it", 10 | "homepage": "http://www.deved.it" 11 | } 12 | ], 13 | "autoload": { 14 | "files": [ 15 | "src/helpers.php" 16 | ], 17 | "psr-4": { 18 | "Deved\\FatturaElettronica\\": "src/" 19 | } 20 | }, 21 | "autoload-dev": { 22 | "psr-4": { 23 | "Deved\\FatturaElettronica\\Tests\\": "tests/" 24 | } 25 | }, 26 | "require": { 27 | "php": "^8.0", 28 | "ext-xmlwriter": "*", 29 | "ext-libxml": "*", 30 | "ext-dom": "*", 31 | "ext-json": "*" 32 | }, 33 | "require-dev": { 34 | "phpunit/phpunit": "^10.5" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Traits/CodificaTrait.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\Traits; 13 | 14 | trait CodificaTrait 15 | { 16 | 17 | /** 18 | * Descrizione della codifica 19 | * 20 | * @param $codice 21 | * @return bool|string 22 | */ 23 | public static function descrizione($codice) 24 | { 25 | $descrizione = false; 26 | try { 27 | $descrizione = self::$codifiche[$codice]; 28 | } catch (\Exception $exception) { 29 | // 30 | } 31 | return $descrizione; 32 | } 33 | /** 34 | * Lista della codifica 35 | * 36 | * @return array 37 | */ 38 | public static function lista() 39 | { 40 | return self::$codifiche; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Codifiche/TipoDocumento.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\Codifiche; 13 | 14 | use Deved\FatturaElettronica\Traits\CodificaTrait; 15 | 16 | abstract class TipoDocumento 17 | { 18 | use CodificaTrait; 19 | 20 | const Fattura = 'TD01'; 21 | const AccontoSuFattura = 'TD02'; 22 | const AccontoSuParcella = 'TD03'; 23 | const NotaDiCredito = 'TD04'; 24 | const NotaDiDebito = 'TD05'; 25 | const Parcella = 'TD06'; 26 | const FatturaDifferita = 'TD24'; 27 | 28 | protected static $codifiche = array( 29 | 'TD01' => 'Fattura', 30 | 'TD02' => 'acconto/anticipo su fattura', 31 | 'TD03' => 'acconto/anticipo su parcella', 32 | 'TD04' => 'nota di credito', 33 | 'TD05' => 'nota di debito', 34 | 'TD06' => 'parcella', 35 | 'TD24' => 'fattura differita' 36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Deved Sas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/FatturaElettronicaInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | 13 | namespace Deved\FatturaElettronica; 14 | 15 | 16 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\CedentePrestatore\IscrizioneRea; 17 | 18 | interface FatturaElettronicaInterface 19 | { 20 | /** 21 | * Restituisce il nome della fattura conforme all'SDI 22 | * @return string 23 | */ 24 | public function getFileName(); 25 | 26 | /** 27 | * Restituisce l'XML della fattura elettronica 28 | * @return string 29 | * @throws \Exception 30 | */ 31 | public function toXml(); 32 | 33 | /** 34 | * @param IscrizioneRea $iscrizioneRea 35 | * @return mixed 36 | */ 37 | public function setIscrizioneRea(IscrizioneRea $iscrizioneRea); 38 | 39 | /** 40 | * Verifica l'xml della fattura 41 | * @return bool 42 | * @throws \Exception 43 | */ 44 | public function verifica(); 45 | } 46 | -------------------------------------------------------------------------------- /src/XmlFactory.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica; 13 | 14 | class XmlFactory 15 | { 16 | /** @var \XMLWriter */ 17 | protected $writer; 18 | 19 | /** 20 | * XmlFactory constructor. 21 | * @param \XMLWriter|null $writer 22 | */ 23 | public function __construct(\XMLWriter $writer = null) 24 | { 25 | $this->writer = $writer ? $writer : new \XMLWriter(); 26 | } 27 | 28 | /** 29 | * @param XmlSerializableInterface $block 30 | * @return void 31 | */ 32 | protected function processXmlBlock(XmlSerializableInterface $block) 33 | { 34 | $block->toXmlBlock($this->writer); 35 | } 36 | 37 | /** 38 | * @param XmlSerializableInterface $document 39 | * @return string 40 | */ 41 | public function toXml(XmlSerializableInterface $document) 42 | { 43 | $this->writer->openMemory(); 44 | $this->writer->startDocument('1.0', 'UTF-8'); 45 | $this->writer->setIndent(4); 46 | $this->processXmlBlock($document); 47 | return $this->writer->outputMemory(true); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaHeader/DatiTrasmissione/IdTrasmittente.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\DatiTrasmissione; 13 | 14 | use Deved\FatturaElettronica\XmlSerializableInterface; 15 | 16 | class IdTrasmittente implements XmlSerializableInterface 17 | { 18 | /** @var string */ 19 | public $idPaese; 20 | /** @var string */ 21 | public $idCodice; 22 | 23 | /** 24 | * IdTrasmittente constructor. 25 | * @param string $idPaese 26 | * @param integer $idCodice 27 | */ 28 | public function __construct($idPaese, $idCodice) 29 | { 30 | $this->idPaese = $idPaese; 31 | $this->idCodice = $idCodice; 32 | } 33 | 34 | /** 35 | * @param \XMLWriter $writer 36 | * @return \XMLWriter 37 | */ 38 | public function toXmlBlock(\XMLWriter $writer) 39 | { 40 | $writer->startElement('IdTrasmittente'); 41 | $writer->writeElement('IdPaese', $this->idPaese); 42 | $writer->writeElement('IdCodice', $this->idCodice); 43 | $writer->endElement(); 44 | return $writer; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiVeicoli.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class DatiVeicoli implements XmlSerializableInterface 18 | { 19 | use MagicFieldsTrait; 20 | 21 | /** @var string */ 22 | protected $data; 23 | /** @var string */ 24 | protected $totalePercorso; 25 | 26 | /** 27 | * DatiVeicoli constructor. 28 | * @param string $data 29 | * @param string $totalePercorso 30 | */ 31 | public function __construct($data, $totalePercorso) 32 | { 33 | $this->data = $data; 34 | $this->totalePercorso = $totalePercorso; 35 | } 36 | 37 | /** 38 | * @param \XMLWriter $writer 39 | * @return \XMLWriter 40 | */ 41 | public function toXmlBlock(\XMLWriter $writer) 42 | { 43 | $writer->startElement('DatiVeicoli'); 44 | $writer->writeElement('Data', $this->data); 45 | $writer->writeElement('TotalePercorso', $this->totalePercorso); 46 | $this->writeXmlFields($writer); 47 | $writer->endElement(); 48 | return $writer; 49 | } 50 | } -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiGenerali/DatiBollo.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class DatiBollo implements XmlSerializableInterface 18 | { 19 | use MagicFieldsTrait; 20 | 21 | /** @var DatiBollo */ 22 | protected $datiBollo; 23 | /** @var string */ 24 | protected $bolloVirtuale; 25 | /** @var float */ 26 | protected $importoBollo; 27 | 28 | /** 29 | * DatiBollo constructor. 30 | * @param $bolloVirtuale 31 | * @param $importo 32 | */ 33 | public function __construct($bolloVirtuale, $importo) 34 | { 35 | $this->bolloVirtuale = $bolloVirtuale; 36 | $this->importoBollo = $importo; 37 | } 38 | 39 | /** 40 | * @param \XMLWriter $writer 41 | * @return \XMLWriter 42 | */ 43 | public function toXmlBlock(\XMLWriter $writer) 44 | { 45 | $writer->startElement('DatiBollo'); 46 | $writer->writeElement('BolloVirtuale', $this->bolloVirtuale); 47 | $writer->writeElement('ImportoBollo', fe_number_format($this->importoBollo, 2)); 48 | $this->writeXmlFields($writer); 49 | $writer->endElement(); 50 | return $writer; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/deved/fattura-elettronica.svg?style=flat-square)](https://packagist.org/packages/deved/fattura-elettronica) 2 | [![Build Status](https://github.com/deved-it/fattura-elettronica/actions/workflows/php.yml/badge.svg)](https://github.com/deved-it/fattura-elettronica/actions/workflows/php.yml) 3 | [![Total Downloads](https://img.shields.io/packagist/dt/deved/fattura-elettronica.svg?style=flat-square)](https://packagist.org/packages/deved/fattura-elettronica) 4 | [![License](https://poser.pugx.org/deved/fattura-elettronica/license)](https://packagist.org/packages/deved/fattura-elettronica) 5 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fdeved-it%2Ffattura-elettronica.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fdeved-it%2Ffattura-elettronica?ref=badge_shield) 6 | 7 | # Fattura Elettronica verso privati e PA 8 | 9 | ## Descrizione 10 | Libreria PHP per la generazione di fatture elettroniche italiane in formato XML conforme alle specifiche tecniche dell'Agenzia delle Entrate. La libreria supporta la creazione di fatture sia verso privati (B2B/B2C) che verso la Pubblica Amministrazione (PA). 11 | [qui](https://github.com/deved-it/fattura-elettronica/issues/new). 12 | 13 | ## Installazione 14 | 15 | composer require deved/fattura-elettronica 16 | 17 | ## Documentazione 18 | 19 | [deved-it.github.io/fattura-elettronica](https://deved-it.github.io/fattura-elettronica) 20 | 21 | 22 | ## License 23 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fdeved-it%2Ffattura-elettronica.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fdeved-it%2Ffattura-elettronica?ref=badge_large) 24 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaHeader/CessionarioCommittente.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader; 13 | 14 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\Common\DatiAnagrafici; 15 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\Common\Sede; 16 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 17 | use Deved\FatturaElettronica\XmlSerializableInterface; 18 | 19 | class CessionarioCommittente implements XmlSerializableInterface 20 | { 21 | use MagicFieldsTrait; 22 | /** @var DatiAnagrafici */ 23 | protected $datiAnagrafici; 24 | /** @var Sede */ 25 | protected $sede; 26 | 27 | /** 28 | * CessionarioCommittente constructor. 29 | * @param DatiAnagrafici $datiAnagrafici 30 | * @param Sede $sede 31 | */ 32 | public function __construct( 33 | DatiAnagrafici $datiAnagrafici, 34 | Sede $sede 35 | ) { 36 | $this->datiAnagrafici = $datiAnagrafici; 37 | $this->sede = $sede; 38 | } 39 | 40 | /** 41 | * @param \XMLWriter $writer 42 | * @return \XMLWriter 43 | */ 44 | public function toXmlBlock(\XMLWriter $writer) 45 | { 46 | $writer->startElement('CessionarioCommittente'); 47 | $this->datiAnagrafici->toXmlBlock($writer); 48 | $this->sede->toXmlBlock($writer); 49 | $this->writeXmlFields($writer); 50 | $writer->endElement(); 51 | return $writer; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Traits/MagicFieldsTrait.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\Traits; 13 | 14 | 15 | trait MagicFieldsTrait 16 | { 17 | protected $xmlFields = []; 18 | protected $hiddenXmlFields = []; 19 | 20 | public function __set($name, $value) 21 | { 22 | $this->xmlFields[$name] = $value; 23 | } 24 | 25 | public function __get($name) 26 | { 27 | if (key_exists($name, $this->xmlFields)) { 28 | return $this->xmlFields[$name]; 29 | } 30 | return false; 31 | } 32 | 33 | /** 34 | * @param $field 35 | * @param \XMLWriter $writer 36 | */ 37 | protected function writeXmlField($field, \XMLWriter $writer) 38 | { 39 | if ($this->{$field} !== false) { 40 | $writer->writeElement(ucfirst($field), $this->{$field}); 41 | $this->hideXmlField($field); 42 | } 43 | } 44 | 45 | /** 46 | * Tag xmlField 47 | * 48 | * @param $field 49 | */ 50 | protected function hideXmlField($field) 51 | { 52 | if (!in_array($field, $this->hiddenXmlFields)) { 53 | $this->hiddenXmlFields[] = $field; 54 | } 55 | } 56 | 57 | /** 58 | * @param \XMLWriter $writer 59 | */ 60 | protected function writeXmlFields(\XMLWriter $writer) 61 | { 62 | foreach ($this->xmlFields as $key => $value) { 63 | if (!in_array($key, $this->hiddenXmlFields)) { 64 | $writer->writeElement(ucfirst($key), $value); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiGenerali/DatiRitenuta.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class DatiRitenuta implements XmlSerializableInterface 18 | { 19 | use MagicFieldsTrait; 20 | 21 | /** @var DatiRitenuta */ 22 | protected $datiRitenuta; 23 | /** @var string */ 24 | protected $tipo; 25 | /** @var float */ 26 | protected $importo; 27 | /** @var float */ 28 | protected $aliquota; 29 | /** @var string */ 30 | protected $causale; 31 | 32 | /** 33 | * DatiRitenuta constructor. 34 | * @param string $numeroDdt 35 | * @param string $dataDdt 36 | * @param array $riferimentoNumeroLinee 37 | */ 38 | public function __construct($tipo, $importo, $aliquota, $causale) 39 | { 40 | $this->tipo = $tipo; 41 | $this->importo = $importo; 42 | $this->aliquota = $aliquota; 43 | $this->causale = $causale; 44 | } 45 | 46 | /** 47 | * @param \XMLWriter $writer 48 | * @return \XMLWriter 49 | */ 50 | public function toXmlBlock(\XMLWriter $writer) 51 | { 52 | $writer->startElement('DatiRitenuta'); 53 | $writer->writeElement('TipoRitenuta', $this->tipo); 54 | $writer->writeElement('ImportoRitenuta', fe_number_format($this->importo,2)); 55 | $writer->writeElement('AliquotaRitenuta', fe_number_format($this->aliquota,2)); 56 | $writer->writeElement('CausalePagamento', $this->causale); 57 | $writer->endElement(); 58 | return $writer; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiGenerali/ScontoMaggiorazione.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class ScontoMaggiorazione implements XmlSerializableInterface 18 | { 19 | use MagicFieldsTrait; 20 | 21 | const SCONTO = 'SC'; 22 | const MAGGIORAZIONE = 'MG'; 23 | 24 | /** @var ScontoMaggiorazione */ 25 | protected $scontoMaggiorazione; 26 | /** @var string */ 27 | protected $tipo; 28 | /** @var float */ 29 | protected $percentuale; 30 | /** @var float */ 31 | protected $importo; 32 | 33 | /** 34 | * ScontoMaggiorazione constructor. 35 | * @param $tipo 36 | * @param $percentuale 37 | * @param $importo 38 | */ 39 | public function __construct($tipo, $percentuale, $importo) 40 | { 41 | $this->tipo = $tipo; 42 | $this->percentuale = $percentuale; 43 | $this->importo = $importo; 44 | } 45 | 46 | /** 47 | * @param \XMLWriter $writer 48 | * @return \XMLWriter 49 | */ 50 | public function toXmlBlock(\XMLWriter $writer) 51 | { 52 | $writer->startElement('ScontoMaggiorazione'); 53 | $writer->writeElement('Tipo', $this->tipo); 54 | if ($this->percentuale) { 55 | $writer->writeElement('Percentuale', fe_number_format($this->percentuale, 2)); 56 | } 57 | if ($this->importo) { 58 | $writer->writeElement('Importo', fe_number_format($this->importo, 2)); 59 | } 60 | $this->writeXmlFields($writer); 61 | $writer->endElement(); 62 | return $writer; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaHeader/Common/Sede.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\Common; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class Sede implements XmlSerializableInterface 18 | { 19 | use MagicFieldsTrait; 20 | /** @var string */ 21 | protected $nazione; 22 | /** @var string */ 23 | protected $indirizzo; 24 | /** @var string */ 25 | protected $cap; 26 | /** @var string */ 27 | protected $comune; 28 | /** @var string */ 29 | protected $provincia; 30 | 31 | /** 32 | * Sede constructor. 33 | * @param string $nazione 34 | * @param string $indirizzo 35 | * @param string $cap 36 | * @param string $comune 37 | * @param string $provincia 38 | */ 39 | public function __construct( 40 | $nazione, 41 | $indirizzo, 42 | $cap, 43 | $comune, 44 | $provincia = '' 45 | ) { 46 | $this->nazione = $nazione; 47 | $this->indirizzo = $indirizzo; 48 | $this->cap = $cap; 49 | $this->comune = $comune; 50 | $this->provincia = $provincia; 51 | } 52 | 53 | /** 54 | * @param \XMLWriter $writer 55 | * @return \XMLWriter 56 | */ 57 | public function toXmlBlock(\XMLWriter $writer) 58 | { 59 | $writer->startElement('Sede'); 60 | $writer->writeElement('Indirizzo', $this->indirizzo); 61 | $writer->writeElement('CAP', $this->cap); 62 | $writer->writeElement('Comune', $this->comune); 63 | if ($this->provincia) { 64 | $writer->writeElement('Provincia', $this->provincia); 65 | } 66 | $writer->writeElement('Nazione', $this->nazione); 67 | $this->writeXmlFields($writer); 68 | $writer->endElement(); 69 | return $writer; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiBeniServizi/AltriDatiGestionali.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiBeniServizi; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class AltriDatiGestionali implements XmlSerializableInterface 18 | { 19 | use MagicFieldsTrait; 20 | 21 | /** @var string */ 22 | public $tipoDato; 23 | /** @var string */ 24 | public $riferimentoTesto; 25 | /** @var string */ 26 | public $riferimentoNumero; 27 | /** @var string */ 28 | public $riferimentoData; 29 | 30 | /** 31 | * AltriDatiGestionali constructor. 32 | * 33 | * @param $tipoDato 34 | * @param null $riferimentoTesto 35 | * @param null $riferimentoNumero 36 | * @param null $riferimentoData 37 | */ 38 | public function __construct($tipoDato, $riferimentoTesto = null, $riferimentoNumero = null, $riferimentoData = null) 39 | { 40 | $this->tipoDato = $tipoDato; 41 | $this->riferimentoTesto = $riferimentoTesto; 42 | $this->riferimentoNumero = $riferimentoNumero; 43 | $this->riferimentoData = $riferimentoData; 44 | } 45 | 46 | /** 47 | * @param \XMLWriter $writer 48 | * @return \XMLWriter 49 | */ 50 | public function toXmlBlock(\XMLWriter $writer) 51 | { 52 | $writer->startElement('AltriDatiGestionali'); 53 | $writer->writeElement('TipoDato', $this->tipoDato); 54 | if ($this->riferimentoTesto) $writer->writeElement('RiferimentoTesto', $this->riferimentoTesto); 55 | if ($this->riferimentoNumero) $writer->writeElement('RiferimentoNumero', $this->riferimentoNumero); 56 | if ($this->riferimentoData) $writer->writeElement('RiferimentoData', $this->riferimentoData); 57 | $this->writeXmlFields($writer); 58 | $writer->endElement(); 59 | return $writer; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/Codifiche/ModalitaPagamento.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\Codifiche; 13 | 14 | use Deved\FatturaElettronica\Traits\CodificaTrait; 15 | 16 | abstract class ModalitaPagamento 17 | { 18 | use CodificaTrait; 19 | 20 | const Contanti = 'MP01'; 21 | const Assegno = 'MP02'; 22 | const AssegnoCircolare = 'MP03'; 23 | const ContantiPressoTesoreria = 'MP04'; 24 | const Bonifico = 'MP05'; 25 | const VagliaCambiario = 'MP06'; 26 | const BollettinoBancario = 'MP07'; 27 | const CartaDiPagamento = 'MP08'; 28 | const RID = 'MP09'; 29 | const RIDUtenze = 'MP10'; 30 | const RIDVeloce = 'MP11'; 31 | const RIBA = 'MP12'; 32 | const MAV = 'MP13'; 33 | const QuietanzaErario = 'MP14'; 34 | const GirocontoSpeciale = 'MP15'; 35 | const DomiciliazioneBancaria = 'MP16'; 36 | const DomiciliazionePostale = 'MP17'; 37 | const BollettinoPostale = 'MP18'; 38 | const SEPA = 'MP19'; 39 | const SEPA_CORE = 'MP20'; 40 | const SEPA_B2B = 'MP21'; 41 | const TrattenutaSommeRiscosse = 'MP22'; 42 | 43 | 44 | protected static $codifiche = array( 45 | 'MP01' => 'contanti', 46 | 'MP02' => 'assegno', 47 | 'MP03' => 'assegno circolare', 48 | 'MP04' => 'contanti presso Tesoreria', 49 | 'MP05' => 'bonifico', 50 | 'MP06' => 'vaglia cambiario', 51 | 'MP07' => 'bollettino bancario', 52 | 'MP08' => 'carta di pagamento', 53 | 'MP09' => 'RID', 54 | 'MP10' => 'RID utenze', 55 | 'MP11' => 'RID veloce', 56 | 'MP12' => 'RIBA', 57 | 'MP13' => 'MAV', 58 | 'MP14' => 'quietanza erario', 59 | 'MP15' => 'giroconto su conti di contabilità speciale', 60 | 'MP16' => 'domiciliazione bancaria', 61 | 'MP17' => 'domiciliazione postale', 62 | 'MP18' => 'bollettino di c/c postale', 63 | 'MP19' => 'SEPA Direct Debit', 64 | 'MP20' => 'SEPA Direct Debit CORE', 65 | 'MP21' => 'SEPA Direct Debit B2B', 66 | 'MP22' => 'Trattenuta su somme già riscosse' 67 | ); 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaHeader/CedentePrestatore/IscrizioneRea.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\CedentePrestatore; 13 | 14 | use Deved\FatturaElettronica\XmlSerializableInterface; 15 | 16 | class IscrizioneRea implements XmlSerializableInterface 17 | { 18 | const SOCIO_UNICO = 'SU'; 19 | const SOCIETA_PLURIPERSONALE = 'SM'; 20 | const NON_IN_LIQUIDAZIONE = 'LN'; 21 | const IN_LIQUIDAZIONE = 'LS'; 22 | 23 | /** @var string */ 24 | protected $ufficio; 25 | /** @var string */ 26 | protected $numeroRea; 27 | /** @var float|null */ 28 | protected $capitaleSociale; 29 | /** @var string|null */ 30 | protected $socioUnico; 31 | /** @var string */ 32 | protected $statoLiquidazione; 33 | 34 | /** 35 | * IscrizioneRea constructor. 36 | * @param string $ufficio 37 | * @param string $numeroRea 38 | * @param null|float $capitaleSociale 39 | * @param null|string $socioUnico 40 | * @param string $statoLiquidazione 41 | */ 42 | public function __construct($ufficio, $numeroRea, $capitaleSociale = null, $socioUnico = null, $statoLiquidazione = 'LN') 43 | { 44 | $this->ufficio = $ufficio; 45 | $this->numeroRea = $numeroRea; 46 | $this->capitaleSociale = $capitaleSociale; 47 | $this->socioUnico = $socioUnico; 48 | $this->statoLiquidazione = $statoLiquidazione; 49 | } 50 | 51 | /** 52 | * @param \XMLWriter $writer 53 | * @return \XMLWriter 54 | */ 55 | public function toXmlBlock(\XMLWriter $writer) 56 | { 57 | $writer->startElement('IscrizioneREA'); 58 | $writer->writeElement('Ufficio', $this->ufficio); 59 | $writer->writeElement('NumeroREA', $this->numeroRea); 60 | if ($this->capitaleSociale) { 61 | $writer->writeElement('CapitaleSociale', fe_number_format($this->capitaleSociale)); 62 | } 63 | if ($this->socioUnico) { 64 | $writer->writeElement('SocioUnico', $this->socioUnico); 65 | } 66 | $writer->writeElement('StatoLiquidazione', $this->statoLiquidazione); 67 | $writer->endElement(); 68 | 69 | return $writer; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiBeniServizi.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody; 13 | 14 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiBeniServizi\DatiRiepilogo; 15 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiBeniServizi\DettaglioLinee; 16 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiBeniServizi\Linea; 17 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 18 | use Deved\FatturaElettronica\XmlSerializableInterface; 19 | 20 | class DatiBeniServizi implements XmlSerializableInterface 21 | { 22 | use MagicFieldsTrait; 23 | 24 | /** @var DettaglioLinee */ 25 | protected $dettaglioLinee; 26 | /** @var DatiRiepilogo */ 27 | protected $datiRiepilogo; 28 | 29 | /** 30 | * DatiBeniServizi constructor. 31 | * @param DettaglioLinee $dettaglioLinee 32 | * @param DatiRiepilogo|null $datiRiepilogo 33 | */ 34 | public function __construct(DettaglioLinee $dettaglioLinee, DatiRiepilogo $datiRiepilogo = null) 35 | { 36 | $this->dettaglioLinee = $dettaglioLinee; 37 | if ($datiRiepilogo) { 38 | $this->datiRiepilogo = $datiRiepilogo; 39 | return; 40 | } 41 | $this->datiRiepilogo = $this->calcolaDatiRiepilogo(); 42 | } 43 | 44 | /** 45 | * @param \XMLWriter $writer 46 | * @return \XMLWriter 47 | */ 48 | public function toXmlBlock(\XMLWriter $writer) 49 | { 50 | $writer->startElement('DatiBeniServizi'); 51 | $this->dettaglioLinee->toXmlBlock($writer); 52 | $this->datiRiepilogo->toXmlBlock($writer); 53 | $this->writeXmlFields($writer); 54 | $writer->endElement(); 55 | return $writer; 56 | } 57 | 58 | /** 59 | * @return DatiRiepilogo 60 | */ 61 | protected function calcolaDatiRiepilogo() 62 | { 63 | $imponibile = 0; 64 | $aliquota = 22; 65 | /** @var Linea $linea */ 66 | foreach ($this->dettaglioLinee as $linea) { 67 | $imponibile += $linea->prezzoTotale(false); 68 | $aliquota = $linea->getAliquotaIva(); 69 | } 70 | return new DatiRiepilogo($imponibile, $aliquota); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/Allegato.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody; 13 | 14 | use Deved\FatturaElettronica\XmlRepeatedBlock; 15 | 16 | class Allegato extends XmlRepeatedBlock 17 | { 18 | public $nomeAttachment; 19 | public $algoritmoCompressione; 20 | public $formatoAttachment; 21 | public $descrizioneAttachment; 22 | public $attachment; 23 | 24 | /** 25 | * Allegati constructor. 26 | * @param string $nomeAttachment 27 | * @param string $attachment 28 | * @param string | null $algoritmoCompressione 29 | * @param string | null $formatoAttachment 30 | * @param string | null $descrizioneAttachment 31 | */ 32 | public function __construct( 33 | $nomeAttachment, 34 | $attachment, 35 | $formatoAttachment = null, 36 | $algoritmoCompressione = null, 37 | $descrizioneAttachment = null 38 | ) { 39 | $this->nomeAttachment = $nomeAttachment; 40 | $this->algoritmoCompressione = $algoritmoCompressione; 41 | $this->formatoAttachment = $formatoAttachment; 42 | $this->descrizioneAttachment = $descrizioneAttachment; 43 | $this->attachment = $attachment; 44 | parent::__construct(); 45 | } 46 | 47 | /** 48 | * @param \XMLWriter $writer 49 | * @return \XMLWriter 50 | */ 51 | public function toXmlBlock(\XMLWriter $writer) 52 | { 53 | /** @var Allegato $block */ 54 | foreach ($this->blocks as $block) { 55 | $writer->startElement('Allegati'); 56 | $writer->writeElement('NomeAttachment', $block->nomeAttachment); 57 | if ($block->algoritmoCompressione) { 58 | $writer->writeElement('AlgoritmoCompressione', $block->algoritmoCompressione); 59 | } 60 | if ($block->formatoAttachment) { 61 | $writer->writeElement('FormatoAttachment', $block->formatoAttachment); 62 | } 63 | if ($block->descrizioneAttachment) { 64 | $writer->writeElement('DescrizioneAttachment', $block->descrizioneAttachment); 65 | } 66 | $writer->writeElement('Attachment', base64_encode($block->attachment)); 67 | $block->writeXmlFields($writer); 68 | $writer->endElement(); 69 | } 70 | return $writer; 71 | } 72 | } -------------------------------------------------------------------------------- /src/Codifiche/RegimeFiscale.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\Codifiche; 13 | use Deved\FatturaElettronica\Traits\CodificaTrait; 14 | 15 | abstract class RegimeFiscale 16 | { 17 | use CodificaTrait; 18 | 19 | const Ordinario = 'RF01'; 20 | const ContribuentiMinimi = 'RF02'; 21 | const Agricoltura = 'RF04'; 22 | const VenditaSalitTabacchi = 'RF05'; 23 | const CommercioFiammiferi = 'RF06'; 24 | const Editoria = 'RF07'; 25 | const GestioneServiziTelefoniaPubblica = 'RF08'; 26 | const RivenditaDocumentiTrasportoPubblico = 'RF09'; 27 | const IntrattenimentiGiochi = 'RF10'; 28 | const AgenzieViaggiTurismo = 'RF11'; 29 | const Agriturismo = 'RF12'; 30 | const VenditeDomicilio = 'RF13'; 31 | const RivenditaBeniUsati = 'RF14'; 32 | const AgenzieVenditeAsta = 'RF15'; 33 | const IvaPerCassaPA = 'RF16'; 34 | const IvaPerCassa = 'RF17'; 35 | const Altro = 'RF18'; 36 | const RegimeForfettario = 'RF19'; 37 | 38 | 39 | protected static $codifiche = array( 40 | 'RF01' => 'Ordinario', 41 | 'RF02' => 'Contribuenti minimi (art.1, c.96-117, L. 244/07)', 42 | 'RF04' => 'Agricoltura e attività connesse e pesca (artt.34 e 34-bis, DPR 633/72)', 43 | 'RF05' => 'Vendita sali e tabacchi (art.74, c.1, DPR. 633/72)', 44 | 'RF06' => 'Commercio fiammiferi (art.74, c.1, DPR 633/72)', 45 | 'RF07' => 'Editoria (art.74, c.1, DPR 633/72)', 46 | 'RF08' => 'Gestione servizi telefonia pubblica (art.74, c.1, DPR 633/72)', 47 | 'RF09' => 'Rivendita documenti di trasporto pubblico e di sosta (art.74, c.1, DPR 633/72)', 48 | 'RF10' => 'Intrattenimenti, giochi e altre attività di cui alla tariffa 49 | allegata al DPR 640/72 (art.74, c.6, DPR 633/72)', 50 | 'RF11' => 'Agenzie viaggi e turismo (art.74-ter, DPR 633/72)', 51 | 'RF12' => 'Agriturismo (art.5, c.2, L. 413/91)', 52 | 'RF13' => 'Vendite a domicilio (art.25-bis, c.6, DPR 600/73)', 53 | 'RF14' => 'Rivendita beni usati, oggetti d’arte, d’antiquariato o da collezione (art.36, DL 41/95)', 54 | 'RF15' => 'Agenzie di vendite all’asta di oggetti d’arte, antiquariato o da collezione (art.40-bis, DL 41/95)', 55 | 'RF16' => 'IVA per cassa P.A. (art.6, c.5, DPR 633/72)', 56 | 'RF17' => 'IVA per cassa (art. 32-bis, DL 83/2012)', 57 | 'RF18' => 'Altro', 58 | 'RF19' => 'Regime forfettario (art.1, c.54-89, L. 190/2014)' 59 | ); 60 | } 61 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiGenerali/DatiConvenzione.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class DatiConvenzione implements XmlSerializableInterface { 18 | const FE_CODE = '2.1.2'; 19 | use MagicFieldsTrait; 20 | protected $codiceCommessaConvenzione; 21 | protected $currentIndex = 0; 22 | protected $riferimentoNumeroLinee = []; 23 | protected $idDocumento; 24 | protected $numItem; 25 | protected $codiceCUP; 26 | protected $codiceCIG; 27 | protected $data; 28 | 29 | /** 30 | * DatiContratto constructor. 31 | * @param string $idDocumento 32 | * @param string $data 33 | * @param string $codiceCommessaConvenzione 34 | * @param int[] $riferimentoNumeroLinee 35 | * @param string $numItem 36 | * @param string $codiceCUP 37 | * @param string $codiceCIG 38 | */ 39 | public function __construct($idDocumento, $data, $codiceCommessaConvenzione, $riferimentoNumeroLinee = [], $numItem = '', $codiceCUP = null, $codiceCIG = null) { 40 | $this->idDocumento = $idDocumento; 41 | $this->riferimentoNumeroLinee = $riferimentoNumeroLinee; 42 | $this->data = $data; 43 | $this->codiceCommessaConvenzione = $codiceCommessaConvenzione; 44 | $this->numItem = $numItem; 45 | $this->codiceCUP = $codiceCUP; 46 | $this->codiceCIG = $codiceCIG; 47 | } 48 | 49 | /** 50 | * @param \XMLWriter $writer 51 | * @return \XMLWriter 52 | */ 53 | public function toXmlBlock(\XMLWriter $writer) { 54 | $writer->startElement('DatiConvenzione'); 55 | if (count($this->riferimentoNumeroLinee) > 0) { 56 | /** @var int $linea */ 57 | foreach ($this->riferimentoNumeroLinee as $linea) { 58 | $writer->writeElement('RiferimentoNumeroLinea', $linea); 59 | } 60 | } 61 | $writer->writeElement('IdDocumento', $this->idDocumento); 62 | $writer->writeElement('Data', $this->data); 63 | if ($this->numItem) { 64 | $writer->writeElement('NumItem', $this->numItem); 65 | } 66 | $writer->writeElement('CodiceCommessaConvenzione', $this->codiceCommessaConvenzione); 67 | 68 | if ($this->codiceCUP) { 69 | $writer->writeElement('CodiceCUP', $this->codiceCUP); 70 | } 71 | if ($this->codiceCIG) { 72 | $writer->writeElement('CodiceCIG', $this->codiceCIG); 73 | } 74 | $writer->endElement(); 75 | return $writer; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/XmlRepeatedBlock.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica; 13 | 14 | abstract class XmlRepeatedBlock extends XmlBlock implements \Countable, \Iterator 15 | { 16 | protected $blocks = []; 17 | protected $currentIndex = 0; 18 | 19 | public function __construct() 20 | { 21 | $this->blocks[] = $this; 22 | } 23 | 24 | public function addBlock(XmlBlock $block) 25 | { 26 | $this->blocks[] = $block; 27 | } 28 | 29 | /** 30 | * Return the current element 31 | * @link https://php.net/manual/en/iterator.current.php 32 | * @return mixed Can return any type. 33 | * @since 5.0.0 34 | */ 35 | public function current(): mixed 36 | { 37 | return $this->blocks[$this->currentIndex]; 38 | } 39 | 40 | /** 41 | * Move forward to next element 42 | * @link https://php.net/manual/en/iterator.next.php 43 | * @return void Any returned value is ignored. 44 | * @since 5.0.0 45 | */ 46 | public function next(): void 47 | { 48 | $this->currentIndex++; 49 | } 50 | 51 | /** 52 | * Return the key of the current element 53 | * @link https://php.net/manual/en/iterator.key.php 54 | * @return mixed scalar on success, or null on failure. 55 | * @since 5.0.0 56 | */ 57 | public function key(): mixed 58 | { 59 | return $this->currentIndex; 60 | } 61 | 62 | /** 63 | * Checks if current position is valid 64 | * @link https://php.net/manual/en/iterator.valid.php 65 | * @return boolean The return value will be casted to boolean and then evaluated. 66 | * Returns true on success or false on failure. 67 | * @since 5.0.0 68 | */ 69 | public function valid(): bool 70 | { 71 | return isset($this->blocks[$this->currentIndex]); 72 | } 73 | 74 | /** 75 | * Rewind the Iterator to the first element 76 | * @link https://php.net/manual/en/iterator.rewind.php 77 | * @return void Any returned value is ignored. 78 | * @since 5.0.0 79 | */ 80 | public function rewind(): void 81 | { 82 | $this->currentIndex = 0; 83 | } 84 | 85 | /** 86 | * Count elements of an object 87 | * @link https://php.net/manual/en/countable.count.php 88 | * @return int The custom count as an integer. 89 | *

90 | *

91 | * The return value is cast to an integer. 92 | * @since 5.1.0 93 | */ 94 | public function count(): int 95 | { 96 | return count($this->blocks); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/Enum/NaturaIvaType.php: -------------------------------------------------------------------------------- 1 | 51 | */ 52 | class NaturaIvaType { 53 | 54 | const ESCLUSA_ART_15 = "N1"; 55 | const NON_SOGGETTA = "N2"; 56 | const NON_SOGGETTA_DPR633 = "N2.1"; 57 | const NON_SOGGETTA_ALTRI_CASI = "N2.2"; 58 | const NON_IMPONIBILI = "N3"; 59 | const NON_IMPONIBILI_ESPORTAZIONI = "N3.1"; 60 | const NON_IMPONIBILI_CESSIONI_INTRACOMUNITARIA = "N3.2"; 61 | const NON_IMPONIBILI_CESSIONI_SAN_MARINO = "N3.3"; 62 | const NON_IMPONIBILI_OPERAZIONI_ASSIMILATE_CESSIONI_ESPORTAZIONE = "N3.4"; 63 | const NON_IMPONIBILI_DICHIARAZIONE_INTENTO = "N3.5"; 64 | const NON_IMPONIBILI_ALTRE_OPERAZIONI = "N3.6"; 65 | const ESENTI = "N4"; 66 | const REGIME_MARGINE = "N5"; 67 | const REVERSE_CHARGE = "N6"; 68 | const REVERSE_CHARGE_CESSIONE_ROTTAMI = "N6.1"; 69 | const REVERSE_CHARGE_CESSIONE_ORO_ARGENTO = "N6.2"; 70 | const REVERSE_CHARGE_SUBAPPALTO_SETTORE_EDILE = "N6.3"; 71 | const REVERSE_CHARGE_CESSIONE_FABBRICATI = "N6.4"; 72 | const REVERSE_CHARGE_CESSIONE_TELEFONI_CELLULARI = "N6.5"; 73 | const REVERSE_CHARGE_CESSIONE_PRODOTTI_ELETTRONICI = "N6.6"; 74 | const REVERSE_CHARGE_PRESTAZIONI_COMPARTO_EDILE = "N6.7"; 75 | const REVERSE_CHARGE_OPERAZIONI_SETTORE_ENERGETICO = "N6.8"; 76 | const REVERSE_CHARGE_ALTRI_CASI = "N6.9"; 77 | const IVA_ASSOLTA_ESTERO = "N7"; 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica; 13 | 14 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\Allegato; 15 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiBeniServizi; 16 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali; 17 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiPagamento; 18 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiVeicoli; 19 | use Deved\FatturaElettronica\XmlSerializableInterface; 20 | 21 | class FatturaElettronicaBody implements XmlSerializableInterface 22 | { 23 | const FE_CODE = '2.0'; 24 | /** @var DatiGenerali */ 25 | public $datGenerali; 26 | /** @var DatiBeniServizi */ 27 | protected $datiBeniServizi; 28 | /** @var DatiPagamento */ 29 | protected $datiPagamento; 30 | /** @var Allegato */ 31 | protected $allegato; 32 | /** @var DatiVeicoli */ 33 | protected $datiVeicoli; 34 | 35 | /** 36 | * FatturaElettronicaBody constructor. 37 | * @param DatiGenerali $datiGenerali 38 | * @param DatiBeniServizi $datiBeniServizi 39 | * @param DatiPagamento $datiPagamento 40 | */ 41 | public function __construct( 42 | DatiGenerali $datiGenerali, 43 | DatiBeniServizi $datiBeniServizi, 44 | DatiPagamento $datiPagamento = null, 45 | Allegato $allegato = null, 46 | DatiVeicoli $datiVeicoli = null 47 | ) { 48 | $this->datGenerali = $datiGenerali; 49 | $this->datiBeniServizi = $datiBeniServizi; 50 | $this->datiPagamento = $datiPagamento; 51 | $this->allegato = $allegato; 52 | $this->datiVeicoli = $datiVeicoli; 53 | } 54 | 55 | /** 56 | * @param \XMLWriter $writer 57 | * @return \XMLWriter 58 | */ 59 | public function toXmlBlock(\XMLWriter $writer) 60 | { 61 | $writer->startElement('FatturaElettronicaBody'); 62 | $this->datGenerali->toXmlBlock($writer); 63 | $this->datiBeniServizi->toXmlBlock($writer); 64 | if ($this->datiVeicoli) { 65 | $this->datiVeicoli->toXmlBlock($writer); 66 | } 67 | if ($this->datiPagamento) { 68 | $this->datiPagamento->toXmlBlock($writer); 69 | } 70 | if ($this->allegato) { 71 | $this->allegato->toXmlBlock($writer); 72 | } 73 | $writer->endElement(); 74 | return $writer; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiBeniServizi/ScontoMaggiorazione.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiBeniServizi; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class ScontoMaggiorazione implements XmlSerializableInterface 18 | { 19 | use MagicFieldsTrait; 20 | 21 | const SCONTO = 'SC'; 22 | const MAGGIORAZIONE = 'MG'; 23 | 24 | /** @var ScontoMaggiorazione */ 25 | protected $scontoMaggiorazione; 26 | /** @var string */ 27 | public $tipo; 28 | /** @var float */ 29 | public $percentuale; 30 | /** @var float */ 31 | public $importo; 32 | 33 | /** 34 | * ScontoMaggiorazione constructor. 35 | * @param $tipo 36 | * @param $percentuale 37 | * @param $importo 38 | */ 39 | public function __construct($tipo, $percentuale, $importo) 40 | { 41 | $this->tipo = $tipo; 42 | $this->percentuale = $percentuale; 43 | $this->importo = $importo; 44 | } 45 | 46 | /** 47 | * @param \XMLWriter $writer 48 | * @return \XMLWriter 49 | */ 50 | public function toXmlBlock(\XMLWriter $writer) 51 | { 52 | $writer->startElement('ScontoMaggiorazione'); 53 | $writer->writeElement('Tipo', $this->tipo); 54 | if ($this->percentuale) { 55 | $writer->writeElement('Percentuale', fe_number_format($this->percentuale, 2)); 56 | } 57 | if ($this->importo) { 58 | $writer->writeElement('Importo', fe_number_format($this->importo, 2)); 59 | } 60 | $this->writeXmlFields($writer); 61 | $writer->endElement(); 62 | return $writer; 63 | } 64 | 65 | /** 66 | * @param float $totale 67 | * @return float 68 | */ 69 | public function applicaScontoMaggiorazione($totale, $quantita, $decimaliLinea) 70 | { 71 | if ($this->importo && $decimaliLinea) { 72 | $importo = fe_number_format($this->importo, $decimaliLinea); 73 | } else { 74 | $importo = $this->importo; 75 | } 76 | if ($this->tipo === ScontoMaggiorazione::SCONTO) { 77 | $totale -= $this->importo ? ($importo * $quantita) : ($totale * $this->percentuale); 78 | } 79 | else if ($this->tipo === ScontoMaggiorazione::MAGGIORAZIONE) { 80 | $totale += $this->importo ? ($importo * $quantita) : ($totale * $this->percentuale); 81 | } 82 | return $totale; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/FatturaInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica; 13 | 14 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiBeniServizi; 15 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali; 16 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiPagamento; 17 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\Common\DatiAnagrafici; 18 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\Common\Sede; 19 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\DatiTrasmissione; 20 | 21 | interface FatturaInterface 22 | { 23 | 24 | /** 25 | * Ritorna anagrafica cedente 26 | * @return DatiAnagrafici 27 | */ 28 | public function getAnagraficaCedente(); 29 | 30 | /** 31 | * Ritorna telefono cedente per contatto 32 | * @return string 33 | */ 34 | public function getTelefonoCedente(); 35 | 36 | /** 37 | * Ritorna email cedente per contatto 38 | */ 39 | public function getEmailCedente(); 40 | 41 | /** 42 | * Ritorna sede cedente 43 | * @return Sede 44 | */ 45 | public function getSedeCedente(); 46 | 47 | /** 48 | * Ritorna anagrafica cessionario 49 | * @return DatiAnagrafici 50 | */ 51 | public function getAnagraficaCessionario(); 52 | 53 | /** 54 | * Ritorna array sede cessionario 55 | * @return Sede 56 | */ 57 | public function getSedeCessionario(); 58 | 59 | /** 60 | * Ritorna i dati trasmissione 61 | * @return DatiTrasmissione 62 | */ 63 | public function getDatiTrasmissione(); 64 | 65 | /** 66 | * Riotrna array dati generali 67 | * @return DatiGenerali 68 | */ 69 | public function getDatiGenerali(); 70 | 71 | /** 72 | * Ritorna array dati pagamento 73 | * @return DatiPagamento 74 | */ 75 | public function getDatiPagamento(); 76 | 77 | /** 78 | * Ritorna dati beni servizi 79 | * @return DatiBeniServizi 80 | */ 81 | public function getDatiBeniServizi(); 82 | 83 | /** 84 | * Ritorna il tipo documento 85 | * @return string 86 | */ 87 | public function getTipoDocumento(); 88 | 89 | /** 90 | * Ritorna la modalità pagamento 91 | * @return string 92 | */ 93 | public function getModalitaPagamento(); 94 | 95 | /** 96 | * Ritorna importo del pagamento 97 | * @return float 98 | */ 99 | public function getImportoPagamento(); 100 | } 101 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaHeader/CedentePrestatore.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader; 13 | 14 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\CedentePrestatore\IscrizioneRea; 15 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\Common\DatiAnagrafici; 16 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\Common\Sede; 17 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 18 | use Deved\FatturaElettronica\XmlSerializableInterface; 19 | 20 | class CedentePrestatore implements XmlSerializableInterface 21 | { 22 | use MagicFieldsTrait; 23 | /** @var DatiAnagrafici */ 24 | protected $datiAnagrafici; 25 | /** @var Sede */ 26 | protected $sede; 27 | /** @var IscrizioneRea */ 28 | protected $iscrizioneRea; 29 | protected $riferimentoAmministrazione; 30 | 31 | 32 | /** 33 | * CedentePrestatore constructor. 34 | * @param DatiAnagrafici $datiAnagrafici 35 | * @param Sede $sede 36 | * @param IscrizioneRea $iscrizioneRea 37 | */ 38 | public function __construct( 39 | DatiAnagrafici $datiAnagrafici, 40 | Sede $sede, 41 | IscrizioneRea $iscrizioneRea = null 42 | ) { 43 | $this->datiAnagrafici = $datiAnagrafici; 44 | $this->sede = $sede; 45 | $this->iscrizioneRea = $iscrizioneRea; 46 | } 47 | 48 | /** 49 | * @param IscrizioneRea $iscrizioneRea 50 | */ 51 | public function setIscrizioneRea(IscrizioneRea $iscrizioneRea) 52 | { 53 | $this->iscrizioneRea = $iscrizioneRea; 54 | } 55 | 56 | /** 57 | * @param string $riferimentoAmministrazione 58 | */ 59 | public function setRiferimentoAmministrazione($riferimentoAmministrazione) 60 | { 61 | $this->riferimentoAmministrazione = $riferimentoAmministrazione; 62 | } 63 | 64 | /** 65 | * @param \XMLWriter $writer 66 | * @return \XMLWriter 67 | */ 68 | public function toXmlBlock(\XMLWriter $writer) 69 | { 70 | $writer->startElement('CedentePrestatore'); 71 | $this->datiAnagrafici->toXmlBlock($writer); 72 | $this->sede->toXmlBlock($writer); 73 | if ($this->iscrizioneRea) { 74 | $this->iscrizioneRea->toXmlBlock($writer); 75 | } 76 | if ($this->riferimentoAmministrazione) { 77 | $writer->writeElement('RiferimentoAmministrazione', $this->riferimentoAmministrazione); 78 | } 79 | $this->writeXmlFields($writer); 80 | $writer->endElement(); 81 | return $writer; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/XmlValidator.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica; 13 | 14 | class XmlValidator 15 | { 16 | 17 | /** 18 | * @var array 19 | */ 20 | public $errors; 21 | 22 | /** 23 | * @return mixed 24 | */ 25 | public function getErrors() 26 | { 27 | return $this->errors; 28 | } 29 | 30 | /** 31 | * @param $xml 32 | * @param $schema 33 | * @return bool 34 | */ 35 | public function validate($xml, $schema) 36 | { 37 | if ('' === trim($xml)) { 38 | throw new \InvalidArgumentException(sprintf('File %s does not contain valid XML, it is empty.', $xml)); 39 | } 40 | 41 | $internalErrors = libxml_use_internal_errors(true); 42 | libxml_clear_errors(); 43 | 44 | $dom = new \DOMDocument(); 45 | $dom->validateOnParse = true; 46 | if (!$dom->loadXML($xml, LIBXML_NONET | (defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) { 47 | $this->errors = $this->getXmlErrors($internalErrors); 48 | return false; 49 | } 50 | 51 | $dom->normalizeDocument(); 52 | 53 | libxml_use_internal_errors($internalErrors); 54 | 55 | foreach ($dom->childNodes as $child) { 56 | if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) { 57 | throw new \InvalidArgumentException('Document types are not allowed.'); 58 | } 59 | } 60 | 61 | if (null !== $schema) { 62 | $internalErrors = libxml_use_internal_errors(true); 63 | libxml_clear_errors(); 64 | 65 | $e = null; 66 | if (!is_array($schema) && is_file((string) $schema)) { 67 | $valid = @$dom->schemaValidate($schema); 68 | } else { 69 | libxml_use_internal_errors($internalErrors); 70 | 71 | throw new \InvalidArgumentException('The schema argument has to be a valid path to XSD file or callable.'); 72 | } 73 | 74 | if (!$valid) { 75 | $this->errors = $this->getXmlErrors($internalErrors); 76 | return false; 77 | } 78 | } 79 | 80 | libxml_clear_errors(); 81 | libxml_use_internal_errors($internalErrors); 82 | 83 | return true; 84 | } 85 | 86 | private function getXmlErrors($internalErrors) 87 | { 88 | $errors = array(); 89 | foreach (libxml_get_errors() as $error) { 90 | $errors[] = $error; 91 | } 92 | 93 | libxml_clear_errors(); 94 | libxml_use_internal_errors($internalErrors); 95 | 96 | return $errors; 97 | } 98 | 99 | public function isValid(){ 100 | return !$this->getErrors(); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/Codifiche/TipoCassa.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\Codifiche; 13 | 14 | 15 | use Deved\FatturaElettronica\Traits\CodificaTrait; 16 | 17 | abstract class TipoCassa 18 | { 19 | use CodificaTrait; 20 | 21 | const Avvocati = 'TC01'; 22 | const DottoriCommercialisti = 'TC02'; 23 | const Geometri = 'TC03'; 24 | const Architetti = 'TC04'; 25 | const Notai = 'TC05'; 26 | const Ragionieri = 'TC06'; 27 | const ENASARCO = 'TC07'; 28 | const ENPACL = 'TC08'; 29 | const ENPAM = 'TC09'; 30 | const ENPAF = 'TC10'; 31 | const ENPAV = 'TC11'; 32 | const ENPAIA = 'TC12'; 33 | const ImpreseSpedizione = 'TC13'; 34 | const AgenzieMarittime = 'TC13'; 35 | const INPGI = 'TC14'; 36 | const ONAOSI = 'TC15'; 37 | const CASAGIT = 'TC16'; 38 | const EPPI = 'TC17'; 39 | const EPAP = 'TC18'; 40 | const ENPAB = 'TC19'; 41 | const ENPAPI = 'TC20'; 42 | const ENPAP = 'TC21'; 43 | const INPS = 'TC22'; 44 | 45 | 46 | protected static $tipoCassa = array( 47 | 'TC01' => 'Cassa nazionale previdenza e assistenza avvocati e procuratori legali', 48 | 'TC02' => 'Cassa previdenza dottori commercialisti', 49 | 'TC03' => 'Cassa previdenza e assistenza geometri', 50 | 'TC04' => 'Cassa nazionale previdenza e assistenza ingegneri e architetti liberi professionisti', 51 | 'TC05' => 'Cassa nazionale del notariato', 52 | 'TC06' => 'Cassa nazionale previdenza e assistenza ragionieri e periti commerciali', 53 | 'TC07' => 'Ente nazionale assistenza agenti e rappresentanti di commercio (ENASARCO)', 54 | 'TC08' => 'Ente nazionale previdenza e assistenza consulenti del lavoro (ENPACL)', 55 | 'TC09' => 'Ente nazionale previdenza e assistenza medici (ENPAM)', 56 | 'TC10' => 'Ente nazionale previdenza e assistenza farmacisti (ENPAF)', 57 | 'TC11' => 'Ente nazionale previdenza e assistenza veterinari (ENPAV)', 58 | 'TC12' => 'Ente nazionale previdenza e assistenza impiegati dell\'agricoltura (ENPAIA)', 59 | 'TC13' => 'Fondo previdenza impiegati imprese di spedizione e agenzie marittime', 60 | 'TC14' => 'Istituto nazionale previdenza giornalisti italiani (INPGI)', 61 | 'TC15' => 'Opera nazionale assistenza orfani sanitari italiani (ONAOSI)', 62 | 'TC16' => 'Cassa autonoma assistenza integrativa giornalisti italiani (CASAGIT)', 63 | 'TC17' => 'Ente previdenza periti industriali e periti industriali laureati (EPPI)', 64 | 'TC18' => 'Ente previdenza e assistenza pluricategoriale (EPAP)', 65 | 'TC19' => 'Ente nazionale previdenza e assistenza biologi (ENPAB)', 66 | 'TC20' => 'Ente nazionale previdenza e assistenza professione infermieristica (ENPAPI)', 67 | 'TC21' => 'Ente nazionale previdenza e assistenza psicologi (ENPAP)', 68 | 'TC22' => 'INPS' 69 | ); 70 | } 71 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaHeader.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica; 13 | 14 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\CedentePrestatore; 15 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\CessionarioCommittente; 16 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\Common\DatiAnagrafici; 17 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\DatiTrasmissione; 18 | use Deved\FatturaElettronica\XmlSerializableInterface; 19 | use phpDocumentor\Reflection\Types\Nullable; 20 | 21 | class FatturaElettronicaHeader implements XmlSerializableInterface 22 | { 23 | const FE_CODE = 1.0; 24 | /** @var DatiTrasmissione */ 25 | public $datiTrasmissione; 26 | /** @var CedentePrestatore */ 27 | public $cedentePrestatore; 28 | /** @var CessionarioCommittente */ 29 | protected $cessionarioCommittente; 30 | /** @var DatiAnagrafici|null */ 31 | protected $terzoIntermediario; 32 | /** @var string */ 33 | protected $soggettoEmittente; 34 | 35 | /** 36 | * FatturaElettronicaHeader constructor. 37 | * @param DatiTrasmissione $datiTrasmissione 38 | * @param CedentePrestatore $cedentePrestatore 39 | * @param CessionarioCommittente $cessionarioCommittente 40 | * @param DatiAnagrafici|null $terzoIntermediario 41 | * @param string $soggettoEmittente 42 | */ 43 | public function __construct( 44 | DatiTrasmissione $datiTrasmissione, 45 | CedentePrestatore $cedentePrestatore, 46 | CessionarioCommittente $cessionarioCommittente, 47 | DatiAnagrafici $terzoIntermediario = null, 48 | $soggettoEmittente = 'TZ' 49 | ) { 50 | $this->datiTrasmissione = $datiTrasmissione; 51 | $this->cedentePrestatore = $cedentePrestatore; 52 | $this->cessionarioCommittente = $cessionarioCommittente; 53 | $this->terzoIntermediario = $terzoIntermediario; 54 | $this->soggettoEmittente = $soggettoEmittente; 55 | } 56 | 57 | /** 58 | * @param \XMLWriter $writer 59 | * @return \XMLWriter 60 | */ 61 | public function toXmlBlock(\XMLWriter $writer) 62 | { 63 | $writer->startElement('FatturaElettronicaHeader'); 64 | $this->datiTrasmissione->toXmlBlock($writer); 65 | $this->cedentePrestatore->toXmlBlock($writer); 66 | $this->cessionarioCommittente->toXmlBlock($writer); 67 | if ($this->terzoIntermediario) { 68 | $writer->startElement('TerzoIntermediarioOSoggettoEmittente'); 69 | $this->terzoIntermediario->toXmlBlock($writer); 70 | $writer->endElement(); 71 | $writer->writeElement('SoggettoEmittente', $this->soggettoEmittente); 72 | } 73 | $writer->endElement(); 74 | return $writer; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiPagamento.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlRepeatedBlock; 16 | 17 | class DatiPagamento extends XmlRepeatedBlock 18 | { 19 | public $modalitaPagamento; 20 | public $dataRiferimentoTerminiPagamento; 21 | public $dataScadenzaPagamento; 22 | public $importoPagamento; 23 | public $iban; 24 | public $istitutoFinanziario; 25 | public $condizioniPagamento; 26 | 27 | /** 28 | * DatiPagamento constructor. 29 | * @param string $modalitaPagamento 30 | * @param string $dataScadenzaPagamento 31 | * @param float $importoPagamento 32 | * @param string | null $iban 33 | * @param string | null $istitutoFinanziario 34 | * @param string $condizioniPagamento 35 | * @param string | null $dataRiferimentoTerminiPagamento 36 | */ 37 | public function __construct( 38 | $modalitaPagamento, 39 | $dataScadenzaPagamento, 40 | $importoPagamento, 41 | $iban = null, 42 | $istitutoFinanziario = null, 43 | $condizioniPagamento = 'TP02', 44 | $dataRiferimentoTerminiPagamento = null 45 | ) { 46 | $this->modalitaPagamento = $modalitaPagamento; 47 | $this->dataRiferimentoTerminiPagamento = $dataRiferimentoTerminiPagamento; 48 | $this->dataScadenzaPagamento = $dataScadenzaPagamento; 49 | $this->importoPagamento = $importoPagamento; 50 | $this->iban = $iban; 51 | $this->istitutoFinanziario = $istitutoFinanziario; 52 | $this->condizioniPagamento = $condizioniPagamento; 53 | parent::__construct(); 54 | } 55 | 56 | /** 57 | * @param \XMLWriter $writer 58 | * @return \XMLWriter 59 | */ 60 | public function toXmlBlock(\XMLWriter $writer) 61 | { 62 | /** @var DatiPagamento $block */ 63 | foreach ($this->blocks as $block) { 64 | $writer->startElement('DatiPagamento'); 65 | $writer->writeElement('CondizioniPagamento', $block->condizioniPagamento); 66 | $writer->startElement('DettaglioPagamento'); 67 | $writer->writeElement('ModalitaPagamento', $block->modalitaPagamento); 68 | if ($block->dataRiferimentoTerminiPagamento) { 69 | $writer->writeElement('DataRiferimentoTerminiPagamento', $block->dataRiferimentoTerminiPagamento); 70 | } 71 | if ($block->dataScadenzaPagamento) { 72 | $writer->writeElement('DataScadenzaPagamento', $block->dataScadenzaPagamento); 73 | } 74 | $writer->writeElement('ImportoPagamento', fe_number_format($block->importoPagamento, 2)); 75 | if ($block->istitutoFinanziario) { 76 | $writer->writeElement('IstitutoFinanziario', $block->istitutoFinanziario); 77 | } 78 | if ($block->iban) { 79 | $writer->writeElement('IBAN', $block->iban); 80 | } 81 | $block->writeXmlFields($writer); 82 | $writer->endElement(); 83 | $writer->endElement(); 84 | } 85 | return $writer; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaHeader/Common/DatiAnagrafici.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\Common; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class DatiAnagrafici implements XmlSerializableInterface 18 | { 19 | use MagicFieldsTrait; 20 | /** @var string */ 21 | public $codiceFiscale; 22 | /** @var string */ 23 | public $denominazione; 24 | /** @var string */ 25 | public $idPaese; 26 | /** @var string */ 27 | public $idCodice; 28 | /** @var string */ 29 | public $regimeFiscale; 30 | /** @var string */ 31 | public $titolo; 32 | /** @var string */ 33 | public $codEORI; 34 | 35 | /** 36 | * DatiAnagrafici constructor. 37 | * @param string $codiceFiscale 38 | * @param string $denominazione 39 | * @param string $idPaese 40 | * @param string $idCodice 41 | * @param string $regimeFiscale 42 | * @param string $titolo 43 | * @param string $codEORI 44 | */ 45 | public function __construct( 46 | $codiceFiscale, 47 | $denominazione = '', 48 | $idPaese = '', 49 | $idCodice = '', 50 | $regimeFiscale = '', 51 | $titolo = '', 52 | $codEORI = '' 53 | ) { 54 | $this->codiceFiscale = $codiceFiscale; 55 | $this->denominazione = $denominazione; 56 | $this->idPaese = $idPaese; 57 | $this->idCodice = $idCodice; 58 | $this->regimeFiscale = $regimeFiscale; 59 | $this->titolo = $titolo; 60 | $this->codEORI = $codEORI; 61 | } 62 | 63 | /** 64 | * @param \XMLWriter $writer 65 | * @return \XMLWriter 66 | */ 67 | public function toXmlBlock(\XMLWriter $writer) 68 | { 69 | $writer->startElement('DatiAnagrafici'); 70 | if ($this->idCodice && $this->idPaese) { 71 | $writer->startElement('IdFiscaleIVA'); 72 | $writer->writeElement('IdPaese', $this->idPaese); 73 | $writer->writeElement('IdCodice', $this->idCodice); 74 | $writer->endElement(); 75 | } 76 | if ($this->codiceFiscale) { 77 | $writer->writeElement('CodiceFiscale', $this->codiceFiscale); 78 | } 79 | $writer->startElement('Anagrafica'); 80 | if ($this->denominazione) { 81 | $writer->writeElement('Denominazione', $this->denominazione); 82 | } 83 | $this->writeXmlField('Nome', $writer); 84 | $this->writeXmlField('Cognome', $writer); 85 | if ($this->titolo) { 86 | $writer->writeElement('Titolo', $this->titolo); 87 | } 88 | if ($this->codEORI) { 89 | $writer->writeElement('CodEORI', $this->codEORI); 90 | } 91 | $writer->endElement(); 92 | if ($this->regimeFiscale) { 93 | $writer->writeElement('RegimeFiscale', $this->regimeFiscale); 94 | } 95 | $this->writeXmlFields($writer); 96 | $writer->endElement(); 97 | return $writer; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at info@deved.it. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiGenerali/DatiCassaPrevidenziale.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class DatiCassaPrevidenziale implements XmlSerializableInterface 18 | { 19 | use MagicFieldsTrait; 20 | 21 | /* 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | */ 36 | /** @var string */ 37 | protected $tipo; 38 | /** @var float */ 39 | protected $alCassa; 40 | /** @var float */ 41 | protected $importoContributo; 42 | /** @var float */ 43 | protected $imponibile; 44 | /** @var float */ 45 | protected $aliquotaIVA; 46 | /** @var ritenuta */ 47 | protected $ritenuta; 48 | /** @var natura */ 49 | protected $natura; 50 | /** @var string */ 51 | protected $riferimentoAmministrazione; 52 | /* 53 | */ 54 | /** 55 | * DatiCassaPrevidenziale constructor. 56 | * 57 | */ 58 | public function __construct($tipo, $alCassa, $importo, $imponibile, $aliquotaIVA, $ritenuta, $natura, $riferimento) 59 | { 60 | $this->tipo = $tipo; 61 | $this->alCassa = $alCassa; 62 | $this->importoContributo = $importo; 63 | $this->imponibile = $imponibile; 64 | $this->aliquotaIVA = $aliquotaIVA; 65 | $this->ritenuta = $ritenuta; 66 | $this->natura = $natura; 67 | $this->riferimentoAmministrazione = $riferimento; 68 | } 69 | 70 | 71 | /** 72 | * @param \XMLWriter $writer 73 | * @return \XMLWriter 74 | */ 75 | public function toXmlBlock(\XMLWriter $writer) 76 | { 77 | $writer->startElement('DatiCassaPrevidenziale'); 78 | $writer->writeElement('TipoCassa', $this->tipo); 79 | $writer->writeElement('AlCassa', fe_number_format($this->alCassa,2)); 80 | $writer->writeElement('ImportoContributoCassa', fe_number_format($this->importoContributo,2)); 81 | $writer->writeElement('ImponibileCassa', fe_number_format($this->imponibile,2)); 82 | $writer->writeElement('AliquotaIVA', fe_number_format($this->aliquotaIVA,2)); 83 | if ($this->ritenuta) { 84 | $this->ritenuta->toXmlBlock($writer); 85 | } 86 | if ($this->natura) { 87 | $writer->writeElement('Natura', $this->natura); 88 | } 89 | if ($this->riferimentoAmministrazione) { 90 | $writer->writeElement('RiferimentoAmministrazione', $this->riferimentoAmministrazione); 91 | } 92 | $writer->endElement(); 93 | return $writer; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaHeader/DatiTrasmissione.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader; 13 | 14 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\DatiTrasmissione\IdTrasmittente; 15 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 16 | use Deved\FatturaElettronica\XmlSerializableInterface; 17 | 18 | class DatiTrasmissione implements XmlSerializableInterface 19 | { 20 | use MagicFieldsTrait; 21 | 22 | const FORMATO_PA = 'FPA12'; 23 | const FORMATO_PRIVATO = 'FPR12'; 24 | 25 | /** @var IdTrasmittente */ 26 | public $idTrasmittente; 27 | /** @var string */ 28 | public $progressivoInvio; 29 | /** @var string */ 30 | public $formatoTrasmissione; 31 | /** @var string */ 32 | protected $codiceDestinatario; 33 | /** @var array */ 34 | protected $contattiTrasmittente = []; 35 | /** @var bool | string */ 36 | protected $pecDestinatario; 37 | 38 | 39 | /** 40 | * DatiTrasmissione constructor. 41 | * @param IdTrasmittente $idTrasmittente 42 | * @param $progressivoInvio 43 | * @param string $codiceDestinatario 44 | * @param bool $pa 45 | * @param string $telefono 46 | * @param string $email 47 | * @param string $pecDestinatario 48 | */ 49 | public function __construct( 50 | IdTrasmittente $idTrasmittente, 51 | $progressivoInvio, 52 | $codiceDestinatario = "0000000", 53 | $pa = false, 54 | $telefono = '', 55 | $email = '', 56 | $pecDestinatario = '' 57 | ) { 58 | $this->idTrasmittente = $idTrasmittente; 59 | $this->progressivoInvio = $progressivoInvio; 60 | $this->codiceDestinatario = $codiceDestinatario; 61 | $this->formatoTrasmissione = $pa ? self::FORMATO_PA : self::FORMATO_PRIVATO; 62 | if ($telefono) { 63 | $this->contattiTrasmittente['telefono'] = $telefono; 64 | } 65 | if ($email) { 66 | $this->contattiTrasmittente['email'] = $email; 67 | } 68 | $this->pecDestinatario = $pecDestinatario; 69 | } 70 | 71 | /** 72 | * @param \XMLWriter $writer 73 | * @return \XMLWriter 74 | */ 75 | public function toXmlBlock(\XMLWriter $writer) 76 | { 77 | $writer->startElement('DatiTrasmissione'); 78 | $this->idTrasmittente->toXmlBlock($writer); 79 | $writer->writeElement('ProgressivoInvio', $this->progressivoInvio); 80 | $writer->writeElement('FormatoTrasmissione', $this->formatoTrasmissione); 81 | $writer->writeElement('CodiceDestinatario', $this->codiceDestinatario); 82 | if (count($this->contattiTrasmittente)) { 83 | $writer->startElement('ContattiTrasmittente'); 84 | if (array_key_exists('telefono', $this->contattiTrasmittente)) { 85 | $writer->writeElement('Telefono', $this->contattiTrasmittente['telefono']); 86 | } 87 | if (array_key_exists('email', $this->contattiTrasmittente)) { 88 | $writer->writeElement('Email', $this->contattiTrasmittente['email']); 89 | } 90 | $writer->endElement(); 91 | } 92 | if ($this->pecDestinatario) { 93 | $writer->writeElement('PECDestinatario', $this->pecDestinatario); 94 | } 95 | $this->writeXmlFields($writer); 96 | $writer->endElement(); 97 | return $writer; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiGenerali/DatiSal.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class DatiSal implements XmlSerializableInterface, \Countable, \Iterator 18 | { 19 | use MagicFieldsTrait; 20 | 21 | /** @var DatiSal[] */ 22 | protected $datiSal = []; 23 | /** @var int[] */ 24 | protected $riferimentoFase = []; 25 | /** @var int */ 26 | protected $currentIndex = 0; 27 | 28 | /** 29 | * DatiSal constructor. 30 | * @param int $riferimentoFase 31 | */ 32 | public function __construct($riferimentoFase) 33 | { 34 | $this->riferimentoFase = $riferimentoFase; 35 | $this->datiSal[] = $this; 36 | } 37 | 38 | public function addatiSal(DatiSal $datiSal) 39 | { 40 | $this->datiSal[] = $datiSal; 41 | } 42 | 43 | /** 44 | * @param \XMLWriter $writer 45 | * @return \XMLWriter 46 | */ 47 | public function toXmlBlock(\XMLWriter $writer) 48 | { 49 | /** @var DatiSAL $block */ 50 | foreach ($this as $block) { 51 | $writer->startElement('DatiSAL'); 52 | $writer->writeElement('RiferimentoFase', $block->riferimentoFase); 53 | $writer->endElement(); 54 | } 55 | return $writer; 56 | } 57 | 58 | /** 59 | * Return the current element 60 | * @link https://php.net/manual/en/iterator.current.php 61 | * @return mixed Can return any type. 62 | * @since 5.0.0 63 | */ 64 | public function current(): mixed 65 | { 66 | return $this->datiSal[$this->currentIndex]; 67 | } 68 | 69 | /** 70 | * Move forward to next element 71 | * @link https://php.net/manual/en/iterator.next.php 72 | * @return void Any returned value is ignored. 73 | * @since 5.0.0 74 | */ 75 | public function next(): void 76 | { 77 | $this->currentIndex++; 78 | } 79 | 80 | /** 81 | * Return the key of the current element 82 | * @link https://php.net/manual/en/iterator.key.php 83 | * @return mixed scalar on success, or null on failure. 84 | * @since 5.0.0 85 | */ 86 | public function key(): mixed 87 | { 88 | return $this->currentIndex; 89 | } 90 | 91 | /** 92 | * Checks if current position is valid 93 | * @link https://php.net/manual/en/iterator.valid.php 94 | * @return boolean The return value will be casted to boolean and then evaluated. 95 | * Returns true on success or false on failure. 96 | * @since 5.0.0 97 | */ 98 | public function valid(): bool 99 | { 100 | return isset($this->datiSal[$this->currentIndex]); 101 | } 102 | 103 | /** 104 | * Rewind the Iterator to the first element 105 | * @link https://php.net/manual/en/iterator.rewind.php 106 | * @return void Any returned value is ignored. 107 | * @since 5.0.0 108 | */ 109 | public function rewind(): void 110 | { 111 | $this->currentIndex = 0; 112 | } 113 | 114 | /** 115 | * Count elements of an object 116 | * @link https://php.net/manual/en/countable.count.php 117 | * @return int The custom count as an integer. 118 | *

119 | *

120 | * The return value is cast to an integer. 121 | * @since 5.1.0 122 | */ 123 | public function count(): int 124 | { 125 | return count($this->datiSal); 126 | } 127 | } -------------------------------------------------------------------------------- /src/Codifiche/Natura.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\Codifiche; 13 | 14 | 15 | use Deved\FatturaElettronica\Traits\CodificaTrait; 16 | 17 | abstract class Natura 18 | { 19 | use CodificaTrait; 20 | 21 | const EscluseArt15 = 'N1'; 22 | 23 | /** Codice non più valido per le fatture emesse a partire dal primo gennaio 2021 */ 24 | const NonSoggette = 'N2'; 25 | const NonSoggetteArt7 = 'N2.1'; 26 | const NonSoggetteAltro = 'N2.2'; 27 | 28 | /** Codice non più valido per le fatture emesse a partire dal primo gennaio 2021 */ 29 | const NonImponibili = 'N3'; 30 | const NonImponibiliEsportazioni = 'N3.1'; 31 | const NonImponibiliCessioniIntracomunitarie = 'N3.2'; 32 | const NonImponibiliCessioniSanMarino = 'N3.3'; 33 | const NonImponibiliOperazioniAssimilate = 'N3.4'; 34 | const NonImponibiliDichiarazioniIntento = 'N3.5'; 35 | const NonImponibiliAltreOperazioni = 'N3.6'; 36 | 37 | const Esenti = 'N4'; 38 | 39 | const RegimeDelMargine = 'N5'; 40 | 41 | /** Codice non più valido per le fatture emesse a partire dal primo gennaio 2021 */ 42 | const InversioneContabile = 'N6'; 43 | const InversioneContabileCessioneRottami = 'N6.1'; 44 | const InversioneContabileCessioneOroArgento = 'N6.2'; 45 | const InversioneContabileSubappaltoEdile = 'N6.3'; 46 | const InversioneContabileCessioneFabbricati = 'N6.4'; 47 | const InversioneContabileCessioneTelefoniCellulari = 'N6.5'; 48 | const InversioneContabileCessioneProdottiElettronici = 'N6.6'; 49 | const InversioneContabilePrestazioniCompartoEdile = 'N6.7'; 50 | const InversioneContabileOperazioniSettoreEnergetico = 'N6.8'; 51 | const InversioneContabileAltriCasi = 'N6.9'; 52 | 53 | const IvaAssoltaUe = 'N7'; 54 | 55 | protected static $codifiche = array( 56 | 'N1' => 'escluse ex art. 15', 57 | 'N2' => 'non soggette', 58 | 'N2.1' => 'non soggette ad IVA ai sensi degli artt. da 7 a 7-septies del DPR 633/72', 59 | 'N2.2' => 'non soggette - altri casi', 60 | 'N3' => 'non imponibili', 61 | 'N3.1' => 'non imponibili - esportazioni', 62 | 'N3.2' => 'non imponibili - cessioni intracomunitarie', 63 | 'N3.3' => 'non imponibili - cessioni verso San Marino', 64 | 'N3.4' => 'non imponibili - operazioni assimilate alle cessioni all\'esportazione', 65 | 'N3.5' => 'non imponibili - a seguito di dichiarazioni d\'intento', 66 | 'N3.6' => 'non imponibili - altre operazioni che non concorrono alla formazione del plafond', 67 | 'N4' => 'esenti', 68 | 'N5' => 'regime del margine / IVA non esposta in fattura', 69 | 'N6' => 'inversione contabile (per le operazioni in reverse charge ovvero nei casi di autofatturazione per acquisti extra UE di servizi ovvero per importazioni di beni nei soli casi previsti)', 70 | 'N6.1' => 'inversione contabile - cessione di rottami e altri materiali di recupero', 71 | 'N6.2' => 'inversione contabile - cessione di oro e argento puro', 72 | 'N6.3' => 'inversione contabile - subappalto nel settore edile', 73 | 'N6.4' => 'inversione contabile - cessione di fabbricati', 74 | 'N6.5' => 'inversione contabile - cessione di telefoni cellulari', 75 | 'N6.6' => 'inversione contabile - cessione di prodotti elettronici', 76 | 'N6.7' => 'inversione contabile - prestazioni comparto edile e settori connessi', 77 | 'N6.8' => 'inversione contabile - operazioni settore energetico', 78 | 'N6.9' => 'inversione contabile - altri casi', 79 | 'N7' => 'IVA assolta in altro stato UE (vendite a distanza ex art. 40 c. 3 e 4 e art. 80 | 41 c. 1 lett. b, DL 331/93; prestazione di servizi di telecomunicazioni, tele-radiodiffusione 81 | ed elettronici ex art. 7-sexies lett. f, g, art. 74-sexies DPR 633/72)' 82 | ); 83 | } 84 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiBeniServizi/DettaglioLinee.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiBeniServizi; 13 | 14 | use Deved\FatturaElettronica\XmlSerializableInterface; 15 | 16 | class DettaglioLinee implements \Countable, \Iterator, XmlSerializableInterface 17 | { 18 | 19 | /** @var Linea[] */ 20 | private $linee = []; 21 | 22 | /** @var int */ 23 | private $currentIndex = 0; 24 | 25 | /** 26 | * DettaglioLinee constructor. 27 | * @param null | Linea[] $linee 28 | */ 29 | public function __construct($linee = null) 30 | { 31 | if ($linee) { 32 | $this->addLinee($linee); 33 | } 34 | } 35 | 36 | /** 37 | * Add single row 38 | * @param Linea $linea 39 | */ 40 | public function addLinea(Linea $linea) 41 | { 42 | $linea->setNumeroLinea($this->count() + 1); 43 | $this->linee[] = $linea; 44 | } 45 | 46 | /** 47 | * Add multiple rows 48 | * @param Linea[] $linee 49 | */ 50 | public function addLinee($linee) 51 | { 52 | /** @var Linea $linea */ 53 | foreach ($linee as $linea) { 54 | if ($linea instanceof Linea) { 55 | $this->addLinea($linea); 56 | } 57 | } 58 | } 59 | 60 | /** 61 | * Return the current element 62 | * @link http://php.net/manual/en/iterator.current.php 63 | * @return mixed Can return any type. 64 | * @since 5.0.0 65 | */ 66 | public function current(): mixed 67 | { 68 | return $this->linee[$this->currentIndex]; 69 | } 70 | 71 | /** 72 | * Move forward to next element 73 | * @link http://php.net/manual/en/iterator.next.php 74 | * @return void Any returned value is ignored. 75 | * @since 5.0.0 76 | */ 77 | public function next(): void 78 | { 79 | $this->currentIndex++; 80 | } 81 | 82 | /** 83 | * Return the key of the current element 84 | * @link http://php.net/manual/en/iterator.key.php 85 | * @return mixed scalar on success, or null on failure. 86 | * @since 5.0.0 87 | */ 88 | public function key(): mixed 89 | { 90 | return $this->currentIndex; 91 | } 92 | 93 | /** 94 | * Checks if current position is valid 95 | * @link http://php.net/manual/en/iterator.valid.php 96 | * @return boolean The return value will be casted to boolean and then evaluated. 97 | * Returns true on success or false on failure. 98 | * @since 5.0.0 99 | */ 100 | public function valid(): bool 101 | { 102 | return isset($this->linee[$this->currentIndex]); 103 | } 104 | 105 | /** 106 | * Rewind the Iterator to the first element 107 | * @link http://php.net/manual/en/iterator.rewind.php 108 | * @return void Any returned value is ignored. 109 | * @since 5.0.0 110 | */ 111 | public function rewind(): void 112 | { 113 | $this->currentIndex = 0; 114 | } 115 | 116 | /** 117 | * Count elements of an object 118 | * @link http://php.net/manual/en/countable.count.php 119 | * @return int The custom count as an integer. 120 | *

121 | *

122 | * The return value is cast to an integer. 123 | * @since 5.1.0 124 | */ 125 | public function count(): int 126 | { 127 | return count($this->linee); 128 | } 129 | 130 | /** 131 | * @param \XMLWriter $writer 132 | * @return \XMLWriter 133 | */ 134 | public function toXmlBlock(\XMLWriter $writer) 135 | { 136 | /** @var Linea $linea */ 137 | foreach ($this as $linea) { 138 | $linea->toXmlBlock($writer); 139 | } 140 | 141 | return $writer; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiGenerali/DatiContratto.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class DatiContratto implements XmlSerializableInterface, \Countable, \Iterator 18 | { 19 | const FE_CODE = '2.1.2'; 20 | use MagicFieldsTrait; 21 | protected $datiContratto = []; 22 | protected $currentIndex = 0; 23 | protected $riferimentoNumeroLinee = []; 24 | protected $idDocumento; 25 | 26 | /** 27 | * DatiContratto constructor. 28 | * @param string $idDocumento 29 | * @param int[] $riferimentoNumeroLinee 30 | */ 31 | public function __construct($idDocumento, $riferimentoNumeroLinee = []) 32 | { 33 | $this->idDocumento = $idDocumento; 34 | $this->riferimentoNumeroLinee = $riferimentoNumeroLinee; 35 | $this->datiContratto[] = $this; 36 | } 37 | 38 | public function addDatiContratto(DatiContratto $datiContratto) 39 | { 40 | $this->datiContratto[] = $datiContratto; 41 | } 42 | 43 | /** 44 | * Return the current element 45 | * @link https://php.net/manual/en/iterator.current.php 46 | * @return mixed Can return any type. 47 | * @since 5.0.0 48 | */ 49 | public function current(): mixed 50 | { 51 | return $this->datiContratto[$this->currentIndex]; 52 | } 53 | 54 | /** 55 | * Move forward to next element 56 | * @link https://php.net/manual/en/iterator.next.php 57 | * @return void Any returned value is ignored. 58 | * @since 5.0.0 59 | */ 60 | public function next(): void 61 | { 62 | $this->currentIndex++; 63 | } 64 | 65 | /** 66 | * Return the key of the current element 67 | * @link https://php.net/manual/en/iterator.key.php 68 | * @return mixed scalar on success, or null on failure. 69 | * @since 5.0.0 70 | */ 71 | public function key(): mixed 72 | { 73 | return $this->currentIndex; 74 | } 75 | 76 | /** 77 | * Checks if current position is valid 78 | * @link https://php.net/manual/en/iterator.valid.php 79 | * @return boolean The return value will be casted to boolean and then evaluated. 80 | * Returns true on success or false on failure. 81 | * @since 5.0.0 82 | */ 83 | public function valid(): bool 84 | { 85 | return isset($this->datiContratto[$this->currentIndex]); 86 | } 87 | 88 | /** 89 | * Rewind the Iterator to the first element 90 | * @link https://php.net/manual/en/iterator.rewind.php 91 | * @return void Any returned value is ignored. 92 | * @since 5.0.0 93 | */ 94 | public function rewind(): void 95 | { 96 | $this->currentIndex = 0; 97 | } 98 | 99 | /** 100 | * Count elements of an object 101 | * @link https://php.net/manual/en/countable.count.php 102 | * @return int The custom count as an integer. 103 | *

104 | *

105 | * The return value is cast to an integer. 106 | * @since 5.1.0 107 | */ 108 | public function count(): int 109 | { 110 | return count($this->datiContratto); 111 | } 112 | 113 | /** 114 | * @param \XMLWriter $writer 115 | * @return \XMLWriter 116 | */ 117 | public function toXmlBlock(\XMLWriter $writer) 118 | { 119 | /** @var DatiContratto $block */ 120 | foreach ($this as $block) { 121 | $writer->startElement('DatiContratto'); 122 | if (count($block->riferimentoNumeroLinee) > 0) { 123 | /** @var int $linea */ 124 | foreach ($block->riferimentoNumeroLinee as $linea) { 125 | $writer->writeElement('RiferimentoNumeroLinea', $linea); 126 | } 127 | } 128 | $writer->writeElement('IdDocumento', $block->idDocumento); 129 | $block->writeXmlFields($writer); 130 | $writer->endElement(); 131 | } 132 | return $writer; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiGenerali/DatiDdt.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class DatiDdt implements XmlSerializableInterface, \Countable, \Iterator 18 | { 19 | use MagicFieldsTrait; 20 | 21 | /** @var DatiDdt[] */ 22 | protected $datiDdt = []; 23 | /** @var string */ 24 | protected $numeroDdt; 25 | /** @var string */ 26 | protected $dataDdt; 27 | /** @var int[] */ 28 | protected $riferimentoNumeroLinee = []; 29 | /** @var int */ 30 | protected $currentIndex = 0; 31 | 32 | /** 33 | * DatiDdt constructor. 34 | * @param string $numeroDdt 35 | * @param string $dataDdt 36 | * @param array $riferimentoNumeroLinee 37 | */ 38 | public function __construct($numeroDdt, $dataDdt, $riferimentoNumeroLinee = []) 39 | { 40 | $this->numeroDdt = $numeroDdt; 41 | $this->dataDdt = $dataDdt; 42 | $this->riferimentoNumeroLinee = $riferimentoNumeroLinee; 43 | $this->datiDdt[] = $this; 44 | } 45 | 46 | 47 | public function addDatiDdt(DatiDdt $datiDdt) 48 | { 49 | $this->datiDdt[] = $datiDdt; 50 | } 51 | 52 | /** 53 | * @param \XMLWriter $writer 54 | * @return \XMLWriter 55 | */ 56 | public function toXmlBlock(\XMLWriter $writer) 57 | { 58 | /** @var DatiDdt $block */ 59 | foreach ($this as $block) { 60 | $writer->startElement('DatiDDT'); 61 | $writer->writeElement('NumeroDDT', $block->numeroDdt); 62 | $writer->writeElement('DataDDT', $block->dataDdt); 63 | foreach ($block->riferimentoNumeroLinee as $numeroLinea) { 64 | $writer->writeElement('RiferimentoNumeroLinea', $numeroLinea); 65 | } 66 | $writer->endElement(); 67 | } 68 | return $writer; 69 | } 70 | 71 | /** 72 | * Return the current element 73 | * @link https://php.net/manual/en/iterator.current.php 74 | * @return mixed Can return any type. 75 | * @since 5.0.0 76 | */ 77 | public function current(): mixed 78 | { 79 | return $this->datiDdt[$this->currentIndex]; 80 | } 81 | 82 | /** 83 | * Move forward to next element 84 | * @link https://php.net/manual/en/iterator.next.php 85 | * @return void Any returned value is ignored. 86 | * @since 5.0.0 87 | */ 88 | public function next(): void 89 | { 90 | $this->currentIndex++; 91 | } 92 | 93 | /** 94 | * Return the key of the current element 95 | * @link https://php.net/manual/en/iterator.key.php 96 | * @return mixed scalar on success, or null on failure. 97 | * @since 5.0.0 98 | */ 99 | public function key(): mixed 100 | { 101 | return $this->currentIndex; 102 | } 103 | 104 | /** 105 | * Checks if current position is valid 106 | * @link https://php.net/manual/en/iterator.valid.php 107 | * @return boolean The return value will be casted to boolean and then evaluated. 108 | * Returns true on success or false on failure. 109 | * @since 5.0.0 110 | */ 111 | public function valid(): bool 112 | { 113 | return isset($this->datiDdt[$this->currentIndex]); 114 | } 115 | 116 | /** 117 | * Rewind the Iterator to the first element 118 | * @link https://php.net/manual/en/iterator.rewind.php 119 | * @return void Any returned value is ignored. 120 | * @since 5.0.0 121 | */ 122 | public function rewind(): void 123 | { 124 | $this->currentIndex = 0; 125 | } 126 | 127 | /** 128 | * Count elements of an object 129 | * @link https://php.net/manual/en/countable.count.php 130 | * @return int The custom count as an integer. 131 | *

132 | *

133 | * The return value is cast to an integer. 134 | * @since 5.1.0 135 | */ 136 | public function count(): int 137 | { 138 | return count($this->datiDdt); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | 8 | ## [2.0.3] - 2025-11-18 9 | ### Added 10 | - Aggiunti schemi XSD separati per FPA12 (Schema_VFPA12_V1.2.3.xsd) e FPR12 (Schema_VFPR12_v1.2.3.xsd) #124 11 | - Aggiunta selezione automatica dello schema in base al formatoTrasmissione 12 | - Aggiunti test FatturaPA12Test e FatturaPR12Test per validare entrambi i formati 13 | 14 | ## [1.1.28] - 2023-11-09 15 | ### Added 16 | - Bug fix 17 | 18 | ## [1.1.27] - 2023-02-21 19 | ### Added 20 | - Aggiunta la possibilità di specificare AltriDatiGestionali nei nodi DettaglioLinee #108 by danielebuso 21 | 22 | ## [1.1.26] - 2023-02-02 23 | ### Added 24 | - Aggiunto RiferimentoAmministrazione nel nodo CedentePrestatore #107 by danielebuso 25 | 26 | ## [1.1.25] - 2022-08-29 27 | ### Fixed 28 | - Hotfix numero decimali quantità linea #103 by danielebuso 29 | 30 | ## [1.1.24] - 2022-05-23 31 | ### Fixed 32 | - Aggiunta gestione natura iva #102 by @snipershady 33 | 34 | ## [1.1.23] - 2022-04-13 35 | ### Fixed 36 | - Hotfix formato trasmissione FPR12/FPA12 in nodo radice #99 by danielebuso 37 | 38 | ## [1.1.22] - 2022-03-02 39 | ### Fixed 40 | - Fix DatiContratto su DatiDocumentiCorrelati #98 by danielebuso 41 | 42 | ## [1.1.21] - 2021-10-06 43 | ### Fixed 44 | - Fix sconto e maggiorazione su importo #93 by danielebuso 45 | 46 | ## [1.1.20] - 2021-10-05 47 | ### Fixed 48 | - Fix sconto e maggiorazione su importo #92 by danielebuso 49 | 50 | ## [1.1.19] - 2021-09-02 51 | ### Fixed 52 | - Sistemato ordine Causale fattura #91 by danielebuso 53 | 54 | ## [1.1.18] - 2021-08-26 55 | ### Added 56 | - Aggiunto Arrotondamento e TipoCessionePrestazione #90 by danielebuso 57 | 58 | ## [1.1.17] - 2021-08-25 59 | ### Added 60 | - Aggiunta impostazione decimali per linea #89 by danielebuso 61 | 62 | ## [1.1.16] - 2021-05-28 63 | ### Added 64 | - Aggiunti supporto ai tipi DatiDocumentiCorrelati #88 by danielebuso 65 | - Aggiunto supporto ScontoMaggiorazione linee #86 by danielebuso 66 | - Aggiunto Titolo e CodEORI per TerzoIntermediarioOSoggettoEmittente #85 by danielebuso 67 | - Aggiunto codice tipo documento TD24 #83 by danielebuso 68 | 69 | ## [1.1.14] - 2021-01-27 70 | ### Added 71 | - Nuovi codici Natura, pull request #79 by vittominacori 72 | - Nuovo schema XSD, pull request #79 by vittominacori 73 | 74 | ## [1.1.13] 75 | ### Fixed 76 | - Bug fix vari 77 | 78 | ## [1.1.12] - 2019-04-26 79 | ### Added 80 | - Aggiunto tipo codice nella linea, pull request #72 by riktar 81 | - Aggiunto blocco DatiConvenzione, pull request #72 by riktar 82 | 83 | ## [1.1.11] - 2019-04-26 84 | ### Fixed 85 | - Bug fix vari 86 | 87 | ## [1.1.10] - 2019-02-05 88 | ### Added 89 | - Aggiunta possibilità di specificare DatiSAL e DatiVeicoli, pull request #51 by manrix 90 | 91 | ## [1.1.9] 92 | ### Fixed 93 | - DataScadenzaPagamento facoltativa in DatiPagamento 94 | 95 | ## [1.1.8] 96 | ### Added 97 | - possibilità di specificare allegati (grazie manrix) 98 | 99 | ## [1.1.7] 100 | ### Fixed 101 | - bug fix vari 102 | 103 | ## [1.1.6] 104 | ### Added 105 | - in FatturaElettronicaFactory aggiunta possibilità di settare l'IdTrasmittente 106 | 107 | ## [1.1.5] 108 | ### Added 109 | - Possibilità di aggiungere blocchi multipli per il pagamento 110 | 111 | ## [1.1.4] 112 | ### Added 113 | - Possibilità di aggiungere nome e cognome in dati anagrafici in alternativa a denominazione (con proprietà dinamiche) 114 | ### Fixed 115 | - Rimosso BOM (byte order mark) da xsd/fattura_pa_1.2.1.xsd 116 | 117 | ## [1.1.3] 118 | ### Added 119 | - Aggiunto blocco DatiGenerali/DatiContratto 120 | 121 | ### Fixed 122 | - Diversi bug fixes 123 | - Reso opzionale il CodiceFIscale nei DatiAnagrafici 124 | 125 | ## [1.1.2] 126 | ### Added 127 | - Aggiunto metodo per verifica fattura con schema xsd dell'sdi 128 | - Possibilità di aggiungere i campi DataInizioPeriodo e DataFinePeriodo 129 | - Possibilità di aggiungere il blocco DatiGenerali => DatiDDT 130 | - Possibilità di aggiungere IscrizioneRea 131 | 132 | ### Fixed 133 | - Riga fattura senza quantità 134 | - DatiPagamento opzionali 135 | 136 | ## [1.1.0] 137 | ### Added 138 | - Righe fattura con aliquota diversa 139 | - Possibilità di aggiungere la Natura nelle righe con importi non imponibili 140 | - Possibilità di aggiungere la Natura nel blocco DatiRiepilogo 141 | - DatiRiepilogo multipli 142 | - Trait MagicFieldsTrait per aggiunta di campi dinamici in blocco o singolarmente dove la sequenza è determinante 143 | 144 | ## [1.0.7] 145 | ### Fixed 146 | - bug fix 147 | 148 | ## [1.0.6] 149 | ### Added 150 | - Possibilità di aggiungere nell'header i blocchi 'TerzoIntermediarioOSoggettoEmittente' e 'SoggettoEmittente' 151 | - IntermediarioInterface.php - interfaccia da implementare per l'aggiunta del terzo intermediario 152 | 153 | ## [1.0.5] - 2018-12-10 154 | ### Fixed 155 | - fix Codice Fiscale nel campo idTrasmittente->idCodice utilizzando FatturaElettronicaFactory 156 | -------------------------------------------------------------------------------- /src/FatturaElettronica.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica; 13 | 14 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody; 15 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader; 16 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\CedentePrestatore\IscrizioneRea; 17 | 18 | class FatturaElettronica implements XmlSerializableInterface, FatturaElettronicaInterface 19 | { 20 | /** @var FatturaElettronicaHeader */ 21 | protected $fatturaElettronicaHeader; 22 | /** @var FatturaElettronicaBody */ 23 | protected $fatturaElettronicaBody; 24 | /** @var XmlFactory */ 25 | protected $xmlFactory; 26 | /** @var XmlValidator */ 27 | protected $xmlValidator; 28 | 29 | public function __construct( 30 | FatturaElettronicaHeader $fatturaElettronicaHeader, 31 | FatturaElettronicaBody $fatturaElettronicaBody, 32 | XmlFactory $xmlFactory = null 33 | ) { 34 | $this->fatturaElettronicaHeader = $fatturaElettronicaHeader; 35 | $this->fatturaElettronicaBody = $fatturaElettronicaBody; 36 | $this->xmlFactory = $xmlFactory; 37 | } 38 | 39 | /** 40 | * @param \XMLWriter $writer 41 | * @return \XMLWriter 42 | */ 43 | public function toXmlBlock(\XMLWriter $writer) 44 | { 45 | $writer->startElementNS('p', 'FatturaElettronica', null); 46 | $writer->writeAttribute('versione', $this->fatturaElettronicaHeader->datiTrasmissione->formatoTrasmissione); 47 | $writer->writeAttributeNS('xmlns', 'ds', null, 'http://www.w3.org/2000/09/xmldsig#'); 48 | $writer->writeAttributeNS('xmlns', 'p', null, 'http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2'); 49 | $writer->writeAttributeNS('xmlns', 'xsi', null, 'http://www.w3.org/2001/XMLSchema-instance'); 50 | $this->fatturaElettronicaHeader->toXmlBlock($writer); 51 | $this->fatturaElettronicaBody->toXmlBlock($writer); 52 | $writer->endElement(); 53 | return $writer; 54 | } 55 | 56 | /** 57 | * Restituisce il nome della fattura conforme all'SDI 58 | * @return string 59 | */ 60 | public function getFileName() 61 | { 62 | $idPaese = $this->fatturaElettronicaHeader->datiTrasmissione->idTrasmittente->idPaese; 63 | $idCodice = $this->fatturaElettronicaHeader->datiTrasmissione->idTrasmittente->idCodice; 64 | $progressivoInvio = $this->fatturaElettronicaHeader->datiTrasmissione->progressivoInvio; 65 | 66 | return $idPaese . $idCodice . '_' . $progressivoInvio . '.xml'; 67 | } 68 | 69 | /** 70 | * Restituisce l'xml della fattura elettronica 71 | * @return string 72 | * @throws \Exception 73 | */ 74 | public function toXml() 75 | { 76 | if ($this->xmlFactory) { 77 | return $this->xmlFactory->toXml($this); 78 | } 79 | throw new \Exception('xmlFactory non presente, utilizzare FatturaElettronicaFactory per generare le fatture'); 80 | } 81 | 82 | 83 | /** 84 | * Verifica l'xml della fattura 85 | * @return bool 86 | * @throws \Exception 87 | */ 88 | public function verifica() 89 | { 90 | $this->xmlValidator = new XmlValidator(); 91 | 92 | // Determine which schema to use based on formato trasmissione 93 | $formatoTrasmissione = $this->fatturaElettronicaHeader->datiTrasmissione->formatoTrasmissione; 94 | 95 | if ($formatoTrasmissione === 'FPA12') { 96 | $schemaPath = dirname(__FILE__) . '/../xsd/Schema_VFPA12_V1.2.3.xsd'; 97 | } elseif ($formatoTrasmissione === 'FPR12') { 98 | $schemaPath = dirname(__FILE__) . '/../xsd/Schema_VFPR12_v1.2.3.xsd'; 99 | } else { 100 | throw new \Exception("Formato trasmissione non valido: " . $formatoTrasmissione); 101 | } 102 | 103 | $isValid = $this->xmlValidator->validate( 104 | $this->toXml(), 105 | $schemaPath 106 | ); 107 | if (!$isValid) { 108 | throw new \Exception(json_encode($this->xmlValidator->errors)); 109 | } 110 | return $isValid; 111 | } 112 | 113 | /** 114 | * @param IscrizioneRea $iscrizioneRea 115 | * @return mixed 116 | */ 117 | public function setIscrizioneRea(IscrizioneRea $iscrizioneRea) 118 | { 119 | $this->fatturaElettronicaHeader->cedentePrestatore->setIscrizioneRea($iscrizioneRea); 120 | } 121 | 122 | /** 123 | * @param string $riferimentoAmministrazione 124 | */ 125 | public function setRiferimentoAmministrazione($riferimentoAmministrazione) 126 | { 127 | $this->fatturaElettronicaHeader->cedentePrestatore->setRiferimentoAmministrazione($riferimentoAmministrazione); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/FatturaAdapter.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica; 13 | 14 | 15 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody; 16 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader; 17 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\CedentePrestatore\IscrizioneRea; 18 | use Deved\FatturaElettronica\IntermediarioInterface; 19 | 20 | class FatturaAdapter implements FatturaElettronicaInterface 21 | { 22 | /** @var FatturaInterface | IntermediarioInterface */ 23 | protected $fattura; 24 | /** @var FatturaElettronicaHeader\CedentePrestatore */ 25 | protected $cedentePrestatore; 26 | /** @var FatturaElettronicaHeader\CessionarioCommittente */ 27 | protected $cessionarioCommittente; 28 | /** @var FatturaElettronica */ 29 | public $fatturaElettronica; 30 | /** @var XmlFactory */ 31 | protected $xmlFactory; 32 | /** @var FatturaElettronicaHeader */ 33 | protected $fatturaElettronicaHeader; 34 | /** @var FatturaElettronicaBody */ 35 | protected $fatturaElettronicaBody; 36 | 37 | 38 | /** 39 | * FatturaAdapter constructor. 40 | * @param FatturaInterface $fattura 41 | * @param XmlFactory|null $xmlFactory 42 | */ 43 | public function __construct(FatturaInterface $fattura, XmlFactory $xmlFactory = null) 44 | { 45 | if ($xmlFactory) { 46 | $this->xmlFactory = $xmlFactory; 47 | } else { 48 | $this->xmlFactory = new XmlFactory(); 49 | } 50 | $this->fattura = $fattura; 51 | $this->setCedentePrestatore(); 52 | $this->setCessionarioCommittente(); 53 | $this->createFatturaElettronica(); 54 | } 55 | 56 | protected function createFatturaElettronica() 57 | { 58 | $terzoIntermediario = null; 59 | $soggettoEmittente = 'TZ'; 60 | if (array_key_exists(IntermediarioInterface::class, class_implements($this->fattura))) { 61 | $terzoIntermediario = $this->fattura->getAnagraficaIntermediario(); 62 | $soggettoEmittente = $this->fattura->getSoggettoEmittente(); 63 | } 64 | $this->fatturaElettronicaHeader = new FatturaElettronicaHeader( 65 | $this->fattura->getDatiTrasmissione(), 66 | $this->cedentePrestatore, 67 | $this->cessionarioCommittente, 68 | $terzoIntermediario, 69 | $soggettoEmittente 70 | ); 71 | $this->fatturaElettronicaBody = new FatturaElettronicaBody( 72 | $this->fattura->getDatiGenerali(), 73 | $this->fattura->getDatiBeniServizi(), 74 | $this->fattura->getDatiPagamento() 75 | ); 76 | $this->fatturaElettronica = new FatturaElettronica( 77 | $this->fatturaElettronicaHeader, 78 | $this->fatturaElettronicaBody, 79 | $this->xmlFactory 80 | ); 81 | } 82 | 83 | protected function setCedentePrestatore() 84 | { 85 | $this->cedentePrestatore = new FatturaElettronicaHeader\CedentePrestatore( 86 | $this->fattura->getAnagraficaCedente(), 87 | $this->fattura->getSedeCedente() 88 | ); 89 | } 90 | protected function setCessionarioCommittente() 91 | { 92 | $this->cessionarioCommittente = new FatturaElettronicaHeader\CessionarioCommittente( 93 | $this->fattura->getAnagraficaCessionario(), 94 | $this->fattura->getSedeCessionario() 95 | ); 96 | } 97 | 98 | /** 99 | * Restituisce l'XML della fattura elettronica 100 | * @return string 101 | * @throws \Exception 102 | */ 103 | public function toXml() 104 | { 105 | return $this->fatturaElettronica->toXml(); 106 | } 107 | 108 | /** 109 | * Restituisce il nome della fattura conforme all'SDI 110 | * @return string 111 | */ 112 | public function getFileName() 113 | { 114 | return $this->fatturaElettronica->getFileName(); 115 | } 116 | 117 | /** 118 | * @param IscrizioneRea $iscrizioneRea 119 | * @return mixed 120 | */ 121 | public function setIscrizioneRea(IscrizioneRea $iscrizioneRea) 122 | { 123 | $this->fatturaElettronicaHeader->cedentePrestatore->setIscrizioneRea($iscrizioneRea); 124 | } 125 | 126 | /** 127 | * @param string $riferimentoAmministrazione 128 | */ 129 | public function setRiferimentoAmministrazione($riferimentoAmministrazione) 130 | { 131 | $this->fatturaElettronicaHeader->cedentePrestatore->setRiferimentoAmministrazione($riferimentoAmministrazione); 132 | } 133 | 134 | /** 135 | * Verifica l'xml della fattura 136 | * @return bool 137 | * @throws \Exception 138 | */ 139 | public function verifica() 140 | { 141 | return $this->fatturaElettronica->verifica(); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiBeniServizi/DatiRiepilogo.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiBeniServizi; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class DatiRiepilogo implements XmlSerializableInterface, \Countable, \Iterator 18 | { 19 | use MagicFieldsTrait; 20 | /** @var float */ 21 | protected $aliquotaIVA; 22 | /** @var float */ 23 | protected $imponibileImporto; 24 | /** @var float */ 25 | protected $imposta; 26 | /** @var string */ 27 | protected $esigibilitaIVA = "I"; 28 | /** @var DatiRiepilogo[] */ 29 | protected $datiRiepilogoAggiuntivi = []; 30 | /** @var int */ 31 | protected $currentIndex = 0; 32 | /** @var float */ 33 | protected $arrotondamento; 34 | /** @var float */ 35 | protected $decimaliArrotondamento; 36 | 37 | /** 38 | * DatiRiepilogo constructor. 39 | * @param $imponibileImporto 40 | * @param $aliquotaIVA 41 | * @param string $esigibilitaIVA 42 | * @param bool $imposta 43 | */ 44 | public function __construct($imponibileImporto, $aliquotaIVA, $esigibilitaIVA = "I", $imposta = false, $arrotondamento = null, $decimaliArrotondamento = 2) 45 | { 46 | if ($imposta === false) { 47 | $this->imposta = ($imponibileImporto / 100) * $aliquotaIVA; 48 | } else { 49 | $this->imposta = $imposta; 50 | } 51 | $this->imponibileImporto = $imponibileImporto; 52 | $this->aliquotaIVA = $aliquotaIVA; 53 | $this->esigibilitaIVA = $esigibilitaIVA; 54 | $this->datiRiepilogoAggiuntivi[] = $this; 55 | $this->arrotondamento = $arrotondamento; 56 | $this->decimaliArrotondamento = $decimaliArrotondamento; 57 | } 58 | 59 | /** 60 | * @param \XMLWriter $writer 61 | * @return \XMLWriter 62 | */ 63 | public function toXmlBlock(\XMLWriter $writer) 64 | { 65 | /** @var DatiRiepilogo $block */ 66 | foreach ($this as $block) { 67 | $natura = $block->natura; 68 | $writer->startElement('DatiRiepilogo'); 69 | $writer->writeElement('AliquotaIVA', fe_number_format($block->aliquotaIVA, 2)); 70 | $block->writeXmlField('Natura', $writer); 71 | if ($block->arrotondamento) { 72 | $writer->writeElement('Arrotondamento', fe_number_format($block->arrotondamento, $block->decimaliArrotondamento)); 73 | } 74 | $writer->writeElement('ImponibileImporto', fe_number_format($block->imponibileImporto, 2)); 75 | $writer->writeElement('Imposta', fe_number_format($block->imposta, 2)); 76 | if (!$natura) { 77 | $writer->writeElement('EsigibilitaIVA', $block->esigibilitaIVA); 78 | } 79 | $block->writeXmlFields($writer); 80 | $writer->endElement(); 81 | } 82 | return $writer; 83 | } 84 | 85 | public function addDatiRiepilogo(DatiRiepilogo $datiRiepilogo) 86 | { 87 | $this->datiRiepilogoAggiuntivi[] = $datiRiepilogo; 88 | } 89 | 90 | /** 91 | * Return the current element 92 | * @link http://php.net/manual/en/iterator.current.php 93 | * @return mixed Can return any type. 94 | * @since 5.0.0 95 | */ 96 | public function current(): mixed 97 | { 98 | return $this->datiRiepilogoAggiuntivi[$this->currentIndex]; 99 | } 100 | 101 | /** 102 | * Move forward to next element 103 | * @link http://php.net/manual/en/iterator.next.php 104 | * @return void Any returned value is ignored. 105 | * @since 5.0.0 106 | */ 107 | public function next(): void 108 | { 109 | $this->currentIndex++; 110 | } 111 | 112 | /** 113 | * Return the key of the current element 114 | * @link http://php.net/manual/en/iterator.key.php 115 | * @return mixed scalar on success, or null on failure. 116 | * @since 5.0.0 117 | */ 118 | public function key(): mixed 119 | { 120 | return $this->currentIndex; 121 | } 122 | 123 | /** 124 | * Checks if current position is valid 125 | * @link http://php.net/manual/en/iterator.valid.php 126 | * @return boolean The return value will be casted to boolean and then evaluated. 127 | * Returns true on success or false on failure. 128 | * @since 5.0.0 129 | */ 130 | public function valid(): bool 131 | { 132 | return isset($this->datiRiepilogoAggiuntivi[$this->currentIndex]); 133 | } 134 | 135 | /** 136 | * Rewind the Iterator to the first element 137 | * @link http://php.net/manual/en/iterator.rewind.php 138 | * @return void Any returned value is ignored. 139 | * @since 5.0.0 140 | */ 141 | public function rewind(): void 142 | { 143 | $this->currentIndex = 0; 144 | } 145 | 146 | /** 147 | * Count elements of an object 148 | * @link http://php.net/manual/en/countable.count.php 149 | * @return int The custom count as an integer. 150 | *

151 | *

152 | * The return value is cast to an integer. 153 | * @since 5.1.0 154 | */ 155 | public function count(): int 156 | { 157 | return count($this->datiRiepilogoAggiuntivi); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiGenerali/DatiDocumentoCorrelato.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali; 13 | 14 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 15 | use Deved\FatturaElettronica\XmlSerializableInterface; 16 | 17 | class DatiDocumentoCorrelato implements XmlSerializableInterface, \Countable, \Iterator 18 | { 19 | use MagicFieldsTrait; 20 | 21 | const OrdineAcquisto = 'DatiOrdineAcquisto'; 22 | const Contratto = 'DatiDocumentoCorrelato'; 23 | const Convenzione = 'DatiConvenzione'; 24 | const Ricezione = 'DatiRicezione'; 25 | const FattureCollegate = 'DatiFattureCollegate'; 26 | 27 | protected $tipoDocumentoCorrelato; 28 | protected $datiDocumentiCorrelati = []; 29 | protected $codiceCommessaConvenzione = ''; 30 | protected $currentIndex = 0; 31 | protected $riferimentoNumeroLinee = []; 32 | protected $idDocumento; 33 | protected $numItem; 34 | protected $codiceCUP; 35 | protected $codiceCIG; 36 | protected $data; 37 | 38 | /** 39 | * DatiDocumentoCorrelato constructor. 40 | * @param string $idDocumento 41 | * @param int[] $riferimentoNumeroLinee 42 | */ 43 | public function __construct($tipoDocumentoCorrelato, $idDocumento, $data, $riferimentoNumeroLinee = [], $codiceCommessaConvenzione = '', $numItem = '', $codiceCUP = null, $codiceCIG = null) 44 | { 45 | $this->tipoDocumentoCorrelato = $tipoDocumentoCorrelato; 46 | $this->idDocumento = $idDocumento; 47 | $this->riferimentoNumeroLinee = $riferimentoNumeroLinee; 48 | $this->data = $data; 49 | $this->codiceCommessaConvenzione = $codiceCommessaConvenzione; 50 | $this->numItem = $numItem; 51 | $this->codiceCUP = $codiceCUP; 52 | $this->codiceCIG = $codiceCIG; 53 | $this->datiDocumentiCorrelati[] = $this; 54 | } 55 | 56 | public function addDatiDocumentoCorrelato(DatiDocumentoCorrelato $datiDocumentiCorrelati) 57 | { 58 | $this->datiDocumentiCorrelati[] = $datiDocumentiCorrelati; 59 | } 60 | 61 | /** 62 | * Return the current element 63 | * @link https://php.net/manual/en/iterator.current.php 64 | * @return mixed Can return any type. 65 | * @since 5.0.0 66 | */ 67 | public function current(): mixed 68 | { 69 | return $this->datiDocumentiCorrelati[$this->currentIndex]; 70 | } 71 | 72 | /** 73 | * Move forward to next element 74 | * @link https://php.net/manual/en/iterator.next.php 75 | * @return void Any returned value is ignored. 76 | * @since 5.0.0 77 | */ 78 | public function next(): void 79 | { 80 | $this->currentIndex++; 81 | } 82 | 83 | /** 84 | * Return the key of the current element 85 | * @link https://php.net/manual/en/iterator.key.php 86 | * @return mixed scalar on success, or null on failure. 87 | * @since 5.0.0 88 | */ 89 | public function key(): mixed 90 | { 91 | return $this->currentIndex; 92 | } 93 | 94 | /** 95 | * Checks if current position is valid 96 | * @link https://php.net/manual/en/iterator.valid.php 97 | * @return boolean The return value will be casted to boolean and then evaluated. 98 | * Returns true on success or false on failure. 99 | * @since 5.0.0 100 | */ 101 | public function valid(): bool 102 | { 103 | return isset($this->datiDocumentiCorrelati[$this->currentIndex]); 104 | } 105 | 106 | /** 107 | * Rewind the Iterator to the first element 108 | * @link https://php.net/manual/en/iterator.rewind.php 109 | * @return void Any returned value is ignored. 110 | * @since 5.0.0 111 | */ 112 | public function rewind(): void 113 | { 114 | $this->currentIndex = 0; 115 | } 116 | 117 | /** 118 | * Count elements of an object 119 | * @link https://php.net/manual/en/countable.count.php 120 | * @return int The custom count as an integer. 121 | *

122 | *

123 | * The return value is cast to an integer. 124 | * @since 5.1.0 125 | */ 126 | public function count(): int 127 | { 128 | return count($this->datiDocumentiCorrelati); 129 | } 130 | 131 | /** 132 | * @param \XMLWriter $writer 133 | * @return \XMLWriter 134 | */ 135 | public function toXmlBlock(\XMLWriter $writer) 136 | { 137 | /** @var DatiDocumentoCorrelato $block */ 138 | foreach ($this as $block) { 139 | $writer->startElement($block->tipoDocumentoCorrelato); 140 | if (count($block->riferimentoNumeroLinee) > 0) { 141 | /** @var int $linea */ 142 | foreach ($block->riferimentoNumeroLinee as $linea) { 143 | $writer->writeElement('RiferimentoNumeroLinea', $linea); 144 | } 145 | } 146 | $writer->writeElement('IdDocumento', $block->idDocumento); 147 | if ($block->data) { 148 | $writer->writeElement('Data', $block->data); 149 | } 150 | if ($block->numItem) { 151 | $writer->writeElement('NumItem', $block->numItem); 152 | } 153 | if ($block->codiceCommessaConvenzione) { 154 | $writer->writeElement('CodiceCommessaConvenzione', $block->codiceCommessaConvenzione); 155 | } 156 | if ($block->codiceCUP) { 157 | $writer->writeElement('CodiceCUP', $block->codiceCUP); 158 | } 159 | if ($block->codiceCIG) { 160 | $writer->writeElement('CodiceCIG', $block->codiceCIG); 161 | } 162 | $writer->endElement(); 163 | } 164 | return $writer; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiBeniServizi/Linea.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiBeniServizi; 13 | 14 | use Deved\FatturaElettronica\Enum\NaturaIvaType; 15 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 16 | use Deved\FatturaElettronica\XmlSerializableInterface; 17 | 18 | class Linea implements XmlSerializableInterface 19 | { 20 | use MagicFieldsTrait; 21 | /** @var int */ 22 | protected $numeroLinea; 23 | /** @var string */ 24 | protected $codiceArticolo; 25 | /** @var string */ 26 | protected $descrizione; 27 | /** @var float */ 28 | protected $quantita; 29 | /** @var string */ 30 | protected $unitaMisura; 31 | /** @var float */ 32 | protected $prezzoUnitario; 33 | /** @var float */ 34 | protected $aliquotaIva; 35 | /** @var string */ 36 | protected $codiceTipo; 37 | /** @var ScontoMaggiorazione[]|null */ 38 | protected $scontoMaggiorazione = []; 39 | /** @var AltriDatiGestionali[] */ 40 | protected $altriDatiGestionali = []; 41 | /** @var int */ 42 | protected $decimaliLinea; 43 | /** @var string */ 44 | protected $tipoCessionePrestazione; 45 | /** @var NaturaIvaType|null */ 46 | protected $naturaIva; 47 | 48 | 49 | /** 50 | * Linea constructor. 51 | * @param $descrizione 52 | * @param $prezzoUnitario 53 | * @param null $codiceArticolo 54 | * @param float $quantita 55 | * @param string $unitaMisura 56 | * @param float $aliquotaIva 57 | * @param string $codiceTipo 58 | * @param int $decimaliLinea 59 | */ 60 | public function __construct( 61 | $descrizione, 62 | $prezzoUnitario, 63 | $codiceArticolo = null, 64 | $quantita = null, 65 | $unitaMisura = 'pz', 66 | $aliquotaIva = 22.00, 67 | $codiceTipo = 'FORN', 68 | $decimaliLinea = 2, 69 | $tipoCessionePrestazione = null, 70 | $naturaIva = null 71 | ) { 72 | $this->codiceArticolo = $codiceArticolo; 73 | $this->descrizione = $descrizione; 74 | $this->prezzoUnitario = $prezzoUnitario; 75 | $this->quantita = $quantita; 76 | $this->unitaMisura = $unitaMisura; 77 | $this->aliquotaIva = $aliquotaIva; 78 | $this->codiceTipo = $codiceTipo; 79 | $this->decimaliLinea = $decimaliLinea; 80 | $this->tipoCessionePrestazione = $tipoCessionePrestazione; 81 | $this->naturaIva = $naturaIva; 82 | } 83 | 84 | 85 | /** 86 | * @param \XMLWriter $writer 87 | * @return \XMLWriter 88 | */ 89 | public function toXmlBlock(\XMLWriter $writer) 90 | { 91 | $writer->startElement('DettaglioLinee'); 92 | $writer->writeElement('NumeroLinea', $this->numeroLinea); 93 | if ($this->tipoCessionePrestazione) { 94 | $writer->writeElement('TipoCessionePrestazione', $this->tipoCessionePrestazione); 95 | } 96 | if ($this->codiceArticolo) { 97 | $writer->startElement('CodiceArticolo'); 98 | $writer->writeElement('CodiceTipo', $this->codiceTipo); 99 | $writer->writeElement('CodiceValore', $this->codiceArticolo); 100 | $writer->endElement(); 101 | } 102 | $writer->writeElement('Descrizione', $this->descrizione); 103 | if ($this->quantita) { 104 | $writer->writeElement('Quantita', fe_number_format($this->quantita, $this->decimaliQuantita())); 105 | if ($this->unitaMisura) { 106 | $writer->writeElement('UnitaMisura', $this->unitaMisura); 107 | } 108 | } 109 | $this->writeXmlField('DataInizioPeriodo', $writer); 110 | $this->writeXmlField('DataFinePeriodo', $writer); 111 | $writer->writeElement('PrezzoUnitario', fe_number_format($this->prezzoUnitario, $this->decimaliLinea)); 112 | foreach ($this->scontoMaggiorazione as $item) { 113 | $item->toXmlBlock($writer); 114 | } 115 | $writer->writeElement('PrezzoTotale', $this->prezzoTotale()); 116 | $writer->writeElement('AliquotaIVA', fe_number_format($this->aliquotaIva, 2)); 117 | if($this->naturaIva !== null) { 118 | $writer->writeElement('Natura', $this->naturaIva); 119 | } 120 | $this->writeXmlFields($writer); 121 | foreach ($this->altriDatiGestionali as $item) { 122 | $item->toXmlBlock($writer); 123 | } 124 | $writer->endElement(); 125 | return $writer; 126 | } 127 | 128 | /** 129 | * Calcola e restituisce il prezzo totale della linea 130 | * 131 | * @param bool $format 132 | * @return string | float 133 | */ 134 | public function prezzoTotale($format = true) 135 | { 136 | $quantita = $this->quantita ?: 1; 137 | $totale = $this->prezzoUnitario * $quantita; 138 | if ($format) { 139 | $totale = fe_number_format($totale, $this->decimaliLinea); 140 | } 141 | foreach ($this->scontoMaggiorazione as $item) { 142 | $totale = $item->applicaScontoMaggiorazione($totale, $quantita, $format ? $this->decimaliLinea : null); 143 | } 144 | return fe_number_format($totale, $this->decimaliLinea); 145 | } 146 | 147 | /** 148 | * Restituisce il numero di decimali della quantita 149 | * 150 | * @return int 151 | */ 152 | public function decimaliQuantita() 153 | { 154 | return max(min(strlen(substr(strrchr($this->quantita, "."), 1)), 8), 2); 155 | } 156 | 157 | /** 158 | * Imposta il numero riga 159 | * 160 | * @param integer $n 161 | */ 162 | public function setNumeroLinea($n) 163 | { 164 | $this->numeroLinea = $n; 165 | } 166 | 167 | /** 168 | * Restituisce Aliquota IVA 169 | * 170 | * @return float 171 | */ 172 | public function getAliquotaIva() 173 | { 174 | return $this->aliquotaIva; 175 | } 176 | 177 | public function setScontoMaggiorazione(ScontoMaggiorazione $scontoMaggiorazione) 178 | { 179 | $this->scontoMaggiorazione[] = $scontoMaggiorazione; 180 | } 181 | 182 | public function setAltriDatiGestionali(AltriDatiGestionali $altriDatiGestionali) 183 | { 184 | $this->altriDatiGestionali[] = $altriDatiGestionali; 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /src/FatturaElettronica/FatturaElettronicaBody/DatiGenerali.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody; 13 | 14 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali\DatiBollo; 15 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali\DatiContratto; 16 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali\DatiConvenzione; 17 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali\DatiDdt; 18 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali\DatiDocumentoCorrelato; 19 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali\DatiRitenuta; 20 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali\DatiCassaPrevidenziale; 21 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali\DatiSal; 22 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali\ScontoMaggiorazione; 23 | use Deved\FatturaElettronica\Traits\MagicFieldsTrait; 24 | use Deved\FatturaElettronica\XmlSerializableInterface; 25 | 26 | class DatiGenerali implements XmlSerializableInterface 27 | { 28 | use MagicFieldsTrait; 29 | 30 | /** @var string */ 31 | protected $tipoDocumento; 32 | /** @var string */ 33 | protected $data; 34 | /** @var string */ 35 | protected $numero; 36 | /** @var ScontoMaggiorazione */ 37 | protected $scontoMaggiorazione; 38 | /** @var float */ 39 | protected $importoTotaleDocumento; 40 | /** @var string */ 41 | protected $divisa; 42 | /** @var string */ 43 | protected $causale; 44 | /** @var DatiDdt */ 45 | protected $datiDdt; 46 | /** @var DatiContratto */ 47 | protected $datiContratto; 48 | /** @var DatiRitenuta */ 49 | protected $datiRitenuta; 50 | /** @var DatiBollo */ 51 | protected $datiBollo; 52 | /** @var DatiCassaPrevidenziale */ 53 | protected $datiCassaPrevidenziale; 54 | /** @var DatiSal */ 55 | protected $datiSal; 56 | /** @var DatiConvenzione */ 57 | protected $datiConvenzione; 58 | /** @var DatiDocumentoCorrelato */ 59 | protected $datiDocumentoCorrelati; 60 | 61 | 62 | /** 63 | * DatiGenerali constructor. 64 | * @param string $tipoDocumento 65 | * @param string $data 66 | * @param string $numero 67 | * @param float $importoTotaleDocumento 68 | * @param string $divisa 69 | */ 70 | public function __construct( 71 | $tipoDocumento, 72 | $data, 73 | $numero, 74 | $importoTotaleDocumento, 75 | $divisa = 'EUR' 76 | ) 77 | { 78 | $this->tipoDocumento = $tipoDocumento; 79 | $this->data = $data; 80 | $this->numero = $numero; 81 | $this->importoTotaleDocumento = $importoTotaleDocumento; 82 | $this->divisa = $divisa; 83 | } 84 | 85 | public function setDatiDdt(DatiDdt $datiDdt) 86 | { 87 | $this->datiDdt = $datiDdt; 88 | } 89 | 90 | public function setDatiConvenzione(DatiConvenzione $datiConvenzione) 91 | { 92 | $this->datiConvenzione = $datiConvenzione; 93 | } 94 | 95 | public function setDatiContratto(DatiContratto $datiContratto) 96 | { 97 | $this->datiContratto = $datiContratto; 98 | } 99 | 100 | public function setDatiDocumentoCorrelato(DatiDocumentoCorrelato $datiDocumentoCorrelati) 101 | { 102 | $this->datiDocumentoCorrelati = $datiDocumentoCorrelati; 103 | } 104 | 105 | public function setDatiRitenuta(DatiRitenuta $datiRitenuta) 106 | { 107 | $this->datiRitenuta = $datiRitenuta; 108 | } 109 | 110 | public function setScontoMaggiorazione(ScontoMaggiorazione $scontoMaggiorazione) 111 | { 112 | $this->scontoMaggiorazione = $scontoMaggiorazione; 113 | } 114 | 115 | public function setDatiBollo(DatiBollo $datiBollo) 116 | { 117 | $this->datiBollo = $datiBollo; 118 | } 119 | 120 | public function setDatiCassaPrevidenziale(DatiCassaPrevidenziale $datiCassaPrevidenziale) 121 | { 122 | $this->datiCassaPrevidenziale = $datiCassaPrevidenziale; 123 | } 124 | 125 | public function setDatiSal(DatiSal $datiSal) 126 | { 127 | $this->datiSal = $datiSal; 128 | } 129 | 130 | public function setCausale(string $causale) 131 | { 132 | $this->causale = $causale; 133 | } 134 | 135 | /** 136 | * @param \XMLWriter $writer 137 | * @return \XMLWriter 138 | */ 139 | public function toXmlBlock(\XMLWriter $writer) 140 | { 141 | $writer->startElement('DatiGenerali'); 142 | $writer->startElement('DatiGeneraliDocumento'); 143 | $writer->writeElement('TipoDocumento', $this->tipoDocumento); 144 | $writer->writeElement('Divisa', $this->divisa); 145 | $writer->writeElement('Data', $this->data); 146 | $writer->writeElement('Numero', $this->numero); 147 | if ($this->datiRitenuta) { 148 | $this->datiRitenuta->toXmlBlock($writer); 149 | } 150 | if ($this->datiBollo) { 151 | $this->datiBollo->toXmlBlock($writer); 152 | } 153 | if ($this->datiCassaPrevidenziale) { 154 | $this->datiCassaPrevidenziale->toXmlBlock($writer); 155 | } 156 | if ($this->scontoMaggiorazione) { 157 | $this->scontoMaggiorazione->toXmlBlock($writer); 158 | } 159 | $writer->writeElement('ImportoTotaleDocumento', fe_number_format($this->importoTotaleDocumento, 2)); 160 | if ($this->causale) { 161 | $writer->writeElement('Causale', $this->causale); 162 | } 163 | $this->writeXmlFields($writer); 164 | $writer->endElement(); 165 | 166 | if ($this->datiContratto) { 167 | $this->datiContratto->toXmlBlock($writer); 168 | } 169 | if ($this->datiConvenzione) { 170 | $this->datiConvenzione->toXmlBlock($writer); 171 | } 172 | if ($this->datiDocumentoCorrelati) { 173 | $this->datiDocumentoCorrelati->toXmlBlock($writer); 174 | } 175 | if ($this->datiSal) { 176 | $this->datiSal->toXmlBlock($writer); 177 | } 178 | if ($this->datiDdt) { 179 | $this->datiDdt->toXmlBlock($writer); 180 | } 181 | $writer->endElement(); 182 | //todo: implementare DatiOrdineAcquisto, DatiContratto etc. (facoltativi) 183 | return $writer; 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /src/FatturaElettronicaFactory.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | */ 11 | 12 | namespace Deved\FatturaElettronica; 13 | 14 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody; 15 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\Allegato; 16 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiBeniServizi\DatiRiepilogo; 17 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiBeniServizi\DettaglioLinee; 18 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiGenerali; 19 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiPagamento; 20 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaBody\DatiVeicoli; 21 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader; 22 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\CedentePrestatore; 23 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\CessionarioCommittente; 24 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\Common\DatiAnagrafici; 25 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\Common\Sede; 26 | use Deved\FatturaElettronica\FatturaElettronica\FatturaElettronicaHeader\DatiTrasmissione\IdTrasmittente; 27 | 28 | class FatturaElettronicaFactory 29 | { 30 | /** @var IdTrasmittente */ 31 | protected $idTrasmittente; 32 | /** @var CedentePrestatore */ 33 | protected $cedentePrestatore; 34 | /** @var CessionarioCommittente */ 35 | protected $cessionarioCommittente; 36 | /** @var string */ 37 | protected $codiceDestinatario = "0000000"; 38 | /** @var string */ 39 | protected $pec; 40 | /** @var bool */ 41 | protected $pa; 42 | /** @var string */ 43 | protected $telefono; 44 | /** @var string */ 45 | protected $email; 46 | /** @var string | integer */ 47 | protected $progressivoInvio = 0; 48 | /** @var XmlFactory */ 49 | protected $xmlFactory; 50 | /** @var string */ 51 | protected $soggettoEmittente; 52 | /** @var DatiAnagrafici */ 53 | protected $terzoIntermediario; 54 | 55 | 56 | /** 57 | * FatturaElettronicaFactory constructor. 58 | * @param DatiAnagrafici $datiAnagraficiCedente 59 | * @param Sede $sedeCedente 60 | * @param string $telefonoCedente 61 | * @param string $emailCedente 62 | * @param DatiAnagrafici|null $terzoIntermediario 63 | * @param string $soggettoEmittente 64 | */ 65 | public function __construct( 66 | DatiAnagrafici $datiAnagraficiCedente, 67 | Sede $sedeCedente, 68 | $telefonoCedente, 69 | $emailCedente, 70 | DatiAnagrafici $terzoIntermediario = null, 71 | $soggettoEmittente = 'TZ' 72 | ) { 73 | $this->setCedentePrestatore($datiAnagraficiCedente, $sedeCedente); 74 | $this->setInformazioniContatto($telefonoCedente, $emailCedente); 75 | if ($terzoIntermediario) { 76 | $this->setIntermediario($terzoIntermediario, $soggettoEmittente); 77 | } 78 | $this->xmlFactory = new XmlFactory(); 79 | } 80 | 81 | /** 82 | * @param DatiAnagrafici $datiAnagrafici 83 | * @param Sede $sede 84 | * @param bool $idTrasmittente 85 | */ 86 | public function setCedentePrestatore(DatiAnagrafici $datiAnagrafici, Sede $sede, $idTrasmittente = true) 87 | { 88 | $this->cedentePrestatore = new CedentePrestatore($datiAnagrafici, $sede); 89 | if ($idTrasmittente) { 90 | $this->idTrasmittente = new IdTrasmittente($datiAnagrafici->idPaese, $datiAnagrafici->codiceFiscale); 91 | } 92 | } 93 | 94 | /** 95 | * @param CedentePrestatore\IscrizioneRea $iscrizioneRea 96 | */ 97 | public function setIscrizioneRea(CedentePrestatore\IscrizioneRea $iscrizioneRea) 98 | { 99 | $this->cedentePrestatore->setIscrizioneRea($iscrizioneRea); 100 | } 101 | 102 | /** 103 | * @param string $riferimentoAmministrazione 104 | */ 105 | public function setRiferimentoAmministrazione($riferimentoAmministrazione) 106 | { 107 | $this->cedentePrestatore->setRiferimentoAmministrazione($riferimentoAmministrazione); 108 | } 109 | 110 | /** 111 | * @param IdTrasmittente $idTrasmittente 112 | */ 113 | public function setIdTrasmittente(IdTrasmittente $idTrasmittente) 114 | { 115 | $this->idTrasmittente = $idTrasmittente; 116 | } 117 | 118 | /** 119 | * @param DatiAnagrafici $terzoIntermediario 120 | * @param string $soggettoEmittente 121 | */ 122 | public function setIntermediario(DatiAnagrafici $terzoIntermediario, $soggettoEmittente = 'TZ') 123 | { 124 | $this->terzoIntermediario = $terzoIntermediario; 125 | $this->soggettoEmittente = $soggettoEmittente; 126 | } 127 | 128 | /** 129 | * @param string $telefono 130 | * @param string $email 131 | */ 132 | public function setInformazioniContatto($telefono, $email) 133 | { 134 | $this->telefono = $telefono; 135 | $this->email = $email; 136 | } 137 | 138 | /** 139 | * @param DatiAnagrafici $datiAnagrafici 140 | * @param Sede $sede 141 | * @param string $codiceDestinatario 142 | * @param string $pec 143 | * @param bool $pa 144 | */ 145 | public function setCessionarioCommittente( 146 | DatiAnagrafici $datiAnagrafici, 147 | Sede $sede, 148 | $codiceDestinatario = null, 149 | $pec = null, 150 | $pa = false 151 | ) { 152 | $this->cessionarioCommittente = new CessionarioCommittente($datiAnagrafici, $sede); 153 | if ($codiceDestinatario) { 154 | $this->codiceDestinatario = $codiceDestinatario; 155 | } else if ($datiAnagrafici->idPaese != 'IT') { 156 | $this->codiceDestinatario = 'XXXXXXX'; 157 | } 158 | if ($pec) { 159 | $this->pec = $pec; 160 | } 161 | $this->pa = $pa; 162 | } 163 | 164 | /** 165 | * @param DatiGenerali $datiGenerali 166 | * @param DatiPagamento $datiPagamento 167 | * @param DettaglioLinee $linee 168 | * @param bool $progessivoInvio 169 | * @param DatiRiepilogo|null $datiRiepilogo 170 | * @param Allegato|null $allegato 171 | * @param DatiVeicoli|null $datiVeicoli 172 | * @return FatturaElettronica 173 | * @throws \Exception 174 | */ 175 | public function create( 176 | DatiGenerali $datiGenerali, 177 | DatiPagamento $datiPagamento = null, 178 | DettaglioLinee $linee, 179 | $progessivoInvio = false, 180 | DatiRiepilogo $datiRiepilogo = null, 181 | Allegato $allegato = null, 182 | DatiVeicoli $datiVeicoli = null 183 | ) { 184 | if (!$this->cessionarioCommittente) { 185 | throw new \Exception('Dati cessionario non presenti!'); 186 | } 187 | if ($progessivoInvio) { 188 | $this->progressivoInvio = $progessivoInvio; 189 | } else { 190 | $this->progressivoInvio++; 191 | } 192 | $datiTrasmissione = new FatturaElettronicaHeader\DatiTrasmissione( 193 | $this->idTrasmittente, 194 | $this->progressivoInvio, 195 | $this->codiceDestinatario, 196 | $this->pa, 197 | $this->telefono, 198 | $this->email, 199 | $this->pec 200 | ); 201 | $fatturaElettronicaHeader = new FatturaElettronicaHeader( 202 | $datiTrasmissione, 203 | $this->cedentePrestatore, 204 | $this->cessionarioCommittente, 205 | $this->terzoIntermediario, 206 | $this->soggettoEmittente 207 | ); 208 | $datiBeniServizi = new FatturaElettronicaBody\DatiBeniServizi($linee, $datiRiepilogo); 209 | $fatturaElettronicaBody = new FatturaElettronicaBody( 210 | $datiGenerali, 211 | $datiBeniServizi, 212 | $datiPagamento, 213 | $allegato, 214 | $datiVeicoli 215 | ); 216 | return new FatturaElettronica($fatturaElettronicaHeader, $fatturaElettronicaBody, $this->xmlFactory); 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /xsd/xmldsig-core-schema.xsd: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | ]> 11 | 12 | 27 | 28 | 29 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 216 | 217 | 218 | 219 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | --------------------------------------------------------------------------------