dorsale 2.4.3 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 607158c6e243ca3759f3ee342f0cb51f510b1849
4
- data.tar.gz: 9bb7ca2ae6a3d937ddb267b810463f481ea795e8
3
+ metadata.gz: 440a037661b26b077f25466d7893487c797e4276
4
+ data.tar.gz: b29007bd7a54add8d064bbc4af228277f8511af2
5
5
  SHA512:
6
- metadata.gz: 08f8c8433616e3cc5e2499601900ec31fa324f1cdcb951a8e3ef764ab8851061da50f2faa57c1b32675fd292a0170a75fb5ae55f2e90cd412cb7664613869619
7
- data.tar.gz: 8f4fe0a820b92c825cbddcbe6c4d2fc54ccd83f74895f2287e3255e7795f515d9f705547f08d64275422c3923d4cf6a136a3a82e7094f8cc92720102b87187c2
6
+ metadata.gz: c94f5122db07d75c03853d8163e90f6627aabd2461652d61aeaa69dc87ee2af3a87788e489c5d965a9e0a6b65f52fb350269476783477a19890e721bfab690db
7
+ data.tar.gz: 3d9d15f4b6ace4de92364f07449cce09acecc3f688765dd0d4a6aca12693cae464ee7299dc142e2c70b0976a70fdf13f54ec08eabce2939f8bc02cd40ce9a706
@@ -126,7 +126,7 @@ module Dorsale
126
126
  def t(*args)
127
127
  return super if args.any?
128
128
 
129
- if balance < 0
129
+ if balance && balance < 0
130
130
  super(:credit_note)
131
131
  else
132
132
  self.class.t
@@ -2,26 +2,11 @@ module Dorsale
2
2
  module BillingMachine
3
3
  class InvoiceMultipleVatPdf < ::Dorsale::BillingMachine::InvoiceSingleVatPdf
4
4
 
5
- def first_column_width
6
- 6.4.cm
7
- end
8
-
9
- def second_column_width
10
- 2.cm
11
- end
12
-
13
- def third_column_width
14
- second_column_width
15
- end
16
-
17
- def fourth_column_width
18
- second_column_width
19
- end
20
-
21
- def fifth_column_width
22
- 2.9.cm
23
- end
24
-
5
+ def first_column_width; 64.mm; end
6
+ def second_column_width; 22.mm; end
7
+ def third_column_width; 20.mm; end
8
+ def fourth_column_width; 20.mm; end
9
+ def fifth_column_width; 29.mm; end
25
10
  def last_column_width
26
11
  bounds.width - first_column_width - second_column_width - third_column_width - fourth_column_width - fifth_column_width
27
12
  end
@@ -31,12 +16,12 @@ module Dorsale
31
16
  top = bounds.top
32
17
  width = bounds.width - left
33
18
 
34
- bounding_box [left, top], width: width, height: 9.5.cm do
19
+ bounding_box [left, top], width: width, height: products_table_height do
35
20
  repeat :all do
36
21
  float do
37
22
  table [["","","","","",""]],
38
23
  :column_widths => [first_column_width, second_column_width, third_column_width, fourth_column_width, fifth_column_width, last_column_width],
39
- :cell_style => {:height => 9.5.cm} do
24
+ :cell_style => {height: products_table_height} do
40
25
  row(0).style :text_color => BLACK
41
26
  row(0).style :font_style => :bold
42
27
  column(0).style :align => :left
@@ -46,20 +31,20 @@ module Dorsale
46
31
  end
47
32
  end
48
33
 
49
- bounding_box [left, top], width: width, height: 8.8.cm do
34
+ bounding_box [left, top], width: width, height: products_table_height do
50
35
  draw_bounds_debug
