Giter Club home page Giter Club logo

php-documents's Introduction

Brazanation Documents

Build Status Codacy Badge Scrutinizer Code Quality Code Coverage StyleCI

A PHP library to provide Brazilian Documents safer, easier and fun!

Installation

Install the library using composer. Add the following to your composer.json:

{
    "require": {
        "brazanation/documents": "2.1.*"
    }
}

Now run the install command.

$ composer.phar install

or

$ composer require brazanation/documents 2.1.*

CPF (cadastro de pessoas físicas)

Registration of individuals or Tax Identification

use Brazanation\Documents\Cpf;

$document = Cpf::createFromString('06843273173');
if (false === $document) {
   echo "Not Valid";
}
echo $document; // prints 06843273173
echo $document->format(); // prints 068.432.731-73

or

use Brazanation\Documents\Cpf;
use Brazanation\Documents\Exception\InvalidDocument as  InvalidDocumentException;

try {
    $document = new Cpf('06843273173');
    echo $document; // prints 06843273173
    echo $document->format(); // prints 068.432.731-73
} catch (InvalidDocumentException $e) {
    echo $e->getMessage();
}

CNPJ (cadastro nacional da pessoa jurídica)

Company Identification or National Register of Legal Entities

use Brazanation\Documents\Cnpj;

$document = Cnpj::createFromString('99999090910270');

if (false === $document) {
   echo "Not Valid";
}
echo $document; // prints 99999090910270
echo $document->format(); // prints 99.999.090/9102-70

CNH (carteira nacional de habilitação)

National Driving License

use Brazanation\Documents\Cnh;

$document = Cnh::createFromString('83592802666');

if (false === $document) {
   echo "Not Valid";
}
echo $document; // prints 83592802666
echo $document->format(); // prints 83592802666

Chave de Acesso Sped (chave da NFe, CTe e MDFe)

Sped Access Key

Available models:

  • NFe
  • NFCe
  • CTe
  • CTeOther
  • MDFe
use Brazanation\Documents\Sped\NFe;

$document = NFe::createFromString('52060433009911002506550120000007801267301613');

if (false === $document) {
   echo "Not Valid";
}
echo $document; // prints 52060433009911002506550120000007801267301613
echo $document->format(); // prints 5206 0433 0099 1100 2506 5501 2000 0007 8012 6730 1613

or generate your number

try {
    $nfeKey = NFe::generate(
        52,
        $generatedAt,
        new Cnpj('33009911002506'),
        12,
        780,
        EmissionType::normal(),
        26730161
    );
    echo $accessKey; // prints 52060433009911002506550120000007801267301613
}catch (InvalidDocumentException $e){
    echo $e->getMessage();
}

PIS/PASEP (programa de integração social e programa de formação do patrimônio do servidor público)

Social Integration Program and Training Program of the Heritage of Public Servant

use Brazanation\Documents\PisPasep;

$document = PisPasep::createFromString('518.23129.49-1');

if (false === $document) {
   echo "Not Valid";
}

echo $document; // prints 51823129491
echo $document->format(); // prints 518.23129.49-1

Título de Eleitor

Voter Registration

use Brazanation\Documents\Voter;

$document = Voter::createFromString('106644440302', 20, 42);

if (false === $document) {
   echo "Not Valid";
}

echo $document; // prints 106644440302
echo $document->getSection(); // prints 0020
echo $document->getZone(); // prints 042

Inscrição Estadual

State Registration

use Brazanation\Documents\StateRegistration;

// for Commercial São Paulo
$state = StateRegistration::SP('110.042.490.114');
echo $state; // prints 110042490114
echo $state->format(); // prints 110.042.490.114

// for Rural Producer São Paulo
$state = StateRegistration::SP('P011004243002');
echo $state; // prints P011004243002
echo $state->format(); // prints P-01100424.3/002

or

use Brazanation\Documents\StateRegistration;

$document = StateRegistration::createFromString('P011004243002', 'SP');

if (false === $document) {
   echo "Not Valid";
}

Cartão Nacional de Saúde (SUS)

National Health Card

use Brazanation\Documents\Cns;

$document = Cns::createFromString('242912018460005');

if (false === $document) {
   echo "Not Valid";
}

echo $document; // prints 242912018460005
echo $document->format(); // prints 242 9120 1846 0005

Renavam (Registro Nacional de Veículos Automotores)

National Registry of Motor Vehicles

use Brazanation\Documents\Renavam;

$document = Renavam::createFromString('61855253306');

if (false === $document) {
   echo "Not Valid";
}

echo $document; // prints 61855253306
echo $document->format(); // prints 6185.525330-6

Processos Judiciais

Numbers of legal proceedings related to Judiciary assessments

use Brazanation\Documents\JudiciaryProcess;

$document = JudiciaryProcess::createFromString('0048032982009809');

if (false === $document) {
   echo "Not Valid";
}

echo $document; //prints  0048032982009809
echo $document->format(); //prints  0048032.98.2009.8.09.0000

Suframa

Number of registration in "Superintendência da Zona Franca de Manaus" (Free Comercial Zones)

