Skip to content

A comprehensible PHP library to write Factur-X/ZUGFeRD XML files

License

Notifications You must be signed in to change notification settings

kinulab/facturx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kinulab/Facturx

This library aims to simplify the generation of Factur-X / ZUGFeRD XML files.

For the moment, this library only generate minimal format.

Installation

composer require kinulab/facturx

Usage

require 'vendor/autoload.php';

$invoice = new \Kinulab\Facturx\CrossIndustryInvoice\CrossIndustryInvoice(
    \Kinulab\Facturx\CrossIndustryInvoice\CrossIndustryInvoice::PROFILE_MINIMUM
);
$invoice->setInvoiceNumber("FC123456789");
$invoice->setInvoiceType(Kinulab\Facturx\CrossIndustryInvoice\CrossIndustryInvoice::INVOICE_TYPE_COMMERCIAL_INVOICE);
$invoice->setIssueDate( new \DateTime('today') );
$invoice->setDueDate( (new \DateTime('today'))->modify('+30 days') );
$invoice->setSeller( new \Kinulab\Facturx\CrossIndustryInvoice\LegalEntity() );
$invoice->setBuyer( new \Kinulab\Facturx\CrossIndustryInvoice\LegalEntity() );
$invoice->setCurrencyCode('EUR');
$invoice->setTaxBasisTotalAmount(100);
$invoice->setTaxTotalAmount(5.61);
$invoice->setGrandTotalAmount( 105.61 );
$invoice->setDuePayableAmount( 105.61 );

$seller = $invoice->getSeller();
$seller->setName('My Company Name');
$seller->setSiret('XXXXXX');
$seller->setVatIdentifier( 'XXXXX');
$seller->setAddress( new \Kinulab\Facturx\CrossIndustryInvoice\Address() );

$sellerAddress = $seller->getAddress();
$sellerAddress->setCountryId('FR');

$buyer = $invoice->getBuyer();
$buyer->setName('The Client');
$buyer->setVatIdentifier("ABC123");

// This is the XML that must be added to the PDF
$xml = \Kinulab\Facturx\CrossIndustryInvoice\XmlWriter::write($invoice);
$pdfFile = './raw-pdf-invoice/invoice-FC123456789.pdf'; // my invoice in PDF format

$facturx = new \Atgp\FacturX\Facturx();
$electronicInvoice = $facturx->generateFacturxFromFiles($pdfFile, $xml);
// $electronicInvoice is your invoice in Factur-x/ZUGFeRD format

file_put_contents('./facturx-invoice/invoice-FC123456789.pdf', $electronicInvoice);

About

A comprehensible PHP library to write Factur-X/ZUGFeRD XML files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages