dorsale 3.8.1 → 3.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +5 -1
  4. data/app/commands/dorsale/flyboy/task_commands.rb +1 -1
  5. data/app/controllers/concerns/dorsale/flyboy/tasks_summary_concern.rb +0 -1
  6. data/app/controllers/dorsale/alexandrie/attachments_controller.rb +1 -2
  7. data/app/controllers/dorsale/application_controller.rb +0 -1
  8. data/app/controllers/dorsale/billing_machine/application_controller.rb +0 -2
  9. data/app/controllers/dorsale/billing_machine/invoices_controller.rb +9 -22
  10. data/app/controllers/dorsale/billing_machine/payment_terms_controller.rb +0 -1
  11. data/app/controllers/dorsale/billing_machine/quotations_controller.rb +1 -4
  12. data/app/controllers/dorsale/comments_controller.rb +3 -2
  13. data/app/controllers/dorsale/customer_vault/activity_types_controller.rb +0 -1
  14. data/app/controllers/dorsale/customer_vault/application_controller.rb +0 -1
  15. data/app/controllers/dorsale/customer_vault/links_controller.rb +22 -12
  16. data/app/controllers/dorsale/customer_vault/origins_controller.rb +0 -1
  17. data/app/controllers/dorsale/customer_vault/people_controller.rb +2 -3
  18. data/app/controllers/dorsale/expense_gun/categories_controller.rb +0 -1
  19. data/app/controllers/dorsale/expense_gun/expenses_controller.rb +0 -1
  20. data/app/controllers/dorsale/flyboy/task_comments_controller.rb +0 -1
  21. data/app/controllers/dorsale/flyboy/tasks_controller.rb +28 -21
  22. data/app/controllers/dorsale/users_controller.rb +0 -1
  23. data/app/filters/dorsale/billing_machine/small_data/filter_strategy_by_payment_status.rb +9 -5
  24. data/app/filters/dorsale/billing_machine/small_data/filter_strategy_by_state.rb +2 -2
  25. data/app/filters/dorsale/flyboy/small_data/filter_for_tasks.rb +1 -1
  26. data/app/helpers/dorsale/billing_machine/application_helper.rb +6 -6
  27. data/app/helpers/dorsale/context_helper.rb +1 -1
  28. data/app/helpers/dorsale/flyboy/application_helper.rb +4 -5
  29. data/app/mailers/dorsale/billing_machine/invoice_mailer.rb +0 -1
  30. data/app/mailers/dorsale/flyboy/task_mailer.rb +0 -1
  31. data/app/mailers/dorsale/user_mailer.rb +0 -1
  32. data/app/models/dorsale/address.rb +2 -2
  33. data/app/models/dorsale/alexandrie/attachment_type.rb +0 -1
  34. data/app/models/dorsale/billing_machine.rb +1 -2
  35. data/app/models/dorsale/billing_machine/invoice.rb +19 -30
  36. data/app/models/dorsale/billing_machine/invoice_line.rb +2 -2
  37. data/app/models/dorsale/billing_machine/quotation.rb +11 -17
  38. data/app/models/dorsale/billing_machine/quotation_line.rb +2 -3
  39. data/app/models/dorsale/comment.rb +1 -1
  40. data/app/models/dorsale/customer_vault/corporation.rb +11 -10
  41. data/app/models/dorsale/customer_vault/event.rb +2 -2
  42. data/app/models/dorsale/customer_vault/individual.rb +4 -2
  43. data/app/models/dorsale/customer_vault/person.rb +14 -4
  44. data/app/models/dorsale/customer_vault/person_data.rb +1 -2
  45. data/app/models/dorsale/expense_gun/expense.rb +2 -5
  46. data/app/models/dorsale/expense_gun/expense_line.rb +2 -2
  47. data/app/models/dorsale/flyboy/task.rb +17 -18
  48. data/app/models/dorsale/flyboy/task_comment.rb +1 -1
  49. data/app/models/dorsale/users/active.rb +1 -1
  50. data/app/models/dorsale/users/avatar.rb +2 -1
  51. data/app/models/dorsale/users/password_generation.rb +0 -1
  52. data/app/pdfs/concerns/dorsale/alexandrie/prawn/render_with_attachments.rb +1 -1
  53. data/app/pdfs/dorsale/application_pdf.rb +7 -0
  54. data/app/pdfs/dorsale/billing_machine/invoice_multiple_vat_pdf.rb +52 -47
  55. data/app/pdfs/dorsale/billing_machine/invoice_single_vat_pdf.rb +94 -205
  56. data/app/pdfs/dorsale/prawn_helpers.rb +107 -0
  57. data/app/policies/dorsale/application_policy.rb +2 -4
  58. data/app/policies/dorsale/expense_gun/expense_policy_helper.rb +0 -1
  59. data/app/policies/dorsale/flyboy/task_policy_helper.rb +3 -3
  60. data/app/policies/dorsale/policy_checker.rb +11 -18
  61. data/app/services/dorsale/billing_machine/invoice/copy.rb +2 -2
  62. data/app/services/dorsale/billing_machine/pdf_file_generator.rb +7 -2
  63. data/app/services/dorsale/billing_machine/quotation/copy.rb +1 -1
  64. data/app/services/dorsale/billing_machine/quotation/to_invoice.rb +10 -7
  65. data/app/services/dorsale/flyboy/task/snoozer.rb +1 -1
  66. data/app/views/dorsale/billing_machine/invoices/_details.html.slim +1 -2
  67. data/app/views/dorsale/billing_machine/invoices/_form.html.slim +4 -11
  68. data/app/views/dorsale/billing_machine/invoices/index.xlsx.ruby +1 -1
  69. data/app/views/dorsale/flyboy/tasks/index.xlsx.ruby +1 -1
  70. data/config/locales/alexandrie.en.yml +0 -4
  71. data/config/locales/alexandrie.fr.yml +0 -4
  72. data/config/locales/billing_machine.en.yml +0 -41
  73. data/config/locales/billing_machine.fr.yml +0 -41
  74. data/config/routes.rb +0 -1
  75. data/db/migrate/20161119064536_delete_id_cards.rb +9 -0
  76. data/features/billing_machine_invoices.feature +0 -1
  77. data/features/billing_machine_multiple_vat.feature +0 -1
  78. data/features/billing_machine_quotations.feature +0 -1
  79. data/features/step_definitions/billing_machine_invoices_steps.rb +73 -79
  80. data/features/step_definitions/billing_machine_multiple_vat.rb +5 -6
  81. data/features/step_definitions/billing_machine_payment_terms_steps.rb +2 -2
  82. data/features/step_definitions/billing_machine_quotations_steps.rb +45 -80
  83. data/features/step_definitions/common_steps.rb +0 -4
  84. data/features/step_definitions/customer_vault_activity_types_steps.rb +1 -1
  85. data/features/step_definitions/customer_vault_corporations_steps.rb +27 -23
  86. data/features/step_definitions/customer_vault_individuals_steps.rb +8 -9
  87. data/features/step_definitions/customer_vault_invoices_steps.rb +1 -1
  88. data/features/step_definitions/customer_vault_links_steps.rb +6 -6
  89. data/features/step_definitions/customer_vault_origins_steps.rb +1 -1
  90. data/features/step_definitions/customer_vault_people_steps.rb +2 -1
  91. data/features/step_definitions/expense_gun_categories_steps.rb +2 -2
  92. data/features/step_definitions/expense_gun_expenses_steps.rb +6 -6
  93. data/features/step_definitions/flyboy_tasks_steps.rb +4 -7
  94. data/features/step_definitions/tasks_summary_steps.rb +3 -3
  95. data/features/support/env.rb +3 -2
  96. data/lib/dorsale/engine.rb +8 -8
  97. data/lib/dorsale/file_loader.rb +1 -1
  98. data/lib/dorsale/simple_form.rb +3 -3
  99. data/lib/dorsale/simple_form_bootstrap.rb +46 -46
  100. data/lib/dorsale/version.rb +1 -1
  101. data/spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb +3 -3
  102. data/spec/controllers/dorsale/billing_machine/invoices_controller_spec.rb +0 -1
  103. data/spec/controllers/dorsale/comments_controller_spec.rb +1 -1
  104. data/spec/controllers/dorsale/customer_vault/events_controller_spec.rb +9 -9
  105. data/spec/controllers/dorsale/customer_vault/people_controller_spec.rb +15 -19
  106. data/spec/controllers/dorsale/flyboy/task_comments_controller_spec.rb +1 -2
  107. data/spec/controllers/dorsale/flyboy/tasks_controller_spec.rb +43 -19
  108. data/spec/factories/alexandrie_attachment_types.rb +1 -1
  109. data/spec/factories/alexandrie_attachments.rb +1 -1
  110. data/spec/factories/billing_machine_invoice_lines.rb +1 -1
  111. data/spec/factories/billing_machine_invoices.rb +1 -2
  112. data/spec/factories/billing_machine_payment_terms.rb +1 -1
  113. data/spec/factories/billing_machine_quotation_lines.rb +1 -2
  114. data/spec/factories/billing_machine_quotations.rb +1 -2
  115. data/spec/factories/customer_vault_activity_types.rb +1 -1
  116. data/spec/factories/customer_vault_corporations.rb +1 -1
  117. data/spec/factories/customer_vault_event.rb +1 -1
  118. data/spec/factories/customer_vault_individuals.rb +2 -2
  119. data/spec/factories/customer_vault_links.rb +1 -1
  120. data/spec/factories/customer_vault_origins.rb +1 -1
  121. data/spec/factories/dorsale_addresses.rb +1 -1
  122. data/spec/factories/dorsale_comments.rb +1 -1
  123. data/spec/factories/expense_gun_categories.rb +2 -2
  124. data/spec/factories/expense_gun_expense_lines.rb +8 -8
  125. data/spec/factories/expense_gun_expenses.rb +2 -3
  126. data/spec/factories/flyboy_task_comments.rb +1 -1
  127. data/spec/factories/flyboy_tasks.rb +1 -1
  128. data/spec/mailers/user_mailer.rb +5 -6
  129. data/spec/models/dorsale/address_spec.rb +26 -26
  130. data/spec/models/dorsale/billing_machine/invoice_line_spec.rb +6 -6
  131. data/spec/models/dorsale/billing_machine/invoice_spec.rb +37 -23
  132. data/spec/models/dorsale/billing_machine/quotation_line_spec.rb +9 -10
  133. data/spec/models/dorsale/billing_machine/quotation_spec.rb +26 -28
  134. data/spec/models/dorsale/billing_machine_spec.rb +0 -1
  135. data/spec/models/dorsale/comment_spec.rb +0 -1
  136. data/spec/models/dorsale/customer_vault/corporation_spec.rb +20 -20
  137. data/spec/models/dorsale/customer_vault/event_spec.rb +1 -1
  138. data/spec/models/dorsale/customer_vault/individual_spec.rb +0 -2
  139. data/spec/models/dorsale/customer_vault/link_spec.rb +0 -1
  140. data/spec/models/dorsale/customer_vault/person_spec.rb +7 -6
  141. data/spec/models/dorsale/expense_gun/category_spec.rb +2 -2
  142. data/spec/models/dorsale/expense_gun/expense_line_spec.rb +14 -14
  143. data/spec/models/dorsale/expense_gun/expense_spec.rb +23 -13
  144. data/spec/models/dorsale/flyboy/task_comment_spec.rb +5 -6
  145. data/spec/models/dorsale/flyboy/task_spec.rb +66 -42
  146. data/spec/models/dorsale/users_spec.rb +3 -5
  147. data/spec/pdfs/dorsale/billing_machine/invoice_multiple_vat_pdf_spec.rb +6 -11
  148. data/spec/pdfs/dorsale/billing_machine/invoice_single_vat_pdf_spec.rb +7 -11
  149. data/spec/pdfs/dorsale/billing_machine/quotation_multiple_vat_pdf_spec.rb +6 -11
  150. data/spec/pdfs/dorsale/billing_machine/quotation_single_vat_pdf_spec.rb +7 -14
  151. data/spec/rails_helper.rb +1 -1
  152. data/spec/routing/dorsale/billing_machine/invoices_routing_spec.rb +0 -1
  153. data/spec/routing/dorsale/billing_machine/quotations_routing_spec.rb +0 -1
  154. data/spec/routing/dorsale/comments_routing_spec.rb +0 -2
  155. data/spec/routing/dorsale/customer_vault/people_routing_spec.rb +0 -1
  156. data/spec/routing/dorsale/expense_gun/expenses_routing_spec.rb +0 -1
  157. data/spec/routing/dorsale/flyboy/task_comments_routing_spec.rb +0 -1
  158. data/spec/routing/dorsale/users_routing_spec.rb +1 -1
  159. data/spec/services/dorsale/billing_machine/quotation/copy_spec.rb +2 -2
  160. data/spec/services/dorsale/expense_gun/expense/copy_spec.rb +13 -17
  161. data/spec/services/dorsale/flyboy/task/copy_spec.rb +1 -2
  162. data/spec/services/dorsale/flyboy/task/snoozer_spec.rb +3 -3
  163. data/spec/spec_helper.rb +1 -0
  164. metadata +5 -43
  165. data/app/controllers/dorsale/billing_machine/id_cards_controller.rb +0 -106
  166. data/app/models/dorsale/billing_machine/id_card.rb +0 -14
  167. data/app/policies/dorsale/billing_machine/id_card_policy_helper.rb +0 -7
  168. data/app/views/dorsale/billing_machine/id_cards/_form.html.slim +0 -42
  169. data/app/views/dorsale/billing_machine/id_cards/_index_actions.html.slim +0 -2
  170. data/app/views/dorsale/billing_machine/id_cards/_list.html.slim +0 -27
  171. data/app/views/dorsale/billing_machine/id_cards/edit.html.slim +0 -1
  172. data/app/views/dorsale/billing_machine/id_cards/index.html.slim +0 -11
  173. data/app/views/dorsale/billing_machine/id_cards/new.html.slim +0 -1
  174. data/features/billing_machine_id_cards.feature +0 -19
  175. data/features/step_definitions/billing_machine_id_cards_steps.rb +0 -53
  176. data/features/support/ajax.rb +0 -20
  177. data/features/support/database_cleaner.rb +0 -12
  178. data/features/support/factory_girl.rb +0 -1
  179. data/features/support/fix_referrer.rb +0 -9
  180. data/features/support/message_delivery.rb +0 -1
  181. data/features/support/poltergeist.rb +0 -22
  182. data/features/support/rails.rb +0 -1
  183. data/features/support/rspec.rb +0 -6
  184. data/features/support/screenshots.rb +0 -5
  185. data/features/support/sign_in.rb +0 -17
  186. data/features/support/simplecov.rb +0 -1
  187. data/features/support/turbolinks.rb +0 -30
  188. data/spec/factories/billing_machine_id_cards.rb +0 -26
  189. data/spec/models/dorsale/billing_machine/id_card_spec.rb +0 -12
