kaui 0.6.6 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/Gemfile.lock +51 -37
  4. data/README.md +5 -0
  5. data/Rakefile +1 -1
  6. data/app/controllers/kaui/account_emails_controller.rb +26 -44
  7. data/app/controllers/kaui/account_tags_controller.rb +26 -38
  8. data/app/controllers/kaui/account_timelines_controller.rb +47 -50
  9. data/app/controllers/kaui/accounts_controller.rb +68 -148
  10. data/app/controllers/kaui/bundle_tags_controller.rb +32 -21
  11. data/app/controllers/kaui/bundles_controller.rb +44 -69
  12. data/app/controllers/kaui/chargebacks_controller.rb +31 -61
  13. data/app/controllers/kaui/charges_controller.rb +19 -21
  14. data/app/controllers/kaui/credits_controller.rb +22 -36
  15. data/app/controllers/kaui/custom_fields_controller.rb +15 -13
  16. data/app/controllers/kaui/engine_controller.rb +8 -10
  17. data/app/controllers/kaui/invoice_items_controller.rb +24 -41
  18. data/app/controllers/kaui/invoices_controller.rb +36 -46
  19. data/app/controllers/kaui/payment_methods_controller.rb +84 -28
  20. data/app/controllers/kaui/payments_controller.rb +64 -26
  21. data/app/controllers/kaui/refunds_controller.rb +27 -107
  22. data/app/controllers/kaui/subscriptions_controller.rb +88 -132
  23. data/app/controllers/kaui/tag_definitions_controller.rb +32 -79
  24. data/app/controllers/kaui/tags_controller.rb +16 -14
  25. data/app/controllers/kaui/transactions_controller.rb +25 -0
  26. data/app/helpers/kaui/money_helper.rb +8 -0
  27. data/app/helpers/kaui/subscription_helper.rb +115 -0
  28. data/app/helpers/kaui/uuid_helper.rb +9 -0
  29. data/app/models/kaui/ability.rb +2 -2
  30. data/app/models/kaui/account.rb +25 -42
  31. data/app/models/kaui/account_email.rb +11 -48
  32. data/app/models/kaui/account_timeline.rb +1 -5
  33. data/app/models/kaui/audit_log.rb +1 -15
  34. data/app/models/kaui/base.rb +1 -126
  35. data/app/models/kaui/bundle.rb +47 -14
  36. data/app/models/kaui/catalog.rb +2 -0
  37. data/app/models/kaui/chargeback.rb +24 -36
  38. data/app/models/kaui/credit.rb +5 -20
  39. data/app/models/kaui/custom_field.rb +9 -5
  40. data/app/models/kaui/invoice.rb +9 -53
  41. data/app/models/kaui/invoice_item.rb +8 -18
  42. data/app/models/kaui/invoice_payment.rb +24 -0
  43. data/app/models/kaui/payment.rb +14 -32
  44. data/app/models/kaui/payment_method.rb +36 -0
  45. data/app/models/kaui/rails_methods.rb +7 -9
  46. data/app/models/kaui/refund.rb +5 -20
  47. data/app/models/kaui/subscription.rb +7 -27
  48. data/app/models/kaui/tag.rb +10 -6
  49. data/app/models/kaui/tag_definition.rb +26 -34
  50. data/app/models/kaui/transaction.rb +30 -0
  51. data/app/models/kaui/user.rb +2 -0
  52. data/app/views/kaui/account_emails/_form.html.erb +8 -28
  53. data/app/views/kaui/account_emails/show.html.erb +10 -10
  54. data/app/views/kaui/account_tags/_account_tags_table.html.erb +20 -18
  55. data/app/views/kaui/account_tags/_form.html.erb +42 -0
  56. data/app/views/kaui/account_tags/edit.html.erb +1 -41
  57. data/app/views/kaui/account_tags/show.html.erb +6 -3
  58. data/app/views/kaui/account_timelines/show.html.erb +273 -302
  59. data/app/views/kaui/accounts/_form.html.erb +116 -0
  60. data/app/views/kaui/accounts/index.html.erb +13 -11
  61. data/app/views/kaui/accounts/new.html.erb +5 -0
  62. data/app/views/kaui/accounts/show.html.erb +101 -99
  63. data/app/views/kaui/bundle_tags/_bundle_tags_table.html.erb +29 -9
  64. data/app/views/kaui/bundle_tags/_form.html.erb +41 -0
  65. data/app/views/kaui/bundle_tags/edit.html.erb +2 -34
  66. data/app/views/kaui/bundle_tags/show.html.erb +6 -0
  67. data/app/views/kaui/bundles/index.html.erb +9 -9
  68. data/app/views/kaui/bundles/show.html.erb +17 -15
  69. data/app/views/kaui/bundles/transfer.html.erb +25 -24
  70. data/app/views/kaui/chargebacks/_form.html.erb +44 -0
  71. data/app/views/kaui/chargebacks/new.html.erb +3 -115
  72. data/app/views/kaui/charges/_form.html.erb +73 -0
  73. data/app/views/kaui/charges/new.html.erb +2 -91
  74. data/app/views/kaui/credits/_form.html.erb +73 -0
  75. data/app/views/kaui/credits/new.html.erb +2 -85
  76. data/app/views/kaui/invoice_items/edit.html.erb +77 -78
  77. data/app/views/kaui/invoices/show.html.erb +3 -10
  78. data/app/views/kaui/layouts/kaui_application.html.erb +0 -2
  79. data/app/views/kaui/payment_methods/_form.html.erb +30 -0
  80. data/app/views/kaui/payment_methods/_new_creditcard_payment_method.html.erb +19 -18
  81. data/app/views/kaui/payment_methods/_payment_methods_table.html.erb +8 -5
  82. data/app/views/kaui/payment_methods/index.html.erb +10 -10
  83. data/app/views/kaui/payment_methods/new.html.erb +2 -20
  84. data/app/views/kaui/payment_methods/show.html.erb +2 -1
  85. data/app/views/kaui/payments/_payments_table.html.erb +30 -22
  86. data/app/views/kaui/payments/index.html.erb +1 -1
  87. data/app/views/kaui/payments/new.html.erb +5 -5
  88. data/app/views/kaui/payments/show.html.erb +3 -0
  89. data/app/views/kaui/refunds/new.html.erb +96 -104
  90. data/app/views/kaui/subscriptions/_form.html.erb +36 -0
  91. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +39 -44
  92. data/app/views/kaui/subscriptions/edit.html.erb +24 -35
  93. data/app/views/kaui/subscriptions/index.html.erb +13 -12
  94. data/app/views/kaui/subscriptions/new.html.erb +6 -43
  95. data/app/views/kaui/subscriptions/show.html.erb +32 -25
  96. data/app/views/kaui/tag_definitions/_form.html.erb +10 -37
  97. data/app/views/kaui/tag_definitions/index.html.erb +3 -5
  98. data/app/views/kaui/tag_definitions/show.html.erb +1 -2
  99. data/app/views/kaui/transactions/_form.html.erb +77 -0
  100. data/app/views/kaui/transactions/new.html.erb +3 -0
  101. data/config/initializers/kilbill-client-init.rb +1 -1
  102. data/config/routes.rb +4 -15
  103. data/kaui.gemspec +8 -6
  104. data/lib/kaui/engine.rb +4 -1
  105. data/lib/kaui/version.rb +1 -1
  106. data/lib/kaui.rb +2 -2
  107. data/test/functional/kaui/account_emails_controller_test.rb +28 -0
  108. data/test/functional/kaui/account_tags_controller_test.rb +29 -0
  109. data/test/functional/kaui/account_timelines_controller_test.rb +21 -0
  110. data/test/functional/kaui/accounts_controller_test.rb +56 -50
  111. data/test/functional/kaui/bundle_tags_controller_test.rb +29 -0
  112. data/test/functional/kaui/bundles_controller_test.rb +58 -13
  113. data/test/functional/kaui/chargebacks_controller_test.rb +16 -5
  114. data/test/functional/kaui/charges_controller_test.rb +39 -0
  115. data/test/functional/kaui/credits_controller_test.rb +35 -0
  116. data/test/functional/kaui/custom_fields_controller_test.rb +21 -0
  117. data/test/functional/kaui/functional_test_helper.rb +61 -0
  118. data/test/functional/kaui/invoice_items_controller_test.rb +24 -10
  119. data/test/functional/kaui/invoices_controller_test.rb +41 -13
  120. data/test/functional/kaui/payment_methods_controller_test.rb +49 -0
  121. data/test/functional/kaui/payments_controller_test.rb +32 -5
  122. data/test/functional/kaui/refunds_controller_test.rb +40 -5
  123. data/test/functional/kaui/subscriptions_controller_test.rb +82 -0
  124. data/test/functional/kaui/tag_definitions_controller_test.rb +27 -53
  125. data/test/functional/kaui/tags_controller_test.rb +21 -0
  126. data/test/functional/kaui/transactions_controller_test.rb +32 -0
  127. data/test/integration/kaui/integration_test_helper.rb +31 -0
  128. data/test/integration/kaui/navigation_test.rb +43 -0
  129. data/test/killbill_test_helper.rb +143 -0
  130. data/test/test_helper.rb +10 -227
  131. data/test/unit/kaui/account_email_test.rb +19 -0
  132. data/test/unit/kaui/account_test.rb +7 -35
  133. data/test/unit/kaui/base_test.rb +5 -46
  134. data/test/unit/kaui/date_helper_test.rb +6 -5
  135. data/test/unit/kaui/invoice_item_test.rb +5 -17
  136. data/test/unit/kaui/invoice_payment_test.rb +42 -0
  137. data/test/unit/kaui/invoice_test.rb +15 -15
  138. data/test/unit/kaui/money_helper_test.rb +10 -0
  139. data/test/unit/kaui/payment_test.rb +42 -0
  140. data/test/unit/kaui/tag_definition_test.rb +5 -28
  141. data/test/unit/kaui/uuid_helper_test.rb +10 -0
  142. metadata +134 -159
  143. data/app/controllers/kaui/analytics_controller.rb +0 -28
  144. data/app/helpers/kaui/killbill_helper.rb +0 -611
  145. data/app/models/kaui/analytics.rb +0 -19
  146. data/app/models/kaui/analytics_sanity.rb +0 -7
  147. data/app/models/kaui/business_account.rb +0 -12
  148. data/app/models/kaui/business_field.rb +0 -6
  149. data/app/models/kaui/business_invoice.rb +0 -31
  150. data/app/models/kaui/business_invoice_item.rb +0 -17
  151. data/app/models/kaui/business_invoice_payment.rb +0 -25
  152. data/app/models/kaui/business_overdue_status.rb +0 -8
  153. data/app/models/kaui/business_snapshot.rb +0 -9
  154. data/app/models/kaui/business_subscription_transition.rb +0 -53
  155. data/app/models/kaui/business_tag.rb +0 -5
  156. data/app/models/kaui/charge.rb +0 -14
  157. data/app/models/kaui/entitlement.rb +0 -2
  158. data/app/models/kaui/event.rb +0 -13
  159. data/app/models/kaui/external_payment.rb +0 -15
  160. data/app/models/kaui/overdue_state.rb +0 -10
  161. data/app/models/kaui/payment_attempt.rb +0 -27
  162. data/app/models/kaui/product.rb +0 -24
  163. data/app/models/kaui/time_series_data.rb +0 -8
  164. data/app/views/kaui/analytics/account_snapshot.html.erb +0 -211
  165. data/app/views/kaui/analytics/index.html.erb +0 -17
  166. data/app/views/kaui/chargebacks/index.html.erb +0 -14
  167. data/app/views/kaui/chargebacks/show.html.erb +0 -19
  168. data/app/views/kaui/credits/index.html.erb +0 -14
  169. data/app/views/kaui/credits/show.html.erb +0 -19
  170. data/app/views/kaui/invoice_items/index.html.erb +0 -20
  171. data/app/views/kaui/invoice_items/show.html.erb +0 -31
  172. data/app/views/kaui/refunds/_refunds_table.html.erb +0 -31
  173. data/app/views/kaui/refunds/index.html.erb +0 -43
  174. data/app/views/kaui/refunds/show.html.erb +0 -33
  175. data/app/views/kaui/tag_definitions/edit.html.erb +0 -3
  176. data/test/dummy/test/fixtures/accounts.yml +0 -32
  177. data/test/dummy/test/fixtures/bill_cycle_days.yml +0 -3
  178. data/test/dummy/test/fixtures/bundles.yml +0 -4
  179. data/test/dummy/test/fixtures/invoice_items.yml +0 -13
  180. data/test/dummy/test/fixtures/invoices.yml +0 -11
  181. data/test/dummy/test/fixtures/overdue_states.yml +0 -8
  182. data/test/dummy/test/fixtures/payment_methods.yml +0 -5
  183. data/test/dummy/test/fixtures/plugin_info_properties.yml +0 -59
  184. data/test/dummy/test/fixtures/plugin_infos.yml +0 -2
  185. data/test/dummy/test/fixtures/refunds.yml +0 -9
  186. data/test/dummy/test/fixtures/tag_definitions.yml +0 -20
  187. data/test/functional/kaui/account_timeline_controller_test.rb +0 -9
  188. data/test/functional/kaui/extpayments_controller_test.rb +0 -9
  189. data/test/functional/kaui/home_controller_test.rb +0 -11
  190. data/test/integration/navigation_test.rb +0 -10
  191. data/test/kaui_test.rb +0 -7
  192. data/test/unit/helpers/kaui/account_timeline_helper_test.rb +0 -6
  193. data/test/unit/helpers/kaui/bundles_helper_test.rb +0 -6
  194. data/test/unit/helpers/kaui/chargebacks_helper_test.rb +0 -6
  195. data/test/unit/helpers/kaui/extpayments_helper_test.rb +0 -6
  196. data/test/unit/helpers/kaui/home_helper_test.rb +0 -6
  197. data/test/unit/helpers/kaui/invoices_helper_test.rb +0 -6
  198. data/test/unit/helpers/kaui/payments_helper_test.rb +0 -6
  199. data/test/unit/helpers/kaui/refunds_helper_test.rb +0 -6
  200. data/test/unit/kaui/overdue_state_test.rb +0 -18
  201. data/test/unit/kaui/refund_test.rb +0 -20
  202. data/test/unit/model_test.rb +0 -151
