mno-enterprise-core 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -0
  3. data/Rakefile +12 -0
  4. data/app/assets/images/mno_enterprise/main-logo.png +0 -0
  5. data/app/controllers/mno_enterprise/application_controller.rb +116 -0
  6. data/app/helpers/mno_enterprise/application_helper.rb +67 -0
  7. data/app/helpers/mno_enterprise/impersonate_helper.rb +27 -0
  8. data/app/models/mno_enterprise/ability.rb +6 -0
  9. data/app/models/mno_enterprise/app.rb +72 -0
  10. data/app/models/mno_enterprise/app_instance.rb +36 -0
  11. data/app/models/mno_enterprise/app_instances_sync.rb +6 -0
  12. data/app/models/mno_enterprise/arrears_situation.rb +6 -0
  13. data/app/models/mno_enterprise/audit_event.rb +21 -0
  14. data/app/models/mno_enterprise/base_resource.rb +228 -0
  15. data/app/models/mno_enterprise/credit_card.rb +40 -0
  16. data/app/models/mno_enterprise/deletion_request.rb +35 -0
  17. data/app/models/mno_enterprise/impac/dashboard.rb +36 -0
  18. data/app/models/mno_enterprise/impac/dashboard_provisioner.rb +5 -0
  19. data/app/models/mno_enterprise/impac/kpi.rb +9 -0
  20. data/app/models/mno_enterprise/impac/widget.rb +13 -0
  21. data/app/models/mno_enterprise/invoice.rb +53 -0
  22. data/app/models/mno_enterprise/org_invite.rb +50 -0
  23. data/app/models/mno_enterprise/organization.rb +33 -0
  24. data/app/models/mno_enterprise/team.rb +50 -0
  25. data/app/models/mno_enterprise/tenant.rb +5 -0
  26. data/app/models/mno_enterprise/tenant_invoice.rb +5 -0
  27. data/app/models/mno_enterprise/user.rb +183 -0
  28. data/app/pdf/mno_enterprise/invoice_pdf.rb +516 -0
  29. data/config/initializers/audit_log.rb +5 -0
  30. data/config/locales/devise.en.yml +60 -0
  31. data/config/routes.rb +2 -0
  32. data/config/styleguide.yml +106 -0
  33. data/lib/accountingjs_serializer.rb +51 -0
  34. data/lib/devise/controllers/extension_helpers.rb +52 -0
  35. data/lib/devise/extension_routes.rb +11 -0
  36. data/lib/devise/hooks/password_expirable.rb +5 -0
  37. data/lib/devise/models/password_expirable.rb +28 -0
  38. data/lib/devise/models/remote_authenticatable.rb +48 -0
  39. data/lib/devise/strategies/remote_authenticatable.rb +44 -0
  40. data/lib/devise_extension.rb +36 -0
  41. data/lib/faraday/adapter/net_http_no_proxy.rb +19 -0
  42. data/lib/generators/mno_enterprise/database_extension/USAGE +11 -0
  43. data/lib/generators/mno_enterprise/database_extension/database_extension_generator.rb +36 -0
  44. data/lib/generators/mno_enterprise/database_extension/templates/model.rb +9 -0
  45. data/lib/generators/mno_enterprise/dummy/dummy_generator.rb +98 -0
  46. data/lib/generators/mno_enterprise/dummy/templates/rails/application.rb.erb +9 -0
  47. data/lib/generators/mno_enterprise/dummy/templates/rails/boot.rb.erb +6 -0
  48. data/lib/generators/mno_enterprise/dummy/templates/rails/database.yml +22 -0
  49. data/lib/generators/mno_enterprise/dummy/templates/rails/routes.rb +8 -0
  50. data/lib/generators/mno_enterprise/dummy/templates/rails/test-env.rb +45 -0
  51. data/lib/generators/mno_enterprise/install/install_generator.rb +140 -0
  52. data/lib/generators/mno_enterprise/install/templates/Procfile +1 -0
  53. data/lib/generators/mno_enterprise/install/templates/config/initializers/mno_enterprise.rb +135 -0
  54. data/lib/generators/mno_enterprise/install/templates/config/mno_enterprise_styleguide.yml +104 -0
  55. data/lib/generators/mno_enterprise/install/templates/javascripts/mno_enterprise_extensions.js +7 -0
  56. data/lib/generators/mno_enterprise/install/templates/stylesheets/main.less_erb +25 -0
  57. data/lib/generators/mno_enterprise/install/templates/stylesheets/theme.less_erb +59 -0
  58. data/lib/generators/mno_enterprise/install/templates/stylesheets/variables.less +337 -0
  59. data/lib/generators/mno_enterprise/install/templates/tasks/sprites.rake +14 -0
  60. data/lib/generators/mno_enterprise/puma_stack/puma_stack_generator.rb +58 -0
  61. data/lib/generators/mno_enterprise/templates/scripts/monit/app-server.conf +8 -0
  62. data/lib/generators/mno_enterprise/templates/scripts/nginx/app +51 -0
  63. data/lib/generators/mno_enterprise/templates/scripts/puma.rb +25 -0
  64. data/lib/generators/mno_enterprise/templates/scripts/setup.sh +27 -0
  65. data/lib/generators/mno_enterprise/templates/scripts/upstart/app-web-hotrestart.conf +26 -0
  66. data/lib/generators/mno_enterprise/templates/scripts/upstart/app-web-server.conf +34 -0
  67. data/lib/generators/mno_enterprise/templates/scripts/upstart/app-web.conf +2 -0
  68. data/lib/generators/mno_enterprise/templates/scripts/upstart/app.conf +11 -0
  69. data/lib/her_extension/her_orm_adapter.rb +54 -0
  70. data/lib/her_extension/middleware/mnoe_api_v1_parse_json.rb +54 -0
  71. data/lib/her_extension/model/associations/association.rb +61 -0
  72. data/lib/her_extension/model/associations/association_proxy.rb +34 -0
  73. data/lib/her_extension/model/associations/has_many_association.rb +115 -0
  74. data/lib/her_extension/model/attributes.rb +43 -0
  75. data/lib/her_extension/model/orm.rb +59 -0
  76. data/lib/her_extension/model/parse.rb +40 -0
  77. data/lib/her_extension/model/relation.rb +92 -0
  78. data/lib/her_extension/validations/remote_uniqueness_validation.rb +33 -0
  79. data/lib/html_processor.rb +106 -0
  80. data/lib/mandrill_client.rb +58 -0
  81. data/lib/mno-enterprise-core.rb +1 -0
  82. data/lib/mno_enterprise/concerns.rb +4 -0
  83. data/lib/mno_enterprise/concerns/controllers.rb +6 -0
  84. data/lib/mno_enterprise/concerns/controllers/angular_csrf.rb +59 -0
  85. data/lib/mno_enterprise/concerns/controllers/auth.rb +9 -0
  86. data/lib/mno_enterprise/concerns/controllers/auth/confirmations_controller.rb +187 -0
  87. data/lib/mno_enterprise/concerns/controllers/auth/passwords_controller.rb +54 -0
  88. data/lib/mno_enterprise/concerns/controllers/auth/registrations_controller.rb +136 -0
  89. data/lib/mno_enterprise/concerns/controllers/auth/sessions_controller.rb +54 -0
  90. data/lib/mno_enterprise/concerns/controllers/auth/unlocks_controller.rb +50 -0
  91. data/lib/mno_enterprise/concerns/models.rb +6 -0
  92. data/lib/mno_enterprise/concerns/models/ability.rb +108 -0
  93. data/lib/mno_enterprise/concerns/models/app_instance.rb +100 -0
  94. data/lib/mno_enterprise/concerns/models/organization.rb +102 -0
  95. data/lib/mno_enterprise/core.rb +279 -0
  96. data/lib/mno_enterprise/database_extendable.rb +57 -0
  97. data/lib/mno_enterprise/engine.rb +33 -0
  98. data/lib/mno_enterprise/testing_support/ability_test_helper.rb +10 -0
  99. data/lib/mno_enterprise/testing_support/common_rake.rb +19 -0
  100. data/lib/mno_enterprise/testing_support/factories.rb +13 -0
  101. data/lib/mno_enterprise/testing_support/factories/app_instances.rb +30 -0
  102. data/lib/mno_enterprise/testing_support/factories/apps.rb +45 -0
  103. data/lib/mno_enterprise/testing_support/factories/arrears_situation.rb +14 -0
  104. data/lib/mno_enterprise/testing_support/factories/audit_event.rb +15 -0
  105. data/lib/mno_enterprise/testing_support/factories/credit_card.rb +33 -0
  106. data/lib/mno_enterprise/testing_support/factories/deletion_request.rb +17 -0
  107. data/lib/mno_enterprise/testing_support/factories/impac/dashboards.rb +15 -0
  108. data/lib/mno_enterprise/testing_support/factories/impac/kpis.rb +20 -0
  109. data/lib/mno_enterprise/testing_support/factories/impac/widgets.rb +15 -0
  110. data/lib/mno_enterprise/testing_support/factories/invoices.rb +51 -0
  111. data/lib/mno_enterprise/testing_support/factories/org_invite.rb +24 -0
  112. data/lib/mno_enterprise/testing_support/factories/organizations.rb +25 -0
  113. data/lib/mno_enterprise/testing_support/factories/team.rb +17 -0
  114. data/lib/mno_enterprise/testing_support/factories/tenant.rb +12 -0
  115. data/lib/mno_enterprise/testing_support/factories/tenant_invoice.rb +29 -0
  116. data/lib/mno_enterprise/testing_support/factories/users.rb +48 -0
  117. data/lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb +49 -0
  118. data/lib/mno_enterprise/testing_support/mno_enterprise_api_test_helper.rb +167 -0
  119. data/lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb +173 -0
  120. data/lib/mno_enterprise/testing_support/organizations_shared_helpers.rb +175 -0
  121. data/lib/mno_enterprise/testing_support/user_action_shared.rb +47 -0
  122. data/lib/mno_enterprise/version.rb +3 -0
  123. data/lib/tasks/mno_enterprise_tasks.rake +22 -0
  124. data/spec/controllers/mno_enterprise/angular_csrf_spec.rb +42 -0
  125. data/spec/lib/her_extension/her_orm_adapter.rb +7 -0
  126. data/spec/lib/her_extension/model/relation_spec.rb +7 -0
  127. data/spec/lib/mandrill_client_spec.rb +64 -0
  128. data/spec/mno_enterprise_spec.rb +79 -0
  129. data/spec/models/mno_enterprise/app_instance_spec.rb +7 -0
  130. data/spec/models/mno_enterprise/app_spec.rb +62 -0
  131. data/spec/models/mno_enterprise/base_resource_spec.rb +28 -0
  132. data/spec/models/mno_enterprise/deletion_request_spec.rb +26 -0
  133. data/spec/models/mno_enterprise/invoice_spec.rb +7 -0
  134. data/spec/models/mno_enterprise/organization_spec.rb +7 -0
  135. data/spec/models/mno_enterprise/user_spec.rb +44 -0
  136. data/spec/rails_helper.rb +73 -0
  137. data/spec/spec_helper.rb +78 -0
  138. metadata +421 -0
