Sha256: 54b3d35f89390419576541ad821893e2814367a264a82d2b02d74805f05038ee

Contents?: true

Size: 1.88 KB

Versions: 35

Compression:

Stored size: 1.88 KB

Contents

# Revenue: Transactions Grouped By Name

module Admin
  class ReportTransactionsGroupedByQbNameDatatable < Effective::Datatable
    filters do
      filter_date_range :current_month
    end

    datatable do
      length 250

      col :qb_item_name
      col :subtotal, as: :price
      col :tax, as: :price
      col :total, as: :price

      payment_providers.each do |provider|
        col(provider, as: :price)
      end

      col :orders_count

      col :orders
      col :users

      col :start_date, as: :date, search: false, sort: false, visible: false do
        date_range.begin&.strftime('%F')
      end

      col :end_date, as: :date, search: false, sort: false, visible: false do
        date_range.end&.strftime('%F')
      end

      aggregate :total
    end

    collection do
      start_date = date_range.begin&.strftime('%F')
      end_date = date_range.end&.strftime('%F')

      orders = Effective::Order.purchased.where(purchased_at: date_range).where('total != 0')
      order_items = Effective::OrderItem.includes(:qb_order_item).where(order_id: orders).includes(:purchasable, order: :user)

      items = order_items.group_by(&:qb_item_name).map do |name, items|
        row = [
          name,
          items.sum { |item| item.subtotal }.to_i,
          items.sum { |item| item.tax }.to_i,
          items.sum { |item| item.total }.to_i,
        ]

        row += payment_providers.map do |payment_provider|
          items.sum { |item| (item.order.payment_provider == payment_provider) ? item.total : 0 }.to_i
        end

        row += [
          items.map(&:order_id).uniq.length,
          items.map { |item| item.order },
          items.map { |item| item.order.user },
          start_date,
          end_date
        ]

        row
      end
    end

    def payment_providers
      @payment_providers ||= EffectiveOrders.payment_providers - ['free', 'pretend']
    end

  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
effective_orders-6.9.4 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.9.2 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.9.1 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.9.0 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.8.2 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.8.1 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.8.0 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.7.3 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.7.2 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.7.1 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.7.0 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.6.3 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.6.2 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.6.1 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.6.0 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.5.9 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.5.8 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.5.7 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.5.6 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb
effective_orders-6.5.5 app/datatables/admin/report_transactions_grouped_by_qb_name_datatable.rb