mno-enterprise-core 3.2.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/mno_enterprise/application_controller.rb +5 -5
  3. data/app/helpers/mno_enterprise/image_helper.rb +32 -0
  4. data/app/models/mno_enterprise/app.rb +11 -2
  5. data/app/models/mno_enterprise/base_resource.rb +2 -0
  6. data/app/models/mno_enterprise/credit_card.rb +7 -4
  7. data/app/models/mno_enterprise/impac/dashboard.rb +4 -1
  8. data/app/models/mno_enterprise/impac/widget.rb +10 -4
  9. data/app/models/mno_enterprise/org_invite.rb +7 -3
  10. data/app/models/mno_enterprise/shared_entity.rb +17 -0
  11. data/app/models/mno_enterprise/user.rb +7 -2
  12. data/app/pdf/mno_enterprise/invoice_pdf.rb +176 -183
  13. data/app/views/system_notifications/email-change.html.erb +1 -1
  14. data/app/views/system_notifications/email-change.text.erb +1 -1
  15. data/config/initializers/audit_log.rb +28 -1
  16. data/config/locales/templates/components/en.yml +29 -4
  17. data/config/locales/templates/dashboard/en.yml +2 -2
  18. data/config/locales/templates/dashboard/marketplace/en.yml +5 -5
  19. data/config/locales/templates/dashboard/organization/en.yml +14 -8
  20. data/config/locales/templates/dashboard/organization/id.yml +4 -4
  21. data/config/locales/templates/dashboard/organization/zh.yml +4 -4
  22. data/config/locales/templates/dashboard/teams/en.yml +3 -3
  23. data/config/locales/templates/dashboard/teams/id.yml +3 -3
  24. data/config/locales/templates/dashboard/teams/zh.yml +3 -3
  25. data/config/locales/templates/onboarding/en.yml +45 -0
  26. data/config/locales/views/auth/confirmations/en.yml +5 -3
  27. data/config/locales/views/webhook/o_auth/providers/en.yml +2 -2
  28. data/lib/generators/mno_enterprise/install/install_generator.rb +19 -1
  29. data/lib/generators/mno_enterprise/install/templates/Procfile.dev +1 -0
  30. data/lib/generators/mno_enterprise/install/templates/config/initializers/mno_enterprise.rb +7 -50
  31. data/lib/generators/mno_enterprise/install/templates/config/newrelic.yml +3 -3
  32. data/lib/generators/mno_enterprise/install/templates/config/settings.yml +49 -2
  33. data/lib/generators/mno_enterprise/install/templates/nginx.conf +71 -0
  34. data/lib/generators/mno_enterprise/install/templates/stylesheets/variables.less +148 -141
  35. data/lib/html_processor.rb +14 -14
  36. data/lib/mno_enterprise/concerns/controllers/auth/registrations_controller.rb +18 -15
  37. data/lib/mno_enterprise/concerns/models/ability.rb +6 -3
  38. data/lib/mno_enterprise/concerns/models/app_instance.rb +2 -3
  39. data/lib/mno_enterprise/concerns/models/intercom_user.rb +22 -0
  40. data/lib/mno_enterprise/concerns/models/organization.rb +8 -0
  41. data/lib/mno_enterprise/concerns/models/shared_entity.rb +36 -0
  42. data/lib/mno_enterprise/concerns/models/team.rb +7 -0
  43. data/lib/mno_enterprise/testing_support/common_rake.rb +1 -1
  44. data/lib/mno_enterprise/testing_support/factories/apps.rb +6 -0
  45. data/lib/mno_enterprise/testing_support/factories/audit_event.rb +2 -0
  46. data/lib/mno_enterprise/testing_support/mno_enterprise_api_test_helper.rb +47 -16
  47. data/lib/mno_enterprise/testing_support/organizations_shared_helpers.rb +6 -9
  48. data/lib/mno_enterprise/version.rb +1 -1
  49. data/spec/config/initializers/audit_log_spec.rb +5 -0
  50. data/spec/controllers/mno_enterprise/application_controller_spec.rb +4 -4
  51. data/spec/helpers/image_helper_spec.rb +69 -0
  52. data/spec/models/mno_enterprise/ability_spec.rb +5 -0
  53. data/spec/models/mno_enterprise/app_spec.rb +1 -1
  54. data/spec/models/mno_enterprise/base_resource_spec.rb +37 -0
  55. data/spec/models/mno_enterprise/credit_card_spec.rb +18 -0
  56. data/spec/models/mno_enterprise/organization_spec.rb +16 -0
  57. data/spec/models/mno_enterprise/shared_entity_spec.rb +7 -0
  58. data/spec/models/mno_enterprise/user_spec.rb +83 -15
  59. metadata +15 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8e1fe8fd42565b2cf5f939e4a018c1ab33ff576
