br_danfe 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/README.md +12 -0
  4. data/lib/br_danfe/danfe.rb +4 -1
  5. data/lib/br_danfe/danfe_lib/det_body.rb +6 -5
  6. data/lib/br_danfe/danfe_lib/options.rb +3 -1
  7. data/lib/br_danfe/version.rb +1 -1
  8. data/spec/features/danfe_spec.rb +20 -0
  9. data/spec/fixtures/cce/lib/barcode#render.pdf +511 -0
  10. data/spec/fixtures/cce/lib/correction#render.pdf +100 -0
  11. data/spec/fixtures/cce/lib/document#box.pdf +55 -0
  12. data/spec/fixtures/cce/lib/document#box.with.block.pdf +72 -0
  13. data/spec/fixtures/cce/lib/document#text.align.pdf +70 -0
  14. data/spec/fixtures/cce/lib/document#text.pad.pdf +70 -0
  15. data/spec/fixtures/cce/lib/document#text.simple.pdf +70 -0
  16. data/spec/fixtures/cce/lib/document#text.size.pdf +70 -0
  17. data/spec/fixtures/cce/lib/document#text.style.pdf +70 -0
  18. data/spec/fixtures/cce/lib/footer#render.pdf +114 -0
  19. data/spec/fixtures/cce/lib/header#render.pdf +72 -0
  20. data/spec/fixtures/cce/lib/nfe_key#render.pdf +88 -0
  21. data/spec/fixtures/cce/lib/protocol#render.pdf +88 -0
  22. data/spec/fixtures/cce/v1.00/cce.fixture.pdf +659 -0
  23. data/spec/fixtures/nfe/lib/dest#render-v2.00.pdf +271 -0
  24. data/spec/fixtures/nfe/lib/dest#render-v3.10.pdf +271 -0
  25. data/spec/fixtures/nfe/lib/dest#render-with_cnpj.pdf +201 -0
  26. data/spec/fixtures/nfe/lib/dest#render-with_cpf.pdf +201 -0
  27. data/spec/fixtures/nfe/lib/dest#render-with_ie.pdf +208 -0
  28. data/spec/fixtures/nfe/lib/det_body#render-csosn.pdf +855 -0
  29. data/spec/fixtures/nfe/lib/det_body#render-cst.pdf +512 -0
  30. data/spec/fixtures/nfe/lib/det_body#render-fci.pdf +267 -0
  31. data/spec/fixtures/nfe/lib/det_body#render-icms_st.pdf +267 -0
  32. data/spec/fixtures/nfe/lib/det_body#render-quantity_with_custom_precision.pdf +246 -0
  33. data/spec/fixtures/nfe/lib/det_body#render-unit_price_with_custom_precision.pdf +246 -0
  34. data/spec/fixtures/nfe/lib/det_header#render.pdf +207 -0
  35. data/spec/fixtures/nfe/lib/document#lcnpj-blank.pdf +74 -0
  36. data/spec/fixtures/nfe/lib/document#lcnpj-invalid.pdf +74 -0
  37. data/spec/fixtures/nfe/lib/document#lcnpj-valid.pdf +81 -0
  38. data/spec/fixtures/nfe/lib/document#lie-blank.pdf +74 -0
  39. data/spec/fixtures/nfe/lib/document#lie-invalid.pdf +74 -0
  40. data/spec/fixtures/nfe/lib/document#lie-valid.pdf +81 -0
  41. data/spec/fixtures/nfe/lib/dup#render.pdf +216 -0
  42. data/spec/fixtures/nfe/lib/emit#render.pdf +143 -0
  43. data/spec/fixtures/nfe/lib/emit_header#render-with_logo.pdf +712 -0
  44. data/spec/fixtures/nfe/lib/emit_header#render-without_logo.pdf +650 -0
  45. data/spec/fixtures/nfe/lib/icmstot#render.pdf +255 -0
  46. data/spec/fixtures/nfe/lib/infadic#render-extra_volume.pdf +295 -0
  47. data/spec/fixtures/nfe/lib/infadic#render.pdf +104 -0
  48. data/spec/fixtures/nfe/lib/issqn#render.pdf +143 -0
  49. data/spec/fixtures/nfe/lib/ticket#render.pdf +113 -0
  50. data/spec/fixtures/nfe/lib/transp#render-modfrete_0.pdf +176 -0
  51. data/spec/fixtures/nfe/lib/transp#render-modfrete_1.pdf +176 -0
  52. data/spec/fixtures/nfe/lib/transp#render-modfrete_2.pdf +176 -0
  53. data/spec/fixtures/nfe/lib/transp#render-modfrete_9.pdf +176 -0
  54. data/spec/fixtures/nfe/lib/transp#render.pdf +239 -0
  55. data/spec/fixtures/nfe/lib/vol#render-blank-boxes.pdf +117 -0
  56. data/spec/fixtures/nfe/lib/vol#render.pdf +152 -0
  57. data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +1994 -0
  58. data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +1932 -0
  59. data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +5207 -0
  60. data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +1980 -0
  61. data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +5032 -0
  62. data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +2314 -0
  63. data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +2807 -0
  64. data/spec/lib/danfe_lib/det_body_spec.rb +80 -2
  65. data/spec/lib/danfe_lib/options_spec.rb +8 -1
  66. metadata +30 -2