@@ -19,8 +19,8 @@ class Dorsale::Flyboy::Task < ::Dorsale::ApplicationRecord
19
19
 
20
20
  def state
21
21
  return "done" if done
22
- return "onalert" if term && term <= Time.zone.now.to_date
23
- return "onwarning" if reminder_date && reminder_date <= Time.zone.now.to_date
22
+ return "onalert" if term && term <= Date.current
23
+ return "onwarning" if reminder_date && reminder_date <= Date.current
24
24
  return "ontime"
25
25
  end
26
26
 
@@ -29,40 +29,40 @@ class Dorsale::Flyboy::Task < ::Dorsale::ApplicationRecord
29
29
 
30
30
  scope :ontime, -> {
31
31
  undone
32
- .where("#{table_name}.term IS NULL OR #{table_name}.term > ?", Time.zone.now.to_date)
33
- .where("#{table_name}.reminder_date IS NULL OR #{table_name}.reminder_date > ?", Time.zone.now.to_date)
32
+ .where("#{table_name}.term IS NULL OR #{table_name}.term > ?", Date.current)
33
+ .where("#{table_name}.reminder_date IS NULL OR #{table_name}.reminder_date > ?", Date.current)
34
34
  }
35
35
 
36
36
  scope :onwarning, -> {
37
37
  undone
38
- .where("#{table_name}.reminder_date <= ?", Time.zone.now.to_date)
39
- .where("#{table_name}.term IS NULL OR #{table_name}.term > ?", Time.zone.now.to_date)
38
+ .where("#{table_name}.reminder_date <= ?", Date.current)
39
+ .where("#{table_name}.term IS NULL OR #{table_name}.term > ?", Date.current)
40
40
  }
