br_danfe 2.0.0 → 2.1.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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/config.yml +3 -5
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +5 -1
  5. data/config/locales/pt-BR.yml +4 -3
  6. data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +2 -10
  7. data/lib/br_danfe/danfe_lib/nfe_lib/document.rb +5 -5
  8. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +9 -1
  9. data/lib/br_danfe/danfe_lib/nfe_lib/entrega.rb +2 -10
  10. data/lib/br_danfe/danfe_lib/nfe_lib/transp.rb +1 -1
  11. data/lib/br_danfe/version.rb +1 -1
  12. data/spec/br_danfe/danfe_lib/nfe_lib/document_spec.rb +7 -7
  13. data/spec/br_danfe/danfe_lib/nfe_lib/emit_header_spec.rb +63 -0
  14. data/spec/fixtures/nfe/lib/emit_header#render-nfe_key.pdf +16 -16
  15. data/spec/fixtures/nfe/lib/emit_header#render-second_page.pdf +16 -16
  16. data/spec/fixtures/nfe/lib/emit_header#render-with_cpf.pdf +1075 -2
  17. data/spec/fixtures/nfe/lib/emit_header#render-with_logo.pdf +16 -16
  18. data/spec/fixtures/nfe/lib/emit_header#render-without_logo.pdf +14 -14
  19. data/spec/fixtures/nfe/lib/entrega#render-v2.00.pdf +0 -0
  20. data/spec/fixtures/nfe/lib/entrega#render-with-address-bigger.pdf +0 -0
  21. data/spec/fixtures/nfe/lib/entrega#render-with_cpf.pdf +0 -0
  22. data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +17 -17
  23. data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +15 -15
  24. data/spec/fixtures/nfe/v2.00/nfe_with_entrega.xml.fixture.pdf +16 -16
  25. data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +24 -24
  26. data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +15 -15
  27. data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +19 -19
  28. data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +15 -15
  29. data/spec/fixtures/nfe/v3.10/multiples.xmls.on.the.same.pdf.pdf +19 -19
  30. data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +15 -15
  31. data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +19 -19
  32. data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +15 -15
  33. data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +23 -23
  34. data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +19 -19
  35. data/spec/spec_helper.rb +9 -1
  36. metadata +6 -5
  37. /data/spec/fixtures/nfe/lib/{document#lcnpj-blank.pdf → document#lcnpj_cpf-blank.pdf} +0 -0
  38. /data/spec/fixtures/nfe/lib/{document#lcnpj-invalid.pdf → document#lcnpj_cpf-invalid.pdf} +0 -0
  39. /data/spec/fixtures/nfe/lib/{document#lcnpj-valid.pdf → document#lcnpj_cpf-valid.pdf} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6957c52fda8133d7dbb9ddf4ae9f29f20bb45bb6ec41127c546ae93bd2221f2c
4
- data.tar.gz: 2b5031a95eb542e75f457723dee23d193f8f3407d22ba26dd85ded6400f55c35
3
+ metadata.gz: 262bed0c378422071afeb0a12ce50e4c4f4a5633266dd7893f2d0c280316a55e
4
+ data.tar.gz: 412bdf1269d5d8c542d1ce5504e3b219621215da71019c3e37b0441ddb06d28f
5
5
  SHA512:
6
- metadata.gz: 5ec5cf3a1c2ded1acc9c010c440328052a6a9660f1aaddd0bf1dcd1b1ea7ddd42f356ca433462743bb2f5443d75fd383f91d8aba8437f8fbc183f24c78a4f017
7
- data.tar.gz: 49b1f817299513b9ba693b2b19bb0d23971578c433193e980824046ae9900a69d63207b422f93046d9c68dba14874a9414c8e8039598baf6c478fce8f384cc9f
6
+ metadata.gz: 811c26b219e61e7a125e9c212ee3750c3ab6016ae6937456397acafd9dce1a03da762f2f50b645b8784ed6c6f8334159933f9aae7b681857e9b439816936cc51
7
+ data.tar.gz: f396a32db9d675a68b87d62aa12d412e73930251c6278d3361cd34db6b7ba7a76048f4c8250335663dca19bac263dddde56f1a6a7506855469a8b715d09daa13
@@ -38,12 +38,10 @@ jobs:
38
38
  bundler-cache: true
39
39
 
40
40
  - run: |
41
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
42
- chmod +x ./cc-test-reporter
41
+ curl https://qlty.sh | sh
43
42
 
44
43
  - run: |
45
- ./cc-test-reporter before-build
46
44
  bundle exec rspec
47
- ./cc-test-reporter after-build -r $CC_TEST_REPORTER_ID --exit-code $?
45
+ ~/.qlty/bin/qlty coverage publish coverage/coverage.json
48
46
  env:
49
- CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
47
+ QLTY_COVERAGE_TOKEN: ${{secrets.QLTY_COVERAGE_TOKEN}}
data/Gemfile CHANGED
@@ -14,4 +14,5 @@ group :development, :test do
14
14
  gem 'rubocop-rspec', '~> 2.25.0'
15
15
  gem 'simplecov', '0.22.0'
16
16
  gem 'simplecov-html', '0.13.1'
17
+ gem 'simplecov-json', '0.2.3'
17
18
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_danfe (2.0.0)
4
+ br_danfe (2.1.0)
5
5
  barby (= 0.6.9)
6
6
  br_documents (>= 0.1.3)
7
7
  i18n (>= 0.8.6)
@@ -164,6 +164,9 @@ GEM
164
164
  simplecov-html (~> 0.11)
165
165
  simplecov_json_formatter (~> 0.1)
166
166
  simplecov-html (0.13.1)
167
+ simplecov-json (0.2.3)
168
+ json
169
+ simplecov
167
170
  simplecov_json_formatter (0.1.4)
168
171
  thor (1.3.2)
169
172
  ttfunk (1.8.0)
@@ -190,6 +193,7 @@ DEPENDENCIES
190
193
  rubocop-rspec (~> 2.25.0)
191
194
  simplecov (= 0.22.0)
192
195
  simplecov-html (= 0.13.1)
196
+ simplecov-json (= 0.2.3)
193
197
 
194
198
  BUNDLED WITH
195
199
  2.5.5
@@ -47,7 +47,8 @@ pt-BR:
47
47
  IM: "INSCRIÇÃO MUNICIPAL"
48
48
  IE: "INSCRIÇÃO ESTADUAL"
49
49
  IEST: "INSC.ESTADUAL DO SUBST. TRIBUTÁRIO"
50
- CNPJ: "CNPJ"
50
+ CNPJ: "CNPJ/CPF"
51
+ CPF: "CNPJ/CPF"
51
52
  dup:
52
53
  title: "FATURA / DUPLICATAS"
53
54
  nDup: "NRO"
@@ -146,8 +147,8 @@ pt-BR:
146
147
  document: "NF-e\nN°. %{nNF}\nSÉRIE %{serie}"
147
148
  entrega:
148
149
  title: "INFORMAÇÕES DO LOCAL DE ENTREGA"
149
- CNPJ: "CNPJ"
150
- CPF: "CPF"
150
+ CNPJ: "CNPJ/CPF"
151
+ CPF: "CNPJ/CPF"
151
152
  xNome: "NOME/RAZÃO SOCIAL"
152
153
  xLgr: "ENDEREÇO"
153
154
  nro: "NÚMERO"
@@ -34,16 +34,8 @@ module BrDanfe
34
34
  end
35
35
 
36
36
  def render_cnpj_cpf
37
- if @xml['dest/CNPJ'] == ''
38
- @pdf.i18n_lbox LINE_HEIGHT, 4.37, 12.57, @l1, 'dest.CPF', cpf
39
- else
40
- @pdf.lcnpj LINE_HEIGHT, 4.37, 12.57, @l1, @xml, 'dest/CNPJ'
41
- end
42
- end
43
-
44
- def cpf
45
- cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['dest/CPF'])
46
- cpf.formatted
37
+ xpath = @xml['dest/CNPJ'].present? ? 'dest/CNPJ' : 'dest/CPF'
38
+ @pdf.lcnpj_cpf LINE_HEIGHT, 4.37, 12.57, @l1, @xml, xpath
47
39
  end
48
40
 
49
41
  def render_line2
@@ -64,12 +64,12 @@ module BrDanfe
64
64
  i18n_lbox(h, w, x, y, i18n, data, options)
65
65
  end
66
66
 
67
- def lcnpj(h, w, x, y, xml, xpath, options = {})
67
+ def lcnpj_cpf(h, w, x, y, xml, xpath, options = {})
68
68
  i18n = xpath.tr('/', '.')
69
-
70
- cnpj = BrDocuments::CnpjCpf::Cnpj.new(xml[xpath])
71
- data = if cnpj.valid?
72
- cnpj.formatted
69
+ document_class = xpath.include?('CNPJ') ? BrDocuments::CnpjCpf::Cnpj : BrDocuments::CnpjCpf::Cpf
70
+ cnpj_cpf = document_class.new(xml[xpath])
71
+ data = if cnpj_cpf.valid?
72
+ cnpj_cpf.formatted
73
73
  else
74
74
  ''
75
75
  end
@@ -108,7 +108,15 @@ module BrDanfe
108
108
 
109
109
  @pdf.lie LINE_HEIGHT, 6.36, 0.75, y_second_line, @xml, 'enderEmit/UF', 'emit/IE'
110
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'
111
+ @pdf.lcnpj_cpf LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, cnpj_cpf
112
+ end
113
+
114
+ def cnpj_cpf
115
+ if @xml['emit/CNPJ'].present?
116
+ 'emit/CNPJ'
117
+ else
118
+ 'emit/CPF'
119
+ end
112
120
  end
113
121
  end
114
122
  end
@@ -39,16 +39,8 @@ module BrDanfe
39
39
  end
40
40
 
41
41
  def render_cnpj_cpf
42
- if @xml['entrega/CNPJ'] == ''
43
- @pdf.i18n_lbox LINE_HEIGHT, 4.37, 12.57, @l1, 'entrega.CPF', cpf
44
- else
45
- @pdf.lcnpj LINE_HEIGHT, 4.37, 12.57, @l1, @xml, 'entrega/CNPJ'
46
- end
47
- end
48
-
49
- def cpf
50
- cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['entrega/CPF'])
51
- cpf.formatted
42
+ xpath = @xml['entrega/CNPJ'].present? ? 'entrega/CNPJ' : 'entrega/CPF'
43
+ @pdf.lcnpj_cpf LINE_HEIGHT, 4.37, 12.57, @l1, @xml, xpath
52
44
  end
53
45
 
54
46
  def render_line2
@@ -25,7 +25,7 @@ module BrDanfe
25
25
  @pdf.lbox LINE_HEIGHT, 1.78, 12.06, @l1, @xml, 'veicTransp/RNTC'
26
26
  @pdf.i18n_lbox LINE_HEIGHT, 2.29, 13.84, @l1, 'veicTransp.placa', plate
27
27
  @pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l1, @xml, 'veicTransp/UF'
28
- @pdf.lcnpj LINE_HEIGHT, 3.44, 16.89, @l1, @xml, 'transporta/CNPJ'
28
+ @pdf.lcnpj_cpf LINE_HEIGHT, 3.44, 16.89, @l1, @xml, 'transporta/CNPJ'
29
29
  @pdf.lbox LINE_HEIGHT, 8.52, 0.75, @l2, @xml, 'transporta/xEnder'
30
30
  @pdf.lbox LINE_HEIGHT, 6.86, 9.27, @l2, @xml, 'transporta/xMun'
31
31
  @pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l2, @xml, 'transporta/UF'
@@ -1,3 +1,3 @@
1
1
  module BrDanfe
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
@@ -114,7 +114,7 @@ describe BrDanfe::DanfeLib::NfeLib::Document do
114
114
  end
115
115
  end
116
116
 
117
- describe '#lcnpj' do
117
+ describe '#lcnpj_cpf' do
118
118
  before do
119
119
  subject.render
120
120
  FileUtils.rm_f(output_pdf)
@@ -138,10 +138,10 @@ describe BrDanfe::DanfeLib::NfeLib::Document do
138
138
  it 'renders a box with a formated CNPJ to the pdf' do
139
139
  expect(File.exist?(output_pdf)).to be_falsey
140
140
 
141
- subject.lcnpj 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
141
+ subject.lcnpj_cpf 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
142
142
  subject.render_file output_pdf
143
143
 
144
- expect("#{base_dir}document#lcnpj-valid.pdf").to have_same_content_of file: output_pdf
144
+ expect("#{base_dir}document#lcnpj_cpf-valid.pdf").to have_same_content_of file: output_pdf
145
145
  end
146
146
  end
147
147
 
@@ -163,10 +163,10 @@ describe BrDanfe::DanfeLib::NfeLib::Document do
163
163
  it 'renders a blank box to the pdf' do
164
164
  expect(File.exist?(output_pdf)).to be_falsey
165
165
 
166
- subject.lcnpj 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
166
+ subject.lcnpj_cpf 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
167
167
  subject.render_file output_pdf
168
168
 
169
- expect("#{base_dir}document#lcnpj-invalid.pdf").to have_same_content_of file: output_pdf
169
+ expect("#{base_dir}document#lcnpj_cpf-invalid.pdf").to have_same_content_of file: output_pdf
170
170
  end
171
171
  end
172
172
 
@@ -187,10 +187,10 @@ describe BrDanfe::DanfeLib::NfeLib::Document do
187
187
  it 'renders a blank box to the pdf' do
188
188
  expect(File.exist?(output_pdf)).to be_falsey
189
189
 
190
- subject.lcnpj 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
190
+ subject.lcnpj_cpf 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
191
191
  subject.render_file output_pdf
192
192
 
193
- expect("#{base_dir}document#lcnpj-blank.pdf").to have_same_content_of file: output_pdf
193
+ expect("#{base_dir}document#lcnpj_cpf-blank.pdf").to have_same_content_of file: output_pdf
194
194
  end
195
195
  end
196
196
  end
@@ -114,5 +114,68 @@ describe BrDanfe::DanfeLib::NfeLib::EmitHeader do
114
114
  end
115
115
  end
116
116
  end
117
+
118
+ context 'when emitter has CPF instead of CNPJ' do
119
+ let(:xml_as_string) do
120
+ <<~XML
121
+ <nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.00">
122
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
123
+ <infNFe Id="NFe25111012345678901234550020000134151000134151" versao="2.00">
124
+ <ide>
125
+ <tpNF>1</tpNF>
126
+ <nNF>1</nNF>
127
+ <serie>1</serie>
128
+ <natOp>Vendas de producao do estabelecimento</natOp>
129
+ </ide>
130
+ <emit>
131
+ <xNome>Nome do Remetente</xNome>
132
+ <CPF>86893723008</CPF>
133
+ <IE>526926313553</IE>
134
+ <enderEmit>
135
+ <xLgr>Rua do Remetente, Casa</xLgr>
136
+ <nro>123</nro>
137
+ <xBairro>Bairro do Remetente</xBairro>
138
+ <xMun>SAO PAULO</xMun>
139
+ <UF>SP</UF>
140
+ <CEP>12345678</CEP>
141
+ <fone>1112345678</fone>
142
+ <email>foo@bar.com</email>
143
+ </enderEmit>
144
+ </emit>
145
+ <det nItem="1">
146
+ <prod>
147
+ <detExport>
148
+ <exportInd>
149
+ <chNFe>41211285493849000105550020000027171182910239</chNFe>
150
+ </exportInd>
151
+ </detExport>
152
+ </prod>
153
+ </det>
154
+ </infNFe>
155
+ </NFe>
156
+ <protNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.00">
157
+ <infProt Id="ID325110012866320">
158
+ <chNFe>25111012345678901234550020000134151000134151</chNFe>
159
+ <dhRecbto>2011-10-29T14:37:09</dhRecbto>
160
+ <nProt>325110012866320</nProt>
161
+ </infProt>
162
+ </protNFe>
163
+ </nfeProc>
164
+ XML
165
+ end
166
+
167
+ before do
168
+ subject.render 1, 3.96, 1
169
+ FileUtils.rm_f(output_pdf)
170
+ end
171
+
172
+ it 'renders xml with CPF to the pdf' do
173
+ expect(File.exist?(output_pdf)).to be_falsey
174
+
175
+ pdf.render_file output_pdf
176
+
177
+ expect("#{base_dir}emit_header#render-with_cpf.pdf").to have_same_content_of file: output_pdf
178
+ end
179
+ end
117
180
  end
118
181
  end
@@ -17,7 +17,7 @@ endobj
17
17
  >>
18
18
  endobj
19
19
  4 0 obj
20
- << /Length 11058
20
+ << /Length 11066
21
21
  >>
22
22
  stream
23
23
  q
@@ -677,7 +677,7 @@ S
677
677
  BT
678
678
  398.0 685.49554 Td
679
679
  /F1.0 6 Tf
680
- <434e504a> Tj
680
+ <434e504a2f435046> Tj
681
681
  ET
682
682
 
683
683
 
@@ -1056,24 +1056,24 @@ xref
1056
1056
  0000000109 00000 n
1057
1057
  0000000158 00000 n
1058
1058
  0000000215 00000 n
1059
- 0000011326 00000 n
1060
- 0000011659 00000 n
1061
- 0000011824 00000 n
1062
- 0000011992 00000 n
1063
- 0000014379 00000 n
1064
- 0000014753 00000 n
1065
- 0000026482 00000 n
1066
- 0000026693 00000 n
1067
- 0000027315 00000 n
1068
- 0000027657 00000 n
1069
- 0000049438 00000 n
1070
- 0000049651 00000 n
1071
- 0000050314 00000 n
1059
+ 0000011334 00000 n
1060
+ 0000011667 00000 n
1061
+ 0000011832 00000 n
1062
+ 0000012000 00000 n
1063
+ 0000014387 00000 n
1064
+ 0000014761 00000 n
1065
+ 0000026490 00000 n
1066
+ 0000026701 00000 n
1067
+ 0000027323 00000 n
1068
+ 0000027665 00000 n
1069
+ 0000049446 00000 n
1070
+ 0000049659 00000 n
1071
+ 0000050322 00000 n
1072
1072
  trailer
1073
1073
  << /Info 1 0 R
1074
1074
  /Root 2 0 R
1075
1075
  /Size 18
1076
1076
  >>
1077
1077
  startxref
1078
- 50866
1078
+ 50874
1079
1079
  %%EOF
@@ -17,7 +17,7 @@ endobj
17
17
  >>
18
18
  endobj
19
19
  4 0 obj
20
- << /Length 11058
20
+ << /Length 11066
21
21
  >>
22
22
  stream
23
23
  q
@@ -677,7 +677,7 @@ S
677
677
  BT
678
678
  398.0 685.49554 Td
679
679
  /F1.0 6 Tf
680
- <434e504a> Tj
680
+ <434e504a2f435046> Tj
681
681
  ET
682
682
 
683
683
 
@@ -1056,24 +1056,24 @@ xref
1056
1056
  0000000109 00000 n
1057
1057
  0000000158 00000 n
1058
1058
  0000000215 00000 n
1059
- 0000011326 00000 n
1060
- 0000011659 00000 n
1061
- 0000011824 00000 n
1062
- 0000011992 00000 n
1063
- 0000014379 00000 n
1064
- 0000014753 00000 n
1065
- 0000026482 00000 n
1066
- 0000026693 00000 n
1067
- 0000027315 00000 n
1068
- 0000027657 00000 n
1069
- 0000049438 00000 n
1070
- 0000049651 00000 n
1071
- 0000050314 00000 n
1059
+ 0000011334 00000 n
1060
+ 0000011667 00000 n
1061
+ 0000011832 00000 n
1062
+ 0000012000 00000 n
1063
+ 0000014387 00000 n
1064
+ 0000014761 00000 n
1065
+ 0000026490 00000 n
1066
+ 0000026701 00000 n
1067
+ 0000027323 00000 n
1068
+ 0000027665 00000 n
1069
+ 0000049446 00000 n
1070
+ 0000049659 00000 n
1071
+ 0000050322 00000 n
1072
1072
  trailer
1073
1073
  << /Info 1 0 R
1074
1074
  /Root 2 0 R
1075
1075
  /Size 18
1076
1076
  >>
1077
1077
  startxref
1078
- 50866
1078
+ 50874
1079
1079
  %%EOF