PHP code example of uctoplus / ubl-wrapper

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

    

uctoplus / ubl-wrapper example snippets


$generator = new Generator();

$invoice = new Invoice();
$invoice->setID(1);
$invoice->setIssueDate(Carbon::now());
$invoice->addNote("Note No. 1!!!");
$invoice->addNote(new NoteType("Note No. 2!!!", ["languageID" => "en"]));


// Create AccountingSupplierParty
$accountingSupplierParty = new SupplierPartyType();
$invoice->setAccountingSupplierParty($accountingSupplierParty);

// Create AccountingCustomerParty
$accountingCustomerParty = new CustomerPartyType();
$invoice->setAccountingCustomerParty($accountingCustomerParty);

// Create LegalMonetaryTotal
$legalMonetaryTotal = new MonetaryTotalType();

$payableAmount = new PayableAmountType();
$payableAmount->setCurrencyIDAttribute("EUR");
$payableAmount->setValue(15.35);
$legalMonetaryTotal->setPayableAmount($payableAmount);
$invoice->setLegalMonetaryTotal($legalMonetaryTotal);

// Create InvoiceLine
$invoiceLine = new InvoiceLineType();
$invoiceLine->setID("1");
$invoiceLine->setLineExtensionAmount(new LineExtensionAmountType("555", ["currencyID" => "EUR"]));

$item = new ItemType();
$item->setName("Item");

$invoiceLine->setItem($item);

$invoice->addInvoiceLine($invoiceLine);

$generator->addDocument($invoice);
$generator->save( 'path/to/file.xml' );

$parser = new Parser();
$parser->fromFile('tests/resources/UBL-Invoice-2.1-Example.xml');

$parser->getDocuments();