ruby_danfe 1.13.2 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,11 @@
1
1
  # encoding:utf-8
2
+ require 'digest/sha1'
2
3
 
3
4
  module RubyDanfe
4
5
  class DanfeNfceGenerator
5
6
  def initialize(xml)
6
7
  @xml = xml
7
- @pdf = Document.new
8
+ @pdf = Document.new(page_size: [390, 845])
8
9
  end
9
10
 
10
11
  def generatePDF
@@ -34,7 +35,7 @@ module RubyDanfe
34
35
  @pdf.ibox 2.85, 3, 1.5, 2, "", "NFC-e", {:size => 12, :align => :center, :border => 0, :style => :bold}
35
36
 
36
37
  @pdf.ibox 4.92, 7, 4, 0, '',
37
- @xml['emit/xNome'] + "\n" +
38
+ @xml['emit/xNome'] + "\n" +
38
39
  "CNPJ: " + @xml['emit/CNPJ'] + "\n" +
39
40
  @xml['enderEmit/xLgr'] + ", " + @xml['enderEmit/nro'] + "\n" +
40
41
  @xml['enderEmit/xBairro']+ " " + "-" + " " + @xml['enderEmit/xMun'] + "/" + @xml['enderEmit/UF'] + "\n" +
@@ -42,22 +43,22 @@ module RubyDanfe
42
43
  "CEP: " + @xml['enderEmit/CEP'] + " - " + "IE: " + @xml['emit/IE'], {:align => :center, :valign => :center, size: 8, border: 0}
43
44
  end
44
45
 
45
- def render_info_fixas
46
+ def render_info_fixas
46
47
  @pdf.ibox 2, 12, 0.9, 4, '',
47
- "DANFE NFC-e - Documento Auxiliar da Nota Fiscal Eletrônica" + "\n" + "para Consumidor Final" + "\n \n" +
48
+ "DANFE NFC-e - Documento Auxiliar da Nota Fiscal Eletrônica" + "\n" + "para Consumidor Final" + "\n \n" +
48
49
  "Não permite aproveitamento de crédito de ICMS", {align: :center, :valign => :center, size: 8}
49
50
  end
50
51
 
51
- def render_detalhes_venda
52
+ def render_detalhes_venda
52
53
  render_cabecalho_dos_produtos
53
-
54
+
54
55
  totais = @xml.css('total')
55
-
56
+
56
57
  @pdf.inumeric 0.70, 4, 0.9, 15.8, "Subtotal", totais.css('vProd').text, {:size => 6}
57
58
  @pdf.inumeric 0.70, 4, 4.9, 15.8, "Desconto", totais.css('vDesc').text, {:size => 6}
58
59
  @pdf.inumeric 0.70, 4, 8.9, 15.8, "Troco", totais.css('vTroco').text, {:size => 6}
59
- end
60
-
60
+ end
61
+
61
62
  def render_cabecalho_dos_produtos
62
63
  @pdf.ibox 9.55, 1.3, 0.9, 6.1, "CÓDIGO", "",{:size => 8, :align => :center, :style => :bold}
63
64
  @pdf.ibox 9.55, 1.3, 2.2, 6.1, "UNIDADE"
@@ -108,7 +109,7 @@ module RubyDanfe
108
109
  return row
109
110
  end
110
111
 
111
- def render_totais
112
+ def render_totais
112
113
  qtde_produtos = @xml.css('det').count
113
114
  forma_pgto = get_forma_pgto
114
115
  valor_total = Helper.numerify(@xml.css('total').css('vProd').text)
@@ -120,7 +121,7 @@ module RubyDanfe
120
121
 
121
122
  def get_forma_pgto
122
123
  cod_forma_pgto = @xml.css('tPag').text
123
- case cod_forma_pgto
124
+ case cod_forma_pgto
124
125
  when "01" then "Dinheiro"
125
126
  when "02" then "Cheque"
126
127
  when "03" then "Cartão de Crédito"
@@ -143,7 +144,7 @@ module RubyDanfe
143
144
  "Informação dos Tributos Totais Incidentes (Lei Federal 12.741 /2012): #{soma_tributos}", {align: :center, :valign => :center, size: 7}