4
- data.tar.gz: a6fb0eece8899bc8c7a9bbd2e584e2a218dce7ca
3
+ metadata.gz: 31badd1b35fad273dd0d904445d60c9af708e87f
4
+ data.tar.gz: 415613eb183bd7f511be46f2cd221a6228e67847
5
5
  SHA512:
6
- metadata.gz: b3e019b4e3e072537b9dffd8ca2e9615b2f1413920dcb769470cd1ffc7c0a4bd8a8d0d0073fb163df83b7daca5d968cce9e34f6c440954e60700701f77d05a8c
7
- data.tar.gz: ed1b104400a046e01a67026f38bea30ace63d99c3b2b3c3f3b10182b530fa708c5878233d51e3ddd02563615b7aeb49c0e3abed1af7b68309a8fb76710ec62fb
6
+ metadata.gz: 5efebbd5a99177c6a089de239354cb0d2b14c63f421b93eabcebf40dab9a4883855ed1735e8c71935afa6cba87233f3b9af7b4890b4be4e78faaf5f4dec88291
7
+ data.tar.gz: c23a3e38b6f423f49fac9be8faeb7821d99ce0d59c972488860ce86ae1de49b9c4923f157586a765eed773351050a267bfb6b4db8d8258bfa11baed56d7e0bd2
@@ -126,13 +126,13 @@ module MnoEnterprise
126
126
  private
127
127
 
128
128
  # Append params to the fragment part of an existing url String
129
- # add_param("/#/platform/accounts", 'foo', 'bar')
130
- # => "/#/platform/accounts?foo=bar"
131
- # add_param("/#/platform/dashboard/he/43?en=690", 'foo', 'bar')
132
- # => "/#/platform/dashboard/he/43?en=690&foo=bar"
129
+ # add_param_to_fragment("/#!/platform/accounts", 'foo', 'bar')
130
+ # => "/#!/platform/accounts?foo=bar"
131
+ # add_param_to_fragment("/#!/platform/dashboard/he/43?en=690", 'foo', 'bar')
132
+ # => "/#!/platform/dashboard/he/43?en=690&foo=bar"
133
133
  def add_param_to_fragment(url, param_name, param_value)
134
134
  uri = URI(url)
135
- fragment = URI(uri.fragment || "")
135
+ fragment = URI(uri.fragment || "!")
136
136
  params = URI.decode_www_form(fragment.query || "") << [param_name, param_value]
137
137
  fragment.query = URI.encode_www_form(params)
138
138
  uri.fragment = fragment.to_s
@@ -0,0 +1,32 @@
1
+ module MnoEnterprise
2
+ module ImageHelper
3
+
4
+ IMAGES_LOCATION = "/app/assets/images/mno_enterprise/"
5
+
6
+ # Helper method to easily access and select the images
7
+ # If full_path is true returns filename appended to the path
8
+ # If full_path is false returns filename
9
+ # Return the main-logo-whitebg.png if exists, otherwise get main-logo.png
10
+ def main_logo_white_bg_path(full_path=false)
11
+ logo_path = app_image_path("main-logo-whitebg.png") || main_logo_path
12
+ full_path ? logo_path : "mno_enterprise/#{File.basename(logo_path)}"
13
+ end
14
+
15
+ # Return the main-logo.png if exists otherwise get engine's logo
16
+ def main_logo_path
17
+ file_name = "main-logo.png"
18
+ app_image_path(file_name) || engine_image_path(file_name)
19
+ end
20
+
21
+ # Build path and checks if the logo exists
22
+ def app_image_path(file_name)
23
+ app_path = "#{Rails.root}#{IMAGES_LOCATION}#{file_name}"
24
+ app_path if File.exists?(app_path)
25
+ end
26
+
27
+ # Get engine's logo and return it
28
+ def engine_image_path(file_name)
29
+ "#{MnoEnterprise::Engine.root}#{IMAGES_LOCATION}#{file_name}"
30
+ end
31
+ end
32
+ end
@@ -42,6 +42,7 @@ module MnoEnterprise
42
42
  has_many :reviews, class_name: 'AppReview'
