dev-master
9999999-devEasy package to manage NFe resources
MIT
The Requires
- lightools/xml ^1.0
- illuminate/support ^5.3
- php >=7.0.13
The Development Requires
by Bruno Ferme Gasparin
Wallogit.com
2017 © Pedro PelĆ”ez
Easy package to manage NFe resources
NFeEasy is a wrapper to manage NFe files., (*1)
You and install via composer:, (*2)
$ composer require nfe-easy/nfe-easy
and use composer autoload:, (*3)
require_once('vendor/autoload.php');
If you don't want to use Composer, download the latest version of NefEasy and include the init.php file:, (*4)
require_once('/path/to/nfeasy/init.php');
You will also need to dowload the NfeEasy php dependencies and autoload then
manually. See composer.json to see NfeEasy dependencies., (*5)
To use the NfeEasy, just pass the xml nfe file content to the XmlInvoiceBuilder and it will returns the PHP objects representing the given NFe., (*6)
XmlInvoiceBuilder::::create(
file_get_contents('path/to//my/invoice.xml')
); // returns an instance of NFeEasy\Invoice
Each Domain from NFe file is represented by an NFeEasy object class. These classes are called Domain Object Classes., (*7)
The list of Domains Object Classes includes:, (*8)
NFeEasy\InvoiceNFeEasy\ProductNFeEasy\EmitterNFeEasy\ReceiverNFeEasy\AddressA full NFe file is represented by a relationship between one or more NFeEasy Domain Objects Classes., (*9)
The NFeEasy Domain Object Classes contain the data extracted from the NFe file. The data is diviled between the NfeEasy Domain Object Classes., (*10)
For a full NfeEasy reprentation, use the
NFeEasy\Builder\XmlInvoiceBuilder::create method.
It will return an NFeEasy\Invoice instance., (*11)
The NFeEasy\Invoice represents the NFe file itself, and contains
data to indentity the NFe., (*12)
All other Domain Object Classes resides below Invoice Object., (*13)
The table bellow describes all attributes you can access from
NFeEasy\Invoice class:, (*14)
| Attribute | Type | Description |
|---|---|---|
cUF |
string | |
cNF |
string | Transaction Nature Id |
natOp |
string | Transaction Nature Description |
indPag |
string | Payment Id (0 = Entrada / 1 = SaĆda) |
mod |
string | |
serie |
string | Invoice Serie |
nNF |
string | Invoice Number |
dhEmi |
string | Emission Date |
tpNF |
string | Invoice Type Id |
idDest |
string | |
cMunFG |
string | |
tpImp |
string | |
tpEmis |
string | |
cDV |
string | |
tpAmb |
string | |
finNFe |
string | |
indFinal |
string | |
indPres |
string | |
procEmi |
string | |
verProc |
string | Version |
products |
Collection(Product) | A list of Product for this Invoice |
additionalInfo |
string | Addicional Information |
emitter |
Emitter | The Invoice Emitter
|
receiver |
Receiver | The Invoice Receiver
|
NFeEasy\Product represents an Invoice`s product.
It contains informations like the name of the product, the NCM, the value, the quantity the taxes, and other product related things., (*15)
The table bellow describes all attributes you can access from
NFeEasy\Product class:, (*16)
| Attribute | Type | Description |
|---|---|---|
cProd |
string | Product Id |
cEAN |
string | |
xProd |
string | Product Description |
NCM |
string | Nomenclatura Comum do Mercosul / Sistema Harmonizado |
CEST |
string | |
CST |
string | Table CST - ICMS |
CFOP |
string | Codigo Fiscal de OperaƧƵes e PrestaƧƵes |
uCom |
string | Invoice Number |
qCom |
string | Emission Date |
vUnCom |
string | Invoice Type Id |
vProd |
string | Product Value |
cEANTrib |
string | |
uTrib |
string | Unit Type (UN, CX) |
qTrib |
string | |
vUnTrib |
string | Unit Value |
indTot |
string | Total Value (nItemPed*intTotal) |
xPed |
string | |
nItemPed |
string | Quantity |
nFCI |
string | |
NFeEasy\Emitter represents the NFe emitter, (*17)
The table bellow describes all attributes you can access from
NFeEasy\Product class:, (*18)
| Attribute | Type | Description |
|---|---|---|
CNPJ |
string | The CNPJ |
xNome |
string | The Emitter name |
xFant |
string | Trading name |
IE |
string | |
IEST |
string | |
CRT |
string | |
address |
Address | The Emitter Address |
NFeEasy\Receiver represents the NFe Receiver, (*19)
The table bellow describes all attributes you can access from
NFeEasy\Product class:, (*20)
| Attribute | Type | Description |
|---|---|---|
CNPJ |
string | The CNPJ |
xNome |
string | The Receiver name |
IE |
string | |
indIEDest |
string | |
address |
Address | The Receiver Address |
NFeEasy\Address represents an address object, (*21)
The table bellow describes all attributes you can access from
NFeEasy\Address class:, (*22)
| Attribute | Type | Description |
|---|---|---|
xLgr |
string | The Street name |
nro |
string | the Street number |
xBairro |
string | The Neighborhood name |
cMun |
string | The District Code |
xMun |
string | The Destrict name |
UF |
string | The District |
CEP |
string | The CEP |
cPais |
string | The Country Code |
xPais |
string | The Country Name |
fone |
string | The phone number |
You can create Domain Object classes individually. Just use
the method created from the respective object
passing the parameters you wnat to populate into the object:, (*23)
$address = Address::create([
'xLgr' => 'Some address street',
'nro' => '207'
]); // returns an NFeEasy\Address
If you dont't want to create the domain objects individually, you can
pass all data directy to the NfeEasy\Invoice:, (*24)
$invoice = Invoice::create([
'cUF' => '32',
'natOp' => 'Venda Sub / Venda Mer',
'addicionalInfo' => 'Some Info',
// ...
'emitter' => [
'xNome' => 'Emitter Name',
'CNPJ' => '23740049120232'
// ...
],
'receiver' => [
'xNome' => 'Receiver Name',
'CNPJ' => '40193549120112'
// ...
],
'products' => [
[
'cProd' => '13'
'xProd' => 'Shampoo'
// ...
],
[
'cProd' => '345'
'xProd' => 'Soap'
// ...
],
// ...
]
]); // returns an NFeEasy\Invoice
After a Domain Object is created, you can access the data by access attributes by its names:, (*25)
$product = Product::create([
'cProd' => '12'
'xProd' => 'Notebook'
]);
echo $product->xProd; // prints 'Shampoo'
You can access child objects by the attributes names too:, (*26)
$emitter = Emitter::create([
'xNome' => 'Andrew'
'CNPJ' => '23740049120232',
'address' => [
'xLgr' => 'Rua IvaĆ',
'nro' => 207,
'xBairro' => 'TatuapƩ'
],
]);
$emitter->address; // returns an instance of NfeEasy\Address;
echo $emitter->address->xBairro; prints 'TatuapƩ'
Array of Domain Objects are treated as Collections into NfeEasy. All Object Collections are represented by an instance of Illuminate\Support\Collection., (*27)
Collections in NfeEasy are used for:, (*28)
products attribute into Invoice Object For example, to return the collection of products from an Invoice, use:, (*29)
$products $invoice->products; // Return an instance of `Illuminate\Support\Collection`.
To filter products with value greater than 20, use:, (*30)
$products = $invoice->products->filter(function ($product, $key){
return $product->vProd > 20;
});
For all Illuminate\Support\Collection available methods, see Illuminate Collection Docs., (*31)
All Domain objects implements Illuminate\Contracts\Support\Arrayable and Illuminate\Contracts\Support\Arrayable\Jsonable., (*32)
So you can transform the all NfeEasy Domain objects easily:, (*33)
$invoice => Invoice::create([
// attributes data
]);
$invoice->toArray(); // converts the domains objects into arrays
$invoice->toJson(); // converts the domains objects into a json string
(string)$invoice; // converts the domains objects into a json string
NfeEasy uses PHPUnit unit tests for better reliablility and security., (*34)
To run all tests, justs go to the project folder and type:, (*35)
$ phpunit
NfeEasy is open-sourced software licensed under the MIT license., (*36)
Easy package to manage NFe resources
MIT