br_danfe 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bfdad1f5eba72650cb7f3502c4d255378cacf217
4
- data.tar.gz: 1652da945d3f4eca2f6f03dd7b3ef53ebef14aa1
3
+ metadata.gz: 8820182a8bbc65175a5bcf053e329a3583edd374
4
+ data.tar.gz: e2248c10394096c63619505c8eacb2f65d4f3cef
5
5
  SHA512:
6
- metadata.gz: 91a9a8b20bac8d845542f37412512d57b7ea924ef1a597630336c2677eca5ca9e198a2589f4704f3b13b1fc912caa35ba76e21b3fe032a5acbecf4bd42a23c6b
7
- data.tar.gz: f6d94fb7f01dfaa286651136c5a4c6bfda71606f6e54c91a2a3c6929bfcd210b36dddb978a7b1079047e6d50434bd16f5b11d53e52aed13927892cae2b252ef1
6
+ metadata.gz: 38ba94bcf2d4b47664f3be6d5f0f00aa58b3c47b12cfb57a547a4e39bb36ca74555fc7bc0471bf5f4eba4e84d5590a836aa06cc1751a4f11f61137cdbbd4bf0a
7
+ data.tar.gz: 5e77bfccdf34f992a5e775269318cf40ad9c5e7c34578905b8f561cab9170586e248b5f8da89b713507dfafcdf06f02c0f9ec21677e258d45e4a2c20a7b67fb9
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  This gem generates PDF files for Brazilian DANFE (_Documento Auxiliar da Nota Fiscal Eletrônica_) from a valid NF-e XML.
6
6
 
