br_danfe 3.1.1 → 3.2.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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/Gemfile.lock +1 -1
  4. data/Guardfile +1 -1
  5. data/config/locales/pt-BR.yml +40 -0
  6. data/lib/br_danfe/danfe_lib/nfe.rb +5 -2
  7. data/lib/br_danfe/danfe_lib/nfe_lib/det_body.rb +22 -63
  8. data/lib/br_danfe/danfe_lib/nfe_lib/det_row.rb +63 -0
  9. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +19 -3
  10. data/lib/br_danfe/danfe_lib/nfe_lib/ibscbstot.rb +58 -0
  11. data/lib/br_danfe/danfe_lib/nfe_lib/icmstot.rb +39 -0
  12. data/lib/br_danfe/danfe_lib/nfe_lib/issqn.rb +20 -11
  13. data/lib/br_danfe/danfe_lib/nfe_lib/rtc_det_row.rb +145 -0
  14. data/lib/br_danfe/danfe_lib/nfe_lib/rtc_layout.rb +26 -0
  15. data/lib/br_danfe/danfe_lib/nfe_lib/transp.rb +1 -0
  16. data/lib/br_danfe/danfe_lib/nfe_lib/vol.rb +1 -0
  17. data/lib/br_danfe/qr_code.rb +1 -1
  18. data/lib/br_danfe/version.rb +1 -1
  19. data/spec/br_danfe/danfe_lib/nfe_lib/emit_header_spec.rb +42 -0
  20. data/spec/br_danfe/danfe_lib/nfe_lib/ibscbstot_spec.rb +125 -0
  21. data/spec/br_danfe/danfe_lib/nfe_lib/icmstot_spec.rb +60 -0
  22. data/spec/br_danfe/danfe_lib/nfe_lib/issqn_spec.rb +69 -0
  23. data/spec/br_danfe/danfe_lib/nfe_lib/rtc_det_row_spec.rb +121 -0
  24. data/spec/br_danfe/danfe_lib/nfe_lib/rtc_layout_spec.rb +113 -0
  25. data/spec/br_danfe/danfe_lib/nfe_spec.rb +115 -0
  26. data/spec/br_danfe/uf_spec.rb +3 -3
  27. data/spec/fixtures/nfe/lib/issqn#render-with_entrega.pdf +0 -0
  28. data/spec/fixtures/nfe/v4.00/rtc_regime_normal.xml +92 -0
  29. data/spec/fixtures/nfe/v4.00/rtc_regime_normal.xml.fixture.pdf +4283 -2
  30. data/spec/fixtures/nfe/v4.00/rtc_regime_normal_with_entrega_and_issqn.xml +105 -0
  31. data/spec/fixtures/nfe/v4.00/rtc_regime_normal_with_entrega_and_issqn.xml.fixture.pdf +5744 -2
  32. data/spec/fixtures/nfe/v4.00/rtc_regime_normal_with_fcp_difal_and_monophasic.xml +103 -0
  33. data/spec/fixtures/nfe/v4.00/rtc_regime_normal_with_fcp_difal_and_monophasic.xml.fixture.pdf +4786 -2
  34. data/spec/fixtures/nfe/v4.00/rtc_regime_normal_with_many_items.xml +709 -0
  35. data/spec/fixtures/nfe/v4.00/rtc_regime_normal_with_many_items.xml.fixture.pdf +27509 -2
  36. data/spec/fixtures/nfe/v4.00/rtc_simples_nacional.xml +65 -0
  37. data/spec/fixtures/nfe/v4.00/rtc_simples_nacional.xml.fixture.pdf +3526 -2
  38. data/spec/fixtures/nfe/v4.00/rtc_simples_nacional_before_start_date.xml +65 -0
  39. data/spec/fixtures/nfe/v4.00/rtc_simples_nacional_before_start_date.xml.fixture.pdf +3998 -2
  40. metadata +21 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ff19b20871262acd4e02135c7e7d237b5052aef8666a83d6e921cc0e3a4930b
