Class: Dorsale::BillingMachine::InvoiceSingleVatPdf

Inherits:
Prawn::Document
  • Object
show all
Includes:
ActionView::Helpers::NumberHelper, Alexandrie::Prawn, AllHelpers
Defined in:
app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb

Direct Known Subclasses

InvoiceMultipleVatPdf, QuotationSingleVatPdf

Constant Summary collapse

DEBUG =
false
GREY =
"808080"
LIGHT_GREY =
"C0C0C0"
WHITE =
"FFFFFF"
BLACK =
"000000"
BLUE =
"005F9E"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UsersHelper

#avatar_img

Methods included from Flyboy::ApplicationHelper

#folder_color, #show_tasks_summary, #task_color, #tasks_for

Methods included from Alexandrie::AttachmentsHelper

#attachment_form_for, #attachments_for, #attachments_list_for

Methods included from TextHelper

#date, #euros, #hours, #info, #number, #percentage, #text2html

Methods included from RoutesHelper

#engine_polymorphic_path

Methods included from PaginationHelper

#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

Methods included from FiltersHelper

#dorsale_time_periods_for_select, #filter_buttons, #filter_reset_button, #filter_submit_button

Methods included from ContextHelper

#actions_for, #context_icon, #context_info, #context_title, #render_contextual

Methods included from CommentsHelper

#comment_form_for, #comments_for, #comments_list_for

Methods included from Dorsale::ButtonHelper

#complete_button, #copy_button, #create_button, #delete_button, #dorsale_button, #download_button, #lock_button, #read_button, #snooze_button, #unlock_button, #update_button

Methods included from Alexandrie::Prawn

#render_with_attachments

Constructor Details

#initialize(main_document) ⇒ InvoiceSingleVatPdf

Returns a new instance of InvoiceSingleVatPdf.



47
48
49
50
51
52
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 47

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_documentObject (readonly)

Returns the value of attribute main_document.



45
46
47
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 45

def main_document
  @main_document
end

Instance Method Details

#address_lineObject



125
126
127
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 125

def address_line
  [@id_card.address1,@id_card.address2, @id_card.zip, @id_card.city].select(&:present?).join(", ")
end

#buildObject



70
71
72
73
74
75
76
77
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 70

def build
  repeat :all do
    build_header
    build_footer
  end
  build_middle
  build_page_numbers
end

#build_bank_informationsObject



342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 342

def build_bank_informations
  top = bounds.top - 11.5.cm
  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 "#{I18n.t("pdfs.iban")} #{@id_card.iban}" if @id_card.iban.present?
      text "#{I18n.t("pdfs.bic_swift")} #{@id_card.bic_swift}"  if @id_card.bic_swift.present?
    end
  end
end

#build_commentsObject



310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 310

def build_comments
  return if @main_document.comments.blank?
  top = bounds.top - 13.cm
  height = 1.5.cm
  width  = 10.cm

  font_size 9 do
    text_box @main_document.comments,
      :at       => [bounds.left, top],
      :height   => height,
      :width    => width,
      :overflow => :shrink_to_fit
  end
end

#build_contactObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 129

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
    font_size 8 do
    text "<b>#{@id_card.entity_name}</b>", inline_format: true if @id_card.entity_name.present?
    text "<b>#{address_line} </b>", inline_format: true
    text " "
    text "<b>#{I18n.t("pdfs.your_contact")} : #{@id_card.contact_full_name}</b>", inline_format: true if @id_card.contact_full_name.present?
    text "<b>#{I18n.t("pdfs.contact_phone")}</b>  #{@id_card.contact_phone}", inline_format: true if @id_card.contact_phone.present?
    text "<b>#{I18n.t("pdfs.contact_fax")}</b> #{@id_card.contact_fax}",   inline_format: true if @id_card.contact_fax.present?
    text "<b>#{I18n.t("pdfs.contact_email")}</b> #{@id_card.contact_email}",   inline_format: true if @id_card.contact_email.present?
    end
  end
end