7
+ [See an example here.](https://github.com/asseinfo/br_danfe/blob/master/spec/fixtures/v2.00/nfe_with_logo.xml.fixture.pdf?raw=true)
8
+
7
9
  This gem requires `ruby >= 1.9.x`.
8
10
 
9
11
  ## Supported NF-e versions
@@ -9,8 +9,8 @@ pt-BR:
9
9
  sefaz: "Consulta de autenticidade no portal nacional da NF-e www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora"
10
10
  ide:
11
11
  dEmi: "DATA DA EMISSÃO"
12
- dSaiEnt: "DATA DA SAÍDA/ENTRADA"
13
- hSaiEnt: "HORA DE SAÍDA"
12
+ dSaiEnt: "DATA DA ENTRADA/SAÍDA"
13
+ hSaiEnt: "HORA DE ENTRADA/SAÍDA"
14
14
  tpNF:
15
15
  entry: "ENTRADA"
16
16
  departure: "SAÍDA"
@@ -119,7 +119,7 @@ pt-BR:
119
119
  pesoB: "PESO B.:"
120
120
  pesoL: "PESO LÍQ.:"
121
121
  ticket:
122
- xNome: "RECEBEMOS DE %{xNome} OS PRODUTOS CONSTANTES DA NOTA FISCAL INDICADA ABAIXO"
122
+ xNome: "RECEBEMOS DE %{xNome} OS PRODUTOS/SERVIÇOS CONSTANTES DA NOTA FISCAL INDICADA AO LADO"
123
123
  received_at: "DATA DE RECEBIMENTO"
124
124
  receiver: "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR"
125
125
  document: "NF-e\nN°. %{nNF}\nSÉRIE %{serie}"
@@ -1,4 +1,7 @@
1
1
  module BrDanfe
2
+ LINE_HEIGHT = 0.80
3
+ SPACE_BETWEEN_GROUPS = 0.52
4
+
2
5
  class Danfe
3
6
  attr_reader :options
4
7
 
@@ -55,14 +58,15 @@ module BrDanfe
55
58
 
56
59
  def repeat_on_each_page
57
60
  Ticket.render(@pdf, @xml)
58
- Emit.new(@pdf, @xml, @options.logo_path).render
61
+ EmitHeader.new(@pdf, @xml, @options.logo_path).render
62
+ Emit.new(@pdf, @xml).render
59
63
  Dest.new(@pdf, @xml).render
60
64
  Dup.new(@pdf, @xml).render
61
- Icmstot.render(@pdf, @xml)
62
- Transp.render(@pdf, @xml)
65
+ Icmstot.new(@pdf, @xml).render
66
+ Transp.new(@pdf, @xml).render
63
67
  nVol = Vol.new(@pdf, @xml).render
64
68
  DetHeader.new(@pdf, @xml).render
65
- Issqn.render(@pdf, @xml)
69
+ Issqn.new(@pdf, @xml).render
66
70
  Infadic.new(@pdf, @xml).render(nVol)
67
71
  end
68
72
  end
data/lib/br_danfe/dest.rb CHANGED
@@ -1,30 +1,38 @@
1
1
  module BrDanfe
2
2
  class Dest
3
+ Y = 8.58
4
+
3
5
  def initialize(pdf, xml)
4
6
  @pdf = pdf
5
7
  @xml = xml
8
+
9
+ @ltitle = Y - 0.42
10
+ @l1 = Y
11
+ @l2 = Y + LINE_HEIGHT
12
+ @l3 = Y + (LINE_HEIGHT * 2)
6
13
  end
7
14
 
8
15
  def render
9
- @pdf.ititle 0.42, 10.00, 0.25, 8.16, "dest.title"
16
+ @pdf.ititle 0.42, 10.00, 0.25, @ltitle, "dest.title"
10
17
 
11
18
  render_line1
12
19
  render_line2
13
20
  render_line3
21
+
22
+ render_dates_block
14
23
  end
15
24
 
16
25
  private
17
26
  def render_line1
18
- @pdf.lbox 0.85, 12.32, 0.25, 8.58, @xml, "dest/xNome"
27
+ @pdf.lbox LINE_HEIGHT, 12.32, 0.25, @l1, @xml, "dest/xNome"
19
28
  render_cnpj_cpf
20
- @pdf.idate 0.85, 2.92, 17.90, 8.58, "ide.dEmi", @xml["ide/dEmi"], { align: :right }
21
29
  end
22
30
 
23
31
  def render_cnpj_cpf
24
32
  if @xml["dest/CNPJ"] == ""
25
- @pdf.ibox 0.85, 5.33, 12.57, 8.58, I18n.t("danfe.dest.CPF"), cpf
33
+ @pdf.ibox LINE_HEIGHT, 4.87, 12.57, @l1, I18n.t("danfe.dest.CPF"), cpf
26
34
  else
27
- @pdf.ibox 0.85, 5.33, 12.57, 8.58, I18n.t("danfe.dest.CNPJ"), cnpj
35
+ @pdf.ibox LINE_HEIGHT, 4.87, 12.57, @l1, I18n.t("danfe.dest.CNPJ"), cnpj
28
36
  end
29
37
  end
30
38
 
@@ -39,14 +47,9 @@ module BrDanfe
39
47
  end
40
48
 
41
49
  def render_line2
42
- @pdf.ibox 0.85, 10.16, 0.25, 9.43, I18n.t("danfe.enderDest.xLgr"), street
43
- @pdf.lbox 0.85, 4.83, 10.41, 9.43, @xml, "enderDest/xBairro"
44
- @pdf.ibox 0.85, 2.67, 15.24, 9.43, I18n.t("danfe.enderDest.CEP"), cep
45
- if @xml.version_310?
46
- @pdf.idate 0.85, 2.92, 17.90, 9.43, "ide.dSaiEnt", @xml["ide/dhSaiEnt"], { align: :right }
47
- else
48
- @pdf.idate 0.85, 2.92, 17.90, 9.43, "ide.dSaiEnt", @xml["ide/dSaiEnt"], { align: :right }
49
- end
50
+ @pdf.ibox LINE_HEIGHT, 10.16, 0.25, @l2, I18n.t("danfe.enderDest.xLgr"), street
51
+ @pdf.lbox LINE_HEIGHT, 4.83, 10.41, @l2, @xml, "enderDest/xBairro"
52
+ @pdf.ibox LINE_HEIGHT, 2.20, 15.24, @l2, I18n.t("danfe.enderDest.CEP"), cep
50
53
  end
51
54
 
52
55
  def street
@@ -58,15 +61,25 @@ module BrDanfe
58
61
  end
59
62
 
60
63
  def render_line3
61
- @pdf.lbox 0.85, 7.11, 0.25, 10.28, @xml, "enderDest/xMun"
62
- @pdf.ibox 0.85, 4.06, 7.36, 10.28, I18n.t("danfe.enderDest.fone"), phone
63
- @pdf.lbox 0.85, 1.14, 11.42, 10.28, @xml, "enderDest/UF"
64
- @pdf.ibox 0.85, 5.33, 12.56, 10.28, I18n.t("danfe.dest.IE"), ie
64
+ @pdf.lbox LINE_HEIGHT, 7.11, 0.25, @l3, @xml, "enderDest/xMun"
65
+ @pdf.ibox LINE_HEIGHT, 4.06, 7.36, @l3, I18n.t("danfe.enderDest.fone"), phone
66
+ @pdf.lbox LINE_HEIGHT, 1.14, 11.42, @l3, @xml, "enderDest/UF"
67
+ @pdf.ibox LINE_HEIGHT, 4.88, 12.56, @l3, I18n.t("danfe.dest.IE"), ie
68
+ end
69
+
70
+ def render_dates_block
71
+ @pdf.ldate LINE_HEIGHT, 2.92, 17.90, @l1, "ide.dEmi", @xml["ide/dEmi"], { align: :right }
72
+
65
73
  if @xml.version_310?
66
- @pdf.itime 0.85, 2.92, 17.90, 10.28, "ide.hSaiEnt", @xml["ide/dhSaiEnt"], { align: :right }
74
+ dSaiEnt = @xml["ide/dhSaiEnt"]
75
+ hSaiEnt = @xml["ide/dhSaiEnt"]
67
76
  else
68
- @pdf.itime 0.85, 2.92, 17.90, 10.28, "ide.hSaiEnt", @xml["ide/hSaiEnt"], { align: :right }
77
+ dSaiEnt = @xml["ide/dSaiEnt"]
78
+ hSaiEnt = @xml["ide/hSaiEnt"]
69
79
  end
80
+
81
+ @pdf.ldate LINE_HEIGHT, 2.92, 17.90, @l2, "ide.dSaiEnt", dSaiEnt, { align: :right }
82
+ @pdf.ltime LINE_HEIGHT, 2.92, 17.90, @l3, "ide.hSaiEnt", hSaiEnt, { align: :right }
70
83
  end
71
84
 
72
85
  def phone
@@ -6,15 +6,20 @@ module BrDanfe
6
6
  end
7
7
 
8
8
  def render
9
+ options = {
10
+ column_widths: column_widths,
11
+ cell_style: { padding: 2, border_width: 0 }
12
+ }
13
+
9
14
  @pdf.font_size(6) do
10
- @pdf.itable 6.37, 21.50, 0.25, 18.17,
11
- products,
12
- column_widths: column_widths,
13
- cell_style: {padding: 2, border_width: 0} do |table|
15
+ @pdf.bounding_box [0.25.cm, Helper.invert(18.17.cm)], width: 21.50.cm, height: 6.37.cm do
16
+ @pdf.table products, options do |table|
14
17
  table.column(6..13).style(align: :right)
15
- table.column(0..13).border_width = 1
18
+ table.column(0..13).border_width = 0.3
19
+ table.column(0..13).border_lines = [:dotted]
16
20
  table.column(0..13).borders = [:bottom]
17
21
  end
22
+ end
18
23
  end
19
24
  end
20
25
 
@@ -1,12 +1,17 @@
1
1
  module BrDanfe
2
+ Y = 17.39 + SPACE_BETWEEN_GROUPS
3
+
2
4
  class DetHeader
3
5
  def initialize(pdf, xml)
4
6
  @pdf = pdf
5
7
  @xml = xml
8
+
9
+ @ltitle = Y - 0.42
10
+ @l1 = Y
6
11
  end
7
12
 
8
13
  def render
9
- @pdf.ititle 0.42, 10.00, 0.25, 17.45, "det.title"
14
+ @pdf.ititle 0.42, 10.00, 0.25, @ltitle, "det.title"
10
15
 
11
16
  column(2.00, 0.25, "prod.cProd")
12
17
  column(4.90, 2.25, "prod.xProd")
@@ -23,12 +28,12 @@ module BrDanfe
23
28
  column(0.90, 19.05, "ICMS.pICMS")
24
29
  column(0.86, 19.95, "IPI.pIPI")
25
30
 
26
- @pdf.horizontal_line 0.25.cm, 20.83.cm, at: Helper.invert(18.17.cm)
31
+ @pdf.horizontal_line 0.25.cm, 20.81.cm, at: Helper.invert(18.17.cm)
27
32
  end
28
33
 
29
34
  private
30
35
  def column(w, x, title)
31
- @pdf.ibox 6.70, w, x, 17.87, I18n.t("danfe.det.#{title}")
36
+ @pdf.ibox 6.70, w, x, @l1, I18n.t("danfe.det.#{title}")
32
37
  end
33
38
  end
34
39
  end
@@ -7,10 +7,10 @@ module BrDanfe
7
7
  left_margin: 0,
8
8
  right_margin: 0,
9
9
  top_margin: 0,
10
- botton_margin: 0
11
- )
10
+ botton_margin: 0)
12
11
 
