Class: Dorsale::BillingMachine::InvoiceSingleVatPdf
- Inherits:
-
Prawn::Document
- Object
- Prawn::Document
- Dorsale::BillingMachine::InvoiceSingleVatPdf
show all
- Includes:
- ActionView::Helpers::NumberHelper, Alexandrie::Prawn, AllHelpers
- Defined in:
- app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb
Constant Summary
collapse
- DEBUG =
false
- GREY =
"808080"
- LIGHT_GREY =
"C0C0C0"
- WHITE =
"FFFFFF"
- BLACK =
"000000"
- BLUE =
"005F9E"
Instance Attribute Summary collapse
Instance Method Summary
collapse
#avatar_img
#expense_states_for_filters_select
#flyboy_status_for_filters_select, #folder_color, #show_tasks_summary, #task_color, #tasks_for
#attachments_for
#icon
Methods included from TextHelper
#currency, #date, #euros, #hours, #info, #lf2br, #number, #percentage, #tags, #text2html
#engine_polymorphic_path
#paginate
Methods included from LinkHelper
#email_link, #icon_link_to, #tel_link, #twitter_link, #web_link
Methods included from FormHelper
#form_buttons, #horizontal_form_for, #search_form
#dorsale_time_periods_for_select, #filter_buttons, #filter_reset_button, #filter_submit_button, #filters_form
#actions_for, #render_contextual, #render_dorsale_index
#comments_for
#complete_button, #copy_button, #create_button, #delete_button, #dorsale_button, #download_button, #lock_button, #print_button, #read_button, #snooze_button, #unlock_button, #update_button
#render_with_attachments
Constructor Details
Returns a new instance of InvoiceSingleVatPdf.
29
30
31
32
33
34
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 29
def initialize(main_document)
super(page_size: 'A4', margin: 1.cm)
setup
@main_document = main_document
@id_card = main_document.id_card
end
|
Instance Attribute Details
#main_document ⇒ Object
Returns the value of attribute main_document.
27
28
29
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 27
def main_document
@main_document
end
|
Instance Method Details
#build ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 55
def build
repeat :all do
end
build_middle
build_page_numbers
end
|
395
396
397
398
399
400
401
402
403
404
405
406
407
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 395
def build_bank_informations
top = bounds.top - products_table_height - 20.mm
height = 1.cm
width = 7.5.cm
bounding_box [bounds.left, top], height: height, width: width do
draw_bounds_debug
font_size 9 do
text "#{main_document.t(:iban)} : #{@id_card.iban}" if @id_card.iban.present?
text "#{main_document.t(:bic_swift)} : #{@id_card.bic_swift}" if @id_card.bic_swift.present?
end
end
end
|
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 359
def
return if main_document..blank?
top = bounds.top - products_table_height - 35.mm
height = top - bounds.bottom
width = 10.cm
text_box main_document.,
:at => [bounds.left, top],
:height => height,
:width => width,
:overflow => :shrink_to_fit,
:size => 9
end
|
139
140
141
142
143
144
145
146
147
148
149
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 139
def build_contact
top = bounds.top - 4.cm
left = bounds.left
width = bounds.width / 2 - 1.1.cm
height = 2.5.cm
bounding_box [left, top], width: width, height: height do
draw_bounds_debug
text contact_content, inline_format: true, size: 8
end
end
|
#build_customer ⇒ Object
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 189
def build_customer
top = bounds.top - 4.cm
left = bounds.width / 2 + 1.1.cm
width = bounds.width / 2 - 1.1.cm
height = 4.5.cm
padding = 3.mm
bounding_box [left, top], width: width, height: height do
draw_bounds_debug
stroke do
fill_color LIGHT_GREY
fill_rounded_rectangle [cursor-bounds.height,cursor], bounds.width, bounds.height, 0
fill_color BLACK
end
bounding_box [bounds.left + padding, bounds.top - padding], height: bounds.height - padding, width: bounds.width - padding do
text customer_content
end
end
end
|
#build_expiry ⇒ Object
392
393
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 392
def build_expiry
end
|
409
410
411
412
413
414
415
416
417
418
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 409
def
top = bounds.bottom +
bounding_box [0, top], width: bounds.width, height: do
draw_bounds_debug
end
end
|
461
462
463
464
465
466
467
468
469
470
471
472
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 461
def
height =
top = bounds.bottom + height
width = bounds.width
text_box ,
:at => [bounds.left, top],
:height => height,
:width => width,
:overflow => :shrink_to_fit,
:size => 9
end
|
437
438
439
440
441
442
443
444
445
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 437
def
n = + ( - - ) / 2
move_down n
stroke do
horizontal_rule
line_width 1
end
end
|
424
425
426
427
428
429
430
431
432
433
434
435
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 424
def
top = bounds.top
height =
width = bounds.width
text_box ,
:at => [bounds.left, top],
:height => height,
:width => width,
:overflow => :shrink_to_fit,
:size => 9
end
|
78
79
80
81
82
83
84
85
86
87
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 78
def
bounding_box [0, bounds.top], width: bounds.width, height: do
draw_bounds_debug
build_title
build_logo
build_contact
build_subject
build_customer
end
end
|
#build_logo ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 106
def build_logo
return if logo_path.nil?
height = logo_height
width = logo_width
bounding_box [bounds.left, bounds.top], width: width, height: height do
draw_bounds_debug
image logo_path, fit: [width, height]
end
end
|
#build_middle ⇒ Object
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 210
def build_middle
left = bounds.left
top = bounds.top -
width = bounds.width - left
height = middle_height
bounding_box [left, top], width: width, height: height do
build_table
build_total
build_payment_conditions
build_bank_informations
build_expiry
end
end
|
#build_page_numbers ⇒ Object
474
475
476
477
478
479
480
481
482
483
484
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 474
def build_page_numbers
height = 5.mm
top = bounds.bottom + height
width = bounds.width
bounding_box [0, top], height: height, width: bounds.width do
float do
number_pages "page <page>/<total>", align: :right, size: 9
end
end
end
|
#build_payment_conditions ⇒ Object
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 374
def build_payment_conditions
return if main_document.payment_term.blank?
top = bounds.top - products_table_height - 5.mm
height = 15.mm
width = 7.5.cm
txt = "<b>#{main_document.t(:payment_terms)}</b> : #{main_document.payment_term}"
text_box txt,
:at => [bounds.left, top],
:height => height,
:width => width,
:overflow => :shrink_to_fit,
:inline_format => true,
:size => 9
end
|
#build_subject ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 151
def build_subject
top = bounds.top - 7.5.cm
left = bounds.left
width = bounds.width / 2 - 1.1.cm
height = 15.mm
bounding_box [left, top], width: width, height: height do
draw_bounds_debug
if main_document.label.present?
text "<b>#{main_document.t(:label)} : </b> #{main_document.label}", inline_format: true
end
if main_document.date.present?
move_down 3.mm
text "<b>#{main_document.t(:date)} : </b> #{date main_document.date}", inline_format: true
end
end
end
|
#build_table ⇒ Object
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 226
def build_table
left = bounds.left
top = bounds.top
width = bounds.width - left
height = products_table_height
bounding_box [left, top], width: width, height: height do
repeat :all do
float do
table [["","","","",""]],
:column_widths => [
first_column_width,
second_column_width,
third_column_width,
fourth_column_width,
last_column_width,
],
:cell_style => {height: height} \
do
row(0).style :text_color => BLACK
row(0).style :font_style => :bold
column(0).style :align => :left
column(1..4).style :align => :right
end end end end
bounding_box [left, top], width: width, height: height do
draw_bounds_debug
table_products = [[
main_document.t(:designation).mb_chars.upcase.to_s,
main_document.t(:quantity).mb_chars.upcase.to_s,
main_document.t(:unit).mb_chars.upcase.to_s,
main_document.t(:unit_price).mb_chars.upcase.to_s,
main_document.t(:line_total).mb_chars.upcase.to_s,
]]
main_document.lines.each do |line|
table_products.push [
line.label,
number(line.quantity).gsub(",00","").gsub(".00",""),
line.unit,
bm_currency(line.unit_price),
bm_currency(line.total),
]
end
table table_products,
:column_widths => [
first_column_width,
second_column_width,
third_column_width,
fourth_column_width,
last_column_width,
],
:header => true,
:cell_style => {border_width: 0} \
do
row(0).font_style = :bold
row(0).border_width = 1,
cells.style { |c| c.align = c.column == 0 ? :left : :right }
end end end
|
#build_title ⇒ Object
89
90
91
92
93
94
95
96
97
98
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 89
def build_title
top = bounds.top - 1.5.cm
left = bounds.left
width = bounds.width
height = 1.cm
bounding_box [left, top], width: width, height: height do
draw_bounds_debug
text "<b>#{main_document.t} n° #{main_document.tracking_id}</b>", inline_format: true, size: 20, align: :center
end
end
|
#build_total ⇒ Object
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 295
def build_total
left = bounds.left
top = bounds.top - products_table_height - 5.mm
width = bounds.width - left
height = middle_height - products_table_height
bounding_box [left, top], width: width, height: height do
draw_bounds_debug
table_totals = [[]]
if has_discount
table_totals.push [
main_document.t(:commercial_discount).mb_chars.upcase.to_s,
bm_currency(-main_document.commercial_discount),
]
end
table_totals.push [
main_document.t(:total_excluding_taxes).mb_chars.upcase.to_s,
bm_currency(main_document.total_excluding_taxes),
]
vat_rate = number(main_document.vat_rate)
table_totals.push [
"#{main_document.t(:vat).mb_chars.upcase.to_s} #{percentage vat_rate}",
bm_currency(main_document.vat_amount),
]
if has_advance
table_totals.push [
main_document.t(:advance).mb_chars.upcase.to_s,
bm_currency(main_document.advance),
]
table_totals.push [
main_document.t(:total_including_taxes).mb_chars.upcase.to_s,
bm_currency(main_document.balance),
]
else
table_totals.push [
main_document.t(:total_including_taxes).mb_chars.upcase.to_s,
bm_currency(main_document.total_including_taxes),
]
end
table table_totals,
:column_widths => [fourth_column_width, last_column_width],
:cell_style => {border_width: [0, 1, 0 ,0]},
:position => :right do
row(-1).style :font_style => :bold
column(0).padding_right = 0.2.cm
row(-1).borders = [:top, :right]
row(-1).border_width = 1
cells.style do |c|
c.align = :right
end
end
stroke do
rectangle [(bounds.right - fourth_column_width - last_column_width), bounds.top], (fourth_column_width + last_column_width), (bounds.top-cursor)
end
end
end
|
118
119
120
121
122
123
124
125
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 118
def contact_address_line
[
@id_card.address1,
@id_card.address2,
@id_card.zip,
@id_card.city,
].select(&:present?).join(", ")
end
|
#contact_content ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 127
def contact_content
content = []
content << "<b>#{@id_card.entity_name}</b>" if @id_card.entity_name.present?
content << "<b>#{contact_address_line}</b>" if contact_address_line.present?
content << " "
content << "<b>#{main_document.t(:your_contact)} : #{@id_card.contact_full_name}</b>" if @id_card.contact_full_name.present?
content << "<b>#{main_document.t(:contact_phone)} : </b> #{@id_card.contact_phone}" if @id_card.contact_phone.present?
content << "<b>#{main_document.t(:contact_fax)} : </b> #{@id_card.contact_fax}" if @id_card.contact_fax.present?
content << "<b>#{main_document.t(:contact_email)} : </b> #{@id_card.contact_email}" if @id_card.contact_email.present?
content.join("\n")
end
|
#customer_content ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 171
def customer_content
return if main_document.customer.nil?
content = []
content << main_document.customer.name
content << main_document.customer.address.street
content << main_document.customer.address.street_bis
content << "#{main_document.customer.address.zip} #{main_document.customer.address.city}"
content << main_document.customer.address.country
if main_document.customer.try(:european_union_vat_number).present?
content << main_document.customer.t(:european_union_vat_number)
content << main_document.customer.european_union_vat_number
end
content.select(&:present?).join("\n")
end
|
#draw_bounds_debug ⇒ Object
486
487
488
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 486
def draw_bounds_debug
transparent(0.5) { stroke_bounds } if DEBUG
end
|
#first_column_width ⇒ Object
47
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 47
def first_column_width; 7.6.cm; end
|
447
448
449
450
451
452
453
454
455
456
457
458
459
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 447
def
infos_text = []
infos_text << @id_card.entity_name if @id_card.entity_name.present?
infos_text << "#{main_document.t(:info_phone)} : #{@id_card.contact_phone}" if @id_card.contact_phone.present?
infos_text << "#{main_document.t(:info_fax)} : #{@id_card.contact_fax}" if @id_card.contact_fax.present?
infos_text << "#{@id_card.contact_email}" if @id_card.contact_email.present?
infos_text << "#{@id_card.legal_form.to_s}" if @id_card.legal_form.present?
infos_text << "#{main_document.t(:capital)} : #{bm_currency @id_card.capital}" if @id_card.capital.present?
infos_text << "#{main_document.t(:registration)} : #{@id_card.registration_city} #{@id_card.registration_number}" if @id_card.registration_number.present?
infos_text << "#{main_document.t(:siret)} : #{@id_card.siret}" if @id_card.siret.present?
infos_text << "#{main_document.t(:intracommunity_vat)} : #{@id_card.}" if @id_card..present?
infos_text = infos_text.join(" - ")
end
|
42
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 42
def ; 15.mm; end
|
40
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 40
def ; 40.mm; end
|
420
421
422
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 420
def
@id_card.custom_info_1.to_s
end
|
41
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 41
def ; 15.mm; end
|
#fourth_column_width ⇒ Object
50
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 50
def fourth_column_width; 2.9.cm; end
|
#has_advance ⇒ Object
19
20
21
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 19
def has_advance
main_document.try(:advance) && main_document.advance != 0.0
end
|
#has_discount ⇒ Object
23
24
25
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 23
def has_discount
main_document.try(:commercial_discount) && main_document.commercial_discount != 0.0
end
|
36
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 36
def ; 90.mm; end
|
#last_column_width ⇒ Object
51
52
53
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 51
def last_column_width
bounds.width - first_column_width - second_column_width - third_column_width - fourth_column_width
end
|
#logo_height ⇒ Object
37
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 37
def logo_height; 32.mm; end
|
#logo_path ⇒ Object
100
101
102
103
104
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 100
def logo_path
main_document.id_card.logo.path
rescue NoMethodError
nil
end
|
#logo_width ⇒ Object
38
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 38
def logo_width; 50.mm; end
|
#middle_height ⇒ Object
44
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 44
def middle_height; 14.cm; end
|
#products_table_height ⇒ Object
45
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 45
def products_table_height; 90.mm; end
|
#second_column_width ⇒ Object
48
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 48
def second_column_width; 2.4.cm; end
|
#setup ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 65
def setup
font_root = ::Dorsale::Engine.root.join("app/assets/fonts")
font_families.update(
"BryantPro" => {
normal: "#{font_root}/BryantPro-Regular.ttf",
bold: "#{font_root}/BryantPro-Bold.ttf",
}
)
font("BryantPro")
font_size 10
end
|
#third_column_width ⇒ Object
49
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 49
def third_column_width; 2.5.cm; end
|