144
145
  end
145
146
 
146
- def render_mensagem_fiscal
147
+ def render_mensagem_fiscal
147
148
  numero_nota = @xml.css('nNF').text
148
149
  serie = @xml.css('serie').text
149
150
  data = @xml.css('dhEmi').text
@@ -158,30 +159,38 @@ module RubyDanfe
158
159
  end
159
160
 
160
161
  @pdf.ibox 3, 12, 0.9, 18.9, 'Mensagem Fiscal',
161
- "#{cabecalho}" +
162
- "Número #{numero_nota} | Série #{serie} | Emissão #{data_emissao} - Via Consumidor" +
163
- "\n \n" + "Consulte pela Chave de Acesso em sistemas.sefaz.am.gov.br/nfceweb/formConsulta.do" +
162
+ "#{cabecalho}" +
163
+ "Número #{numero_nota} | Série #{serie} | Emissão #{data_emissao} - Via Consumidor" +
164
+ "\n \n" + "Consulte pela Chave de Acesso em #{get_url_consulta}" +
164
165
  "\n \n" + "CHAVE DE ACESSO:" +
165
- "\n \n" + chave_acesso + "\n", {align: :center, :valign => :center, size: 7}
166
+ "\n \n" + chave_acesso + "\n", {align: :center, :valign => :center, size: 7}
166
167
  end
167
168
 
168
169
  def get_chave
169
- chave = @xml.css('infNFe').attr("Id").value.gsub(/^(NFe|CTe)/, "")
170
+ chave = @xml.css('infNFe').attr("Id").value.gsub(/^(NFe|CTe)/, "")
170
171
  return "%s %s %s %s %s %s %s %s %s %s %s" %[chave[0..3], chave[4..7], chave[8..11], chave[12..15], chave[16..19], chave[20..23], chave[24..27], chave[28..31], chave[32..35], chave[36..39], chave[40..43]]
171
172
  end
172
173
 
173
- def render_consumidor
174
+ def render_consumidor
174
175
  consumidor = @xml.xpath("//dest")
175
- cpf = @xml.regex_string(consumidor.to_s.downcase, "//cpf").text
176
176
  nome = @xml.regex_string(consumidor.to_s.downcase, "//xnome").text.split.map(&:capitalize).join(' ')
177
-
177
+
178
178
  endereco = @xml.regex_string(consumidor.to_s.downcase, "//xlgr").text + " - " + @xml.regex_string(consumidor.to_s.downcase, "//xbairro").text
179
- endereco += " - " + @xml.regex_string(consumidor.to_s.downcase, "//xmun").text + " - " + @xml.regex_string(consumidor.to_s.downcase, "//uf").text
179
+ endereco += " - " + @xml.regex_string(consumidor.to_s.downcase, "//xmun").text + " - " + @xml.regex_string(consumidor.to_s.downcase, "//uf").text.downcase
180
180
  endereco = endereco.split.map(&:capitalize).join(' ')
181
+ endereco = endereco.upcase
181
182
 
182
183
  if consumidor.any?
183
- consumidor_msg = cpf.empty? ? "" : "CNPJ/CPF/ID Estrangeiro - #{cpf} - "
184
- consumidor_msg += nome
184
+ documento = @xml.css('dest idEstrangeiro, dest CPF, dest CNPJ').text
185
+ tipo_documento, documento =
186
+ case documento.length
187
+ when 11 then ["CPF", "%s.%s.%s-%s" % documento.match(/(...)(...)(...)(..)/).captures]
188
+ when 14 then ["CNPJ", "%s.%s.%s/%s-%s" % documento.match(/(..)(...)(...)(....)(..)/).captures]
189
+ else ["ID Estrangeiro", documento]
190
+ end
191
+
192
+ consumidor_msg = nome
193
+ consumidor_msg += " - #{tipo_documento}: #{documento}"
185
194
  consumidor_msg += "\n" + endereco
186
195
  else
187
196
  consumidor_msg = "CONSUMIDOR NÃO IDENTIFICADO"
@@ -191,15 +200,16 @@ module RubyDanfe
191
200
  consumidor_msg, {align: :center, :valign => :top, size: 7}