13
12
  @document.font "Times-Roman"
13
+ @document.line_width = 0.3
14
14
  end
15
15
 
16
16
  def method_missing(method_name, *args, &block)
@@ -21,7 +21,7 @@ module BrDanfe
21
21
  title = ""
22
22
  title = I18n.t("danfe.#{i18n}") if i18n != ""
23
23
 
24
- self.text_box title, size: 10, at: [x.cm, Helper.invert(y.cm) - 2], width: w.cm, height: h.cm, style: :bold
24
+ self.text_box title, size: 8, at: [x.cm, Helper.invert(y.cm) - 4], width: w.cm, height: h.cm, style: :bold
25
25
  end
26
26
 
27
27
  def ibarcode(h, w, x, y, info)
@@ -40,22 +40,14 @@ module BrDanfe
40
40
  ibox(h, w, x, y, label, data, options)
41
41
  end
42
42
 
43
- def idate(h, w, x, y, i18n = "", info = "", options = {})
43
+ def ldate(h, w, x, y, i18n = "", info = "", options = {})
44
44
  data = BrDanfe::Helper::format_date(info)
45
-
46
- label = ""
47
- label = I18n.t("danfe.#{i18n}") if i18n != ""
48
-
49
- ibox h, w, x, y, label, data, options
45
+ i18n_lbox(h, w, x, y, i18n, data, options)
50
46
  end
