Skip to content

Commit 7204185

Browse files
authored
Add new ship fields (#231)
1 parent ca977f2 commit 7204185

38 files changed

+963
-92
lines changed

.codeclimate.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ engines:
1414
enabled: true
1515
rubocop:
1616
enabled: true
17-
channel: rubocop-0-67-0
17+
channel: rubocop-0-92
1818
ratings:
1919
paths:
2020
- Gemfile.lock

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
br_danfe (0.20.0)
4+
br_danfe (1.0.0)
55
barby (= 0.6.9)
66
br_documents (>= 0.1.3)
77
i18n (>= 0.8.6)

config/locales/pt-BR.yml

+15
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,21 @@ pt-BR:
144144
received_at: "DATA DE RECEBIMENTO"
145145
receiver: "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR"
146146
document: "NF-e\nN°. %{nNF}\nSÉRIE %{serie}"
147+
entrega:
148+
title: "INFORMAÇÕES DO LOCAL DE ENTREGA"
149+
CNPJ: "CNPJ"
150+
CPF: "CPF"
151+
xNome: "NOME/RAZÃO SOCIAL"
152+
xLgr: "ENDEREÇO"
153+
nro: "NÚMERO"
154+
xCpl: "COMPLEMENTO"
155+
xBairro: "BAIRRO"
156+
cMun: "CÓDIGO DE MUNICÍPIO"
157+
xMun: "MUNICÍPIO"
158+
UF: "UF"
159+
CEP: "CEP"
160+
fone: "FONE/FAX"
161+
IE: "INSCRIÇÃO ESTADUAL"
147162
nfce:
148163
payment_methods:
149164
'01': "Dinheiro"

lib/br_danfe/danfe_lib/nfe.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def generate(footer_info)
4242
def render_on_first_page(xml)
4343
NfeLib::Ticket.new(@document, xml).render
4444
NfeLib::Dest.new(@document, xml).render
45+
NfeLib::Entrega.new(@document, xml).render
4546
NfeLib::Dup.new(@document, xml).render
4647
NfeLib::Icmstot.new(@document, xml).render
4748
NfeLib::Transp.new(@document, xml).render
@@ -73,13 +74,14 @@ def repeated_information(page, y_position, emitter, footer_info, xml, total_page
7374
@document.go_to_page(page)
7475

7576
emitter.render(initial_page_of_pdf, y_position, total_pages)
76-
render_product_table_title initial_page_of_pdf
77+
render_product_table_title initial_page_of_pdf, xml
7778
render_footer_information footer_info
7879
render_no_fiscal_value(xml)
7980
end
8081

81-
def render_product_table_title(page)
82-
y_position = page == 1 ? 18.91 : 7.40
82+
def render_product_table_title(page, xml)
83+
y_position = NfeLib::Entrega.delivery_local?(xml) && page == 1 ? 3.00 : 0
84+
y_position += page == 1 ? 18.91 : 7.40
8385
@document.ititle 0.42, 10.00, 0.75, y_position, 'det.title'
8486
end
8587

lib/br_danfe/danfe_lib/nfe_lib/dest.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def render_line2
5353
end
5454

5555
def address
56-
address = Helper.generate_address @xml
56+
address = Helper.generate_address @xml, 'enderDest'
5757

5858
if Helper.address_is_too_big(@pdf, address)
5959
address = address[0..address.length - 2] while Helper.mensure_text(@pdf, "#{address.strip}...") > MAXIMUM_SIZE_FOR_STREET && !address.empty?

lib/br_danfe/danfe_lib/nfe_lib/det_body.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ module BrDanfe
22
module DanfeLib
33
module NfeLib
44
class DetBody
5+
attr_reader :y_position_with_entrega
6+
57
def initialize(pdf, xml)
68
@pdf = pdf
79
@xml = xml
10+
11+
@y_position_with_entrega = Entrega.delivery_local?(@xml) ? 3.00 : 0.00
812
end
913

1014
def render(has_issqn)
@@ -121,7 +125,8 @@ def render_table(data, start_position, height)
121125
end
122126

123127
def table_position_on_first_page
124-
Helper.invert(18.07.cm)
128+
y_position = @y_position_with_entrega.cm + 18.07.cm
129+
Helper.invert(y_position)
125130
end
126131

127132
def table_position_on_next_pages

lib/br_danfe/danfe_lib/nfe_lib/dup.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@ module BrDanfe
22
module DanfeLib
33
module NfeLib
44
class Dup
5-
Y = 12.92
5+
attr_reader :y_position
6+
7+
Y_POSITION = 12.92
68

79
def initialize(pdf, xml)
810
@pdf = pdf
911
@xml = xml
1012

11-
@ltitle = Y - 0.42
13+
@y_position = Entrega.delivery_local?(@xml) ? Y_POSITION + 3.00 : Y_POSITION
14+
15+
@ltitle = @y_position - 0.42
1216
end
1317

1418
def render
1519
@pdf.ititle 0.42, 10.00, 0.75, @ltitle, 'dup.title'
16-
@pdf.ibox 0.85, 19.57, 0.75, Y
20+
@pdf.ibox 0.85, 19.57, 0.75, @y_position
1721

1822
x = 0.75
19-
y = Y
23+
y = @y_position
2024
@xml.collect('xmlns', 'dup') do |det|
2125
render_dup(det, x, y)
2226
x += 2.30
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
module BrDanfe
2+
module DanfeLib
3+
module NfeLib
4+
class Entrega
5+
Y_POSITION = 12.92
6+
MAXIMUM_SIZE_FOR_STREET = 319
7+
8+
def initialize(pdf, xml)
9+
@pdf = pdf
10+
@xml = xml
11+
12+
@y_position = Y_POSITION
13+
@ltitle = @y_position - 0.42
14+
@l1 = @y_position
15+
@l2 = @y_position + LINE_HEIGHT
16+
@l3 = @y_position + (LINE_HEIGHT * 2)
17+
end
18+
19+
def render
20+
if Entrega.delivery_local?(@xml)
21+
@pdf.ititle 0.42, 10.00, 0.75, @ltitle, 'entrega.title'
22+
render_line1
23+
render_line2
24+
render_line3
25+
end
26+
end
27+
28+
def self.delivery_local?(xml)
29+
doc = xml.is_a?(BrDanfe::XML) ? xml : Nokogiri::XML(xml)
30+
doc.css('entrega/xLgr').text.present?
31+
end
32+
33+
private
34+
35+
def render_line1
36+
@pdf.lbox LINE_HEIGHT, 11.82, 0.75, @l1, @xml, 'entrega/xNome'
37+
render_cnpj_cpf
38+
@pdf.lie LINE_HEIGHT, 2.92, 17.40, @l1, @xml, 'entrega/UF', 'entrega/IE'
39+
end
40+
41+
def render_cnpj_cpf
42+
if @xml['entrega/CNPJ'] == ''
43+
@pdf.i18n_lbox LINE_HEIGHT, 4.37, 12.57, @l1, 'entrega.CPF', cpf
44+
else
45+
@pdf.lcnpj LINE_HEIGHT, 4.37, 12.57, @l1, @xml, 'entrega/CNPJ'
46+
end
47+
end
48+
49+
def cpf
50+
cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['entrega/CPF'])
51+
cpf.formatted
52+
end
53+
54+
def render_line2
55+
@pdf.i18n_lbox LINE_HEIGHT, 11.82, 0.75, @l2, 'entrega.xLgr', address
56+
@pdf.lbox LINE_HEIGHT, 4.37, 12.57, @l2, @xml, 'entrega/xBairro'
57+
@pdf.i18n_lbox LINE_HEIGHT, 2.92, 17.40, @l2, 'entrega.CEP', cep
58+
end
59+
60+
def address
61+
address = Helper.generate_address @xml, 'entrega'
62+
63+
if Helper.address_is_too_big(@pdf, address)
64+
address = address[0..address.length - 2] while Helper.mensure_text(@pdf, "#{address.strip}...") > MAXIMUM_SIZE_FOR_STREET && !address.empty?
65+
address = "#{address.strip}..."
66+
end
67+
address
68+
end
69+
70+
def cep
71+
BrDanfe::Helper.format_cep(@xml['entrega/CEP'])
72+
end
73+
74+
def render_line3
75+
@pdf.lbox LINE_HEIGHT, 15.05, 0.75, @l3, @xml, 'entrega/xMun'
76+
@pdf.lbox LINE_HEIGHT, 1.14, 15.8, @l3, @xml, 'entrega/UF'
77+
@pdf.i18n_lbox LINE_HEIGHT, 2.92, 17.40, @l3, 'entrega.fone', phone
78+
end
79+
80+
def phone
81+
Phone.format(@xml['entrega/fone'])
82+
end
83+
end
84+
end
85+
end
86+
end

lib/br_danfe/danfe_lib/nfe_lib/helper.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def self.address_is_too_big(pdf, address)
3838
Helper.mensure_text(pdf, address) > Dest::MAXIMUM_SIZE_FOR_STREET
3939
end
4040

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}"
41+
def self.generate_address(xml, path)
42+
address_complement = " - #{xml_text(xml, "#{path}/xCpl")}" if xml_text(xml, "#{path}/xCpl").present?
43+
address_number = " #{xml_text(xml, "#{path}/nro")}" if xml_text(xml, "#{path}/nro").present?
44+
"#{xml_text(xml, "#{path}/xLgr")}#{address_number}#{address_complement}"
4545
end
4646

