赵爱国 / 发票ec
Ecuador(SRI)电子发票处理的PHP库
dev-master
2020-04-15 16:16 UTC
Requires
- php: >=7.2
- doctrine/annotations: ^1.6
- doctrine/cache: ^1.8
- elao/enum: ^1.5
- jms/serializer: ^2.1
- league/csv: ^9.0@dev
- psr/http-message: ^1.0
- symfony/dom-crawler: ^4.2
- symfony/finder: ^4.2
- symfony/property-access: ^4.2
- symfony/validator: ^4.2
Requires (Dev)
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^8
- symfony/var-dumper: ^4.2
- symplify/easy-coding-standard: ^5.4
This package is auto-updated.
Last update: 2024-09-16 01:50:11 UTC
README
FacturaEC
正在开发过程中的项目。
简介
这是一个处理Ecuador(SRI)电子发票的PHP库,支持:发票(facturas)。包括从xml导入、读取和转换(xml、json、csv)数据的功能。该库不实现用户界面,应作为库使用。
安装
composer require pabloveintimilla/facturaec
使用
引导。
应将其包含到自动加载类中
<?php use Doctrine\Common\Annotations\AnnotationRegistry; $autoloader = require dirname(__DIR__).'/vendor/autoload.php'; AnnotationRegistry::registerLoader([$autoloader, 'loadClass']);
读取xml文件
从xml文件中获取数据
use PabloVeintimilla\FacturaEC\Model\Invoice; use PabloVeintimilla\FacturaEC\Reader\XML; use PabloVeintimilla\FacturaEC\Reader\Adapter; use PabloVeintimilla\FacturaEC\Reader\Loader; $invoice = (new Reader(Invoice::class)) ->loadFromFile('PATH TO FILE') ->read(); // Get data $invoice->getDate();
读取目录中的多个文件
自动检测目录中的xml文件
use PabloVeintimilla\FacturaEC\Model\Collection\VoucherCollection; $loader = (new Loader()) ->loadXMLFromDirectory('PATH TO DIRECTORY'); $invoices = new VoucherCollection(); foreach ($loader as $data){ $adapter = new Adapter($data); $type = ucfirst(strtolower($adapter->getVoucherType())); $class = "PabloVeintimilla\FacturaEC\Model\\".$type; $invoice = (new XML($adapter->tranformIn(), $class)) ->read(); $invoices->add($invoice); }
导出
将数据导出到csv文件
use PabloVeintimilla\FacturaEC\Writer\Csv; $csv = new Csv($invoices); $csv->write($directory. DIRECTORY_SEPARATOR . 'FILE NAME');
创建发票对象
使用流式方法创建对象。
use PabloVeintimilla\FacturaEC\Model\InvoiceDetail; use PabloVeintimilla\FacturaEC\Model\Seller; $invoice = (new Invoice()) ->setStore('001') ->setPoint('002') ->setSequential('0000000003') ->setVoucherType('01') ->setEnviromentType('1') ->setEmissionType('1'); $seller = (new Seller()) ->setCompany('Pablo Veintimilla') ->setName('Clouder 7') ->setIdentification('1719415677') ->setAddress('Quito'); $invoice->setSeller($seller); for ($i = 1; $i <= 3; $i++) { $detail = (new InvoiceDetail($invoice)) ->setDescription("Producto $i") ->setQuantity($i) ->setUnitPrice($i * 10) ->setTotal(($i * 10) * $i); $invoice->addDetail($detail); }