51
47
 
52
- def itime(h, w, x, y, i18n = "", info = "", options = {})
48
+ def ltime(h, w, x, y, i18n = "", info = "", options = {})
53
49
  data = BrDanfe::Helper::format_time(info)
54
-
55
- label = ""
56
- label = I18n.t("danfe.#{i18n}") if i18n != ""
57
-
58
- ibox h, w, x, y, label, data, options
50
+ i18n_lbox(h, w, x, y, i18n, data, options)
59
51
  end
60
52
 
61
53
  def lnumeric(h, w, x, y, xml, xpath, options = {})
@@ -72,14 +64,6 @@ module BrDanfe
72
64
  numeric [x.cm, Helper.invert(y.cm)], w.cm, h.cm, label, data, options
73
65
  end
74
66
 
75
- def itable(h, w, x, y, data, options = {}, &block)
76
- self.bounding_box [x.cm, Helper.invert(y.cm)], width: w.cm, height: h.cm do
77
- self.table data, options do |table|
78
- yield(table)
79
- end
80
- end
81
- end
82
-
83
67
  private
84
68
  def numeric(at, w, h, title = "", info = "", options = {})
85
69
  options = {
@@ -90,6 +74,13 @@ module BrDanfe
90
74
  box at, w, h, title, info, options.merge({align: :right})
91
75
  end
92
76
 
77
+ def i18n_lbox(h, w, x, y, i18n = "", info = "", options = {})
78
+ label = ""
79
+ label = I18n.t("danfe.#{i18n}") if i18n != ""
80
+
81
+ ibox h, w, x, y, label, info, options
82
+ end
83
+
93
84
  def box(at, w, h, title = "", info = "", options = {})
94
85
  options = {
95
86
  align: :left,
@@ -106,10 +97,10 @@ module BrDanfe
106
97
  if title != ""
107
98
  title_coord = Array.new(at)
108
99
  title_coord[1] -= 2
109
- self.text_box title, size: 6, style: :italic, at: title_coord, width: w - 4, height: 8
100
+ self.text_box title, size: 6, at: title_coord, width: w - 4, height: 8
110
101
  end
111
102
 
112
- title_adjustment = title == "" ? 4 : 14
103
+ title_adjustment = title == "" ? 4 : 13
113
104
  at[1] -= title_adjustment
114
105
  self.text_box info, size: options[:size], at: at, width: w - 4, height: h - title_adjustment, align: options[:align], style: options[:style], valign: options[:valign]
115
106
  end
data/lib/br_danfe/dup.rb CHANGED
@@ -1,16 +1,20 @@
1
1
  module BrDanfe
2
2
  class Dup
3
+ Y = 11.50
4
+
3
5
  def initialize(pdf, xml)
4
6
  @pdf = pdf
5
7
  @xml = xml
8
+
9
+ @ltitle = Y - 0.42
6
10
  end
7
11
 
8
12
  def render
9
- @pdf.ititle 0.42, 10.00, 0.25, 11.12, "dup.title"
10
- @pdf.ibox 0.85, 20.57, 0.25, 11.51
13
+ @pdf.ititle 0.42, 10.00, 0.25, @ltitle, "dup.title"
14
+ @pdf.ibox 0.85, 20.57, 0.25, Y
11
15
 
12
16
  x = 0.25
13
- y = 11.51
17
+ y = Y
14
18
  @xml.collect("xmlns", "dup") do |det|
15
19
  render_dup(det, x, y)
16
20
  x += 2.30
data/lib/br_danfe/emit.rb CHANGED
@@ -1,111 +1,31 @@
1
1
  module BrDanfe
2
2
  class Emit
3
- def initialize(pdf, xml, logo_path)
3
+ Y = 6.46
4
+ L1 = Y
5
+ L2 = Y + LINE_HEIGHT
6
+
7
+ def initialize(pdf, xml)
4
8
  @pdf = pdf
5
9
  @xml = xml
6
- @logo_path = logo_path
7
10
  end
8
11
 
9
12
  def render
10
- address_box
11
- danfe_box
12
- access_key_box
13
- sefaz_box
14
- operationkind_box
15
- protocol_box
16
- ie_box
17
- ie_st_box
18
- cnpj_box
19
- end
20
-
21
- private
22
- def address_box
23
- @pdf.ibox 3.92, 8.46, 0.25, 2.54
24
-
25
- @pdf.ibox 3.92, 8.46, 0.25, 2.80, "", @xml["emit/xNome"],
26
- { size: 12, align: :center, border: 0, style: :bold }
27
-
28
- if @logo_path.empty?
29
- @pdf.ibox 3.92, 8.46, 0.75, 4, "", address, { align: :left, border: 0 }
30
- else
31
- @pdf.ibox 3.92, 8.46, 2.75, 4, "", address,
32
- { size: 8, align: :left, border: 0 }
33
-
34
- @pdf.image @logo_path, at: [0.5.cm, Helper.invert(4.cm)],
35
- width: 2.cm
36
- end
37
- end
38
-
39
- def address
40
- formatted = @xml["enderEmit/xLgr"] + ", " + @xml["enderEmit/nro"] + "\n"
41
- formatted += @xml["enderEmit/xBairro"] + " - " + cep + "\n"
42
- formatted += @xml["enderEmit/xMun"] + "/" + @xml["enderEmit/UF"] + "\n"
43
- formatted += phone + " " + @xml["enderEmit/email"]
44
-
45
- formatted
46
- end
47
-
48
- def phone
49
- Phone.format(@xml["enderEmit/fone"])
50
- end
51
-
52
- def cep
53
- Cep.format(@xml["enderEmit/CEP"])
54
- end
55
-
56
- def danfe_box
57
- @pdf.ibox 3.92, 2.08, 8.71, 2.54
58
-
59
- @pdf.ibox 0.60, 2.08, 8.71, 2.54, "", "DANFE",
60
- { size: 12, align: :center, border: 0, style: :bold }
61
-
62
- @pdf.ibox 1.20, 2.08, 8.71, 3.14, "", I18n.t("danfe.others.danfe"),
63
- { size: 8, align: :center, border: 0 }
64
-
65
- @pdf.ibox 0.60, 2.08, 8.71, 4.34, "", "#{@xml['ide/tpNF']} - " + (@xml["ide/tpNF"] == "0" ? I18n.t("danfe.ide.tpNF.entry") : I18n.t("danfe.ide.tpNF.departure")),
66
- { size: 8, align: :center, border: 0 }
67
-
68
- @pdf.ibox 1.00, 2.08, 8.71, 4.94, "",
69
- I18n.t("danfe.ide.document", nNF: @xml["ide/nNF"], serie: @xml["ide/serie"]),
70
- { size: 8, align: :center, valign: :center, border: 0, style: :bold }
71
- end
72
-
73
- def access_key_box
74
- @pdf.ibox 2.20, 10.02, 10.79, 2.54
75
- @pdf.ibarcode 1.50, 8.00, 10.9010, 4.44, @xml["chNFe"]
76
- @pdf.ibox 0.85, 10.02, 10.79, 4.74, I18n.t("danfe.chNFe"), @xml["chNFe"].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, "\\1 "),
77
- { style: :bold, align: :center }
78
- end
79
-
80
- def sefaz_box
81
- @pdf.ibox 0.85, 10.02, 10.79, 5.60 , "", I18n.t("danfe.others.sefaz"),
82
- { align: :center, size: 8 }
83
- end
84
-
85
- def operationkind_box
86
- @pdf.lbox 0.85, 10.54, 0.25, 6.46, @xml, "ide/natOp"
87
- end
88
-
89
- def protocol_box
90
- @pdf.ibox 0.85, 10.02, 10.79, 6.46, I18n.t("danfe.infProt"), @xml["infProt/nProt"] + " " + Helper.format_datetime(@xml["infProt/dhRecbto"]), { align: :center }
91
- end
92
-
93
- def ie_box
13
+ @pdf.lbox LINE_HEIGHT, 10.54, 0.25, L1, @xml, "ide/natOp"
14
+ @pdf.ibox LINE_HEIGHT, 10.02, 10.79, L1, I18n.t("danfe.infProt"), @xml["infProt/nProt"] + " " + Helper.format_datetime(@xml["infProt/dhRecbto"]), { align: :center }
94
15
  ie(0.25, "IE")
95
- end
96
-
97
- def ie_st_box
98
16
  ie(7.11, "IE_ST")
17
+ cnpj_box
99
18
  end
100
19
 
20
+ private
101
21
  def ie(x, field)
102
22
  ie = BrDocuments::IE::Factory.create(@xml["enderEmit/UF"], @xml["emit/#{field}"])
103
- @pdf.ibox 0.85, 6.86, x, 7.31, I18n.t("danfe.emit.#{field}"), ie.formatted
23
+ @pdf.ibox LINE_HEIGHT, 6.86, x, L2, I18n.t("danfe.emit.#{field}"), ie.formatted
104
24
  end
105
25
 
106
26
  def cnpj_box
107
27
  cnpj = BrDocuments::CnpjCpf::Cnpj.new(@xml["emit/CNPJ"])
108
- @pdf.ibox 0.85, 6.84, 13.97, 7.31, I18n.t("danfe.emit.CNPJ"), cnpj.formatted
28
+ @pdf.ibox LINE_HEIGHT, 6.84, 13.97, L2, I18n.t("danfe.emit.CNPJ"), cnpj.formatted
109
29
  end
110
30
  end
111
31
  end
@@ -0,0 +1,80 @@
1
+ module BrDanfe
2
+ class EmitHeader
3
+ def initialize(pdf, xml, logo_path)
4
+ @pdf = pdf
5
+ @xml = xml
6
+ @logo_path = logo_path
7
+ end
8
+
9
+ def render
10
+ address_box
11
+ danfe_box
12
+ access_key_box
13
+ sefaz_box
14
+ end
15
+
16
+ private
17
+ def address_box
18
+ @pdf.ibox 3.92, 8.46, 0.25, 2.54
19
+
20
+ @pdf.ibox 3.92, 8.46, 0.25, 2.80, "", @xml["emit/xNome"],
21
+ { size: 12, align: :center, border: 0, style: :bold }
22
+
23
+ if @logo_path.empty?
24
+ @pdf.ibox 3.92, 8.46, 0.75, 4, "", address, { align: :left, border: 0 }
25
+ else
26
+ @pdf.ibox 3.92, 8.46, 2.75, 4, "", address,
27
+ { size: 8, align: :left, border: 0 }
28
+
29
+ @pdf.image @logo_path, at: [0.5.cm, Helper.invert(4.cm)],
30
+ width: 2.cm
31
+ end
32
+ end
33
+
34
+ def address
35
+ formatted = @xml["enderEmit/xLgr"] + ", " + @xml["enderEmit/nro"] + "\n"
36
+ formatted += @xml["enderEmit/xBairro"] + " - " + cep + "\n"
37
+ formatted += @xml["enderEmit/xMun"] + "/" + @xml["enderEmit/UF"] + "\n"
38
+ formatted += phone + " " + @xml["enderEmit/email"]
39
+
40
+ formatted
41
+ end
42
+
43
+ def phone
44
+ Phone.format(@xml["enderEmit/fone"])
45
+ end
46
+
47
+ def cep
48
+ Cep.format(@xml["enderEmit/CEP"])
49
+ end
50
+
51
+ def danfe_box
52
+ @pdf.ibox 3.92, 2.08, 8.71, 2.54
53
+
54
+ @pdf.ibox 0.60, 2.08, 8.71, 2.54, "", "DANFE",
55
+ { size: 12, align: :center, border: 0, style: :bold }
56
+
57
+ @pdf.ibox 1.20, 2.08, 8.71, 3.14, "", I18n.t("danfe.others.danfe"),
58
+ { size: 8, align: :center, border: 0 }
59
+
60
+ @pdf.ibox 0.60, 2.08, 8.71, 4.34, "", "#{@xml['ide/tpNF']} - " + (@xml["ide/tpNF"] == "0" ? I18n.t("danfe.ide.tpNF.entry") : I18n.t("danfe.ide.tpNF.departure")),
61
+ { size: 8, align: :center, border: 0 }
62
+
63
+ @pdf.ibox 1.00, 2.08, 8.71, 4.94, "",
64
+ I18n.t("danfe.ide.document", nNF: @xml["ide/nNF"], serie: @xml["ide/serie"]),
65
+ { size: 8, align: :center, valign: :center, border: 0, style: :bold }
66
+ end
67
+
68
+ def access_key_box
69
+ @pdf.ibox 2.22, 10.02, 10.79, 2.54
70
+ @pdf.ibarcode 1.50, 8.00, 10.9010, 4.44, @xml["chNFe"]
71
+ @pdf.ibox 0.85, 10.02, 10.79, 4.76, I18n.t("danfe.chNFe"), @xml["chNFe"].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, "\\1 "),
72
+ { style: :bold, align: :center }
73
+ end
74
+
75
+ def sefaz_box
76
+ @pdf.ibox 0.85, 10.02, 10.79, 5.61, "", I18n.t("danfe.others.sefaz"),
77
+ { align: :center, size: 8 }
78
+ end
79
+ end
80
+ end
@@ -40,7 +40,7 @@ module BrDanfe
40
40
  formated = xml_datetime
