Sha256: f2ac14e5a69af7bf4778b02383822336ec6e3317e6a2dd819c793c55b2d985f6

Contents?: true

Size: 1.41 KB

Versions: 20

Compression:

Stored size: 1.41 KB

Contents

if defined?(EffectiveDatatables)
  module Effective
    module Datatables
      class Customers < Effective::Datatable
        default_order :email, :asc

        table_column :id, visible: false
        table_column(:email, column: 'users.email') { |user| mail_to user.email, user.email }

        if EffectiveOrders.stripe_enabled
          table_column :stripe_customer_id
          table_column :stripe_active_card
        end

        if EffectiveOrders.stripe_connect_enabled
          table_column :stripe_connect_access_token
        end

        table_column :subscription_types, column: 'subscription_types'

        table_column :actions, sortable: false, filter: false, partial: '/admin/customers/actions'

        def collection
          Effective::Customer.customers.uniq
            .joins(:user, :subscriptions)
            .select('customers.*, users.email AS email')
            .select("array_to_string(array(#{Effective::Subscription.purchased.select('subscriptions.stripe_plan_id').where('subscriptions.customer_id = customers.id').to_sql}), ' ,') AS subscription_types")
            .group('customers.id, subscriptions.stripe_plan_id, users.email')
        end

        def search_column(collection, table_column, search_term)
          return collection.where('subscriptions.stripe_plan_id ILIKE ?', "%#{search_term}%") if table_column[:name] == 'subscription_types'
          super
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
effective_orders-1.3.12 app/models/effective/datatables/customers.rb
effective_orders-1.3.11 app/models/effective/datatables/customers.rb
effective_orders-1.3.10 app/models/effective/datatables/customers.rb
effective_orders-1.3.9 app/models/effective/datatables/customers.rb
effective_orders-1.3.8 app/models/effective/datatables/customers.rb
effective_orders-1.3.7 app/models/effective/datatables/customers.rb
effective_orders-1.3.6 app/models/effective/datatables/customers.rb
effective_orders-1.3.5 app/models/effective/datatables/customers.rb
effective_orders-1.3.4 app/models/effective/datatables/customers.rb
effective_orders-1.3.3 app/models/effective/datatables/customers.rb
effective_orders-1.3.2 app/models/effective/datatables/customers.rb
effective_orders-1.3.1 app/models/effective/datatables/customers.rb
effective_orders-1.3.0 app/models/effective/datatables/customers.rb
effective_orders-1.2.13 app/models/effective/datatables/customers.rb
effective_orders-1.2.12 app/models/effective/datatables/customers.rb
effective_orders-1.2.11 app/models/effective/datatables/customers.rb
effective_orders-1.2.10 app/models/effective/datatables/customers.rb
effective_orders-1.2.9 app/models/effective/datatables/customers.rb
effective_orders-1.2.8 app/models/effective/datatables/customers.rb
effective_orders-1.2.7 app/models/effective/datatables/customers.rb