4
- data.tar.gz: 4410d226e4eaa0123a5180db9d2e33328caacc46105b23aff0715cb605d08e50
3
+ metadata.gz: 3bc7ee3b8c7c0d1b2f88af07f7c53ec27de36b84f1b082c2b6a3e653908ddc3c
4
+ data.tar.gz: 25f32de99bd11182620ddfa7f08d2bd5de4cfcc7093e296a46f6e590d5f99c64
5
5
  SHA512:
6
- metadata.gz: d562723a34053ba2e2b8e541fceb2e73357995d7ac173cb73e3ccfa02fa88b127376da1b146930ba5145bed36d8909b0823146811b7662e8e66f8d4b47e612ab
7
- data.tar.gz: a2966067515c05e32f12f464d13ec16c0184827e1175e2a3e774d9af9fa06b1768d3ba850dbfde4f78d2b0945a21ae3f793973eb07a545eb2920394d290ae7ce
6
+ metadata.gz: aaa108cc8c8062f50becce7d14c1099f7a59da850c9381b96d024208ff8d79465998f2c33f7c463b057cb1b8c0acab9d90534c78b35602cbb327678c83b7bb7e
7
+ data.tar.gz: 440245cab68841c83fb723fb20f7da99cd0be11757b939bce6a4737fcb0888acdef5992dadddcf87a1c355f77702689554176cd47e8319a3fe580d6ac7b7092c
data/.rubocop.yml CHANGED
@@ -64,6 +64,9 @@ Style/IfUnlessModifier:
64
64
  Style/SymbolArray:
65
65
  EnforcedStyle: brackets
66
66
 
67
+ Style/WordArray:
68
+ EnforcedStyle: brackets
69
+
67
70
  Style/HashEachMethods:
68
71
  Enabled: false
69
72
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_danfe (3.1.1)
4
+ br_danfe (3.2.0)
5
5
  barby (= 0.6.9)
6
6
  br_documents (>= 0.1.3)
7
7
  i18n (>= 0.8.6)
data/Guardfile CHANGED
@@ -1,4 +1,4 @@
1
- directories %w[lib spec]
1
+ directories ['lib', 'spec']
2
2
 
3
3
  guard :rspec, cmd: 'NO_COVERAGE=true bundle exec rspec' do
4
4
  require 'guard/rspec/dsl'
@@ -50,6 +50,12 @@ pt-BR:
50
50
  IEST: "INSC.ESTADUAL DO SUBST. TRIBUTÁRIO"
51
51
  CNPJ: "CNPJ/CPF"
52
52
  CPF: "CNPJ/CPF"
53
+ CRT:
54
+ title: "CÓDIGO DO REGIME TRIBUTÁRIO"
55
+ "1": "1 - SIMPLES NACIONAL"
56
+ "2": "2 - SIMPLES NACIONAL - EXCESSO"
57
+ "3": "3 - REGIME NORMAL"
58
+ "4": "4 - SIMPLES NACIONAL - MEI"
53
59
  dup:
54
60
  title: "FATURA / DUPLICATAS"
55
61
  nDup: "NRO"
@@ -68,6 +74,30 @@ pt-BR:
68
74
  vOutro: "OUTRAS DESPESAS ACESSORIAS"
69
75
  vIPI: "VALOR DO IPI"
70
76
  vNF: "VALOR TOTAL DA NOTA"
77
+ vFCP: "VALOR DO FCP"
78
+ vFCPST: "VALOR DO FCP RETIDO POR ST"
79
+ vICMSUFDest: "VALOR DO DIFAL NA UF DE DESTINO"
80
+ vFCPUFDest: "VALOR DO FCP NA UF DE DESTINO"
81
+ qBCMono: "BC DO ICMS MONOFÁSICO"
82
+ vICMSMono: "VALOR DO ICMS MONOFÁSICO"
83
+ qBCMonoReten: "BC DO ICMS MONOFÁSICO POR RETENÇÃO"
84
+ vICMSMonoReten: "VALOR ICMS MONOFÁSICO POR RETENÇÃO"
85
+ IBSCBSTot:
86
+ title: "TOTAL DO IBS / CBS / IS"
87
+ gCBS:
88
+ vCBS: "VALOR DA CBS"
89
+ gIBS:
90
+ gIBSUF:
91
+ vIBSUF: "VALOR DO IBS UF"
92
+ gIBSMun:
93
+ vIBSMun: "VALOR DO IBS MUNICÍPIO"
94
+ gMono:
95
+ vIBSMono: "VALOR DO IBS MONOFÁSICO"
96
+ vCBSMono: "VALOR DA CBS MONOFÁSICA"
97
+ vIBSMonoReten: "VALOR DO IBS MONOFÁSICO POR RETENÇÃO"
98
+ vCBSMonoReten: "VALOR DA CBS MONOFÁSICA POR RETENÇÃO"
99
+ ISTot:
100
+ vIS: "VALOR DO IMPOSTO SELETIVO"
71
101
  transporta:
