PHP code example of einfacharchiv / zugferd
1. Go to this page and download the library: Download einfacharchiv/zugferd 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/ */
einfacharchiv / zugferd example snippets
$xml = file_get_contents('path/to/ZUGFeRD-invoice.xml');
// Validates the XML against the ZUGFeRD XSD.
if (Validator::isValid($xml)) {
$reader = new Reader($xml);
// Available methods
// Context
$reader->getType();
// Header
$reader->getId();
$reader->getName();
$reader->getTypeCode();
$reader->getIssueDate()->toDateTimeString();
foreach ($reader->getNotes() as $note) {
$note->getNote();
}
// Seller
$reader->getSeller()->getName();
$reader->getSeller()->getLineOne();
$reader->getSeller()->getLineTwo();
$reader->getSeller()->getZip();
$reader->getSeller()->getCity();
$reader->getSeller()->getCountry();
foreach ($reader->getSeller()->getTaxNumbers() as $taxNumber) {
$taxNumber->getNumber();
$taxNumber->getType();
}
// Buyer
$reader->getBuyer()->getId();
$reader->getBuyer()->getName();
$reader->getBuyer()->getLineOne();
$reader->getBuyer()->getLineTwo();
$reader->getBuyer()->getZip();
$reader->getBuyer()->getCity();
$reader->getBuyer()->getCountry();
foreach ($reader->getBuyer()->getTaxNumbers() as $taxNumber) {
$taxNumber->getNumber();
$taxNumber->getType();
}
// Delivery
$reader->getOccurrenceDate()->toDateTimeString();
// Settlement
$reader->getPaymentReference();
$reader->getCurrency();
foreach ($reader->getPaymentMethods() as $paymentMethod) {
$paymentMethod->getTypeCode();
$paymentMethod->getInformation();
$paymentMethod->getFinancialAccount()->getIban();
$paymentMethod->getFinancialAccount()->getName();
$paymentMethod->getFinancialAccount()->getId();
$paymentMethod->getFinancialInstitution()->getBic();
$paymentMethod->getFinancialInstitution()->getName();
}
foreach ($reader->getTaxes() as $tax) {
$tax->getTax()->getAmount();
$tax->getTax()->getCurrency();
$tax->getTypeCode();
$tax->getBasisAmount()->getAmount();
$tax->getBasisAmount()->getCurrency();
$tax->getCategoryCode();
$tax->getPercentage();
}
$reader->getLineTotal()->getAmount();
$reader->getLineTotal()->getCurrency();
$reader->getChargeTotal()->getAmount();
$reader->getChargeTotal()->getCurrency();
$reader->getAllowanceTotal()->getAmount();
$reader->getAllowanceTotal()->getCurrency();
$reader->getTaxBasisTotal()->getAmount();
$reader->getTaxBasisTotal()->getCurrency();
$reader->getTaxTotal()->getAmount();
$reader->getTaxTotal()->getCurrency();
$reader->getGrandTotal()->getAmount();
$reader->getGrandTotal()->getCurrency();
$reader->getTotalPrepaid()->getAmount();
$reader->getTotalPrepaid()->getCurrency();
$reader->getTotalAllowanceCharge()->getAmount();
$reader->getTotalAllowanceCharge()->getCurrency();
$reader->getDuePayable()->getAmount();
$reader->getDuePayable()->getCurrency();
foreach ($reader->getPaymentTerms() as $paymentTerms) {
$paymentTerms->getDescription();
$paymentTerms->getDueDate()->toDateTimeString();
}
}