@@ -5,440 +5,411 @@
5
5
  <form class="form-horizontal">
6
6
  <div class="control-group">
7
7
  <label for="bundles" class="control-label">Filter by bundle name</label>
8
+
8
9
  <div class="controls">
9
- <%= select_tag "bundles", options_for_select([ "" ] + @bundle_names.values.sort, @selected_bundle || 'all') %>
10
+ <%= select_tag 'bundles', options_for_select([''] + @bundle_names.values.sort, @selected_bundle || 'all') %>
10
11
  </div>
11
12
 
12
13
  <label for="events" class="control-label">Filter by event type</label>
14
+
13
15
  <div class="controls">
14
- <%= select_tag "event_types", options_for_select('<option value="all">ALL</option><option value="invoice">INVOICE</option><option value="payment">PAYMENT</option><option value="refund">REFUND</option><option value="chargeback">CHARGEBACK</option><option value="entitlement">ENTITLEMENTS</option>'.html_safe) %>
16
+ <%= select_tag 'event_types', options_for_select('<option value="all">ALL</option><option value="invoice">INVOICE</option><option value="payment">PAYMENT</option><option value="entitlement">ENTITLEMENTS</option>'.html_safe) %>
15
17
  </div>
16
18
 
17
19
  <dl class="dl-horizontal">