@@ -0,0 +1,516 @@
1
+ module MnoEnterprise
2
+ class InvoicePdf
3
+ attr_reader :invoice, :pdf, :data
4
+
5
+ # InvoicePdf requires to be initialized
6
+ # with an Invoice object
7
+ def initialize(invoice)
8
+ raise ArgumentError, "Received #{invoice.class} object (expected instance of Invoice)" unless invoice.is_a?(MnoEnterprise::Invoice)
9
+ @invoice = invoice
10
+ @pdf = nil
11
+ @data = {}
12
+
13
+ #===============================
14
+ # Initialize formatting
15
+ #===============================
16
+ @format = {}
17
+ @format[:header_size] = 120
18
+ @format[:footer_size] = 100
19
+ @format[:top_margin] = 36
20
+ @format[:bottom_margin] = 36
21
+
22
+ #===============================
23
+ # Data hash
24
+ #===============================
25
+ @data = {}
26
+
27
+ # Invoice details
28
+ @data[:invoice_reference] = @invoice.slug
29
+
30
+ # Customer details
31
+ invoicable = @invoice.organization
32
+ [:name, :email, :current_credit].each do |detail|
33
+ @data["customer_#{detail}".to_sym] = invoicable.respond_to?(detail) ? invoicable.send(detail) : nil
34
+ end
35
+
36
+ # Billing Address - Kept at the invoice level for audit purpose
37
+ @data[:customer_billing_address] = @invoice.billing_address
38
+
39
+ # Financial values
40
+ @data[:invoice_price] = @invoice.price
41
+ @data[:invoice_currency] = @invoice.price.currency_as_string
42
+ @data[:invoice_currency_name] = @invoice.price.currency.name
43
+ @data[:invoice_credit_paid] = @invoice.credit_paid
44
+ @data[:invoice_total_due] = @invoice.total_due
45
+ @data[:invoice_total_payable] = @invoice.total_payable
46
+ @data[:invoice_tax_payable] = @invoice.tax_payable
47
+ @data[:invoice_tax_pips] = (@invoice.tax_pips_applied || 0)
48
+ @data[:invoice_total_payable_with_tax] = @data[:invoice_total_payable] + @data[:invoice_tax_payable]
49
+ @data[:invoice_fully_paid] = (@data[:invoice_total_payable].zero? || @data[:invoice_total_payable].negative?)
50
+
51
+ # Last App billing (Account Situation)
52
+ @data[:invoice_previous_total_due] = @invoice.previous_total_due
53
+ @data[:invoice_previous_total_paid] = @invoice.previous_total_paid
54
+
55
+ # Billing details
56
+ @data[:billing_report] = @invoice.billing_summary.map do |item|
57
+ item_label = item[:label]
58
+ price_label = item[:price_tag]
59
+
60
+ (item[:lines] || []).each do |item_line|
61
+ item_label += "<font size='4'>\n\n</font><font size='8'><color rgb='999999'><i>#{Prawn::Text::NBSP * 3}#{item_line[:label]}</i></color></font>"
62
+ price_label += "<font size='4'>\n\n</font><font size='8'><color rgb='999999'>#{item_line[:price_tag]}</color></font>"
63
+ end
64
+
65
+ [item_label, item[:name], item[:usage], price_label]
66
+ end
67
+
68
+ # Billing period
69
+ @data[:period_started_at] = @invoice.started_at.utc.to_date
70
+ @data[:period_ended_at] = (@invoice.ended_at.utc - 1.minute).to_date # '- 1 minute' to avoid midnight (which belongs to following day)
71
+ @data[:period_month] = @invoice.ended_at.strftime("%B")
72
+ next_period = @data[:period_ended_at] + 1.month
73
+ @data[:period_charge_date] = Date.new(next_period.year,next_period.month,2)
74
+ end
75
+
76
+ # Render the pdf document and return
77
+ # it as a string object
78
+ def render
79
+ generate_content
80
+ @pdf.render
81
+ end
82
+
83
+ # Generate the document content
84
+ # by adding body, header, footer and
85
+ # page numbering
86
+ def generate_content
87
+ @pdf = Prawn::Document.new(
88
+ info: self.metadata,
89
+ top_margin: @format[:header_size] + @format[:top_margin],
90
+ bottom_margin: @format[:footer_size] + @format[:bottom_margin]
91
+ )
92
+ add_page_body
93
+ add_page_header
94
+ add_page_footer
95
+ add_page_numbering
96
+ end
97
+
98
+ # Generate the document metadata
99
+ def metadata
100
+ {
101
+ Title: 'Maestrano Monthly Invoice',
102
+ Author: 'Maestrano',
103
+ Subject: 'Maestrano Monthly Invoice',
104
+ Producer: 'Maestrano',
105
+ CreationDate: Time.now
106
+ }
107
+ end
108
+
109
+ # Helper method to easily access
110
+ # images
111
+ def image_path(name)
112
+ path = "/app/assets/images/#{name}"
113
+ engine_path = "#{MnoEnterprise::Engine.root}#{path}"
114
+ app_path = "#{Rails.root}#{path}"
115
+
116
+ File.exists?(app_path) ? app_path : engine_path
117
+ end
118
+
119
+ # Add a repeated header to the document
120
+ def add_page_header
121
+ @pdf.repeat :all do
122
+ @pdf.bounding_box([0, @pdf.bounds.top+@format[:header_size]], width: 540, height: @format[:footer_size]) do
123
+ @pdf.float do
124
+ @pdf.image image_path('mno_enterprise/main-logo.png'), scale: 0.5
125
+ end
126
+ @pdf.move_down 52
127
+ @pdf.font_size(20) { @pdf.text "Monthly Invoice - #{@data[:period_month]}", style: :bold, align: :right }
128
+ end
129
+ end
130
+ end
131
+
132
+ # Add a repeated footer to the document
133
+ def add_page_footer
134
+ @pdf.repeat :all do
135
+ @pdf.bounding_box([0, @pdf.bounds.bottom], width: 540, height: @format[:footer_size]) do
136
+ @pdf.move_down 50
137
+ @pdf.stroke_color '999999'
138
+ @pdf.stroke_horizontal_rule
139
+ @pdf.move_down 10
140
+ @pdf.font_size(8) do
141
+ @pdf.text "<color rgb='999999'>Maestrano is a service of Maestrano Pty Ltd (ABN: 80 152 564 424),</color>", inline_format: true
142
+ @pdf.text "<color rgb='999999'>Suite 102, 410 Elizabeth Street, Surry Hills 2010, Sydney, Australia.</color>", inline_format: true
143
+ @pdf.text "<color rgb='999999'>All charges are in #{@data[:invoice_currency_name]} (#{@data[:invoice_currency]}).</color>", inline_format: true
144
+ end
145
+ end
146
+ end
147
+ end
148
+
149
+ # Add page number on every page
150
+ def add_page_numbering
151
+ numbering_options = {
152
+ at: [@pdf.bounds.right - 150, 0-@format[:footer_size]],
153
+ width: 150,
154
+ align: :right,
155
+ start_count_at: 1,
156
+ color: "999999",
157
+ size: 8
158
+ }
159
+ @pdf.number_pages "Page <page> of <total>", numbering_options
160
+ end
161
+
162
+ # This method is responsible for
163
+ # generating the actual pdf content
164
+ def add_page_body
165
+ @pdf.stroke_color '999999'
166
+
167
+ #===============================
168
+ # Invoice Reference
169
+ #===============================
170
+ @pdf.float do
171
+ original_color = @pdf.fill_color
172
+ @pdf.fill_color "F0F0F0"
173
+ @pdf.fill_rounded_rectangle [310,@pdf.cursor], 230, 50, 5
174
+ @pdf.fill_color = original_color
175
+
176
+ @pdf.text_box "Your Reference", at: [310,@pdf.cursor], width: 65, height: 13, align: :center, valign: :center,
177
+ style: :bold_italic, size: 7
178
+
179
+ @pdf.text_box @data[:invoice_reference], at: [310,@pdf.cursor], width: 230, height: 50, align: :center, valign: :center,
180
+ style: :bold
181
+ end
182
+
183
+ #===============================
184
+ # Customer information
185
+ #===============================
186
+ @pdf.text @data[:customer_name], align: :left, inline_format: true
187
+
188
+ if @data[:customer_email]
189
+ @pdf.text "<color rgb='999999'>#{@data[:customer_email]}</color>", align: :left, inline_format: true
190
+ end
191
+
192
+ if @data[:customer_billing_address]
193
+ @pdf.move_down 5
194
+ @pdf.text "<color rgb='999999'>#{@data[:customer_billing_address]}</color>", align: :left, inline_format: true, style: :italic, size: 9
195
+ end
196
+
197
+
198
+
199
+ #===============================
200
+ # Summary
201
+ #===============================
202
+ @pdf.move_down 40
203
+ @pdf.font_size(20) { @pdf.text 'Summary', style: :bold }
204
+ @pdf.stroke_horizontal_rule
205
+ @pdf.move_down 10
206
+
207
+ summary_data = []
208
+ summary_data << ['Period', 'Total Payable' + (@data[:invoice_tax_pips] > 0 ? "\n<font size='8'><i>(incl. GST)</i></font>" : '')]
209
+ summary_data << ["#{@data[:period_started_at].strftime("%B, %e %Y")} to #{@data[:period_ended_at].strftime("%B, %e %Y")}",@data[:invoice_total_payable_with_tax].format]
210
+
211
+ # Draw Table background
212
+ bg_height = @data[:invoice_tax_pips] > 0 ? 58 : 50
213
+ @pdf.float do
214
+ original_color = @pdf.fill_color
215
+ @pdf.fill_color "d1e17c"
216
+ @pdf.fill_rounded_rectangle [0,@pdf.cursor], 540, bg_height, 5
217
+ @pdf.fill_color = original_color
218
+ end
219
+
220
+ # Draw Table
221
+ @pdf.table(summary_data) do |t|
222
+ t.header = true
223
+ t.width = 540
224
+ t.column_widths = [435,105]
225
+ t.cell_style = { borders: [] }
226
+ t.row(0).font_style = :bold
227
+
228
+ t.cell_style = { padding: [5, 5, 5, 10], inline_format: true }
229
+ t.cells.style do |c|
230
+ if c.column == 1
231
+ c.align = :center
232
+ end
233
+ end
234
+ end
235
+
236
+ @pdf.move_down 10
237
+ @pdf.indent(5) do
238
+ @pdf.font_size(8) do
239
+ @pdf.text "<color rgb='999999'> Charges are all displayed in #{@data[:invoice_currency_name]} (#{@data[:invoice_currency]})</color>", inline_format: true
240
+ if @data[:invoice_fully_paid]
241
+ @pdf.text "<color rgb='999999'> No credit card payments required for this invoice</color>", inline_format: true
242
+ else
243
+ @pdf.text "<color rgb='999999'> Your designated credit card will be charged on #{@data[:period_charge_date].strftime("%B,%e %Y")} at midnight UTC</color>", inline_format: true
244
+ end
245
+ end
246
+ end
247
+
248
+ #===============================
249
+ # Credit Remaining
250
+ # ---
251
+ # Only if greater than zero
252
+ #===============================
253
+ if @data[:customer_current_credit] && @data[:customer_current_credit].positive?
254
+ @pdf.move_down 5
255
+ @pdf.indent(5) do
256
+ @pdf.font_size(8) do
257
+ @pdf.text "<color rgb='999999'> Note that your credit is shared with any organization you may have created</color>", inline_format: true
258
+ end
259
+ end
260
+
261
+ @pdf.move_up 28
262
+
263
+ @pdf.float do
264
+ original_color = @pdf.fill_color
265
+ @pdf.fill_color "67BBE9"
266
+ @pdf.fill_rounded_rectangle [445,@pdf.cursor], 95, 50, 5
267
+ @pdf.fill_color = original_color
268
+
269
+ @pdf.text_box "Credit Remaining", at: [445,@pdf.cursor], width: 95, height: 23, align: :center, valign: :center,
270
+ style: :bold, size: 10
271
+
272
+ @pdf.text_box @data[:customer_current_credit].format, at: [445,@pdf.cursor], width: 95, height: 37, align: :center, valign: :bottom
273
+ end
274
+
275
+ @pdf.move_down 40
276
+ end
277
+
278
+ #===============================
279
+ # Account Situation
280
+ #===============================
281
+ @pdf.move_down 30
282
+ @pdf.font_size(20) { @pdf.text 'Account Situation', style: :bold }
283
+ @pdf.stroke_horizontal_rule
284
+ @pdf.move_down 10
285
+
286
+ # Situation Data
287
+ situation_data = []
288
+ # Header
289
+ situation_data << [
290
+ '',
291
+ '',
292
+ 'Due Last Month',
293
+ '',
294
+ 'Paid (Thank You)',
295
+ '',
296
+ 'This Month',
297
+ '',
298
+ 'Credit',
299
+ '',
300
+ 'Total'
301
+ ]
302
+
303
+ #Content
304
+ situation_data << [
305
+ '',
306
+ '',
307
+ @data[:invoice_previous_total_due].format,
308
+ '-',
309
+ @data[:invoice_previous_total_paid].format,
310
+ '+',
311
+ @data[:invoice_price].format,
312
+ '-',
313
+ @data[:invoice_credit_paid].format,
314
+ '=',
315
+ @data[:invoice_total_payable].format
316
+ ]
317
+
318
+ # Draw background
319
+ @pdf.float do
320
+ original_color = @pdf.fill_color
321
+ @pdf.fill_color "F0F0F0"
322
+ @pdf.fill_rounded_rectangle [0,@pdf.cursor], 540, 50, 5
323
+ @pdf.fill_color = original_color
324
+ end
325
+
326
+
327
+ # Draw left background
328
+ @pdf.float do
329
+ original_color = @pdf.fill_color
330
+ @pdf.fill_color "E0E0E0"
331
+ @pdf.fill_rounded_rectangle [0,@pdf.cursor], 80, 50, 5
332
+ @pdf.fill_color = original_color
333
+ @pdf.move_down 21
334
+ if @data[:invoice_tax_pips] > 0
335
+ @pdf.text_box 'Excl. GST', at: [12,@pdf.cursor]
336
+ else
337
+ @pdf.text_box 'Details', at: [20,@pdf.cursor]
338
+ end
339
+ end
340
+
341
+ # Draw table
342
+ @pdf.table(situation_data) do |t|
343
+ t.header = true
344
+ t.width = 540
345
+ t.column_widths = [75,18,75,18,75,18,75,18,75,18,75]
346
+ t.row(0).font_style = :bold
347
+ t.row(0).size = 8
348
+ t.row(0).height = 22
349
+ t.row(1).height = 25
350
+
351
+ t.cell_style = {
352
+ borders: [],
353
+ overflow: :shrink_to_fit,
354
+ align: :center
355
+ }
356
+
357
+ # Color the '+','-' and '=' characters
358
+ t.cells.style do |c|
359
+ if c.row == 1 && c.column.odd?
360
+ c.text_color = "a8a8a8"
361
+ end
362
+ end
363
+ end
364
+
365
+
366
+ #=================================
367
+ # Account Situation - Tax Section
368
+ #=================================
369
+ if @data[:invoice_tax_pips] > 0
370
+
371
+ #-----------------
372
+ # GST row
373
+ #-----------------
374
+ @pdf.move_down 8
375
+
376
+ table_data = []
377
+ table_data << [
378
+ '',
379
+ '',
380
+ '',
381
+ '',
382
+ '',
383
+ '',
384
+ '',
385
+ '',
386
+ 'GST',
387
+ '+',
388
+ @data[:invoice_tax_payable].format,
389
+ ]
390
+
391
+ # Draw table background
392
+ @pdf.float do
393
+ original_color = @pdf.fill_color
394
+ @pdf.fill_color "F0F0F0"
395
+ @pdf.fill_rounded_rectangle [368,@pdf.cursor], 172, 24, 5
396
+ @pdf.fill_color = original_color
397
+ end
398
+
399
+ # Draw left background
400
+ @pdf.float do
401
+ original_color = @pdf.fill_color
402
+ @pdf.fill_color "FAB451"
403
+ @pdf.fill_rounded_rectangle [368,@pdf.cursor], 80, 24, 5
404
+ @pdf.fill_color = original_color
405
+ end
406
+
407
+ @pdf.table(table_data) do |t|
408
+ t.header = true
409
+ t.width = 540
410
+ t.column_widths = [75,18,75,18,75,18,75,18,75,18,75]
411
+ t.row(0).height = 25
412
+
413
+ t.cell_style = {
414
+ borders: [],
415
+ overflow: :shrink_to_fit,
416
+ align: :center
417
+ }
418
+
419
+ # Color the '+','-' and '=' characters
420
+ t.cells.style do |c|
421
+ if c.row == 0 && c.column.odd?
422
+ c.text_color = "a8a8a8"
423
+ end
424
+ end
425
+ end
426
+
427
+
428
+ #-----------------
429
+ # Total (incl. GST)
430
+ #-----------------
431
+ @pdf.move_down 5
432
+
433
+ table_data = []
434
+ table_data << [
435
+ '',
436
+ '',
437
+ '',
438
+ '',
439
+ '',
440
+ '',
441
+ '',
442
+ '',
443
+ 'Total (incl. GST)',
444
+ '=',
445
+ @data[:invoice_total_payable_with_tax].format,
446
+ ]
447
+
448
+ # Draw table background
449
+ @pdf.float do
450
+ original_color = @pdf.fill_color
451
+ @pdf.fill_color "F0F0F0"
452
+ @pdf.fill_rounded_rectangle [368,@pdf.cursor], 172, 24, 5
453
+ @pdf.fill_color = original_color
454
+ end
455
+
456
+ # Draw left background
457
+ @pdf.float do
458
+ original_color = @pdf.fill_color
459
+ @pdf.fill_color "DAE173"
460
+ @pdf.fill_rounded_rectangle [368,@pdf.cursor], 80, 24, 5
461
+ @pdf.fill_color = original_color
462
+ end
463
+
464
+ @pdf.table(table_data) do |t|
465
+ t.header = true
466
+ t.width = 540
467
+ t.row(0).font_style = :bold
468
+ t.column_widths = [75,18,75,18,75,18,75,18,75,18,75]
469
+ t.row(0).height = 25
470
+
471
+ t.cell_style = {
472
+ borders: [],
473
+ overflow: :shrink_to_fit,
474
+ align: :center
475
+ }
476
+
477
+ # Color the '+','-' and '=' characters
478
+ t.cells.style do |c|
479
+ if c.row == 0 && c.column.odd?
480
+ c.text_color = "a8a8a8"
481
+ end
482
+ end
483
+ end
484
+
485
+ end
486
+
487
+
488
+ #===============================
489
+ # Details
490
+ #===============================
491
+ @pdf.start_new_page
492
+ @pdf.font_size(20) { @pdf.text 'Details', style: :bold }
493
+ @pdf.stroke_horizontal_rule
494
+ @pdf.move_down 10
495
+
496
+ app_details_data = []
497
+ app_details_data << ['Product', 'Type', 'Usage', 'Price' + (@data[:invoice_tax_pips] > 0 ? "\n<font size='8'><i>(excl. GST)</i></font>" : '')]
498
+ app_details_data += @data[:billing_report]
499
+
500
+ @pdf.table(app_details_data) do |t|
501
+ t.header = true
502
+ t.width = 540
503
+ t.row_colors = ["FFFFFF", "F0F0F0"]
504
+ t.column_widths = [240,100,100,100]
505
+ t.cell_style = { borders: [:bottom],
506
+ border_width: 1,
507
+ border_color: "999999",
508
+ inline_format: true
509
+ }
510
+ t.row(0).borders = [:bottom]
511
+ t.row(0).border_width = 2
512
+ t.row(0).font_style = :bold
513
+ end
514
+ end
515
+ end
516
+ end