192
201
  end
193
202
 
194
- def render_qrcode
195
- @pdf.ibox 0.7, 12, 0.9, 23.3, '', ''
196
- #@pdf.iqrcode 1.7, 8.2, 6.5, 25, get_qrcode_url
203
+ def render_qrcode
204
+ @pdf.iqrcode 5.18, 28, get_qrcode_url, 20
197
205
 
198
206
  data = @xml.css('dhRecbto').text
199
207
  data_receb = Date.parse(data).strftime('%d/%m/%Y %I:%M:%S')
200
208
 
201
209
  protocolo = @xml.css('nProt').text
202
- @pdf.draw_text "\n" + "Protocolo de Autorização: #{protocolo} - Data: #{data_receb}", at: [100, 140], :size => 6
210
+ msg_protocolo = "Protocolo de Autorização: #{protocolo} - Data: #{data_receb}"
211
+
212
+ @pdf.ibox 0.7, 12, 0.9, 23.3, '', msg_protocolo, size: 6, align: :center, valign: :center
203
213
  end
204
214
 
205
215
  def get_qrcode_url
@@ -207,30 +217,59 @@ module RubyDanfe
207
217
  end
208
218
 
209
219
  def get_ender_consulta
210
- tipo_ambiente = @xml.css('tpAmb')
211
- uf = @xml.css('emit').css('UF').text.upcase
212
- url = ""
213
-
214
- if tipo_ambiente == "2" # HOMOLOGAÇÃO
215
- case uf
216
- when "AC" then return "http://www.sefaznet.ac.gov.br/nfe/NFe.jsp?opc=3"
217
- when "AM" then return "http://sistemas.sefaz.am.gov.br/nfceweb/consultarNFCe.jsp?"
218
- when "MA" then return "http://www.nfce.sefaz.ma.gov.br/portal/consultarNFCe.jsp"
219
- when "MT" then return "http://www.sefaz.mt.gov.br/nfe/portal/consultanfce"
220
- when "RN" then return "http://www.nfe.rn.gov.br/portal/consultarNFCe.jsp?"
221
- when "RS" then return "https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx"
222
- when "SE" then return "http://www.nfe.se.gov.br/portal/consultarNFCe.jsp?"
223
- end
224
- else # PRODUÇÃO
225
- case uf
226
- when "AC" then return "http://hml.sefaznet.ac.gov.br"
227
- when "AM" then return "http://homnfe.sefaz.am.gov.br/nfceweb/consultarNFCe.jsp?"
228
- when "MA" then return "http://www.hom.nfce.sefaz.ma.gov.br/portal/consultarNFCe.jsp"
229
- when "MT" then return "http://www.hom.nfe.sefaz.mt.gov.br/portal/consultarNFCe.jsp"
230
- when "RN" then return "http://www.hom.nfe.rn.gov.br/portal/consultarNFCe.jsp?"
231
- when "RS" then return "https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx"
232
- when "SE" then return "http://www.hom.nfe.se.gov.br/portal/consultarNFCe.jsp?"
233
- end
220
+ url = get_url_qr_code
221
+
222
+ params = {
223
+ "chNFe" => get_chave.gsub(/ /, ""),
224
+ "nVersao" => @xml.css('nfeProc').attr("versao"),
225
+ "tpAmb" => @xml['ide/tpAmb'],
226
+ "dhEmi" => str_to_hex(@xml['ide/dhEmi']),
227
+ "vNF" => @xml['ICMSTot/vNF'],
228
+ "vICMS" => @xml['ICMSTot/vICMS'],
229
+ "digVal" => str_to_hex(@xml['nfe/DigestValue']),
230
+ "cIdToken" => '000001',
231
+ }
232
+
233
+ unless @xml.css('dest').empty?
234
+ params["cDest"] = @xml.css('dest idEstrangeiro, dest CPF, dest CNPJ').text
235
+ end
236
+
237
+ params_string = params.to_a.map{|p| p.join("=")}.join("&")
238
+
239
+ hash_token = Digest::SHA1.base64digest params_string
240
+
241
+ url + params_string + "&cHashQRCode=" + hash_token
242
+ end
243
+
244
+ def get_url_qr_code
245
+ case @xml.css('emit').css('UF').text.upcase
246
+ when "AC" then "http://www.sefaznet.ac.gov.br/nfe/NFe.jsp?opc=3"
247
+ when "AM" then "http://sistemas.sefaz.am.gov.br/nfceweb/consultarNFCe.jsp?"
248
+ when "MA" then "http://www.nfce.sefaz.ma.gov.br/portal/consultarNFCe.jsp?"
249
+ when "MT" then "http://www.sefaz.mt.gov.br/nfe/portal/consultanfce?"
250
+ when "RN" then "http://www.nfe.rn.gov.br/portal/consultarNFCe.jsp?"
251
+ when "RO" then "http://www.nfce.sefin.ro.gov.br/consultanfce/consulta.jsp?"
252
+ when "RS" then "https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx?"
253
+ when "SE" then "http://www.nfe.se.gov.br/portal/consultarNFCe.jsp?"
254
+ end
255
+ end
256
+
257
+ def get_url_consulta
258
+ case @xml.css('emit').css('UF').text.upcase
259
+ when "AC" then "http://www.sefaznet.ac.gov.br/nfe/NFe.jsp?opc=3"
260
+ when "AM" then "http://sistemas.sefaz.am.gov.br/nfceweb/consultarNFCe.jsp"
261
+ when "MA" then "http://www.nfce.sefaz.ma.gov.br/portal/consultarNFCe.jsp"
262
+ when "MT" then "http://www.sefaz.mt.gov.br/nfe/portal/consultanfce"
263
+ when "RN" then "http://www.nfe.rn.gov.br/portal/consultarNFCe.jsp"
264
+ when "RO" then "http://www.nfce.sefin.ro.gov.br"
265
+ when "RS" then "https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx"
266
+ when "SE" then "http://www.nfe.se.gov.br/portal/consultarNFCe.jsp"
267
+ end
268
+ end
269
+
270
+ def str_to_hex str
271
+ str.split("").reduce("") do |str, char|
272
+ str + char.ord.to_s(16)
234
273
  end