51
- repeat :all do
52
- build_line
53
- end
54
- table_products = [[I18n.t("pdfs.designation"),
55
- I18n.t("pdfs.quantity"),
56
- I18n.t("pdfs.unity"),
57
- I18n.t("pdfs.tax"),
58
- I18n.t("pdfs.unit_price"),
59
- I18n.t("pdfs.line_total")]]
36
+
37
+ table_products = [[
38
+ main_document.t(:designation).mb_chars.upcase.to_s,
39
+ main_document.t(:quantity).mb_chars.upcase.to_s,
40
+ main_document.t(:unit).mb_chars.upcase.to_s,
41
+ main_document.t(:tax).mb_chars.upcase.to_s,
42
+ main_document.t(:unit_price).mb_chars.upcase.to_s,
43
+ main_document.t(:line_total).mb_chars.upcase.to_s,
44
+ ]]
60
45
 
61
46
 
62
- @main_document.lines.each do |line|
47
+ main_document.lines.each do |line|
63
48
  table_products.push [line.label,
64
49
  number(line.quantity).gsub(",00","").gsub(".00",""),
65
50
  line.unit,
@@ -82,29 +67,48 @@ module Dorsale
82
67
  end
83
68
 
84
69
  def build_total
85
-
86
70
  left = bounds.left
87
- top = bounds.top - 10.3.cm
71
+ top = bounds.top - products_table_height - 5.mm
88
72
  width = bounds.width - left
73
+ height = middle_height - products_table_height
89
74
 
90
- bounding_box [left, top], width: width, height: middle_height - 9.5.cm do
75
+ bounding_box [left, top], width: width, height: height do
91
76
  draw_bounds_debug
92
77
 
93
78
  table_totals = [[]]
94
79
 
95
80
  if has_discount
96
- table_totals.push ["#{I18n.t("pdfs.commercial_discount")}", "\- #{euros(@main_document.commercial_discount)}"]
81
+ table_totals.push [
82
+ main_document.t(:commercial_discount).mb_chars.upcase.to_s,
83
+ euros(-main_document.commercial_discount),
84
+ ]
97
85
  end
98
86
 
99
- table_totals.push ["#{I18n.t("pdfs.total_excluding_taxes")}", euros(@main_document.total_excluding_taxes)]
87
+ table_totals.push [
88
+ main_document.t(:total_excluding_taxes).mb_chars.upcase.to_s,
89
+ euros(main_document.total_excluding_taxes),
90
+ ]
100
91
 
101
- table_totals.push ["#{I18n.t("pdfs.vat_amount")}", euros(@main_document.vat_amount)]
92
+ table_totals.push [
93
+ main_document.t(:vat_amount).mb_chars.upcase.to_s,
94
+ euros(main_document.vat_amount),
95
+ ]
102
96
 
103
97
  if has_advance
104
- table_totals.push ["#{I18n.t("pdfs.advance")}", euros(@main_document.advance)]
105
- table_totals.push ["#{I18n.t("pdfs.total_including_taxes")}", euros(@main_document.balance)]
98
+ table_totals.push [
99
+ main_document.t(:advance).mb_chars.upcase.to_s,
100
+ euros(main_document.advance),
101
+ ]
102
+
103
+ table_totals.push [
104
+ main_document.t(:total_including_taxes).mb_chars.upcase.to_s,
105
+ euros(main_document.balance),
106
+ ]
106
107
  else
107
- table_totals.push ["#{I18n.t("pdfs.total_including_taxes")}", euros(@main_document.total_including_taxes)]
108
+ table_totals.push [
109
+ main_document.t(:total_including_taxes).mb_chars.upcase.to_s,
110
+ euros(main_document.total_including_taxes),
111
+ ]
108
112
  end
109
113
 
110
114
  table table_totals,
@@ -15,31 +15,11 @@ module Dorsale
15
15
  BLUE = "005F9E"
16
16
 
17
17
  def has_advance
18
- @main_document.try(:advance) && @main_document.advance != 0.0
18
+ main_document.try(:advance) && main_document.advance != 0.0
19
19
  end
20
20
 
21
21
  def has_discount
22
- @main_document.try(:commercial_discount) && @main_document.commercial_discount != 0.0
23
- end
24
-
25
- def first_column_width
26
- 7.6.cm
27
- end
28
-
29
- def second_column_width
30
- 2.4.cm
31
- end
32
-
33
- def third_column_width
34
- second_column_width
35
- end
36
-
37
- def fourth_column_width
38
- 2.9.cm
39
- end
40
-
41
- def last_column_width
42
- bounds.width - first_column_width - second_column_width - third_column_width - fourth_column_width
22
+ main_document.try(:commercial_discount) && main_document.commercial_discount != 0.0
43
23
  end
44
24
 
45
25
  attr_reader :main_document
@@ -51,20 +31,22 @@ module Dorsale
51
31
  @id_card = main_document.id_card
52
32
  end
53
33
 
54
- def header_height
55
- 9.cm
56
- end
34
+ def header_height; 90.mm; end
35
+ def logo_height; 32.mm; end
57
36
 
58
- def middle_height
59
- 15.cm
60
- end
37
+ def footer_height; 40.mm; end
38
+ def footer_top_height; 15.mm; end
39
+ def footer_bottom_height; 15.mm; end
61
40
 
62
- def footer_height
63
- 4.cm
64
- end
41
+ def middle_height; 14.cm; end
42
+ def products_table_height; 90.mm; end
65
43
 
66
- def logo_height
67
- 3.2.cm
44
+ def first_column_width; 7.6.cm; end
45
+ def second_column_width; 2.4.cm; end
46
+ def third_column_width; 2.5.cm; end
47
+ def fourth_column_width; 2.9.cm; end
48
+ def last_column_width
49
+ bounds.width - first_column_width - second_column_width - third_column_width - fourth_column_width
68
50
  end
69
51
 
70
52
  def build
@@ -72,6 +54,7 @@ module Dorsale
72
54
  build_header
73
55
  build_footer
74
56
  end
57
+
75
58
  build_middle
76
59
  build_page_numbers
77
60
  end
@@ -107,23 +90,35 @@ module Dorsale
107
90
  height = 1.cm
108
91
  bounding_box [left, top], width: width, height: height do
109
92
  draw_bounds_debug
110
- text "<b>#{main_document.t} n° #{@main_document.tracking_id}</b>", inline_format: true, size: 20, align: :center
93
+ text "<b>#{main_document.t} n° #{main_document.tracking_id}</b>", inline_format: true, size: 20, align: :center
111
94
  end
112
95
  end
113
96
 
97
+ def logo_path
98
+ main_document.id_card.logo.path
99
+ rescue NoMethodError
100
+ nil
101
+ end
102
+
114
103
  def build_logo
115
- width = 3.2.cm
104
+ return if logo_path.nil?
105
+
106
+ width = 3.2.cm
116
107
  height = logo_height
108
+
117
109
  bounding_box [bounds.left, bounds.top], width: width, height: height do
118
110
  draw_bounds_debug
119
- if @main_document.id_card.logo.present?
120
- image @main_document.id_card.logo.path, width: (bounds.width - 1.cm)
121
- end
111
+ image logo_path, width: (bounds.width - 1.cm)
122
112
  end
123
113
  end
124
114
 
125
- def address_line
126
- [@id_card.address1,@id_card.address2, @id_card.zip, @id_card.city].select(&:present?).join(", ")
115
+ def contact_address_line
116
+ [
117
+ @id_card.address1,
118
+ @id_card.address2,
119
+ @id_card.zip,
120
+ @id_card.city,
121
+ ].select(&:present?).join(", ")
127
122
  end
128
123
 
129
124
  def build_contact
@@ -132,16 +127,20 @@ module Dorsale
132
127
  width = bounds.width / 2 - 1.1.cm
133
128
  height = 2.5.cm
134
129
 
130
+ contact_text = []
131
+ contact_text << "<b>#{@id_card.entity_name}</b>" if @id_card.entity_name.present?
132
+ contact_text << "<b>#{contact_address_line}</b>" if contact_address_line.present?
133
+ contact_text << " "
134
+ contact_text << "<b>#{main_document.t(:your_contact)} : #{@id_card.contact_full_name}</b>" if @id_card.contact_full_name.present?
135
+ contact_text << "<b>#{main_document.t(:contact_phone)} : </b> #{@id_card.contact_phone}" if @id_card.contact_phone.present?
136
+ contact_text << "<b>#{main_document.t(:contact_fax)} : </b> #{@id_card.contact_fax}" if @id_card.contact_fax.present?
137
+ contact_text << "<b>#{main_document.t(:contact_email)} : </b> #{@id_card.contact_email}" if @id_card.contact_email.present?
138
+ contact_text = contact_text.join("\n")
139
+
135
140
  bounding_box [left, top], width: width, height: height do
136
141
  draw_bounds_debug
137
142
  font_size 8 do
138
- text "<b>#{@id_card.entity_name}</b>", inline_format: true if @id_card.entity_name.present?
139
- text "<b>#{address_line} </b>", inline_format: true
140
- text " "
141
- text "<b>#{I18n.t("pdfs.your_contact")} : #{@id_card.contact_full_name}</b>", inline_format: true if @id_card.contact_full_name.present?
142
- text "<b>#{I18n.t("pdfs.contact_phone")}</b> #{@id_card.contact_phone}", inline_format: true if @id_card.contact_phone.present?
143
- text "<b>#{I18n.t("pdfs.contact_fax")}</b> #{@id_card.contact_fax}", inline_format: true if @id_card.contact_fax.present?
144
- text "<b>#{I18n.t("pdfs.contact_email")}</b> #{@id_card.contact_email}", inline_format: true if @id_card.contact_email.present?
143
+ text contact_text, inline_format: true
145
144
  end
146
145
  end
147
146
  end
@@ -155,17 +154,35 @@ module Dorsale
155
154
  bounding_box [left, top], width: width, height: height do
156
155
  draw_bounds_debug
157
156
 
158
- if @main_document.label.present?
159
- text "<b>#{I18n.t("pdfs.subject")}</b> #{@main_document.label}", inline_format: true
157
+ if main_document.label.present?
158
+ text "<b>#{main_document.t(:label)} : </b> #{main_document.label}", inline_format: true
160
159
  end
161
160
 
162
- if @main_document.date.present?
161
+ if main_document.date.present?
163
162
  move_down 3.mm
164
- text "<b>#{@main_document.t :date} :</b> #{date @main_document.date}", inline_format: true
163
+ text "<b>#{main_document.t(:date)} : </b> #{date main_document.date}", inline_format: true
165
164
  end
166
165
  end
167
166
  end
168
167
 
168
+ def customer_content
169
+ return if main_document.customer.nil?
170
+
171
+ content = []
172
+ content << main_document.customer.name
173
+ content << main_document.customer.address.street
174
+ content << main_document.customer.address.street_bis
175
+ content << "#{main_document.customer.address.zip} #{main_document.customer.address.city}"
176
+ content << main_document.customer.address.country
177
+
178
+ if main_document.customer.try(:european_union_vat_number).present?
179
+ content << main_document.customer.t(:european_union_vat_number)
180
+ content << main_document.customer.european_union_vat_number
181
+ end
182
+
183
+ content.select(&:present?).join("\n")
184
+ end
185
+
169
186
  def build_customer
170
187
  top = bounds.top - 4.cm
171
188
  left = bounds.width / 2 + 1.1.cm
@@ -181,22 +198,8 @@ module Dorsale
181
198
  fill_color BLACK
182
199
  end
183
200
 
184
- customer_text = []
185
- customer_text << @main_document.customer.name
186
- customer_text << @main_document.customer.address.street
187
- customer_text << @main_document.customer.address.street_bis
188
- customer_text << "#{@main_document.customer.address.zip} #{@main_document.customer.address.city}"
189
- customer_text << @main_document.customer.address.country
190
-
191
- if @main_document.customer.try(:european_union_vat_number).present?
192
- customer_text << @main_document.customer.t(:european_union_vat_number)
193
- customer_text << @main_document.customer.european_union_vat_number
194
- end
195
-
196
- customer_text = customer_text.select(&:present?).join("\n")
197
-
198
201
  bounding_box [bounds.left + padding, bounds.top - padding], height: bounds.height - padding, width: bounds.width - padding do
199
- text customer_text
202
+ text customer_content
200
203
  end
201
204
  end
202
205
  end # def build_customer
@@ -205,7 +208,9 @@ module Dorsale
205
208
  left = bounds.left
206
209
  top = bounds.top - header_height
207
210
  width = bounds.width - left
208
- bounding_box [left, top], width: width, height: middle_height do
211
+ height = middle_height
212
+
213
+ bounding_box [left, top], width: width, height: height do
209
214
  build_table
210
215
  build_total
211
216
  build_payment_conditions
@@ -219,80 +224,115 @@ module Dorsale
219
224
  left = bounds.left
220
225
  top = bounds.top
221
226
  width = bounds.width - left
227
+ height = products_table_height
222
228
 
223
- bounding_box [left, top], width: width, height: 9.5.cm do
229
+ # Empty table to draw lines
230
+ bounding_box [left, top], width: width, height: height do
224
231
  repeat :all do
225
232
  float do
226
- table [["","","","",""]],
227
- :column_widths => [first_column_width, second_column_width, third_column_width, fourth_column_width, last_column_width],
228
- :cell_style => {:height => 9.5.cm} do
229
- row(0).style :text_color => BLACK
230
- row(0).style :font_style => :bold
231
- column(0).style :align => :left
232
- column(1..4).style :align => :right
233
- end
234
- end
235
- end
236
- end
237
-
238
- bounding_box [left, top], width: width, height: 8.8.cm do
233
+ table [["","","","",""]],
234
+ :column_widths => [
235
+ first_column_width,
236
+ second_column_width,
237
+ third_column_width,
238
+ fourth_column_width,
239
+ last_column_width,
240
+ ],
241
+ :cell_style => {height: height} \
242
+ do
243
+ row(0).style :text_color => BLACK
244
+ row(0).style :font_style => :bold
245
+ column(0).style :align => :left
246
+ column(1..4).style :align => :right
247
+ end # table
248
+ end # float
249
+ end # repeat all
250
+ end # bounding_box
251
+
252
+ # products table
253
+ bounding_box [left, top], width: width, height: height do
239
254
  draw_bounds_debug
240
- repeat :all do
241
- build_line
242
- end
243
- table_products = [[I18n.t("pdfs.designation"),
244
- I18n.t("pdfs.quantity"),
245
- I18n.t("pdfs.unity"),
246
- I18n.t("pdfs.unit_price"),
247
- I18n.t("pdfs.line_total")]]
248
-
249
-
250
- @main_document.lines.each do |line|
251
- table_products.push [line.label,
252
- number(line.quantity).gsub(",00","").gsub(".00",""),
253
- line.unit,
254
- euros(line.unit_price),
255
- euros(line.total),]
255
+
256
+ table_products = [[
257
+ main_document.t(:designation).mb_chars.upcase.to_s,
258
+ main_document.t(:quantity).mb_chars.upcase.to_s,
259
+ main_document.t(:unit).mb_chars.upcase.to_s,
260
+ main_document.t(:unit_price).mb_chars.upcase.to_s,
261
+ main_document.t(:line_total).mb_chars.upcase.to_s,
262
+ ]]
263
+
264
+ main_document.lines.each do |line|
265
+ table_products.push [
266
+ line.label,
267
+ number(line.quantity).gsub(",00","").gsub(".00",""),
268
+ line.unit,
269
+ euros(line.unit_price),
270
+ euros(line.total),
271
+ ]
256
272
  end
257
273
 
258
- table table_products,
259
- :column_widths => [first_column_width, second_column_width, third_column_width, fourth_column_width, last_column_width],
260
- :header => true,
261
- :cell_style => {border_width: 0} do
274
+ table table_products,
275
+ :column_widths => [
276
+ first_column_width,
277
+ second_column_width,
278
+ third_column_width,
279
+ fourth_column_width,
280
+ last_column_width,
281
+ ],
282
+ :header => true,
283
+ :cell_style => {border_width: 0} \
284
+ do
262
285
  row(0).font_style = :bold
263
286
  row(0).border_width = 1,
264
- cells.style do |c|
265
- c.align = c.column == 0 ? :left : :right
266
- end
267
- end
268
- end
269
- end
287
+ cells.style { |c| c.align = c.column == 0 ? :left : :right }
288
+ end # table
289
+ end # bounding_box
290
+ end # build_table
270
291
 
271
292
  def build_total
272
-
273
293
  left = bounds.left
274
- top = bounds.top - 10.3.cm
294
+ top = bounds.top - products_table_height - 5.mm
275
295
  width = bounds.width - left
296
+ height = middle_height - products_table_height
276
297
 
277
- bounding_box [left, top], width: width, height: middle_height - 9.5.cm do
298
+ bounding_box [left, top], width: width, height: height do
278
299
  draw_bounds_debug
279
300
 
280
301
  table_totals = [[]]
281
302
 
282
303
  if has_discount
283
- table_totals.push ["#{I18n.t("pdfs.commercial_discount")}", "\- #{euros(@main_document.commercial_discount)}"]
304
+ table_totals.push [
305
+ main_document.t(:commercial_discount).mb_chars.upcase.to_s,
306
+ euros(-main_document.commercial_discount),
307
+ ]
284
308
  end
285
309
 
286
- table_totals.push ["#{I18n.t("pdfs.total_excluding_taxes")}", euros(@main_document.total_excluding_taxes)]
310
+ table_totals.push [
311
+ main_document.t(:total_excluding_taxes).mb_chars.upcase.to_s,
312
+ euros(main_document.total_excluding_taxes),
313
+ ]
287
314
 
288
- vat_rate = number(@main_document.vat_rate)
289
- table_totals.push ["#{I18n.t("pdfs.vat")}#{vat_rate} %", euros(@main_document.vat_amount)]
315
+ vat_rate = number(main_document.vat_rate)
316
+ table_totals.push [
317
+ "#{main_document.t(:vat).mb_chars.upcase.to_s} #{percentage vat_rate}",
318
+ euros(main_document.vat_amount),
319
+ ]
290
320
 
291
321
  if has_advance
292
- table_totals.push ["#{I18n.t("pdfs.advance")}", euros(@main_document.advance)]
293
- table_totals.push ["#{I18n.t("pdfs.total_including_taxes")}", euros(@main_document.balance)]
322
+ table_totals.push [
323
+ main_document.t(:advance).mb_chars.upcase.to_s,
324
+ euros(main_document.advance),
325
+ ]
326
+
327
+ table_totals.push [
328
+ main_document.t(:total_including_taxes).mb_chars.upcase.to_s,
329
+ euros(main_document.balance),
330
+ ]
294
331
  else
295
- table_totals.push ["#{I18n.t("pdfs.total_including_taxes")}", euros(@main_document.total_including_taxes)]
332
+ table_totals.push [
333
+ main_document.t(:total_including_taxes).mb_chars.upcase.to_s,
334
+ euros(main_document.total_including_taxes),
335
+ ]
296
336
  end
297
337
 
298
338
  table table_totals,
@@ -314,13 +354,14 @@ module Dorsale
314
354
  end
315
355
 
316
356
  def build_comments
317
- return if @main_document.comments.blank?
318
- top = bounds.top - 13.cm
319
- height = 1.5.cm
357
+ return if main_document.comments.blank?
358
+
359
+ top = bounds.top - products_table_height - 35.mm
360
+ height = top - bounds.bottom
320
361
  width = 10.cm
321
362
 
322
363
  font_size 9 do
323
- text_box @main_document.comments,
364
+ text_box main_document.comments,
324
365
  :at => [bounds.left, top],
325
366
  :height => height,
326
367
  :width => width,
@@ -329,15 +370,15 @@ module Dorsale
329
370
  end
330
371
 
331
372
  def build_payment_conditions
332
- top = bounds.top - 10.3.cm
373
+ top = bounds.top - products_table_height - 5.mm
333
374
  height = 1.cm
334
375
  width = 7.5.cm
335
376
 
336
377
  bounding_box [bounds.left, top], height: height, width: width do
337
378
  draw_bounds_debug
338
379
  font_size 9 do
339
- text I18n.t("pdfs.payment_terms"), style: :bold if @main_document.payment_term.present?
340
- text @main_document.payment_term.try(:label)
380
+ text main_document.t(:payment_terms), style: :bold if main_document.payment_term.present?
381
+ text main_document.payment_term.try(:label)
341
382
  end
342
383
  end
343
384
  end
@@ -346,61 +387,79 @@ module Dorsale
346
387
  end
347
388
 
348
389
  def build_bank_informations
349
- top = bounds.top - 11.5.cm
390
+ top = bounds.top - products_table_height - 20.mm
350
391
  height = 1.cm
351
392
  width = 7.5.cm
352
393
 
353
394
  bounding_box [bounds.left, top], height: height, width: width do
354
395
  draw_bounds_debug
355
396
  font_size 9 do
356
- text "#{I18n.t("pdfs.iban")} #{@id_card.iban}" if @id_card.iban.present?
357
- text "#{I18n.t("pdfs.bic_swift")} #{@id_card.bic_swift}" if @id_card.bic_swift.present?
397
+ text "#{main_document.t(:iban)} : #{@id_card.iban}" if @id_card.iban.present?
398
+ text "#{main_document.t(:bic_swift)} : #{@id_card.bic_swift}" if @id_card.bic_swift.present?
358
399
  end
359
400
  end
360
401
  end
361
402
 
362
403
  def build_footer
363
404
  top = bounds.bottom + footer_height
364
- bounding_box [0, top], width: bounds.width, height: footer_height do
365
-
366
- builds_legals
367
- build_line
368
- builds_id_card_informations
369
405
 
406
+ bounding_box [0, top], width: bounds.width, height: footer_height do
407
+ draw_bounds_debug
408
+ build_footer_top
409
+ build_footer_line
410
+ build_footer_bottom
370
411
  end
371
412
  end
372
413
 
373
- def builds_legals
374
- top = bounds.top
375
- height = 1.5.cm
414
+ def footer_top_content
415
+ @id_card.custom_info_1.to_s
416
+ end
417
+
418
+ def build_footer_top
419
+ top = bounds.top
420
+ height = footer_top_height
376
421
  width = bounds.width
377
- bounding_box [bounds.left, top], height: height, width: width do
378
- font_size 9 do
379
- text @id_card.custom_info_1, inline_format: true
380
- end
422
+
423
+ font_size 9 do
424
+ text_box footer_top_content,
425
+ :at => [bounds.left, top],
426
+ :height => height,
427
+ :width => width,
428
+ :overflow => :shrink_to_fit
381
429
  end
382
430
  end
383
431
 
384
- def build_line
432
+ def build_footer_line
433
+ # Center line between the two footer parts
434
+ n = footer_top_height + (footer_height - footer_top_height - footer_bottom_height) / 2
435
+ move_down n
385
436
  stroke do
386
437
  horizontal_rule
387
438
  line_width 1
388
439
  end
389
440
  end
390
441
 
391
- def builds_id_card_informations
392
- top = bounds.top - 1.8.cm
393
- height = 1.1.cm
442
+ def footer_bottom_content
443
+ infos_text = []
444
+ infos_text << @id_card.entity_name if @id_card.entity_name.present?
445
+ infos_text << "#{main_document.t(:info_phone)} : #{@id_card.contact_phone}" if @id_card.contact_phone.present?
446
+ infos_text << "#{main_document.t(:info_fax)} : #{@id_card.contact_fax}" if @id_card.contact_fax.present?
447
+ infos_text << "#{@id_card.contact_email}" if @id_card.contact_email.present?
448
+ infos_text << "#{@id_card.legal_form.to_s}" if @id_card.legal_form.present?
449
+ infos_text << "#{main_document.t(:capital)} : #{euros @id_card.capital}" if @id_card.capital.present?
450
+ infos_text << "#{main_document.t(:registration)} : #{@id_card.registration_city} #{@id_card.registration_number}" if @id_card.registration_number.present?
451
+ infos_text << "#{main_document.t(:siret)} : #{@id_card.siret}" if @id_card.siret.present?
452
+ infos_text << "#{main_document.t(:intracommunity_vat)} : #{@id_card.intracommunity_vat}" if @id_card.intracommunity_vat.present?
453
+ infos_text = infos_text.join(" - ")
454
+ end
455
+
456
+ def build_footer_bottom
457
+ height = footer_bottom_height
458
+ top = bounds.bottom + height
394
459
  width = bounds.width
395
- tel = "#{I18n.t("pdfs.info_phone")} #{@id_card.contact_phone} - " if @id_card.contact_phone.present?
396
- fax = "#{I18n.t("pdfs.info_fax")} #{@id_card.contact_fax} -" if @id_card.contact_fax.present?
397
- email = "#{@id_card.contact_email}" if @id_card.contact_email.present?
398
- capital = "#{ @id_card.legal_form.to_s} #{I18n.t("pdfs.capital")} " + number_with_delimiter(@id_card.capital, :delimiter => '.').to_s + " €" if @id_card.legal_form.present? && @id_card.capital.present?
399
- registration = I18n.t("pdfs.registration") + @id_card.registration_city.to_s + ' ' + @id_card.registration_number.to_s if @id_card.registration_number.present?
400
- siret = I18n.t("pdfs.siret") + @id_card.siret.to_s if @id_card.siret.present?
401
- tva = I18n.t("pdfs.vat") + @id_card.intracommunity_vat.to_s if @id_card.intracommunity_vat.present?
460
+
402
461
  font_size 9 do
403
- text_box "#{@id_card.entity_name} #{address_line}\n#{tel} #{fax} #{email}\n#{capital} #{registration} #{siret} #{tva}",
462
+ text_box footer_bottom_content,
404
463
  :at => [bounds.left, top],
405
464
  :height => height,
406
465
  :width => width,
@@ -409,15 +468,14 @@ module Dorsale
409
468
  end
410
469
 
411
470
  def build_page_numbers
412
- top = bounds.bottom + footer_height - 1.8.cm
413
- bounding_box [0, top], height: footer_height, width: bounds.width do
471
+ height = 5.mm
472
+ top = bounds.bottom + height
473
+ width = bounds.width
474
+
475
+ bounding_box [0, top], height: height, width: bounds.width do
414
476
  font_size 9 do
415
477
  float do
416
- options = {
417
- :align => :right,
418
- :start_count_at => 1
419
- }
420
- number_pages "page <page>/<total>", options
478
+ number_pages "page <page>/<total>", align: :right
421
479
  end
422
480
  end
423
481
  end