@@ -1,13 +1,25 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe BrDanfe::DanfeLib::DetBody do
4
- let(:base_dir) { "./spec/fixtures/nfe/lib/"}
4
+ let(:base_dir) { "./spec/fixtures/nfe/lib/" }
5
5
  let(:output_pdf) { "#{base_dir}output.pdf" }
6
6
 
7
7
  let(:pdf) { BrDanfe::DanfeLib::Document.new }
8
8
  let(:xml) { BrDanfe::DanfeLib::XML.new(xml_as_string) }
9
9
 
10
- subject { described_class.new(pdf, xml) }
10
+ let(:options) do
11
+ { unit_price_precision: 2, quantity_precision: 2 }
12
+ end
13
+
14
+ let(:options_custom_unit_price_precision) do
15
+ { unit_price_precision: 4, quantity_precision: 2 }
16
+ end
17
+
18
+ let(:options_custom_quantity_precision) do
19
+ { unit_price_precision: 2, quantity_precision: 4 }
20
+ end
21
+
22
+ subject { described_class.new(pdf, xml, options) }
11
23
 
12
24
  describe "#render" do
13
25
  before do
@@ -295,5 +307,71 @@ describe BrDanfe::DanfeLib::DetBody do
295
307
  expect("#{base_dir}det_body#render-icms_st.pdf").to have_same_content_of file: output_pdf
296
308
  end
297
309
  end