72
102
  title: "TRANSPORTADOR / VOLUMES TRANSPORTADOS"
73
103
  xNome: "RAZÃO SOCIAL"
@@ -121,6 +151,16 @@ pt-BR:
121
151
  IPI:
122
152
  vIPI: "VL IPI"
123
153
  pIPI: "% IPI"
154
+ code: "CÓD"
155
+ columns:
156
+ description: "DESCRIÇÃO DO PRODUTO / SERVIÇO"
157
+ cst_cfop: "CST / CFOP"
158
+ quantity_unit: "QTD / UN"
159
+ unit_value: "VLR UNIT"
160
+ total_value: "VLR TOTAL"
161
+ bases: "BASES DE CÁLCULO"
162
+ rates: "ALÍQUOTAS"
163
+ taxes: "VALOR DOS TRIBUTOS"
124
164
  issqn:
125
165
  title: "CÁLCULO DO ISSQN"
126
166
  total:
@@ -45,12 +45,13 @@ module BrDanfe
45
45
  NfeLib::Entrega.new(@document, xml).render
46
46
  NfeLib::Dup.new(@document, xml).render
47
47
  NfeLib::Icmstot.new(@document, xml).render
48
+ NfeLib::Ibscbstot.new(@document, xml).render
48
49
  NfeLib::Transp.new(@document, xml).render
49
50
  n_vol = NfeLib::Vol.new(@document, xml).render
50
51
  has_issqn = NfeLib::Issqn.new(@document, xml).render
51
52
  NfeLib::Infadic.new(@document, xml).render(n_vol)
52
53
 
53
- render_products(has_issqn, xml)
54
+ @products_on_first_page = render_products(has_issqn, xml)
54
55
  end
55
56
 
56
57
  def render_products(has_issqn, xml)
@@ -80,8 +81,10 @@ module BrDanfe
80
81
  end
81
82
 
82
83
  def render_product_table_title(page, xml)
84
+ return if page == 1 && !@products_on_first_page
85
+
83
86
  y_position = NfeLib::Entrega.delivery_local?(xml) && page == 1 ? 3.00 : 0
84
- y_position += page == 1 ? 18.91 : 7.40
87
+ y_position += page == 1 ? 18.91 + NfeLib::RtcLayout.offset(xml) : 7.40
85
88
  @document.ititle 0.42, 10.00, 0.75, y_position, 'det.title'
86
89
  end
87
90
 
@@ -3,6 +3,8 @@ module BrDanfe
3
3
  module NfeLib
4
4
  class DetBody
5
5
  TABLE_CELL_PADDING = 2
6
+ TABLE_WITH_ONLY_HEADER = 1
7
+ private_constant :TABLE_WITH_ONLY_HEADER
6
8
 
7
9
  attr_reader :y_position_with_entrega
8
10
 
@@ -11,6 +13,8 @@ module BrDanfe
11
13
  @xml = xml
12
14
 
13
15
  @y_position_with_entrega = Entrega.delivery_local?(@xml) ? 3.00 : 0.00
16
+ @first_page_offset = @y_position_with_entrega + RtcLayout.offset(@xml)
17
+ @row = RtcLayout.applies?(@xml) ? RtcDetRow : DetRow
14
18
  end
15
19
 
16
20
  def render(has_issqn)
@@ -25,8 +29,8 @@ module BrDanfe
25
29
  private