235
274
  end
236
275
  end
@@ -0,0 +1,102 @@
1
+ # coding: utf-8
2
+ module RubyDanfe
3
+ class DanfseGenerator
4
+ def initialize(xml)
5
+ @xml = xml
6
+ @pdf = Document.new
7
+ @vol = 0
8
+ end
9
+
10
+ attr_reader :municipios
11
+
12
+ def municipios
13
+ lib_path = File.expand_path("../../", __FILE__)
14
+ @municipios ||= JSON.parse(File.read(File.join(lib_path, 'municipios.json')))
15
+ end
16
+
17
+ def generatePDF
18
+ render_titulo
19
+ render_prestador
20
+ render_tomador
21
+ render_intermediario
22
+ render_discriminacao
23
+ render_valor_total
24
+ render_outras
25
+ @pdf
26
+ end
27
+
28
+ private
29
+ def render_titulo
30
+ @pdf.ibox 2.55, 16.10, 0.25, 0.42, '',
31
+ "PREFEITURA DO MUNICÍPIO DE #{municipios[@xml['InfNfse/PrestadorServico/Endereco/CodigoMunicipio']].upcase} \n" +
32
+ "Secretaria Municipal da Fazenda \n" +
33
+ "NOTA FISCAL ELETRÔNICA DE SERVIÇOS - NFS-e \n" +
34
+ "RPS n° #{@xml['IdentificacaoRps/Numero']}, emitido em #{@xml['DataEmissaoRps']}", {:align => :center, :valign => :center}
35
+
36
+ @pdf.ibox 0.85, 4.47, 16.35, 0.42, "NÚMERO DA NOTA", "#{@xml['InfNfse/Numero'].rjust(8,'0')}"
37
+ @pdf.ibox 0.85, 4.47, 16.35, 1.27, "DATA E HORA DE EMISSÃO", "#{@xml['InfNfse/DataEmissao'].gsub('T', ' ')}"
38
+ @pdf.ibox 0.85, 4.47, 16.35, 2.12, "CÓDIGO DE VERIFICAÇÃO", "#{@xml['CodigoVerificacao']}"
39
+ end
40
+
41
+ def render_prestador
42
+ @pdf.ibox 4.25, 20.57, 0.25, 2.97
43
+ @pdf.ibox 0.85, 20.57, 0.25, 2.97, '', 'PRESTADOR DE SERVIÇOS', {border: 0, style: :bold,:align => :center, :valign => :center}
44
+ @pdf.ibox 0.85, 20.57, 0.25, 3.82, "Nome/Razão Social", "#{@xml['PrestadorServico/RazaoSocial']}", {border: 0}
45
+ @pdf.ibox 0.85, 12, 0.25, 4.67, "CPF/CNPJ", "#{@xml['PrestadorServico/IdentificacaoPrestador/Cnpj'] || @xml['PrestadorServico/IdentificacaoPrestador/Cpf']}", {border: 0}
46
+ @pdf.ibox 0.85, 4.47, 12, 4.67, "Inscrição Municipal", "#{@xml['IdentificacaoPrestador/InscricaoMunicipal']}", {border: 0}
47
+ @pdf.ibox 0.85, 20.57, 0.25, 5.52, "Endereço", "#{@xml['PrestadorServico/Endereco/Endereco']}", {border: 0}
48
+ @pdf.ibox 0.85, 10, 0.25, 6.37, "Município", "#{municipios[@xml['PrestadorServico/Endereco/CodigoMunicipio']]}", {border: 0}
49
+ @pdf.ibox 0.85, 4.47, 10, 6.37, "UF", "#{@xml['PrestadorServico/Endereco/Uf']}", {border: 0}
50
+ @pdf.ibox 0.85, 4.47, 15, 6.37, "E-mail", "#{@xml['PrestadorServico/Contato/Email']}", {border: 0}
51
+ end
52
+
53
+ def render_tomador
54
+ @pdf.ibox 4.25, 20.57, 0.25, 7.22
55
+ @pdf.ibox 0.85, 20.57, 0.25, 7.22, '', 'TOMADOR DE SERVIÇOS', {border: 0, style: :bold,:align => :center, :valign => :center}
56
+ @pdf.ibox 0.85, 20.57, 0.25, 8.07, "Nome/Razão Social", "#{@xml['TomadorServico/RazaoSocial']}", {border: 0}
57
+ @pdf.ibox 0.85, 12, 0.25, 8.92, "CPF/CNPJ", "#{@xml['TomadorServico/IdentificacaoTomador/CpfCnpj/Cnpj'] || @xml['TomadorServico/IdentificacaoTomador/CpfCnpj/Cpf']}", {border: 0}
58
+ @pdf.ibox 0.85, 4.47, 12, 8.92, "Inscrição Municipal", "#{@xml['IdentificacaoTomador/InscricaoMunicipal']}", {border: 0}
59
+ @pdf.ibox 0.85, 20.57, 0.25, 9.77, "Endereço", "#{@xml['TomadorServico/Endereco/Endereco']}", {border: 0}
60
+ @pdf.ibox 0.85, 10, 0.25, 10.62, "Município", "#{municipios[@xml['TomadorServico/Endereco/CodigoMunicipio']]}", {border: 0}
61
+ @pdf.ibox 0.85, 4.47, 10, 10.62, "UF", "#{@xml['TomadorServico/Endereco/Uf']}", {border: 0}
62
+ @pdf.ibox 0.85, 4.47, 15, 10.62, "E-mail", "#{@xml['TomadorServico/Contato/Email']}", {border: 0}
63
+ end
64
+
65
+ def render_intermediario
66
+ @pdf.ibox 1.70, 20.57, 0.25, 11.47
67
+ @pdf.ibox 0.85, 20.57, 0.25, 11.47, '', 'INTERMEDIÁRIO DE SERVIÇOS', {border: 0, style: :bold,:align => :center, :valign => :center}
68
+ @pdf.ibox 0.85, 12, 0.25, 12.32, "Nome/Razão Social", "#{@xml['IdentificacaoIntermediarioServico/RazaoSocial']}", {border: 0}
69
+ @pdf.ibox 0.85, 8, 12.25, 12.32, "CPF/CNPJ", "#{@xml['IdentificacaoIntermediarioServico/CpfCnpj/Cnpj'] || @xml['IdentificacaoIntermediarioServico/CpfCnpj/Cpf']}", {border: 0}
70
+ end
71
+
72
+ def render_discriminacao
73
+ @pdf.ibox 9.35, 20.57, 0.25, 13.17
74
+ @pdf.ibox 0.85, 20.57, 0.25, 13.17, '', 'DISCRIMINAÇÃO DOS SERVIÇOS', {border: 0, style: :bold,:align => :center, :valign => :center}
75
+ @pdf.ibox 8, 19.57, 0.75, 14.02, "", "#{@xml['Servico/Discriminacao']}", {border: 0}
76
+ end
77
+
78
+ def render_valor_total
79
+ @pdf.ibox 1.70, 20.57, 0.25, 22.52
80
+ @pdf.ibox 0.85, 20.57, 0.25, 22.52, '', "VALOR TOTAL DO SERVIÇO = R$#{Helper.numerify(@xml['Servico/Valores/ValorServicos'])}", {border: 0, style: :bold,:align => :center, :valign => :center}
81
+ @pdf.inumeric 0.85, 4.06, 0.25, 23.37, "INSS", @xml['Servico/Valores/ValorInss']
82
+ @pdf.inumeric 0.85, 4.06, 4.31, 23.37, "IRRF", @xml['Servico/Valores/ValorIr']
83
+ @pdf.inumeric 0.85, 4.06, 8.37, 23.37, "CSLL", @xml['Servico/Valores/ValorCsll']
84
+ @pdf.inumeric 0.85, 4.06, 12.43, 23.37, "COFINS", @xml['Servico/Valores/ValorCofins']
85
+ @pdf.inumeric 0.85, 4.32, 16.49, 23.37, "PIS/PASEP", @xml['Servico/Valores/ValorPis']
86
+ @pdf.ibox 0.85, 20.57, 0.25, 24.22, "Código do Serviço", @xml['Servico/CodigoTributacaoMunicipio']
87
+ @pdf.inumeric 0.85, 3.46, 0.25, 25.07, "Valor Total das Deduções", @xml['Servico/Valores/ValorDeducoes']
88
+ @pdf.inumeric 0.85, 3.46, 3.71, 25.07 , "Base de Cálculo", @xml['Servico/Valores/BaseCalculo']
89
+ @pdf.ibox 0.85, 3.46, 7.17, 25.07, "Alíquota", @xml['Servico/Valores/Aliquota']
90
+ @pdf.inumeric 0.85, 3.46, 10.63, 25.07, "Valor do ISS", @xml['Servico/Valores/ValorIss']
91
+ @pdf.inumeric 0.85, 6.73, 14.09, 25.07, "Crédito", @xml['InfNfse/ValorCredito']
92
+ @pdf.ibox 0.85, 10.38, 0.25, 25.92, "Muncípio da Prestação do Serviço", municipios[@xml['OrgaoGerador/CodigoMunicipio']], :style => :bold
93
+ @pdf.ibox 0.85, 10.19, 10.63, 25.92, "Número Inscrição da Obra", @xml['DadosConstrucaoCivil/CodigoObra'], :style => :bold
94
+ end
95
+
96
+ def render_outras
97
+ @pdf.ibox 2.55, 20.57, 0.25, 26.77
98
+ @pdf.ibox 0.85, 20.57, 0.25, 26.77, '', 'OUTRAS INFORMAÇÕES', {border: 0, style: :bold,:align => :center, :valign => :center}
99
+ @pdf.ibox 1.70, 19.57, 0.75, 27.62, "", "#{@xml['InfNfse/OutrasInformacoes']}", {border: 0}
100
+ end
101
+ end
102
+ end
@@ -40,5 +40,6 @@ module RubyDanfe
40
40
  def self.need_st(det)
