br_danfe 0.11.2 → 0.12.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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/Gemfile.lock +31 -31
  4. data/br_danfe.gemspec +6 -5
  5. data/config/locales/pt-BR.yml +8 -0
  6. data/lib/br_danfe/danfe.rb +2 -2
  7. data/lib/br_danfe/danfe_lib/det_body.rb +1 -1
  8. data/lib/br_danfe/danfe_lib/document.rb +1 -1
  9. data/lib/br_danfe/danfe_lib/emit_header.rb +2 -2
  10. data/lib/br_danfe/danfe_lib/helper.rb +1 -27
  11. data/lib/br_danfe/danfe_lib/infadic.rb +1 -1
  12. data/lib/br_danfe/danfe_lib/xprod.rb +15 -15
  13. data/lib/br_danfe/danfe_nfce.rb +43 -0
  14. data/lib/br_danfe/danfe_nfce_lib/document.rb +35 -0
  15. data/lib/br_danfe/danfe_nfce_lib/footer.rb +15 -0
  16. data/lib/br_danfe/danfe_nfce_lib/header.rb +67 -0
  17. data/lib/br_danfe/danfe_nfce_lib/helper.rb +9 -0
  18. data/lib/br_danfe/danfe_nfce_lib/key.rb +18 -0
  19. data/lib/br_danfe/danfe_nfce_lib/nfce_identification.rb +20 -0
  20. data/lib/br_danfe/danfe_nfce_lib/product_list.rb +100 -0
  21. data/lib/br_danfe/danfe_nfce_lib/qr_code.rb +23 -0
  22. data/lib/br_danfe/danfe_nfce_lib/recipient.rb +72 -0
  23. data/lib/br_danfe/danfe_nfce_lib/total_list.rb +78 -0
  24. data/lib/br_danfe/helper.rb +29 -0
  25. data/lib/br_danfe/{danfe_lib/options.rb → logo_config.rb} +2 -2
  26. data/lib/br_danfe/{danfe_lib/logo_options.rb → logo_options.rb} +2 -2
  27. data/lib/br_danfe/version.rb +1 -1
  28. data/lib/br_danfe/xml.rb +36 -0
  29. data/spec/features/danfe_nfce_spec.rb +31 -0
  30. data/spec/fixtures/nfce/lib/document#render.pdf +99 -0
  31. data/spec/fixtures/nfce/lib/footer#render.pdf +74 -0
  32. data/spec/fixtures/nfce/lib/header#render-homologation.pdf +0 -0
  33. data/spec/fixtures/nfce/lib/header#render-long_name_with_logo.pdf +0 -0
  34. data/spec/fixtures/nfce/lib/header#render-long_name_without_logo.pdf +118 -0
  35. data/spec/fixtures/nfce/lib/header#render-short_name_with_logo.pdf +0 -0
  36. data/spec/fixtures/nfce/lib/header#render-short_name_without_logo.pdf +118 -0
  37. data/spec/fixtures/nfce/lib/key#render.pdf +104 -0
  38. data/spec/fixtures/nfce/lib/nfce_identification#render.pdf +118 -0
  39. data/spec/fixtures/nfce/lib/product_list#render-with_many_products.pdf +307 -0
  40. data/spec/fixtures/nfce/lib/product_list#render-with_many_products_and_long_names.pdf +335 -0
  41. data/spec/fixtures/nfce/lib/product_list#render-with_single_product.pdf +181 -0
  42. data/spec/fixtures/nfce/lib/product_list#render-with_single_product_and_long_name.pdf +195 -0
  43. data/spec/fixtures/nfce/lib/product_list_with_many_products.xml +367 -0
  44. data/spec/fixtures/nfce/lib/product_list_with_many_products_and_long_names.xml +367 -0
  45. data/spec/fixtures/nfce/lib/product_list_with_single_product.xml +238 -0
  46. data/spec/fixtures/nfce/lib/product_list_with_single_product_and_long_name.xml +238 -0
  47. data/spec/fixtures/nfce/lib/qr_code#render.pdf +0 -0
  48. data/spec/fixtures/nfce/lib/recipient#render-company.pdf +95 -0
  49. data/spec/fixtures/nfce/lib/recipient#render-consumer_without_document.pdf +88 -0
  50. data/spec/fixtures/nfce/lib/recipient#render-foreign.pdf +95 -0
  51. data/spec/fixtures/nfce/lib/recipient#render-individual.pdf +95 -0
  52. data/spec/fixtures/nfce/lib/recipient#render-unidentified_consumer.pdf +81 -0
  53. data/spec/fixtures/nfce/lib/total_list#does_not_render-payment_methods.pdf +139 -0
  54. data/spec/fixtures/nfce/lib/total_list#render-grouped_payment_methods.pdf +188 -0
  55. data/spec/fixtures/nfce/lib/total_list#render-totals.pdf +139 -0
  56. data/spec/fixtures/nfce/lib/total_list#render-without_payment.pdf +202 -0
  57. data/spec/fixtures/nfce/lib/total_list#render.pdf +202 -0
  58. data/spec/fixtures/nfce/v4.00/nfce.xml +367 -0
  59. data/spec/fixtures/nfce/v4.00/rendered_nfce.fixture.pdf +0 -0
  60. data/spec/fixtures/nfce/v4.00/saved_nfce.fixture.pdf +0 -0
  61. data/spec/lib/danfe_lib/dest_spec.rb +1 -1
  62. data/spec/lib/danfe_lib/det_body_spec.rb +1 -1
  63. data/spec/lib/danfe_lib/document_spec.rb +1 -1
  64. data/spec/lib/danfe_lib/dup_spec.rb +1 -1
  65. data/spec/lib/danfe_lib/emit_header_spec.rb +1 -1
  66. data/spec/lib/danfe_lib/helper_spec.rb +0 -54
  67. data/spec/lib/danfe_lib/icmstot_spec.rb +1 -1
  68. data/spec/lib/danfe_lib/infadic_spec.rb +1 -1
  69. data/spec/lib/danfe_lib/infadic_vol_spec.rb +1 -1
  70. data/spec/lib/danfe_lib/issqn_spec.rb +1 -1
  71. data/spec/lib/danfe_lib/ticket_spec.rb +1 -1
  72. data/spec/lib/danfe_lib/transp_spec.rb +1 -1
  73. data/spec/lib/danfe_lib/vol_spec.rb +1 -1
  74. data/spec/lib/danfe_nfce_lib/document_spec.rb +19 -0
  75. data/spec/lib/danfe_nfce_lib/footer_spec.rb +42 -0
  76. data/spec/lib/danfe_nfce_lib/header_spec.rb +117 -0
  77. data/spec/lib/danfe_nfce_lib/helper_spec.rb +28 -0
  78. data/spec/lib/danfe_nfce_lib/key_spec.rb +45 -0
  79. data/spec/lib/danfe_nfce_lib/nfce_identification_spec.rb +48 -0
  80. data/spec/lib/danfe_nfce_lib/product_list_spec.rb +66 -0
  81. data/spec/lib/danfe_nfce_lib/qr_code_spec.rb +35 -0
  82. data/spec/lib/danfe_nfce_lib/recipient_spec.rb +163 -0
  83. data/spec/lib/danfe_nfce_lib/total_list_spec.rb +188 -0
  84. data/spec/lib/helper_spec.rb +102 -0
  85. data/spec/lib/logo_config_spec.rb +21 -0
  86. data/spec/lib/{danfe_lib/logo_options_spec.rb → logo_options_spec.rb} +8 -22
  87. data/spec/lib/{danfe_lib/xml_spec.rb → xml_spec.rb} +2 -2
  88. metadata +87 -18
  89. data/lib/br_danfe/danfe_lib/xml.rb +0 -38
  90. data/spec/lib/danfe_lib/options_spec.rb +0 -17
