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,55 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfeLib
|
4
|
+
class Dup
|
5
|
+
Y = 12.92
|
6
|
+
|
7
|
+
def initialize(pdf, xml)
|
8
|
+
@pdf = pdf
|
9
|
+
@xml = xml
|
10
|
+
|
11
|
+
@ltitle = Y - 0.42
|
12
|
+
end
|
13
|
+
|
14
|
+
def render
|
15
|
+
@pdf.ititle 0.42, 10.00, 0.75, @ltitle, 'dup.title'
|
16
|
+
@pdf.ibox 0.85, 19.57, 0.75, Y
|
17
|
+
|
18
|
+
x = 0.75
|
19
|
+
y = Y
|
20
|
+
@xml.collect('xmlns', 'dup') do |det|
|
21
|
+
render_dup(det, x, y)
|
22
|
+
x += 2.30
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def render_dup(det, x, y)
|
29
|
+
@pdf.ibox 0.85, 2.12, x, y, '', I18n.t('danfe.dup.nDup'), italic
|
30
|
+
@pdf.ibox 0.85, 2.12, x + 0.70, y, '', det.css('nDup').text, normal
|
31
|
+
@pdf.ibox 0.85, 2.12, x, y + 0.20, '', I18n.t('danfe.dup.dVenc'), italic
|
32
|
+
|
33
|
+
@pdf.ibox 0.85, 2.12, x + 0.70, y + 0.20, '', dtduplicata(det), normal
|
34
|
+
|
35
|
+
@pdf.ibox 0.85, 2.12, x, y + 0.40, '', I18n.t('danfe.dup.vDup'), italic
|
36
|
+
@pdf.inumeric 0.85, 1.25, x + 0.70, y + 0.40, '', det.css('vDup').text, normal
|
37
|
+
end
|
38
|
+
|
39
|
+
def dtduplicata(det)
|
40
|
+
dtduplicata = det.css('dVenc').text
|
41
|
+
dtduplicata = dtduplicata[8, 2] + '/' + dtduplicata[5, 2] + '/' + dtduplicata[0, 4]
|
42
|
+
dtduplicata
|
43
|
+
end
|
44
|
+
|
45
|
+
def normal
|
46
|
+
{ size: 6, border: 0 }
|
47
|
+
end
|
48
|
+
|
49
|
+
def italic
|
50
|
+
normal.merge(style: :italic)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfeLib
|
4
|
+
class EmitHeader
|
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(page, y_position)
|
13
|
+
@y_position = y_position
|
14
|
+
company_box
|
15
|
+
danfe_box page
|
16
|
+
access_key_box
|
17
|
+
sefaz_box
|
18
|
+
render_emit y_position
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def company_box
|
24
|
+
@pdf.ibox 3.92, 7.46, 0.75, @y_position
|
25
|
+
@pdf.ibox 3.92, 7.46, 0.75, @y_position, '', @xml['emit/xNome'],
|
26
|
+
size: 12, align: :center, border: 0, style: :bold
|
27
|
+
|
28
|
+
address_company
|
29
|
+
end
|
30
|
+
|
31
|
+
def address_company
|
32
|
+
if @logo.blank?
|
33
|
+
@pdf.ibox 3.92, 7.46, 1.25, @y_position + 1.46, '', address, align: :left, border: 0
|
34
|
+
else
|
35
|
+
@pdf.ibox 3.92, 7.46, 3.60, @y_position + 1.46, '', address, size: 8, align: :left, border: 0
|
36
|
+
logo
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def address
|
41
|
+
formatted = @xml['enderEmit/xLgr'] + ', ' + @xml['enderEmit/nro'] + "\n"
|
42
|
+
formatted += @xml['enderEmit/xBairro'] + ' - ' + cep + "\n"
|
43
|
+
formatted += @xml['enderEmit/xMun'] + '/' + @xml['enderEmit/UF'] + "\n"
|
44
|
+
formatted += phone + ' ' + @xml['enderEmit/email']
|
45
|
+
formatted
|
46
|
+
end
|
47
|
+
|
48
|
+
def phone
|
49
|
+
Phone.format(@xml['enderEmit/fone'])
|
50
|
+
end
|
51
|
+
|
52
|
+
def cep
|
53
|
+
Cep.format(@xml['enderEmit/CEP'])
|
54
|
+
end
|
55
|
+
|
56
|
+
def logo
|
57
|
+
bounding_box_size = 80
|
58
|
+
logo_options = BrDanfe::Logo::Options.new(bounding_box_size, @logo_dimensions).options
|
59
|
+
|
60
|
+
@pdf.bounding_box(
|
61
|
+
[0.83.cm, Helper.invert(@y_position.cm + 1.02.cm)], width: bounding_box_size, height: bounding_box_size
|
62
|
+
) do
|
63
|
+
@pdf.image @logo, logo_options
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def danfe_box(page)
|
68
|
+
@pdf.ibox 3.92, 2.08, 8.21, @y_position
|
69
|
+
|
70
|
+
@pdf.ibox 0.60, 2.08, 8.21, @y_position, '', 'DANFE',
|
71
|
+
size: 12, align: :center, border: 0, style: :bold
|
72
|
+
|
73
|
+
@pdf.ibox 1.20, 2.08, 8.21, @y_position + 0.60, '', I18n.t('danfe.others.danfe'),
|
74
|
+
size: 8, align: :center, border: 0
|
75
|
+
|
76
|
+
@pdf.ibox 0.60, 2.08, 8.21, @y_position + 1.80, '',
|
77
|
+
"#{@xml['ide/tpNF']} - " +
|
78
|
+
(@xml['ide/tpNF'] == '0' ? I18n.t('danfe.ide.tpNF.entry') : I18n.t('danfe.ide.tpNF.departure')),
|
79
|
+
size: 8, align: :center, border: 0
|
80
|
+
|
81
|
+
@pdf.ibox 1.00, 2.08, 8.21, @y_position + 2.40, '',
|
82
|
+
I18n.t('danfe.ide.document', nNF: @xml['ide/nNF'], serie: @xml['ide/serie']),
|
83
|
+
size: 8, align: :center, valign: :center, border: 0, style: :bold
|
84
|
+
|
85
|
+
@pdf.ibox 1.00, 2.08, 8.21, @y_position + 3.00, '',
|
86
|
+
I18n.t('danfe.others.page', current: page, total: @pdf.page_count),
|
87
|
+
size: 8, align: :center, valign: :center, border: 0, style: :bold
|
88
|
+
end
|
89
|
+
|
90
|
+
def access_key_box
|
91
|
+
@pdf.ibox 2.22, 10.02, 10.29, @y_position
|
92
|
+
@pdf.ibarcode 1.50, 8.00, 10.4010, @y_position + 1.90, @xml['chNFe']
|
93
|
+
@pdf.ibox 0.85, 10.02, 10.29, @y_position + 2.22, I18n.t('danfe.chNFe'),
|
94
|
+
@xml['chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, '\\1 '), style: :bold, align: :center
|
95
|
+
end
|
96
|
+
|
97
|
+
def sefaz_box
|
98
|
+
@pdf.ibox 0.85, 10.02, 10.29, @y_position + 3.07, '', I18n.t('danfe.others.sefaz'),
|
99
|
+
align: :center, size: 8
|
100
|
+
end
|
101
|
+
|
102
|
+
def render_emit(y_position)
|
103
|
+
y_first_line = y_position + 3.92
|
104
|
+
y_second_line = y_first_line + LINE_HEIGHT
|
105
|
+
|
106
|
+
@pdf.lbox LINE_HEIGHT, 10.04, 0.75, y_first_line, @xml, 'ide/natOp'
|
107
|
+
@pdf.ibox LINE_HEIGHT, 9.52, 10.79, y_first_line, I18n.t('danfe.infProt'),
|
108
|
+
"#{@xml['infProt/nProt']} #{BrDanfe::Helper.format_datetime(@xml['infProt/dhRecbto'])}", align: :center
|
109
|
+
|
110
|
+
@pdf.lie LINE_HEIGHT, 6.36, 0.75, y_second_line, @xml, 'enderEmit/UF', 'emit/IE'
|
111
|
+
@pdf.lie LINE_HEIGHT, 6.86, 7.11, y_second_line, @xml, 'enderDest/UF', 'emit/IEST'
|
112
|
+
@pdf.lcnpj LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, 'emit/CNPJ'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfeLib
|
4
|
+
class Helper
|
5
|
+
def self.invert(y)
|
6
|
+
29.7.cm - y
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.format_date(xml_datetime)
|
10
|
+
formated = ''
|
11
|
+
|
12
|
+
unless xml_datetime.empty?
|
13
|
+
date = DateTime.strptime(xml_datetime, '%Y-%m-%d')
|
14
|
+
formated = date.strftime('%d/%m/%Y')
|
15
|
+
end
|
16
|
+
|
17
|
+
formated
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.format_time(xml_datetime)
|
21
|
+
formated = ''
|
22
|
+
|
23
|
+
if xml_datetime.length == 8
|
24
|
+
formated = xml_datetime
|
25
|
+
elsif xml_datetime.length > 8
|
26
|
+
date = DateTime.strptime(xml_datetime, '%Y-%m-%dT%H:%M:%S %Z').to_time
|
27
|
+
formated = date.strftime('%H:%M:%S')
|
28
|
+
end
|
29
|
+
|
30
|
+
formated
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.mensure_text(pdf, text)
|
34
|
+
pdf.width_of(text)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.address_is_too_big(pdf, address)
|
38
|
+
Helper.mensure_text(pdf, address) > Dest::MAXIMUM_SIZE_FOR_STREET
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.generate_address(xml)
|
42
|
+
address_complement = " - #{xml_text(xml, 'enderDest/xCpl')}" if xml_text(xml, 'enderDest/xCpl').present?
|
43
|
+
address_number = " #{xml_text(xml, 'enderDest/nro')}" if xml_text(xml, 'enderDest/nro').present?
|
44
|
+
"#{xml_text(xml, 'enderDest/xLgr')}#{address_number}#{address_complement}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.xml_text(xml, property)
|
48
|
+
xml.css(property).text
|
49
|
+
end
|
50
|
+
|
51
|
+
private_class_method :xml_text
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfeLib
|
4
|
+
class Icmstot
|
5
|
+
Y = 13.77 + SPACE_BETWEEN_GROUPS
|
6
|
+
|
7
|
+
def initialize(pdf, xml)
|
8
|
+
@pdf = pdf
|
9
|
+
@xml = xml
|
10
|
+
|
11
|
+
@ltitle = Y - 0.42
|
12
|
+
@l1 = Y
|
13
|
+
@l2 = Y + LINE_HEIGHT
|
14
|
+
end
|
15
|
+
|
16
|
+
def render
|
17
|
+
@pdf.ititle 0.42, 5.60, 0.75, @ltitle, 'ICMSTot.title'
|
18
|
+
|
19
|
+
@pdf.lnumeric LINE_HEIGHT, 3.56, 0.75, @l1, @xml, 'ICMSTot/vBC'
|
20
|
+
@pdf.lnumeric LINE_HEIGHT, 4.06, 4.31, @l1, @xml, 'ICMSTot/vICMS'
|
21
|
+
@pdf.lnumeric LINE_HEIGHT, 4.06, 8.37, @l1, @xml, 'ICMSTot/vBCST'
|
22
|
+
@pdf.lnumeric LINE_HEIGHT, 4.06, 12.43, @l1, @xml, 'ICMSTot/vST'
|
23
|
+
@pdf.lnumeric LINE_HEIGHT, 3.82, 16.49, @l1, @xml, 'ICMSTot/vProd'
|
24
|
+
|
25
|
+
@pdf.lnumeric LINE_HEIGHT, 2.55, 0.75, @l2, @xml, 'ICMSTot/vFrete'
|
26
|
+
@pdf.lnumeric LINE_HEIGHT, 3.05, 3.30, @l2, @xml, 'ICMSTot/vSeg'
|
27
|
+
@pdf.lnumeric LINE_HEIGHT, 3.04, 6.35, @l2, @xml, 'ICMSTot/vDesc'
|
28
|
+
@pdf.lnumeric LINE_HEIGHT, 3.04, 9.39, @l2, @xml, 'ICMSTot/vOutro'
|
29
|
+
@pdf.lnumeric LINE_HEIGHT, 4.06, 12.43, @l2, @xml, 'ICMSTot/vIPI'
|
30
|
+
@pdf.lnumeric LINE_HEIGHT, 3.82, 16.49, @l2, @xml, 'ICMSTot/vNF', style: :bold
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfeLib
|
4
|
+
class Infadic
|
5
|
+
Y_POSITION = 27.04 + SPACE_BETWEEN_GROUPS
|
6
|
+
|
7
|
+
def initialize(pdf, xml)
|
8
|
+
@pdf = pdf
|
9
|
+
@xml = xml
|
10
|
+
@title_position = Y_POSITION - 0.41
|
11
|
+
@y_position = Y_POSITION
|
12
|
+
end
|
13
|
+
|
14
|
+
def render(volumes_number)
|
15
|
+
render_title
|
16
|
+
render_subtitle
|
17
|
+
render_volumes if volumes_number > 1
|
18
|
+
render_additional_data generate_y_position(volumes_number) if additional_data?
|
19
|
+
render_reserved_fisco
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def render_title
|
25
|
+
@pdf.ititle 0.42, 10.00, 0.75, @title_position, 'infAdic.title'
|
26
|
+
end
|
27
|
+
|
28
|
+
def render_subtitle
|
29
|
+
@pdf.ibox 2.65, 12.45, 0.75, @y_position, I18n.t('danfe.infAdic.infCpl'), '', size: 8, valign: :top
|
30
|
+
end
|
31
|
+
|
32
|
+
def render_volumes
|
33
|
+
InfadicVol.new(@xml, @pdf).render
|
34
|
+
end
|
35
|
+
|
36
|
+
def render_additional_data(y_position)
|
37
|
+
data = generate_additional_data
|
38
|
+
@pdf.ibox 2.65, 12.45, 0.75, y_position, '', data, size: 6, valign: :top, border: 0
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate_additional_data
|
42
|
+
additional_data = []
|
43
|
+
additional_data.push(complementary_content) if complementary?
|
44
|
+
additional_data.push(address_content) if address?
|
45
|
+
additional_data.push(difal_content) if difal?
|
46
|
+
additional_data.push(fisco_content) if fisco?
|
47
|
+
additional_data.push(address_shipment) if shipment?
|
48
|
+
additional_data.join(' * ')
|
49
|
+
end
|
50
|
+
|
51
|
+
def complementary_content
|
52
|
+
@xml['infAdic/infCpl'].to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
def complementary?
|
56
|
+
@xml['infAdic/infCpl'].to_s != ''
|
57
|
+
end
|
58
|
+
|
59
|
+
def address_content
|
60
|
+
"Endereço: #{Helper.generate_address @xml}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def address?
|
64
|
+
Helper.address_is_too_big @pdf, Helper.generate_address(@xml)
|
65
|
+
end
|
66
|
+
|
67
|
+
def difal_content
|
68
|
+
I18n.t(
|
69
|
+
'danfe.infAdic.difal',
|
70
|
+
vICMSUFDest: numerify(@xml['ICMSTot/vICMSUFDest']),
|
71
|
+
vFCPUFDest: numerify(@xml['ICMSTot/vFCPUFDest']),
|
72
|
+
vICMSUFRemet: numerify(@xml['ICMSTot/vICMSUFRemet'])
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def numerify(value)
|
77
|
+
BrDanfe::Helper.numerify(value) if value != ''
|
78
|
+
end
|
79
|
+
|
80
|
+
def shipment?
|
81
|
+
@xml['entrega'].present?
|
82
|
+
end
|
83
|
+
|
84
|
+
def address_shipment
|
85
|
+
street = @xml['entrega/xLgr'].to_s
|
86
|
+
number = @xml['entrega/nro'].to_s
|
87
|
+
complement = @xml['entrega/xCpl'].to_s
|
88
|
+
neighborhood = @xml['entrega/xBairro'].to_s
|
89
|
+
city = @xml['entrega/xMun'].to_s
|
90
|
+
uf = @xml['entrega/UF'].to_s
|
91
|
+
|
92
|
+
"Endereço de entrega: #{street}, nº #{number} - #{neighborhood} - #{city} - #{uf} - #{complement}"
|
93
|
+
end
|
94
|
+
|
95
|
+
def difal?
|
96
|
+
@xml['ICMSTot/vICMSUFDest'].to_f != 0
|
97
|
+
end
|
98
|
+
|
99
|
+
def fisco_content
|
100
|
+
@xml['infAdic/infAdFisco'].to_s
|
101
|
+
end
|
102
|
+
|
103
|
+
def fisco?
|
104
|
+
@xml['infAdic/infAdFisco'].to_s.present?
|
105
|
+
end
|
106
|
+
|
107
|
+
def generate_y_position(volumes_number)
|
108
|
+
if volumes_number > 1
|
109
|
+
return Y_POSITION + 0.30 + volumes_number * 0.15 + 0.2
|
110
|
+
end
|
111
|
+
|
112
|
+
Y_POSITION + 0.30
|
113
|
+
end
|
114
|
+
|
115
|
+
def additional_data?
|
116
|
+
complementary? || address? || difal? || fisco? || shipment?
|
117
|
+
end
|
118
|
+
|
119
|
+
def render_reserved_fisco
|
120
|
+
@pdf.ibox 2.65, 7.15, 13.20, @y_position, I18n.t('danfe.infAdic.reserved')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
module NfeLib
|
4
|
+
class InfadicVol
|
5
|
+
def initialize(xml, pdf)
|
6
|
+
@xml = xml
|
7
|
+
@pdf = pdf
|
8
|
+
@y_position = 27.56
|
9
|
+
end
|
10
|
+
|
11
|
+
def render
|
12
|
+
render_volume_title
|
13
|
+
render_volume
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def render_volume_title
|
19
|
+
@pdf.ibox 2.65, 12.45, 0.75, @y_position + 0.30, '', I18n.t('danfe.infAdic.vol.title'), size: 5, valign: :top,
|
20
|
+
border: 0
|
21
|
+
end
|
22
|
+
|
23
|
+
def render_volume
|
24
|
+
volumes = 0
|
25
|
+
y_position = @y_position + 0.47
|
26
|
+
|
27
|
+
@xml.collect('xmlns', 'vol') do |det|
|
28
|
+
volumes += 1
|
29
|
+
|
30
|
+
if volumes > 1
|
31
|
+
render_fields det, y_position
|
32
|
+
y_position += 0.15
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def render_fields(det, y_position)
|
38
|
+
render_esp det, y_position
|
39
|
+
render_marca det, y_position
|
40
|
+
render_qvol det, y_position
|
41
|
+
render_nvol det, y_position
|
42
|
+
render_pesob det, y_position
|
43
|
+
render_pesol det, y_position
|
44
|
+
end
|
45
|
+
|
46
|
+
def render_esp(det, y_position)
|
47
|
+
render_item_title 0.5, 1.35, 'esp', y_position
|
48
|
+
render_item_field det.css('esp').text, 3, 1.75, y_position
|
49
|
+
end
|
50
|
+
|
51
|
+
def render_item_title(width, x_position, field, y_position)
|
52
|
+
label = I18n.t("danfe.infAdic.vol.#{field}")
|
53
|
+
@pdf.ibox 0.35, width, x_position, y_position, '', label, style_normal
|
54
|
+
end
|
55
|
+
|
56
|
+
def style_normal
|
57
|
+
{ size: 4, border: 0 }
|
58
|
+
end
|
59
|
+
|
60
|
+
def render_item_field(value, width, x_position, y_position)
|
61
|
+
@pdf.ibox 0.35, width, x_position, y_position, '', value, style_italic
|
62
|
+
end
|
63
|
+
|
64
|
+
def style_italic
|
65
|
+
style_normal.merge(style: :italic)
|
66
|
+
end
|
67
|
+
|
68
|
+
def render_marca(det, y_position)
|
69
|
+
render_item_title 0.7, 4.15, 'marca', y_position
|
70
|
+
render_item_field det.css('marca').text, 2, 4.75, y_position
|
71
|
+
end
|
72
|
+
|
73
|
+
def render_qvol(det, y_position)
|
74
|
+
render_item_title 0.7, 0.75, 'qVol', y_position
|
75
|
+
render_item_field det.css('qVol').text, 0.7, 1.04, y_position
|
76
|
+
end
|
77
|
+
|
78
|
+
def render_nvol(det, y_position)
|
79
|
+
render_item_title 1, 6.1, 'nVol', y_position
|
80
|
+
render_item_field det.css('nVol').text, 1, 6.7, y_position
|
81
|
+
end
|
82
|
+
|
83
|
+
def render_pesob(det, y_position)
|
84
|
+
render_item_title 1.3, 7, 'pesoB', y_position
|
85
|
+
render_peso_item_field det.css('pesoB').text, 1.3, 7, y_position
|
86
|
+
end
|
87
|
+
|
88
|
+
def render_peso_item_field(value, width, x_position, y_pos)
|
89
|
+
@pdf.inumeric 0.35, width, x_position, y_pos, '', value, style_decimal
|
90
|
+
end
|
91
|
+
|
92
|
+
def style_decimal
|
93
|
+
style_italic.merge(decimals: 3)
|
94
|
+
end
|
95
|
+
|
96
|
+
def render_pesol(det, y_position)
|
97
|
+
render_item_title 0.9, 8.5, 'pesoL', y_position
|
98
|
+
render_peso_item_field det.css('pesoL').text, 1.5, 8.5, y_position
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|