41
41
 
42
42
  scope :onalert, -> {
43
43
  undone
44
- .where("#{table_name}.term <= ?", Time.zone.now.to_date)
44
+ .where("#{table_name}.term <= ?", Date.current)
45
45
  }
46
46
 
47
- scope :delayed, -> { where(done: false).where("#{table_name}.term < ?", Time.zone.now.to_date) }
48
- scope :today, -> { where(done: false).where("#{table_name}.term = ?", Time.zone.now.to_date) }
49
- scope :tomorrow, -> { where(done: false).where("#{table_name}.term = ?", Date.tomorrow) }
47
+ scope :delayed, -> { where(done: false).where("#{table_name}.term < ?", Date.current) }
48
+ scope :today, -> { where(done: false).where("#{table_name}.term = ?", Date.current) }
49
+ scope :tomorrow, -> { where(done: false).where("#{table_name}.term = ?", Date.tomorrow) }
50
50
 
51
51
  scope :this_week, -> {
52
52
  min = Date.tomorrow
53
- max = Time.zone.now.to_date.end_of_week
53
+ max = Date.current.end_of_week
54
54
  where(done: false).where("#{table_name}.term > ?", min).where("#{table_name}.term <= ?", max)
55
55
  }
56
56
 
57
57
  scope :next_week, -> {
58
- min = Time.zone.now.to_date.end_of_week
59
- max = Time.zone.now.to_date.next_week.end_of_week
58
+ min = Date.current.end_of_week
59
+ max = Date.current.next_week.end_of_week
60
60
  where(done: false).where("#{table_name}.term > ?", min).where("#{table_name}.term <= ?", max)
61
61
  }