310
+
311
+ context "when the unit price of the product has a custom precision" do
312
+ subject { described_class.new(pdf, xml, options_custom_unit_price_precision) }
313
+
314
+ let(:xml_as_string) do
315
+ <<-eos
316
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
317
+ <infNFe Id="NFe25111012345678901234550020000134151000134151" versao="2.00">
318
+ <det nItem="1">
319
+ <prod>
320
+ <cProd>3</cProd>
321
+ <xProd>Produto Com Csosn 201 - ICMS ST</xProd>
322
+ <NCM>45678901</NCM>
323
+ <CFOP>5401</CFOP>
324
+ <uCom>UN</uCom>
325
+ <qCom>6.0000</qCom>
326
+ <vUnCom>1.1312000000</vUnCom>
327
+ <vProd>6.79</vProd>
328
+ </prod>
329
+ </det>
330
+ </infNFe>
331
+ </NFe>
332
+ eos
333
+ end
334
+
335
+ it "renders xml to the pdf" do
336
+ expect(File.exist?(output_pdf)).to be_falsey
337
+
338
+ pdf.render_file output_pdf
339
+
340
+ expect("#{base_dir}det_body#render-unit_price_with_custom_precision.pdf").to have_same_content_of file: output_pdf
341
+ end
342
+ end
343
+
344
+ context "when the quantity of the product has a custom precision" do
345
+ subject { described_class.new(pdf, xml, options_custom_quantity_precision) }
346
+
347
+ let(:xml_as_string) do
348
+ <<-eos
349
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
350
+ <infNFe Id="NFe25111012345678901234550020000134151000134151" versao="2.00">
351
+ <det nItem="1">
352
+ <prod>
353
+ <cProd>3</cProd>
354
+ <xProd>Produto Com Csosn 201 - ICMS ST</xProd>
355
+ <NCM>45678901</NCM>
356
+ <CFOP>5401</CFOP>
357
+ <uCom>UN</uCom>
358
+ <qCom>6.4545</qCom>
359
+ <vUnCom>1.0300000000</vUnCom>
360
+ <vProd>6.65</vProd>
361
+ </prod>
362
+ </det>
363
+ </infNFe>
364
+ </NFe>
365
+ eos
366
+ end
367
+
368
+ it "renders xml to the pdf" do
369
+ expect(File.exist?(output_pdf)).to be_falsey
370
+
371
+ pdf.render_file output_pdf
372
+
373
+ expect("#{base_dir}det_body#render-quantity_with_custom_precision.pdf").to have_same_content_of file: output_pdf
374
+ end
375
+ end
298
376
  end
299
377
  end
@@ -4,10 +4,17 @@ describe BrDanfe::DanfeLib::Options do
4
4
  it "returns the default config set in the code" do
5
5
  options = BrDanfe::DanfeLib::Options.new
6
6
  expect(options.logo_path).to eq("")
7
+ expect(options.products_unit_price_precision).to eq(2)
8
+ expect(options.products_quantity_precision).to eq(2)
7
9
  end
8
10
 
9
11
  it "returns the config set in params" do
10
- options = BrDanfe::DanfeLib::Options.new({"logo_path" => "/fake/path/file.png"})
12
+ custom_options = { logo_path: "/fake/path/file.png",
13
+ products_unit_price_precision: 3, products_quantity_precision: 4 }
14
+
15
+ options = BrDanfe::DanfeLib::Options.new(custom_options)
11
16
  expect(options.logo_path).to eq("/fake/path/file.png")
17
+ expect(options.products_unit_price_precision).to eq(3)
18
+ expect(options.products_quantity_precision).to eq(4)
12
19
  end
13
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: br_danfe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ASSEINFO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-03 00:00:00.000000000 Z
11
+ date: 2015-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -216,10 +216,17 @@ files:
216
216
  - spec/fixtures/cce/v1.00/cce.fixture.pdf
217
217
  - spec/fixtures/cce/v1.00/cce.xml
218
218
  - spec/fixtures/logo.png
219
+ - spec/fixtures/nfe/lib/dest#render-v2.00.pdf
220
+ - spec/fixtures/nfe/lib/dest#render-v3.10.pdf
221
+ - spec/fixtures/nfe/lib/dest#render-with_cnpj.pdf
222
+ - spec/fixtures/nfe/lib/dest#render-with_cpf.pdf
223
+ - spec/fixtures/nfe/lib/dest#render-with_ie.pdf
219
224
  - spec/fixtures/nfe/lib/det_body#render-csosn.pdf
220
225
  - spec/fixtures/nfe/lib/det_body#render-cst.pdf
221
226
  - spec/fixtures/nfe/lib/det_body#render-fci.pdf
222
227
  - spec/fixtures/nfe/lib/det_body#render-icms_st.pdf
228
+ - spec/fixtures/nfe/lib/det_body#render-quantity_with_custom_precision.pdf
229
+ - spec/fixtures/nfe/lib/det_body#render-unit_price_with_custom_precision.pdf
223
230
  - spec/fixtures/nfe/lib/det_header#render.pdf
224
231
  - spec/fixtures/nfe/lib/document#lcnpj-blank.pdf
