Sha256: c165bf1e987573c3dbaee95033d67282f85d651904564d71cd809567743f4706

Contents?: true

Size: 1.81 KB

Versions: 11

Compression:

Stored size: 1.81 KB

Contents

# This is a user specific EffectiveOrdersDatatable

class EffectiveOrdersDatatable < Effective::Datatable
  filters do
    unless attributes[:not_purchased]
      scope :purchased, default: true
      scope :deferred
      scope :refunds
      scope :not_purchased
      scope :all
    end
  end

  datatable do
    order :id, :desc

    col :created_at, visible: false
    col :updated_at, visible: false

    col :id, label: 'Number' do |order|
      '#' + order.to_param
    end

    unless attributes[:not_purchased]
      col :purchased_at do |order|
        order.purchased_at&.strftime('%F %H:%M') || 'not purchased'
      end
    end

    if EffectiveOrders.billing_address
      col :billing_address, visible: false
    end

    if EffectiveOrders.shipping_address
      col :shipping_address, visible: false
    end

    col :order_items, search: { as: :string }

    col :subtotal, as: :price, visible: false
    col :tax, as: :price, visible: false

    col :tax_rate, visible: false do |order|
      tax_rate_to_percentage(order.tax_rate)
    end

    col :total, as: :price

    col :payment_provider, label: 'Provider', visible: false, search: { collection: EffectiveOrders.payment_providers }
    col :payment_card, label: 'Card', visible: false

    if EffectiveOrders.collect_note
      col :note
    end

    col :note_to_buyer

    actions_col partial: 'effective/orders/datatable_actions', partial_as: :order
  end

  collection do
    scope = Effective::Order.all.where(user: user).includes(:addresses, :order_items, :user)

    if EffectiveOrders.orders_collection_scope.respond_to?(:call)
      scope = EffectiveOrders.orders_collection_scope.call(scope)
    end

    if attributes[:not_purchased]
      scope = scope.not_purchased
    end

    scope
  end

  def user
    @user ||= User.find(attributes[:user_id])
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
effective_orders-4.5.1 app/datatables/effective_orders_datatable.rb
effective_orders-4.5.0 app/datatables/effective_orders_datatable.rb
effective_orders-4.4.10 app/datatables/effective_orders_datatable.rb
effective_orders-4.4.9 app/datatables/effective_orders_datatable.rb
effective_orders-4.4.8 app/datatables/effective_orders_datatable.rb
effective_orders-4.4.7 app/datatables/effective_orders_datatable.rb
effective_orders-4.4.6 app/datatables/effective_orders_datatable.rb
effective_orders-4.4.5 app/datatables/effective_orders_datatable.rb
effective_orders-4.4.4 app/datatables/effective_orders_datatable.rb
effective_orders-4.4.3 app/datatables/effective_orders_datatable.rb
effective_orders-4.4.2 app/datatables/effective_orders_datatable.rb