62
62
 
63
63
  scope :next_next_week, -> {
64
- min = Time.zone.now.to_date.next_week.end_of_week
65
- max = Time.zone.now.to_date.next_week.next_week.end_of_week
64
+ min = Date.current.next_week.end_of_week
65
+ max = Date.current.next_week.next_week.end_of_week
66
66
  where(done: false).where("#{table_name}.term > ?", min).where("#{table_name}.term <= ?", max)
67
67
  }
68
68
 
@@ -77,7 +77,7 @@ class Dorsale::Flyboy::Task < ::Dorsale::ApplicationRecord
77
77
  def assign_default_values
78
78
  assign_default :progress, 0
79
79
  assign_default :done, false
80
- assign_default :term, Time.zone.now.to_date.end_of_week
80
+ assign_default :term, Date.current.end_of_week
81
81
  end
82
82
 
83
83
  def snoozer
@@ -112,7 +112,7 @@ class Dorsale::Flyboy::Task < ::Dorsale::ApplicationRecord
112
112
  end
113
113
 
114
114
  if reminder_type == "duration" && term && reminder_duration && reminder_unit.in?(REMINDER_UNITS)
115
- self.reminder_date = term - eval("#{reminder_duration}.#{reminder_unit}")
115
+ self.reminder_date = term - reminder_duration.public_send(reminder_unit)
116
116
  end
117
117
 
118
118
  true
@@ -123,5 +123,4 @@ class Dorsale::Flyboy::Task < ::Dorsale::ApplicationRecord
123
123
  errors.add(:reminder_date, :less_than, count: term)
124
124
  end
125
125
  end
126
-
127
126
  end
@@ -22,7 +22,7 @@ class Dorsale::Flyboy::TaskComment < ::Dorsale::ApplicationRecord
22
22
  def update_task_progress
23
23
  task.update!(
24
24
  :progress => progress,
25
- :done => progress.equal?(100)
25
+ :done => progress.equal?(100),
26
26
  )
27
27
  end
28
28
  end
@@ -11,7 +11,7 @@ module Dorsale::Users::Active
11
11
  end
12
12
 
13
13
  def active_for_authentication?
14
- super && self.is_active?
14
+ super && is_active?
15
15
  end
16
16
 
17
17
  def inactive_message
@@ -12,7 +12,8 @@ module Dorsale::Users::Avatar
12
12
  end
13
13
 
14
14
  def gravatar_url
15
- "https://www.gravatar.com/avatar/" + Digest::MD5.hexdigest(email.to_s) + "?default=mm&size=200"
15
+ gravatar_id = Digest::MD5.hexdigest(email.to_s)
16
+ "https://www.gravatar.com/avatar/#{gravatar_id}?default=mm&size=200"
16
17
  end
17
18
  end
18
19
  end
@@ -11,7 +11,6 @@ module Dorsale::Users::PasswordGeneration
11
11
  def send_welcome_email
12
12
  Dorsale::UserMailer.new_account(self, password).deliver_later
13
13
  end
14
-
15
14
  end
16
15
  end
17
16
  end
@@ -1,6 +1,6 @@
1
1
  module Dorsale::Alexandrie::Prawn::RenderWithAttachments
2
2
  def render_with_attachments
3
- final_pdf = ::CombinePDF.parse(self.render)
3
+ final_pdf = ::CombinePDF.parse(render)
4
4
 
5
5
  attachments.each do |attachment|
6
6
  next unless File.extname(attachment.file.path) == ".pdf"
@@ -0,0 +1,7 @@
1
+ require "prawn"
2
+ require "prawn/table"
3
+ require "prawn/measurement_extensions"
4
+
5
+ class Dorsale::ApplicationPdf < Prawn::Document
6
+ include ::Dorsale::PrawnHelpers
7
+ end
@@ -1,36 +1,37 @@
1
1
  class Dorsale::BillingMachine::InvoiceMultipleVatPdf < ::Dorsale::BillingMachine::InvoiceSingleVatPdf
2
+ # rubocop:disable Style/SingleLineMethods, Layout/EmptyLineBetweenDefs
2
3
  def first_column_width; 64.mm; end
3
4
  def second_column_width; 22.mm; end
4
5
  def third_column_width; 20.mm; end
5
6
  def fourth_column_width; 20.mm; end
6
7
  def fifth_column_width; 29.mm; end
8
+ # rubocop:enable Style/SingleLineMethods, Layout/EmptyLineBetweenDefs
9
+
7
10
  def last_column_width
8
11
  bounds.width - first_column_width - second_column_width - third_column_width - fourth_column_width - fifth_column_width
9
12
  end
10
13
 
11
14
  def build_table
12
- left = bounds.left
13
- top = bounds.top
14
- width = bounds.width - left
15
+ height = products_table_height
15
16
 
16
- bounding_box [left, top], width: width, height: products_table_height do
17
+ # Empty table to draw lines
18
+ bb height: products_table_height do
17
19
  repeat :all do
18
20
  float do