18
20
  <dt>Billing timezone:</dt>
19
- <dd><%= @account.timezone %></dd>
21
+ <dd><%= @account.time_zone %></dd>
20
22
  </dl>
21
23
  </div>
22
24
  </form>
23
25
  <hr/>
24
26
  <table id="timeline-table" class="table table-condensed">
25
- <thead>
26
- <tr>
27
- <th>Requested Date</th>
28
- <th>Effective Date</th>
29
- <th>Bundle Name</th>
30
- <th>Event Type</th>
31
- <th>Details</th>
32
- <th>Reason Code / Comments</th>
33
- <th>Actions</th>
34
- </tr>
35
- </thead>
36
- <tbody>
37
- <% if @account.present? && @timeline.present? %>
38
- <% @timeline.invoices.each do |invoice_stub| %>
27
+ <thead>
28
+ <tr>
29
+ <th>Requested Date</th>
30
+ <th>Effective Date</th>
31
+ <th>Bundle Name</th>
32
+ <th>Event Type</th>
33
+ <th>Details</th>
34
+ <th>Reason Code / Comments</th>
35
+ <th>Actions</th>
36
+ </tr>
37
+ </thead>
38
+ <tbody>
39
+ <% if @account.present? && @timeline.present? %>
40
+ <% @timeline.invoices.each do |invoice_stub| %>
39
41
  <% if invoice_stub.bundle_keys.present? %>
40
- <% bundles = invoice_stub.bundle_keys.split(",").map {|bundle_key| @bundle_names[bundle_key] }.join(",") %>
42
+ <% bundles = invoice_stub.bundle_keys.split(',').map { |bundle_key| @bundle_names[bundle_key] }.join(',') %>
41
43
  <% end %>
42
44
  <% if invoice_stub.invoice_id.present? && @invoices_by_id.has_key?(invoice_stub.invoice_id) %>
43
- <% invoice = @invoices_by_id[invoice_stub.invoice_id] %>
45
+ <% invoice = @invoices_by_id[invoice_stub.invoice_id] %>
44
46
  <% else %>
45
- <% invoice = invoice_stub %>
47
+ <% invoice = invoice_stub %>
46
48
  <% end %>
47
49
  <tr title="<%= bundles %>" data-event_type="INVOICE">
48
50
  <td>
49
51
  <% if invoice.invoice_date.present? %>
50
- <%= invoice.invoice_date %>
52
+ <%= invoice.invoice_date %>
51
53
  <% else %>
52
- [unknown]
54
+ [unknown]
53
55
  <% end %>
54
56
  </td>
55
57
  <td>
56
58
  <% if invoice.target_date.present? %>
57
- <%= invoice.target_date %>
59
+ <%= invoice.target_date %>
58
60
  <% else %>
59
- [unknown]
61
+ [unknown]
60
62
  <% end %>
61
63
  </td>
62
64
  <td>
63
65
  <% if invoice_stub.bundle_keys.present? %>