43
43
  has_many :feedbacks, class_name: 'AppFeedback'
44
44
  has_many :questions, class_name: 'AppQuestion'
45
+ has_many :shared_entities
45
46
 
46
47
  # Return the list of available categories
47
48
  def self.categories(list = nil)
@@ -64,12 +65,20 @@ module MnoEnterprise
64
65
  end
65
66
 
66
67
  # Methods for appinfo flags
67
- %w(coming_soon single_billing add_on).each do |method|
68
+ %w(responsive coming_soon single_billing add_on).each do |method|
68
69
  define_method "#{method}?" do
69
- appinfo.presence && appinfo[method]
70
+ !!(appinfo.presence && appinfo[method])
70
71
  end
71
72
  end
72
73
 
74
+ def star_ready?
75
+ !!(appinfo.presence && appinfo['starReady'])
76
+ end
77
+
78
+ def connec_ready?
79
+ !!(appinfo.presence && !!appinfo['connecReady'])
80
+ end
81
+
73
82
  def regenerate_api_key!
74
83
  data = self.put(operation: 'regenerate_api_key')
75
84
  self.api_key = data[:data][:api_key]
@@ -115,9 +115,11 @@ module MnoEnterprise
115
115
  .max
116
116
  end
117
117
 
118
+ # Clear the record association cache
118
119
  def clear_association_cache
119
120
  self.class.associations[:has_many].each do |assoc|
120
121
  instance_variable_set(:"@_her_association_#{assoc[:name]}", nil)
122
+ attributes.delete(assoc[:name].to_s)
121
123
  end
122
124
  end
123
125
 
@@ -1,6 +1,6 @@
1
1
  # == Schema Information
2
2
  #
3
- # Endpoint:
3
+ # Endpoint:
4
4
  # - /v1/credit_cards
5
5
  # - /v1/organizations/:organization_id/credit_card
6
6
  #
@@ -27,14 +27,17 @@
27
27
 
28
28
  module MnoEnterprise
29
29
  class CreditCard < BaseResource
30
-
30
+
31
31
  attributes :id, :created_at, :updated_at, :title, :first_name, :last_name, :country, :masked_number, :number,
32
32
  :month, :year, :billing_address, :billing_city, :billing_postcode, :billing_country, :verification_value, :organization_id
33
-
33
+
34
34
  #==============================================================
35
35
  # Associations
36
36
  #==============================================================
37
37
  belongs_to :organization, class_name: 'MnoEnterprise::Organization'
38
-
38
+
39
+ def expiry_date
40
+ year && month && Date.new(year, month).end_of_month
41
+ end
39
42
  end
40
43
  end
@@ -38,7 +38,10 @@ module MnoEnterprise
38
38
  end
39
39
 
40
40
  def to_audit_event
41
- {name: name}
41
+ {
42
+ name: name,
43
+ organization_id: (owner_type == 'MnoEnterprise::Organization') ? owner_id : nil
44
+ }
42
45
  end
43
46
  end
44
47
  end
@@ -1,15 +1,21 @@
1
1
  module MnoEnterprise
2
2
  class Impac::Widget < BaseResource
3
3
 
4
- attributes :name, :width, :widget_category, :settings
5
-
6
- alias_attribute :endpoint, :widget_category
4
+ # TODO: remove :widget_category when mnohub migrated to new model
5
+ attributes :name, :width, :widget_category, :settings, :endpoint
7
6
 
8
7
  belongs_to :dashboard, class_name: 'MnoEnterprise::Impac::Dashboard'
9
8
  has_many :kpis, class_name: 'MnoEnterprise::Impac::Kpi'
10
9
 
11
10
  def to_audit_event
12
- {name: name}
11
+
12
+ if settings['organization_ids'].any?
13
+ organization = MnoEnterprise::Organization.find_by(uid: settings['organization_ids'].first)
14
+ { name: name, organization_id: organization.id }
15
+ else
16
+ { name: name }
17
+ end
18
+
13
19
  end
14
20
 
15
21
  end
@@ -29,23 +29,27 @@ module MnoEnterprise
29
29
  belongs_to :referrer, class_name: 'MnoEnterprise::User'