26
30
 
27
31
  def table_height_on_first_page(has_issqn)
28
- base_height = has_issqn ? 6.35.cm : 7.72.cm
29
- (base_height - @y_position_with_entrega.cm)
32
+ base_height = has_issqn && !RtcLayout.applies?(@xml) ? 6.35.cm : 7.72.cm
33
+ base_height - @first_page_offset.cm
30
34
  end
31
35
 
32
36
  def create_table
@@ -34,96 +38,51 @@ module BrDanfe
34
38
  end
35
39
 
36
40
  def create_header
37
- header = [[
38
- header_column('prod.cProd'), header_column('prod.xProd'), header_column('prod.NCM'),
39
- header_column('ICMS.CST'), header_column('prod.CFOP'), header_column('prod.uCom'),
40
- header_column('prod.qCom'), header_column('prod.vUnCom'), header_column('prod.vProd'),
41
- header_column('ICMS.vBC'), header_column('ICMS.vICMS'), header_column('IPI.vIPI'),
42
- header_column('ICMS.pICMS'), header_column('IPI.pIPI')
43
- ]]
44
- @pdf.make_table(header, options)
41
+ @pdf.make_table([@row.titles.map { |title| header_cell(title) }], options)
45
42
  end
46
43
 
47
- def header_column(title)
44
+ def header_cell(content)
48
45
  {
49
- content: I18n.t("danfe.det.#{title}"), align: :center, size: 5, valign: :top, font_style: :bold,
46
+ content: content, align: :center, size: 5, valign: :top, font_style: :bold,
50
47
  background_color: TITLE_BACKGROUND_COLOR, padding: [4, TABLE_CELL_PADDING, 3.5, TABLE_CELL_PADDING]
51
48
  }
52
49
  end
53
50
 
54
51
  def options
55
52
  {
56
- column_widths: column_widths,
53
+ column_widths: @row.column_widths,
57
54
  cell_style: { padding: [0.5, TABLE_CELL_PADDING, 1.5, TABLE_CELL_PADDING], border_width: LINE_WIDTH }
58
55
  }
59
56
  end
60
57
 
61
- def column_widths
62
- {
63
- 0 => 1.60.cm, 1 => 6.10.cm, 2 => 1.05.cm, 3 => 0.60.cm, 4 => 0.70.cm, 5 => 1.05.cm, 6 => 1.20.cm,
64
- 7 => 1.20.cm, 8 => 1.20.cm, 9 => 1.20.cm, 10 => 1.00.cm, 11 => 1.00.cm, 12 => 0.90.cm, 13 => 0.76.cm
65
- }
66
- end
67
-
68
58
  def fill_tables(first_table, next_table, first_table_height)
69
59
  total_height = first_table.first.height
70
60
 
71
- products.each do |product|
72
- row = create_row product
61
+ @xml.collect('xmlns', 'det') { _1 }.each do |det|
62
+ row = create_row(@row.new(@pdf, det).render)
73
63
  total_height += row.height
74
64
  total_height <= first_table_height ? first_table << row : next_table << row
75
65
  end
76
66
  end
77
67
 
78
- def products
79
- @xml.collect('xmlns', 'det') { |det| product(det) }
80
- end
81
-
82
- def product(det)
83
- [
84
- cell_text(det.css('prod/cProd').text),
85
- cell_text(Xprod.new(det).render),
86
- cell_text(det.css('prod/NCM').text),
87
- cell_text(Cst.to_danfe(det)),
88
- cell_text(det.css('prod/CFOP').text),
89
- cell_text(det.css('prod/uCom').text),
90
- cell_number(numerify(det, 'prod/qCom')),
91
- cell_number(numerify(det, 'prod/vUnCom')),
92
- cell_number(numerify(det, 'prod/vProd')),
93
- cell_number(numerify(det, 'ICMS/*/vBC')),
94
- cell_number(numerify(det, 'ICMS/*/vICMS')),
95
- cell_number(numerify(det, 'IPI/*/vIPI')),
96
- cell_number(numerify(det, 'ICMS/*/pICMS')),
97
- cell_number(numerify(det, 'IPI/*/pIPI'))
98
- ]
99
- end
100
-
101
- def cell_text(text, options = {})
102
- cell = { content: text, border_lines: [:solid], size: 6 }
103
- cell.merge!(options)
104
- cell
105
- end
106
-
107
- def cell_number(text)
108
- cell_text(text, align: :right)
109
- end
110
-
111
- def numerify(det, xpath)
112
- BrDanfe::Helper.numerify(det.css(xpath.to_s).text)
113
- end
114
-
115
68
  def create_row(data)
