Class: Kaui::AccountsController
- Inherits:
-
EngineController
- Object
- ApplicationController
- EngineController
- Kaui::AccountsController
- Defined in:
- app/controllers/kaui/accounts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #pagination ⇒ Object
- #pay_all_invoices ⇒ Object
- #set_default_payment_method ⇒ Object
- #show ⇒ Object
- #toggle_email_notifications ⇒ Object
Methods inherited from EngineController
#current_ability, #current_user, #options_for_klient
Instance Method Details
#create ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/kaui/accounts_controller.rb', line 40 def create @account = Kaui::Account.new(params[:account].delete_if { |key, value| value.blank? }) # Transform "1" into boolean @account.is_migrated = @account.is_migrated == '1' @account.is_notified_for_invoices = @account.is_notified_for_invoices == '1' begin @account = @account.create(current_user.kb_username, params[:reason], params[:comment], ) redirect_to account_path(@account.account_id), :notice => 'Account was successfully created' rescue => e flash.now[:error] = "Error while creating account: #{as_string(e)}" render :action => :new end end |
#index ⇒ Object
3 4 |
# File 'app/controllers/kaui/accounts_controller.rb', line 3 def index end |
#new ⇒ Object
36 37 38 |
# File 'app/controllers/kaui/accounts_controller.rb', line 36 def new @account = Kaui::Account.new end |
#pagination ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/kaui/accounts_controller.rb', line 6 def pagination search_key = params[:sSearch] offset = params[:iDisplayStart] || 0 limit = params[:iDisplayLength] || 10 accounts = Kaui::Account.list_or_search(search_key, offset, limit, ) json = { :sEcho => params[:sEcho], :iTotalRecords => accounts.pagination_max_nb_records, :iTotalDisplayRecords => accounts.pagination_total_nb_records, :aaData => [] } accounts.each do |account| json[:aaData] << [ view_context.link_to(view_context.truncate_uuid(account.account_id), view_context.url_for(:action => :show, :id => account.account_id)), account.name, account.external_key, account.currency, account.city, account.country ] end respond_to do |format| format.json { render :json => json } end end |
#pay_all_invoices ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/controllers/kaui/accounts_controller.rb', line 103 def pay_all_invoices payment = Kaui::InvoicePayment.new(:account_id => params[:id]) begin payment.bulk_create(params[:is_external_payment], current_user.kb_username, params[:reason], params[:comment], ) flash[:notice] = 'Successfully triggered a payment for all unpaid invoices' rescue => e flash[:error] = "Error while triggering payments: #{as_string(e)}" end redirect_to account_path(payment.account_id) end |
#set_default_payment_method ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/kaui/accounts_controller.rb', line 76 def set_default_payment_method account_id = params[:id] payment_method_id = params[:payment_method_id] begin Kaui::PaymentMethod.set_default(payment_method_id, account_id, current_user.kb_username, params[:reason], params[:comment], ) flash[:notice] = "Successfully set #{payment_method_id} as default" rescue => e flash[:error] = "Error while setting payment method #{payment_method_id} as default: #{as_string(e)}" end redirect_to account_path(account_id) end |
#show ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/kaui/accounts_controller.rb', line 56 def show begin @account = Kaui::Account::find_by_id_or_key(params[:id], true, true, ) @overdue_state = @account.overdue() @bundles = @account.bundles() @tags = @account.(false, 'NONE', ).sort { |tag_a, tag_b| tag_a <=> tag_b } @account_emails = Kaui::AccountEmail.find_all_sorted_by_account_id(@account.account_id, 'NONE', ) @payment_methods = Kaui::PaymentMethod.find_non_external_by_account_id(@account.account_id, true, ) rescue => e flash.now[:error] = "Error while retrieving account information: #{as_string(e)}" render :action => :index and return end @subscriptions_by_bundle_id = {} @bundles.each do |bundle| @subscriptions_by_bundle_id[bundle.bundle_id.to_s] = (@subscriptions_by_bundle_id[bundle.bundle_id.to_s] || []) + bundle.subscriptions end end |
#toggle_email_notifications ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/kaui/accounts_controller.rb', line 90 def toggle_email_notifications account = Kaui::Account.new(:account_id => params[:id], :is_notified_for_invoices => params[:is_notified]) begin account.update_email_notifications(current_user.kb_username, params[:reason], params[:comment], ) flash[:notice] = 'Email preferences updated' rescue => e flash[:error] = "Error while setting email notifications: #{as_string(e)}" end redirect_to account_path(account.account_id) end |