easybill/e-invoicing

一个用于读取和创建符合EN16931标准的e-invoice或CIUS(如:XRechnung,ZUGFeRD等)的包。

0.2.3 2024-09-20 06:23 UTC

This package is auto-updated.

Last update: 2024-09-24 09:29:56 UTC


README

Packagist Version Generic badge

简介

e-invoicing是一个库,用于生成和读取符合EN16931规范的规范数据。它可以生成类似于XRechnung、Peppol BIS Billing和ZUGFeRD / factur-x的CIUS。

用法

composer require easybill/e-invoicing

示例:EN16931跨行业发票

在这个示例中,我们生成一个普通的EN16931跨行业发票。

use easybill\eInvoicing\CII\Documents\CrossIndustryInvoice;
use easybill\eInvoicing\CII\Models\DocumentContextParameter;
use easybill\eInvoicing\CII\Models\ExchangedDocument;
use easybill\eInvoicing\CII\Models\ExchangedDocumentContext;
use easybill\eInvoicing\CII\Models\DateTime;
use easybill\eInvoicing\Transformer;

$document = new CrossIndustryInvoice();
$document->exchangedDocument = new ExchangedDocument();
$document->exchangedDocumentContext = new ExchangedDocumentContext();
$document->exchangedDocumentContext->documentContextParameter = new DocumentContextParameter();
$document->exchangedDocumentContext->documentContextParameter->id = 'urn:cen.eu:en16931:2017';
$document->exchangedDocument->id = '471102';
$document->exchangedDocument->issueDateTime = DateTime::create(102, '20200305');
// etc...
$xml = Transformer::create()->transformToXml($document)

示例:EN16931通用商业语言发票

在这个示例中,我们生成一个CIUS(XRechnung 3.0)作为UBL文档。

use easybill\eInvoicing\Transformer;
use easybill\eInvoicing\UBL\Documents\UblInvoice;
use easybill\eInvoicing\Enums\CurrencyCode;
use easybill\eInvoicing\Enums\DocumentType;

$document = new UblInvoice();
$document->customizationId = 'urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0';
$document->profileId = 'urn:fdc:peppol.eu:2017:poacc:billing:01:1.0';
$document->id = '123456XX';
$document->issueDate = '2016-04-04';
$document->invoiceTypeCode = DocumentType::COMMERCIAL_INVOICE;
$document->documentCurrencyCode = CurrencyCode::EUR;
$document->buyerReference = '04011000-12345-03';
// etc...
$xml = Transformer::create()->transformToXml($document)

示例:读取未知XML文件

可能存在您收到某些XML文件的情况,这些文件可能或可能不被本库支持。e-invoicing提供了一种方便的方式来解析该XML文件并查看它是否可反序列化为UBL或CII。

use easybill\eInvoicing\Reader;
use easybill\eInvoicing\CII\Documents\CrossIndustryInvoice;

$xml = file_get_contents($exampleXmlFile);

$readerResult = Reader::create()->read($xml);

// If the format is supported and valid in its structure the following check will be true
$readerResult->isSuccess()

// If the format is not supported or a different error occurred the result will have the state error.
$readerResult->isError()

// If it's valid you may retrieve the deserialized object from the dto.
// Invoking the getDocument method on an error will result in a LogicException
$document = $readerResult->getDocument(); 

if ($document instanceof CrossIndustryInvoice) {
    // do something with the CrossIndustryInvoice
}

您可以参考此存储库中的测试以获取使用此库的示例。

注意事项

限制

此库不提供任何方式来验证结构化数据是否符合EN16931或任何CIUS的规则。请参阅测试文件夹中的Validators文件夹。在那里,您可以找到验证文档是否符合CIUS规范规则集的方法。ZUGFeRD/factur-x提供可以直接在PHP代码中使用的XSD-Schema文件。KOSiT提供了一种专门的验证器,用于验证您的EN16931文档是否符合XRechnung CIUS规范。

问题和贡献

如果您在使用此库或任何相关资源时遇到问题,请随时创建Pull-Requests或Issue。