Class: Spree::UsersWhoRecentlyPurchasedReport

Inherits:
Report
  • Object
show all
Defined in:
app/reports/spree/users_who_recently_purchased_report.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

DEFAULT_SORTABLE_ATTRIBUTE =
:user_email
HEADERS =
{ user_email: :string, purchase_count: :integer, last_purchase_date: :date, last_purchased_order_number: :string }
SEARCH_ATTRIBUTES =
{ start_date: :start_date, end_date: :end_date, email_cont: :email }
SORTABLE_ATTRIBUTES =
[:user_email, :purchase_count, :last_purchase_date]

Constants inherited from Report

Report::TIME_SCALES

Instance Attribute Summary

Attributes inherited from Report

#current_page, #paginate, #records_per_page, #reporting_period, #search, #sortable_attribute, #sortable_type, #total_records

Instance Method Summary collapse

Methods inherited from Report

#active_record_sort, deeplink, #deeplink_properties, #generate, #get_results, #header_sorted?, #initialize, #name, #pagination_required?, #set_sortable_attributes, #time_scale_columns, #time_scale_columns_to_s, #time_scale_selects, #total_pages

Constructor Details

This class inherits a constructor from Spree::Report

Instance Method Details

#paginated?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'app/reports/spree/users_who_recently_purchased_report.rb', line 8

def paginated?
  true
end

#paginated_report_queryObject



42
43
44
45
46
# File 'app/reports/spree/users_who_recently_purchased_report.rb', line 42

def paginated_report_query
  report_query
    .take(records_per_page)
    .skip(current_page)
end

#record_count_queryObject



22
23
24
# File 'app/reports/spree/users_who_recently_purchased_report.rb', line 22

def record_count_query
  Spree::Report::QueryFragments.from_subquery(report_query).project(Arel.star.count)
end

#report_queryObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/reports/spree/users_who_recently_purchased_report.rb', line 26

def report_query
  Spree::Report::QueryFragments
    .from_subquery(all_orders_with_users)
    .project(
      "user_email",
      "last_purchased_order_number",
      "last_purchase_date",
      "COUNT(user_email) as purchase_count")
    .group(
      "user_email",
      "last_purchased_order_number",
      "last_purchase_date"
    )
end