Service to create and process UBL xml documents.
composer require dmt-software/ubl-serviceuse DMT\Ubl\Service\Entity\Invoice;
use DMT\Ubl\Service\UblService;
/** @var Invoice $invoice */
$service = new UblService();
print $service->toXml($invoice);
// <Invoice xmlns:cac="...">...</Invoice>use DMT\Ubl\Service\UblService;
$service = new UblService();
$invoice = $service->fromXml('<Invoice xmlns:cac="...">...</Invoice>');
// process the invoiceuse DMT\Ubl\Service\UblService;
use DMT\Ubl\Service\Transformer\Invoice\SimpleObjectToInvoiceTransformer;
use DMT\Ubl\Service\Objects\Invoice;
/** @var Invoice $invoice */
$service = new UblService();
$ublInvoice = $service->toInvoice($invoice, new SimpleObjectToInvoiceTransformer());use DMT\Ubl\Service\UblService;
use DMT\Ubl\Service\Transformer\Invoice\InvoiceLineToSimpleObjectTransformer;
use DMT\Ubl\Service\Entity\Invoice;
/** @var Invoice $ublInvoice */
$service = new UblService();
$invoice = $service->fromInvoice($ublInvoice, new InvoiceLineToSimpleObjectTransformer());use DMT\Ubl\Service\UblService;
use InvalidArgumentException;
$service = new UblService();
try {
// test (and formats) the identifier
$identifier = $service->checkIdentifier('0000000000123', 'GTIN');
} catch (InvalidArgumentException) {
// identifier is invalid
}By default toXml will return an UBL Invoice in PEPPOL BIS Billing 3.0 format.
To change the format you can add the correct format in the call:
use DMT\Ubl\Service\Entity\Invoice;
use DMT\Ubl\Service\UblService;
/** @var Invoice $invoice */
$service = new UblService();
print $service->toXml($invoice, Invoice::VERSION_NLCIUS);
// output is according to the NLCIUS formatIt is possible to change format from an existing XML by creating an invoice using fromXML followed by toXML with a
different format.
NOTE: When changing format, especially from new to older one, some data may be lost or invalid.