19
- table [["","","","","",""]],
20
- :column_widths => [first_column_width, second_column_width, third_column_width, fourth_column_width, fifth_column_width, last_column_width],
21
- :cell_style => {height: products_table_height} do
22
- row(0).style :text_color => BLACK
23
- row(0).style :font_style => :bold
24
- column(0).style :align => :left
25
- column(1..4).style :align => :right
26
- end
27
- end
28
- end
29
- end
30
-
31
- bounding_box [left, top], width: width, height: products_table_height do
32
- draw_bounds_debug
33
-
21
+ table [["", "", "", "", "", ""]],
22
+ :column_widths => [first_column_width, second_column_width, third_column_width, fourth_column_width, fifth_column_width, last_column_width],
23
+ :cell_style => {height: products_table_height} do
24
+ row(0).style :text_color => BLACK
25
+ row(0).style :font_style => :bold
26
+ column(0).style :align => :left
27
+ column(1..4).style :align => :right
28
+ end # table
29
+ end # float
30
+ end # repeat
31
+ end # bb
32
+
33
+ # Products table
34
+ bb height: height do
34
35
  table_products = [[
35
36
  main_document.t(:designation).mb_chars.upcase.to_s,
36
37
  main_document.t(:quantity).mb_chars.upcase.to_s,
@@ -40,38 +41,42 @@ class Dorsale::BillingMachine::InvoiceMultipleVatPdf < ::Dorsale::BillingMachine
40
41
  main_document.t(:line_total).mb_chars.upcase.to_s,
41
42
  ]]
42
43
 
43
-
44
44
  main_document.lines.each do |line|
45
- table_products.push [line.label,
46
- number(line.quantity).gsub(",00","").gsub(".00",""),
47
- line.unit,
48
- percentage(line.vat_rate),
49
- bm_currency(line.unit_price),
50
- bm_currency(line.total),]
45
+ table_products.push [
46
+ line.label,
47
+ number(line.quantity).gsub(",00", "").gsub(".00", ""),
48
+ line.unit,
49
+ percentage(line.vat_rate),
50
+ bm_currency(line.unit_price),
51
+ bm_currency(line.total),
52
+ ]
51
53
  end
52
54
 
53
- table table_products,
54
- :column_widths => [first_column_width, second_column_width, third_column_width, fourth_column_width, fifth_column_width, last_column_width],
55
- :header => true,
56
- :cell_style => {border_width: 0} do
55
+ table table_products,
56
+ :column_widths => [
57
+ first_column_width,
58
+ second_column_width,
59
+ third_column_width,
60
+ fourth_column_width,
61
+ fifth_column_width,
62
+ last_column_width,
63
+ ],
64
+ :header => true,
65
+ :cell_style => {border_width: 0} \
66
+ do
57
67
  row(0).font_style = :bold
58
- row(0).border_width = 1,
59
- cells.style do |c|
60
- c.align = c.column == 0 ? :left : :right
61
- end
62
- end
63
- end
64
- end
68
+ row(0).border_width =
69
+ 1,
70
+ cells.style { |c| c.align = c.column.zero? ? :left : :right }
71
+ end # table
72
+ end # bb
73
+ end # build_table
65
74
 
66
75
  def build_total
67
- left = bounds.left
68
76
  top = bounds.top - products_table_height - 5.mm
69
- width = bounds.width - left
70
- height = middle_height - products_table_height
71
-
72
- bounding_box [left, top], width: width, height: height do
73
- draw_bounds_debug
77
+ height = middle_height - products_table_height - 5.mm
74
78
 
79
+ bb top: top, height: height do
75
80
  table_totals = [[]]
76
81
 
77
82
  if has_discount
@@ -109,10 +114,10 @@ class Dorsale::BillingMachine::InvoiceMultipleVatPdf < ::Dorsale::BillingMachine
109
114
  end
110
115
 
111
116
  table table_totals,
112
- :column_widths => [fifth_column_width , last_column_width],
113
- :cell_style => {border_width: [0, 1, 0 ,0]},
117
+ :column_widths => [fifth_column_width, last_column_width],
118
+ :cell_style => {border_width: [0, 1, 0, 0]},
114
119
  :position => :right do
115
- row(-1).style :font_style => :bold
120
+ row(-1).style :font_style => :bold
116
121
  column(0).padding_right = 0.2.cm
117
122
  row(-1).borders = [:top, :right]
118
123
  row(-1).border_width = 1
@@ -120,10 +125,10 @@ class Dorsale::BillingMachine::InvoiceMultipleVatPdf < ::Dorsale::BillingMachine
120
125
  c.align = :right
121
126
  end
122
127
  end
128
+
123
129
  stroke do
124
130
  rectangle [(bounds.right - fifth_column_width - last_column_width), bounds.top], (fifth_column_width + last_column_width), (bounds.top-cursor)
125
131
  end
126
132
  end
127
133
  end
128
-
129
134
  end
@@ -1,9 +1,5 @@
1
- require "prawn/measurement_extensions"
2
-
3
- class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
1
+ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Dorsale::ApplicationPdf
4
2
  include Dorsale::Alexandrie::Prawn::RenderWithAttachments
5
- include Dorsale::AllHelpers
6
- include ActionView::Helpers::NumberHelper
7
3
 
8
4
  def attachments
9
5
  @main_document.try(:attachments) || []
@@ -11,40 +7,33 @@ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
11
7
 
12
8
  DEBUG = false
13
9
 
10
+ BLACK = "000000"
11
+ WHITE = "FFFFFF"
14
12
  GREY = "808080"
15
13
  LIGHT_GREY = "C0C0C0"
16
- WHITE = "FFFFFF"
17
- BLACK = "000000"
18
- BLUE = "005F9E"
19
14
 
20
15
  def bm_currency(n)
21
16
  currency(n, Dorsale::BillingMachine.default_currency)
22
17
  end
23
18
 
24
- def has_advance
25
- main_document.try(:advance) && main_document.advance != 0.0
26
- end
27
-
28
- def has_discount
29
- main_document.try(:commercial_discount) && main_document.commercial_discount != 0.0
30
- end
31
-
32
19
  attr_reader :main_document
33
20
 
34
21
  def initialize(main_document)
35
- super(page_size: 'A4', margin: 1.cm)
36
- setup
22
+ super(page_size: "A4", margin: 1.cm)
37
23
  @main_document = main_document
38
- @id_card = main_document.id_card
24
+ setup
39
25
  end
40
26
 
27
+ # rubocop:disable Style/SingleLineMethods, Layout/EmptyLineBetweenDefs
41
28
  def header_height; 90.mm; end
42
29
  def logo_height; 32.mm; end
43
30
  def logo_width; 50.mm; end
