Sha256: eae95a8a4228a63b271d871a72946f18cc9485e4f14e55e4457644d91d843111

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

class Kaui::AccountChildrenController < Kaui::EngineController

  def index

    # check that the required parent account id is provided and get its data
    begin
      @account = Kaui::Account::find_by_id(params.require(:account_id), false, false, options_for_klient)
    rescue KillBillClient::API::NotFound
      flash[:error] = "Invalid parent account id supplied #{params.require(:account_id)}"
      redirect_to kaui_engine.home_path and return
    end

  end

  # It will fetch all the children. It use the paginate to fetch all children as permitting for future exchange
  # when killbill account/{account_id}/children endpoint includes offset and limit parameters.
  def pagination

    searcher = lambda do |parent_account_id, offset, limit|
      Kaui::Account.find_children(parent_account_id, true, true, 'NONE', options_for_klient)
    end

    data_extractor = lambda do |account_child, column|
      [
          account_child.name,
          account_child.account_id,
          account_child.external_key,
          account_child.account_balance,
          account_child.city,
          account_child.country
      ][column]
    end

    formatter = lambda do |account_child|
      [
          view_context.link_to(account_child.name || '(not set)', account_path(account_child.account_id)),
          view_context.truncate_uuid(account_child.account_id),
          account_child.external_key,
          view_context.humanized_money_with_symbol(account_child.balance_to_money),
          account_child.city,
          account_child.country
      ]
    end

    paginate searcher, data_extractor, formatter
  end


end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kaui-1.0.0 app/controllers/kaui/account_children_controller.rb
kaui-0.16.2 app/controllers/kaui/account_children_controller.rb
kaui-0.16.1 app/controllers/kaui/account_children_controller.rb
kaui-0.16.0 app/controllers/kaui/account_children_controller.rb