赵爱国/发票ec

Ecuador(SRI)电子发票处理的PHP库

安装: 33

依赖项: 0

建议者: 0

安全: 0

星标: 18

关注者: 2

分支: 12

开放问题: 3

类型:项目

dev-master 2020-04-15 16:16 UTC

README

Codacy Badge Coding Standards

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);
}