Class: Nfe400

Inherits:
Object
  • Object
show all
Defined in:
lib/mock_dfe/dfes/nfe_400.rb

Overview

template for NFe 4.00

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNfe400

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

#AAMMObject (readonly)

Returns the value of attribute AAMM.



3
4
5
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3

def AAMM
  @AAMM
end

#cDVObject (readonly)

Returns the value of attribute cDV.



3
4
5
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3

def cDV
  @cDV
end

#chaveObject (readonly)

Returns the value of attribute chave.



3
4
5
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3

def chave
  @chave
end

#cNFObject (readonly)

Returns the value of attribute cNF.



3
4
5
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3

def cNF
  @cNF
end

#CNPJObject (readonly)

Returns the value of attribute CNPJ.



3
4
5
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3

def CNPJ
  @CNPJ
end

#cUFObject (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_dateObject (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

#modObject (readonly)

Returns the value of attribute mod.



3
4
5
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3

def mod
  @mod
end

#nNFObject (readonly)

Returns the value of attribute nNF.



3
4
5
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3

def nNF
  @nNF
end

#serieObject (readonly)

Returns the value of attribute serie.



3
4
5
# File 'lib/mock_dfe/dfes/nfe_400.rb', line 3

def serie
  @serie
end

#tpEmisObject (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