pabloveintimilla / facturaec
PHP library to handle electronic invoices of Ecuador (SRI)
Installs: 33
Dependents: 0
Suggesters: 0
Security: 0
Stars: 18
Watchers: 2
Forks: 12
Open Issues: 3
Type:project
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-11-16 02:11:34 UTC
README
FacturaEC
Project in development process.
Introduction
This is a PHP Library to handle electronic invoice of Ecuador (SRI), support: Invoices (facturas). Include operations to import from xml, read an transform (xml, json, cvs) data. This not implement user interface, this should be used as a library.
Installation
composer require pabloveintimilla/facturaec
Use
Bootstrap.
This should be include to autoload classes
<?php use Doctrine\Common\Annotations\AnnotationRegistry; $autoloader = require dirname(__DIR__).'/vendor/autoload.php'; AnnotationRegistry::registerLoader([$autoloader, 'loadClass']);
Read a xml file
Get data from a xml file
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();
Read miltiple files from directory
Automatic detect xml files from directory
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); }
Export
Export data to csv fie
use PabloVeintimilla\FacturaEC\Writer\Csv; $csv = new Csv($invoices); $csv->write($directory. DIRECTORY_SEPARATOR . 'FILE NAME');
Create a invoice object
Create object with fluent methods.
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); }