4747
def self.xml_text(xml, property)

lib/br_danfe/danfe_lib/nfe_lib/icmstot.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ module BrDanfe
22
module DanfeLib
33
module NfeLib
44
class Icmstot
5-
Y = 13.77 + SPACE_BETWEEN_GROUPS
5+
attr_reader :y_position
6+
7+
Y_POSITION = 13.77 + SPACE_BETWEEN_GROUPS
68

79
def initialize(pdf, xml)
810
@pdf = pdf
911
@xml = xml
1012

11-
@ltitle = Y - 0.42
12-
@l1 = Y
13-
@l2 = Y + LINE_HEIGHT
13+
@y_position = Entrega.delivery_local?(@xml) ? Y_POSITION + 3.00 : Y_POSITION
14+
15+
@ltitle = @y_position - 0.42
16+
@l1 = @y_position
17+
@l2 = @y_position + LINE_HEIGHT
1418
end
1519

1620
def render

lib/br_danfe/danfe_lib/nfe_lib/infadic.rb

+3-19
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def generate_additional_data
4444
additional_data.push(address_content) if address?
4545
additional_data.push(difal_content) if difal?
4646
additional_data.push(fisco_content) if fisco?
47-
additional_data.push(address_shipment) if shipment?
4847
additional_data.join(' * ')
4948
end
5049

