br_danfe 0.12.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -25
- data/Gemfile.lock +54 -18
- data/Guardfile +14 -0
- data/README.md +5 -5
- data/br_danfe.gemspec +3 -1
- data/lib/br_danfe.rb +0 -1
- data/lib/br_danfe/danfe.rb +6 -90
- data/lib/br_danfe/danfe_lib/base.rb +33 -0
- data/lib/br_danfe/danfe_lib/nfce.rb +49 -0
- data/lib/br_danfe/danfe_lib/nfce_lib/document.rb +37 -0
- data/lib/br_danfe/danfe_lib/nfce_lib/footer.rb +22 -0
- data/lib/br_danfe/danfe_lib/nfce_lib/header.rb +69 -0
- data/lib/br_danfe/danfe_lib/nfce_lib/helper.rb +11 -0
- data/lib/br_danfe/danfe_lib/nfce_lib/key.rb +20 -0
- data/lib/br_danfe/danfe_lib/nfce_lib/nfce_identification.rb +22 -0
- data/lib/br_danfe/danfe_lib/nfce_lib/product_list.rb +102 -0
- data/lib/br_danfe/danfe_lib/nfce_lib/qr_code.rb +25 -0
- data/lib/br_danfe/danfe_lib/nfce_lib/recipient.rb +75 -0
- data/lib/br_danfe/danfe_lib/nfce_lib/total_list.rb +81 -0
- data/lib/br_danfe/danfe_lib/nfe.rb +83 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/cep.rb +11 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/consts.rb +8 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/cst.rb +34 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +96 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/det_body.rb +137 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/document.rb +142 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/dup.rb +55 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +117 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/helper.rb +55 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/icmstot.rb +35 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/infadic.rb +125 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/infadic_vol.rb +103 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/issqn.rb +37 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/phone.rb +15 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/plate.rb +11 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/ticket.rb +21 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/transp.rb +58 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/vol.rb +44 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/xprod.rb +109 -0
- data/lib/br_danfe/helper.rb +8 -0
- data/lib/br_danfe/version.rb +1 -1
- data/spec/{lib → br_danfe}/cce_lib/barcode_spec.rb +0 -0
- data/spec/{lib → br_danfe}/cce_lib/correction_spec.rb +0 -0
- data/spec/{lib → br_danfe}/cce_lib/document_spec.rb +0 -0
- data/spec/{lib → br_danfe}/cce_lib/footer_spec.rb +0 -0
- data/spec/{lib → br_danfe}/cce_lib/header_spec.rb +0 -0
- data/spec/{lib → br_danfe}/cce_lib/nfe_key_spec.rb +0 -0
- data/spec/{lib → br_danfe}/cce_lib/protocol_spec.rb +0 -0
- data/spec/{features → br_danfe}/cce_spec.rb +0 -0
- data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/document_spec.rb +2 -2
- data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/footer_spec.rb +2 -2
- data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/header_spec.rb +2 -2
- data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/helper_spec.rb +1 -1
- data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/key_spec.rb +2 -2
- data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/nfce_identification_spec.rb +2 -2
- data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/product_list_spec.rb +2 -2
- data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/qr_code_spec.rb +2 -2
- data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/recipient_spec.rb +7 -7
- data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/total_list_spec.rb +4 -4
- data/spec/br_danfe/danfe_lib/nfce_spec.rb +57 -0
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/cep_spec.rb +2 -2
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/cst_spec.rb +3 -3
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/dest_spec.rb +2 -2
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/det_body_spec.rb +2 -2
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/document_spec.rb +1 -1
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/dup_spec.rb +2 -2
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/emit_header_spec.rb +3 -3
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/helper_spec.rb +13 -87
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/icmstot_spec.rb +2 -2
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/infadic_spec.rb +45 -4
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/infadic_vol_spec.rb +2 -2
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/issqn_spec.rb +2 -2
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/phone_spec.rb +3 -3
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/plate_spec.rb +3 -3
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/ticket_spec.rb +2 -2
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/transp_spec.rb +2 -2
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/vol_spec.rb +2 -2
- data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/xprod_spec.rb +9 -9
- data/spec/{features/danfe_spec.rb → br_danfe/danfe_lib/nfe_spec.rb} +55 -47
- data/spec/br_danfe/danfe_spec.rb +40 -0
- data/spec/{lib → br_danfe}/helper_spec.rb +114 -0
- data/spec/{lib → br_danfe}/logo_config_spec.rb +1 -1
- data/spec/{lib → br_danfe}/logo_options_spec.rb +7 -7
- data/spec/{lib → br_danfe}/uf_spec.rb +0 -0
- data/spec/{lib → br_danfe}/xml_spec.rb +0 -0
- data/spec/fixtures/nfce/v4.00/nfce-unauthorized-hom.fixture.pdf +0 -0
- data/spec/fixtures/nfce/v4.00/nfce-unauthorized-hom.xml +358 -0
- data/spec/fixtures/nfce/v4.00/nfce-unauthorized-prod.fixture.pdf +0 -0
- data/spec/fixtures/nfce/v4.00/nfce-unauthorized-prod.xml +358 -0
- data/spec/fixtures/nfce/v4.00/nfce.xml +2 -2
- data/spec/fixtures/nfce/v4.00/rendered_nfce.fixture.pdf +0 -0
- data/spec/fixtures/nfce/v4.00/saved_nfce.fixture.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#address-shipment.pdf +108 -0
- data/spec/fixtures/nfe/lib/infadic#render-all_the_informations.pdf +7 -7
- data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +10 -10
- data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +8 -8
- data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +10 -10
- data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +8 -8
- data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +10 -10
- data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +7 -7
- data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +8 -8
- data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +10 -10
- data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +10 -10
- data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +12 -12
- data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +10 -10
- metadata +114 -77
- data/lib/br_danfe/danfe_lib/cep.rb +0 -9
- data/lib/br_danfe/danfe_lib/consts.rb +0 -6
- data/lib/br_danfe/danfe_lib/cst.rb +0 -32
- data/lib/br_danfe/danfe_lib/dest.rb +0 -94
- data/lib/br_danfe/danfe_lib/det_body.rb +0 -135
- data/lib/br_danfe/danfe_lib/document.rb +0 -140
- data/lib/br_danfe/danfe_lib/dup.rb +0 -53
- data/lib/br_danfe/danfe_lib/emit_header.rb +0 -115
- data/lib/br_danfe/danfe_lib/helper.rb +0 -61
- data/lib/br_danfe/danfe_lib/icmstot.rb +0 -33
- data/lib/br_danfe/danfe_lib/infadic.rb +0 -107
- data/lib/br_danfe/danfe_lib/infadic_vol.rb +0 -101
- data/lib/br_danfe/danfe_lib/issqn.rb +0 -35
- data/lib/br_danfe/danfe_lib/phone.rb +0 -13
- data/lib/br_danfe/danfe_lib/plate.rb +0 -9
- data/lib/br_danfe/danfe_lib/ticket.rb +0 -19
- data/lib/br_danfe/danfe_lib/transp.rb +0 -56
- data/lib/br_danfe/danfe_lib/vol.rb +0 -42
- data/lib/br_danfe/danfe_lib/xprod.rb +0 -107
- data/lib/br_danfe/danfe_nfce.rb +0 -43
- data/lib/br_danfe/danfe_nfce_lib/document.rb +0 -35
- data/lib/br_danfe/danfe_nfce_lib/footer.rb +0 -20
- data/lib/br_danfe/danfe_nfce_lib/header.rb +0 -67
- data/lib/br_danfe/danfe_nfce_lib/helper.rb +0 -9
- data/lib/br_danfe/danfe_nfce_lib/key.rb +0 -18
- data/lib/br_danfe/danfe_nfce_lib/nfce_identification.rb +0 -20
- data/lib/br_danfe/danfe_nfce_lib/product_list.rb +0 -100
- data/lib/br_danfe/danfe_nfce_lib/qr_code.rb +0 -23
- data/lib/br_danfe/danfe_nfce_lib/recipient.rb +0 -72
- data/lib/br_danfe/danfe_nfce_lib/total_list.rb +0 -78
- data/spec/features/danfe_nfce_spec.rb +0 -31
@@ -0,0 +1,37 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfceLib
|
4
|
+
class Document
|
5
|
+
def initialize(page_width, page_height)
|
6
|
+
@document = Prawn::Document.new(
|
7
|
+
page_size: [page_width, page_height],
|
8
|
+
page_layout: :portrait,
|
9
|
+
left_margin: 0.3.cm,
|
10
|
+
right_margin: 0.3.cm,
|
11
|
+
top_margin: 0.3.cm,
|
12
|
+
botton_margin: 0
|
13
|
+
)
|
14
|
+
|
15
|
+
@document.font 'Courier'
|
16
|
+
@document.line_width = 0.3
|
17
|
+
end
|
18
|
+
|
19
|
+
def render_blank_line(font_size = 6)
|
20
|
+
@document.text ' ', size: font_size
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(method_name, *args, &block)
|
24
|
+
if @document.respond_to? method_name
|
25
|
+
@document.send method_name, *args, &block
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def respond_to_missing?(method_name, include_private = false)
|
32
|
+
@document.respond_to?(method_name, include_private) || super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfceLib
|
4
|
+
class Footer
|
5
|
+
def initialize(pdf, xml)
|
6
|
+
@pdf = pdf
|
7
|
+
@xml = xml
|
8
|
+
end
|
9
|
+
|
10
|
+
def render(info = '')
|
11
|
+
tot_trib = @xml['ICMSTot/vTotTrib'].present? ? BrDanfe::Helper.numerify(@xml['ICMSTot/vTotTrib']) : '0,00'
|
12
|
+
@pdf.text "Tributos Totais Incidentes (Lei Federal 12.741/2012): R$ #{tot_trib}", size: 5, align: :center
|
13
|
+
|
14
|
+
if info.present?
|
15
|
+
@pdf.render_blank_line
|
16
|
+
@pdf.text info, size: 5, align: :center
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfceLib
|
4
|
+
class Header
|
5
|
+
def initialize(pdf, xml, logo, logo_dimensions)
|
6
|
+
@pdf = pdf
|
7
|
+
@xml = xml
|
8
|
+
@logo = logo
|
9
|
+
@logo_dimensions = logo_dimensions
|
10
|
+
end
|
11
|
+
|
12
|
+
def render
|
13
|
+
cursor = @pdf.cursor
|
14
|
+
|
15
|
+
render_company_info(cursor)
|
16
|
+
render_logo(cursor) if @logo.present?
|
17
|
+
|
18
|
+
render_homologation if BrDanfe::Helper.homologation?(@xml)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def render_company_info(cursor)
|
24
|
+
one_line = 1
|
25
|
+
|
26
|
+
@pdf.bounding_box([x_position, cursor], width: width_box, height: 45) do
|
27
|
+
@pdf.text (@xml['emit/xNome']).to_s, size: 7, align: :left, style: :bold
|
28
|
+
@pdf.text cnpj(@xml['emit/CNPJ']), size: 6, align: :left
|
29
|
+
@pdf.text BrDanfe::DanfeLib::NfceLib::Helper.address(@xml.css('enderEmit')), size: 6, align: :left
|
30
|
+
@pdf.render_blank_line if count_name_lines(@xml['emit/xNome']) == one_line
|
31
|
+
@pdf.text 'Documento Auxiliar da Nota Fiscal de Consumidor Eletrônica', size: 6, align: :left
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def x_position
|
36
|
+
@logo.present? ? 1.7.cm : 0
|
37
|
+
end
|
38
|
+
|
39
|
+
def width_box
|
40
|
+
@logo.present? ? 5.7.cm : 7.4.cm
|
41
|
+
end
|
42
|
+
|
43
|
+
def cnpj(info)
|
44
|
+
cnpj = BrDocuments::CnpjCpf::Cnpj.new info
|
45
|
+
data = "CNPJ: #{cnpj.valid? ? cnpj.formatted : ''}"
|
46
|
+
data
|
47
|
+
end
|
48
|
+
|
49
|
+
def count_name_lines(company_name)
|
50
|
+
company_name.scan(/([\s\S]{1,38}( |$)|[\s\S]{1,38})/).length
|
51
|
+
end
|
52
|
+
|
53
|
+
def render_logo(cursor)
|
54
|
+
box_size = 45
|
55
|
+
logo_options = BrDanfe::Logo::Options.new(box_size, @logo_dimensions).options
|
56
|
+
|
57
|
+
@pdf.bounding_box([0, cursor], width: box_size, height: box_size) do
|
58
|
+
@pdf.image @logo, logo_options
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def render_homologation
|
63
|
+
@pdf.render_blank_line
|
64
|
+
@pdf.text 'EMITIDA EM AMBIENTE DE HOMOLOGAÇÃO – SEM VALOR FISCAL', size: 7, align: :center, style: :bold
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfceLib
|
4
|
+
class Helper
|
5
|
+
def self.address(ender_tag)
|
6
|
+
"#{ender_tag.css('xLgr').text}, #{ender_tag.css('nro').text}, #{ender_tag.css('xBairro').text}, #{ender_tag.css('xMun').text} - #{ender_tag.css('UF').text}"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfceLib
|
4
|
+
class Key
|
5
|
+
def initialize(pdf, xml)
|
6
|
+
@pdf = pdf
|
7
|
+
@xml = xml
|
8
|
+
end
|
9
|
+
|
10
|
+
def render
|
11
|
+
@pdf.render_blank_line
|
12
|
+
|
13
|
+
@pdf.text 'Consulte pela Chave de Acesso em', size: 7, align: :center, style: :bold
|
14
|
+
@pdf.text @xml['urlChave'], size: 7, align: :center
|
15
|
+
@pdf.text @xml['chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, '\\1 '), size: 6, align: :center
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfceLib
|
4
|
+
class NfceIdentification
|
5
|
+
def initialize(pdf, xml)
|
6
|
+
@pdf = pdf
|
7
|
+
@xml = xml
|
8
|
+
end
|
9
|
+
|
10
|
+
def render
|
11
|
+
emitted_at = BrDanfe::Helper.format_datetime(@xml['ide/dhEmi'])
|
12
|
+
identification = "NFC-e nº #{@xml['ide/nNF']} Série #{@xml['ide/serie']} #{emitted_at}"
|
13
|
+
|
14
|
+
@pdf.render_blank_line
|
15
|
+
@pdf.text identification, size: 7, align: :center, style: :bold
|
16
|
+
@pdf.text "<b>Protocolo de autorização:</b> #{@xml['infProt/nProt']}", size: 7, align: :center, inline_format: true
|
17
|
+
@pdf.text "<b>Data de autorização: </b> #{BrDanfe::Helper.format_datetime(@xml['infProt/dhRecbto'])}", size: 7, align: :center, inline_format: true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfceLib
|
4
|
+
class ProductList
|
5
|
+
def initialize(pdf, xml)
|
6
|
+
@pdf = pdf
|
7
|
+
@xml = xml
|
8
|
+
end
|
9
|
+
|
10
|
+
def render
|
11
|
+
render_headers(headers)
|
12
|
+
render_products
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def headers
|
18
|
+
[
|
19
|
+
header_column('Código', :left),
|
20
|
+
header_column('Descrição', :left),
|
21
|
+
header_column('Qtde', :right),
|
22
|
+
header_column('UN', :right),
|
23
|
+
header_column('Vl Unit', :right),
|
24
|
+
header_column('Vl Total', :right)
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
def header_column(title, align)
|
29
|
+
{ content: title, options: { align: align, size: 6, style: :bold } }
|
30
|
+
end
|
31
|
+
|
32
|
+
def products
|
33
|
+
@xml.collect('xmlns', 'det') { |det| product(det) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def product(det)
|
37
|
+
[
|
38
|
+
cell_text(det.css('prod/cProd').text),
|
39
|
+
cell_text(det.css('prod/xProd').text),
|
40
|
+
cell_number(BrDanfe::Helper.numerify(det.css('prod/qCom').text)),
|
41
|
+
cell_text(det.css('prod/uCom').text, align: :right),
|
42
|
+
cell_number(BrDanfe::Helper.numerify(det.css('prod/vUnCom').text)),
|
43
|
+
cell_number(BrDanfe::Helper.numerify(det.css('prod/vProd').text))
|
44
|
+
]
|
45
|
+
end
|
46
|
+
|
47
|
+
def cell_text(text, options = {})
|
48
|
+
cell = { content: text, options: { border_width: 0, size: 6 } }
|
49
|
+
cell[:options].merge!(options)
|
50
|
+
cell
|
51
|
+
end
|
52
|
+
|
53
|
+
def cell_number(text)
|
54
|
+
cell_text(text, align: :right)
|
55
|
+
end
|
56
|
+
|
57
|
+
def columns
|
58
|
+
[
|
59
|
+
{ width: 0.9.cm, position: 0 },
|
60
|
+
{ width: 2.6.cm, position: 0.9.cm },
|
61
|
+
{ width: 1.1.cm, position: 3.5.cm },
|
62
|
+
{ width: 0.4.cm, position: 4.6.cm },
|
63
|
+
{ width: 1.2.cm, position: 5.cm },
|
64
|
+
{ width: 1.2.cm, position: 6.2.cm }
|
65
|
+
]
|
66
|
+
end
|
67
|
+
|
68
|
+
def render_headers(headers)
|
69
|
+
2.times { @pdf.render_blank_line }
|
70
|
+
cursor = @pdf.cursor
|
71
|
+
headers.each_with_index do |header, index|
|
72
|
+
@pdf.bounding_box [columns[index][:position], cursor], width: columns[index][:width], height: 0.2.cm do
|
73
|
+
@pdf.text header[:content], header[:options]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def render_products
|
79
|
+
@pdf.render_blank_line
|
80
|
+
index_of_product_name = 1
|
81
|
+
products.each do |product|
|
82
|
+
box_height = box_height(product[index_of_product_name][:content])
|
83
|
+
cursor = @pdf.cursor
|
84
|
+
|
85
|
+
product.each_with_index do |cell, index|
|
86
|
+
@pdf.bounding_box [columns[index][:position], cursor], width: columns[index][:width], height: box_height do
|
87
|
+
@pdf.text cell[:content], cell[:options]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def box_height(content)
|
94
|
+
line_height_base = 0.23.cm
|
95
|
+
|
96
|
+
lines = content.scan(/[\s\S]{1,20}( |$)/).length
|
97
|
+
line_height_base * lines
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfceLib
|
4
|
+
class QrCode
|
5
|
+
require 'rqrcode'
|
6
|
+
require 'chunky_png'
|
7
|
+
require 'tempfile'
|
8
|
+
|
9
|
+
def initialize(pdf, xml)
|
10
|
+
@pdf = pdf
|
11
|
+
@xml = xml
|
12
|
+
end
|
13
|
+
|
14
|
+
def render
|
15
|
+
qrcode = RQRCode::QRCode.new(@xml['qrCode'])
|
16
|
+
image = Tempfile.new(%w[qrcode png], binmode: true)
|
17
|
+
image.write(qrcode.as_png(module_px_size: 12).to_s)
|
18
|
+
|
19
|
+
box_size = 3.cm
|
20
|
+
@pdf.image image, width: box_size, height: box_size, position: :center
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfceLib
|
4
|
+
class Recipient
|
5
|
+
def initialize(pdf, xml)
|
6
|
+
@pdf = pdf
|
7
|
+
@xml = xml
|
8
|
+
end
|
9
|
+
|
10
|
+
def render
|
11
|
+
@pdf.render_blank_line
|
12
|
+
|
13
|
+
if identified_recipient?
|
14
|
+
render_document
|
15
|
+
|
16
|
+
@pdf.text @xml['dest/xNome'], options
|
17
|
+
@pdf.text BrDanfe::DanfeLib::NfceLib::Helper.address(@xml.css('enderDest')), options
|
18
|
+
else
|
19
|
+
@pdf.text 'CONSUMIDOR NÃO IDENTIFICADO', options
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def options
|
26
|
+
{ size: 7, align: :center }
|
27
|
+
end
|
28
|
+
|
29
|
+
def identified_recipient?
|
30
|
+
@xml['dest/xNome'].present?
|
31
|
+
end
|
32
|
+
|
33
|
+
def render_document
|
34
|
+
document_text = document
|
35
|
+
|
36
|
+
@pdf.text document_text, options if document_text.present?
|
37
|
+
end
|
38
|
+
|
39
|
+
def document
|
40
|
+
return company if company?
|
41
|
+
return individual if individual?
|
42
|
+
return foreign if foreign?
|
43
|
+
|
44
|
+
''
|
45
|
+
end
|
46
|
+
|
47
|
+
def company?
|
48
|
+
@xml['dest/CNPJ'].present?
|
49
|
+
end
|
50
|
+
|
51
|
+
def company
|
52
|
+
cnpj = BrDocuments::CnpjCpf::Cnpj.new @xml['dest/CNPJ']
|
53
|
+
"CONSUMIDOR CNPJ: #{cnpj.formatted}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def individual?
|
57
|
+
@xml['dest/CPF'].present?
|
58
|
+
end
|
59
|
+
|
60
|
+
def individual
|
61
|
+
cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['dest/CPF'])
|
62
|
+
"CONSUMIDOR CPF: #{cpf.formatted}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def foreign?
|
66
|
+
@xml['dest/idEstrangeiro'].present?
|
67
|
+
end
|
68
|
+
|
69
|
+
def foreign
|
70
|
+
"CONSUMIDOR Id. Estrangeiro: #{@xml['dest/idEstrangeiro']}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfceLib
|
4
|
+
class TotalList
|
5
|
+
require 'bigdecimal'
|
6
|
+
|
7
|
+
def initialize(pdf, xml)
|
8
|
+
@pdf = pdf
|
9
|
+
@xml = xml
|
10
|
+
end
|
11
|
+
|
12
|
+
def render
|
13
|
+
subtotal
|
14
|
+
totals
|
15
|
+
payment_methods
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def subtotal
|
21
|
+
cursor = @pdf.cursor
|
22
|
+
@pdf.bounding_box [4.8.cm, cursor], width: 1.4.cm, height: 0.2.cm do
|
23
|
+
@pdf.text 'Subtotal R$', size: 6, align: :left
|
24
|
+
end
|
25
|
+
@pdf.bounding_box [6.2.cm, cursor], width: 1.2.cm, height: 0.2.cm do
|
26
|
+
@pdf.text BrDanfe::Helper.numerify(@xml['ICMSTot > vProd'].to_f), size: 6, align: :right
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def totals
|
31
|
+
@pdf.render_blank_line
|
32
|
+
|
33
|
+
cursor = @pdf.cursor
|
34
|
+
print_text('Qtde. total de itens', cursor, size: 7, align: :left)
|
35
|
+
print_text(@xml.css('det').count.to_s, cursor, size: 7, align: :right)
|
36
|
+
|
37
|
+
cursor = @pdf.cursor
|
38
|
+
print_text('Desconto R$', cursor, size: 7, align: :left)
|
39
|
+
print_text(BrDanfe::Helper.numerify(@xml['ICMSTot > vDesc'].to_f), cursor, size: 7, align: :right)
|
40
|
+
|
41
|
+
cursor = @pdf.cursor
|
42
|
+
print_text('Valor Total R$', cursor, size: 7, align: :left, style: :bold)
|
43
|
+
print_text(BrDanfe::Helper.numerify(@xml['ICMSTot > vNF'].to_f), cursor, size: 7, align: :right, style: :bold)
|
44
|
+
end
|
45
|
+
|
46
|
+
def payment_methods
|
47
|
+
payments = {}
|
48
|
+
without_payment = '90'
|
49
|
+
|
50
|
+
@xml.css('detPag').each do |detPag|
|
51
|
+
next if detPag.css('tPag').text == without_payment
|
52
|
+
|
53
|
+
payments[detPag.css('tPag').text] ||= BigDecimal('0')
|
54
|
+
actual_payment_value = BigDecimal(detPag.css('vPag').text)
|
55
|
+
payments[detPag.css('tPag').text] += actual_payment_value
|
56
|
+
end
|
57
|
+
|
58
|
+
if payments.present?
|
59
|
+
@pdf.render_blank_line
|
60
|
+
|
61
|
+
cursor = @pdf.cursor
|
62
|
+
print_text('Forma de pagamento', cursor, size: 7, align: :left, style: :bold)
|
63
|
+
print_text('Valor pago R$', cursor, size: 7, align: :right, style: :bold)
|
64
|
+
|
65
|
+
payments.each do |key, value|
|
66
|
+
cursor = @pdf.cursor
|
67
|
+
print_text(I18n.t("nfce.payment_methods.#{key}"), cursor, size: 7, align: :left)
|
68
|
+
print_text(BrDanfe::Helper.numerify(value.to_f), cursor, size: 7, align: :right)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def print_text(text, cursor, options)
|
74
|
+
@pdf.bounding_box [0, cursor], width: 7.4.cm, height: 0.25.cm do
|
75
|
+
@pdf.text text, options
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|