116
69
  @pdf.make_table([data], options)
117
70
  end
118
71
 
119
72
  def render_tables(first_table, next_table, first_table_height)
120
- render_table first_table, table_position_on_first_page, first_table_height
73
+ products_on_first_page = products_on_first_page?(first_table, next_table)
74
+ render_table first_table, table_position_on_first_page, first_table_height if products_on_first_page
121
75
 
122
- table_with_only_header = 1
123
- if next_table.size > table_with_only_header
76
+ if next_table.size > TABLE_WITH_ONLY_HEADER
124
77
  @pdf.start_new_page
125
78
  render_table next_table, table_position_on_next_pages, table_height_on_next_pages
126
79
  end
80
+
81
+ products_on_first_page
82
+ end
83
+
84
+ def products_on_first_page?(first_table, next_table)
85
+ first_table.size > TABLE_WITH_ONLY_HEADER || next_table.size == TABLE_WITH_ONLY_HEADER
127
86
  end
128
87
 
129
88
  def render_table(data, start_position, height)
@@ -134,7 +93,7 @@ module BrDanfe
134
93
  end
135
94
 
136
95
  def table_position_on_first_page
137
- y_position = @y_position_with_entrega.cm + 18.07.cm
96
+ y_position = @first_page_offset.cm + 18.07.cm
138
97
  Helper.invert(y_position)
139
98
  end
140
99
 
@@ -0,0 +1,63 @@
1
+ module BrDanfe
2
+ module DanfeLib
3
+ module NfeLib
4
+ class DetRow
5
+ HEADER = [
6
+ 'prod.cProd', 'prod.xProd', 'prod.NCM', 'ICMS.CST', 'prod.CFOP', 'prod.uCom', 'prod.qCom',
7
+ 'prod.vUnCom', 'prod.vProd', 'ICMS.vBC', 'ICMS.vICMS', 'IPI.vIPI', 'ICMS.pICMS', 'IPI.pIPI'
8
+ ].freeze
9
+ private_constant :HEADER
10
+
11
+ def self.titles
12
+ HEADER.map { |key| I18n.t("danfe.det.#{key}") }
13
+ end
14
+
15
+ def self.column_widths
16
+ {
17
+ 0 => 1.60.cm, 1 => 6.10.cm, 2 => 1.05.cm, 3 => 0.60.cm, 4 => 0.70.cm, 5 => 1.05.cm, 6 => 1.20.cm,
18
+ 7 => 1.20.cm, 8 => 1.20.cm, 9 => 1.20.cm, 10 => 1.00.cm, 11 => 1.00.cm, 12 => 0.90.cm, 13 => 0.76.cm
19
+ }
20
+ end
21
+
22
+ def initialize(_pdf, det)
23
+ @det = det
24
+ end
25
+
26
+ def render
27
+ [
28
+ cell_text(@det.css('prod/cProd').text),
29
+ cell_text(Xprod.new(@det).render),
30
+ cell_text(@det.css('prod/NCM').text),
31
+ cell_text(Cst.to_danfe(@det)),
32
+ cell_text(@det.css('prod/CFOP').text),
33
+ cell_text(@det.css('prod/uCom').text),
34
+ cell_number(numerify('prod/qCom')),
35
+ cell_number(numerify('prod/vUnCom')),
36
+ cell_number(numerify('prod/vProd')),
37
+ cell_number(numerify('ICMS/*/vBC')),
38
+ cell_number(numerify('ICMS/*/vICMS')),
39
+ cell_number(numerify('IPI/*/vIPI')),
40
+ cell_number(numerify('ICMS/*/pICMS')),
41
+ cell_number(numerify('IPI/*/pIPI'))
42
+ ]
43
+ end
44
+
45
+ private
46
+
47
+ def cell_text(text, options = {})
48
+ cell = { content: text, border_lines: [:solid], size: 6 }
49
+ cell.merge!(options)
50
+ cell
51
+ end
52
+
53
+ def cell_number(text)
54
+ cell_text(text, align: :right)
55
+ end
56
+
57
+ def numerify(xpath)
58
+ BrDanfe::Helper.numerify(@det.css(xpath.to_s).text)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -124,9 +124,25 @@ module BrDanfe
124
124
  @pdf.ibox LINE_HEIGHT, 9.52, 10.79, y_first_line, I18n.t('danfe.infProt'),
