Class: SpreeCmCommissioner::SubscriptionRevenueOverviewQuery
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::SubscriptionRevenueOverviewQuery
- Defined in:
- app/queries/spree_cm_commissioner/subscription_revenue_overview_query.rb
Instance Attribute Summary collapse
-
#current_date ⇒ Object
readonly
Returns the value of attribute current_date.
-
#from_date ⇒ Object
readonly
Returns the value of attribute from_date.
-
#spree_current_user ⇒ Object
readonly
Returns the value of attribute spree_current_user.
-
#to_date ⇒ Object
readonly
Returns the value of attribute to_date.
-
#vendor_id ⇒ Object
readonly
Returns the value of attribute vendor_id.
Instance Method Summary collapse
-
#initialize(from_date:, to_date:, vendor_id:, spree_current_user:, current_date: Time.zone.today) ⇒ SubscriptionRevenueOverviewQuery
constructor
A new instance of SubscriptionRevenueOverviewQuery.
- #overdues ⇒ Object
- #reports ⇒ Object
- #reports_with_overdues ⇒ Object
Constructor Details
#initialize(from_date:, to_date:, vendor_id:, spree_current_user:, current_date: Time.zone.today) ⇒ SubscriptionRevenueOverviewQuery
Returns a new instance of SubscriptionRevenueOverviewQuery.
5 6 7 8 9 10 11 |
# File 'app/queries/spree_cm_commissioner/subscription_revenue_overview_query.rb', line 5 def initialize(from_date:, to_date:, vendor_id:, spree_current_user:, current_date: Time.zone.today) @from_date = from_date @to_date = to_date @vendor_id = vendor_id @current_date = current_date @spree_current_user = spree_current_user end |
Instance Attribute Details
#current_date ⇒ Object (readonly)
Returns the value of attribute current_date.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/subscription_revenue_overview_query.rb', line 3 def current_date @current_date end |
#from_date ⇒ Object (readonly)
Returns the value of attribute from_date.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/subscription_revenue_overview_query.rb', line 3 def from_date @from_date end |
#spree_current_user ⇒ Object (readonly)
Returns the value of attribute spree_current_user.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/subscription_revenue_overview_query.rb', line 3 def spree_current_user @spree_current_user end |
#to_date ⇒ Object (readonly)
Returns the value of attribute to_date.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/subscription_revenue_overview_query.rb', line 3 def to_date @to_date end |
#vendor_id ⇒ Object (readonly)
Returns the value of attribute vendor_id.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/subscription_revenue_overview_query.rb', line 3 def vendor_id @vendor_id end |
Instance Method Details
#overdues ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/queries/spree_cm_commissioner/subscription_revenue_overview_query.rb', line 27 def overdues subquery = build_subquery(overdue: true) Spree::Order.from(subquery, :orders) .group(:payment_state) .select(*select_fields) .map do |report| report.slice(:orders_count, :total, :payment_total) .symbolize_keys .merge({ state: 'overdue' }) end end |
#reports ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'app/queries/spree_cm_commissioner/subscription_revenue_overview_query.rb', line 18 def reports subquery ||= build_subquery Spree::Order.from(subquery, :orders) .group(:payment_state) .select('payment_state AS state', *select_fields) .map { |r| r.slice(:state, :orders_count, :total, :payment_total).symbolize_keys } end |
#reports_with_overdues ⇒ Object
13 14 15 16 |
# File 'app/queries/spree_cm_commissioner/subscription_revenue_overview_query.rb', line 13 def reports_with_overdues all_reports = reports.concat(overdues) all_reports.sort_by { |report| report_types.index(report[:state]) || report_types.size } end |