41
41
  elsif xml_datetime.length > 8
42
42
  date = DateTime.strptime(xml_datetime, "%Y-%m-%dT%H:%M:%S %Z").to_time
43
- formated = date.getutc.strftime("%H:%M:%S")
43
+ formated = date.strftime("%H:%M:%S")
44
44
  end
45
45
 
46
46
  formated
@@ -1,19 +1,31 @@
1
1
  module BrDanfe
2
2
  class Icmstot
3
- def self.render(pdf, xml)
4
- pdf.ititle 0.42, 5.60, 0.25, 12.36, "ICMSTot.title"
3
+ Y = 12.35 + SPACE_BETWEEN_GROUPS
5
4
 
6
- pdf.lnumeric 0.85, 4.06, 0.25, 12.78, xml, "ICMSTot/vBC"
7
- pdf.lnumeric 0.85, 4.06, 4.31, 12.78, xml, "ICMSTot/vICMS"
8
- pdf.lnumeric 0.85, 4.06, 8.37, 12.78, xml, "ICMSTot/vBCST"
9
- pdf.lnumeric 0.85, 4.06, 12.43, 12.78, xml, "ICMSTot/vST"
10
- pdf.lnumeric 0.85, 4.32, 16.49, 12.78, xml, "ICMSTot/vProd"
11
- pdf.lnumeric 0.85, 3.46, 0.25, 13.63, xml, "ICMSTot/vFrete"
12
- pdf.lnumeric 0.85, 3.46, 3.71, 13.63, xml, "ICMSTot/vSeg"
13
- pdf.lnumeric 0.85, 3.46, 7.17, 13.63, xml, "ICMSTot/vDesc"
14
- pdf.lnumeric 0.85, 3.46, 10.63, 13.63, xml, "ICMSTot/vOutro"
15
- pdf.lnumeric 0.85, 3.46, 14.09, 13.63, xml, "ICMSTot/vIPI"
16
- pdf.lnumeric 0.85, 3.27, 17.55, 13.63, xml, "ICMSTot/vNF", style: :bold
5
+ def initialize(pdf, xml)
6
+ @pdf = pdf
7
+ @xml = xml
8
+
9
+ @ltitle = Y - 0.42
10
+ @l1 = Y
11
+ @l2 = Y + LINE_HEIGHT
12
+ end
13
+
14
+ def render
15
+ @pdf.ititle 0.42, 5.60, 0.25, @ltitle, "ICMSTot.title"
16
+
17
+ @pdf.lnumeric LINE_HEIGHT, 4.06, 0.25, @l1, @xml, "ICMSTot/vBC"
18
+ @pdf.lnumeric LINE_HEIGHT, 4.06, 4.31, @l1, @xml, "ICMSTot/vICMS"
19
+ @pdf.lnumeric LINE_HEIGHT, 4.06, 8.37, @l1, @xml, "ICMSTot/vBCST"
20
+ @pdf.lnumeric LINE_HEIGHT, 4.06, 12.43, @l1, @xml, "ICMSTot/vST"
21
+ @pdf.lnumeric LINE_HEIGHT, 4.32, 16.49, @l1, @xml, "ICMSTot/vProd"
22
+
23
+ @pdf.lnumeric LINE_HEIGHT, 3.05, 0.25, @l2, @xml, "ICMSTot/vFrete"
24
+ @pdf.lnumeric LINE_HEIGHT, 3.05, 3.30, @l2, @xml, "ICMSTot/vSeg"
25
+ @pdf.lnumeric LINE_HEIGHT, 3.04, 6.35, @l2, @xml, "ICMSTot/vDesc"
26
+ @pdf.lnumeric LINE_HEIGHT, 3.04, 9.39, @l2, @xml, "ICMSTot/vOutro"
27
+ @pdf.lnumeric LINE_HEIGHT, 4.06, 12.43, @l2, @xml, "ICMSTot/vIPI"
28
+ @pdf.lnumeric LINE_HEIGHT, 4.32, 16.49, @l2, @xml, "ICMSTot/vNF", style: :bold
17
29
  end