64
- <% invoice_stub.bundle_keys.split(",").each do |bundle_key| %>
65
- <%= link_to @bundle_names[bundle_key], Kaui.bundle_home_path.call(bundle_key) %><br/>
66
- <% end %>
66
+ <% invoice_stub.bundle_keys.split(',').each do |bundle_key| %>
67
+ <%= link_to @bundle_names[bundle_key], Kaui.bundle_home_path.call(bundle_key) %>
68
+ <br/>
69
+ <% end %>
67
70
  <% end %>
68
71
  </td>
69
- <td><%= "INVOICE" %></td>
72
+ <td><%= 'INVOICE' %></td>
70
73
  <td><span class="hide" title="<%= invoice.invoice_number %>"></span>
71
- <%= "Amount:" %> <%= humanized_money_with_symbol Kaui::Base.to_money(invoice.amount, @account.currency) %> (<%= @account.currency %>)<br/>
72
- <%= "Balance:" %> <%= humanized_money_with_symbol Kaui::Base.to_money(invoice.balance, @account.currency) %> (<%= @account.currency %>)<br/>
73
- <% if invoice.credit_adj.present? && invoice.credit_adj > 0 %>
74
- <%= "Credit adjustment:" %> <%= humanized_money_with_symbol Kaui::Base.to_money(invoice.credit_adj, @account.currency) %> (<%= @account.currency %>)<br/>
75
- <% end %>
76
- <% if invoice.credits.present? && invoice.credits > 0 %>
77
- <%= "Credit balance adjustment:" %> <%= humanized_money_with_symbol Kaui::Base.to_money(invoice.credits, @account.currency) %> (<%= @account.currency %>)<br/>
78
- <% end %>
79
- <% if invoice.refund_adj.present? && invoice.refund_adj < 0 %>
80
- <%= "Refund adjustment:" %> <%= humanized_money_with_symbol Kaui::Base.to_money(invoice.refund_adj, @account.currency) %> (<%= @account.currency %>)<br/>
81
- <% end %>
82
- <%= "Invoice #" %>
83
- <%= link_to invoice.invoice_number, invoice_path(:id => invoice.invoice_id) %>
74
+ <%= 'Amount:' %> <%= humanized_money_with_symbol invoice.amount_to_money %>
75
+ (<%= @account.currency %>)<br/>
76
+ <%= 'Balance:' %> <%= humanized_money_with_symbol invoice.balance_to_money %>
77
+ (<%= @account.currency %>)<br/>
78
+ <% if invoice.credit_adj.present? && invoice.credit_adj > 0 %>
79
+ <%= 'Credit adjustment:' %> <%= humanized_money_with_symbol invoice.credit_adjustment_to_money %>
80
+ (<%= @account.currency %>)<br/>
81
+ <% end %>
82
+ <% if invoice.credits.present? && invoice.credits > 0 %>
83
+ <%= 'Credit balance adjustment:' %> <%= humanized_money_with_symbol invoice.credits_to_money %>
84
+ (<%= @account.currency %>)<br/>
85
+ <% end %>
86
+ <% if invoice.refund_adj.present? && invoice.refund_adj < 0 %>
87
+ <%= 'Refund adjustment:' %> <%= humanized_money_with_symbol invoice.refund_adjustment_to_money %>
88
+ (<%= @account.currency %>)<br/>
89
+ <% end %>
90
+ <%= 'Invoice #' %>
91
+ <%= link_to invoice.invoice_number, invoice_path(:id => invoice.invoice_id) %>
84
92
  </td>
85
93
  <td>
86
94
  <% if invoice_stub.audit_logs.present? %>
87
- <% invoice_stub.audit_logs.each do |entry| %>
88
- <%= Kaui::AuditLog.description(entry) unless entry.changed_by == 'Transition' %><br/>
89
- <% end %>
95
+ <% invoice_stub.audit_logs.each do |entry| %>
96
+ <%= Kaui::AuditLog.description(entry) unless entry.changed_by == 'Transition' %>
97
+ <br/>
98
+ <% end %>
90
99
  <% end %>
91
100
  </td>
92
101
  <td>
93
102
  <nobr>
94
- <%= link_to "Payment",
95
- kaui_engine.new_payment_path(:params => { :account_id => invoice.account_id,
96
- :invoice_id => invoice.invoice_id }),
97
- :class => "btn btn-mini #{"disabled" unless invoice.balance > 0}" %>
103
+ <%= link_to 'Payment',
104
+ kaui_engine.new_payment_path(:params => {:account_id => invoice.account_id,
105
+ :invoice_id => invoice.invoice_id}),
106
+ :class => "btn btn-mini #{'disabled' unless invoice.balance > 0}" %>
98
107
  </nobr>
99
108
  <% if can? :credit, Kaui::Invoice %>
100
- <nobr>
101
- <%= link_to "Credit",
102
- kaui_engine.new_credit_path(:params => { :account_id => invoice.account_id,
103
- :invoice_id => invoice.invoice_id }),
104
- :class => "btn btn-mini" %>
105
- </nobr>
109
+ <nobr>
110
+ <%= link_to 'Credit',
111
+ kaui_engine.new_credit_path(:params => {:account_id => invoice.account_id,
112
+ :invoice_id => invoice.invoice_id}),
113
+ :class => 'btn btn-mini' %>
114
+ </nobr>
106
115
  <% end %>
107
116
  <% if can? :charge, Kaui::Invoice %>
108
- <nobr>
109
- <%= link_to "Charge",
110
- kaui_engine.new_charge_path(:params => { :account_id => invoice.account_id,
111
- :invoice_id => invoice.invoice_id }),
112
- :class => "btn btn-mini" %>
113
- </nobr>
117
+ <nobr>
118
+ <%= link_to 'Charge',
119
+ kaui_engine.new_charge_path(:params => {:account_id => invoice.account_id,
120
+ :invoice_id => invoice.invoice_id}),
121
+ :class => 'btn btn-mini' %>
122
+ </nobr>
114
123
  <% end %>
115
124
  </td>
116
125
  </tr>
