Class: Nfe400
- Inherits:
-
Object
- Object
- Nfe400
- Defined in:
- lib/mock_dfe/dfes/nfe_400.rb
Overview
template for NFe 4.00
Instance Attribute Summary collapse
-
#AAMM ⇒ Object
readonly
Returns the value of attribute AAMM.
-
#cDV ⇒ Object
readonly
Returns the value of attribute cDV.
-
#chave ⇒ Object
readonly
Returns the value of attribute chave.
-
#cNF ⇒ Object
readonly
Returns the value of attribute cNF.
-
#CNPJ ⇒ Object
readonly
Returns the value of attribute CNPJ.
-
#cUF ⇒ Object
readonly
Returns the value of attribute cUF.
-
#emit_date ⇒ Object
readonly
Returns the value of attribute emit_date.
-
#mod ⇒ Object
readonly
Returns the value of attribute mod.
-
#nNF ⇒ Object
readonly
Returns the value of attribute nNF.
-
#serie ⇒ Object
readonly
Returns the value of attribute serie.
-
#tpEmis ⇒ Object
readonly
Returns the value of attribute tpEmis.
Instance Method Summary collapse
- #calculate_cdv(chave) ⇒ Object
-
#initialize ⇒ Nfe400
constructor
A new instance of Nfe400.
Constructor Details
#initialize ⇒ Nfe400
Returns a new instance of Nfe400.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 5 def initialize @emit_date = DateTime.parse(Faker::Date.backward(1825).to_s) @cUF = COD_DA_UF.values.sample @AAMM = @emit_date.strftime('%y%m') @CNPJ = CNPJ.generate @mod = '55' @serie = '002' @nNF = Faker::Number.between(1, 999_999_999).to_s.rjust(9, '0') @tpEmis = '1' @cNF = Faker::Number.number(8) chave_sem_cdv = "#{@cUF}#{@AAMM}#{@CNPJ}#{@mod}#{@serie}#{@nNF}#{@tpEmis}#{@cNF}" @cDV = calculate_cdv(chave_sem_cdv) @chave = "#{chave_sem_cdv}#{@cDV}" end |
Instance Attribute Details
#AAMM ⇒ Object (readonly)
Returns the value of attribute AAMM.
3 4 5 |
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3 def AAMM @AAMM end |
#cDV ⇒ Object (readonly)
Returns the value of attribute cDV.
3 4 5 |
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3 def cDV @cDV end |
#chave ⇒ Object (readonly)
Returns the value of attribute chave.
3 4 5 |
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3 def chave @chave end |
#cNF ⇒ Object (readonly)
Returns the value of attribute cNF.
3 4 5 |
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3 def cNF @cNF end |
#CNPJ ⇒ Object (readonly)
Returns the value of attribute CNPJ.
3 4 5 |
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3 def CNPJ @CNPJ end |
#cUF ⇒ Object (readonly)
Returns the value of attribute cUF.
3 4 5 |
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3 def cUF @cUF end |
#emit_date ⇒ Object (readonly)
Returns the value of attribute emit_date.
3 4 5 |
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3 def emit_date @emit_date end |
#mod ⇒ Object (readonly)
Returns the value of attribute mod.
3 4 5 |
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3 def mod @mod end |
#nNF ⇒ Object (readonly)
Returns the value of attribute nNF.
3 4 5 |
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3 def nNF @nNF end |
#serie ⇒ Object (readonly)
Returns the value of attribute serie.
3 4 5 |
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3 def serie @serie end |
#tpEmis ⇒ Object (readonly)
Returns the value of attribute tpEmis.
3 4 5 |
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3 def tpEmis @tpEmis end |
Instance Method Details
#calculate_cdv(chave) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 20 def calculate_cdv(chave) soma = 0 multiplicador = 2 [*0..42].reverse_each do |i| soma += (chave[i].to_i * multiplicador) multiplicador += 1 multiplicador = 2 if multiplicador > 9 end resto = soma % 11 digito_verificador = 11 - resto digito_verificador = 0 if digito_verificador >= 10 digito_verificador end |