18
30
  end
19
31
  end
@@ -1,29 +1,34 @@
1
1
  module BrDanfe
2
2
  class Infadic
3
+ Y = 25.92 + SPACE_BETWEEN_GROUPS
4
+
3
5
  def initialize(pdf, xml)
4
6
  @pdf = pdf
5
7
  @xml = xml
8
+
9
+ @ltitle = Y - 0.41
10
+ @l1 = Y
6
11
  end
7
12
 
8
13
  def render(nVol)
9
- @pdf.ititle 0.42, 10.00, 0.25, 25.91, "infAdic.title"
14
+ @pdf.ititle 0.42, 10.00, 0.25, @ltitle, "infAdic.title"
10
15
 
11
16
  if nVol > 1
12
17
  render_extra_volumes
13
18
  else
14
- @pdf.ibox 3.07, 12.93, 0.25, 26.33, I18n.t("danfe.infAdic.infCpl"), @xml["infAdic/infCpl"], { size: 6, valign: :top }
19
+ @pdf.ibox 3.07, 12.93, 0.25, @l1, I18n.t("danfe.infAdic.infCpl"), @xml["infAdic/infCpl"], { size: 6, valign: :top }
15
20
  end
16
21
 
17
- @pdf.ibox 3.07, 7.62, 13.17, 26.33, I18n.t("danfe.infAdic.reserved")
22
+ @pdf.ibox 3.07, 7.62, 13.19, @l1, I18n.t("danfe.infAdic.reserved")
18
23
  end
