Module: CustomerQueries
- Extended by:
- ActiveSupport::Concern
- Included in:
- Customer
- Defined in:
- app/models/concerns/customer_queries.rb
Overview
Aggregate queries, uploads, line items, and room submissions for Customer.
Instance Method Summary collapse
- #all_line_items ⇒ Object
- #all_opportunities ⇒ Object
- #all_orders ⇒ Object
- #all_uploads ⇒ Object
- #hold_quotes_for_transmission_default? ⇒ Boolean
- #next_opportunity_name(existing_name = nil) ⇒ Object
- #orders? ⇒ Boolean
- #project_in_progress? ⇒ Boolean
- #quotes_complete_for_select ⇒ Object
Instance Method Details
#all_line_items ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/concerns/customer_queries.rb', line 36 def all_line_items where_sql = <<~SQL.squish (resource_type = 'Order' and resource_id IN (?)) OR (resource_type = 'Quote' and resource_id IN (?)) OR (resource_type = 'Invoice' and resource_id IN (?)) OR (resource_type = 'RoomConfiguration' and resource_id IN (?)) SQL LineItem.non_shipping.where(where_sql, customer.order_ids, customer.quote_ids, customer.invoice_ids, customer.room_configuration_ids) end |
#all_opportunities ⇒ Object
9 10 11 |
# File 'app/models/concerns/customer_queries.rb', line 9 def all_opportunities Query::PartyScopedOpportunities.call(self) end |
#all_orders ⇒ Object
13 14 15 |
# File 'app/models/concerns/customer_queries.rb', line 13 def all_orders Query::PartyScopedOrders.call(self) end |
#all_uploads ⇒ Object
29 30 31 32 33 34 |
# File 'app/models/concerns/customer_queries.rb', line 29 def all_uploads te_upload_ids = tax_exemptions.where.not(upload_id: nil).pluck(:upload_id) Upload.where(resource_type: 'Party', resource_id: id) .or(Upload.where(id: te_upload_ids)) .order(Upload[:created_at].desc) end |
#hold_quotes_for_transmission_default? ⇒ Boolean
66 67 68 69 |
# File 'app/models/concerns/customer_queries.rb', line 66 def hold_quotes_for_transmission_default? rep = primary_sales_rep || secondary_sales_rep || local_sales_rep rep&.heatwave_preferences&.dig('hold_quotes_for_transmission') == 'true' end |
#next_opportunity_name(existing_name = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/concerns/customer_queries.rb', line 49 def next_opportunity_name(existing_name = nil) list_of_names = opportunities.pluck(:name).compact.map(&:upcase) next_opp_number = 1 new_name = existing_name || "#{Opportunity::UNKNOWN_JOB_NAME_PREFIX} #1" loop do break unless list_of_names.include?(new_name.strip.upcase) next_opp_number += 1 new_name = if new_name&.start_with?(Opportunity::UNKNOWN_JOB_NAME_PREFIX) "#{Opportunity::UNKNOWN_JOB_NAME_PREFIX} ##{next_opp_number}" else "#{existing_name} (#{next_opp_number})" end end new_name end |
#orders? ⇒ Boolean
25 26 27 |
# File 'app/models/concerns/customer_queries.rb', line 25 def orders? orders.active.where.not(state: 'pending').present? end |
#project_in_progress? ⇒ Boolean
17 18 19 |
# File 'app/models/concerns/customer_queries.rb', line 17 def project_in_progress? room_configurations.active.exists? end |
#quotes_complete_for_select ⇒ Object
21 22 23 |
# File 'app/models/concerns/customer_queries.rb', line 21 def quotes_complete_for_select quotes.where(state: 'complete').pluck(:reference_number, :id) end |