125
125
  "#{@xml['infProt/nProt']} #{BrDanfe::Helper.format_datetime(@xml['infProt/dhRecbto'])}", align: :right
126
126
 
127
- @pdf.lie LINE_HEIGHT, 6.36, 0.75, y_second_line, @xml, 'enderEmit/UF', 'emit/IE'
128
- @pdf.lie LINE_HEIGHT, 6.86, 7.11, y_second_line, @xml, 'enderDest/UF', 'emit/IEST'
129
- @pdf.lcnpj_cpf LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, cnpj_cpf, align: :right
127
+ RtcLayout.applies?(@xml) ? render_rtc_second_line(y_second_line) : render_second_line(y_second_line)
128
+ end
129
+
130
+ def render_second_line(y_position)
131
+ @pdf.lie LINE_HEIGHT, 6.36, 0.75, y_position, @xml, 'enderEmit/UF', 'emit/IE'
132
+ @pdf.lie LINE_HEIGHT, 6.86, 7.11, y_position, @xml, 'enderDest/UF', 'emit/IEST'
133
+ @pdf.lcnpj_cpf LINE_HEIGHT, 6.34, 13.97, y_position, @xml, cnpj_cpf, align: :right
134
+ end
135
+
136
+ def render_rtc_second_line(y_position)
137
+ @pdf.lie LINE_HEIGHT, 4.40, 0.75, y_position, @xml, 'enderEmit/UF', 'emit/IE'
138
+ @pdf.lie LINE_HEIGHT, 4.40, 5.15, y_position, @xml, 'enderDest/UF', 'emit/IEST'
139
+ @pdf.i18n_lbox LINE_HEIGHT, 6.00, 9.55, y_position, 'emit.CRT.title', crt
140
+ @pdf.lcnpj_cpf LINE_HEIGHT, 4.76, 15.55, y_position, @xml, cnpj_cpf, align: :right
141
+ end
142
+
143
+ def crt
144
+ code = @xml['emit/CRT']
145
+ code.present? ? I18n.t("danfe.emit.CRT.#{code}", default: code) : ''
130
146
  end
131
147
 
132
148
  def cnpj_cpf