19
24
 
20
25
  private
21
26
  def render_extra_volumes
22
- @pdf.ibox 3.07, 12.93, 0.25, 26.33, I18n.t("danfe.infAdic.infCpl"), "", { size: 8, valign: :top }
23
- @pdf.ibox 3.07, 12.93, 0.25, 26.60, "", I18n.t("danfe.infAdic.vol.title"), { size: 5, valign: :top, border: 0 }
27
+ @pdf.ibox 3.07, 12.93, 0.25, @l1, I18n.t("danfe.infAdic.infCpl"), "", { size: 8, valign: :top }
28
+ @pdf.ibox 3.07, 12.93, 0.25, Y + 0.27, "", I18n.t("danfe.infAdic.vol.title"), { size: 5, valign: :top, border: 0 }
24
29
 
25
30
  volumes = 0
26
- y = 26.67
31
+ y = Y + 0.34
27
32
  @xml.collect("xmlns", "vol") do |det|
28
33
  volumes += 1
29
34
  if volumes > 1
@@ -1,12 +1,22 @@
1
1
  module BrDanfe
2
2
  class Issqn
3
- def self.render(pdf, xml)
4
- pdf.ititle 0.42, 10.00, 0.25, 24.64, "issqn.title"
3
+ Y = 24.60 + SPACE_BETWEEN_GROUPS
5
4
 