@@ -0,0 +1,163 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrDanfe::DanfeNfceLib::Recipient do
4
+ let(:base_dir) { './spec/fixtures/nfce/lib/' }
5
+ let(:output_pdf) { "#{base_dir}output.pdf" }
6
+
7
+ let(:pdf) { BrDanfe::DanfeNfceLib::Document.new(8.cm, 5.cm) }
8
+ let(:xml_recipient) { BrDanfe::XML.new(xml_as_string) }
9
+
10
+ subject { described_class.new pdf, xml_recipient }
11
+
12
+ describe '#render' do
13
+ before do
14
+ subject.render
15
+ File.delete(output_pdf) if File.exist?(output_pdf)
16
+ end
17
+
18
+ context 'when has identified recipient' do
19
+ context 'when the recipient is a company' do
20
+ let(:xml_as_string) do
21
+ xml = <<-eos
22
+ <nfeProc>
23
+ <NFe>
24
+ <dest>
25
+ <CNPJ>18191228000171</CNPJ>
26
+ <xNome>John Doe</xNome>
27
+ <enderDest>
28
+ <xLgr>Av. Bayer Filho</xLgr>
29
+ <nro>1999</nro>
30
+ <xBairro>Centro</xBairro>
31
+ <xMun>Tijucas</xMun>
32
+ <UF>SC</UF>
33
+ </enderDest>
34
+ </dest>
35
+ </NFe>
36
+ </nfeProc>
37
+ eos
38
+ end
39
+
40
+ it 'renders the CNPJ and company informations' do
41
+ expect(File.exist?(output_pdf)).to be_falsey
42
+ pdf.render_file output_pdf
43
+
44
+ expect("#{base_dir}recipient#render-company.pdf").to have_same_content_of file: output_pdf
45
+ end
46
+ end
47
+
48
+ context 'when the recipient is an individual person' do
49
+ let(:xml_as_string) do
50
+ xml = <<-eos
51
+ <nfeProc>
52
+ <NFe>
53
+ <dest>
54
+ <CPF>37626406028</CPF>
55
+ <xNome>John Doe</xNome>
56
+ <enderDest>
57
+ <xLgr>Av. Bayer Filho</xLgr>
58
+ <nro>1999</nro>
59
+ <xBairro>Centro</xBairro>
60
+ <xMun>Tijucas</xMun>
61
+ <UF>SC</UF>
62
+ </enderDest>
63
+ </dest>
64
+ </NFe>
65
+ </nfeProc>
66
+ eos
67
+ end
68
+
69
+ it 'renders the CPF and individual informations' do
70
+ expect(File.exist?(output_pdf)).to be_falsey
71
+ pdf.render_file output_pdf
72
+
73
+ expect("#{base_dir}recipient#render-individual.pdf").to have_same_content_of file: output_pdf
74
+ end
75
+ end
76
+
77
+ context 'when the recipient is a foreign' do
78
+ let(:xml_as_string) do
79
+ xml = <<-eos
80
+ <nfeProc>
81
+ <NFe>
82
+ <dest>
83
+ <idEstrangeiro>123456789</idEstrangeiro>
84
+ <xNome>John Doe</xNome>
85
+ <enderDest>
86
+ <xLgr>Av. Bayer Filho</xLgr>
87
+ <nro>1999</nro>
88
+ <xBairro>Centro</xBairro>
89
+ <xMun>Tijucas</xMun>
90
+ <UF>SC</UF>
91
+ </enderDest>
92
+ </dest>
93
+ </NFe>
94
+ </nfeProc>
95
+ eos
96
+ end
97
+
98
+ it 'renders the ID Estrangeiro and foreign informations' do
99
+ expect(File.exist?(output_pdf)).to be_falsey
100
+ pdf.render_file output_pdf
101
+
102
+ expect("#{base_dir}recipient#render-foreign.pdf").to have_same_content_of file: output_pdf
103
+ end
104
+ end
105
+
106
+ context 'when the recipient does not have document' do
107
+ let(:xml_as_string) do
108
+ xml = <<-eos
109
+ <nfeProc>
110
+ <NFe>
111
+ <dest>
112
+ <xNome>John Doe</xNome>
113
+ <enderDest>
114
+ <xLgr>Av. Bayer Filho</xLgr>
115
+ <nro>1999</nro>
116
+ <xBairro>Centro</xBairro>
117
+ <xMun>Tijucas</xMun>
118
+ <UF>SC</UF>
119
+ </enderDest>
120
+ </dest>
121
+ </NFe>
122
+ </nfeProc>
123
+ eos
124
+ end
125
+
126
+ it 'renders the name and the address of the consumer' do
127
+ expect(File.exist?(output_pdf)).to be_falsey
128
+ pdf.render_file output_pdf
129
+
130
+ expect("#{base_dir}recipient#render-consumer_without_document.pdf").to have_same_content_of file: output_pdf
131
+ end
132
+ end
133
+ end
134
+
135
+ context 'when does not have identified recipient' do
136
+ let(:xml_as_string) do
137
+ xml = <<-eos
138
+ <nfeProc>
139
+ <NFe>
140
+ <dest>
141
+ <CNPJ>18191228000171</CNPJ>
142
+ <enderDest>
143
+ <xLgr>Rua Tijucas</xLgr>
144
+ <nro>99</nro>
145
+ <xBairro>Centro</xBairro>
146
+ <xMun>TIJUCAS</xMun>
147
+ <UF>SC</UF>
148
+ </enderDest>
149
+ </dest>
150
+ </NFe>
151
+ </nfeProc>
152
+ eos
153
+ end
154
+
155
+ it 'renders unidentified consumer' do
156
+ expect(File.exist?(output_pdf)).to be_falsey
157
+ pdf.render_file output_pdf
158
+
159
+ expect("#{base_dir}recipient#render-unidentified_consumer.pdf").to have_same_content_of file: output_pdf
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,188 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrDanfe::DanfeNfceLib::TotalList do
4
+ let(:base_dir) { './spec/fixtures/nfce/lib/' }
5
+ let(:output_pdf) { "#{base_dir}output.pdf" }
6
+
7
+ let(:pdf) { BrDanfe::DanfeNfceLib::Document.new(8.cm, 5.cm) }
8
+ let(:payment_xml) do
9
+ <<-eos
10
+ <pag>
11
+ <detPag>
12
+ <tPag>01</tPag>
13
+ <vPag>10.00</vPag>
14
+ </detPag>
15
+ <detPag>
16
+ <tPag>02</tPag>
17
+ <vPag>15.30</vPag>
18
+ </detPag>
19
+ <detPag>
20
+ <tPag>05</tPag>
21
+ <vPag>66.70</vPag>
22
+ </detPag>
23
+ </pag>
24
+ eos
25
+ end
26
+ let(:xml_as_string) do
27
+ xml = <<-eos
28
+ <nfeProc>
29
+ <NFe>
30
+ <infNFe>
31
+ <det nItem="1"></det>
32
+ <det nItem="2"></det>
33
+ <det nItem="3"></det>
34
+ <det nItem="4"></det>
35
+ <total>
36
+ <ICMSTot>
37
+ <vProd>104.00</vProd>
38
+ <vDesc>12.00</vDesc>
39
+ <vNF>92.00</vNF>
40
+ </ICMSTot>
41
+ </total>
42
+ #{payment_xml}
43
+ </infNFe>
44
+ </NFe>
45
+ </nfeProc>
46
+ eos
47
+ end
48
+ let(:xml_total_list) { BrDanfe::XML.new(xml_as_string) }
49
+
50
+ subject { described_class.new pdf, xml_total_list }
51
+
52
+ describe '#render' do
53
+ before do
54
+ subject.render
55
+ File.delete(output_pdf) if File.exist?(output_pdf)
56
+ end
57
+
58
+ it 'renders the total list' do
59
+ expect(File.exist?(output_pdf)).to be_falsey
60
+ pdf.render_file output_pdf
61
+
62
+ expect("#{base_dir}total_list#render.pdf").to have_same_content_of file: output_pdf
63
+ end
64
+
65
+ describe 'about totals' do
66
+ let(:xml_as_string) do
67
+ xml = <<-eos
68
+ <nfeProc>
69
+ <NFe>
70
+ <infNFe>
71
+ <det nItem="1"></det>
72
+ <det nItem="2"></det>
73
+ <det nItem="3"></det>
74
+ <det nItem="4"></det>
75
+ <total>
76
+ <ICMSTot>
77
+ <vProd>104.00</vProd>
78
+ <vDesc>12.00</vDesc>
79
+ <vNF>92.00</vNF>
80
+ </ICMSTot>
81
+ </total>
82
+ </infNFe>
83
+ </NFe>
84
+ </nfeProc>
85
+ eos
86
+ end
87
+
88
+ it 'renders the totals' do
89
+ expect(File.exist?(output_pdf)).to be_falsey
90
+ pdf.render_file output_pdf
91
+
92
+ expect("#{base_dir}total_list#render-totals.pdf").to have_same_content_of file: output_pdf
93
+ end
94
+ end
95
+
96
+ describe 'about payment methods' do
97
+ let(:payment_xml) do
98
+ <<-eos
99
+ <pag>
100
+ <detPag>
101
+ <tPag>01</tPag>
102
+ <vPag>10.00</vPag>
103
+ </detPag>
104
+ <detPag>
105
+ <tPag>02</tPag>
106
+ <vPag>15.30</vPag>
107
+ </detPag>
108
+ <detPag>
109
+ <tPag>05</tPag>
110
+ <vPag>66.70</vPag>
111
+ </detPag>
112
+ <detPag>
113
+ <tPag>90</tPag>
114
+ <vPag>1.99</vPag>
115
+ </detPag>
116
+ </pag>
117
+ eos
118
+ end
119
+
120
+ it 'does not render the ""without payment"" payment method ' do
121
+ expect(File.exist?(output_pdf)).to be_falsey
122
+ pdf.render_file output_pdf
123
+
124
+ expect("#{base_dir}total_list#render-without_payment.pdf").to have_same_content_of file: output_pdf
125
+ end
126
+
127
+ context 'when there are repeated payment methods' do
128
+ let(:payment_xml) do
129
+ <<-eos
130
+ <pag>
131
+ <detPag>
132
+ <tPag>01</tPag>
133
+ <vPag>10.00</vPag>
134
+ </detPag>
135
+ <detPag>
136
+ <tPag>01</tPag>
137
+ <vPag>30.00</vPag>
138
+ </detPag>
139
+ <detPag>
140
+ <tPag>02</tPag>
141
+ <vPag>25.50</vPag>
142
+ </detPag>
143
+ <detPag>
144
+ <tPag>02</tPag>
145
+ <vPag>26.50</vPag>
146
+ </detPag>
147
+ </pag>
148
+ eos
149
+ end
150
+
151
+ it 'renders grouped payment methods' do
152
+ expect(File.exist?(output_pdf)).to be_falsey
153
+ pdf.render_file output_pdf
154
+
155
+ expect("#{base_dir}total_list#render-grouped_payment_methods.pdf").to have_same_content_of file: output_pdf
156
+ end
157
+ end
158
+
159
+ context 'when there are only "without payment" payment methods' do
160
+ let(:payment_xml) do
161
+ <<-eos
162
+ <pag>
163
+ <detPag>
164
+ <tPag>90</tPag>
165
+ <vPag>10.00</vPag>
166
+ </detPag>
167
+ <detPag>
168
+ <tPag>90</tPag>
169
+ <vPag>15.30</vPag>
170
+ </detPag>
171
+ <detPag>
172
+ <tPag>90</tPag>
173
+ <vPag>66.70</vPag>
174
+ </detPag>
175
+ </pag>
176
+ eos
177
+ end
178
+
179
+ it 'does not render payment methods' do
180
+ expect(File.exist?(output_pdf)).to be_falsey
181
+ pdf.render_file output_pdf
182
+
183
+ expect("#{base_dir}total_list#does_not_render-payment_methods.pdf").to have_same_content_of file: output_pdf
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrDanfe::Helper do
4
+ describe '.homologation?' do
5
+ context 'when tpAmb is equal to "2"' do
6
+ let(:xml_homologation) do
7
+ xml = <<-eos
8
+ <nfeProc>
9
+ <NFe>
10
+ <infNFe>
11
+ <ide>
12
+ <tpAmb>2</tpAmb>
13
+ </ide>
14
+ </infNFe>
15
+ </NFe>
16
+ </nfeProc>
17
+ eos
18
+
19
+ Nokogiri::XML(xml)
20
+ end
21
+
22
+ it 'returns true' do
23
+ expect(described_class.homologation?(xml_homologation)).to be true
24
+ end
25
+ end
26
+
27
+ context 'when tpAmb is different to "2"' do
28
+ let(:xml_production) do
29
+ xml = <<-eos
30
+ <nfeProc>
31
+ <NFe>
32
+ <infNFe>
33
+ <ide>
34
+ <tpAmb>1</tpAmb>
35
+ </ide>
36
+ </infNFe>
37
+ </NFe>
38
+ </nfeProc>
39
+ eos
40
+
41
+ Nokogiri::XML(xml)
42
+ end
43
+
44
+ it 'returns true' do
45
+ expect(described_class.homologation?(xml_production)).to be false
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '.numerify' do
51
+ it 'formats with the decimals' do
52
+ expect(described_class.numerify(0.123)).to eql '0,123'
53
+ expect(described_class.numerify(0.1234)).to eql '0,1234'
54
+ expect(described_class.numerify(0.12345)).to eql '0,12345'
55
+ expect(described_class.numerify(0.1234567891)).to eql '0,1234567891'
56
+ end
57
+
58
+ it 'formats integers' do
59
+ expect(described_class.numerify(100)).to eql '100,00'
60
+ end
61
+
62
+ it 'formats decimals' do
63
+ expect(described_class.numerify(123.45)).to eql '123,45'
64
+ end
65
+
66
+ it 'formats thousands' do
67
+ expect(described_class.numerify(1000)).to eql '1.000,00'
68
+ end
69
+
70
+ it 'formats millions' do
71
+ expect(described_class.numerify(1_000_000)).to eql '1.000.000,00'
72
+ end
73
+
74
+ it 'formats using two as min decimal precision' do
75
+ expect(described_class.numerify(123.4)).to eql '123,40'
76
+ end
77
+
78
+ it 'formats 0 to 0,00' do
79
+ expect(described_class.numerify(0)).to eql '0,00'
80
+ end
81
+
82
+ it 'does not format nil value' do
83
+ expect(described_class.numerify(nil)).to eql ''
84
+ end
85
+
86
+ it 'does not format blank value' do
87
+ expect(described_class.numerify('')).to eql ''
88
+ end
89
+ end
90
+
91
+ describe '.format_datetime' do
92
+ it 'returns a formated string' do
93
+ expect(described_class.format_datetime('2013-10-18T13:54:04')).to eql '18/10/2013 13:54:04'
94
+ end
95
+
96
+ describe 'when the source is blank' do
97
+ it 'is empty' do
98
+ expect(described_class.format_datetime('')).to eql ''
99
+ end
100
+ end
101
+ end
102
+ end