josemmo/einvoicing

用于读取和创建符合欧洲标准的电子发票(EN 16931)的库

v0.2.7 2023-10-03 18:14 UTC

README


欧洲电子发票(eInvoicing)

Build Status Latest Version Supported PHP Versions License Documentation

关于

eInvoicing是一个PHP库,用于根据电子发票指令和欧洲标准创建和读取电子发票。

它旨在100%符合EN 16931标准以及最受欢迎的CIUS和扩展,如PEPPOL BIS

安装

首先,请确保您的环境满足以下要求:

  • PHP 7.1或更高版本
  • 用于读取和导出UBL/CII发票的SimpleXML扩展

然后,您应该可以使用Composer安装此库

composer require josemmo/einvoicing

使用方法

有关适当的快速入门指南,请访问文档网站:https://josemmo.github.io/einvoicing/

导入发票文档

use Einvoicing\Exceptions\ValidationException;
use Einvoicing\Readers\UblReader;

$reader = new UblReader();
$document = file_get_contents(__DIR__ . "/example.xml");
$inv = $reader->import($document);
try {
    $inv->validate();
} catch (ValidationException $e) {
    // Invoice is not EN 16931 complaint 
}

导出发票文档

use Einvoicing\Identifier;
use Einvoicing\Invoice;
use Einvoicing\InvoiceLine;
use Einvoicing\Party;
use Einvoicing\Presets;
use Einvoicing\Writers\UblWriter;

// Create PEPPOL invoice instance
$inv = new Invoice(Presets\Peppol::class);
$inv->setNumber('F-202000012')
    ->setIssueDate(new DateTime('2020-11-01'))
    ->setDueDate(new DateTime('2020-11-30'));

// Set seller
$seller = new Party();
$seller->setElectronicAddress(new Identifier('9482348239847239874', '0088'))
    ->setCompanyId(new Identifier('AH88726', '0183'))
    ->setName('Seller Name Ltd.')
    ->setTradingName('Seller Name')
    ->setVatNumber('ESA00000000')
    ->setAddress(['Fake Street 123', 'Apartment Block 2B'])
    ->setCity('Springfield')
    ->setCountry('DE');
$inv->setSeller($seller);

// Set buyer
$buyer = new Party();
$buyer->setElectronicAddress(new Identifier('ES12345', '0002'))
    ->setName('Buyer Name Ltd.')
    ->setCountry('FR');
$inv->setBuyer($buyer);

// Add a product line
$line = new InvoiceLine();
$line->setName('Product Name')
    ->setPrice(100)
    ->setVatRate(16)
    ->setQuantity(1);
$inv->addLine($line);

// Export invoice to a UBL document
header('Content-Type: text/xml');
$writer = new UblWriter();
echo $writer->export($inv);

路线图

以下是库的预期功能和当前进度

  • 将发票、当事人和发票行表示为对象
  • 与最常用的CIUS和扩展兼容
  • 将发票导出为UBL文档
  • 从UBL文档导入发票
  • 将发票导出为CII文档
  • 从CII文档导入发票
  • 完善的文档