6
- pdf.lbox 0.85, 5.08, 0.25, 25.06, xml, "emit/IM"
7
- pdf.lbox 0.85, 5.08, 5.33, 25.06, xml, "total/vServ"
8
- pdf.lbox 0.85, 5.08, 10.41, 25.06, xml, "total/vBCISS"
9
- pdf.lbox 0.85, 5.28, 15.49, 25.06, xml, "total/ISSTot"
5
+ def initialize(pdf, xml)
6
+ @pdf = pdf
7
+ @xml = xml
8
+
9
+ @ltitle = Y - 0.42
10
+ @l1 = Y
11
+ end
12
+
13
+ def render
14
+ @pdf.ititle 0.42, 10.00, 0.25, @ltitle, "issqn.title"
15
+
16
+ @pdf.lbox LINE_HEIGHT, 5.14, 0.25, @l1, @xml, "emit/IM"
17
+ @pdf.lbox LINE_HEIGHT, 5.14, 5.39, @l1, @xml, "total/vServ"
18
+ @pdf.lbox LINE_HEIGHT, 5.14, 10.53, @l1, @xml, "total/vBCISS"
19
+ @pdf.lbox LINE_HEIGHT, 5.14, 15.67, @l1, @xml, "total/ISSTot"
10
20
  end
11
21
  end
12
22
  end