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,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,109 @@
|
|
|
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.join(' * ')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def complementary_content
|
|
51
|
+
@xml['infAdic/infCpl'].to_s
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def complementary?
|
|
55
|
+
@xml['infAdic/infCpl'].to_s != ''
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def address_content
|
|
59
|
+
"Endereço: #{Helper.generate_address @xml}"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def address?
|
|
63
|
+
Helper.address_is_too_big @pdf, Helper.generate_address(@xml)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def difal_content
|
|
67
|
+
I18n.t(
|
|
68
|
+
'danfe.infAdic.difal',
|
|
69
|
+
vICMSUFDest: numerify(@xml['ICMSTot/vICMSUFDest']),
|
|
70
|
+
vFCPUFDest: numerify(@xml['ICMSTot/vFCPUFDest']),
|
|
71
|
+
vICMSUFRemet: numerify(@xml['ICMSTot/vICMSUFRemet'])
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def numerify(value)
|
|
76
|
+
BrDanfe::Helper.numerify(value) if value != ''
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def difal?
|
|
80
|
+
@xml['ICMSTot/vICMSUFDest'].to_f != 0
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def fisco_content
|
|
84
|
+
@xml['infAdic/infAdFisco'].to_s
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def fisco?
|
|
88
|
+
@xml['infAdic/infAdFisco'].to_s.present?
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def generate_y_position(volumes_number)
|
|
92
|
+
if volumes_number > 1
|
|
93
|
+
return Y_POSITION + 0.30 + volumes_number * 0.15 + 0.2
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
Y_POSITION + 0.30
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def additional_data?
|
|
100
|
+
complementary? || address? || difal? || fisco?
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def render_reserved_fisco
|
|
104
|
+
@pdf.ibox 2.65, 7.15, 13.20, @y_position, I18n.t('danfe.infAdic.reserved')
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
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
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module BrDanfe
|
|
2
|
+
module DanfeLib
|
|
3
|
+
module NfeLib
|
|
4
|
+
class Issqn
|
|
5
|
+
Y_POSITION = 25.72 + SPACE_BETWEEN_GROUPS
|
|
6
|
+
|
|
7
|
+
def initialize(pdf, xml)
|
|
8
|
+
@pdf = pdf
|
|
9
|
+
@xml = xml
|
|
10
|
+
|
|
11
|
+
@title = Y_POSITION - 0.42
|
|
12
|
+
@y_position = Y_POSITION
|
|
13
|
+
|
|
14
|
+
@serv = 'total/ISSQNtot/vServ'
|
|
15
|
+
@bc = 'total/ISSQNtot/vBC'
|
|
16
|
+
@iss = 'total/ISSQNtot/vISS'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def render
|
|
20
|
+
if can_render?
|
|
21
|
+
@pdf.ititle 0.42, 10.00, 0.75, @title, 'issqn.title'
|
|
22
|
+
@pdf.lbox LINE_HEIGHT, 4.64, 0.75, @y_position, @xml, 'emit/IM'
|
|
23
|
+
@pdf.lnumeric LINE_HEIGHT, 5.14, 5.39, @y_position, @xml, @serv
|
|
24
|
+
@pdf.lnumeric LINE_HEIGHT, 5.14, 10.53, @y_position, @xml, @bc
|
|
25
|
+
@pdf.lnumeric LINE_HEIGHT, 4.64, 15.67, @y_position, @xml, @iss
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def can_render?
|
|
32
|
+
@xml[@serv].to_i.positive? || @xml[@bc].to_i.positive? || @xml[@iss].to_i.positive?
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|