41
41
  det.css('ICMS/*/vBCST').text.to_i > 0
42
42
  end
43
+
43
44
  end
44
45
  end
@@ -1,14 +1,16 @@
1
1
  module RubyDanfe
2
2
  class Document
3
- def initialize
4
- @document = Prawn::Document.new(
3
+ def initialize(opts = {})
4
+ default_opts = {
5
5
  :page_size => 'A4',
6
6
  :page_layout => :portrait,
7
7
  :left_margin => 0,
8
8
  :right_margin => 0,
9
9
  :top_margin => 0,
10
10
  :botton_margin => 0
11
- )
11
+ }
12
+
13
+ @document = Prawn::Document.new(default_opts.merge(opts))
12
14
 
13
15
  @document.font "Times-Roman"
14
16
  end
@@ -26,11 +28,12 @@ module RubyDanfe
26
28
  end
27
29
 
28
30
  def ibarcode(h, w, x, y, info)
31
+ info = info.gsub(/\D/, '')
29
32
  Barby::Code128C.new(info).annotate_pdf(self, :x => x.cm, :y => Helper.invert(y.cm), :width => w.cm, :height => h.cm) if info != ''
30
33
  end
31
34
 
32
- def iqrcode(h, w, x, y, info)
33
- Barby::QrCode.new(info, :level => :q).annotate_pdf(self, :x => x.cm, :y => Helper.invert(y.cm), :width => w.cm, :height => h.cm) if info != ''
35
+ def iqrcode(x, y, info, size = nil)
36
+ Barby::QrCode.new(info, :level => :q, :size => size).annotate_pdf(self, :x => x.cm, :y => Helper.invert(y.cm)) if info != ''
34
37
  end