#build_customerObject



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 169

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
      if @main_document.customer.present?
        text @main_document.customer.name if @main_document.customer.name.present?
        text @main_document.customer.address.street if @main_document.customer.address.street.present?
        text @main_document.customer.address.street_bis if @main_document.customer.address.street_bis.present?
        text "#{@main_document.customer.address.zip} #{@main_document.customer.address.city}, #{@main_document.customer.address.country}" if @main_document.customer.address.zip.present? || @main_document.customer.address.city.present? || @main_document.customer.address.country.present?
        text "#{@main_document.customer.t :european_union_vat_number} :\n#{@main_document.customer.european_union_vat_number}" if @main_document.customer.try(:european_union_vat_number).present?
      end
    end

  end
end

#build_expiryObject



339
340
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 339

def build_expiry
end


356
357
358
359
360
361
362
363
364
365
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 356

def build_footer
  top = bounds.bottom + footer_height
  bounding_box [0, top], width: bounds.width, height: footer_height do

    builds_legals
    build_line
    builds_id_card_informations

  end
end

#build_headerObject



92
93
94
95
96
97
98
99
100
101
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 92

def build_header
  bounding_box [0, bounds.top], width: bounds.width, height: header_height do
    draw_bounds_debug
    build_title
    
    build_contact
    build_subject
    build_customer
  end
end

#build_lineObject



378
379
380
381
382
383
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 378

def build_line
  stroke do
    horizontal_rule
    line_width 1
  end
end

#build_logoObject



114
115
116
117
118
119
120
121
122
123
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 114

def 
  width = 3.2.cm
  height = logo_height
  bounding_box [bounds.left, bounds.top], width: width, height: height do
    draw_bounds_debug
    if @main_document.id_card..present?
      image @main_document.id_card..path, width: (bounds.width - 1.cm)
    end
  end
end

#build_middleObject



198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 198

def build_middle
  left   = bounds.left
  top    = bounds.top - header_height
  width  = bounds.width - left
  bounding_box [left, top], width: width, height: middle_height do
    build_table
    build_total
    build_payment_conditions
    build_bank_informations
    build_expiry
    build_comments
  end
end

#build_page_numbersObject



405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 405

def build_page_numbers
  top = bounds.bottom + footer_height - 1.8.cm
  bounding_box [0, top], height: footer_height, width: bounds.width do
    font_size 9 do
      float do
        options = {
        :align => :right,
        :start_count_at => 1
        }
        number_pages "page <page>/<total>", options
      end
    end
  end
end

#build_payment_conditionsObject



325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 325

def build_payment_conditions
  top = bounds.top - 10.3.cm
  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 I18n.t("pdfs.payment_terms"), style: :bold if @main_document.payment_term.present?
      text @main_document.payment_term.try(:label)
    end
  end
end

#build_subjectObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 149

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>#{I18n.t("pdfs.subject")}</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_tableObject



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
253
254
255
256
257
258
259
260
261
262
263
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 212

