1. Go to this page and download the library: Download jh3ady/einvoicing 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/ */
jh3ady / einvoicing example snippets
use Jh3ady\EInvoicing\Enum\CountryCode;
use Jh3ady\EInvoicing\Enum\CurrencyCode;
use Jh3ady\EInvoicing\Enum\InvoiceType;
use Jh3ady\EInvoicing\Enum\TaxCategoryCode;
use Jh3ady\EInvoicing\Model\Invoice;
use Jh3ady\EInvoicing\Model\InvoiceLine;
use Jh3ady\EInvoicing\Model\Item;
use Jh3ady\EInvoicing\Model\MonetaryTotal;
use Jh3ady\EInvoicing\Model\Party;
use Jh3ady\EInvoicing\Model\PostalAddress;
use Jh3ady\EInvoicing\Model\Price;
use Jh3ady\EInvoicing\Model\TaxSubtotal;
use Jh3ady\EInvoicing\Model\TaxTotal;
use Jh3ady\EInvoicing\Model\ValueObject\Amount;
use Jh3ady\EInvoicing\Model\ValueObject\Quantity;
$address = new PostalAddress('10 rue de la Paix', 'Paris', CountryCode::FR, '75002');
$invoice = new Invoice(
number: 'FA-2024-001',
issueDate: new \DateTimeImmutable('2024-01-15'),
type: InvoiceType::Invoice,
currency: CurrencyCode::EUR,
seller: new Party(name: 'Seller SAS', address: $address, vatNumber: 'FR12345678901'),
buyer: new Party(name: 'Buyer SA', address: $address, vatNumber: 'FR98765432101'),
lines: [
new InvoiceLine(
id: '1',
quantity: new Quantity('2', 'C62'),
item: new Item(name: 'Consulting service'),
price: new Price(amount: new Amount('500.00')),
taxCategory: TaxCategoryCode::StandardRate,
taxRate: '20.00',
lineTotal: new Amount('1000.00'),
),
],
taxTotal: new TaxTotal(
taxAmount: new Amount('200.00'),
subtotals: [
new TaxSubtotal(
taxableAmount: new Amount('1000.00'),
taxAmount: new Amount('200.00'),
category: TaxCategoryCode::StandardRate,
taxRate: '20.00',
),
],
),
monetaryTotal: new MonetaryTotal(
lineExtensionAmount: new Amount('1000.00'),
taxExclusiveAmount: new Amount('1000.00'),
taxInclusiveAmount: new Amount('1200.00'),
payableAmount: new Amount('1200.00'),
),
);
use Jh3ady\EInvoicing\EInvoicing;
use Jh3ady\EInvoicing\Specification;
$xml = EInvoicing::serialize($invoice, Specification::ubl21());
use Jh3ady\EInvoicing\EInvoicing;
use Jh3ady\EInvoicing\Enum\FacturXProfile;
use Jh3ady\EInvoicing\Specification;
$xml = EInvoicing::serialize($invoice, Specification::facturX(FacturXProfile::EN16931));
$result = EInvoicing::validate($invoice, $spec);
if (!$result->isValid()) {
foreach ($result->errors() as $error) {
echo "[{$error->code}] {$error->message}\n";
}
}
$output = EInvoicing::process($invoice, $spec);
if ($output->isValid()) {
file_put_contents('invoice.xml', $output->xml);
}