PHP code example of b3it / x-rechnung-ubl

1. Go to this page and download the library: Download b3it/x-rechnung-ubl library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

b3it / x-rechnung-ubl example snippets


use UBL\Builder;
use UBL\Invoice;
use UBL\CommonAggregateComponents\MonetaryTotalType;
use UBL\UnqualifiedDataTypes\AmountType;
use UBL\UnqualifiedDataTypes\IdentifierType;

$invoice = new Invoice();
$invoice->setId(new IdentifierType('RE-2026-0001'));
$invoice->setIssueDate(new DateTime('2026-07-06'));

$legalMonetaryTotal = new MonetaryTotalType();
$legalMonetaryTotal->setLineExtensionAmount(new AmountType(314.86, 'EUR'));
$legalMonetaryTotal->setTaxExclusiveAmount(new AmountType(314.86, 'EUR'));
$legalMonetaryTotal->setTaxInclusiveAmount(new AmountType(336.90, 'EUR'));
$legalMonetaryTotal->setPayableAmount(new AmountType(336.90, 'EUR'));
$invoice->setLegalMonetaryTotal($legalMonetaryTotal);

$builder = new Builder();
$xml = $builder->serializeInvoice($invoice);

echo $xml;

use UBL\Builder;
use UBL\Invoice;

$builder = new Builder();
$xmlString = file_get_contents('invoice.xml');

/** @var Invoice $invoice */
$invoice = $builder->deserialize($xmlString, Invoice::class);

echo $invoice->getLegalMonetaryTotal()->getPayableAmount()->getValue();

Invoice::XR_CIUS_ID;       // urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0
Invoice::XR_EXTENSION_ID;  // ...#conformant#urn:xeinkauf.de:kosit:extension:xrechnung_3.0
Invoice::PROFILE_ID;       // urn:fdc:peppol.eu:2017:poacc:billing:01:1.0