117
- <% end %>
118
- <% @timeline.payments.each do |payment| %>
119
- <% payment.refunds.each do |refund| %>
120
- <% bundles = payment.bundle_keys.split(",").map {|bundle_key| @bundle_names[bundle_key] }.join(",") %>
121
- <tr title="<%= bundles %>" data-event_type="REFUND">
122
- <td>
123
- <% if refund.requested_date.present? %>
124
- <%= format_date(refund.requested_date, @account.timezone).html_safe %>
125
- <% else %>
126
- [unknown]
127
- <% end %>
128
- </td>
129
- <td>
130
- <% if refund.effective_date.present? %>
131
- <%= format_date(refund.effective_date, @account.timezone).html_safe %>
132
- <% else %>
133
- [unknown]
134
- <% end %>
135
- </td>
136
- <td>
137
- <% payment.bundle_keys.split(",").each do |bundle_key| %>
138
- <%= link_to @bundle_names[bundle_key], Kaui.bundle_home_path.call(bundle_key) %><br/>
139
- <% end %>
140
- </td>
141
- <td><%= "REFUND" %></td>
142
- <td>
143
- <%= "Adjusted:" %> <% if refund.adjusted %>yes<% else %>no<% end %><br/>
144
- <%= "Payment id:" %> <%= refund.payment_id %><br/>
145
- <%= "Refund Amount:" %> <%= humanized_money_with_symbol Kaui::Base.to_money(refund.amount, refund.currency) %> (<%= refund.currency %>)<br/>
146
- <span <% if refund.status != 'COMPLETED' %>class="alert-error" <% else %>class="alert-success" <% end %>>
147
- <%= refund.status %>
148
- </span>
149
- <br/>
150
- </td>
151
- <td>
152
- <% if refund.audit_logs.present? %>
153
- <%= Kaui::AuditLog.description(refund.audit_logs[0])%><br/>
154
- <% end %>
155
- </td>
156
- <td></td>
157
- </tr>
158
- <% end %>
159
- <% end %>
160
- <% @timeline.payments.each do |payment| %>
161
- <% payment.chargebacks.each do |chargeback| %>
162
- <% bundles = payment.bundle_keys.split(",").map {|bundle_key| @bundle_names[bundle_key] }.join(",") %>
163
- <tr title="<%= bundles %>" data-event_type="CHARGEBACK">
164
- <td>
165
- <% if chargeback.effective_date.present? %>
166
- <%= format_date(chargeback.effective_date, @account.timezone).html_safe %>
167
- <% else %>
168
- [unknown]
169
- <% end %>
170
- </td>
171
- <td>
172
- <% if chargeback.effective_date.present? %>
173
- <%= format_date(chargeback.effective_date, @account.timezone).html_safe %>
174
- <% else %>
175
- [unknown]
176
- <% end %>
177
- </td>
178
- <td>
179
- <% payment.bundle_keys.split(",").each do |bundle_key| %>
180
- <%= link_to @bundle_names[bundle_key], Kaui.bundle_home_path.call(bundle_key) %><br/>
181
- <% end %>
182
- </td>
183
- <td><%= "CHARGEBACK" %></td>
184
- <td>
185
- <%= "Payment id:" %> <%= chargeback.payment_id %><br/>
186
- <%= "Chargeback Amount:" %> <%= humanized_money_with_symbol Kaui::Base.to_money(chargeback.amount, payment.currency) %> (<%= payment.currency %>)<br/>
187
- </td>
188
- <td>
189
- <% if chargeback.audit_logs.present? %>
190
- <%= Kaui::AuditLog.description(chargeback.audit_logs[0]) %><br/>
191
- <% end %>
192
- </td>
193
- <td></td>
194
- <% end %>
195
- <% end %>
196
- <% @timeline.payments.each do |payment| %>
197
- <% if payment.bundle_keys.present? %>
198
- <% bundles = payment.bundle_keys.split(",").map {|bundle_key| @bundle_names[bundle_key] }.join(",") %>
199
- <% end %>
200
- <% if payment.invoice_id.present? %>
201
- <% invoice = @invoices_by_id[payment.invoice_id] %>
126
+ <% end %>
127
+ <% @timeline.payments.each do |payment| %>
128
+ <% if payment.target_invoice_id.present? %>
129
+ <% bundles = @bundle_names_by_invoice_id[payment.target_invoice_id].to_a.join(',') %>
130
+ <% invoice = @invoices_by_id[payment.target_invoice_id] %>
202
131
  <% else %>
203
- <% invoice = nil %>
132
+ <% bundles = nil %>
133
+ <% invoice = nil %>
204
134
  <% end %>
205
- <tr title="<%= bundles %>" data-event_type="PAYMENT">
206
- <td>
207
- <% if payment.requested_date.present? %>
208
- <%= format_date(payment.requested_date, @account.timezone).html_safe %>
209
- <% else %>
210
- [unknown]
211
- <% end %>
212
- </td>
213
- <td>
214
- <% if payment.effective_date.present? %>
215
- <%= format_date(payment.effective_date, @account.timezone).html_safe %>
216
- <% else %>
217
- [unknown]
218
- <% end %>
219
- </td>
220
- <td>
221
- <% payment.bundle_keys.split(",").each do |bundle_key| %>
222
- <%= link_to @bundle_names[bundle_key], Kaui.bundle_home_path.call(bundle_key) %><br/>
223
- <% end %>
224
- </td>
225
- <td><%= "PAYMENT" %></td>
226
- <td>
227
- <span class="hide" title="<%= invoice.invoice_number %>"></span>
228
- <%= "Payment id:" %> <%= payment.payment_id %><br/>
229
- <%= "Total amount:" %> <%= humanized_money_with_symbol Kaui::Base.to_money(payment.amount, payment.currency) %> (<%= payment.currency %>)<br/>
230
- <%= "Paid amount:" %> <%= humanized_money_with_symbol Kaui::Base.to_money(payment.paid_amount, payment.currency) %> (<%= payment.currency %>)<br/>
231
- <span <% if payment.status == 'FAILED' %>class="alert-error" <% elsif payment.status == 'SUCCESS' %>class="alert-success" <% end %>>
232
- <%= payment.status %>
233
- </span>
234
- <br/>
235
- <%= "Invoice #" %> <%= link_to invoice.invoice_number, invoice_path(:id => invoice.invoice_id) %>
236
- </td>
237
- <td>
238
- <% if payment.audit_logs.present? %>
239
- <% payment.audit_logs.each do |entry| %>
240
- <%= Kaui::AuditLog.description(entry) unless entry.changed_by == 'PaymentRequestProcessor' %><br/>
241
- <% end %>
242
- <% end %>
243
- </td>
244
- <td>
245
- <% if can? :refund, Kaui::Payment %>
246
- <nobr>
247
- <%= link_to 'Refund', kaui_engine.new_refund_path(:params => { :payment_id => payment.payment_id,
248
- :account_id => @account.account_id,
249
- :invoice_id => payment.invoice_id }),
250
- :class => "btn btn-mini #{"disabled" unless payment.payment_id.present? and payment.status == 'SUCCESS' and payment.paid_amount != 0}" %>
251
- </nobr>
252
- <% end %>
253
- <% if can? :chargeback, Kaui::Payment %>
254
- <nobr>
255
- <%= link_to 'Chargeback', kaui_engine.new_chargeback_path(:params => { :payment_id => payment.payment_id,
256
- :account_id => @account.account_id,
257
- :invoice_id => payment.invoice_id }),
258
- :class => "btn btn-mini #{"disabled" unless payment.payment_id.present? and payment.status == 'SUCCESS'}" %>
259
- </nobr>
260
- <% end %>
261
- </td>
262
- </tr>
263
- <% end %>
264
- <% @timeline.bundles.each do |bundle| %>
265
- <% bundle.subscriptions.each do |sub| %>
266
- <% sub.events.each do |event| %>
267
- <!-- SKIP SERVICE_STATE_CHANGE -->
268
- <% next if event.event_type == 'SERVICE_STATE_CHANGE' %>
269
- <tr title="<%= @bundle_names[bundle.external_key] %>" data-event_type="<%= event.event_type %>">
135
+ <% payment.transactions.each do |transaction| %>
136
+ <tr title="<%= bundles %>" data-event_type="PAYMENT">
270
137
  <td>