35
38
 
36
39
  def irectangle(h, w, x, y)
@@ -10,6 +10,16 @@ module RubyDanfe
10
10
  number
11
11
  end
12
12
 
13
+ def self.numerify_default_zero(number, decimals = 2)
14
+ number = number.tr("\n","").delete(" ")
15
+ return "0,00" if !number || number == ""
16
+ int, frac = ("%.#{decimals}f" % number).split(".")
17
+ int.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1\.")
18
+ int + "," + frac
19
+ rescue
20
+ number
21
+ end
22
+
13
23
  def self.invert(y)
14
24
  28.7.cm - y
15
25
  end
@@ -1,11 +1,16 @@
1
1
  require "prawn"
2
+ require "prawn/table"
2
3
  require "prawn/measurement_extensions"
3
4
  require "barby"
4
5
  require "barby/barcode/code_128"
6
+ require 'barby/barcode/qr_code'
5
7
  require "barby/outputter/prawn_outputter"
6
8
  require "nokogiri"
7
9
  require 'ostruct'
8
10
  require 'yaml'
11
+ require 'date'
12
+ require 'time'
13
+ require 'json'
9
14
 
10
15
  require_relative '../ruby_danfe.rb'
11
16
  require_relative 'options.rb'
@@ -14,7 +19,10 @@ require_relative 'cst.rb'
14
19
  require_relative 'document.rb'
