### Install Fattura Elettronica Package Source: https://fatturaelettronicaphp.github.io/FatturaElettronica Install the package using Composer. Ensure you have PHP 7.3+ or 8.0. ```bash composer require fatturaelettronicaphp/fattura-elettronica ``` -------------------------------- ### Check for Errors Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/validating Call the `validate()->errors()` method to get a detailed list of any validation errors found in the XML document. Errors are returned as an associative array where keys are file paths and values are arrays of error messages. ```php $xml = '/path/to/file.xml'; $eDocument = Weble FatturaElettronica DigitalDocument::parseFrom($xml); $errors = $eDocument->validate()->errors(); // [ // '/path/to/xml/wrong/field' => [ // 'First Error', // 'Second Error' // ] // ] ``` -------------------------------- ### Recupero Dati Cliente Fattura Elettronica Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/manipulating Estrae informazioni specifiche sul cliente (cessionario/committente) da un documento XML di Fattura Elettronica. Assicura che il documento sia stato precedentemente parsato. ```php $xml = '/path/to/file.xml'; $eDocument = Weble FatturaElettronica DigitalDocument::parseFrom($xml); /** @var Weble FatturaElettronica Customer $ customer **/ $customer = $eDocument->getCustomer(); $customer->getName(); $customer->getVatNumber(); $customer->getSurname(); $customer->getOrganization(); $customer->getCountryCode(); $customer->getFiscalCode (); $customer->getTitle(); $customer->getEori(); $customer->getRepresentative(); ``` -------------------------------- ### Recupero Dati Fornitore Fattura Elettronica Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/manipulating Estrae informazioni specifiche sul fornitore da un documento XML di Fattura Elettronica. Richiede che il documento sia stato precedentemente parsato. ```php $xml = '/path/to/file.xml'; $eDocument = Weble FatturaElettronica DigitalDocument::parseFrom($xml); /** @var Weble FatturaElettronica Supplier $ customer **/ $supplier = $eDocument->getSupplier(); $supplier->getOrganization(); $supplier->getVatNumber(); ``` -------------------------------- ### Iterazione sui Dati del Documento Fattura Elettronica Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/manipulating Accede e itera sulle istanze dei documenti contenuti in un file XML di Fattura Elettronica. Assicura che il documento sia stato parsato correttamente. ```php $xml = '/path/to/file.xml'; $eDocument = Weble FatturaElettronica DigitalDocument::parseFrom($xml); $documents = $eDocument->getDocumentInstances(); /** @var Weble FatturaElettronica DigitalDocumentInstance $ document **/ foreach ( $documents as $document) { $document->getDocumentDate(); $document->getDocumentNumber(); } ``` -------------------------------- ### Analisi Dati Intestazione Fattura Elettronica Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/manipulating Estrae i dati di intestazione da un documento XML di Fattura Elettronica. Richiede il percorso del file XML. ```php $xml = '/path/to/file.xml'; $eDocument = Weble FatturaElettronica DigitalDocument::parseFrom($xml); /** @var Weble FatturaElettronica Customer $ customer **/ $customer = $eDocument->getCustomer(); /** @var Weble FatturaElettronica Supplier $ supplier **/ $supplier = $eDocument->getSupplier(); /** @var Weble FatturaElettronica DigitalDocument[] $ documents **/ $documents = $eDocument->getDocumentInstances(); $customer->getOrganization(); $customer->getVatNumber(); ``` -------------------------------- ### Run Package Tests Source: https://fatturaelettronicaphp.github.io/FatturaElettronica Execute the package's tests using Composer. ```bash composer test ``` -------------------------------- ### Writing to a File Path Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/writing This snippet demonstrates how to write an electronic document to a specified file path. If a full file path is provided, the XML will be written with that name. If a directory is provided, the file will be named according to SDI requirements. ```APIDOC ## Writing to a File Path This snippet demonstrates how to write an electronic document to a specified file path. If a full file path is provided, the XML will be written with that name. If a directory is provided, the file will be named according to SDI requirements. ```php $eDocument = new DigitalDocument(); $eDocument->setTransmissionFormat('FPR12'); $eDocument->write($filePath); ``` **Parameters:** * `$filePath` (string) - The path to the file or directory where the XML should be written. ``` -------------------------------- ### Write XML to File Path or Directory Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/writing Use the `write` method to save the digital document to a specified file path or directory. If a directory is provided, the filename will be generated according to SDI requirements. ```php $eDocument = new DigitalDocument(); $eDocument->setTransmissionFormat('FPR12'); $eDocument->write($filePath); ``` -------------------------------- ### Parse Fattura Elettronica from XML File Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/parsing Use DigitalDocument::parseFrom with an XML file path to load a Fattura Elettronica document. Access customer, supplier, and document instance details after parsing. ```php $xml = '/path/to/file.xml'; $eDocument = DigitalDocument::parseFrom($xml); /** @var \FatturaElettronicaPhp\FatturaElettronica\Customer $customer **/ $customer = $digitalDocument->getCustomer(); /** @var \FatturaElettronicaPhp\FatturaElettronica\Supplier $supplier **/ $supplier = $digitalDocument->getSupplier(); /** @var \FatturaElettronicaPhp\FatturaElettronica\DigitalDocument[] $documents **/ $documents = $digitalDocument->getDocumentInstances(); $customer->getOrganization(); // Alpha Srl $customer->getVatNumber(); // 03412317712 /** @var \FatturaElettronicaPhp\FatturaElettronica\DigitalDocument $document **/ foreach ($documents as $document) { $document->getDocumentDate(); // \DateTime $document->getDocumentNumber(); // 123 } ``` -------------------------------- ### Parse Fattura Elettronica from P7M File Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/parsing Load a Fattura Elettronica document from a .p7m file using DigitalDocument::parseFrom. This method handles the decryption and parsing of signed documents. ```php $p7m = '/path/to/file.xml.p7m'; $eDocument = DigitalDocument::parseFrom($p7m); ``` -------------------------------- ### Serialize Digital Document to SimpleXmlElement Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/writing Serialize a digital document instance into a `SimpleXMLElement` object. Ensure the input is an instance of `DigitalDocumentInterface`. ```php // Deve essere un'istanza di \FatturaElettronicaPhp\FatturaElettronica\Contracts\DigitalDocumentInterface $eDocument = new DigitalDocument(); $eDocument->setTransmissionFormat('FPR12'); /** @var \SimpleXmlElement $xml **/ $xml = $eDocument->serialize(); ``` -------------------------------- ### Parse XML Fattura Elettronica Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/structure Use the `parseFrom` static method on the `DigitalDocument` class to parse an XML string into a digital document object. This class represents the entire XML file structure. ```php $eDocument = \FatturaElettronicaPhp\FatturaElettronica\DigitalDocument::parseFrom( $xml ); ``` -------------------------------- ### Generate Electronic Invoice XML Source: https://fatturaelettronicaphp.github.io/FatturaElettronica Create a DigitalDocument instance, set the transmission format, and then serialize it to an XML SimpleXMLElement or write directly to a file. ```php // Deve essere un'istanza di \FatturaElettronicaPhp\FatturaElettronica\Contracts\DigitalDocumentInterface $eDocument = new DigitalDocument(); $eDocument->setTransmissionFormat('FPR12'); .... // Oggetto \SimpleXmlElement $xml = $eDocument->serialize(); // Scrive direttamente il file XML $eDocument->write($filePath); ``` -------------------------------- ### Parse Fattura Elettronica from SimpleXMLElement Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/parsing Parse a Fattura Elettronica document directly from a SimpleXMLElement object. This is useful when the XML has already been loaded into memory. ```php $xml = simplexml_load_string($stringXmlFatturaElettronica); $eDocument = DigitalDocument::parseFrom($xml); ``` -------------------------------- ### Serializing to SimpleXmlElement Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/writing This snippet shows how to serialize a DigitalDocument object into a SimpleXMLElement, which can be useful for further manipulation or inspection of the XML structure before writing. ```APIDOC ## Serializing to SimpleXmlElement This snippet shows how to serialize a DigitalDocument object into a SimpleXMLElement, which can be useful for further manipulation or inspection of the XML structure before writing. ```php // Must be an instance of \FatturaElettronicaPhp\FatturaElettronica\Contracts\DigitalDocumentInterface $eDocument = new DigitalDocument(); $eDocument->setTransmissionFormat('FPR12'); /** @var \SimpleXmlElement $xml **/ $xml = $eDocument->serialize(); ``` **Returns:** * `SimpleXMLElement` - The XML representation of the electronic document. ``` -------------------------------- ### Read Electronic Invoice XML Source: https://fatturaelettronicaphp.github.io/FatturaElettronica Parse an XML, p7m file, or SimpleXMLElement instance into a DigitalDocument object to extract customer, supplier, and document details. ```php // $xml può essere un file xml, p7m o un'istanza di \SimpleXmlElement $eDocument = DigitalDocument::parseFrom($xml); $customer = $digitalDocument->getCustomer(); $supplier = $digitalDocument->getSupplier(); $documents = $digitalDocument->getDocumentInstances(); ... $customer->getOrganization(); $customer->getVatNumber(); ... $documents[0]->getDocumentDate(); $documents[0]->getDocumentNumber(); ... ``` -------------------------------- ### Check Document Validity Source: https://fatturaelettronicaphp.github.io/FatturaElettronica/validating Use the `isValid()` method to determine if the XML document conforms to the official schema. This method returns a boolean value. ```php $xml = '/path/to/file.xml'; $eDocument = Weble FatturaElettronica DigitalDocument::parseFrom($xml); // true / False $eDocument->isValid(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.