271
- <% if event.requested_date.present? %>
272
- <%= format_date(event.requested_date, @account.timezone).html_safe %>
138
+ <% if transaction.effective_date.present? %>
139
+ <%= format_date(transaction.effective_date, @account.time_zone).html_safe %>
273
140
  <% else %>
274
- [unknown]
141
+ [unknown]
275
142
  <% end %>
276
143
  </td>
277
144
  <td>
278
- <% if event.effective_date.present? %>
279
- <%= format_date(event.effective_date, @account.timezone).html_safe %>
145
+ <% if transaction.effective_date.present? %>
146
+ <%= format_date(transaction.effective_date, @account.time_zone).html_safe %>
280
147
  <% else %>
281
- [unknown]
148
+ [unknown]
149
+ <% end %>
150
+ </td>
151
+ <td>
152
+ <% (@bundle_keys_by_invoice_id[payment.target_invoice_id] || []).each do |bundle_key| %>
153
+ <%= link_to @bundle_names[bundle_key], Kaui.bundle_home_path.call(bundle_key) %>
154
+ <br/>
155
+ <% end %>
156
+ </td>
157
+ <td><%= transaction.transaction_type %></td>
158
+ <td>
159
+ <span class="hide" title="<%= invoice.invoice_number unless invoice.nil? %>"></span>
160
+ <%= 'Transaction id:' %> <%= truncate_uuid(transaction.transaction_id) %>
161
+ <br/>
162
+ <%= 'Amount:' %> <%= humanized_money_with_symbol Kaui::Transaction.amount_to_money(transaction) %>
163
+ (<%= transaction.currency %>)<br/>
164
+ <span
165
+ <% if transaction.status == 'FAILED' %>class="alert-error"
166
+ <% elsif transaction.status == 'SUCCESS' %>class="alert-success" <% end %>>
167
+ <%= transaction.status %>
168
+ </span>
169
+ <br/>
170
+ <%= 'Payment #' %> <%= link_to payment.payment_number, payment_path(:id => payment.payment_id) %>
171
+ <% unless invoice.nil? %>
172
+ <br/><%= 'Invoice #' %> <%= link_to invoice.invoice_number, invoice_path(:id => invoice.invoice_id) %>
282
173
  <% end %>
283
174
  </td>
284
175
  <td>
285
- <%= link_to @bundle_names[bundle.external_key], Kaui.bundle_home_path.call(bundle.external_key) %><br/>
176
+ <% if transaction.audit_logs.present? %>
177
+ <% transaction.audit_logs.each do |entry| %>
178
+ <%= Kaui::AuditLog.description(entry) unless entry.changed_by == 'PaymentRequestProcessor' %>
179
+ <br/>
180
+ <% end %>
181
+ <% end %>
286
182
  </td>
287
- <td><%= event.event_type %></td>
288
- <td><span class="hide" title="<%= sub.product_category %>"></span><%= event.product %> <%= event.billing_period == 'NO_BILLING_PERIOD' || event.billing_period.nil? ? "" : event.billing_period.downcase.capitalize %> <%= event.phase.downcase.capitalize if event.phase.present? %></td>
289
183
  <td>
290
- <% if event.audit_logs.present? %>
291
- <% event.audit_logs.each do |entry| %>
292
- <%= Kaui::AuditLog.description(entry) %><br/>
293
- <% end %>
184
+ <% if invoice.present? and %w(CAPTURE PURCHASE).include?(transaction.transaction_type) %>
185
+ <% if can? :refund, Kaui::Payment %>
186
+ <nobr>
187
+ <%= link_to 'Refund', kaui_engine.new_refund_path(:params => {:payment_id => payment.payment_id,
188
+ :account_id => @account.account_id,
189
+ :invoice_id => payment.target_invoice_id}),
190
+ :class => "btn btn-mini #{'disabled' unless payment.payment_id.present? and transaction.status == 'SUCCESS' }" %>
191
+ </nobr>
192
+ <% end %>
193
+ <% if can? :chargeback, Kaui::Payment %>
194
+ <nobr>
195
+ <%= link_to 'Chargeback', kaui_engine.new_chargeback_path(:params => {:payment_id => payment.payment_id,
196
+ :account_id => @account.account_id,
197
+ :invoice_id => payment.target_invoice_id}),
198
+ :class => "btn btn-mini #{'disabled' unless payment.payment_id.present? and transaction.status == 'SUCCESS'}" %>
199
+ </nobr>
200
+ <% end %>
201
+ <% elsif !invoice.present? %>
202
+ <% if transaction.transaction_type == 'AUTHORIZE' %>
203
+ <% %w(CAPTURE VOID).each do |transaction_type| %>
204
+ <nobr>
205
+ <%= link_to transaction_type.downcase.capitalize, kaui_engine.new_transaction_path(:account_id => payment.account_id,
206
+ :payment_id => transaction.payment_id,
207
+ :payment_method_id => payment.payment_method_id,
208
+ :amount => transaction.amount,
209
+ :currency => transaction.currency,
210
+ :transaction_type => transaction_type), :class => 'btn btn-mini' %>
211
+ </nobr>
212
+ <% end %>
213
+ <% elsif %w(CAPTURE PURCHASE).include?(transaction.transaction_type) %>
214
+ <% %w(REFUND CHARGEBACK).each do |transaction_type| %>
215
+ <nobr>
216
+ <%= link_to transaction_type.downcase.capitalize, kaui_engine.new_transaction_path(:account_id => payment.account_id,
217
+ :payment_id => transaction.payment_id,
218
+ :payment_method_id => payment.payment_method_id,
219
+ :amount => transaction.amount,
220
+ :currency => transaction.currency,
221
+ :transaction_type => transaction_type), :class => 'btn btn-mini' %>
222
+ </nobr>
223
+ <% end %>
224
+ <% end %>
294
225
  <% end %>
