br_danfe 0.12.1 → 0.13.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -25
- data/Gemfile.lock +1 -1
- data/README.md +5 -5
- 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 +109 -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 +2 -2
- 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 +35 -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
- metadata +82 -75
- 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,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.create('qrcode.png')
|
|
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
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module BrDanfe
|
|
2
|
+
module DanfeLib
|
|
3
|
+
class Nfe < Base
|
|
4
|
+
private
|
|
5
|
+
|
|
6
|
+
def document
|
|
7
|
+
NfeLib::Document.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def create_watermark
|
|
11
|
+
@document.create_stamp('has_no_fiscal_value') do
|
|
12
|
+
@document.fill_color '7d7d7d'
|
|
13
|
+
@document.text_box I18n.t('danfe.others.has_no_fiscal_value'),
|
|
14
|
+
size: 2.2.cm,
|
|
15
|
+
width: @document.bounds.width,
|
|
16
|
+
height: @document.bounds.height,
|
|
17
|
+
align: :center,
|
|
18
|
+
valign: :center,
|
|
19
|
+
at: [0, @document.bounds.height],
|
|
20
|
+
rotate: 45,
|
|
21
|
+
rotate_around: :center
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def generate(footer_info)
|
|
26
|
+
render_on_first_page
|
|
27
|
+
render_on_each_page footer_info
|
|
28
|
+
@document
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def render_on_first_page
|
|
32
|
+
NfeLib::Ticket.new(@document, @xml).render
|
|
33
|
+
NfeLib::Dest.new(@document, @xml).render
|
|
34
|
+
NfeLib::Dup.new(@document, @xml).render
|
|
35
|
+
NfeLib::Icmstot.new(@document, @xml).render
|
|
36
|
+
NfeLib::Transp.new(@document, @xml).render
|
|
37
|
+
n_vol = NfeLib::Vol.new(@document, @xml).render
|
|
38
|
+
has_issqn = NfeLib::Issqn.new(@document, @xml).render
|
|
39
|
+
NfeLib::Infadic.new(@document, @xml).render(n_vol)
|
|
40
|
+
|
|
41
|
+
render_products has_issqn
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def render_products(has_issqn)
|
|
45
|
+
NfeLib::DetBody.new(@document, @xml).render(has_issqn)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def render_on_each_page(footer_info)
|
|
49
|
+
emitter = NfeLib::EmitHeader.new(@document, @xml, @options.logo, @options.logo_dimensions)
|
|
50
|
+
|
|
51
|
+
@document.page_count.times do |i|
|
|
52
|
+
page = i + 1
|
|
53
|
+
position = page == 1 ? 3.96 : 1.85
|
|
54
|
+
repeated_information page, position, emitter, footer_info
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def repeated_information(page, y_position, emitter, footer_info)
|
|
59
|
+
@document.go_to_page(page)
|
|
60
|
+
|
|
61
|
+
emitter.render page, y_position
|
|
62
|
+
render_product_table_title page
|
|
63
|
+
render_footer_information footer_info
|
|
64
|
+
render_no_fiscal_value
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def render_product_table_title(page)
|
|
68
|
+
y_position = page == 1 ? 18.91 : 7.40
|
|
69
|
+
@document.ititle 0.42, 10.00, 0.75, y_position, 'det.title'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def render_footer_information(footer_info)
|
|
73
|
+
if footer_info.present?
|
|
74
|
+
@document.ibox 0.35, 12.45, 0.75, 30.21, '', footer_info, size: 5, border: 0
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def render_no_fiscal_value
|
|
79
|
+
@document.stamp('has_no_fiscal_value') if BrDanfe::Helper.no_fiscal_value?(@xml)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|