br_danfe 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,54 +0,0 @@
1
- module BrDanfe
2
- class DanfeGenerator
3
- def initialize(xml)
4
- @xml = xml
5
- @pdf = Document.new
6
-
7
- create_watermark
8
- end
9
-
10
- def generatePDF
11
- @pdf.stamp("without_fiscal_value") if Helper.without_fiscal_value?(@xml)
12
-
13
- @pdf.repeat :all do
14
- Ticket.render(@pdf, @xml)
15
- Emit.render(@pdf, @xml)
16
- Dest.render(@pdf, @xml)
17
- Dup.render(@pdf, @xml)
18
- Icmstot.render(@pdf, @xml)
19
- Transp.render(@pdf, @xml)
20
- nVol = Vol.render(@pdf, @xml)
21
- Det.render_header(@pdf, @xml)
22
- Issqn.render(@pdf, @xml)
23
- Infadic.render(@pdf, @xml, nVol)
24
- end
25
-
26
- Det.render_body(@pdf, @xml)
27
-
28
- @pdf.page_count.times do |i|
29
- @pdf.go_to_page(i + 1)
30
- @pdf.ibox 1.00, 2.08, 8.71, 5.54, "",
31
- I18n.t("danfe.others.page", current: i+1, total: @pdf.page_count),
32
- {size: 8, align: :center, valign: :center, border: 0, style: :bold}
33
- end
34
-
35
- @pdf
36
- end
37
-
38
- private
39
- def create_watermark
40
- @pdf.create_stamp("without_fiscal_value") do
41
- @pdf.fill_color "7d7d7d"
42
- @pdf.text_box I18n.t("danfe.others.without_fiscal_value"),
43
- size: 2.2.cm,
44
- width: @pdf.bounds.width,
45
- height: @pdf.bounds.height,
46
- align: :center,
47
- valign: :center,
48
- at: [0, @pdf.bounds.height],
49
- rotate: 45,
50
- rotate_around: :center
51
- end
52
- end
53
- end
54
- end
@@ -1,69 +0,0 @@
1
- module BrDanfe
2
- class Det
3
- def self.render_header(pdf, xml)
4
- pdf.ititle 0.42, 10.00, 0.25, 17.45, "det.title"
5
-
6
- pdf.ibox 6.70, 2.00, 0.25, 17.87, I18n.t("danfe.det.prod.cProd")
7
- pdf.ibox 6.70, 4.90, 2.25, 17.87, I18n.t("danfe.det.prod.xProd")
8
- pdf.ibox 6.70, 1.30, 7.15, 17.87, I18n.t("danfe.det.prod.NCM")
9
- pdf.ibox 6.70, 0.80, 8.45, 17.87, I18n.t("danfe.det.ICMS.CST")
10
- pdf.ibox 6.70, 1.00, 9.25, 17.87, I18n.t("danfe.det.prod.CFOP")
11
- pdf.ibox 6.70, 1.00, 10.25, 17.87, I18n.t("danfe.det.prod.uCom")
12
- pdf.ibox 6.70, 1.30, 11.25, 17.87, I18n.t("danfe.det.prod.qCom")
13
- pdf.ibox 6.70, 1.50, 12.55, 17.87, I18n.t("danfe.det.prod.vUnCom")
14
- pdf.ibox 6.70, 1.50, 14.05, 17.87, I18n.t("danfe.det.prod.vProd")
15
- pdf.ibox 6.70, 1.50, 15.55, 17.87, I18n.t("danfe.det.ICMS.vBC")
16
- pdf.ibox 6.70, 1.00, 17.05, 17.87, I18n.t("danfe.det.ICMS.vICMS")
17
- pdf.ibox 6.70, 1.00, 18.05, 17.87, I18n.t("danfe.det.IPI.vIPI")
18
- pdf.ibox 6.70, 0.90, 19.05, 17.87, I18n.t("danfe.det.ICMS.pICMS")
19
- pdf.ibox 6.70, 0.86, 19.95, 17.87, I18n.t("danfe.det.IPI.pIPI")
20
-
21
- pdf.horizontal_line 0.25.cm, 20.83.cm, at: Helper.invert(18.17.cm)
22
- end
23
-
24
- def self.render_body(pdf, xml)
25
- pdf.font_size(6) do
26
- pdf.itable 6.37, 21.50, 0.25, 18.17,
27
- xml.collect("xmlns", "det") { |det|
28
- [
29
- det.css("prod/cProd").text,
30
- Xprod.generate(det),
31
- det.css("prod/NCM").text,
32
- Cst.to_danfe(det),
33
- det.css("prod/CFOP").text,
34
- det.css("prod/uCom").text,
35
- Helper.numerify(det.css("prod/qCom").text),
36
- Helper.numerify(det.css("prod/vUnCom").text),
37
- Helper.numerify(det.css("prod/vProd").text),
38
- Helper.numerify(det.css("ICMS/*/vBC").text),
39
- Helper.numerify(det.css("ICMS/*/vICMS").text),
40
- Helper.numerify(det.css("IPI/*/vIPI").text),
41
- Helper.numerify(det.css("ICMS/*/pICMS").text),
42
- Helper.numerify(det.css("IPI/*/pIPI").text)
43
- ]
44
- },
45
- column_widths: {
46
- 0 => 2.00.cm,
47
- 1 => 4.90.cm,
48
- 2 => 1.30.cm,
49
- 3 => 0.80.cm,
50
- 4 => 1.00.cm,
51
- 5 => 1.00.cm,
52
- 6 => 1.30.cm,
53
- 7 => 1.50.cm,
54
- 8 => 1.50.cm,
55
- 9 => 1.50.cm,
56
- 10 => 1.00.cm,
57
- 11 => 1.00.cm,
58
- 12 => 0.90.cm,
59
- 13 => 0.86.cm
60
- },
61
- cell_style: {padding: 2, border_width: 0} do |table|
62
- table.column(6..13).style(align: :right)
63
- table.column(0..13).border_width = 1
64
- table.column(0..13).borders = [:bottom]
65
- end
66
- end
67
- end
68
- end
69
- end
@@ -1,42 +0,0 @@
1
- module BrDanfe
2
- def self.generate(pdf_filename, xml_filename, new_options = {})
3
- self.options = new_options if !new_options.empty?
4
-
5
- xml_string = File.new(xml_filename)
6
- render_file(pdf_filename, xml_string)
7
- end
8
-
9
- def self.render(xml_string, new_options = {})
10
- self.options = new_options if !new_options.empty?
11
-
12
- pdf = generatePDF(xml_string)
13
- pdf.render
14
- end
15
-
16
- def self.render_file(pdf_filename, xml_string, new_options = {})
17
- self.options = new_options if !new_options.empty?
18
-
19
- pdf = generatePDF(xml_string)
20
- pdf.render_file pdf_filename
21
- end
22
-
23
- def self.options
24
- @options ||= BrDanfe::Options.new
25
- end
26
-
27
- def self.options=(new_options = {})
28
- @options = BrDanfe::Options.new(new_options)
29
- end
30
-
31
- private
32
- def self.generatePDF(xml_string, new_options = {})
33
- self.options = new_options if !new_options.empty?
34
-
35
- xml = XML.new(xml_string)
36
-
37
- generator = DanfeGenerator.new(xml)
38
-
39
- pdf = generator.generatePDF
40
- pdf
41
- end
42
- end
@@ -1,40 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe BrDanfe do
4
- let(:base_dir) { "./spec/fixtures/"}
5
- let(:output_pdf) { "#{base_dir}output.pdf" }
6
-
7
- before { File.delete(output_pdf) if File.exist?(output_pdf) }
8
-
9
- describe ".generate" do
10
- it "saves the PDF document to file based on a xml file" do
11
- expect(File.exist?(output_pdf)).to be_false
12
-
13
- BrDanfe.generate(output_pdf, "#{base_dir}nfe_with_ns.xml")
14
-
15
- expect("#{base_dir}nfe_with_ns.xml.fixture.pdf").to be_same_file_as(output_pdf)
16
- end
17
- end
18
-
19
- describe ".render" do
20
- it "renders the PDF document to string based on a xml string" do
21
- xml_string = File.new("#{base_dir}nfe_with_ns.xml")
22
-
23
- pdf_string = BrDanfe.render(xml_string)
24
-
25
- expect(pdf_string).to include "%PDF-1.3\n%"
26
- end
27
- end
28
-
29
- describe ".render_file" do
30
- it "renders the PDF document to file based on a xml string" do
31
- expect(File.exist?(output_pdf)).to be_false
32
-
33
- xml_string = File.new("#{base_dir}nfe_with_ns.xml")
34
-
35
- BrDanfe.render_file(output_pdf, xml_string)
36
-
37
- expect("#{base_dir}nfe_with_ns.xml.fixture.pdf").to be_same_file_as(output_pdf)
38
- end
39
- end
40
- end