30
30
  belongs_to :organization, class_name: 'MnoEnterprise::Organization'
31
31
  belongs_to :team, class_name: 'MnoEnterprise::Team'
32
-
32
+
33
33
  # TODO: specs
34
34
  # Add the user to the organization and update the status of the invite
35
35
  # Add team
36
36
  def accept!(user = self.user)
37
37
  self.put(operation: 'accept', data: { user_id: user.id})
38
38
  end
39
-
39
+
40
40
  # TODO: specs
41
41
  def cancel!
42
42
  self.put(operation: 'cancel')
43
43
  end
44
-
44
+
45
45
  # TODO: specs
46
46
  # Check whether the invite is expired or not
47
47
  def expired?
48
48
  self.status != 'pending' || self.created_at < 3.days.ago
49
49
  end
50
+
51
+ def to_audit_event
52
+ self.attributes.slice(:team_id, :user_role, :user_email, :user_id, :referrer_id, :organization_id)
53
+ end
50
54
  end
51
55
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ # == Schema Information
3
+ #
4
+ # Endpoint:
5
+ # - /v1/app/:app_id/shared_entities
6
+ #
7
+ # id :integer not null, primary key
8
+ # nid :string
9
+ # name :string
10
+ # created_at :datetime not null
11
+ # updated_at :datetime not null
12
+
13
+ module MnoEnterprise
14
+ class SharedEntity < BaseResource
15
+ include MnoEnterprise::Concerns::Models::SharedEntity
16
+ end
17
+ end
@@ -54,9 +54,14 @@ module MnoEnterprise
54
54
  :api_key, :api_secret, :developer, :kpi_enabled, :external_id, :meta_data
55
55
 
56
56
  define_model_callbacks :validation #required by Devise
57
- devise :remote_authenticatable, :registerable, :recoverable, :rememberable,
57
+
58
+ devise_modules = [
59
+ :remote_authenticatable, :registerable, :recoverable, :rememberable,
58
60
  :trackable, :validatable, :lockable, :confirmable, :timeoutable, :password_expirable,
59
- :omniauthable, omniauth_providers: Devise.omniauth_providers
61
+ :omniauthable
62
+ ]
63
+ devise_modules.delete(:registerable) if Settings.try(:devise).try(:registration).try(:disabled)
64
+ devise(*devise_modules, omniauth_providers: Devise.omniauth_providers)
60
65
 
61
66
  #================================
62
67
  # Validation
@@ -1,5 +1,6 @@
1
1
  module MnoEnterprise
2
2
  class InvoicePdf
3
+ include MnoEnterprise::ImageHelper
3
4
  attr_reader :invoice, :pdf, :data
4
5
 
5
6
  # InvoicePdf requires to be initialized
@@ -41,7 +42,6 @@ module MnoEnterprise
41
42
  @data[:invoice_currency] = @invoice.price.currency_as_string
42
43
  @data[:invoice_currency_name] = @invoice.price.currency.name
43
44
  @data[:invoice_credit_paid] = @invoice.credit_paid
44
- @data[:invoice_total_due] = @invoice.total_due
45
45
  @data[:invoice_total_payable] = @invoice.total_payable
46
46
  @data[:invoice_tax_payable] = @invoice.tax_payable
47
47
  @data[:invoice_tax_pips] = (@invoice.tax_pips_applied || 0)
@@ -117,31 +117,21 @@ module MnoEnterprise
117
117
  }
118
118
  end
119
119
 
120
- # Helper method to easily access
121
- # images
122
- def image_path(name)
123
- path = "/app/assets/images/#{name}"
124
- engine_path = "#{MnoEnterprise::Engine.root}#{path}"
125
- app_path = "#{Rails.root}#{path}"
126
-
127
- File.exists?(app_path) ? app_path : engine_path
128
- end
129
-
130
120
  # Format a money object
131
121
  def money(m)
132
122
  "#{m.format(symbol: false)} #{m.currency_as_string}"
133
123
  end
134
124
 
135
-
136
125
  # Add a repeated header to the document
137
126
  def add_page_header
127
+ title = Settings.payment.disabled ? 'Account Statement - ' : 'Monthly Invoice - '
138
128
  @pdf.repeat :all do
