kaui 2.0.4 → 2.2.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 -23
- 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} +13 -1
- data/app/assets/stylesheets/kaui/{audit.less → audit.scss} +5 -1
- data/app/assets/stylesheets/kaui/{common.less → common.scss} +19 -17
- 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 +269 -255
- 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 +87 -84
- 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 +134 -114
- 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 +32 -0
- data/app/controllers/kaui/invoices_controller.rb +134 -88
- data/app/controllers/kaui/login_proxy_controller.rb +2 -1
- data/app/controllers/kaui/payment_methods_controller.rb +103 -90
- 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 +22 -12
- data/app/helpers/kaui/application_helper.rb +8 -3
- data/app/helpers/kaui/date_helper.rb +3 -2
- 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 -5
- 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 +5 -1
- data/app/views/kaui/accounts/_form.html.erb +2 -2
- data/app/views/kaui/accounts/_payment_methods.html.erb +3 -0
- data/app/views/kaui/accounts/index.html.erb +9 -4
- 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/_form_plugin_config.erb +13 -3
- 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/_bundle_details.html.erb +12 -0
- data/app/views/kaui/bundles/index.html.erb +3 -14
- data/app/views/kaui/bundles/transfer.html.erb +13 -5
- data/app/views/kaui/invoice_tags/_form.html.erb +33 -0
- data/app/views/kaui/invoice_tags/_form_bar.html.erb +21 -0
- data/app/views/kaui/invoice_tags/edit.html.erb +10 -0
- data/app/views/kaui/invoices/_invoice_table.html.erb +29 -8
- data/app/views/kaui/invoices/index.html.erb +6 -4
- data/app/views/kaui/invoices/show.html.erb +10 -1
- data/app/views/kaui/layouts/kaui_flash.html.erb +32 -1
- 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 +12 -10
- 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 +40 -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 +74 -30
- data/lib/tasks/kaui_tasks.rake +1 -0
- metadata +145 -440
- 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/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 -217
- 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,332 +1,346 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
if
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kaui
|
4
|
+
class AccountsController < Kaui::EngineController
|
5
|
+
def index
|
6
|
+
@search_query = params[:q]
|
7
|
+
|
8
|
+
if params[:fast] == '1' && !@search_query.blank?
|
9
|
+
account = Kaui::Account.list_or_search(@search_query, -1, 1, options_for_klient).first
|
10
|
+
if account.nil?
|
11
|
+
flash[:error] = "No account matches \"#{@search_query}\""
|
12
|
+
redirect_to kaui_engine.home_path
|
13
|
+
else
|
14
|
+
redirect_to kaui_engine.account_path(account.account_id)
|
15
|
+
end
|
16
|
+
return
|
13
17
|
end
|
14
|
-
end
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
@ordering = params[:ordering] || (@search_query.blank? ? 'desc' : 'asc')
|
20
|
+
@offset = params[:offset] || 0
|
21
|
+
@limit = params[:limit] || 50
|
19
22
|
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
def pagination
|
24
|
-
cached_options_for_klient = options_for_klient
|
25
|
-
searcher = lambda do |search_key, offset, limit|
|
26
|
-
Kaui::Account.list_or_search(search_key, offset, limit, cached_options_for_klient)
|
23
|
+
@max_nb_records = @search_query.blank? ? Kaui::Account.list_or_search(nil, 0, 0, options_for_klient).pagination_max_nb_records : 0
|
27
24
|
end
|
28
25
|
|
29
|
-
|
30
|
-
|
26
|
+
def pagination
|
27
|
+
cached_options_for_klient = options_for_klient
|
28
|
+
searcher = lambda do |search_key, offset, limit|
|
29
|
+
Kaui::Account.list_or_search(search_key, offset, limit, cached_options_for_klient)
|
30
|
+
end
|
31
|
+
|
32
|
+
data_extractor = lambda do |account, column|
|
33
|
+
[
|
31
34
|
account.parent_account_id,
|
32
|
-
account.name,
|
33
35
|
account.account_id,
|
34
36
|
account.external_key,
|
35
|
-
account.account_balance
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
account.account_balance
|
38
|
+
][column]
|
39
|
+
end
|
40
|
+
|
41
|
+
formatter = lambda do |account|
|
42
|
+
child_label = ''
|
43
|
+
unless account.parent_account_id.nil?
|
44
|
+
child_label = account.parent_account_id.nil? ? '' : view_context.content_tag(:span, 'Child', class: %w[label label-info account-child-label])
|
45
|
+
end
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
child_label = account.parent_account_id.nil? ? '' : view_context.content_tag(:span, 'Child', class: ['label', 'label-info', 'account-child-label'])
|
47
|
+
row = [child_label, view_context.link_to(account.account_id, view_context.url_for(action: :show, account_id: account.account_id))]
|
48
|
+
row += Kaui.account_search_columns.call(account, view_context)[1]
|
49
|
+
row
|
45
50
|
end
|
46
51
|
|
47
|
-
|
48
|
-
child_label,
|
49
|
-
view_context.link_to(account.account_id, view_context.url_for(:action => :show, :account_id => account.account_id)),
|
50
|
-
account.external_key,
|
51
|
-
view_context.humanized_money_with_symbol(account.balance_to_money)
|
52
|
-
]
|
52
|
+
paginate searcher, data_extractor, formatter
|
53
53
|
end
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
def new
|
56
|
+
@account = Kaui::Account.new
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
end
|
59
|
+
def create
|
60
|
+
@account = Kaui::Account.new(params.require(:account).delete_if { |_key, value| value.blank? })
|
61
61
|
|
62
|
-
|
63
|
-
@account = Kaui::Account.new(params.require(:account).delete_if { |key, value| value.blank? })
|
62
|
+
@account.errors.add(:phone, :invalid_phone) if !@account.phone.nil? && !@account.check_account_details_phone
|
64
63
|
|
65
|
-
|
66
|
-
@account.is_migrated = @account.is_migrated == '1'
|
64
|
+
@account.errors.add(:check_account_details_bill_cycle_day_local, :invalid_bill_cycle_day_local) if !@account.bill_cycle_day_local.nil? && !@account.check_account_details_bill_cycle_day_local
|
67
65
|
|
68
|
-
|
69
|
-
|
66
|
+
unless @account.errors.empty?
|
67
|
+
flash.now[:errors] = @account.errors.messages.values.flatten
|
68
|
+
render action: :new and return
|
69
|
+
end
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
flash.now[:error] = "Error while creating account: #{as_string(e)}"
|
74
|
-
render :action => :new
|
75
|
-
end
|
76
|
-
end
|
71
|
+
# Transform "1" into boolean
|
72
|
+
@account.is_migrated = @account.is_migrated == '1'
|
77
73
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
fetch_children = promise { @account.children(false, false, 'NONE',cached_options_for_klient)}
|
86
|
-
fetch_parent = promise (!@account.parent_account_id.nil?){ Kaui::Account::find_by_id(@account.parent_account_id,false,false,cached_options_for_klient)}
|
87
|
-
fetch_overdue_state = promise { @account.overdue(cached_options_for_klient) }
|
88
|
-
fetch_account_tags = promise { @account.tags(false, 'NONE', cached_options_for_klient).sort { |tag_a, tag_b| tag_a <=> tag_b } }
|
89
|
-
fetch_account_fields = promise { @account.custom_fields('NONE', cached_options_for_klient).sort { |cf_a, cf_b| cf_a.name.downcase <=> cf_b.name.downcase } }
|
90
|
-
fetch_account_emails = promise { Kaui::AccountEmail.find_all_sorted_by_account_id(@account.account_id, 'NONE', cached_options_for_klient) }
|
91
|
-
fetch_payments = promise { @account.payments(cached_options_for_klient).map! { |payment| Kaui::Payment.build_from_raw_payment(payment) } }
|
92
|
-
fetch_payment_methods = promise(false) { Kaui::PaymentMethod.find_all_by_account_id(@account.account_id, false, cached_options_for_klient) }
|
93
|
-
|
94
|
-
# is email notification plugin available
|
95
|
-
is_email_notifications_plugin_available = Kenui::EmailNotificationService.email_notification_plugin_available?(cached_options_for_klient).first
|
96
|
-
fetch_email_notification_configuration = promise(is_email_notifications_plugin_available) do
|
97
|
-
Kenui::EmailNotificationService.get_configuration_per_account(params.require(:account_id),cached_options_for_klient)
|
98
|
-
end.then do |configuration|
|
99
|
-
if configuration.first.is_a?(FalseClass)
|
100
|
-
Rails.logger.warn(configuration[1])
|
101
|
-
configuration = []
|
74
|
+
begin
|
75
|
+
@account = @account.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
76
|
+
|
77
|
+
redirect_to account_path(@account.account_id), notice: 'Account was successfully created'
|
78
|
+
rescue StandardError => e
|
79
|
+
flash.now[:error] = "Error while creating account: #{as_string(e)}"
|
80
|
+
render action: :new
|
102
81
|
end
|
103
|
-
configuration
|
104
82
|
end
|
105
83
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
84
|
+
# rubocop:disable Style/MultilineBlockChain
|
85
|
+
def show
|
86
|
+
# Go to the database once
|
87
|
+
cached_options_for_klient = options_for_klient
|
88
|
+
|
89
|
+
# Re-fetch the account with balance and CBA
|
90
|
+
@account = Kaui::Account.find_by_id_or_key(params.require(:account_id), true, true, cached_options_for_klient)
|
91
|
+
|
92
|
+
fetch_children = promise { @account.children(false, false, 'NONE', cached_options_for_klient) }
|
93
|
+
fetch_parent = @account.parent_account_id.nil? ? nil : promise { Kaui::Account.find_by_id(@account.parent_account_id, false, false, cached_options_for_klient) }
|
94
|
+
fetch_overdue_state = promise { @account.overdue(cached_options_for_klient) }
|
95
|
+
fetch_account_tags = promise { @account.tags(false, 'NONE', cached_options_for_klient).sort { |tag_a, tag_b| tag_a <=> tag_b } }
|
96
|
+
fetch_account_fields = promise { @account.custom_fields('NONE', cached_options_for_klient).sort { |cf_a, cf_b| cf_a.name.downcase <=> cf_b.name.downcase } }
|
97
|
+
fetch_account_emails = promise { Kaui::AccountEmail.find_all_sorted_by_account_id(@account.account_id, 'NONE', cached_options_for_klient) }
|
98
|
+
fetch_payments = promise { @account.payments(cached_options_for_klient).map! { |payment| Kaui::Payment.build_from_raw_payment(payment) } }
|
99
|
+
fetch_payment_methods = promise { Kaui::PaymentMethod.find_all_by_account_id(@account.account_id, false, cached_options_for_klient) }
|
100
|
+
|
101
|
+
# is email notification plugin available
|
102
|
+
is_email_notifications_plugin_available = Kenui::EmailNotificationService.email_notification_plugin_available?(cached_options_for_klient).first
|
103
|
+
fetch_email_notification_configuration = if is_email_notifications_plugin_available
|
104
|
+
promise do
|
105
|
+
Kenui::EmailNotificationService.get_configuration_per_account(params.require(:account_id), cached_options_for_klient)
|
106
|
+
end.then do |configuration|
|
107
|
+
if configuration.first.is_a?(FalseClass)
|
108
|
+
Rails.logger.warn(configuration[1])
|
109
|
+
configuration = []
|
110
|
+
end
|
111
|
+
configuration
|
112
|
+
end
|
113
|
+
else
|
114
|
+
nil
|
115
|
+
end
|
116
|
+
|
117
|
+
fetch_payment_methods_with_details = fetch_payment_methods.then do |pms|
|
118
|
+
ops = []
|
119
|
+
pms.each do |pm|
|
120
|
+
ops << promise do
|
111
121
|
Kaui::PaymentMethod.find_by_id(pm.payment_method_id, true, cached_options_for_klient)
|
112
|
-
rescue => e
|
122
|
+
rescue StandardError => e
|
113
123
|
# Maybe the plugin is not registered or the plugin threw an exception
|
114
124
|
Rails.logger.warn(e)
|
115
125
|
nil
|
116
126
|
end
|
117
|
-
|
127
|
+
end
|
128
|
+
ops
|
118
129
|
end
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
last_seen_transaction_date = @last_transaction_by_payment_method_id[payment.payment_method_id]
|
140
|
-
if last_seen_transaction_date.nil? || Date.parse(last_seen_transaction_date.effective_date) < transaction_date
|
141
|
-
@last_transaction_by_payment_method_id[payment.payment_method_id] = transaction
|
130
|
+
fetch_available_tags = promise { Kaui::TagDefinition.all_for_account(cached_options_for_klient) }
|
131
|
+
|
132
|
+
@overdue_state = wait(fetch_overdue_state)
|
133
|
+
@tags = wait(fetch_account_tags)
|
134
|
+
@custom_fields = wait(fetch_account_fields)
|
135
|
+
@account_emails = wait(fetch_account_emails)
|
136
|
+
wait(fetch_payment_methods)
|
137
|
+
@payment_methods = wait(fetch_payment_methods_with_details).map { |pm_f| wait(pm_f) }.compact
|
138
|
+
@available_tags = wait(fetch_available_tags)
|
139
|
+
@children = wait(fetch_children)
|
140
|
+
@account_parent = @account.parent_account_id.nil? ? nil : wait(fetch_parent)
|
141
|
+
@email_notification_configuration = wait(fetch_email_notification_configuration) if is_email_notifications_plugin_available
|
142
|
+
|
143
|
+
@last_transaction_by_payment_method_id = {}
|
144
|
+
wait(fetch_payments).each do |payment|
|
145
|
+
transaction = payment.transactions.last
|
146
|
+
transaction_date = Date.parse(transaction.effective_date)
|
147
|
+
|
148
|
+
last_seen_transaction_date = @last_transaction_by_payment_method_id[payment.payment_method_id]
|
149
|
+
@last_transaction_by_payment_method_id[payment.payment_method_id] = transaction if last_seen_transaction_date.nil? || Date.parse(last_seen_transaction_date.effective_date) < transaction_date
|
142
150
|
end
|
151
|
+
|
152
|
+
params.permit!
|
143
153
|
end
|
154
|
+
# rubocop:enable Style/MultilineBlockChain
|
144
155
|
|
145
|
-
|
146
|
-
|
156
|
+
def destroy
|
157
|
+
account_id = params.require(:account_id)
|
158
|
+
options = params[:options] || []
|
147
159
|
|
148
|
-
|
149
|
-
|
150
|
-
|
160
|
+
cancel_subscriptions = options.include?('cancel_all_subscriptions')
|
161
|
+
writeoff_unpaid_invoices = options.include?('writeoff_unpaid_invoices')
|
162
|
+
item_adjust_unpaid_invoices = options.include?('item_adjust_unpaid_invoices')
|
163
|
+
cached_options_for_klient = options_for_klient
|
151
164
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
cached_options_for_klient = options_for_klient
|
165
|
+
begin
|
166
|
+
@account = Kaui::Account.find_by_id_or_key(account_id, false, false, cached_options_for_klient)
|
167
|
+
@account.close(cancel_subscriptions, writeoff_unpaid_invoices, item_adjust_unpaid_invoices, current_user.kb_username, nil, nil, cached_options_for_klient)
|
156
168
|
|
157
|
-
|
158
|
-
|
159
|
-
|
169
|
+
flash[:notice] = "Account #{account_id} successfully closed"
|
170
|
+
rescue StandardError => e
|
171
|
+
flash[:error] = "Error while closing account: #{as_string(e)}"
|
172
|
+
end
|
160
173
|
|
161
|
-
|
162
|
-
rescue => e
|
163
|
-
flash[:error] = "Error while closing account: #{as_string(e)}"
|
174
|
+
redirect_to account_path(account_id)
|
164
175
|
end
|
165
176
|
|
166
|
-
|
167
|
-
|
177
|
+
def trigger_invoice
|
178
|
+
account_id = params.require(:account_id)
|
179
|
+
target_date = params[:target_date].presence
|
180
|
+
dry_run = params[:dry_run].nil? ? false : params[:dry_run] == '1'
|
168
181
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
# Null invoice
|
180
|
-
end
|
182
|
+
invoice = nil
|
183
|
+
begin
|
184
|
+
invoice = if dry_run
|
185
|
+
Kaui::Invoice.trigger_invoice_dry_run(account_id, target_date, false, options_for_klient)
|
186
|
+
else
|
187
|
+
Kaui::Invoice.trigger_invoice(account_id, target_date, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
188
|
+
end
|
189
|
+
rescue KillBillClient::API::NotFound
|
190
|
+
# Null invoice
|
191
|
+
end
|
181
192
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
+
if invoice.nil?
|
194
|
+
redirect_to account_path(account_id), notice: "Nothing to generate for target date #{target_date.nil? ? 'today' : target_date}"
|
195
|
+
elsif dry_run
|
196
|
+
@invoice = Kaui::Invoice.build_from_raw_invoice(invoice)
|
197
|
+
@invoice_tags = []
|
198
|
+
@available_invoice_tags = []
|
199
|
+
@payments = []
|
200
|
+
@payment_methods = nil
|
201
|
+
@account = Kaui::Account.find_by_id(account_id, false, false, options_for_klient)
|
202
|
+
render template: 'kaui/invoices/show'
|
203
|
+
else
|
204
|
+
# Redirect to fetch payments, etc.
|
205
|
+
redirect_to invoice_path(invoice.invoice_id, account_id: account_id), notice: "Generated invoice #{invoice.invoice_number} for target date #{invoice.target_date}"
|
206
|
+
end
|
193
207
|
end
|
194
|
-
end
|
195
208
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
209
|
+
# Fetched asynchronously, as it takes time. This also helps with enforcing permissions.
|
210
|
+
def next_invoice_date
|
211
|
+
json_response do
|
212
|
+
next_invoice = Kaui::Invoice.trigger_invoice_dry_run(params.require(:account_id), nil, true, options_for_klient)
|
213
|
+
next_invoice ? next_invoice.target_date.to_json : nil
|
214
|
+
end
|
201
215
|
end
|
202
|
-
end
|
203
216
|
|
204
|
-
|
205
|
-
end
|
217
|
+
def edit; end
|
206
218
|
|
207
|
-
|
208
|
-
|
209
|
-
|
219
|
+
def update
|
220
|
+
@account = Kaui::Account.new(params.require(:account).delete_if { |_key, value| value.blank? })
|
221
|
+
@account.account_id = params.require(:account_id)
|
210
222
|
|
211
|
-
|
212
|
-
|
223
|
+
# Transform "1" into boolean
|
224
|
+
@account.is_migrated = @account.is_migrated == '1'
|
213
225
|
|
214
|
-
|
226
|
+
@account.update(true, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
215
227
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
228
|
+
redirect_to account_path(@account.account_id), notice: 'Account successfully updated'
|
229
|
+
rescue StandardError => e
|
230
|
+
flash.now[:error] = "Error while updating account: #{as_string(e)}"
|
231
|
+
render action: :edit
|
232
|
+
end
|
221
233
|
|
222
|
-
|
223
|
-
|
224
|
-
|
234
|
+
def set_default_payment_method
|
235
|
+
account_id = params.require(:account_id)
|
236
|
+
payment_method_id = params.require(:payment_method_id)
|
225
237
|
|
226
|
-
|
238
|
+
Kaui::PaymentMethod.set_default(payment_method_id, account_id, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
227
239
|
|
228
|
-
|
229
|
-
|
240
|
+
redirect_to account_path(account_id), notice: "Successfully set #{payment_method_id} as default"
|
241
|
+
end
|
230
242
|
|
231
|
-
|
232
|
-
|
243
|
+
def pay_all_invoices
|
244
|
+
payment = Kaui::InvoicePayment.new(account_id: params.require(:account_id))
|
233
245
|
|
234
|
-
|
246
|
+
payment.bulk_create(params[:is_external_payment] == 'true', nil, nil, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
235
247
|
|
236
|
-
|
237
|
-
|
248
|
+
redirect_to account_path(payment.account_id), notice: 'Successfully triggered a payment for all unpaid invoices'
|
249
|
+
end
|
238
250
|
|
239
|
-
|
240
|
-
|
241
|
-
|
251
|
+
def validate_external_key
|
252
|
+
json_response do
|
253
|
+
external_key = params.require(:external_key)
|
242
254
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
255
|
+
begin
|
256
|
+
account = Kaui::Account.find_by_external_key(external_key, false, false, options_for_klient)
|
257
|
+
rescue KillBillClient::API::NotFound
|
258
|
+
account = nil
|
259
|
+
end
|
260
|
+
{ is_found: !account.nil? }
|
247
261
|
end
|
248
|
-
{:is_found => !account.nil?}
|
249
262
|
end
|
250
|
-
end
|
251
263
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
264
|
+
def link_to_parent
|
265
|
+
@account = Kaui::Account.new(params.require(:account).delete_if { |_key, value| value.blank? })
|
266
|
+
@account.account_id = params.require(:account_id)
|
267
|
+
@account.is_payment_delegated_to_parent = @account.is_payment_delegated_to_parent == '1'
|
256
268
|
|
257
|
-
|
269
|
+
raise('Account id and account parent id cannot be equal.') if @account.account_id == @account.parent_account_id
|
258
270
|
|
259
|
-
|
271
|
+
cached_options_for_klient = options_for_klient
|
260
272
|
|
261
|
-
|
262
|
-
|
273
|
+
# check if parent id is valid
|
274
|
+
Kaui::Account.find_by_id(@account.parent_account_id, false, false, cached_options_for_klient)
|
263
275
|
|
264
|
-
|
276
|
+
@account.update(false, current_user.kb_username, params[:reason], params[:comment], cached_options_for_klient)
|
265
277
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
278
|
+
redirect_to account_path(@account.account_id), notice: 'Account successfully updated'
|
279
|
+
rescue StandardError => e
|
280
|
+
flash[:error] = if e.is_a?(KillBillClient::API::NotFound)
|
281
|
+
"Parent account id not found: #{@account.parent_account_id}"
|
282
|
+
else
|
283
|
+
"Error while linking parent account: #{as_string(e)}"
|
284
|
+
end
|
285
|
+
redirect_to account_path(@account.account_id)
|
272
286
|
end
|
273
|
-
redirect_to account_path(@account.account_id)
|
274
|
-
end
|
275
287
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
288
|
+
def unlink_to_parent
|
289
|
+
account_id = params.require(:account_id)
|
290
|
+
cached_options_for_klient = options_for_klient
|
291
|
+
|
292
|
+
# search for the account and remove the parent account id
|
293
|
+
# check if parent id is valid
|
294
|
+
account = Kaui::Account.find_by_id(account_id, false, false, cached_options_for_klient)
|
295
|
+
account.is_payment_delegated_to_parent = false
|
296
|
+
account.parent_account_id = nil
|
297
|
+
account.update(true, current_user.kb_username, params[:reason], params[:comment], cached_options_for_klient)
|
298
|
+
|
299
|
+
redirect_to account_path(@account.account_id), notice: 'Account successfully updated'
|
300
|
+
rescue StandardError => e
|
301
|
+
flash[:error] = "Error while un-linking parent account: #{as_string(e)}"
|
302
|
+
redirect_to account_path(@account.account_id)
|
303
|
+
end
|
292
304
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
305
|
+
def set_email_notifications_configuration
|
306
|
+
configuration = params.require(:configuration)
|
307
|
+
account_id = configuration[:account_id]
|
308
|
+
event_types = configuration[:event_types]
|
309
|
+
cached_options_for_klient = options_for_klient
|
310
|
+
|
311
|
+
is_success, message = email_notification_plugin_available?(cached_options_for_klient)
|
312
|
+
|
313
|
+
if is_success
|
314
|
+
is_success, message = Kenui::EmailNotificationService.set_configuration_per_account(account_id,
|
315
|
+
event_types,
|
316
|
+
current_user.kb_username,
|
317
|
+
params[:reason],
|
318
|
+
params[:comment],
|
319
|
+
cached_options_for_klient)
|
320
|
+
end
|
321
|
+
if is_success
|
322
|
+
flash[:notice] = message
|
323
|
+
else
|
324
|
+
flash[:error] = message
|
325
|
+
end
|
326
|
+
redirect_to account_path(account_id)
|
311
327
|
end
|
312
|
-
redirect_to account_path(account_id)
|
313
|
-
end
|
314
328
|
|
315
|
-
|
316
|
-
|
317
|
-
|
329
|
+
def events_to_consider
|
330
|
+
json_response do
|
331
|
+
{ data: Kenui::EmailNotificationService.get_events_to_consider(options_for_klient) }
|
332
|
+
end
|
318
333
|
end
|
319
|
-
end
|
320
334
|
|
321
|
-
|
335
|
+
private
|
322
336
|
|
323
337
|
def email_notification_plugin_available?(options_for_klient)
|
324
338
|
error_message = 'Email notification plugin is not installed'
|
325
339
|
|
326
340
|
is_available = Kenui::EmailNotificationService.email_notification_plugin_available?(options_for_klient).first
|
327
|
-
|
328
|
-
rescue
|
329
|
-
|
341
|
+
[is_available, is_available ? nil : error_message]
|
342
|
+
rescue StandardError
|
343
|
+
[false, error_message]
|
330
344
|
end
|
331
|
-
|
345
|
+
end
|
332
346
|
end
|