kaui 2.1.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +8 -7
- data/Rakefile +4 -2
- data/app/assets/config/kaui_manifest.js +45 -0
- data/app/assets/javascripts/jquery.spin.js +76 -0
- data/app/assets/javascripts/kaui/kaui.js +76 -0
- data/app/assets/javascripts/kaui_application.js +25 -0
- data/app/assets/javascripts/spin.js +76 -0
- data/app/assets/stylesheets/bootstrap_and_overrides.scss +240 -0
- data/app/assets/stylesheets/kaui/{account.less → account.scss} +4 -0
- data/app/assets/stylesheets/kaui/{audit.less → audit.scss} +5 -1
- data/app/assets/stylesheets/kaui/{common.less → common.scss} +17 -15
- data/app/assets/stylesheets/kaui/{datatable.less → datatable.scss} +6 -3
- data/app/assets/stylesheets/kaui/{header.less → header.scss} +16 -12
- data/app/assets/stylesheets/kaui/{home.less → home.scss} +7 -4
- data/app/assets/stylesheets/kaui/{invoice.less → invoice.scss} +7 -3
- data/app/assets/stylesheets/kaui/kaui.scss +265 -0
- data/app/assets/stylesheets/kaui/kaui_bootstrap.scss +3 -0
- data/app/assets/stylesheets/kaui/{overdue.less → overdue.scss} +3 -1
- data/app/assets/stylesheets/kaui/{payment.less → payment.scss} +3 -0
- data/app/assets/stylesheets/kaui/{subscription.less → subscription.scss} +4 -1
- data/app/assets/stylesheets/kaui/{tags.less → tags.scss} +9 -5
- data/app/assets/stylesheets/kaui/timeline.scss +7 -0
- data/app/assets/stylesheets/kaui/tooltip.scss +15 -0
- data/app/controllers/kaui/account_children_controller.rb +25 -28
- data/app/controllers/kaui/account_custom_fields_controller.rb +16 -15
- data/app/controllers/kaui/account_emails_controller.rb +28 -25
- data/app/controllers/kaui/account_tags_controller.rb +37 -34
- data/app/controllers/kaui/account_timelines_controller.rb +38 -33
- data/app/controllers/kaui/accounts_controller.rb +268 -250
- data/app/controllers/kaui/admin_allowed_users_controller.rb +105 -99
- data/app/controllers/kaui/admin_controller.rb +32 -31
- data/app/controllers/kaui/admin_tenants_controller.rb +434 -388
- data/app/controllers/kaui/audit_logs_controller.rb +86 -83
- data/app/controllers/kaui/bundle_tags_controller.rb +24 -20
- data/app/controllers/kaui/bundles_controller.rb +96 -82
- data/app/controllers/kaui/chargebacks_controller.rb +36 -33
- data/app/controllers/kaui/charges_controller.rb +23 -20
- data/app/controllers/kaui/credits_controller.rb +28 -25
- data/app/controllers/kaui/custom_fields_controller.rb +172 -38
- data/app/controllers/kaui/engine_controller.rb +2 -1
- data/app/controllers/kaui/engine_controller_util.rb +128 -117
- data/app/controllers/kaui/home_controller.rb +230 -217
- data/app/controllers/kaui/invoice_items_controller.rb +43 -39
- data/app/controllers/kaui/invoice_tags_controller.rb +24 -20
- data/app/controllers/kaui/invoices_controller.rb +132 -117
- data/app/controllers/kaui/login_proxy_controller.rb +2 -1
- data/app/controllers/kaui/payment_methods_controller.rb +102 -94
- data/app/controllers/kaui/payments_controller.rb +95 -92
- data/app/controllers/kaui/queues_controller.rb +47 -14
- data/app/controllers/kaui/refunds_controller.rb +36 -33
- data/app/controllers/kaui/registrations_controller.rb +7 -7
- data/app/controllers/kaui/role_definitions_controller.rb +17 -14
- data/app/controllers/kaui/sessions_controller.rb +7 -4
- data/app/controllers/kaui/subscriptions_controller.rb +197 -187
- data/app/controllers/kaui/tag_definitions_controller.rb +28 -27
- data/app/controllers/kaui/tags_controller.rb +25 -22
- data/app/controllers/kaui/tenants_controller.rb +30 -28
- data/app/controllers/kaui/transactions_controller.rb +43 -38
- data/app/helpers/kaui/account_helper.rb +16 -14
- data/app/helpers/kaui/application_helper.rb +8 -3
- data/app/helpers/kaui/date_helper.rb +4 -3
- data/app/helpers/kaui/home_helper.rb +2 -0
- data/app/helpers/kaui/locale_helper.rb +7 -6
- data/app/helpers/kaui/money_helper.rb +2 -1
- data/app/helpers/kaui/object_helper.rb +11 -10
- data/app/helpers/kaui/payment_helper.rb +7 -6
- data/app/helpers/kaui/payment_method_helper.rb +3 -2
- data/app/helpers/kaui/permissions_helper.rb +9 -9
- data/app/helpers/kaui/plugin_helper.rb +25 -23
- data/app/helpers/kaui/subscription_helper.rb +27 -29
- data/app/helpers/kaui/us_states_helper.rb +7 -6
- data/app/helpers/kaui/uuid_helper.rb +8 -6
- data/app/models/kaui/ability.rb +19 -12
- data/app/models/kaui/account.rb +45 -28
- data/app/models/kaui/account_email.rb +23 -20
- data/app/models/kaui/account_timeline.rb +5 -1
- data/app/models/kaui/admin.rb +65 -64
- data/app/models/kaui/admin_tenant.rb +81 -82
- data/app/models/kaui/allowed_user.rb +13 -9
- data/app/models/kaui/allowed_user_tenant.rb +4 -2
- data/app/models/kaui/application_record.rb +2 -0
- data/app/models/kaui/audit_log.rb +6 -3
- data/app/models/kaui/base.rb +13 -7
- data/app/models/kaui/bundle.rb +41 -24
- data/app/models/kaui/catalog.rb +118 -113
- data/app/models/kaui/chargeback.rb +5 -1
- data/app/models/kaui/credit.rb +4 -1
- data/app/models/kaui/custom_field.rb +9 -6
- data/app/models/kaui/invoice.rb +25 -22
- data/app/models/kaui/invoice_item.rb +9 -6
- data/app/models/kaui/invoice_payment.rb +49 -54
- data/app/models/kaui/killbill_authenticatable.rb +14 -8
- data/app/models/kaui/killbill_registerable.rb +7 -0
- data/app/models/kaui/overdue.rb +64 -65
- data/app/models/kaui/payment.rb +22 -19
- data/app/models/kaui/payment_method.rb +48 -39
- data/app/models/kaui/payment_state.rb +41 -38
- data/app/models/kaui/rails_methods.rb +9 -9
- data/app/models/kaui/refund.rb +7 -1
- data/app/models/kaui/role_definition.rb +5 -1
- data/app/models/kaui/simple_plan.rb +5 -3
- data/app/models/kaui/subscription.rb +10 -7
- data/app/models/kaui/tag.rb +25 -22
- data/app/models/kaui/tag_definition.rb +50 -45
- data/app/models/kaui/tenant.rb +6 -5
- data/app/models/kaui/transaction.rb +43 -31
- data/app/models/kaui/user.rb +10 -16
- data/app/models/kaui/user_role.rb +8 -5
- data/app/views/kaui/accounts/_billing_info.html.erb +1 -1
- data/app/views/kaui/accounts/_form.html.erb +2 -2
- data/app/views/kaui/accounts/index.html.erb +2 -0
- data/app/views/kaui/admin_allowed_users/_form.html.erb +3 -3
- data/app/views/kaui/admin_tenants/_form_catalog_translation.erb +1 -1
- data/app/views/kaui/admin_tenants/_form_invoice_template.erb +1 -1
- data/app/views/kaui/admin_tenants/_form_invoice_translation.erb +1 -1
- data/app/views/kaui/admin_tenants/_show_catalog_simple.erb +11 -5
- data/app/views/kaui/admin_tenants/new_catalog.html.erb +2 -2
- data/app/views/kaui/admin_tenants/new_overdue_config.html.erb +2 -2
- data/app/views/kaui/admin_tenants/new_plan_currency.html.erb +1 -1
- data/app/views/kaui/bundles/index.html.erb +1 -1
- data/app/views/kaui/bundles/transfer.html.erb +13 -5
- data/app/views/kaui/invoices/_invoice_table.html.erb +1 -1
- data/app/views/kaui/layouts/kaui_flash.html.erb +24 -0
- data/app/views/kaui/layouts/kaui_header.html.erb +19 -2
- data/app/views/kaui/payment_methods/_payment_methods_details_table.html.erb +13 -4
- data/app/views/kaui/payments/_payment_table.html.erb +21 -11
- data/app/views/kaui/payments/index.html.erb +9 -9
- data/app/views/kaui/queues/index.html.erb +1 -1
- data/app/views/kaui/subscriptions/_cancel_by_date_modal.html.erb +1 -4
- data/app/views/kaui/subscriptions/_edit_form.html.erb +1 -1
- data/app/views/kaui/subscriptions/_form.html.erb +1 -1
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +3 -3
- data/app/views/kaui/subscriptions/edit_bcd.erb +1 -1
- data/app/views/kaui/tag_definitions/index.html.erb +2 -2
- data/app/views/kaui/tags/index.html.erb +1 -0
- data/config/initializers/bootstrap_datepicker_rails.rb +3 -0
- data/config/initializers/devise.rb +8 -6
- data/config/initializers/js_routes.rb +9 -0
- data/config/initializers/kilbill_client_init.rb +13 -0
- data/config/initializers/killbill_authenticatable.rb +71 -21
- data/config/initializers/killbill_registerable.rb +5 -3
- data/config/initializers/time_formats.rb +6 -4
- data/config/locales/en.yml +78 -1
- data/config/routes.rb +34 -32
- data/db/migrate/20130812155313_devise_create_kaui_users.rb +10 -8
- data/db/migrate/20150109214021_create_kaui_tenants.rb +10 -8
- data/db/migrate/20150112232813_create_kaui_allowed_users.rb +10 -8
- data/lib/generators/kaui/install/install_generator.rb +23 -20
- data/lib/generators/kaui/install/templates/config/initializers/kaui.rb +3 -1
- data/lib/kaui/engine.rb +17 -5
- data/lib/kaui/installer/installer.rb +27 -26
- data/lib/kaui/version.rb +3 -1
- data/lib/kaui.rb +28 -30
- data/lib/tasks/kaui_tasks.rake +1 -0
- metadata +136 -438
- data/app/assets/javascripts/application.js +0 -17
- data/app/assets/javascripts/kaui/bootstrap-tweaks.js +0 -172
- data/app/assets/stylesheets/bootstrap_and_overrides.css.less +0 -44
- data/app/assets/stylesheets/kaui/kaui.less +0 -21
- data/app/assets/stylesheets/kaui/timeline.less +0 -4
- data/config/initializers/asset.rb +0 -1
- data/config/initializers/kilbill-client-init.rb +0 -9
- data/db/schema.rb +0 -15
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/controllers/application_controller.rb +0 -9
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/bin/bundle +0 -3
- data/test/dummy/bin/rails +0 -4
- data/test/dummy/bin/rake +0 -4
- data/test/dummy/bin/setup +0 -38
- data/test/dummy/bin/update +0 -29
- data/test/dummy/bin/yarn +0 -11
- data/test/dummy/config/application.rb +0 -18
- data/test/dummy/config/boot.rb +0 -3
- data/test/dummy/config/database.yml +0 -27
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -58
- data/test/dummy/config/environments/production.rb +0 -91
- data/test/dummy/config/environments/test.rb +0 -49
- data/test/dummy/config/initializers/application_controller_renderer.rb +0 -6
- data/test/dummy/config/initializers/assets.rb +0 -14
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/cookies_serializer.rb +0 -5
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/killbill_client.rb +0 -1
- data/test/dummy/config/initializers/mime_types.rb +0 -4
- data/test/dummy/config/initializers/money.rb +0 -2
- data/test/dummy/config/initializers/new_framework_defaults_5_1.rb +0 -14
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -33
- data/test/dummy/config/routes.rb +0 -3
- data/test/dummy/config/secrets.yml +0 -32
- data/test/dummy/config/symmetric-encryption.yml +0 -135
- data/test/dummy/config.ru +0 -4
- data/test/dummy/db/schema.rb +0 -52
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/fixtures/SpyCarAdvanced.xml +0 -824
- data/test/fixtures/catalog-v1.xml +0 -73
- data/test/fixtures/catalog_translation_fr-v1.properties +0 -1
- data/test/fixtures/invoice_template-v1.html +0 -100
- data/test/fixtures/invoice_translation_fr-v1.properties +0 -23
- data/test/fixtures/overdue-v1.xml +0 -49
- data/test/fixtures/stripe.yml +0 -2
- data/test/functional/kaui/account_children_controller_test.rb +0 -32
- data/test/functional/kaui/account_custom_fields_controller_test.rb +0 -29
- data/test/functional/kaui/account_emails_controller_test.rb +0 -55
- data/test/functional/kaui/account_tags_controller_test.rb +0 -48
- data/test/functional/kaui/account_timelines_controller_test.rb +0 -20
- data/test/functional/kaui/accounts_controller_test.rb +0 -297
- data/test/functional/kaui/admin_allowed_users_controller_test.rb +0 -234
- data/test/functional/kaui/admin_controller_test.rb +0 -45
- data/test/functional/kaui/admin_tenants_controller_test.rb +0 -352
- data/test/functional/kaui/audit_logs_controller_test.rb +0 -71
- data/test/functional/kaui/bundle_tags_controller_test.rb +0 -23
- data/test/functional/kaui/bundles_controller_test.rb +0 -130
- data/test/functional/kaui/chargebacks_controller_test.rb +0 -42
- data/test/functional/kaui/charges_controller_test.rb +0 -60
- data/test/functional/kaui/credits_controller_test.rb +0 -54
- data/test/functional/kaui/custom_fields_controller_test.rb +0 -52
- data/test/functional/kaui/functional_test_helper.rb +0 -13
- data/test/functional/kaui/functional_test_helper_nosetup.rb +0 -120
- data/test/functional/kaui/home_controller_test.rb +0 -407
- data/test/functional/kaui/invoice_items_controller_test.rb +0 -82
- data/test/functional/kaui/invoices_controller_test.rb +0 -88
- data/test/functional/kaui/login_proxy_controller_test.rb +0 -12
- data/test/functional/kaui/payment_methods_controller_test.rb +0 -52
- data/test/functional/kaui/payments_controller_test.rb +0 -59
- data/test/functional/kaui/queues_controller_test.rb +0 -17
- data/test/functional/kaui/refunds_controller_test.rb +0 -63
- data/test/functional/kaui/registrations_controller_test.rb +0 -49
- data/test/functional/kaui/role_definitions_controller_test.rb +0 -47
- data/test/functional/kaui/subscriptions_controller_test.rb +0 -194
- data/test/functional/kaui/tag_definitions_controller_test.rb +0 -29
- data/test/functional/kaui/tags_controller_test.rb +0 -21
- data/test/functional/kaui/tenants_controller_test.rb +0 -60
- data/test/functional/kaui/transactions_controller_test.rb +0 -90
- data/test/integration/kaui/date_helper_integration_test.rb +0 -16
- data/test/integration/kaui/integration_test_helper.rb +0 -32
- data/test/integration/kaui/navigation_test.rb +0 -43
- data/test/killbill_test_helper.rb +0 -219
- data/test/test_helper.rb +0 -22
- data/test/unit/helpers/kaui/admin_allowed_users_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/admin_tenants_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/payment_method_helper_test.rb +0 -17
- data/test/unit/helpers/kaui/tenants_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/uuid_helper_test.rb +0 -16
- data/test/unit/kaui/account_email_test.rb +0 -19
- data/test/unit/kaui/account_test.rb +0 -14
- data/test/unit/kaui/admin_tenant_test.rb +0 -132
- data/test/unit/kaui/allowed_user_test.rb +0 -34
- data/test/unit/kaui/base_test.rb +0 -23
- data/test/unit/kaui/date_helper_test.rb +0 -26
- data/test/unit/kaui/invoice_item_test.rb +0 -11
- data/test/unit/kaui/invoice_payment_test.rb +0 -42
- data/test/unit/kaui/invoice_test.rb +0 -20
- data/test/unit/kaui/money_helper_test.rb +0 -16
- data/test/unit/kaui/payment_test.rb +0 -42
- data/test/unit/kaui/tag_definition_test.rb +0 -11
- data/test/unit/kaui/tenant_test.rb +0 -19
- /data/app/assets/stylesheets/{application.css → kaui_application.css} +0 -0
@@ -1,288 +1,301 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module Kaui
|
4
|
+
class HomeController < Kaui::EngineController
|
5
|
+
QUERY_PARSE_REGEX = ['FIND:(?<object_type>.*) BY:(?<search_by>.*) FOR:(?<search_for>.*) ONLY_FIRST:(?<fast>.*)',
|
6
|
+
'FIND:(?<object_type>.*) BY:(?<search_by>.*) FOR:(?<search_for>.*)',
|
7
|
+
'FIND:(?<object_type>.*) FOR:(?<search_for>.*) ONLY_FIRST:(?<fast>.*)',
|
8
|
+
'FIND:(?<object_type>.*) FOR:(?<search_for>.*)'].freeze
|
7
9
|
|
8
|
-
|
10
|
+
SIMPLE_PARSE_REGEX = '(?<search_for>.*)'
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
def index
|
13
|
+
@search_query = params[:q]
|
14
|
+
end
|
15
|
+
|
16
|
+
def search
|
17
|
+
object_type, search_query, search_by, fast = parse_query(params[:q])
|
13
18
|
|
14
|
-
|
15
|
-
object_type, search_query, search_by, fast = parse_query(params[:q])
|
19
|
+
return if object_type.nil?
|
16
20
|
|
17
|
-
unless object_type.nil?
|
18
21
|
cached_options_for_klient = options_for_klient
|
19
22
|
send("#{object_type}_search", search_query, search_by, fast, cached_options_for_klient)
|
20
23
|
end
|
21
|
-
end
|
22
24
|
|
23
|
-
|
25
|
+
private
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
account = Kaui::Account.list_or_search(search_query, 0, 1, options).first
|
42
|
-
if account.blank?
|
43
|
-
search_error("No account matches \"#{search_query}\"")
|
44
|
-
elsif true?(fast)
|
45
|
-
redirect_to account_path(account.account_id) and return
|
27
|
+
def account_search(search_query, search_by = nil, fast = 0, options = {})
|
28
|
+
if search_by == 'ID'
|
29
|
+
begin
|
30
|
+
account = Kaui::Account.find_by_id(search_query, false, false, options)
|
31
|
+
redirect_to account_path(account.account_id) and return
|
32
|
+
rescue KillBillClient::API::NotFound => _e
|
33
|
+
search_error("No account matches \"#{search_query}\"")
|
34
|
+
end
|
35
|
+
elsif search_by == 'EXTERNAL_KEY'
|
36
|
+
begin
|
37
|
+
account = Kaui::Account.find_by_external_key(search_query, false, false, options)
|
38
|
+
redirect_to account_path(account.account_id) and return
|
39
|
+
rescue KillBillClient::API::NotFound => _e
|
40
|
+
search_error("No account matches \"#{search_query}\"")
|
41
|
+
end
|
46
42
|
else
|
47
|
-
|
43
|
+
account = Kaui::Account.list_or_search(search_query, 0, 1, options).first
|
44
|
+
if account.blank?
|
45
|
+
search_error("No account matches \"#{search_query}\"")
|
46
|
+
elsif true?(fast)
|
47
|
+
redirect_to account_path(account.account_id) and return
|
48
|
+
else
|
49
|
+
redirect_to accounts_path(q: search_query, fast:) and return
|
50
|
+
end
|
48
51
|
end
|
49
52
|
end
|
50
|
-
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
begin
|
55
|
-
invoice = Kaui::Invoice.find_by_id(search_query, 'NONE', options)
|
56
|
-
redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id) and return
|
57
|
-
rescue KillBillClient::API::NotFound => _
|
58
|
-
search_error("No invoice matches \"#{search_query}\"")
|
59
|
-
end
|
60
|
-
elsif search_by == 'EXTERNAL_KEY'
|
61
|
-
unsupported_external_key_search('INVOICE')
|
62
|
-
else
|
63
|
-
invoice = Kaui::Invoice.list_or_search(search_query, 0, 1, options).first
|
64
|
-
if invoice.blank?
|
54
|
+
def invoice_search(search_query, search_by = nil, fast = 0, options = {})
|
55
|
+
if search_by == 'ID'
|
65
56
|
begin
|
66
|
-
invoice = Kaui::Invoice.
|
57
|
+
invoice = Kaui::Invoice.find_by_id(search_query, 'NONE', options)
|
67
58
|
redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id) and return
|
68
|
-
rescue KillBillClient::API::NotFound =>
|
59
|
+
rescue KillBillClient::API::NotFound => _e
|
69
60
|
search_error("No invoice matches \"#{search_query}\"")
|
70
61
|
end
|
71
|
-
elsif
|
72
|
-
|
62
|
+
elsif search_by == 'EXTERNAL_KEY'
|
63
|
+
unsupported_external_key_search('INVOICE')
|
73
64
|
else
|
74
|
-
|
65
|
+
invoice = Kaui::Invoice.list_or_search(search_query, 0, 1, options).first
|
66
|
+
if invoice.blank?
|
67
|
+
begin
|
68
|
+
invoice = Kaui::Invoice.find_by_invoice_item_id(search_query, false, 'NONE', options)
|
69
|
+
redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id) and return
|
70
|
+
rescue KillBillClient::API::NotFound => _e
|
71
|
+
search_error("No invoice matches \"#{search_query}\"")
|
72
|
+
end
|
73
|
+
elsif true?(fast)
|
74
|
+
redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id) and return
|
75
|
+
else
|
76
|
+
redirect_to account_invoices_path(account_id: invoice.account_id, q: search_query, fast:) and return
|
77
|
+
end
|
75
78
|
end
|
76
79
|
end
|
77
|
-
end
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
else
|
95
|
-
payment = Kaui::Payment.list_or_search(search_query, 0, 1, options).first
|
96
|
-
if payment.blank?
|
97
|
-
search_error("No payment matches \"#{search_query}\"")
|
98
|
-
elsif true?(fast)
|
99
|
-
redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
|
81
|
+
def payment_search(search_query, search_by = nil, fast = 0, options = {})
|
82
|
+
if search_by == 'ID'
|
83
|
+
begin
|
84
|
+
payment = Kaui::Payment.find_by_id(search_query, false, false, options)
|
85
|
+
redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
|
86
|
+
rescue KillBillClient::API::NotFound => _e
|
87
|
+
search_error("No payment matches \"#{search_query}\"")
|
88
|
+
end
|
89
|
+
elsif search_by == 'EXTERNAL_KEY'
|
90
|
+
begin
|
91
|
+
payment = Kaui::Payment.find_by_external_key(search_query, false, false, options)
|
92
|
+
redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
|
93
|
+
rescue KillBillClient::API::NotFound => _e
|
94
|
+
search_error("No payment matches \"#{search_query}\"")
|
95
|
+
end
|
100
96
|
else
|
101
|
-
|
97
|
+
payment = Kaui::Payment.list_or_search(search_query, 0, 1, options).first
|
98
|
+
if payment.blank?
|
99
|
+
search_error("No payment matches \"#{search_query}\"")
|
100
|
+
elsif true?(fast)
|
101
|
+
redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
|
102
|
+
else
|
103
|
+
redirect_to account_payments_path(account_id: payment.account_id, q: search_query, fast:) and return
|
104
|
+
end
|
102
105
|
end
|
103
106
|
end
|
104
|
-
end
|
105
107
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
108
|
+
def transaction_search(search_query, search_by = nil, _fast = 0, options = {})
|
109
|
+
if search_by.blank? || search_by == 'ID'
|
110
|
+
begin
|
111
|
+
payment = Kaui::Payment.find_by_transaction_id(search_query, false, true, options)
|
112
|
+
redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
|
113
|
+
rescue KillBillClient::API::NotFound => _e
|
114
|
+
search_error("No transaction matches \"#{search_query}\"")
|
115
|
+
end
|
116
|
+
else
|
117
|
+
begin
|
118
|
+
payment = Kaui::Payment.find_by_transaction_external_key(search_query, false, true, 'NONE', options)
|
119
|
+
redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
|
120
|
+
rescue KillBillClient::API::NotFound => _e
|
121
|
+
search_error("No transaction matches \"#{search_query}\"")
|
122
|
+
end
|
120
123
|
end
|
121
124
|
end
|
122
|
-
end
|
123
125
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
else
|
140
|
-
bundle = Kaui::Bundle.list_or_search(search_query, 0, 1, options).first
|
141
|
-
if bundle.blank?
|
142
|
-
search_error("No bundle matches \"#{search_query}\"")
|
126
|
+
def bundle_search(search_query, search_by = nil, _fast = 0, options = {})
|
127
|
+
if search_by == 'ID'
|
128
|
+
begin
|
129
|
+
bundle = Kaui::Bundle.find_by_id(search_query, options)
|
130
|
+
redirect_to kaui_engine.account_bundles_path(bundle.account_id)
|
131
|
+
rescue KillBillClient::API::NotFound => _e
|
132
|
+
search_error("No bundle matches \"#{search_query}\"")
|
133
|
+
end
|
134
|
+
elsif search_by == 'EXTERNAL_KEY'
|
135
|
+
begin
|
136
|
+
bundle = Kaui::Bundle.find_by_external_key(search_query, false, options)
|
137
|
+
redirect_to kaui_engine.account_bundles_path(bundle.account_id) and return
|
138
|
+
rescue KillBillClient::API::NotFound => _e
|
139
|
+
search_error("No bundle matches \"#{search_query}\"")
|
140
|
+
end
|
143
141
|
else
|
144
|
-
|
142
|
+
bundle = Kaui::Bundle.list_or_search(search_query, 0, 1, options).first
|
143
|
+
if bundle.blank?
|
144
|
+
search_error("No bundle matches \"#{search_query}\"")
|
145
|
+
else
|
146
|
+
redirect_to kaui_engine.account_bundles_path(bundle.account_id)
|
147
|
+
end
|
145
148
|
end
|
146
149
|
end
|
147
|
-
end
|
148
150
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
151
|
+
def credit_search(search_query, search_by = nil, _fast = 0, options = {})
|
152
|
+
if search_by.blank? || search_by == 'ID'
|
153
|
+
begin
|
154
|
+
credit = Kaui::Credit.find_by_id(search_query, options)
|
155
|
+
redirect_to account_invoice_path(credit.account_id, credit.invoice_id) and return
|
156
|
+
rescue KillBillClient::API::NotFound => _e
|
157
|
+
search_error("No credit matches \"#{search_query}\"")
|
158
|
+
end
|
159
|
+
else
|
160
|
+
unsupported_external_key_search('CREDIT')
|
156
161
|
end
|
157
|
-
else
|
158
|
-
unsupported_external_key_search('CREDIT')
|
159
162
|
end
|
160
|
-
end
|
161
163
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
164
|
+
def custom_field_search(search_query, search_by = nil, fast = 0, options = {})
|
165
|
+
if search_by.blank? || search_by == 'ID'
|
166
|
+
custom_field = Kaui::CustomField.list_or_search(search_query, 0, 1, options)
|
167
|
+
if custom_field.blank?
|
168
|
+
search_error("No custom field matches \"#{search_query}\"")
|
169
|
+
else
|
170
|
+
redirect_to custom_fields_path(q: search_query, fast:)
|
171
|
+
end
|
167
172
|
else
|
168
|
-
|
173
|
+
unsupported_external_key_search('CUSTOM FIELD')
|
169
174
|
end
|
170
|
-
else
|
171
|
-
unsupported_external_key_search('CUSTOM FIELD')
|
172
175
|
end
|
173
|
-
end
|
174
176
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
177
|
+
def invoice_payment_search(search_query, search_by = nil, _fast = 0, options = {})
|
178
|
+
if search_by.blank? || search_by == 'ID'
|
179
|
+
begin
|
180
|
+
invoice_payment = Kaui::InvoicePayment.find_safely_by_id(search_query, options)
|
181
|
+
redirect_to account_payment_path(invoice_payment.account_id, invoice_payment.payment_id) and return
|
182
|
+
rescue KillBillClient::API::NotFound => _e
|
183
|
+
search_error("No invoice payment matches \"#{search_query}\"")
|
184
|
+
end
|
185
|
+
else
|
186
|
+
unsupported_external_key_search('INVOICE PAYMENT')
|
182
187
|
end
|
183
|
-
else
|
184
|
-
unsupported_external_key_search('INVOICE PAYMENT')
|
185
188
|
end
|
186
|
-
end
|
187
189
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
190
|
+
def subscription_search(search_query, search_by = nil, _fast = 0, options = {})
|
191
|
+
if search_by.blank? || search_by == 'ID'
|
192
|
+
begin
|
193
|
+
subscription = Kaui::Subscription.find_by_id(search_query, options)
|
194
|
+
redirect_to account_bundles_path(subscription.account_id) and return
|
195
|
+
rescue KillBillClient::API::NotFound => _e
|
196
|
+
search_error("No subscription matches \"#{search_query}\"")
|
197
|
+
end
|
198
|
+
else
|
199
|
+
unsupported_external_key_search('SUBSCRIPTION')
|
195
200
|
end
|
196
|
-
else
|
197
|
-
unsupported_external_key_search('SUBSCRIPTION')
|
198
201
|
end
|
199
|
-
end
|
200
202
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
203
|
+
def tag_search(search_query, search_by = nil, fast = 0, options = {})
|
204
|
+
if search_by.blank? || search_by == 'ID'
|
205
|
+
tag = Kaui::Tag.list_or_search(search_query, 0, 1, options)
|
206
|
+
if tag.blank?
|
207
|
+
search_error("No tag matches \"#{search_query}\"")
|
208
|
+
else
|
209
|
+
redirect_to tags_path(q: search_query, fast:)
|
210
|
+
end
|
206
211
|
else
|
207
|
-
|
212
|
+
unsupported_external_key_search('TAG')
|
208
213
|
end
|
209
|
-
else
|
210
|
-
unsupported_external_key_search('TAG')
|
211
214
|
end
|
212
|
-
end
|
213
215
|
|
214
|
-
|
215
|
-
|
216
|
-
begin
|
217
|
-
Kaui::TagDefinition.find_by_id(search_query, 'NONE', options)
|
218
|
-
redirect_to tag_definitions_path(:q => search_query, :fast => fast) and return
|
219
|
-
rescue KillBillClient::API::NotFound => _
|
220
|
-
search_error("No tag definition matches \"#{search_query}\"")
|
221
|
-
end
|
222
|
-
elsif search_by == 'EXTERNAL_KEY'
|
223
|
-
unsupported_external_key_search('TAG DEFINITION')
|
224
|
-
else
|
225
|
-
tag_definition = Kaui::TagDefinition.find_by_name(search_query, 'NONE', options)
|
226
|
-
if tag_definition.blank?
|
216
|
+
def tag_definition_search(search_query, search_by = nil, fast = 0, options = {})
|
217
|
+
if search_by == 'ID'
|
227
218
|
begin
|
228
219
|
Kaui::TagDefinition.find_by_id(search_query, 'NONE', options)
|
229
|
-
redirect_to tag_definitions_path(:
|
230
|
-
rescue KillBillClient::API::NotFound =>
|
220
|
+
redirect_to tag_definitions_path(q: search_query, fast:)
|
221
|
+
rescue KillBillClient::API::NotFound => _e
|
231
222
|
search_error("No tag definition matches \"#{search_query}\"")
|
232
223
|
end
|
224
|
+
elsif search_by == 'EXTERNAL_KEY'
|
225
|
+
unsupported_external_key_search('TAG DEFINITION')
|
233
226
|
else
|
234
|
-
|
227
|
+
tag_definition = Kaui::TagDefinition.find_by_name(search_query, 'NONE', options)
|
228
|
+
if tag_definition.blank?
|
229
|
+
begin
|
230
|
+
Kaui::TagDefinition.find_by_id(search_query, 'NONE', options)
|
231
|
+
redirect_to tag_definitions_path(q: search_query, fast:) and return
|
232
|
+
rescue KillBillClient::API::NotFound => _e
|
233
|
+
search_error("No tag definition matches \"#{search_query}\"")
|
234
|
+
end
|
235
|
+
else
|
236
|
+
redirect_to tag_definitions_path(q: search_query, fast:)
|
237
|
+
end
|
235
238
|
end
|
236
239
|
end
|
237
|
-
end
|
238
240
|
|
239
|
-
|
240
|
-
|
241
|
-
|
241
|
+
def unsupported_external_key_search(object_type)
|
242
|
+
search_error("\"#{object_type}\": Search by \"EXTERNAL KEY\" is not supported.")
|
243
|
+
end
|
242
244
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
245
|
+
def search_error(message)
|
246
|
+
flash[:error] = message
|
247
|
+
redirect_to kaui_engine.home_path
|
248
|
+
end
|
247
249
|
|
248
|
-
|
249
|
-
|
250
|
+
def parse_query(query)
|
251
|
+
statements, simple_regex_used = regex_parse_query(query)
|
252
|
+
|
253
|
+
object_type = begin
|
254
|
+
statements[:object_type].strip.downcase
|
255
|
+
rescue StandardError
|
256
|
+
'account'
|
257
|
+
end
|
258
|
+
search_for = statements[:search_for].strip
|
259
|
+
search_by = begin
|
260
|
+
statements[:search_by].strip.upcase
|
261
|
+
rescue StandardError
|
262
|
+
simple_regex_used && uuid?(search_for) ? 'ID' : nil
|
263
|
+
end
|
264
|
+
fast = begin
|
265
|
+
statements[:fast]
|
266
|
+
rescue StandardError
|
267
|
+
'0'
|
268
|
+
end
|
250
269
|
|
251
|
-
|
252
|
-
search_for = statements[:search_for].strip
|
253
|
-
search_by = statements[:search_by].strip.upcase rescue simple_regex_used && uuid?(search_for) ? 'ID' : nil
|
254
|
-
fast = statements[:fast] rescue '0'
|
270
|
+
search_error("\"#{search_by}\" is not a valid search by value") if !search_by.blank? && !%w[ID EXTERNAL_KEY].include?(search_by)
|
255
271
|
|
256
|
-
|
257
|
-
search_error("\"#{search_by}\" is not a valid search by value")
|
272
|
+
[object_type, search_for, search_by, fast]
|
258
273
|
end
|
259
274
|
|
260
|
-
|
261
|
-
|
275
|
+
def regex_parse_query(query)
|
276
|
+
statements = nil
|
277
|
+
simple_regex_used = false
|
278
|
+
QUERY_PARSE_REGEX.each do |query_regex|
|
279
|
+
regex_exp = Regexp.new(query_regex, true)
|
280
|
+
statements = regex_exp.match(query)
|
281
|
+
break unless statements.nil?
|
282
|
+
end
|
262
283
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
statements = regex_exp.match(query)
|
269
|
-
break unless statements.nil?
|
270
|
-
end
|
284
|
+
if statements.nil?
|
285
|
+
regex_exp = Regexp.new(SIMPLE_PARSE_REGEX, true)
|
286
|
+
statements = regex_exp.match(query)
|
287
|
+
simple_regex_used = true
|
288
|
+
end
|
271
289
|
|
272
|
-
|
273
|
-
regex_exp = Regexp.new(SIMPLE_PARSE_REGEX, true)
|
274
|
-
statements = regex_exp.match(query)
|
275
|
-
simple_regex_used = true
|
290
|
+
[statements, simple_regex_used]
|
276
291
|
end
|
277
292
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
def true?(statement)
|
282
|
-
[1,'1',true,'true'].include? ((statement.instance_of? String) ? statement.downcase : statement)
|
283
|
-
end
|
293
|
+
def true?(statement)
|
294
|
+
[1, '1', true, 'true'].include?(statement.instance_of?(String) ? statement.downcase : statement)
|
295
|
+
end
|
284
296
|
|
285
|
-
|
286
|
-
|
297
|
+
def uuid?(value)
|
298
|
+
value =~ /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/
|
299
|
+
end
|
287
300
|
end
|
288
301
|
end
|
@@ -1,54 +1,58 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module Kaui
|
4
|
+
class InvoiceItemsController < Kaui::EngineController
|
5
|
+
def edit
|
6
|
+
invoice_item_id = params.require(:id)
|
7
|
+
invoice_id = params.require(:invoice_id)
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
# See https://github.com/killbill/killbill/issues/7
|
10
|
+
invoice = Kaui::Invoice.find_by_id(invoice_id, 'NONE', options_for_klient)
|
11
|
+
@invoice_item = invoice.items.find { |ii| ii.invoice_item_id == invoice_item_id }
|
12
|
+
|
13
|
+
return unless @invoice_item.nil?
|
10
14
|
|
11
|
-
if @invoice_item.nil?
|
12
15
|
flash[:error] = "Unable to find invoice item #{invoice_item_id}"
|
13
16
|
redirect_to account_invoice_path(params.require(:account_id), invoice_id)
|
14
17
|
end
|
15
|
-
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
def update
|
20
|
+
@invoice_item = Kaui::InvoiceItem.new(params.require(:invoice_item))
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
begin
|
23
|
+
invoice = @invoice_item.update(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
24
|
+
redirect_to kaui_engine.account_invoice_path(invoice.account_id, invoice.invoice_id), notice: 'Adjustment item was successfully created'
|
25
|
+
rescue StandardError => e
|
26
|
+
flash.now[:error] = "Error while adjusting invoice item: #{as_string(e)}"
|
27
|
+
render action: :edit
|
28
|
+
end
|
26
29
|
end
|
27
|
-
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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'
|
36
|
-
end
|
31
|
+
def destroy
|
32
|
+
invoice_item = Kaui::InvoiceItem.new(invoice_item_id: params.require(:id),
|
33
|
+
invoice_id: params.require(:invoice_id),
|
34
|
+
account_id: params.require(:account_id))
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
invoice_id = params.require(:invoice_id)
|
41
|
-
account_id = params.require(:account_id)
|
42
|
-
@invoice_item.account_id = account_id
|
43
|
-
|
44
|
-
tags = []
|
45
|
-
params.each do |tag|
|
46
|
-
tag_info = tag.split('_')
|
47
|
-
next if tag_info.size != 2 or tag_info[0] != 'tag'
|
48
|
-
tags << tag_info[1]
|
36
|
+
invoice_item.delete(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
37
|
+
redirect_to kaui_engine.account_invoice_path(invoice_item.account_id, invoice_item.invoice_id), notice: 'CBA item was successfully deleted'
|
49
38
|
end
|
50
39
|
|
51
|
-
|
52
|
-
|
40
|
+
def update_tags
|
41
|
+
@invoice_item = Kaui::InvoiceItem.new(invoice_item_id: params.require(:id))
|
42
|
+
invoice_id = params.require(:invoice_id)
|
43
|
+
account_id = params.require(:account_id)
|
44
|
+
@invoice_item.account_id = account_id
|
45
|
+
|
46
|
+
tags = []
|
47
|
+
params.each do |tag|
|
48
|
+
tag_info = tag.split('_')
|
49
|
+
next if (tag_info.size != 2) || (tag_info[0] != 'tag')
|
50
|
+
|
51
|
+
tags << tag_info[1]
|
52
|
+
end
|
53
|
+
|
54
|
+
@invoice_item.set_tags(tags, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
55
|
+
redirect_to account_invoice_path(account_id, invoice_id), notice: 'Invoice Item tags successfully set'
|
56
|
+
end
|
53
57
|
end
|
54
58
|
end
|