15
20
  require_relative 'version.rb'
16
21
  require_relative 'dacte_generator.rb'
22
+ require_relative 'dacteos_generator.rb'
17
23
  require_relative 'danfe_generator.rb'
24
+ require_relative 'danfse_generator.rb'
25
+ require_relative 'danfe_nfce_generator.rb'
18
26
  require_relative 'xml.rb'
19
27
  require_relative 'descricao.rb'
20
28
  require_relative 'ruby_danfe.rb'
@@ -35,15 +35,15 @@ module RubyDanfe
35
35
 
36
36
  xml = XML.new(xml_string)
37
37
 
38
- if type == :danfe
39
- generator = DanfeGenerator.new(xml)
40
- elsif type == :danfe_nfce
41
- generator = DanfeNfceGenerator.new(xml)
42
- else
43
- generator = DacteGenerator.new(xml)
44
- end
45
-
46
- pdf = generator.generatePDF
47
- pdf
38
+ generator =
39
+ case type
40
+ when :danfe then DanfeGenerator.new(xml)
41
+ when :danfe_nfce then DanfeNfceGenerator.new(xml)
42
+ when :dacte then DacteGenerator.new(xml)
43
+ when :danfse then DanfseGenerator.new(xml)
44
+ when :dacteos then DacteosGenerator.new(xml)
45
+ else raise "unknown type #{type}"
46
+ end
47
+ generator.generatePDF
48
48
  end
49
49
  end