31
+ def contact_infos_height; 30.mm; end
44
32
 
45
- def footer_height; 40.mm; end
46
- def footer_top_height; 15.mm; end
47
- def footer_bottom_height; 15.mm; end
33
+ def footer_height; 40.mm; end
34
+ def footer_top_height; 15.mm; end
35
+ def footer_bottom_height; 15.mm; end
36
+ def footer_pagination_height; 5.mm; end
48
37
 
49
38
  def middle_height; 14.cm; end
50
39
  def products_table_height; 90.mm; end
@@ -53,6 +42,8 @@ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
53
42
  def second_column_width; 2.4.cm; end
54
43
  def third_column_width; 2.5.cm; end
55
44
  def fourth_column_width; 2.9.cm; end
45
+ # rubocop:enable Style/SingleLineMethods, Layout/EmptyLineBetweenDefs
46
+
56
47
  def last_column_width
57
48
  bounds.width - first_column_width - second_column_width - third_column_width - fourth_column_width
58
49
  end
@@ -69,11 +60,11 @@ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
69
60
 
70
61
  def setup
71
62
  font_root = ::Dorsale::Engine.root.join("app/assets/fonts")
72
- font_families.update(
63
+ font_families.update( # rubocop:disable Rails/SaveBang
73
64
  "BryantPro" => {
74
65
  normal: "#{font_root}/BryantPro-Regular.ttf",
75
66
  bold: "#{font_root}/BryantPro-Bold.ttf",
76
- }
67
+ },
77
68
  )
78
69
 
79
70
  font("BryantPro")
@@ -81,11 +72,10 @@ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
81
72
  end
82
73
 
83
74
  def build_header
84
- bounding_box [0, bounds.top], width: bounds.width, height: header_height do
85
- draw_bounds_debug
75
+ bb height: header_height do
86
76
  build_title
87
77
  build_logo
88
- build_contact
78
+ build_contact_infos
89
79
  build_subject
90
80
  build_customer
91
81
  end
@@ -93,75 +83,47 @@ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
93
83
 
94
84
  def build_title
95
85
  top = bounds.top - 1.5.cm
96
- left = bounds.left
97
- width = bounds.width
98
86
  height = 1.cm
99
- bounding_box [left, top], width: width, height: height do
100
- draw_bounds_debug
101
- text "<b>#{main_document.t} n° #{main_document.tracking_id}</b>", inline_format: true, size: 20, align: :center
87
+
88
+ title = "<b>#{main_document.t} n° #{main_document.tracking_id}</b>"
89
+
90
+ bb top: top, height: height do
91
+ tb title, size: 20, align: :center
102
92
  end
103
93
  end
104
94
 
105
95
  def logo_path
106
- main_document.id_card.logo.path
107
- rescue NoMethodError
108
- nil
109
96
  end
110
97
 
111
98
  def build_logo
112
- return if logo_path.nil?
113
-
114
99
  height = logo_height
115
100
  width = logo_width
116
101
 
117
- bounding_box [bounds.left, bounds.top], width: width, height: height do
118
- draw_bounds_debug
119
- image logo_path, fit: [width, height]
102
+ bb width: width, height: height do
103
+ image logo_path, fit: [width, height] if logo_path
120
104
  end
121
105
  end
122
106
 
123
- def contact_address_line
124
- [
125
- @id_card.address1,
126
- @id_card.address2,
127
- @id_card.zip,
128
- @id_card.city,
129
- ].select(&:present?).join(", ")
107
+ def contact_infos_content
108
+ placeholder __method__
130
109
  end
131
110
 
132
- def contact_content
133
- content = []
134
- content << "<b>#{@id_card.entity_name}</b>" if @id_card.entity_name.present?
135
- content << "<b>#{contact_address_line}</b>" if contact_address_line.present?
136
- content << " "
137
- content << "<b>#{main_document.t(:your_contact)} : #{@id_card.contact_full_name}</b>" if @id_card.contact_full_name.present?
138
- content << "<b>#{main_document.t(:contact_phone)} : </b> #{@id_card.contact_phone}" if @id_card.contact_phone.present?
139
- content << "<b>#{main_document.t(:contact_fax)} : </b> #{@id_card.contact_fax}" if @id_card.contact_fax.present?
140
- content << "<b>#{main_document.t(:contact_email)} : </b> #{@id_card.contact_email}" if @id_card.contact_email.present?
141
- content.join("\n")
142
- end
143
-
144
- def build_contact
111
+ def build_contact_infos
145
112
  top = bounds.top - 4.cm
146
- left = bounds.left
147
113
  width = bounds.width / 2 - 1.1.cm
148
- height = 2.5.cm
114
+ height = contact_infos_height
149
115
 
150
- bounding_box [left, top], width: width, height: height do
151
- draw_bounds_debug
152
- text contact_content, inline_format: true, size: 8
116
+ bb top: top, width: width, height: height do
117
+ tb contact_infos_content.to_s, size: 9
153
118
  end
154
119
  end
155
120
 
156
121
  def build_subject
157
122
  top = bounds.top - 7.5.cm
158
- left = bounds.left
159
123
  width = bounds.width / 2 - 1.1.cm
160
124
  height = 15.mm
161
125
 
162
- bounding_box [left, top], width: width, height: height do
163
- draw_bounds_debug
164
-
126
+ bb top: top, width: width, height: height do
165
127
  if main_document.label.present?
166
128
  text "<b>#{main_document.t(:label)} : </b> #{main_document.label}", inline_format: true
167
129
  end
@@ -184,7 +146,7 @@ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
184
146
  content << main_document.customer.address.country
185
147
 
186
148
  if main_document.customer.try(:european_union_vat_number).present?
187
- content << main_document.customer.t(:european_union_vat_number)
149
+ content << main_document.customer.t(:european_union_vat_number) + " : "
188
150
  content << main_document.customer.european_union_vat_number
189
151
  end
190
152
 
@@ -192,53 +154,44 @@ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
192
154
  end
193
155
 
194
156
  def build_customer