295
226
  </td>
296
- <td> </td>
297
227
  </tr>
298
- <% end %>
299
228
  <% end %>
300
- <% end %>
301
229
  <% end %>
302
- </tbody>
230
+ <% @timeline.bundles.each do |bundle| %>
231
+ <% bundle.subscriptions.each do |sub| %>
232
+ <% sub.events.each do |event| %>
233
+ <!-- SKIP SERVICE_STATE_CHANGE -->
234
+ <% next if event.event_type == 'SERVICE_STATE_CHANGE' %>
235
+ <tr title="<%= @bundle_names[bundle.external_key] %>" data-event_type="<%= event.event_type %>">
236
+ <td>
237
+ <% if event.requested_date.present? %>
238
+ <%= format_date(event.requested_date, @account.time_zone).html_safe %>
239
+ <% else %>
240
+ [unknown]
241
+ <% end %>
242
+ </td>
243
+ <td>
244
+ <% if event.effective_date.present? %>
245
+ <%= format_date(event.effective_date, @account.time_zone).html_safe %>
246
+ <% else %>
247
+ [unknown]
248
+ <% end %>
249
+ </td>
250
+ <td>
251
+ <%= link_to @bundle_names[bundle.external_key], Kaui.bundle_home_path.call(bundle.external_key) %>
252
+ <br/>
253
+ </td>
254
+ <td><%= event.event_type %></td>
255
+ <td>
256
+ <span class="hide" title="<%= sub.product_category %>"></span><%= event.product %> <%= event.billing_period == 'NO_BILLING_PERIOD' || event.billing_period.nil? ? '' : event.billing_period.downcase.capitalize %> <%= event.phase.downcase.capitalize if event.phase.present? %>
257
+ </td>
258
+ <td>
259
+ <% if event.audit_logs.present? %>
260
+ <% event.audit_logs.each do |entry| %>
261
+ <%= Kaui::AuditLog.description(entry) %>
262
+ <br/>
263
+ <% end %>
264
+ <% end %>
265
+ </td>
266
+ <td></td>
267
+ </tr>
268
+ <% end %>
269
+ <% end %>
270
+ <% end %>
271
+ <% end %>
272
+ </tbody>
303
273
  </table>
304
274
  <div class="form-actions">
305
275
  <%= link_to 'Back', :back, :class => 'btn' %>
306
276
  </div>
307
277
  <%= javascript_tag do %>
308
- function disableLinks() {
278
+ function disableLinks() {
309
279
  $('a.btn.disabled').click(function (e) {
310
- e.preventDefault();
280
+ e.preventDefault();
311
281
  });
312
- }
282
+ }
313
283
 
314
- eventsOrder = ["START_ENTITLEMENT", "START_BILLING", "PAUSE_ENTITLEMENT", "PAUSE_BILLING", "RESUME_ENTITLEMENT", "RESUME_BILLING", "PHASE", "CHANGE", "STOP_ENTITLEMENT", "STOP_BILLING", "INVOICE", "PAYMENT", "REFUND", "CHARGEBACK"];
284
+ eventsOrder = ["START_ENTITLEMENT", "START_BILLING", "PAUSE_ENTITLEMENT", "PAUSE_BILLING", "RESUME_ENTITLEMENT",
285
+ "RESUME_BILLING", "PHASE", "CHANGE", "STOP_ENTITLEMENT", "STOP_BILLING", "INVOICE", "PAYMENT"];
315
286
 
316
- jQuery.fn.dataTableExt.oSort['timeline-event-asc'] = function(e1,e2) {
287
+ jQuery.fn.dataTableExt.oSort['timeline-event-asc'] = function(e1,e2) {
317
288
  var x = eventsOrder.indexOf(e1);
318
289
  var y = eventsOrder.indexOf(e2);
319
- return ((x < y) ? -1 : ((x > y) ? 1 : 0));
320
- };
290
+ return ((x < y) ? -1 : ((x > y) ? 1 : 0));
291
+ };
321
292
 
322
- jQuery.fn.dataTableExt.oSort['timeline-event-desc'] = function(e1,e2) {
293
+ jQuery.fn.dataTableExt.oSort['timeline-event-desc'] = function(e1,e2) {
323
294
  var x = eventsOrder.indexOf(e1);
324
295
  var y = eventsOrder.indexOf(e2);
325
- return ((x < y) ? 1 : ((x > y) ? -1 : 0));
326
- };
296
+ return ((x < y) ? 1 : ((x > y) ? -1 : 0));
297
+ };
327
298
 
328
- function extractTitleAttributeFromText(txt) {
299
+ function extractTitleAttributeFromText(txt) {
329
300
  // Ugly - better way of doing this?
330
301
  var matches = txt.match(/title="\w+"/g);
331
302
  if (matches == null || matches.size == 0) {
332
- return null;
303
+ return null;
333
304
  }
334
305
  return matches[0].split('=')[1];
335
- }
306
+ }
336
307
 