use Brazanation\Documents\Suframa;

$document = Suframa::createFromString('201111019');

if (false === $document) {
   echo "Not Valid";
}

echo $document; //prints  201111019
echo $document->format(); //prints  20.1111.019

License

MIT, hell yeah!

php-documents's People

Contributors

begnini avatar carusogabriel avatar ferreiramg avatar guil95 avatar henriqueholanda avatar joubertredrat avatar lerox avatar robmachado avatar thalfm avatar tonicospinelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-documents's Issues

Erro na construção das Chaves para o SPED

@tonicospinelli

Vou fazer um pull request para isso, por favor verifique se não usei algo errado.

Estou testando as chaves porém existe um BUG na geração das chaves do SPED.

A chave de 44 dígitos é formada com os seguintes campos:

cUF OK (2 dígitos) total = 2
AAMM OK (4 dígitos) total = 6
CNPJ OK (14 dígitos) total = 20
modelo OK (2 dígitos) total = 22
serie OK (3 dígitos) total = 25
numero da documento fiscal OK (9 dígitos) total = 34
tipo de Emissão NOK (1 dígito) total = 34 ???? DEVERIA SER 35
numero de controle ---- OK (8 dígitos) total = 42 ???? DEVERIA SER 43

ERRO, o campo "tpEmis" não está presente, ele é um inteiro de 1 a 9 indicando emissão normal ou uma das contingências e deve ser passado como parâmetro na função. Com isso o numero formado fica com apenas 42 dígitos e deveria ser de 43 dígitos complementado para 44 pelo digito verificador "cDV".

Tem um outro detalhe que também está errado o numero de controle "cNF" tem apenas 8 dígitos e não 9 como indicado nas classes. A versão que tinha com 9 dígitos é bemmmmm antiga, já faz anos que isso mudou !!

Encontrei outro erro na geração do digito verificador Modulo 11 quando calculo do resto resulta em 0 esta retornando dois dígitos (11) e não deveria !!

missing CNS document

Cartão Nacional de Saúde (CNS) / National Health Card

  • CNS Card starts with 1 or 2
  • CNS Temporary starts with 7, 8 or 9

create Renavam Document

RENAVAM has 11 digits with follow format NNNN.NNNNNN-N, first 10 digits are base numbers and the last is checker digit calculated with Module 11.

The checker digit is calculated multiplying each digit by the sequence of multipliers 2, 3, 4, 5, 6, 7, 8, 9, 2 and 3, allocated from right to left side.

The sum of mulpltications will be multiplied by 10 and after divided by 11, the remainder of division is the digit checker. Except when 10 is the remainder of division, it must be changed to 0.

missing State Registration document

State Registration is so complex, because it has different numbers based on State rules.

So, what are states from Brazil?

  • AC - ACRE
  • AL - ALAGOAS
  • AM - AMAZONAS
  • AP - AMAPÁ
  • BA - BAHIA
  • CE - CEARÁ
  • DF - DISTRITO FEDERAL
  • ES - ESPÍRITO SANTO
  • GO - GOIÁS
  • MA - MARANHÃO
  • MG - MINAS GERAIS
  • MS - MATO GROSSO DO SUL
  • MT - MATO GROSSO
  • PA - PARÁ
  • PB - PARAÍBA
  • PE - PERNAMBUCO
  • PI - PIAUÍ
  • PR - PARANÁ
  • RJ - RIO DE JANEIRO
  • RN - RIO GRANDE DO NORTE
  • RO - RONDÔNIA
  • RR - RORAIMA
  • RS - RIO GRANDE DO SUL
  • SC - SANTA CATARINA
  • SE - SERGIPE
  • SP - SÃO PAULO
  • TO - TOCANTINS

Tornar NFeAccessKey em uma classe mais generica

As chaves de acesso tanto para NFe como para CTe e MDFe possuem a mesma estrutura e os mesmos dados são usados para cria-las.

Portanto, como já conversado podemos deixar essa classe como:
AccessKey ou ainda SpedAccessKey ao invés de NFeAccessKey, isso deixaria menos confuso aos desenvolvedores. Pois ela seria usada em vários locais.

Cnpj::createFromString() retornando sempre NULL

Ao implementar Cnpj::createFromString() como exemplificado em

use Brazanation\Documents\Cnpj;

$document = Cnpj::createFromString('99999090910270');

if (false === $document) {
   echo "Not Valid";
}
echo $document; // prints 99999090910270
echo $document->format(); // prints 99.999.090/9102-70

$document sempre retorna NULL

Erro no método discoverModule da classe Bahia

Segundo o manual:

  • Para inscrições com 8 dígitos, deve-se calcular com módulo 10, desde que comecem com 0,1,2,3,4,5 e 8.
  • Para inscrições com 9 dígitos, deve-se calcular com módulo 10, desde que o segundo dígito seja 0,1,2,3,4,5 e 8.
    O módulo 11 esta sendo utilizado para o intervalo de 6 à 9 pegando o 8 o que pode ocasionar erro.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.