承接 dmt-software/ubl-service 相关项目开发

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

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

dmt-software/ubl-service

最新稳定版本:0.1.1

Composer 安装命令:

composer require dmt-software/ubl-service

包简介

Service to handle UBL documents

README 文档

README

Service to create and process UBL xml documents.

Install

composer require dmt-software/ubl-service

Usage

Invoice XML

Create an UBL Invoice XML

use DMT\Ubl\Service\Entity\Invoice;
use DMT\Ubl\Service\InvoiceService;

/** @var Invoice $invoice */
$service = new InvoiceService();
print $service->toXml($invoice);

// <Invoice xmlns:cac="...">...</Invoice>

Process an UBL Invoice XML

use DMT\Ubl\Service\InvoiceService;

$service = new InvoiceService();
$invoice = $service->fromXml('<Invoice xmlns:cac="...">...</Invoice>');

// process the invoice

Transformers

Create UBL Invoice from DTO

use DMT\Ubl\Service\InvoiceService;
use DMT\Ubl\Service\Transformer\Invoice\SimpleObjectToInvoiceTransformer;
use DMT\Ubl\Service\Objects\Invoice;

/** @var Invoice $invoice */
$service = new InvoiceService();
$ublInvoice = $service->toInvoice($invoice, new SimpleObjectToInvoiceTransformer());

Fetch DTO from UBL Invoice

use DMT\Ubl\Service\InvoiceService;
use DMT\Ubl\Service\Transformer\Invoice\InvoiceLineToSimpleObjectTransformer;
use DMT\Ubl\Service\Entity\Invoice;

/** @var Invoice $ublInvoice */
$service = new InvoiceService();
$invoice = $service->fromInvoice($ublInvoice, new InvoiceLineToSimpleObjectTransformer());

Validation

use DMT\Ubl\Service\InvoiceService;
use InvalidArgumentException;

$service = new InvoiceService();
try {
    // test (and formats) the identifier
    $identifier = $service->checkIdentifier('0000000000123', 'GTIN');
} catch (InvalidArgumentException) {
    // identifier is invalid
}

Different UBL versions

By default toXml will return an UBL Invoice in PEPPOL BIS Billing 3.0 format.
To change the format you can add the correct format in the call:

use DMT\Ubl\Service\Entity\Invoice;
use DMT\Ubl\Service\InvoiceService;

/** @var Invoice $invoice */
$service = new InvoiceService();
print $service->toXml($invoice, Invoice::VERSION_NLCIUS);

// output is according to the NLCIUS format

It is possible to change format from an existing XML by creating an invoice using fromXML followed by toXML with a different format.

NOTE: When changing format, especially from new to older one, some data may be lost or invalid.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-27