337
- jQuery.fn.dataTableExt.oSort['timeline-details-asc'] = function(e1,e2) {
308
+ jQuery.fn.dataTableExt.oSort['timeline-details-asc'] = function(e1,e2) {
338
309
  var x = extractTitleAttributeFromText(e1);
339
310
  var y = extractTitleAttributeFromText(e2);
340
- return ((x < y) ? -1 : ((x > y) ? 1 : 0));
341
- };
311
+ return ((x < y) ? -1 : ((x > y) ? 1 : 0));
312
+ };
342
313
 
343
- jQuery.fn.dataTableExt.oSort['timeline-details-desc'] = function(e1,e2) {
314
+ jQuery.fn.dataTableExt.oSort['timeline-details-desc'] = function(e1,e2) {
344
315
  var x = extractTitleAttributeFromText(e1);
345
316
  var y = extractTitleAttributeFromText(e2);
346
- return ((x < y) ? 1 : ((x > y) ? -1 : 0));
347
- };
317
+ return ((x < y) ? 1 : ((x > y) ? -1 : 0));
318
+ };
348
319
 
349
- function initTable() {
320
+ function initTable() {
350
321
  return $("#timeline-table").dataTable({
351
- "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
352
- "sPaginationType": "bootstrap",
353
- "oLanguage": {
354
- "sLengthMenu": "_MENU_ records per page"
355
- },
356
- "iDisplayLength": 100,
357
- "bRetrieve": true,
358
- // Force a predictive order for event types, invoices and payments
359
- "aaSorting": [[1, 'desc'], [4, 'asc'], [3, 'desc']],
360
- "aoColumns": [
361
- { "sType": 'date' },
362
- { "sType": 'date' },
363
- null,
364
- { "sType": 'timeline-event' },
365
- { "sType": 'timeline-details' },
366
- null,
367
- null
368
- ]
322
+ "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
323
+ "sPaginationType": "bootstrap",
324
+ "oLanguage": {
325
+ "sLengthMenu": "_MENU_ records per page"
326
+ },
327
+ "iDisplayLength": 100,
328
+ "bRetrieve": true,
329
+ // Force a predictive order for event types, invoices and payments
330
+ "aaSorting": [[1, 'desc'], [4, 'asc'], [3, 'desc']],
331
+ "aoColumns": [
332
+ { "sType": 'date' },
333
+ { "sType": 'date' },
334
+ null,
335
+ { "sType": 'timeline-event' },
336
+ { "sType": 'timeline-details' },
337
+ null,
338
+ null
339
+ ]
369
340
  });
370
- }
341
+ }
371
342
 
372
- function filterEachNode(rows) {
343
+ function filterEachNode(rows) {
373
344
  var bundle = $("#bundles").val();
374
345
  var event_to_filter = $('#event_types').val().toUpperCase();
375
346
 
376
347
  for (i = 0; i < rows.length; i++)
377
348
  {
378
- tr = $(rows[i]);
349
+ tr = $(rows[i]);
379
350
 
380
- //filter bundles
381
- if (bundle == "" || tr.attr("title").split(",").indexOf(bundle) >= 0) {
382
- //first level filtering, so can remove hide
383
- tr.removeClass("hide");
384
- }
385
- else {
386
- //remove tr's not under this filter mode
387
- tr.addClass("hide");
388
- }
351
+ //filter bundles
352
+ if (bundle == "" || tr.attr("title").split(",").indexOf(bundle) >= 0) {
353
+ //first level filtering, so can remove hide
354
+ tr.removeClass("hide");
355
+ }
356
+ else {
357
+ //remove tr's not under this filter mode
358
+ tr.addClass("hide");
359
+ }
389
360
 
390
- //filter events
391
- if ("ALL" != event_to_filter)
392
- filterEvents(tr, event_to_filter);
361
+ //filter events
362
+ if ("ALL" != event_to_filter)
363
+ filterEvents(tr, event_to_filter);
393
364
 
394
- //add more filters here
395
- //do not unhide any rows
365
+ //add more filters here
366
+ //do not unhide any rows
396
367
  }
397
368
 
398
- }
369
+ }
399
370
 
400
- function filterEvents(tr, event_to_filter) {
371
+ function filterEvents(tr, event_to_filter) {
401
372
  tr_event_type = tr.data().event_type;
402
-
403
- core_events = ["INVOICE", "PAYMENT", "REFUND", "CHARGEBACK"]; //events which are not entitlements
373
+
374
+ core_events = ["INVOICE", "PAYMENT"]; //events which are not entitlements
404
375
 
405
376
  //is tr event not an event in question
406
- tr_event_does_not_match_filter = ("ENTITLEMENT" != event_to_filter &&
407
- tr_event_type != event_to_filter);
377
+ tr_event_does_not_match_filter = ("ENTITLEMENT" != event_to_filter &&
378
+ tr_event_type != event_to_filter);
408
379
 
409
380
  //tr event is not an entitlement
410
- tr_event_is_not_entitlement = ("ENTITLEMENT" == event_to_filter &&
411
- core_events.indexOf(tr_event_type) >= 0);
381
+ tr_event_is_not_entitlement = ("ENTITLEMENT" == event_to_filter &&
382
+ core_events.indexOf(tr_event_type) >= 0);
412
383
 
413
384
  if ( tr_event_does_not_match_filter || tr_event_is_not_entitlement )
414
385
  {
415
- //add hide to all who dont deserve the filter
416
- tr.addClass("hide");
386
+ //add hide to all who dont deserve the filter
387
+ tr.addClass("hide");
388
+ }
417
389
  }
418
- }
419
390
 
420
- function filterTable()
421
- {
391
+ function filterTable()
392
+ {
422
393
  var dataTable = initTable();
423
394
  var all_nodes = dataTable.fnGetNodes();
424
-
395
+
425
396
  filterEachNode(all_nodes);
426
-
397
+
427
398
  //my rows are filtered, draw table
428
399
  dataTable.fnDraw();
429
- }
400
+ }
430
401
 
431
402
 
432
- $(document).ready(function() {
403
+ $(document).ready(function() {
433
404
  disableLinks();
434
405
  // When going through the pages of the table, disable links as needed
435
406
  $('#timeline-table').bind('draw', function (e) {
436
- disableLinks();
407
+ disableLinks();
437
408
  });
438
409
 
439
410
  initTable();
440
411
 
441
412
  $("#bundles, #event_types").change(filterTable);
442
413
  filterTable();
443
- });
414
+ });
444
415
  <% end %>