@@ -57,11 +56,11 @@ def complementary?
5756
end
5857

5958
def address_content
60-
"Endereço: #{Helper.generate_address @xml}"
59+
"Endereço: #{Helper.generate_address @xml, 'enderDest'}"
6160
end
6261

6362
def address?
64-
Helper.address_is_too_big @pdf, Helper.generate_address(@xml)
63+
Helper.address_is_too_big @pdf, Helper.generate_address(@xml, 'enderDest')
6564
end
6665

6766
def difal_content
@@ -77,21 +76,6 @@ def numerify(value)
7776
BrDanfe::Helper.numerify(value) if value != ''
7877
end
7978

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-
9579
def difal?
9680
value = @xml['ICMSTot/vICMSUFDest'].presence || '0.0'
9781
BigDecimal(value).positive?
@@ -114,7 +98,7 @@ def generate_y_position(volumes_number)
11498
end
11599

116100
def additional_data?
117-
complementary? || address? || difal? || fisco? || shipment?
101+
complementary? || address? || difal? || fisco?
118102
end
119103

120104
def render_reserved_fisco

lib/br_danfe/danfe_lib/nfe_lib/issqn.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ module BrDanfe
22
module DanfeLib
33
module NfeLib
44
class Issqn
5+
attr_reader :y_position
6+
57
Y_POSITION = 25.72 + SPACE_BETWEEN_GROUPS
68

79
def initialize(pdf, xml)
810
@pdf = pdf
911
@xml = xml
1012

11-
@title = Y_POSITION - 0.42
12-
@y_position = Y_POSITION
13+
@y_position = Entrega.delivery_local?(@xml) ? Y_POSITION + 3.00 : Y_POSITION
14+
@title = @y_position - 0.42
1315

1416
@serv = 'total/ISSQNtot/vServ'
1517
@bc = 'total/ISSQNtot/vBC'

lib/br_danfe/danfe_lib/nfe_lib/transp.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ module BrDanfe
22
module DanfeLib
33
module NfeLib
44
class Transp
5-
Y = 15.89 + SPACE_BETWEEN_GROUPS
5+
attr_reader :y_position
6+
7+
Y_POSITION = 15.89 + SPACE_BETWEEN_GROUPS
68

79
def initialize(pdf, xml)
810
@pdf = pdf
911
@xml = xml
1012

11-
@ltitle = Y - 0.42
12-
@l1 = Y
13-
@l2 = Y + LINE_HEIGHT
13+
@y_position = Entrega.delivery_local?(@xml) ? Y_POSITION + 3.00 : Y_POSITION
14+
15+
@ltitle = @y_position - 0.42
16+
@l1 = @y_position
17+
@l2 = @y_position + LINE_HEIGHT
1418
end
1519

1620
def render

lib/br_danfe/danfe_lib/nfe_lib/vol.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ module BrDanfe
22
module DanfeLib
33
module NfeLib
44
class Vol
5-
Y = 18.01
5+
attr_reader :y_position
6+
7+
Y_POSITION = 18.01
68

79
def initialize(pdf, xml)
810
@pdf = pdf
911
@xml = xml
1012

11-
@l1 = Y
13+
@y_position = Entrega.delivery_local?(@xml) ? Y_POSITION + 3.00 : Y_POSITION
14+
15+
@l1 = @y_position
1216
end
1317

1418
def render

lib/br_danfe/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module BrDanfe
2-
VERSION = '0.20.0'.freeze
2+
VERSION = '1.0.0'.freeze
33
end

0 commit comments

Comments
 (0)