225
232
  - spec/fixtures/nfe/lib/document#lcnpj-invalid.pdf
@@ -243,13 +250,20 @@ files:
243
250
  - spec/fixtures/nfe/lib/transp#render.pdf
244
251
  - spec/fixtures/nfe/lib/vol#render-blank-boxes.pdf
245
252
  - spec/fixtures/nfe/lib/vol#render.pdf
253
+ - spec/fixtures/nfe/v2.00/custom_options.fixture.pdf
246
254
  - spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml
255
+ - spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf
247
256
  - spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml
257
+ - spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf
248
258
  - spec/fixtures/nfe/v2.00/nfe_with_fci.xml
259
+ - spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf
249
260
  - spec/fixtures/nfe/v2.00/nfe_with_logo.xml
250
261
  - spec/fixtures/nfe/v2.00/nfe_with_ns.xml
262
+ - spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf
251
263
  - spec/fixtures/nfe/v2.00/nfe_without_ns.xml
264
+ - spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf
252
265
  - spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml
266
+ - spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf
253
267
  - spec/lib/cce_lib/barcode_spec.rb
254
268
  - spec/lib/cce_lib/correction_spec.rb
255
269
  - spec/lib/cce_lib/document_spec.rb
@@ -323,10 +337,17 @@ test_files:
323
337
  - spec/fixtures/cce/v1.00/cce.fixture.pdf
324
338
  - spec/fixtures/cce/v1.00/cce.xml
325
339
  - spec/fixtures/logo.png
340
+ - spec/fixtures/nfe/lib/dest#render-v2.00.pdf
341
+ - spec/fixtures/nfe/lib/dest#render-v3.10.pdf
342
+ - spec/fixtures/nfe/lib/dest#render-with_cnpj.pdf
343
+ - spec/fixtures/nfe/lib/dest#render-with_cpf.pdf
344
+ - spec/fixtures/nfe/lib/dest#render-with_ie.pdf
326
345
  - spec/fixtures/nfe/lib/det_body#render-csosn.pdf
327
346
  - spec/fixtures/nfe/lib/det_body#render-cst.pdf
328
347
  - spec/fixtures/nfe/lib/det_body#render-fci.pdf
329
348
  - spec/fixtures/nfe/lib/det_body#render-icms_st.pdf
349
+ - spec/fixtures/nfe/lib/det_body#render-quantity_with_custom_precision.pdf
350
+ - spec/fixtures/nfe/lib/det_body#render-unit_price_with_custom_precision.pdf
330
351
  - spec/fixtures/nfe/lib/det_header#render.pdf
331
352
  - spec/fixtures/nfe/lib/document#lcnpj-blank.pdf
332
353
  - spec/fixtures/nfe/lib/document#lcnpj-invalid.pdf
@@ -350,13 +371,20 @@ test_files:
350
371
  - spec/fixtures/nfe/lib/transp#render.pdf
351
372
  - spec/fixtures/nfe/lib/vol#render-blank-boxes.pdf
352
373
  - spec/fixtures/nfe/lib/vol#render.pdf
374
+ - spec/fixtures/nfe/v2.00/custom_options.fixture.pdf
353
375
  - spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml
376
+ - spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf
354
377
  - spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml
378
+ - spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf
355
379
  - spec/fixtures/nfe/v2.00/nfe_with_fci.xml
380
+ - spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf
356
381
  - spec/fixtures/nfe/v2.00/nfe_with_logo.xml
357
382
  - spec/fixtures/nfe/v2.00/nfe_with_ns.xml
383
+ - spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf
358
384
  - spec/fixtures/nfe/v2.00/nfe_without_ns.xml
385
+ - spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf
359
386
  - spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml
387
+ - spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf
360
388
  - spec/lib/cce_lib/barcode_spec.rb
361
389
  - spec/lib/cce_lib/correction_spec.rb
362
390
  - spec/lib/cce_lib/document_spec.rb