GithubHelp home page GithubHelp logo

php-fatturapa's Introduction

php-fatturapa

php-fatturapa is a php implementation for FatturaPA XML specification. It allows reading from and writing to files formatted as described in the current specifications

1. Installation

To install php-fatturapa, require it using composer:

composer require robertogallea/php-fatturapa 

2. Usage

php-fatturapa currently supports only the Fattura Ordinaria model (not Fattura Semplificata)

The whole DOM of the XML document is wrapped by the class FatturaOrdinaria, which could be used directly or build using FatturaPA class.

Follow some basic usage exmaples:

2.1 Read From XML document file

/*   
 * Read from XML
 */
 $filename = 'IT01234567890_FPA01.xml';
 $fattura = FatturaPA::readFromXML($filename); 

2.2 Read From signed XML file

/*   
 * Read from XML signed document
 */
 $filename = 'IT01879020517_e4duu.xml.p7m';
 $fattura = FatturaPA::readFromSignedXML($filename); 

2.3 Read From XML string

/*   
 * Read from XML string
 */
 $xml = '<your-xml-string>';
 $fattura = FatturaPA::readFromXMLString($xml); 

2.4 Write to XML file

/*   
 * Read from XML
 */
 $filename = 'IT01234567890_FPA01.xml';
 FatturaPA::writeToXML($fattura, $filename); 

2.5 Write to XML string

/*   
 * Write to XML string
 */
 $xml = FatturaPA::writeToXMLString($fattura); 

3. Attachment handling

php-fatturapa provides methods for easily add and extract attachments to and from the XML document.
By specifications they are stored inside the FatturaElettronicaBody element, so theFatturaElettronicaBody class provides convenient methods for storing attachments performing the required compresson and base64 encoding:

/*   
 * Export attachments to folder
 */
 $filename = 'IT01234567890_FPA01.xml';
 $fattura = FatturaPA::readFromXML($filename);
 $folder = '/your/path';  
 
 foreach ($fattura->getFatturaElettronicaBody() as $body);
   $body->esportaAllegati($folder);
 }
/*   
 * Add attachment
 */
 $filename = 'IT01234567890_FPA01.xml';
 $fattura = FatturaPA::readFromXML($filename);
 $attachment_filename = /path/to.pdf;
 $attachment = Allegati::createFromFile($attachment_filename,'Name','Description');
 $fattura->getFatturaElettronicaBody()[0]->addAttachment($attachment);
 

php-fatturapa's People

Contributors

robertogallea avatar gecche avatar dependabot[bot] avatar

Stargazers

 avatar Ciro Lo Sapio avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.