@@ -0,0 +1,58 @@
1
+ module BrDanfe
2
+ module DanfeLib
3
+ module NfeLib
4
+ class Ibscbstot
5
+ def self.offset(xml)
6
+ return 0.0 unless RtcLayout.applies?(xml)
7
+
8
+ lines = monophasic?(xml) ? 2 : 1
9
+ (LINE_HEIGHT * lines) + SPACE_BETWEEN_GROUPS
10
+ end
11
+
12
+ def self.monophasic?(xml)
13
+ xml['IBSCBSTot/gMono'].present?
14
+ end
15
+
16
+ def initialize(pdf, xml)
17
+ @pdf = pdf
18
+ @xml = xml
19
+ @y_position = Entrega.delivery_local?(@xml) ? Transp::Y_POSITION + 3.00 : Transp::Y_POSITION
20
+ @y_position += Icmstot.offset(@xml)
21
+ end
22
+
23
+ def render
24
+ return unless RtcLayout.applies?(@xml)
25
+
26
+ @pdf.ititle 0.42, 10.00, 0.75, @y_position - 0.42, 'IBSCBSTot.title'
27
+
28
+ render_totals
29
+ render_monophasic_totals if self.class.monophasic?(@xml)
30
+ end
31
+
32
+ private
33
+
34
+ def render_totals
35
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 0.75, @y_position, @xml, 'IBSCBSTot/gCBS/vCBS'
36
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 5.64, @y_position, @xml, 'IBSCBSTot/gIBS/gIBSUF/vIBSUF'
37
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 10.53, @y_position, @xml, 'IBSCBSTot/gIBS/gIBSMun/vIBSMun'
38
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 15.42, @y_position, @xml, 'ISTot/vIS'
39
+ end
40
+
41
+ def render_monophasic_totals
42
+ y_position = @y_position + LINE_HEIGHT
43
+
44
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 0.75, y_position, @xml, 'IBSCBSTot/gMono/vIBSMono'
45
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 5.64, y_position, @xml, 'IBSCBSTot/gMono/vCBSMono'
46
+ @pdf.inumeric LINE_HEIGHT, 4.89, 10.53, y_position, 'IBSCBSTot.gMono.vIBSMonoReten',
47
+ retention('IBSCBSTot/gMono/vIBSMonoReten')
48
+ @pdf.inumeric LINE_HEIGHT, 4.89, 15.42, y_position, 'IBSCBSTot.gMono.vCBSMonoReten',
49
+ retention('IBSCBSTot/gMono/vCBSMonoReten')
50
+ end
51
+
52
+ def retention(xpath)
53
+ @xml[xpath].to_f.positive? ? @xml[xpath] : ''
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -5,6 +5,23 @@ module BrDanfe
5
5
  attr_reader :y_position
6
6
 
7
7
  Y_POSITION = 13.77 + SPACE_BETWEEN_GROUPS
8
+ FCP_DIFAL_TOTALS = ['ICMSTot/vFCP', 'ICMSTot/vFCPST', 'ICMSTot/vICMSUFDest', 'ICMSTot/vFCPUFDest'].freeze
9
+ MONOPHASIC_TOTALS = [
10
+ 'ICMSTot/qBCMono', 'ICMSTot/vICMSMono', 'ICMSTot/qBCMonoReten', 'ICMSTot/vICMSMonoReten'
11
+ ].freeze
12
+ private_constant :FCP_DIFAL_TOTALS, :MONOPHASIC_TOTALS
13
+
14
+ def self.offset(xml)
15
+ [fcp_difal?(xml), monophasic?(xml)].count(true) * LINE_HEIGHT
16
+ end
17
+
18
+ def self.fcp_difal?(xml)
19
+ RtcLayout.applies?(xml) && FCP_DIFAL_TOTALS.any? { |xpath| xml[xpath].to_f.positive? }
20
+ end
21
+
22
+ def self.monophasic?(xml)
23
+ RtcLayout.applies?(xml) && MONOPHASIC_TOTALS.any? { |xpath| xml[xpath].to_f.positive? }
24
+ end
8
25
 
9
26
  def initialize(pdf, xml)
10
27
  @pdf = pdf
@@ -15,6 +32,7 @@ module BrDanfe
15
32
  @ltitle = @y_position - 0.42
16
33
  @l1 = @y_position
17
34
  @l2 = @y_position + LINE_HEIGHT
35
+ @l3 = @l2 + LINE_HEIGHT
18
36
  end
19
37
 
20
38
  def render
@@ -32,6 +50,27 @@ module BrDanfe
32
50
  @pdf.lnumeric LINE_HEIGHT, 3.04, 9.39, @l2, @xml, 'ICMSTot/vOutro'
33
51
  @pdf.lnumeric LINE_HEIGHT, 4.06, 12.43, @l2, @xml, 'ICMSTot/vIPI'
34
52
  @pdf.lnumeric LINE_HEIGHT, 3.82, 16.49, @l2, @xml, 'ICMSTot/vNF', style: :bold