def build_table
  left   = bounds.left
  top    = bounds.top
  width  = bounds.width - left

  bounding_box [left, top], width: width, height: 9.5.cm 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 => 9.5.cm} 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: 8.8.cm do
    draw_bounds_debug
    repeat :all do
      build_line
    end
    table_products = [[I18n.t("pdfs.designation"),
      I18n.t("pdfs.quantity"),
      I18n.t("pdfs.unity"),
      I18n.t("pdfs.unit_price"),
      I18n.t("pdfs.line_total")]]


    @main_document.lines.each do |line|
      table_products.push [line.label,
          number(line.quantity).gsub(",00","").gsub(".00",""),
          line.unit,
          euros(line.unit_price),
          euros(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 do |c|
        c.align = c.column == 0 ? :left : :right
      end
    end
  end
end

#build_titleObject



103
104
105
106
107
108
109
110
111
112
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 103

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}#{@main_document.tracking_id}</b>", inline_format: true, size: 20, align: :center
  end
end

#build_totalObject



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
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 265

def build_total

  left   = bounds.left
  top    = bounds.top - 10.3.cm
  width  = bounds.width - left

  bounding_box [left, top], width: width, height: middle_height - 9.5.cm do
    draw_bounds_debug

    table_totals = [[]]

    if has_discount
      table_totals.push ["#{I18n.t("pdfs.commercial_discount")}", "\- #{euros(@main_document.commercial_discount)}"]
    end

    table_totals.push ["#{I18n.t("pdfs.total_excluding_taxes")}", euros(@main_document.total_excluding_taxes)]

    vat_rate = number(@main_document.vat_rate)
    table_totals.push ["#{I18n.t("pdfs.vat")}#{vat_rate} %", euros(@main_document.vat_amount)]

    if has_advance
      table_totals.push ["#{I18n.t("pdfs.advance")}", euros(@main_document.advance)]
      table_totals.push ["#{I18n.t("pdfs.total_including_taxes")}", euros(@main_document.balance)]
    else
      table_totals.push ["#{I18n.t("pdfs.total_including_taxes")}", euros(@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

#builds_id_card_informationsObject



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 385

def builds_id_card_informations
  top = bounds.top - 1.8.cm
  height = 1.1.cm
  width  = bounds.width
  tel = "#{I18n.t("pdfs.info_phone")} #{@id_card.contact_phone} - " if @id_card.contact_phone.present?
  fax = "#{I18n.t("pdfs.info_fax")} #{@id_card.contact_fax} -" if @id_card.contact_fax.present?
  email = "#{@id_card.contact_email}" if @id_card.contact_email.present?
  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?
  registration = I18n.t("pdfs.registration") + @id_card.registration_city.to_s + ' ' + @id_card.registration_number.to_s if @id_card.registration_number.present?
  siret = I18n.t("pdfs.siret") + @id_card.siret.to_s if @id_card.siret.present?
  tva = I18n.t("pdfs.vat") + @id_card.intracommunity_vat.to_s if @id_card.intracommunity_vat.present?
  font_size 9 do
    text_box "#{@id_card.entity_name} #{address_line}\n#{tel} #{fax} #{email}\n#{capital} #{registration} #{siret} #{tva}",
      :at       => [bounds.left, top],
      :height   => height,
      :width    => width,
      :overflow => :shrink_to_fit
  end
end

#builds_legalsObject



367
368
369
370
371
372
373
374
375
376
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 367

def builds_legals
  top = bounds.top
  height = 1.5.cm
  width  = bounds.width
  bounding_box [bounds.left, top], height: height, width: width do
    font_size 9 do
      text @id_card.custom_info_1, inline_format: true
    end
  end
end

#draw_bounds_debugObject



420
421
422
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 420

def draw_bounds_debug
  transparent(0.5) { stroke_bounds } if DEBUG
end

#first_column_widthObject



25
26
27
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 25

def first_column_width
  7.6.cm
end


62
63
64
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 62

def footer_height
  4.cm
end

#fourth_column_widthObject



37
38
39
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 37

def fourth_column_width
 2.9.cm
end

#has_advanceObject



17
18
19
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 17

def has_advance
  @main_document.try(:advance) && @main_document.advance != 0.0
end

#has_discountObject



21
22
23
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 21

def has_discount
  @main_document.try(:commercial_discount) && @main_document.commercial_discount != 0.0
end

#header_heightObject



54
55
56
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 54

def header_height
  9.cm
end

#last_column_widthObject



41
42
43
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 41

def last_column_width
  bounds.width - first_column_width - second_column_width - third_column_width - fourth_column_width
end

#logo_heightObject



66
67
68
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 66

def logo_height
  3.2.cm
end

#middle_heightObject



58
59
60
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 58

def middle_height
  15.cm
end

#second_column_widthObject



29
30
31
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 29

def second_column_width
  2.4.cm
end

#setupObject



79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 79

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_widthObject



33
34
35
# File 'app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb', line 33

def third_column_width
  second_column_width
end