br_danfe 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +15 -25
  3. data/Gemfile.lock +1 -1
  4. data/README.md +5 -5
  5. data/lib/br_danfe.rb +0 -1
  6. data/lib/br_danfe/danfe.rb +6 -90
  7. data/lib/br_danfe/danfe_lib/base.rb +33 -0
  8. data/lib/br_danfe/danfe_lib/nfce.rb +49 -0
  9. data/lib/br_danfe/danfe_lib/nfce_lib/document.rb +37 -0
  10. data/lib/br_danfe/danfe_lib/nfce_lib/footer.rb +22 -0
  11. data/lib/br_danfe/danfe_lib/nfce_lib/header.rb +69 -0
  12. data/lib/br_danfe/danfe_lib/nfce_lib/helper.rb +11 -0
  13. data/lib/br_danfe/danfe_lib/nfce_lib/key.rb +20 -0
  14. data/lib/br_danfe/danfe_lib/nfce_lib/nfce_identification.rb +22 -0
  15. data/lib/br_danfe/danfe_lib/nfce_lib/product_list.rb +102 -0
  16. data/lib/br_danfe/danfe_lib/nfce_lib/qr_code.rb +25 -0
  17. data/lib/br_danfe/danfe_lib/nfce_lib/recipient.rb +75 -0
  18. data/lib/br_danfe/danfe_lib/nfce_lib/total_list.rb +81 -0
  19. data/lib/br_danfe/danfe_lib/nfe.rb +83 -0
  20. data/lib/br_danfe/danfe_lib/nfe_lib/cep.rb +11 -0
  21. data/lib/br_danfe/danfe_lib/nfe_lib/consts.rb +8 -0
  22. data/lib/br_danfe/danfe_lib/nfe_lib/cst.rb +34 -0
  23. data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +96 -0
  24. data/lib/br_danfe/danfe_lib/nfe_lib/det_body.rb +137 -0
  25. data/lib/br_danfe/danfe_lib/nfe_lib/document.rb +142 -0
  26. data/lib/br_danfe/danfe_lib/nfe_lib/dup.rb +55 -0
  27. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +117 -0
  28. data/lib/br_danfe/danfe_lib/nfe_lib/helper.rb +55 -0
  29. data/lib/br_danfe/danfe_lib/nfe_lib/icmstot.rb +35 -0
  30. data/lib/br_danfe/danfe_lib/nfe_lib/infadic.rb +109 -0
  31. data/lib/br_danfe/danfe_lib/nfe_lib/infadic_vol.rb +103 -0
  32. data/lib/br_danfe/danfe_lib/nfe_lib/issqn.rb +37 -0
  33. data/lib/br_danfe/danfe_lib/nfe_lib/phone.rb +15 -0
  34. data/lib/br_danfe/danfe_lib/nfe_lib/plate.rb +11 -0
  35. data/lib/br_danfe/danfe_lib/nfe_lib/ticket.rb +21 -0
  36. data/lib/br_danfe/danfe_lib/nfe_lib/transp.rb +58 -0
  37. data/lib/br_danfe/danfe_lib/nfe_lib/vol.rb +44 -0
  38. data/lib/br_danfe/danfe_lib/nfe_lib/xprod.rb +109 -0
  39. data/lib/br_danfe/helper.rb +8 -0
  40. data/lib/br_danfe/version.rb +1 -1
  41. data/spec/{lib → br_danfe}/cce_lib/barcode_spec.rb +0 -0
  42. data/spec/{lib → br_danfe}/cce_lib/correction_spec.rb +0 -0
  43. data/spec/{lib → br_danfe}/cce_lib/document_spec.rb +0 -0
  44. data/spec/{lib → br_danfe}/cce_lib/footer_spec.rb +0 -0
  45. data/spec/{lib → br_danfe}/cce_lib/header_spec.rb +0 -0
  46. data/spec/{lib → br_danfe}/cce_lib/nfe_key_spec.rb +0 -0
  47. data/spec/{lib → br_danfe}/cce_lib/protocol_spec.rb +0 -0
  48. data/spec/{features → br_danfe}/cce_spec.rb +0 -0
  49. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/document_spec.rb +2 -2
  50. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/footer_spec.rb +2 -2
  51. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/header_spec.rb +2 -2
  52. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/helper_spec.rb +1 -1
  53. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/key_spec.rb +2 -2
  54. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/nfce_identification_spec.rb +2 -2
  55. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/product_list_spec.rb +2 -2
  56. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/qr_code_spec.rb +2 -2
  57. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/recipient_spec.rb +7 -7
  58. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/total_list_spec.rb +4 -4
  59. data/spec/br_danfe/danfe_lib/nfce_spec.rb +57 -0
  60. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/cep_spec.rb +2 -2
  61. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/cst_spec.rb +3 -3
  62. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/dest_spec.rb +2 -2
  63. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/det_body_spec.rb +2 -2
  64. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/document_spec.rb +1 -1
  65. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/dup_spec.rb +2 -2
  66. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/emit_header_spec.rb +3 -3
  67. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/helper_spec.rb +13 -87
  68. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/icmstot_spec.rb +2 -2
  69. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/infadic_spec.rb +2 -2
  70. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/infadic_vol_spec.rb +2 -2
  71. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/issqn_spec.rb +2 -2
  72. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/phone_spec.rb +3 -3
  73. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/plate_spec.rb +3 -3
  74. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/ticket_spec.rb +2 -2
  75. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/transp_spec.rb +2 -2
  76. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/vol_spec.rb +2 -2
  77. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/xprod_spec.rb +9 -9
  78. data/spec/{features/danfe_spec.rb → br_danfe/danfe_lib/nfe_spec.rb} +55 -47
  79. data/spec/br_danfe/danfe_spec.rb +35 -0
  80. data/spec/{lib → br_danfe}/helper_spec.rb +114 -0
  81. data/spec/{lib → br_danfe}/logo_config_spec.rb +1 -1
  82. data/spec/{lib → br_danfe}/logo_options_spec.rb +7 -7
  83. data/spec/{lib → br_danfe}/uf_spec.rb +0 -0
  84. data/spec/{lib → br_danfe}/xml_spec.rb +0 -0
  85. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-hom.fixture.pdf +0 -0
  86. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-hom.xml +358 -0
  87. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-prod.fixture.pdf +0 -0
  88. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-prod.xml +358 -0
  89. data/spec/fixtures/nfce/v4.00/nfce.xml +2 -2
  90. data/spec/fixtures/nfce/v4.00/rendered_nfce.fixture.pdf +0 -0
  91. data/spec/fixtures/nfce/v4.00/saved_nfce.fixture.pdf +0 -0
  92. metadata +82 -75
  93. data/lib/br_danfe/danfe_lib/cep.rb +0 -9
  94. data/lib/br_danfe/danfe_lib/consts.rb +0 -6
  95. data/lib/br_danfe/danfe_lib/cst.rb +0 -32
  96. data/lib/br_danfe/danfe_lib/dest.rb +0 -94
  97. data/lib/br_danfe/danfe_lib/det_body.rb +0 -135
  98. data/lib/br_danfe/danfe_lib/document.rb +0 -140
  99. data/lib/br_danfe/danfe_lib/dup.rb +0 -53
  100. data/lib/br_danfe/danfe_lib/emit_header.rb +0 -115
  101. data/lib/br_danfe/danfe_lib/helper.rb +0 -61
  102. data/lib/br_danfe/danfe_lib/icmstot.rb +0 -33
  103. data/lib/br_danfe/danfe_lib/infadic.rb +0 -107
  104. data/lib/br_danfe/danfe_lib/infadic_vol.rb +0 -101
  105. data/lib/br_danfe/danfe_lib/issqn.rb +0 -35
  106. data/lib/br_danfe/danfe_lib/phone.rb +0 -13
  107. data/lib/br_danfe/danfe_lib/plate.rb +0 -9
  108. data/lib/br_danfe/danfe_lib/ticket.rb +0 -19
  109. data/lib/br_danfe/danfe_lib/transp.rb +0 -56
  110. data/lib/br_danfe/danfe_lib/vol.rb +0 -42
  111. data/lib/br_danfe/danfe_lib/xprod.rb +0 -107
  112. data/lib/br_danfe/danfe_nfce.rb +0 -43
  113. data/lib/br_danfe/danfe_nfce_lib/document.rb +0 -35
  114. data/lib/br_danfe/danfe_nfce_lib/footer.rb +0 -20
  115. data/lib/br_danfe/danfe_nfce_lib/header.rb +0 -67
  116. data/lib/br_danfe/danfe_nfce_lib/helper.rb +0 -9
  117. data/lib/br_danfe/danfe_nfce_lib/key.rb +0 -18
  118. data/lib/br_danfe/danfe_nfce_lib/nfce_identification.rb +0 -20
  119. data/lib/br_danfe/danfe_nfce_lib/product_list.rb +0 -100
  120. data/lib/br_danfe/danfe_nfce_lib/qr_code.rb +0 -23
  121. data/lib/br_danfe/danfe_nfce_lib/recipient.rb +0 -72
  122. data/lib/br_danfe/danfe_nfce_lib/total_list.rb +0 -78
  123. data/spec/features/danfe_nfce_spec.rb +0 -31
