Class: Nfcom::Models::Emitente
- Inherits:
-
Object
- Object
- Nfcom::Models::Emitente
- Includes:
- Utils::Helpers
- Defined in:
- lib/nfcom/models/emitente.rb
Overview
O emitente deve estar cadastrado e credenciado na SEFAZ para emissão de NF-COM antes de usar esta gem.
Representa o emitente da NF-COM
O emitente é a empresa prestadora do serviço de comunicação que está emitindo a nota fiscal. Deve ser sempre pessoa jurídica (CNPJ).
Atributos obrigatórios:
-
cnpj (14 dígitos, com validação)
-
razao_social (razão social da empresa)
-
inscricao_estadual (IE do estado)
-
endereco completo
Atributos opcionais:
-
nome_fantasia (nome de fantasia/comercial)
-
inscricao_municipal (IM do município)
-
cnae (classificação da atividade econômica)
-
regime_tributario (1=Simples Nacional, 2=Simples Excesso, 3=Normal)
Validações automáticas:
-
Validação de dígitos verificadores do CNPJ
-
Rejeita CNPJ com todos dígitos iguais
-
Valida presença de campos obrigatórios
-
Valida campos obrigatórios do endereço
Constant Summary collapse
- REGIME_TRIBUTARIO =
Códigos de Regime Tributário (CRT)
{ simples_nacional: 1, simples_excesso: 2, normal: 3 }.freeze
Instance Attribute Summary collapse
-
#cnae ⇒ Object
Returns the value of attribute cnae.
-
#cnpj ⇒ Object
Returns the value of attribute cnpj.
-
#endereco ⇒ Object
Returns the value of attribute endereco.
-
#inscricao_estadual ⇒ Object
Returns the value of attribute inscricao_estadual.
-
#inscricao_municipal ⇒ Object
Returns the value of attribute inscricao_municipal.
-
#nome_fantasia ⇒ Object
Returns the value of attribute nome_fantasia.
-
#razao_social ⇒ Object
Returns the value of attribute razao_social.
-
#regime_tributario ⇒ Object
Returns the value of attribute regime_tributario.
Instance Method Summary collapse
- #erros ⇒ Object
-
#initialize(attributes = {}) ⇒ Emitente
constructor
A new instance of Emitente.
-
#regime_tributario_codigo ⇒ Integer
Retorna o código do regime tributário para o XML.
- #valido? ⇒ Boolean
Methods included from Utils::Helpers
apenas_numeros, cnpj_valido?, cpf_valido?, formatar_cep, formatar_cnpj, formatar_cpf, formatar_data, formatar_data_hora, formatar_decimal, gerar_id, limitar_texto, remover_acentos, safe_to_date, vazio?
Constructor Details
#initialize(attributes = {}) ⇒ Emitente
Returns a new instance of Emitente.
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/nfcom/models/emitente.rb', line 71 def initialize(attributes = {}) @endereco = Endereco.new @regime_tributario = :normal # Padrão: Regime Normal attributes.each do |key, value| if key == :endereco && value.is_a?(Hash) @endereco = Endereco.new(value) elsif respond_to?("#{key}=") send("#{key}=", value) end end end |
Instance Attribute Details
#cnae ⇒ Object
Returns the value of attribute cnae.
61 62 63 |
# File 'lib/nfcom/models/emitente.rb', line 61 def cnae @cnae end |
#cnpj ⇒ Object
Returns the value of attribute cnpj.
61 62 63 |
# File 'lib/nfcom/models/emitente.rb', line 61 def cnpj @cnpj end |
#endereco ⇒ Object
Returns the value of attribute endereco.
61 62 63 |
# File 'lib/nfcom/models/emitente.rb', line 61 def endereco @endereco end |
#inscricao_estadual ⇒ Object
Returns the value of attribute inscricao_estadual.
61 62 63 |
# File 'lib/nfcom/models/emitente.rb', line 61 def inscricao_estadual @inscricao_estadual end |
#inscricao_municipal ⇒ Object
Returns the value of attribute inscricao_municipal.
61 62 63 |
# File 'lib/nfcom/models/emitente.rb', line 61 def inscricao_municipal @inscricao_municipal end |
#nome_fantasia ⇒ Object
Returns the value of attribute nome_fantasia.
61 62 63 |
# File 'lib/nfcom/models/emitente.rb', line 61 def nome_fantasia @nome_fantasia end |
#razao_social ⇒ Object
Returns the value of attribute razao_social.
61 62 63 |
# File 'lib/nfcom/models/emitente.rb', line 61 def @razao_social end |
#regime_tributario ⇒ Object
Returns the value of attribute regime_tributario.
61 62 63 |
# File 'lib/nfcom/models/emitente.rb', line 61 def regime_tributario @regime_tributario end |
Instance Method Details
#erros ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/nfcom/models/emitente.rb', line 94 def erros errors = [] errors << 'CNPJ é obrigatório' if cnpj.to_s.strip.empty? errors << 'CNPJ inválido' unless cnpj_valido?(cnpj) errors << 'Razão social é obrigatória' if .to_s.strip.empty? errors << 'Inscrição estadual é obrigatória' if inscricao_estadual.to_s.strip.empty? errors.concat(endereco.erros.map { |e| "Endereço: #{e}" }) unless endereco.valido? errors end |
#regime_tributario_codigo ⇒ Integer
Retorna o código do regime tributário para o XML
86 87 88 |
# File 'lib/nfcom/models/emitente.rb', line 86 def regime_tributario_codigo REGIME_TRIBUTARIO[regime_tributario] || REGIME_TRIBUTARIO[:normal] end |
#valido? ⇒ Boolean
90 91 92 |
# File 'lib/nfcom/models/emitente.rb', line 90 def valido? erros.empty? end |