139
129
  @pdf.bounding_box([0, @pdf.bounds.top+@format[:header_size]], width: 540, height: @format[:footer_size]) do
140
130
  @pdf.float do
141
- @pdf.image image_path('mno_enterprise/main-logo.png'), :fit => [135, (@format[:footer_size])]
131
+ @pdf.image main_logo_white_bg_path(true), scale: 0.5
142
132
  end
143
133
  @pdf.move_down 52
144
- @pdf.font_size(20) { @pdf.text "Monthly Invoice - #{@data[:period_month]}", style: :bold, align: :right }
134
+ @pdf.font_size(20) { @pdf.text "#{title} #{@data[:period_month]}", style: :bold, align: :right }
145
135
  end
146
136
  end
147
137
  end
@@ -156,7 +146,7 @@ module MnoEnterprise
156
146
  @pdf.move_down 10
157
147
  @pdf.font_size(8) do
158
148
  @pdf.text "<color rgb='999999'>Maestrano is a service of Maestrano Pty Ltd (ABN: 80 152 564 424),</color>", inline_format: true
159
- @pdf.text "<color rgb='999999'>Suite 102, 410 Elizabeth Street, Surry Hills 2010, Sydney, Australia.</color>", inline_format: true
149
+ @pdf.text "<color rgb='999999'>Suite 504, 46 Market Street, Sydney, NSW 2000, Australia.</color>", inline_format: true
160
150
  @pdf.text "<color rgb='999999'>All charges are in #{@data[:invoice_currency_name]} (#{@data[:invoice_currency]}).</color>", inline_format: true
161
151
  end
162
152
  end
@@ -179,6 +169,8 @@ module MnoEnterprise
179
169
  # This method is responsible for
180
170
  # generating the actual pdf content
181
171
  def add_page_body
172
+ payment_enabled = !Settings.payment.disabled
173
+
182
174
  @pdf.stroke_color '999999'
183
175
 
184
176
  #===============================
@@ -191,10 +183,10 @@ module MnoEnterprise
191
183
  @pdf.fill_color = original_color
192
184
 
193
185
  @pdf.text_box "Your Reference", at: [310,@pdf.cursor], width: 65, height: 13, align: :center, valign: :center,
194
- style: :bold_italic, size: 7
186
+ style: :bold_italic, size: 7
195
187
 
196
188
  @pdf.text_box @data[:invoice_reference], at: [310,@pdf.cursor], width: 230, height: 50, align: :center, valign: :center,
197
- style: :bold
189
+ style: :bold
198
190
  end
199
191
 
200
192
  #===============================
@@ -211,8 +203,6 @@ module MnoEnterprise
211
203
  @pdf.text "<color rgb='999999'>#{@data[:customer_billing_address]}</color>", align: :left, inline_format: true, style: :italic, size: 9
212
204
  end
213
205
 
214
-
215
-
216
206
  #===============================
217
207
  # Summary
218
208
  #===============================
@@ -221,9 +211,12 @@ module MnoEnterprise
221
211
  @pdf.stroke_horizontal_rule
222
212
  @pdf.move_down 10
223
213
 
214
+ summary_data_amount = @data[:invoice_price]
215
+ summary_data_amount = @data[:invoice_total_payable_with_tax] if payment_enabled
216
+
224
217
  summary_data = []
225
218
  summary_data << ['Period', 'Total Payable' + (@data[:invoice_tax_pips] > 0 ? "\n<font size='8'><i>(incl. GST)</i></font>" : '')]
226
- summary_data << ["#{@data[:period_started_at].strftime("%B, %e %Y")} to #{@data[:period_ended_at].strftime("%B, %e %Y")}",money(@data[:invoice_total_payable_with_tax])]
219
+ summary_data << ["#{@data[:period_started_at].strftime("%B, %e %Y")} to #{@data[:period_ended_at].strftime("%B, %e %Y")}",money(summary_data_amount)]
227
220
 
228
221
  # Draw Table background
229
222
  bg_height = @data[:invoice_tax_pips] > 0 ? 58 : 50
@@ -284,7 +277,7 @@ module MnoEnterprise
284
277
  @pdf.fill_color = original_color
285
278
 
286
279
  @pdf.text_box "Credit Remaining", at: [445,@pdf.cursor], width: 95, height: 23, align: :center, valign: :center,
287
- style: :bold, size: 10
280
+ style: :bold, size: 10
288
281
 
