Class: SpreeCmCommissioner::SubscriptionOrdersQuery
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::SubscriptionOrdersQuery
- Defined in:
- app/queries/spree_cm_commissioner/subscription_orders_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) ⇒ SubscriptionOrdersQuery
constructor
A new instance of SubscriptionOrdersQuery.
-
#overdues ⇒ Object
when payment state != :paid & order.line_item.to_date < now.
- #query_builder ⇒ Object
Constructor Details
#initialize(from_date:, to_date:, vendor_id:, spree_current_user:, current_date: Time.zone.today) ⇒ SubscriptionOrdersQuery
Returns a new instance of SubscriptionOrdersQuery.
5 6 7 8 9 10 11 |
# File 'app/queries/spree_cm_commissioner/subscription_orders_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_orders_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_orders_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_orders_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_orders_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_orders_query.rb', line 3 def vendor_id @vendor_id end |
Instance Method Details
#overdues ⇒ Object
when payment state != :paid & order.line_item.to_date < now
15 16 17 18 |
# File 'app/queries/spree_cm_commissioner/subscription_orders_query.rb', line 15 def overdues @overdues ||= query_builder.where(payment_state: :balance_due) .where('line_items.due_date < ?', current_date) end |
#query_builder ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/queries/spree_cm_commissioner/subscription_orders_query.rb', line 20 def query_builder if spree_current_user.has_spree_role?('admin') Spree::Order.subscription .joins(:line_items) .where(line_items: { vendor_id: vendor_id }) .joins(:invoice) .where(cm_invoices: { date: from_date..to_date }) else Spree::Order.subscription .joins(:line_items) .joins(subscription: :customer) .where(line_items: { vendor_id: vendor_id }) .joins(:invoice) .where(cm_invoices: { date: from_date..to_date }) .where(cm_customers: { place_id: spree_current_user.place_ids }) end end |