195
- top = bounds.top - 4.cm
196
- left = bounds.width / 2 + 1.1.cm
197
- width = bounds.width / 2 - 1.1.cm
198
- height = 4.5.cm
157
+ top = bounds.top - 4.cm
158
+ left = bounds.width / 2 + 1.1.cm
159
+ width = bounds.width / 2 - 1.1.cm
160
+ height = 4.5.cm
199
161
  padding = 3.mm
200
162
 
201
- bounding_box [left, top], width: width, height: height do
202
- draw_bounds_debug
203
- stroke do
204
- fill_color LIGHT_GREY
205
- fill_rounded_rectangle [cursor-bounds.height,cursor], bounds.width, bounds.height, 0
206
- fill_color BLACK
207
- end
208
-
209
- bounding_box [bounds.left + padding, bounds.top - padding], height: bounds.height - padding, width: bounds.width - padding do
210
- text customer_content
211
- end
163
+ bb top: top, left: left, height: height, width: width, padding: padding, background: LIGHT_GREY do
164
+ tb customer_content.to_s
212
165
  end
213
166
  end # def build_customer
214
167
 
215
168
  def build_middle
216
- left = bounds.left
217
169
  top = bounds.top - header_height
218
- width = bounds.width - left
219
170
  height = middle_height
220
171
 
221
- bounding_box [left, top], width: width, height: height do
172
+ bb top: top, height: height do
222
173
  build_table
223
174
  build_total
224
- build_payment_conditions
225
- build_bank_informations
226
- build_expiry
227
- build_comments
175
+ build_document_infos
228
176
  end
229
177
  end
230
178
 
179
+ def has_advance
180
+ main_document.try(:advance) && main_document.advance != 0.0
181
+ end
182
+
183
+ def has_discount
184
+ main_document.try(:commercial_discount) && main_document.commercial_discount != 0.0
185
+ end
186
+
231
187
  def build_table
232
- left = bounds.left
233
- top = bounds.top
234
- width = bounds.width - left
235
188
  height = products_table_height
236
189
 
237
190
  # Empty table to draw lines
238
- bounding_box [left, top], width: width, height: height do
191
+ bb height: products_table_height do
239
192
  repeat :all do
240
193
  float do
