PHP code example of dmt-software / ubl-service

1. Go to this page and download the library: Download dmt-software/ubl-service 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/ */

    

dmt-software / ubl-service example snippets


use 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 invoice

use 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
}

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 format