53
+
54
+ render_fcp_difal_line if self.class.fcp_difal?(@xml)
55
+ render_monophasic_line if self.class.monophasic?(@xml)
56
+ end
57
+
58
+ private
59
+
60
+ def render_fcp_difal_line
61
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 0.75, @l3, @xml, 'ICMSTot/vFCP'
62
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 5.64, @l3, @xml, 'ICMSTot/vFCPST'
63
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 10.53, @l3, @xml, 'ICMSTot/vICMSUFDest'
64
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 15.42, @l3, @xml, 'ICMSTot/vFCPUFDest'
65
+ end
66
+
67
+ def render_monophasic_line
68
+ y_position = self.class.fcp_difal?(@xml) ? @l3 + LINE_HEIGHT : @l3
69
+
70
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 0.75, y_position, @xml, 'ICMSTot/qBCMono'
71
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 5.64, y_position, @xml, 'ICMSTot/vICMSMono'
72
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 10.53, y_position, @xml, 'ICMSTot/qBCMonoReten'
73
+ @pdf.lnumeric LINE_HEIGHT, 4.89, 15.42, y_position, @xml, 'ICMSTot/vICMSMonoReten'
35
74
  end
36
75
  end
37
76
  end
@@ -5,33 +5,42 @@ module BrDanfe
5
5
  attr_reader :y_position
6
6
 
7
7
  Y_POSITION = 25.72 + SPACE_BETWEEN_GROUPS
8
+ SERV = 'total/ISSQNtot/vServ'.freeze
9
+ BC = 'total/ISSQNtot/vBC'.freeze
10
+ ISS = 'total/ISSQNtot/vISS'.freeze
11
+ private_constant :SERV, :BC, :ISS
12
+
13
+ def self.offset(xml)
14
+ RtcLayout.applies?(xml) && informed?(xml) ? LINE_HEIGHT + SPACE_BETWEEN_GROUPS : 0.0
15
+ end
16
+
17
+ def self.informed?(xml)
18
+ xml[SERV].to_f.positive? || xml[BC].to_f.positive? || xml[ISS].to_f.positive?
19
+ end
8
20
 
9
21
  def initialize(pdf, xml)
10
22
  @pdf = pdf
11
23
  @xml = xml
12
24
 
13
- @y_position = Entrega.delivery_local?(@xml) ? Y_POSITION + 3.00 : Y_POSITION
25
+ @y_position = RtcLayout.applies?(@xml) ? position_below_the_tax_totals : Y_POSITION
14
26
  @title = @y_position - 0.42
15
-
16
- @serv = 'total/ISSQNtot/vServ'
17
- @bc = 'total/ISSQNtot/vBC'
18
- @iss = 'total/ISSQNtot/vISS'
19
27
  end
20
28
 
21
29
  def render
22
- if can_render?
30
+ if self.class.informed?(@xml)
23
31
  @pdf.ititle 0.42, 10.00, 0.75, @title, 'issqn.title'
24
32
  @pdf.lbox LINE_HEIGHT, 4.64, 0.75, @y_position, @xml, 'emit/IM'
25
- @pdf.lnumeric LINE_HEIGHT, 5.14, 5.39, @y_position, @xml, @serv
26
- @pdf.lnumeric LINE_HEIGHT, 5.14, 10.53, @y_position, @xml, @bc
27
- @pdf.lnumeric LINE_HEIGHT, 4.64, 15.67, @y_position, @xml, @iss
33
+ @pdf.lnumeric LINE_HEIGHT, 5.14, 5.39, @y_position, @xml, SERV
34
+ @pdf.lnumeric LINE_HEIGHT, 5.14, 10.53, @y_position, @xml, BC
35
+ @pdf.lnumeric LINE_HEIGHT, 4.64, 15.67, @y_position, @xml, ISS
28
36
  end
29
37
  end
30
38
 
31
39
  private
32
40
 
33
- def can_render?
34
- @xml[@serv].to_f.positive? || @xml[@bc].to_f.positive? || @xml[@iss].to_f.positive?
41
+ def position_below_the_tax_totals
42
+ y_position = Entrega.delivery_local?(@xml) ? Transp::Y_POSITION + 3.00 : Transp::Y_POSITION
43
+ y_position + Icmstot.offset(@xml) + Ibscbstot.offset(@xml)
35
44
  end
36
45
  end
37
46
  end