承接 easybill/e-invoicing 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

easybill/e-invoicing

Composer 安装命令:

composer require easybill/e-invoicing

包简介

A package to read and create EN16931 e-invoices or CIUS like: XRechnung, ZUGFeRD etc.

README 文档

README

Packagist Version Generic badge

Introduction

e-invoicing is a library to generate and read data of specifications which comply with the EN16931. It is possible to generate CIUS like XRechnung, Peppol BIS Billing and ZUGFeRD / factur-x.

Usage

composer require easybill/e-invoicing

Example: EN16931 Cross Industry Invoice

In this example we generate a normal EN16931 as Cross Industry Invoice.

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)

Example: EN16931 Universal Business Language Invoice

In this example we generate a CIUS (XRechnung 3.0) as UBL document

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)

Example: Reading an unknown XML file

There might be the case that you receive some XML which may or may not be supported by this library. e-invoicing offers a handy way to just parse that XML and see if is deserializable to UBL or 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
}

You can refer to the tests in this repository for examples of using this library.

Customization

This library offers some degree of customization. You may create a customized Reader, Transformer or Writer. By default, the library does not trim whitespaces around values. This is true for values which do not end as enums. If you want to add that the functionality to trim the values you may refer to this test.

 $transformer = new Transformer(ConfiguredSerializer::createWithHandlers([
    new TrimStringValueHandler(),
    new CountryCodeEnumHandler(),
    new CurrencyCodeEnumHandler(),
    new DocumentTypeEnumHandler(),
    new ReferenceQualifierEnumHandler(),
    new UnitCodeEnumHandler(),
    new MimeTypeEnumHandler(),
    new ElectronicAddressSchemeIdentifierEnumHandler(),
]));

This allows to register custom handlers, or even add handlers which the library offers but does not include by default (yet) like the TrimStringValueHandler.

Considerations

Limitations

This library does not offer any way to validate the structured data against the rules of EN16931 or any of the CIUS. Please take a look at the folder Validators in the tests folder. There you will find ways to validate the documents against the CIUS specification rulesets. ZUGFeRD/factur-x offers XSD-Schema-Files which you may use directly in your PHP code. KOSiT offers a dedicated validator to validate your EN16931 document against the XRechnung CIUS specification.

Issues and contribution

Feel free to create Pull-Requests or Issue if you have trouble with this library or any related resource.

easybill/e-invoicing 适用场景与选型建议

easybill/e-invoicing 是一款 基于 XSLT 开发的 Composer 扩展包,目前已累计 155.26k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2024 年 06 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「xml」 「invoicing」 「einvoice」 「ZUGFeRD」 「cii」 「ubl」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 easybill/e-invoicing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 easybill/e-invoicing 我们能提供哪些服务?
定制开发 / 二次开发

基于 easybill/e-invoicing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 155.26k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 44
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 6
  • Forks: 2
  • 开发语言: XSLT

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-27