kaui 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Gemfile +1 -1
- data/README.md +10 -15
- data/app/assets/images/kaui/duck.png +0 -0
- data/app/assets/images/kaui/logo.png +0 -0
- data/app/assets/images/kaui/search.png +0 -0
- data/app/assets/images/kaui/search_white.png +0 -0
- data/app/assets/javascripts/application.js +3 -0
- data/app/assets/javascripts/kaui/bootstrap-tweaks.js +3 -0
- data/app/assets/javascripts/kaui/kaui.js +99 -0
- data/app/assets/stylesheets/application.css +3 -1
- data/app/assets/stylesheets/bootstrap_and_overrides.less +39 -0
- data/app/assets/stylesheets/kaui/common.less +538 -0
- data/app/assets/stylesheets/kaui/datatable.less +75 -0
- data/app/assets/stylesheets/kaui/header.less +186 -0
- data/app/assets/stylesheets/kaui/home.less +82 -0
- data/app/assets/stylesheets/kaui/invoice.less +54 -0
- data/app/assets/stylesheets/kaui/kaui.less +16 -0
- data/app/assets/stylesheets/kaui/payment.less +29 -0
- data/app/assets/stylesheets/kaui/subscription.less +5 -0
- data/app/assets/stylesheets/kaui/tags.less +175 -0
- data/app/assets/stylesheets/kaui/timeline.less +4 -0
- data/app/controllers/kaui/account_emails_controller.rb +18 -18
- data/app/controllers/kaui/account_tags_controller.rb +8 -30
- data/app/controllers/kaui/account_timelines_controller.rb +13 -23
- data/app/controllers/kaui/accounts_controller.rb +65 -62
- data/app/controllers/kaui/admin_allowed_users_controller.rb +48 -32
- data/app/controllers/kaui/admin_tenants_controller.rb +147 -142
- data/app/controllers/kaui/bundle_tags_controller.rb +9 -33
- data/app/controllers/kaui/bundles_controller.rb +23 -62
- data/app/controllers/kaui/chargebacks_controller.rb +5 -11
- data/app/controllers/kaui/charges_controller.rb +11 -18
- data/app/controllers/kaui/credits_controller.rb +19 -22
- data/app/controllers/kaui/custom_fields_controller.rb +44 -16
- data/app/controllers/kaui/engine_controller.rb +56 -3
- data/app/controllers/kaui/engine_controller_util.rb +75 -1
- data/app/controllers/kaui/home_controller.rb +19 -0
- data/app/controllers/kaui/invoice_items_controller.rb +16 -21
- data/app/controllers/kaui/invoices_controller.rb +31 -53
- data/app/controllers/kaui/payment_methods_controller.rb +14 -46
- data/app/controllers/kaui/payments_controller.rb +60 -69
- data/app/controllers/kaui/refunds_controller.rb +11 -25
- data/app/controllers/kaui/registrations_controller.rb +38 -0
- data/app/controllers/kaui/subscriptions_controller.rb +82 -95
- data/app/controllers/kaui/tag_definitions_controller.rb +1 -5
- data/app/controllers/kaui/tags_controller.rb +17 -17
- data/app/controllers/kaui/tenants_controller.rb +38 -55
- data/app/controllers/kaui/transactions_controller.rb +8 -15
- data/app/helpers/kaui/application_helper.rb +4 -0
- data/app/helpers/kaui/object_helper.rb +24 -0
- data/app/helpers/kaui/payment_method_helper.rb +9 -0
- data/app/helpers/kaui/subscription_helper.rb +1 -1
- data/app/helpers/kaui/uuid_helper.rb +1 -0
- data/app/models/kaui/ability.rb +7 -1
- data/app/models/kaui/account.rb +6 -2
- data/app/models/kaui/account_email.rb +10 -0
- data/app/models/kaui/allowed_user.rb +16 -4
- data/app/models/kaui/audit_log.rb +5 -3
- data/app/models/kaui/bundle.rb +6 -11
- data/app/models/kaui/credit.rb +3 -0
- data/app/models/kaui/invoice.rb +10 -15
- data/app/models/kaui/invoice_payment.rb +10 -13
- data/app/models/kaui/killbill_registerable.rb +7 -0
- data/app/models/kaui/payment.rb +19 -12
- data/app/models/kaui/payment_method.rb +9 -0
- data/app/models/kaui/payment_state.rb +52 -0
- data/app/models/kaui/tag.rb +14 -0
- data/app/models/kaui/tag_definition.rb +8 -2
- data/app/models/kaui/user.rb +5 -4
- data/app/views/kaui/account_emails/_account_emails_table.html.erb +12 -9
- data/app/views/kaui/account_emails/_form.html.erb +9 -9
- data/app/views/kaui/account_emails/new.html.erb +9 -2
- data/app/views/kaui/account_tags/_form.html.erb +20 -29
- data/app/views/kaui/account_tags/_form_bar.html.erb +21 -0
- data/app/views/kaui/account_tags/edit.html.erb +9 -4
- data/app/views/kaui/account_timelines/show.html.erb +204 -287
- data/app/views/kaui/accounts/_account_info.html.erb +108 -0
- data/app/views/kaui/accounts/_billing_info.html.erb +129 -0
- data/app/views/kaui/accounts/_form.html.erb +127 -115
- data/app/views/kaui/accounts/_payment_methods.html.erb +28 -0
- data/app/views/kaui/accounts/edit.html.erb +10 -0
- data/app/views/kaui/accounts/index.html.erb +38 -23
- data/app/views/kaui/accounts/new.html.erb +9 -4
- data/app/views/kaui/accounts/show.html.erb +4 -106
- data/app/views/kaui/admin_allowed_users/_form.html.erb +19 -0
- data/app/views/kaui/admin_allowed_users/index.html.erb +35 -18
- data/app/views/kaui/admin_allowed_users/new.html.erb +9 -21
- data/app/views/kaui/admin_allowed_users/show.html.erb +42 -50
- data/app/views/kaui/admin_tenants/_form.html.erb +25 -0
- data/app/views/kaui/admin_tenants/_tenants_table.html.erb +27 -0
- data/app/views/kaui/admin_tenants/index.html.erb +14 -23
- data/app/views/kaui/admin_tenants/new.html.erb +8 -37
- data/app/views/kaui/admin_tenants/show.html.erb +128 -113
- data/app/views/kaui/bundle_tags/_form.html.erb +20 -28
- data/app/views/kaui/bundle_tags/_form_bar.html.erb +21 -0
- data/app/views/kaui/bundle_tags/edit.html.erb +9 -4
- data/app/views/kaui/bundles/index.html.erb +76 -29
- data/app/views/kaui/bundles/transfer.html.erb +28 -28
- data/app/views/kaui/chargebacks/_form.html.erb +31 -29
- data/app/views/kaui/chargebacks/new.html.erb +9 -4
- data/app/views/kaui/charges/_form.html.erb +35 -59
- data/app/views/kaui/charges/new.html.erb +9 -4
- data/app/views/kaui/credits/_form.html.erb +32 -59
- data/app/views/kaui/credits/new.html.erb +9 -4
- data/app/views/kaui/custom_fields/_form.html.erb +31 -0
- data/app/views/kaui/custom_fields/index.html.erb +33 -20
- data/app/views/kaui/custom_fields/new.html.erb +10 -0
- data/app/views/kaui/home/index.html.erb +12 -9
- data/app/views/kaui/invoice_items/_edit_form.html.erb +30 -0
- data/app/views/kaui/invoice_items/edit.html.erb +10 -91
- data/app/views/kaui/invoices/_invoice_table.html.erb +113 -0
- data/app/views/kaui/invoices/index.html.erb +31 -22
- data/app/views/kaui/invoices/show.html.erb +77 -91
- data/app/views/kaui/layouts/kaui_account_navbar.html.erb +11 -0
- data/app/views/kaui/layouts/kaui_application.html.erb +14 -53
- data/app/views/kaui/layouts/kaui_flash.html.erb +17 -0
- data/app/views/kaui/layouts/kaui_footer.html.erb +2 -0
- data/app/views/kaui/layouts/kaui_header.html.erb +17 -0
- data/app/views/kaui/layouts/kaui_navbar.html.erb +75 -0
- data/app/views/kaui/payment_methods/_form.html.erb +26 -23
- data/app/views/kaui/payment_methods/_new_creditcard_payment_method.html.erb +46 -41
- data/app/views/kaui/payment_methods/_payment_methods_details_table.html.erb +25 -0
- data/app/views/kaui/payment_methods/_payment_methods_table.html.erb +50 -52
- data/app/views/kaui/payment_methods/new.html.erb +9 -4
- data/app/views/kaui/payments/_form.html.erb +55 -0
- data/app/views/kaui/payments/_payment_table.html.erb +117 -0
- data/app/views/kaui/payments/index.html.erb +31 -22
- data/app/views/kaui/payments/new.html.erb +9 -92
- data/app/views/kaui/payments/show.html.erb +38 -2
- data/app/views/kaui/refunds/_form.html.erb +240 -0
- data/app/views/kaui/refunds/new.html.erb +8 -280
- data/app/views/kaui/registrations/_form.html.erb +19 -0
- data/app/views/kaui/registrations/new.html.erb +10 -0
- data/app/views/kaui/sessions/_form.html.erb +19 -0
- data/app/views/kaui/sessions/new.html.erb +7 -18
- data/app/views/kaui/subscriptions/_edit_form.html.erb +26 -0
- data/app/views/kaui/subscriptions/_form.html.erb +34 -31
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +37 -24
- data/app/views/kaui/subscriptions/edit.html.erb +10 -30
- data/app/views/kaui/subscriptions/new.html.erb +14 -11
- data/app/views/kaui/tag_definitions/_form.html.erb +14 -11
- data/app/views/kaui/tag_definitions/index.html.erb +56 -30
- data/app/views/kaui/tag_definitions/new.html.erb +9 -2
- data/app/views/kaui/tags/_tags_table.html.erb +7 -10
- data/app/views/kaui/tags/index.html.erb +29 -20
- data/app/views/kaui/tenants/_form.html.erb +13 -0
- data/app/views/kaui/tenants/index.html.erb +9 -16
- data/app/views/kaui/transactions/_form.html.erb +47 -67
- data/app/views/kaui/transactions/new.html.erb +9 -2
- data/config/initializers/killbill_registerable.rb +4 -0
- data/config/routes.rb +88 -93
- data/kaui.gemspec +11 -2
- data/lib/kaui/engine.rb +6 -4
- data/lib/kaui/version.rb +1 -1
- data/lib/kaui.rb +24 -1
- data/test/dummy/config/application.rb +2 -0
- data/test/dummy/config/database.yml +6 -3
- data/test/dummy/config/initializers/killbill_client.rb +0 -2
- data/test/fixtures/catalog-v1.xml +74 -0
- data/test/fixtures/catalog_translation_fr-v1.properties +1 -0
- data/test/fixtures/invoice_template-v1.html +100 -0
- data/test/fixtures/invoice_translation_fr-v1.properties +23 -0
- data/test/fixtures/overdue-v1.xml +49 -0
- data/test/fixtures/stripe.yml +2 -0
- data/test/functional/kaui/account_emails_controller_test.rb +35 -8
- data/test/functional/kaui/account_tags_controller_test.rb +8 -8
- data/test/functional/kaui/account_timelines_controller_test.rb +6 -7
- data/test/functional/kaui/accounts_controller_test.rb +72 -10
- data/test/functional/kaui/admin_allowed_users_controller_test.rb +6 -5
- data/test/functional/kaui/admin_tenants_controller_test.rb +104 -48
- data/test/functional/kaui/bundle_tags_controller_test.rb +14 -9
- data/test/functional/kaui/bundles_controller_test.rb +59 -23
- data/test/functional/kaui/chargebacks_controller_test.rb +29 -7
- data/test/functional/kaui/charges_controller_test.rb +31 -10
- data/test/functional/kaui/credits_controller_test.rb +25 -6
- data/test/functional/kaui/custom_fields_controller_test.rb +25 -1
- data/test/functional/kaui/functional_test_helper_nosetup.rb +6 -4
- data/test/functional/kaui/home_controller_test.rb +24 -0
- data/test/functional/kaui/invoice_items_controller_test.rb +56 -8
- data/test/functional/kaui/invoices_controller_test.rb +27 -18
- data/test/functional/kaui/payment_methods_controller_test.rb +2 -22
- data/test/functional/kaui/payments_controller_test.rb +8 -3
- data/test/functional/kaui/refunds_controller_test.rb +40 -21
- data/test/functional/kaui/subscriptions_controller_test.rb +77 -24
- data/test/functional/kaui/tag_definitions_controller_test.rb +1 -7
- data/test/functional/kaui/tags_controller_test.rb +1 -1
- data/test/functional/kaui/tenants_controller_test.rb +9 -9
- data/test/functional/kaui/transactions_controller_test.rb +41 -16
- data/test/integration/kaui/integration_test_helper.rb +0 -1
- data/test/integration/kaui/navigation_test.rb +4 -6
- data/test/test_helper.rb +2 -0
- metadata +155 -28
- data/Gemfile.lock +0 -210
- data/app/assets/stylesheets/bootstrap_and_overrides.css +0 -7
- data/app/assets/stylesheets/datatables.scss +0 -14
- data/app/assets/stylesheets/layout.scss +0 -19
- data/app/views/kaui/account_emails/show.html.erb +0 -25
- data/app/views/kaui/account_tags/_account_tags_table.html.erb +0 -32
- data/app/views/kaui/account_tags/show.html.erb +0 -6
- data/app/views/kaui/account_timelines/index.html.erb +0 -14
- data/app/views/kaui/bundle_tags/_bundle_tags_table.html.erb +0 -31
- data/app/views/kaui/bundle_tags/show.html.erb +0 -6
- data/app/views/kaui/bundles/show.html.erb +0 -18
- data/app/views/kaui/payment_methods/index.html.erb +0 -30
- data/app/views/kaui/payment_methods/show.html.erb +0 -3
- data/app/views/kaui/payments/_payments_table.html.erb +0 -41
- data/app/views/kaui/subscriptions/index.html.erb +0 -15
- data/app/views/kaui/subscriptions/show.html.erb +0 -33
- data/app/views/kaui/tag_definitions/show.html.erb +0 -15
- data/vendor/assets/images/img/glyphicons-halflings-white.png +0 -0
- data/vendor/assets/images/img/glyphicons-halflings.png +0 -0
- data/vendor/assets/stylesheets/css/bootstrap-datepicker.cd46d38.css +0 -274
@@ -4,28 +4,56 @@ class Kaui::CustomFieldsController < Kaui::EngineController
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def pagination
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
custom_fields = Kaui::CustomField.list_or_search(search_key, offset, limit, options_for_klient)
|
7
|
+
searcher = lambda do |search_key, offset, limit|
|
8
|
+
Kaui::CustomField.list_or_search(search_key, offset, limit, options_for_klient)
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
data_extractor = lambda do |custom_field, column|
|
12
|
+
[
|
13
|
+
custom_field.object_id,
|
14
|
+
custom_field.object_type,
|
15
|
+
custom_field.name,
|
16
|
+
custom_field.value
|
17
|
+
][column]
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
formatter = lambda do |custom_field|
|
21
|
+
url_for_object = view_context.url_for_object(custom_field.object_id, custom_field.object_type)
|
22
|
+
[
|
23
|
+
url_for_object ? view_context.link_to(custom_field.object_id, url_for_object) : custom_field.object_id,
|
24
|
+
custom_field.object_type,
|
22
25
|
custom_field.name,
|
23
26
|
custom_field.value
|
24
27
|
]
|
25
28
|
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
paginate searcher, data_extractor, formatter
|
31
|
+
end
|
32
|
+
|
33
|
+
def new
|
34
|
+
@custom_field = Kaui::CustomField.new
|
35
|
+
end
|
36
|
+
|
37
|
+
def create
|
38
|
+
@custom_field = Kaui::CustomField.new(params.require(:custom_field))
|
39
|
+
|
40
|
+
model = case @custom_field.object_type.to_sym
|
41
|
+
when :ACCOUNT
|
42
|
+
Kaui::Account.new(:account_id => @custom_field.object_id)
|
43
|
+
when :BUNDLE
|
44
|
+
Kaui::Bundle.new(:bundle_id => @custom_field.object_id)
|
45
|
+
when :SUBSCRIPTION
|
46
|
+
Kaui::Subscription.new(:subscription_id => @custom_field.object_id)
|
47
|
+
when :INVOICE
|
48
|
+
Kaui::Invoice.new(:invoice_id => @custom_field.object_id)
|
49
|
+
when :PAYMENT
|
50
|
+
Kaui::Payment.new(:payment_id => @custom_field.object_id)
|
51
|
+
else
|
52
|
+
flash.now[:error] = "Invalid object type #{@custom_field.object_type}"
|
53
|
+
render :new and return
|
54
|
+
end
|
55
|
+
model.add_custom_field(@custom_field, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
56
|
+
|
57
|
+
redirect_to custom_fields_path, :notice => 'Custom field was successfully created'
|
30
58
|
end
|
31
59
|
end
|
@@ -25,13 +25,54 @@ class Kaui::EngineController < ApplicationController
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def check_for_redirect_to_tenant_screen
|
28
|
-
|
29
|
-
flash[:error] =
|
28
|
+
unless Kaui.is_user_assigned_valid_tenant?(current_user, session)
|
29
|
+
flash[:error] = 'No tenants configured for users AND KillBillClient.api_key, KillBillClient.api_secret have not been set'
|
30
30
|
session[:kb_tenant_id] = nil
|
31
|
-
redirect_to Kaui.tenant_home_path.call
|
31
|
+
redirect_to Kaui.tenant_home_path.call
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
def retrieve_tenants_for_current_user
|
36
|
+
if Kaui.root_username == current_user.kb_username
|
37
|
+
Kaui::Tenant.all.map(&:kb_tenant_id)
|
38
|
+
else
|
39
|
+
Kaui::AllowedUser.preload(:kaui_tenants).find_by_kb_username(current_user.kb_username).kaui_tenants.map(&:kb_tenant_id)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def retrieve_allowed_users_for_current_user
|
44
|
+
tenants_for_current_user = retrieve_tenants_for_current_user
|
45
|
+
|
46
|
+
Kaui::AllowedUser.preload(:kaui_tenants).all.select do |user|
|
47
|
+
tenants_for_user = user.kaui_tenants.map(&:kb_tenant_id)
|
48
|
+
if tenants_for_user.empty?
|
49
|
+
Kaui.root_username == current_user.kb_username
|
50
|
+
else
|
51
|
+
(tenants_for_user - tenants_for_current_user).empty?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Note! Order matters, StandardError needs to be first
|
57
|
+
rescue_from(StandardError) do |error|
|
58
|
+
log_rescue_error error
|
59
|
+
flash[:error] = "Error: #{error.to_s}"
|
60
|
+
try_to_redirect_to_account_path = !params[:controller].ends_with?('accounts')
|
61
|
+
perform_redirect_after_error try_to_redirect_to_account_path
|
62
|
+
end
|
63
|
+
|
64
|
+
rescue_from(ActionController::ParameterMissing) do |parameter_missing_exception|
|
65
|
+
log_rescue_error parameter_missing_exception
|
66
|
+
flash[:error] = "Required parameter missing: #{parameter_missing_exception.param}"
|
67
|
+
perform_redirect_after_error
|
68
|
+
end
|
69
|
+
|
70
|
+
rescue_from(KillBillClient::API::ResponseError) do |killbill_exception|
|
71
|
+
log_rescue_error killbill_exception
|
72
|
+
flash[:error] = "Error while communicating with the Kill Bill server: #{as_string(killbill_exception)}"
|
73
|
+
try_to_redirect_to_account_path = !(killbill_exception.is_a?(KillBillClient::API::NotFound) && params[:controller].ends_with?('accounts'))
|
74
|
+
perform_redirect_after_error try_to_redirect_to_account_path
|
75
|
+
end
|
35
76
|
|
36
77
|
private
|
37
78
|
|
@@ -51,4 +92,16 @@ class Kaui::EngineController < ApplicationController
|
|
51
92
|
result
|
52
93
|
end
|
53
94
|
|
95
|
+
def log_rescue_error(error)
|
96
|
+
Rails.logger.warn "#{error.class} #{error.to_s}. #{error.backtrace.join("\n")}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def perform_redirect_after_error(try_to_redirect_to_account_path = true)
|
100
|
+
account_id = nested_hash_value(params, :account_id)
|
101
|
+
if try_to_redirect_to_account_path && account_id.present?
|
102
|
+
redirect_to kaui_engine.account_path(account_id)
|
103
|
+
else
|
104
|
+
redirect_to kaui_engine.home_path
|
105
|
+
end
|
106
|
+
end
|
54
107
|
end
|
@@ -6,6 +6,69 @@ module Kaui::EngineControllerUtil
|
|
6
6
|
layout ||= Kaui.config[:layout]
|
7
7
|
end
|
8
8
|
|
9
|
+
def paginate(searcher, data_extractor, formatter)
|
10
|
+
search_key = (params[:search] || {})[:value].presence
|
11
|
+
offset = (params[:start] || 0).to_i
|
12
|
+
limit = (params[:length] || 10).to_i
|
13
|
+
|
14
|
+
limit = 2147483647 if limit == -1
|
15
|
+
|
16
|
+
begin
|
17
|
+
pages = searcher.call(search_key, offset, limit)
|
18
|
+
rescue => e
|
19
|
+
error = e.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
json = {
|
23
|
+
:draw => (params[:draw] || 0).to_i,
|
24
|
+
:recordsTotal => pages.nil? ? 0 : pages.pagination_max_nb_records,
|
25
|
+
:recordsFiltered => pages.nil? ? 0 : pages.pagination_total_nb_records,
|
26
|
+
:data => []
|
27
|
+
}
|
28
|
+
json[:error] = error unless error.nil?
|
29
|
+
|
30
|
+
pages ||= []
|
31
|
+
|
32
|
+
# Until we support server-side sorting
|
33
|
+
ordering = ((params[:order] || {})[:'0'] || {})
|
34
|
+
ordering_column = (ordering[:column] || 0).to_i
|
35
|
+
ordering_dir = ordering[:dir] || 'asc'
|
36
|
+
pages.sort! do |a, b|
|
37
|
+
a = data_extractor.call(a, ordering_column)
|
38
|
+
b = data_extractor.call(b, ordering_column)
|
39
|
+
sort = a <=> b
|
40
|
+
sort.nil? ? -1 : sort
|
41
|
+
end
|
42
|
+
pages.reverse! if ordering_dir == 'desc'
|
43
|
+
|
44
|
+
pages.each { |page| json[:data] << formatter.call(page) }
|
45
|
+
|
46
|
+
respond_to do |format|
|
47
|
+
format.json { render :json => json }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def run_in_parallel(*tasks)
|
52
|
+
latch = Concurrent::CountDownLatch.new(tasks.size)
|
53
|
+
exceptions = Concurrent::Array.new
|
54
|
+
|
55
|
+
tasks.each do |task|
|
56
|
+
Kaui.thread_pool.post do
|
57
|
+
begin
|
58
|
+
task.call
|
59
|
+
rescue => e
|
60
|
+
exceptions << e
|
61
|
+
ensure
|
62
|
+
latch.count_down
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
latch.wait
|
67
|
+
|
68
|
+
exception = exceptions.shift
|
69
|
+
raise exception unless exception.nil?
|
70
|
+
end
|
71
|
+
|
9
72
|
def as_string(e)
|
10
73
|
if e.is_a?(KillBillClient::API::ResponseError)
|
11
74
|
"Error #{e.response.code}: #{as_string_from_response(e.response.body)}"
|
@@ -30,4 +93,15 @@ module Kaui::EngineControllerUtil
|
|
30
93
|
error_message[0..1000]
|
31
94
|
end
|
32
95
|
|
33
|
-
|
96
|
+
def nested_hash_value(obj, key)
|
97
|
+
if obj.respond_to?(:key?) && obj.key?(key)
|
98
|
+
obj[key]
|
99
|
+
elsif obj.is_a?(Hash) or obj.is_a?(Array)
|
100
|
+
r = nil
|
101
|
+
obj.find { |*a| r = nested_hash_value(a.last, key) }
|
102
|
+
r
|
103
|
+
else
|
104
|
+
nil
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -1,4 +1,23 @@
|
|
1
1
|
class Kaui::HomeController < Kaui::EngineController
|
2
|
+
|
2
3
|
def index
|
4
|
+
@search_query = params[:q]
|
5
|
+
end
|
6
|
+
|
7
|
+
def search
|
8
|
+
search_type, search_query = parse_query(params[:q])
|
9
|
+
if search_type == 'invoice'
|
10
|
+
redirect_to invoice_path(:id => search_query)
|
11
|
+
elsif search_type == 'payment'
|
12
|
+
redirect_to payment_path(:id => search_query)
|
13
|
+
else
|
14
|
+
redirect_to accounts_path(:q => search_query)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def parse_query(query)
|
21
|
+
/((invoice|payment):)?(.*)/.match(query).captures.drop(1)
|
3
22
|
end
|
4
23
|
end
|
@@ -1,25 +1,25 @@
|
|
1
1
|
class Kaui::InvoiceItemsController < Kaui::EngineController
|
2
2
|
|
3
3
|
def edit
|
4
|
-
invoice_item_id = params
|
5
|
-
invoice_id
|
6
|
-
|
7
|
-
begin
|
8
|
-
invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
|
9
|
-
rescue => e
|
10
|
-
flash[:error] = "Error while getting information for invoice #{invoice_id}: #{as_string(e)}"
|
11
|
-
redirect_to :back
|
12
|
-
end
|
4
|
+
invoice_item_id = params.require(:id)
|
5
|
+
invoice_id = params.require(:invoice_id)
|
13
6
|
|
7
|
+
# See https://github.com/killbill/killbill/issues/7
|
8
|
+
invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
|
14
9
|
@invoice_item = invoice.items.find { |ii| ii.invoice_item_id == invoice_item_id }
|
10
|
+
|
11
|
+
if @invoice_item.nil?
|
12
|
+
flash[:error] = "Unable to find invoice item #{invoice_item_id}"
|
13
|
+
redirect_to account_invoice_path(params.require(:account_id), invoice_id)
|
14
|
+
end
|
15
15
|
end
|
16
16
|
|
17
17
|
def update
|
18
|
-
@invoice_item = Kaui::InvoiceItem.new(params
|
18
|
+
@invoice_item = Kaui::InvoiceItem.new(params.require(:invoice_item))
|
19
19
|
|
20
20
|
begin
|
21
21
|
invoice = @invoice_item.update(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
22
|
-
redirect_to kaui_engine.
|
22
|
+
redirect_to kaui_engine.account_invoice_path(invoice.account_id, invoice.invoice_id), :notice => 'Adjustment item was successfully created'
|
23
23
|
rescue => e
|
24
24
|
flash.now[:error] = "Error while adjusting invoice item: #{as_string(e)}"
|
25
25
|
render :action => :edit
|
@@ -27,16 +27,11 @@ class Kaui::InvoiceItemsController < Kaui::EngineController
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def destroy
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
invoice_item = Kaui::InvoiceItem.new(:invoice_item_id => params.require(:id),
|
31
|
+
:invoice_id => params.require(:invoice_id),
|
32
|
+
:account_id => params.require(:account_id))
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
redirect_to kaui_engine.invoice_path(@invoice_item.invoice_id), :notice => 'CBA item was successfully deleted'
|
37
|
-
rescue => e
|
38
|
-
flash.now[:error] = "Error while deleting CBA item: #{as_string(e)}"
|
39
|
-
render :action => :edit
|
40
|
-
end
|
34
|
+
invoice_item.delete(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
35
|
+
redirect_to kaui_engine.account_invoice_path(invoice_item.account_id, invoice_item.invoice_id), :notice => 'CBA item was successfully deleted'
|
41
36
|
end
|
42
37
|
end
|
@@ -1,80 +1,58 @@
|
|
1
1
|
class Kaui::InvoicesController < Kaui::EngineController
|
2
2
|
|
3
3
|
def index
|
4
|
-
|
5
|
-
redirect_to kaui_engine.invoice_path(params[:invoice_id])
|
6
|
-
end
|
4
|
+
@search_query = params[:account_id]
|
7
5
|
end
|
8
6
|
|
9
7
|
def pagination
|
10
|
-
|
8
|
+
searcher = lambda do |search_key, offset, limit|
|
9
|
+
account = Kaui::Account::find_by_id_or_key(search_key, false, false, options_for_klient) rescue nil
|
10
|
+
if account.nil?
|
11
|
+
Kaui::Invoice.list_or_search(search_key, offset, limit, options_for_klient)
|
12
|
+
else
|
13
|
+
account.invoices(true, options_for_klient).map! { |invoice| Kaui::Invoice.build_from_raw_invoice(invoice) }
|
14
|
+
end
|
15
|
+
end
|
11
16
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
data_extractor = lambda do |invoice, column|
|
18
|
+
[
|
19
|
+
invoice.invoice_number.to_i,
|
20
|
+
invoice.invoice_date,
|
21
|
+
invoice.amount,
|
22
|
+
invoice.balance
|
23
|
+
][column]
|
17
24
|
end
|
18
|
-
json[:iTotalDisplayRecords] = invoices.pagination_total_nb_records
|
19
|
-
json[:iTotalRecords] = invoices.pagination_max_nb_records
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
view_context.link_to(
|
24
|
-
invoice.invoice_number,
|
26
|
+
formatter = lambda do |invoice|
|
27
|
+
[
|
28
|
+
view_context.link_to(invoice.invoice_number, view_context.url_for(:controller => :invoices, :action => :show, :account_id => invoice.account_id, :id => invoice.invoice_id)),
|
25
29
|
view_context.format_date(invoice.invoice_date),
|
26
30
|
view_context.humanized_money_with_symbol(invoice.amount_to_money),
|
27
31
|
view_context.humanized_money_with_symbol(invoice.balance_to_money)
|
28
32
|
]
|
29
33
|
end
|
30
34
|
|
31
|
-
|
32
|
-
format.json { render :json => json }
|
33
|
-
end
|
35
|
+
paginate searcher, data_extractor, formatter
|
34
36
|
end
|
35
37
|
|
36
38
|
def show
|
37
|
-
|
38
|
-
unless invoice_id_or_number.present?
|
39
|
-
flash.now[:error] = 'No id given'
|
40
|
-
render :index and return
|
41
|
-
end
|
39
|
+
@invoice = Kaui::Invoice.find_by_id_or_number(params.require(:id), true, 'FULL', options_for_klient)
|
42
40
|
|
43
|
-
|
44
|
-
@
|
45
|
-
@invoice_id = @invoice.invoice_id
|
46
|
-
@account = Kaui::Account.find_by_id(@invoice.account_id, false, false, options_for_klient)
|
47
|
-
@payments = Kaui::Invoice.new(:invoice_id => @invoice_id).payments(false, 'FULL', options_for_klient)
|
41
|
+
fetch_payments_and_pms = lambda do
|
42
|
+
@payments = @invoice.payments(true, 'FULL', options_for_klient).map { |payment| Kaui::InvoicePayment.build_from_raw_payment(payment) }
|
48
43
|
@payment_methods = Kaui::PaymentMethod.payment_methods_for_payments(@payments, options_for_klient)
|
44
|
+
end
|
45
|
+
fetch_account = lambda { @account = Kaui::Account.find_by_id(@invoice.account_id, false, false, options_for_klient) }
|
49
46
|
|
50
|
-
|
51
|
-
|
52
|
-
@cba_items_not_deleteable = []
|
53
|
-
if @invoice.items.present?
|
54
|
-
@invoice.items.each do |item|
|
55
|
-
@cba_items_not_deleteable << item.linked_invoice_item_id if item.description =~ /account credit/ and item.amount < 0
|
47
|
+
run_in_parallel fetch_payments_and_pms, fetch_account
|
48
|
+
end
|
56
49
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
unless item.bundle_id.nil? || @bundles.has_key?(item.bundle_id)
|
61
|
-
@bundles[item.bundle_id] = Kaui::Bundle::find_by_id(item.bundle_id, options_for_klient)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
else
|
65
|
-
flash.now[:error] = "Invoice items for #{@invoice_id} not found"
|
66
|
-
end
|
67
|
-
rescue => e
|
68
|
-
flash.now[:error] = "Error while getting information for invoice #{invoice_id_or_number}: #{as_string(e)}"
|
69
|
-
end
|
50
|
+
def restful_show
|
51
|
+
invoice = Kaui::Invoice.find_by_id_or_number(params.require(:id), false, 'NONE', options_for_klient)
|
52
|
+
redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id)
|
70
53
|
end
|
71
54
|
|
72
55
|
def show_html
|
73
|
-
|
74
|
-
render :text => Kaui::Invoice.as_html(params[:id], options_for_klient)
|
75
|
-
rescue => e
|
76
|
-
flash.now[:error] = "Error rendering invoice html #{params[:id]}: #{as_string(e)}"
|
77
|
-
render :action => :index
|
78
|
-
end
|
56
|
+
render :text => Kaui::Invoice.as_html(params.require(:id), options_for_klient)
|
79
57
|
end
|
80
58
|
end
|
@@ -1,38 +1,5 @@
|
|
1
1
|
class Kaui::PaymentMethodsController < Kaui::EngineController
|
2
2
|
|
3
|
-
def index
|
4
|
-
end
|
5
|
-
|
6
|
-
def pagination
|
7
|
-
search_key = params[:sSearch]
|
8
|
-
offset = params[:iDisplayStart] || 0
|
9
|
-
limit = params[:iDisplayLength] || 10
|
10
|
-
|
11
|
-
payment_methods = Kaui::PaymentMethod.list_or_search(search_key, offset, limit, options_for_klient)
|
12
|
-
|
13
|
-
json = {
|
14
|
-
:sEcho => params[:sEcho],
|
15
|
-
:iTotalRecords => payment_methods.pagination_max_nb_records,
|
16
|
-
:iTotalDisplayRecords => payment_methods.pagination_total_nb_records,
|
17
|
-
:aaData => []
|
18
|
-
}
|
19
|
-
|
20
|
-
payment_methods.each do |payment_method|
|
21
|
-
info_plugin = payment_method.plugin_info || OpenStruct.new
|
22
|
-
json[:aaData] << [
|
23
|
-
view_context.link_to(view_context.truncate_uuid(payment_method.payment_method_id), view_context.url_for(:controller => :payment_methods, :action => :show, :id => payment_method.payment_method_id)),
|
24
|
-
view_context.link_to(view_context.truncate_uuid(payment_method.account_id), view_context.url_for(:controller => :accounts, :action => :show, :id => payment_method.account_id)),
|
25
|
-
info_plugin.external_payment_id,
|
26
|
-
find_value_from_properties(info_plugin.properties, 'ccName'),
|
27
|
-
find_value_from_properties(info_plugin.properties, 'ccLast4'),
|
28
|
-
]
|
29
|
-
end
|
30
|
-
|
31
|
-
respond_to do |format|
|
32
|
-
format.json { render :json => json }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
3
|
def new
|
37
4
|
@payment_method = Kaui::PaymentMethod.new(:account_id => params[:account_id],
|
38
5
|
:plugin_name => params[:plugin_name] || Kaui.creditcard_plugin_name.call)
|
@@ -79,34 +46,35 @@ class Kaui::PaymentMethodsController < Kaui::EngineController
|
|
79
46
|
|
80
47
|
begin
|
81
48
|
@payment_method = @payment_method.create(@payment_method.is_default, current_user.kb_username, @reason, @comment, options_for_klient)
|
82
|
-
redirect_to
|
49
|
+
redirect_to kaui_engine.account_path(@payment_method.account_id), :notice => 'Payment method was successfully created'
|
83
50
|
rescue => e
|
84
51
|
flash.now[:error] = "Error while creating payment method: #{as_string(e)}"
|
85
52
|
render :action => :new
|
86
53
|
end
|
87
54
|
end
|
88
55
|
|
89
|
-
def show
|
90
|
-
begin
|
91
|
-
@payment_methods = [Kaui::PaymentMethod.find_by_id(params[:id], true, options_for_klient)]
|
92
|
-
rescue => e
|
93
|
-
flash.now[:error] = "Error while retrieving payment method #{params[:id]}: #{as_string(e)}"
|
94
|
-
render :action => :index
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
56
|
def destroy
|
99
57
|
payment_method_id = params[:id]
|
100
58
|
|
59
|
+
payment_method = Kaui::PaymentMethod.find_by_id(payment_method_id, false, options_for_klient)
|
101
60
|
begin
|
102
61
|
Kaui::PaymentMethod.destroy(payment_method_id, params[:set_auto_pay_off], current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
103
|
-
redirect_to
|
62
|
+
redirect_to kaui_engine.account_path(payment_method.account_id), :notice => "Payment method #{payment_method_id} successfully deleted"
|
104
63
|
rescue => e
|
105
|
-
flash
|
106
|
-
|
64
|
+
flash[:error] = "Error while deleting payment method #{payment_method_id}: #{as_string(e)}"
|
65
|
+
redirect_to kaui_engine.account_path(payment_method.account_id)
|
107
66
|
end
|
108
67
|
end
|
109
68
|
|
69
|
+
def show
|
70
|
+
restful_show
|
71
|
+
end
|
72
|
+
|
73
|
+
def restful_show
|
74
|
+
payment_method = Kaui::PaymentMethod.find_by_id(params.require(:id), false, options_for_klient)
|
75
|
+
redirect_to kaui_engine.account_path(payment_method.account_id)
|
76
|
+
end
|
77
|
+
|
110
78
|
private
|
111
79
|
|
112
80
|
def find_value_from_properties(properties, key)
|