Class: Dorsale::BillingMachine::InvoiceSingleVatPdf
- Inherits:
-
ApplicationPdf
- Object
- Prawn::Document
- ApplicationPdf
- Dorsale::BillingMachine::InvoiceSingleVatPdf
show all
- Includes:
- Alexandrie::Prawn::RenderWithAttachments
- Defined in:
- app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb
Constant Summary
collapse
- DEBUG =
false
- BLACK =
"000000"
- WHITE =
"FFFFFF"
- GREY =
"808080"
- LIGHT_GREY =
"C0C0C0"
Instance Attribute Summary collapse
Instance Method Summary
collapse
#open!
#bb, #btb, #draw_debug_bounds!, #draw_debug_bounds?, #get_image, #page_height, #page_width, #placeholder, #t, #tb
#avatar_img, #default_avatar_url
#expense_states_for_filters_select
#flyboy_reminder_type_units_for_select, #flyboy_reminder_types_for_select, #flyboy_status_for_filters_select, #flyboy_tasks_owners_for_filters_select, #flyboy_tasks_owners_for_select, #flyboy_tasks_tags_for_filters_select, #flyboy_tasks_tags_for_select, #show_tasks_summary, #task_term_values_for_select, #tasks_for
#customer_vault_activity_types_for_select, #customer_vault_event_actions_for_filter_select, #customer_vault_event_contact_types_for_filter_select, #customer_vault_link_form_path, #customer_vault_origins_for_select, #customer_vault_tag_list, #new_event_for, #person_address_blank?, #person_related_people_blank?, #person_social_blank?, #person_types_for_filter_select
#billing_machine_invoices_chart, #billing_machine_payment_status_for_filter_select, #billing_machine_quotation_states_for_filter_select, #billing_machine_quotation_states_for_select, #quotation_state_classes
#attachments_for
#comments_for, #new_comment_for, #truncate_comment_text, #truncate_comments_in_this_page?
#actions_for, #render_dorsale_page
Constructor Details
Returns a new instance of InvoiceSingleVatPdf.
13
14
15
16
17
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 13
def initialize(main_document)
super(page_size: "A4", margin: 1.cm)
@main_document = main_document
setup
end
|
Instance Attribute Details
#main_document ⇒ Object
Returns the value of attribute main_document.
11
12
13
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 11
def main_document
@main_document
end
|
Instance Method Details
#attachments ⇒ Object
19
20
21
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 19
def attachments
@main_document.try(:attachments) || []
end
|
#build ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 51
def build
repeat :all do
end
build_middle
build_page_numbers
end
|
111
112
113
114
115
116
117
118
119
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 111
def build_contact_infos
top = bounds.top - 4.cm
width = (bounds.width / 2) - 1.1.cm
height = contact_infos_height
bb top: top, width: width, height: height do
tb contact_infos_content.to_s, size: 9
end
end
|
#build_customer ⇒ Object
156
157
158
159
160
161
162
163
164
165
166
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 156
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
bb top: top, left: left, height: height, width: width, padding: padding, background: LIGHT_GREY do
tb customer_content.to_s
end
end
|
#build_document_infos ⇒ Object
331
332
333
334
335
336
337
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 331
def build_document_infos
top = bounds.top - products_table_height - 5.mm
height = middle_height - products_table_height - 5.mm
width = 10.cm
btb document_infos_content, top:, height:, width:
end
|
339
340
341
342
343
344
345
346
347
348
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 339
def
top = bounds.bottom +
height =
bb top: top, height: height do
end
end
|
370
371
372
373
374
375
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 370
def
height =
top = bounds.bottom + height +
btb , top:, height:, size: 9
end
|
359
360
361
362
363
364
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 359
def
top = bounds.top - - (( - - - ) / 2)
stroke do
horizontal_line bounds.left, bounds.right, at: top
end
end
|
355
356
357
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 355
def
btb , height: , size: 9
end
|
74
75
76
77
78
79
80
81
82
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 74
def
bb height: do
build_title
build_logo
build_contact_infos
build_subject
build_customer
end
end
|
#build_logo ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 98
def build_logo
height = logo_height
width = logo_width
bb width: width, height: height do
image logo_path, fit: [width, height] if logo_path
end
end
|
#build_middle ⇒ Object
168
169
170
171
172
173
174
175
176
177
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 168
def build_middle
top = bounds.top -
height = middle_height
bb top: top, height: height do
build_table
build_total
build_document_infos
end
end
|
#build_page_numbers ⇒ Object
377
378
379
380
381
382
383
384
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 377
def build_page_numbers
height =
top = bounds.bottom + height
bb top: top, height: height do
number_pages "page <page>/<total>", align: :right, size: 9
end
end
|
#build_subject ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 121
def build_subject
top = bounds.top - 7.5.cm
width = (bounds.width / 2) - 1.1.cm
height = 15.mm
bb top: top, width: width, height: height do
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 187
def build_table
height = products_table_height
bb height: products_table_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:} \
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
bb height: height do
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.zero? ? :left : :right }
end end end
|
#build_title ⇒ Object
84
85
86
87
88
89
90
91
92
93
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 84
def build_title
top = bounds.top - 1.5.cm
height = 1.cm
title = "<b>#{main_document.t} n° #{main_document.tracking_id}</b>"
bb top: top, height: height do
tb title, size: 20, align: :center
end
end
|
#build_total ⇒ Object
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 254
def build_total
top = bounds.top - products_table_height - 5.mm
height = middle_height - products_table_height - 5.mm
bb top: top, height: height do
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} #{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
|
#contact_infos_content ⇒ Object
107
108
109
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 107
def contact_infos_content
placeholder __method__
end
|
31
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 31
def contact_infos_height; 30.mm; end
|
#customer_content ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 138
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
|
#document_infos_content ⇒ Object
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 315
def document_infos_content
txt = []
if main_document.try(:payment_term).present?
txt << "<b>#{main_document.t :payment_term}</b> : #{main_document.payment_term}"
end
if main_document.try(:expires_at).present?
txt << "<b>#{main_document.t :expires_at}</b> : #{date main_document.expires_at}"
end
txt << main_document.
txt.select(&:present?).join("\n\n")
end
|
#first_column_width ⇒ Object
41
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 41
def first_column_width; 7.6.cm; end
|
366
367
368
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 366
def
placeholder __method__
end
|
35
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 35
def ; 15.mm; end
|
33
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 33
def ; 40.mm; end
|
36
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 36
def ; 5.mm; end
|
351
352
353
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 351
def
placeholder __method__
end
|
34
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 34
def ; 15.mm; end
|
#fourth_column_width ⇒ Object
44
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 44
def fourth_column_width; 2.9.cm; end
|
#has_advance ⇒ Object
179
180
181
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 179
def has_advance
main_document.try(:advance) && main_document.advance.to_d != BigDecimal("0.0")
end
|
#has_discount ⇒ Object
183
184
185
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 183
def has_discount
main_document.try(:commercial_discount) && main_document.commercial_discount.to_d != BigDecimal("0.0")
end
|
rubocop:disable Style/SingleLineMethods
28
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 28
def ; 90.mm; end
|
#last_column_width ⇒ Object
rubocop:enable Style/SingleLineMethods
47
48
49
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 47
def last_column_width
bounds.width - first_column_width - second_column_width - third_column_width - fourth_column_width
end
|
#logo_height ⇒ Object
29
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 29
def logo_height; 32.mm; end
|
#logo_path ⇒ Object
95
96
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 95
def logo_path
end
|
#logo_width ⇒ Object
30
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 30
def logo_width; 50.mm; end
|
#middle_height ⇒ Object
38
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 38
def middle_height; 14.cm; end
|
#products_table_height ⇒ Object
39
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 39
def products_table_height; 90.mm; end
|
#second_column_width ⇒ Object
42
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 42
def second_column_width; 2.4.cm; end
|
#setup ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 61
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
43
|
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 43
def third_column_width; 2.5.cm; end
|