241
- table [["","","","",""]],
194
+ table [["", "", "", "", ""]],
242
195
  :column_widths => [
243
196
  first_column_width,
244
197
  second_column_width,
@@ -255,12 +208,10 @@ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
255
208
  end # table
256
209
  end # float
257
210
  end # repeat all
258
- end # bounding_box
259
-
260
- # products table
261
- bounding_box [left, top], width: width, height: height do
262
- draw_bounds_debug
211
+ end # bb
263
212
 
213
+ # Products table
214
+ bb height: height do
264
215
  table_products = [[
265
216
  main_document.t(:designation).mb_chars.upcase.to_s,
266
217
  main_document.t(:quantity).mb_chars.upcase.to_s,
@@ -272,7 +223,7 @@ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
272
223
  main_document.lines.each do |line|
273
224
  table_products.push [
274
225
  line.label,
275
- number(line.quantity).gsub(",00","").gsub(".00",""),
226
+ number(line.quantity).gsub(",00", "").gsub(".00", ""),
276
227
  line.unit,
277
228
  bm_currency(line.unit_price),
278
229
  bm_currency(line.total),
@@ -291,21 +242,18 @@ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
291
242
  :cell_style => {border_width: 0} \
292
243
  do
293
244
  row(0).font_style = :bold
294
- row(0).border_width = 1,
295
- cells.style { |c| c.align = c.column == 0 ? :left : :right }
245
+ row(0).border_width =
246
+ 1,
247
+ cells.style { |c| c.align = c.column.zero? ? :left : :right }
296
248
  end # table
297
- end # bounding_box
249
+ end # bb
298
250
  end # build_table
299
251
 
300
252
  def build_total
301
- left = bounds.left
302
253
  top = bounds.top - products_table_height - 5.mm
303
- width = bounds.width - left
304
- height = middle_height - products_table_height
305
-
306
- bounding_box [left, top], width: width, height: height do
307
- draw_bounds_debug
254
+ height = middle_height - products_table_height - 5.mm
308
255
 
256
+ bb top: top, height: height do
309
257
  table_totals = [[]]
310
258
 
311
259
  if has_discount
@@ -322,7 +270,7 @@ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
322
270
 
323
271
  vat_rate = number(main_document.vat_rate)
324
272
  table_totals.push [
325
- "#{main_document.t(:vat).mb_chars.upcase.to_s} #{percentage vat_rate}",
273
+ "#{main_document.t(:vat).mb_chars.upcase} #{percentage vat_rate}",
326
274
  bm_currency(main_document.vat_amount),
327
275
  ]
328
276
 
@@ -345,9 +293,9 @@ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
345
293
 
346
294
  table table_totals,
347
295
  :column_widths => [fourth_column_width, last_column_width],
348
- :cell_style => {border_width: [0, 1, 0 ,0]},
296
+ :cell_style => {border_width: [0, 1, 0, 0]},
349
297
  :position => :right do
350
- row(-1).style :font_style => :bold
298
+ row(-1).style :font_style => :bold
351
299
  column(0).padding_right = 0.2.cm
352
300
  row(-1).borders = [:top, :right]
353
301
  row(-1).border_width = 1
@@ -355,140 +303,81 @@ class Dorsale::BillingMachine::InvoiceSingleVatPdf < Prawn::Document
355
303
  c.align = :right
356
304
  end
357
305
  end
306
+
358
307
  stroke do
359
308
  rectangle [(bounds.right - fourth_column_width - last_column_width), bounds.top], (fourth_column_width + last_column_width), (bounds.top-cursor)
360
309
  end
361
310
  end
362
311
  end
363
312
 
364
- def build_comments
365
- return if main_document.comments.blank?
366
-
367
- top = bounds.top - products_table_height - 35.mm
368
- height = top - bounds.bottom
369
- width = 10.cm
370
-
371
- text_box main_document.comments,
372
- :at => [bounds.left, top],
373
- :height => height,
374
- :width => width,
375
- :overflow => :shrink_to_fit,
376
- :size => 9
377
- end
378
-
379
- def build_payment_conditions
380
- return if main_document.payment_term.blank?
313
+ def document_infos_content
314
+ txt = []
381
315
 
382
- top = bounds.top - products_table_height - 5.mm
383
- height = 15.mm
384
- width = 7.5.cm
316
+ if main_document.try(:payment_term).present?
317
+ txt << "<b>#{main_document.t :payment_term}</b> : #{main_document.payment_term}"
318
+ end
385
319
 
386
- txt = "<b>#{main_document.t(:payment_terms)}</b> : #{main_document.payment_term}"
320
+ if main_document.try(:expires_at).present?
321
+ txt << "<b>#{main_document.t :expires_at}</b> : #{date main_document.expires_at}"
322
+ end
387
323
 
388
- text_box txt,
389
- :at => [bounds.left, top],
390
- :height => height,
391
- :width => width,
392
- :overflow => :shrink_to_fit,
393
- :inline_format => true,
394
- :size => 9
395
- end
324
+ txt << main_document.comments
396
325
 
397
- def build_expiry
326
+ txt.select(&:present?).join("\n\n")
398
327
  end
399
328
 
400
- def build_bank_informations
401
- top = bounds.top - products_table_height - 20.mm
402
- height = 1.cm
403
- width = 7.5.cm
329
+ def build_document_infos
330
+ top = bounds.top - products_table_height - 5.mm
331
+ height = middle_height - products_table_height - 5.mm
332
+ width = 10.cm
404
333
 
405
- bounding_box [bounds.left, top], height: height, width: width do
406
- draw_bounds_debug
407
- font_size 9 do
408
- text "#{main_document.t(:iban)} : #{@id_card.iban}" if @id_card.iban.present?
409
- text "#{main_document.t(:bic_swift)} : #{@id_card.bic_swift}" if @id_card.bic_swift.present?
410
- end
411
- end
334
+ btb document_infos_content, top: top, height: height, width: width
412
335
  end
413
336
 
414
337
  def build_footer
415
- top = bounds.bottom + footer_height
338
+ top = bounds.bottom + footer_height
339
+ height = footer_height
416
340
 
417
- bounding_box [0, top], width: bounds.width, height: footer_height do
418
- draw_bounds_debug
341
+ bb top: top, height: height do
419
342
  build_footer_top
420
343
  build_footer_line
421
344
  build_footer_bottom
422
345
  end
423
346
  end
424
347
 
348
+ # TODO
425
349
  def footer_top_content
426
- @id_card.custom_info_1.to_s
350
+ placeholder __method__
427
351
  end
428
352
 
429
353
  def build_footer_top
430
- top = bounds.top
431
- height = footer_top_height
432
- width = bounds.width
433
-
434
- text_box footer_top_content,
435
- :at => [bounds.left, top],
436
- :height => height,
437
- :width => width,
438
- :overflow => :shrink_to_fit,
439
- :size => 9
354
+ btb footer_top_content, height: footer_top_height, size: 9
440
355
  end
441
356
 
442
357
  def build_footer_line
443
- # Center line between the two footer parts
444
- n = footer_top_height + (footer_height - footer_top_height - footer_bottom_height) / 2
445
- move_down n
358
+ top = bounds.top - footer_top_height - (footer_height - footer_top_height - footer_bottom_height - footer_pagination_height) / 2
446
359
  stroke do
447
- horizontal_rule
448
- line_width 1
360
+ horizontal_line bounds.left, bounds.right, at: top
449
361
  end
450
362
  end
451
363
 
452
364
  def footer_bottom_content
453
- infos_text = []
454
- infos_text << @id_card.entity_name if @id_card.entity_name.present?
455
- infos_text << "#{main_document.t(:info_phone)} : #{@id_card.contact_phone}" if @id_card.contact_phone.present?
456
- infos_text << "#{main_document.t(:info_fax)} : #{@id_card.contact_fax}" if @id_card.contact_fax.present?
457
- infos_text << "#{@id_card.contact_email}" if @id_card.contact_email.present?
458
- infos_text << "#{@id_card.legal_form.to_s}" if @id_card.legal_form.present?
459
- infos_text << "#{main_document.t(:capital)} : #{bm_currency @id_card.capital}" if @id_card.capital.present?
460
- infos_text << "#{main_document.t(:registration)} : #{@id_card.registration_city} #{@id_card.registration_number}" if @id_card.registration_number.present?
461
- infos_text << "#{main_document.t(:siret)} : #{@id_card.siret}" if @id_card.siret.present?
462
- infos_text << "#{main_document.t(:intracommunity_vat)} : #{@id_card.intracommunity_vat}" if @id_card.intracommunity_vat.present?
463
- infos_text = infos_text.join(" - ")
365
+ placeholder __method__
464
366
  end
465
367
 
466
368
  def build_footer_bottom
467
369
  height = footer_bottom_height
468
- top = bounds.bottom + height
469
- width = bounds.width
470
-
471
- text_box footer_bottom_content,
472
- :at => [bounds.left, top],
473
- :height => height,
474
- :width => width,
475
- :overflow => :shrink_to_fit,
476
- :size => 9
370
+ top = bounds.bottom + height + footer_pagination_height
371
+
372
+ btb footer_bottom_content, top: top, height: height, size: 9
477
373
  end
478
374
 
479
375
  def build_page_numbers
480
- height = 5.mm
376
+ height = footer_pagination_height
481
377
  top = bounds.bottom + height
482
- width = bounds.width
483
378
 
484
- bounding_box [0, top], height: height, width: bounds.width do
485
- float do
486
- number_pages "page <page>/<total>", align: :right, size: 9
487
- end
379
+ bb top: top, height: height do
380
+ number_pages "page <page>/<total>", align: :right, size: 9
488
381
  end
489
382
  end
490
-
491
- def draw_bounds_debug
492
- transparent(0.5) { stroke_bounds } if DEBUG
493
- end
494
383
  end