@@ -1,140 +0,0 @@
1
- module BrDanfe
2
- module DanfeLib
3
- class Document
4
- def initialize
5
- @document = Prawn::Document.new(
6
- page_size: 'A4',
7
- page_layout: :portrait,
8
- left_margin: 0,
9
- right_margin: 0,
10
- top_margin: 0,
11
- botton_margin: 0
12
- )
13
-
14
- @document.font 'Times-Roman'
15
- @document.line_width = 0.3
16
- end
17
-
18
- def method_missing(method_name, *args, &block)
19
- if @document.respond_to? method_name
20
- @document.send method_name, *args, &block
21
- else
22
- super
23
- end
24
- end
25
-
26
- def respond_to_missing?(method_name, include_private = false)
27
- @document.respond_to?(method_name, include_private) || super
28
- end
29
-
30
- def ititle(h, w, x, y, i18n)
31
- title = ''
32
- title = I18n.t("danfe.#{i18n}") if i18n != ''
33
-
34
- text_box title, size: 8, at: [x.cm, Helper.invert(y.cm) - 4], width: w.cm, height: h.cm, style: :bold
35
- end
36
-
37
- def ibarcode(h, w, x, y, info)
38
- if info != ''
39
- Barby::Code128C.new(info).annotate_pdf(self, x: x.cm, y: Helper.invert(y.cm), width: w.cm, height: h.cm)
40
- end
41
- end
42
-
43
- def ibox(h, w, x, y, title = '', info = '', options = {})
44
- box [x.cm, Helper.invert(y.cm)], w.cm, h.cm, title, info, options
45
- end
46
-
47
- def lbox(h, w, x, y, xml, xpath, options = {})
48
- i18n = xpath.tr('/', '.')
49
- label = I18n.t("danfe.#{i18n}")
50
- data = xml[xpath]
51
-
52
- ibox(h, w, x, y, label, data, options)
53
- end
54
-
55
- def ldate(h, w, x, y, i18n = '', info = '', options = {})
56
- data = Helper.format_date(info)
57
- i18n_lbox(h, w, x, y, i18n, data, options)
58
- end
59
-
60
- def ltime(h, w, x, y, i18n = '', info = '', options = {})
61
- data = Helper.format_time(info)
62
- i18n_lbox(h, w, x, y, i18n, data, options)
63
- end
64
-
65
- def lcnpj(h, w, x, y, xml, xpath, options = {})
66
- i18n = xpath.tr('/', '.')
67
-
68
- cnpj = BrDocuments::CnpjCpf::Cnpj.new(xml[xpath])
69
- data = if cnpj.valid?
70
- cnpj.formatted
71
- else
72
- ''
73
- end
74
-
75
- i18n_lbox(h, w, x, y, i18n, data, options)
76
- end
77
-
78
- def lie(h, w, x, y, xml, xpath_uf, xpath_ie, options = {})
79
- i18n = xpath_ie.tr('/', '.')
80
-
81
- data = ''
82
- if BrDanfe::Uf.include?(xml[xpath_uf])
83
- ie = BrDocuments::IE::Factory.create(xml[xpath_uf], xml[xpath_ie])
84
- data = ie.formatted if ie.valid?
85
- end
86
-
87
- i18n_lbox(h, w, x, y, i18n, data, options)
88
- end
89
-
90
- def lnumeric(h, w, x, y, xml, xpath, options = {})
91
- i18n = xpath.tr('/', '.')
92
- data = xml[xpath]
93
-
94
- inumeric(h, w, x, y, i18n, data, options)
95
- end
96
-
97
- def inumeric(h, w, x, y, i18n = '', data = '', options = {})
98
- label = i18n != '' ? I18n.t("danfe.#{i18n}") : ''
99
- numeric [x.cm, Helper.invert(y.cm)], w.cm, h.cm, label, data, options
100
- end
101
-
102
- def i18n_lbox(h, w, x, y, i18n = '', info = '', options = {})
103
- label = i18n != '' ? I18n.t("danfe.#{i18n}") : ''
104
- ibox h, w, x, y, label, info, options
105
- end
106
-
107
- private
108
-
109
- def numeric(at, w, h, title = '', info = '', options = {})
110
- info = BrDanfe::Helper.numerify(info) if info != ''
111
- box at, w, h, title, info, options.merge({ align: :right })
112
- end
113
-
114
- def box(at, w, h, title = '', info = '', options = {})
115
- options = {
116
- align: :left,
117
- size: 10,
118
- style: nil,
119
- valign: :top,
120
- border: 1
121
- }.merge(options)
122
-
123
- stroke_rectangle at, w, h if options[:border] == 1
124
-
125
- at[0] += 2
126
-
127
- if title != ''
128
- title_coord = Array.new(at)
129
- title_coord[1] -= 2
130
- text_box title, size: 6, at: title_coord, width: w - 4, height: 8
131
- end
132
-
133
- title_adjustment = title == '' ? 4 : 13
134
- at[1] -= title_adjustment
135
- text_box info, size: options[:size], at: at, width: w - 4, height: h - title_adjustment, align: options[:align],
136
- style: options[:style], valign: options[:valign]
137
- end
138
- end
139
- end
140
- end
@@ -1,53 +0,0 @@
1
- module BrDanfe
2
- module DanfeLib
3
- class Dup
4
- Y = 12.92
5
-
6
- def initialize(pdf, xml)
7
- @pdf = pdf
8
- @xml = xml
9
-
10
- @ltitle = Y - 0.42
11
- end
12
-
13
- def render
14
- @pdf.ititle 0.42, 10.00, 0.75, @ltitle, 'dup.title'
15
- @pdf.ibox 0.85, 19.57, 0.75, Y
16
-
17
- x = 0.75
18
- y = Y
19
- @xml.collect('xmlns', 'dup') do |det|
20
- render_dup(det, x, y)
21
- x += 2.30
22
- end
23
- end
24
-
25
- private
26
-
27
- def render_dup(det, x, y)
28
- @pdf.ibox 0.85, 2.12, x, y, '', I18n.t('danfe.dup.nDup'), italic
29
- @pdf.ibox 0.85, 2.12, x + 0.70, y, '', det.css('nDup').text, normal
30
- @pdf.ibox 0.85, 2.12, x, y + 0.20, '', I18n.t('danfe.dup.dVenc'), italic
31
-
32
- @pdf.ibox 0.85, 2.12, x + 0.70, y + 0.20, '', dtduplicata(det), normal
33
-
34
- @pdf.ibox 0.85, 2.12, x, y + 0.40, '', I18n.t('danfe.dup.vDup'), italic
35
- @pdf.inumeric 0.85, 1.25, x + 0.70, y + 0.40, '', det.css('vDup').text, normal
36
- end
37
-
38
- def dtduplicata(det)
39
- dtduplicata = det.css('dVenc').text
40
- dtduplicata = dtduplicata[8, 2] + '/' + dtduplicata[5, 2] + '/' + dtduplicata[0, 4]
41
- dtduplicata
42
- end
43
-
44
- def normal
45
- { size: 6, border: 0 }
46
- end
47
-
48
- def italic
49
- normal.merge({ style: :italic })
50
- end
51
- end
52
- end
53
- end
@@ -1,115 +0,0 @@
1
- module BrDanfe
2
- module DanfeLib
3
- class EmitHeader
4
- def initialize(pdf, xml, logo, logo_dimensions)
5
- @pdf = pdf
6
- @xml = xml
7
- @logo = logo
8
- @logo_dimensions = logo_dimensions
9
- end
10
-
11
- def render(page, y_position)
12
- @y_position = y_position
13
- company_box
14
- danfe_box page
15
- access_key_box
16
- sefaz_box
17
- render_emit y_position
18
- end
19
-
20
- private
21
-
22
- def company_box
23
- @pdf.ibox 3.92, 7.46, 0.75, @y_position
24
- @pdf.ibox 3.92, 7.46, 0.75, @y_position, '', @xml['emit/xNome'],
25
- { size: 12, align: :center, border: 0, style: :bold }
26
-
27
- address_company
28
- end
29
-
30
- def address_company
31
- if @logo.blank?
32
- @pdf.ibox 3.92, 7.46, 1.25, @y_position + 1.46, '', address, { align: :left, border: 0 }
33
- else
34
- @pdf.ibox 3.92, 7.46, 3.60, @y_position + 1.46, '', address, { size: 8, align: :left, border: 0 }
35
- logo
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
- formatted
45
- end
46
-
47
- def phone
48
- Phone.format(@xml['enderEmit/fone'])
49
- end
50
-
51
- def cep
52
- Cep.format(@xml['enderEmit/CEP'])
53
- end
54
-
55
- def logo
56
- bounding_box_size = 80
57
- logo_options = BrDanfe::Logo::Options.new(bounding_box_size, @logo_dimensions).options
58
-
59
- @pdf.bounding_box(
60
- [0.83.cm, Helper.invert(@y_position.cm + 1.02.cm)], width: bounding_box_size, height: bounding_box_size
61
- ) do
62
- @pdf.image @logo, logo_options
63
- end
64
- end
65
-
66
- def danfe_box(page)
67
- @pdf.ibox 3.92, 2.08, 8.21, @y_position
68
-
69
- @pdf.ibox 0.60, 2.08, 8.21, @y_position, '', 'DANFE',
70
- { size: 12, align: :center, border: 0, style: :bold }
71
-
72
- @pdf.ibox 1.20, 2.08, 8.21, @y_position + 0.60, '', I18n.t('danfe.others.danfe'),
73
- { size: 8, align: :center, border: 0 }
74
-
75
- @pdf.ibox 0.60, 2.08, 8.21, @y_position + 1.80, '',
76
- "#{@xml['ide/tpNF']} - " +
77
- (@xml['ide/tpNF'] == '0' ? I18n.t('danfe.ide.tpNF.entry') : I18n.t('danfe.ide.tpNF.departure')),
78
- { size: 8, align: :center, border: 0 }
79
-
80
- @pdf.ibox 1.00, 2.08, 8.21, @y_position + 2.40, '',
81
- I18n.t('danfe.ide.document', nNF: @xml['ide/nNF'], serie: @xml['ide/serie']),
82
- { size: 8, align: :center, valign: :center, border: 0, style: :bold }
83
-
84
- @pdf.ibox 1.00, 2.08, 8.21, @y_position + 3.00, '',
85
- I18n.t('danfe.others.page', current: page, total: @pdf.page_count),
86
- { size: 8, align: :center, valign: :center, border: 0, style: :bold }
87
- end
88
-
89
- def access_key_box
90
- @pdf.ibox 2.22, 10.02, 10.29, @y_position
91
- @pdf.ibarcode 1.50, 8.00, 10.4010, @y_position + 1.90, @xml['chNFe']
92
- @pdf.ibox 0.85, 10.02, 10.29, @y_position + 2.22, I18n.t('danfe.chNFe'),
93
- @xml['chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, '\\1 '), { style: :bold, align: :center }
94
- end
95
-
96
- def sefaz_box
97
- @pdf.ibox 0.85, 10.02, 10.29, @y_position + 3.07, '', I18n.t('danfe.others.sefaz'),
98
- { align: :center, size: 8 }
99
- end
100
-
101
- def render_emit(y_position)
102
- y_first_line = y_position + 3.92
103
- y_second_line = y_first_line + LINE_HEIGHT
104
-
105
- @pdf.lbox LINE_HEIGHT, 10.04, 0.75, y_first_line, @xml, 'ide/natOp'
106
- @pdf.ibox LINE_HEIGHT, 9.52, 10.79, y_first_line, I18n.t('danfe.infProt'),
107
- "#{@xml['infProt/nProt']} #{BrDanfe::Helper.format_datetime(@xml['infProt/dhRecbto'])}", { align: :center }
108
-
109
- @pdf.lie LINE_HEIGHT, 6.36, 0.75, y_second_line, @xml, 'enderEmit/UF', 'emit/IE'
110
- @pdf.lie LINE_HEIGHT, 6.86, 7.11, y_second_line, @xml, 'enderDest/UF', 'emit/IEST'
111
- @pdf.lcnpj LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, 'emit/CNPJ'
112
- end
113
- end
114
- end
115
- end
@@ -1,61 +0,0 @@
1
- module BrDanfe
2
- module DanfeLib
3
- class Helper
4
- def self.invert(y)
5
- 29.7.cm - y
6
- end
7
-
8
- def self.format_date(xml_datetime)
9
- formated = ''
10
-
11
- unless xml_datetime.empty?
12
- date = DateTime.strptime(xml_datetime, '%Y-%m-%d')
13
- formated = date.strftime('%d/%m/%Y')
14
- end
15
-
16
- formated
17
- end
18
-
19
- def self.format_time(xml_datetime)
20
- formated = ''
21
-
22
- if xml_datetime.length == 8
23
- formated = xml_datetime
24
- elsif xml_datetime.length > 8
25
- date = DateTime.strptime(xml_datetime, '%Y-%m-%dT%H:%M:%S %Z').to_time
26
- formated = date.strftime('%H:%M:%S')
27
- end
28
-
29
- formated
30
- end
31
-
32
- def self.no_fiscal_value?(xml)
33
- BrDanfe::Helper.homologation?(xml) || unauthorized?(xml)
34
- end
35
-
36
- def self.unauthorized?(xml)
37
- xml.css('nfeProc/protNFe/infProt/dhRecbto').empty?
38
- end
39
-
40
- def self.mensure_text(pdf, text)
41
- pdf.width_of(text)
42
- end
43
-
44
- def self.address_is_too_big(pdf, address)
45
- Helper.mensure_text(pdf, address) > Dest::MAXIMUM_SIZE_FOR_STREET
46
- end
47
-
48
- def self.generate_address(xml)
49
- address_complement = " - #{xml_text(xml, 'enderDest/xCpl')}" if xml_text(xml, 'enderDest/xCpl').present?
50
- address_number = " #{xml_text(xml, 'enderDest/nro')}" if xml_text(xml, 'enderDest/nro').present?
51
- "#{xml_text(xml, 'enderDest/xLgr')}#{address_number}#{address_complement}"
52
- end
53
-
54
- def self.xml_text(xml, property)
55
- xml.css(property).text
56
- end
57
-
58
- private_class_method :xml_text
59
- end
60
- end
61
- end
@@ -1,33 +0,0 @@
1
- module BrDanfe
2
- module DanfeLib
3
- class Icmstot
4
- Y = 13.77 + SPACE_BETWEEN_GROUPS
5
-
6
- def initialize(pdf, xml)
7
- @pdf = pdf
8
- @xml = xml
9
-
10
- @ltitle = Y - 0.42
11
- @l1 = Y
12
- @l2 = Y + LINE_HEIGHT
13
- end
14
-
15
- def render
16
- @pdf.ititle 0.42, 5.60, 0.75, @ltitle, 'ICMSTot.title'
17
-
18
- @pdf.lnumeric LINE_HEIGHT, 3.56, 0.75, @l1, @xml, 'ICMSTot/vBC'
19
- @pdf.lnumeric LINE_HEIGHT, 4.06, 4.31, @l1, @xml, 'ICMSTot/vICMS'
20
- @pdf.lnumeric LINE_HEIGHT, 4.06, 8.37, @l1, @xml, 'ICMSTot/vBCST'
21
- @pdf.lnumeric LINE_HEIGHT, 4.06, 12.43, @l1, @xml, 'ICMSTot/vST'
22
- @pdf.lnumeric LINE_HEIGHT, 3.82, 16.49, @l1, @xml, 'ICMSTot/vProd'
23
-
24
- @pdf.lnumeric LINE_HEIGHT, 2.55, 0.75, @l2, @xml, 'ICMSTot/vFrete'
25
- @pdf.lnumeric LINE_HEIGHT, 3.05, 3.30, @l2, @xml, 'ICMSTot/vSeg'
26
- @pdf.lnumeric LINE_HEIGHT, 3.04, 6.35, @l2, @xml, 'ICMSTot/vDesc'
27
- @pdf.lnumeric LINE_HEIGHT, 3.04, 9.39, @l2, @xml, 'ICMSTot/vOutro'
28
- @pdf.lnumeric LINE_HEIGHT, 4.06, 12.43, @l2, @xml, 'ICMSTot/vIPI'
29
- @pdf.lnumeric LINE_HEIGHT, 3.82, 16.49, @l2, @xml, 'ICMSTot/vNF', style: :bold
30
- end
31
- end
32
- end
33
- end
@@ -1,107 +0,0 @@
1
- module BrDanfe
2
- module DanfeLib
3
- class Infadic
4
- Y_POSITION = 27.04 + SPACE_BETWEEN_GROUPS
5
-
6
- def initialize(pdf, xml)
7
- @pdf = pdf
8
- @xml = xml
9
- @title_position = Y_POSITION - 0.41
10
- @y_position = Y_POSITION
11
- end
12
-
13
- def render(volumes_number)
14
- render_title
15
- render_subtitle
16
- render_volumes if volumes_number > 1
17
- render_additional_data generate_y_position(volumes_number) if additional_data?
18
- render_reserved_fisco
19
- end
20
-
21
- private
22
-
23
- def render_title
24
- @pdf.ititle 0.42, 10.00, 0.75, @title_position, 'infAdic.title'
25
- end
26
-
27
- def render_subtitle
28
- @pdf.ibox 2.65, 12.45, 0.75, @y_position, I18n.t('danfe.infAdic.infCpl'), '', size: 8, valign: :top
29
- end
30
-
31
- def render_volumes
32
- InfadicVol.new(@xml, @pdf).render
33
- end
34
-
35
- def render_additional_data(y_position)
36
- data = generate_additional_data
37
- @pdf.ibox 2.65, 12.45, 0.75, y_position, '', data, { size: 6, valign: :top, border: 0 }
38
- end
39
-
40
- def generate_additional_data
41
- additional_data = []
42
- additional_data.push(complementary_content) if complementary?
43
- additional_data.push(address_content) if address?
44
- additional_data.push(difal_content) if difal?
45
- additional_data.push(fisco_content) if fisco?
46
- additional_data.join(' * ')
47
- end
48
-
49
- def complementary_content
50
- @xml['infAdic/infCpl'].to_s
51
- end
52
-
53
- def complementary?
54
- @xml['infAdic/infCpl'].to_s != ''
55
- end
56
-
57
- def address_content
58
- "Endereço: #{Helper.generate_address @xml}"
59
- end
60
-
61
- def address?
62
- Helper.address_is_too_big @pdf, Helper.generate_address(@xml)
63
- end
64
-
65
- def difal_content
66
- I18n.t(
67
- 'danfe.infAdic.difal',
68
- vICMSUFDest: numerify(@xml['ICMSTot/vICMSUFDest']),
69
- vFCPUFDest: numerify(@xml['ICMSTot/vFCPUFDest']),
70
- vICMSUFRemet: numerify(@xml['ICMSTot/vICMSUFRemet'])
71
- )
72
- end
73
-
74
- def numerify(value)
75
- BrDanfe::Helper.numerify(value) if value != ''
76
- end
77
-
78
- def difal?
79
- @xml['ICMSTot/vICMSUFDest'].to_f != 0
80
- end
81
-
82
- def fisco_content
83
- @xml['infAdic/infAdFisco'].to_s
84
- end
85
-
86
- def fisco?
87
- @xml['infAdic/infAdFisco'].to_s.present?
88
- end
89
-
90
- def generate_y_position(volumes_number)
91
- if volumes_number > 1
92
- return Y_POSITION + 0.30 + volumes_number * 0.15 + 0.2
93
- end
94
-
95
- Y_POSITION + 0.30
96
- end
97
-
98
- def additional_data?
99
- complementary? || address? || difal? || fisco?
100
- end
101
-
102
- def render_reserved_fisco
103
- @pdf.ibox 2.65, 7.15, 13.20, @y_position, I18n.t('danfe.infAdic.reserved')
104
- end
105
- end
106
- end
107
- end