289
282
  @pdf.text_box money(@data[:customer_current_credit]), at: [445,@pdf.cursor], width: 95, height: 37, align: :center, valign: :bottom
290
283
  end
@@ -292,140 +285,79 @@ module MnoEnterprise
292
285
  @pdf.move_down 40
293
286
  end
294
287
 
295
- #========================()=======
296
- # Account Situation
297
- #===============================
298
- @pdf.move_down 30
299
- @pdf.font_size(20) { @pdf.text 'Account Situation', style: :bold }
300
- @pdf.stroke_horizontal_rule
301
- @pdf.move_down 10
302
-
303
- # Situation Data
304
- situation_data = []
305
- # Header
306
- situation_data << [
307
- '',
308
- '',
309
- 'Due Last Month',
310
- '',
311
- 'Paid (Thank You)',
312
- '',
313
- 'This Month',
314
- '',
315
- 'Credit',
316
- '',
317
- 'Total'
318
- ]
319
-
320
- #Content
321
- situation_data << [
322
- '',
323
- '',
324
- money(@data[:invoice_previous_total_due]),
325
- '-',
326
- money(@data[:invoice_previous_total_paid]),
327
- '+',
328
- money(@data[:invoice_price]),
329
- '-',
330
- money(@data[:invoice_credit_paid]),
331
- '=',
332
- money(@data[:invoice_total_payable])
333
- ]
334
-
335
- # Draw background
336
- @pdf.float do
337
- original_color = @pdf.fill_color
338
- @pdf.fill_color "F0F0F0"
339
- @pdf.fill_rounded_rectangle [0,@pdf.cursor], 540, 50, 5
340
- @pdf.fill_color = original_color
341
- end
342
-
343
-
344
- # Draw left background
345
- @pdf.float do
346
- original_color = @pdf.fill_color
347
- @pdf.fill_color "E0E0E0"
348
- @pdf.fill_rounded_rectangle [0,@pdf.cursor], 80, 50, 5
349
- @pdf.fill_color = original_color
350
- @pdf.move_down 21
351
- if @data[:invoice_tax_pips] > 0
352
- @pdf.text_box 'Excl. GST', at: [12,@pdf.cursor]
353
- else
354
- @pdf.text_box 'Details', at: [20,@pdf.cursor]
355
- end
356
- end
357
-
358
- # Draw table
359
- @pdf.table(situation_data) do |t|
360
- t.header = true
361
- t.width = 540
362
- t.column_widths = [75,18,75,18,75,18,75,18,75,18,75]
363
- t.row(0).font_style = :bold
364
- t.row(0).size = 8
365
- t.row(0).height = 22
366
- t.row(1).height = 25
367
-
368
- t.cell_style = {
369
- borders: [],
370
- overflow: :shrink_to_fit,
371
- align: :center
372
- }
373
-
374
- # Color the '+','-' and '=' characters
375
- t.cells.style do |c|
376
- if c.row == 1 && c.column.odd?
377
- c.text_color = "a8a8a8"
378
- end
379
- end
380
- end
381
-
382
-
383
- #=================================
384
- # Account Situation - Tax Section
385
- #=================================
386
- if @data[:invoice_tax_pips] > 0
387
-
388
- #-----------------
389
- # GST row
390
- #-----------------
391
- @pdf.move_down 8
392
-
393
- table_data = []
394
- table_data << [
288
+ if payment_enabled
289
+ #===============================
290
+ # Account Situation
291
+ #===============================
292
+ @pdf.move_down 30
293
+ @pdf.font_size(20) { @pdf.text 'Account Situation', style: :bold }
294
+ @pdf.stroke_horizontal_rule
295
+ @pdf.move_down 10
296
+
297
+ # Situation Data
298
+ situation_data = []
299
+ # Header
300
+ situation_data << [
395
301
  '',
396
302
  '',
303
+ 'Due Last Month',
397
304
  '',
305
+ 'Paid (Thank You)',
398
306
  '',
307
+ 'This Month',
399
308
  '',
309
+ 'Credit',
400
310
  '',
311
+ 'Total'
312
+ ]
313
+
314
+ #Content
315
+ situation_data << [
401
316
  '',
402
317
  '',
403
- 'GST',
318
+ money(@data[:invoice_previous_total_due]),
319
+ '-',
320
+ money(@data[:invoice_previous_total_paid]),
404
321
  '+',
405
- money(@data[:invoice_tax_payable]),
322
+ money(@data[:invoice_price]),
323
+ '-',
324
+ money(@data[:invoice_credit_paid]),
325
+ '=',
326
+ money(@data[:invoice_total_payable])
406
327
  ]
407
328
 
408
- # Draw table background
329
+ # Draw background
409
330
  @pdf.float do
410
331
  original_color = @pdf.fill_color
411
332
  @pdf.fill_color "F0F0F0"
412
- @pdf.fill_rounded_rectangle [368,@pdf.cursor], 172, 24, 5
333
+ @pdf.fill_rounded_rectangle [0,@pdf.cursor], 540, 50, 5
413
334
  @pdf.fill_color = original_color
414
335
  end
415
336
 
337
+
416
338
  # Draw left background
417
339
  @pdf.float do
418
340
  original_color = @pdf.fill_color
419
- @pdf.fill_color "FAB451"
420
- @pdf.fill_rounded_rectangle [368,@pdf.cursor], 80, 24, 5
341
+ @pdf.fill_color "E0E0E0"
342
+ @pdf.fill_rounded_rectangle [0,@pdf.cursor], 80, 50, 5
421
343
  @pdf.fill_color = original_color
344
+ @pdf.move_down 21
345
+ if @data[:invoice_tax_pips] > 0
346
+ @pdf.text_box 'Excl. GST', at: [12,@pdf.cursor]
347
+ else
348
+ @pdf.text_box 'Details', at: [20,@pdf.cursor]
349
+ end
422
350
  end
423
351
 
424
- @pdf.table(table_data) do |t|
352
+ # Draw table
353
+ @pdf.table(situation_data) do |t|
425
354
  t.header = true
426
355
  t.width = 540
427
356
  t.column_widths = [75,18,75,18,75,18,75,18,75,18,75]
428
- t.row(0).height = 25
357
+ t.row(0).font_style = :bold
358
+ t.row(0).size = 8
359
+ t.row(0).height = 22
360
+ t.row(1).height = 25
429
361
 
430
362
  t.cell_style = {
431
363
  borders: [],
@@ -435,73 +367,134 @@ module MnoEnterprise
435
367
 
436
368
  # Color the '+','-' and '=' characters
437
369
  t.cells.style do |c|
438
- if c.row == 0 && c.column.odd?
370
+ if c.row == 1 && c.column.odd?
439
371
  c.text_color = "a8a8a8"
440
372
  end
441
373
  end
442
374
  end
443
375
 
444
376
 
445
- #-----------------
446
- # Total (incl. GST)
447
- #-----------------
448
- @pdf.move_down 5
377
+ #=================================
378
+ # Account Situation - Tax Section
379
+ #=================================
380
+ if @data[:invoice_tax_pips] > 0
449
381
 
450
- table_data = []
451
- table_data << [
452
- '',
453
- '',
454
- '',
455
- '',
456
- '',
457
- '',
458
- '',
459
- '',
460
- 'Total (incl. GST)',
461
- '=',
462
- money(@data[:invoice_total_payable_with_tax]),
463
- ]
382
+ #-----------------
383
+ # GST row
384
+ #-----------------
385
+ @pdf.move_down 8
386
+
387
+ table_data = []
388
+ table_data << [
389
+ '',
390
+ '',
391
+ '',
392
+ '',
393
+ '',
394
+ '',
395
+ '',
396
+ '',
397
+ 'GST',
398
+ '+',
399
+ money(@data[:invoice_tax_payable]),
400
+ ]
401
+
402
+ # Draw table background
403
+ @pdf.float do
404
+ original_color = @pdf.fill_color
405
+ @pdf.fill_color "F0F0F0"
406
+ @pdf.fill_rounded_rectangle [368,@pdf.cursor], 172, 24, 5
407
+ @pdf.fill_color = original_color
408
+ end
464
409
 
465
- # Draw table background
466
- @pdf.float do
467
- original_color = @pdf.fill_color
468
- @pdf.fill_color "F0F0F0"
469
- @pdf.fill_rounded_rectangle [368,@pdf.cursor], 172, 24, 5
470
- @pdf.fill_color = original_color
471
- end
410
+ # Draw left background
411
+ @pdf.float do
412
+ original_color = @pdf.fill_color
413
+ @pdf.fill_color "FAB451"
414
+ @pdf.fill_rounded_rectangle [368,@pdf.cursor], 80, 24, 5
415
+ @pdf.fill_color = original_color
416
+ end
472
417
 
473
- # Draw left background
474
- @pdf.float do
475
- original_color = @pdf.fill_color
476
- @pdf.fill_color "DAE173"
477
- @pdf.fill_rounded_rectangle [368,@pdf.cursor], 80, 24, 5
478
- @pdf.fill_color = original_color
479
- end
418
+ @pdf.table(table_data) do |t|
419
+ t.header = true
420
+ t.width = 540
421
+ t.column_widths = [75,18,75,18,75,18,75,18,75,18,75]
422
+ t.row(0).height = 25
423
+
424
+ t.cell_style = {
425
+ borders: [],
426
+ overflow: :shrink_to_fit,
427
+ align: :center
428
+ }
429
+
430
+ # Color the '+','-' and '=' characters
431
+ t.cells.style do |c|
432
+ if c.row == 0 && c.column.odd?
433
+ c.text_color = "a8a8a8"
434
+ end
435
+ end
436
+ end
480
437
 
481
- @pdf.table(table_data) do |t|
482
- t.header = true
483
- t.width = 540
484
- t.row(0).font_style = :bold
485
- t.column_widths = [75,18,75,18,75,18,75,18,75,18,75]
486
- t.row(0).height = 25
487
438
 
488
- t.cell_style = {
489
- borders: [],
490
- overflow: :shrink_to_fit,
491
- align: :center
492
- }
439
+ #-----------------
440
+ # Total (incl. GST)
441
+ #-----------------
442
+ @pdf.move_down 5
443
+
444
+ table_data = []
445
+ table_data << [
446
+ '',
447
+ '',
448
+ '',
449
+ '',
450
+ '',
451
+ '',
452
+ '',
453
+ '',
454
+ 'Total (incl. GST)',
455
+ '=',
456
+ money(@data[:invoice_total_payable_with_tax]),
457
+ ]
458
+
459
+ # Draw table background
460
+ @pdf.float do
461
+ original_color = @pdf.fill_color
462
+ @pdf.fill_color "F0F0F0"
463
+ @pdf.fill_rounded_rectangle [368,@pdf.cursor], 172, 24, 5
464
+ @pdf.fill_color = original_color
465
+ end
493
466
 
494
- # Color the '+','-' and '=' characters
495
- t.cells.style do |c|
496
- if c.row == 0 && c.column.odd?
497
- c.text_color = "a8a8a8"
467
+ # Draw left background
468
+ @pdf.float do
469
+ original_color = @pdf.fill_color
470
+ @pdf.fill_color "DAE173"
471
+ @pdf.fill_rounded_rectangle [368,@pdf.cursor], 80, 24, 5
472
+ @pdf.fill_color = original_color
473
+ end
474
+
475
+ @pdf.table(table_data) do |t|
476
+ t.header = true
477
+ t.width = 540
478
+ t.row(0).font_style = :bold
479
+ t.column_widths = [75,18,75,18,75,18,75,18,75,18,75]
480
+ t.row(0).height = 25
481
+
482
+ t.cell_style = {
483
+ borders: [],
484
+ overflow: :shrink_to_fit,
485
+ align: :center
486
+ }
487
+
488
+ # Color the '+','-' and '=' characters
489
+ t.cells.style do |c|
490
+ if c.row == 0 && c.column.odd?
491
+ c.text_color = "a8a8a8"
492
+ end
498
493
  end
499
494
  end
500
495
  end
501
-
502
496
  end
503
497
 
504
-
505
498
  #===============================
506
499
  # Details
507
500
  #===============================
@@ -520,10 +513,10 @@ module MnoEnterprise
520
513
  t.row_colors = ["FFFFFF", "F0F0F0"]
521
514
  t.column_widths = [240,100,100,100]
522
515
  t.cell_style = { borders: [:bottom],
523
- border_width: 1,
524
- border_color: "999999",
525
- inline_format: true
526
- }
516
+ border_width: 1,
517
+ border_color: "999999",
518
+ inline_format: true
519
+ }
527
520
  t.row(0).borders = [:bottom]
528
521
  t.row(0).border_width = 2
529
522
  t.row(0).font_style = :bold