Class: ViewOpportunity
- Inherits:
-
ApplicationViewRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ApplicationViewRecord
- ViewOpportunity
- Includes:
- Models::SearchableView
- Defined in:
- app/models/view_opportunity.rb
Overview
== Schema Information
Table name: view_opportunities
Database name: primary
id :integer primary key
adequate_sales_follow_up :boolean
awaiting_iq_transmission :boolean
close_date :date
closed_sales_activity :bigint
company_name :string(255)
completed_sales_activity :bigint
contact_full_name :string(255)
contactable :boolean
customer_full_name :string(255)
customer_local_sales_rep_full_name :string(255)
email :string(255)
last_activity_notes :text
last_quote :integer
last_sales_activity_completed_on :datetime
latitude :decimal(9, 6)
local_sales_rep_full_name :string(255)
longitude :decimal(9, 6)
media :string(255)
name :string(80)
open_sales_activity :bigint
opportunity_local_sales_rep_full_name :string(255)
opportunity_reception_type :string(255)
opportunity_type :string(1)
phone :string(255)
planned_installation_date :datetime
pricing_program :text
primary_sales_rep_full_name :string(255)
report_grouping :string
sales_priority_index :integer
secondary_sales_rep_full_name :string(255)
ship_to_state :string(255)
ship_to_state_code :text
source_full_name :string(500)
state :string(255)
technical_support_rep_full_name :string(255)
value :decimal(, )
won_lost_date :datetime
created_at :datetime
updated_at :datetime
company_id :integer
contact_id :integer
customer_id :integer
customer_local_sales_rep_id :integer
local_sales_rep_id :integer
next_sales_activity_id :integer
opportunity_local_sales_rep_id :integer
primary_sales_rep_id :integer
secondary_sales_rep_id :integer
source_id :integer
technical_support_rep_id :integer
Constant Summary
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Belongs to collapse
Has many collapse
- #contact_contact_points ⇒ ActiveRecord::Relation<ContactPoint>
- #customer_contact_points ⇒ ActiveRecord::Relation<ContactPoint>
Delegated Instance Attributes collapse
-
#location ⇒ Object
Alias for Opportunity#location.
Class Method Summary collapse
-
.contains_product_line_id ⇒ ActiveRecord::Relation<ViewOpportunity>
A relation of ViewOpportunities that are contains product line id.
- .ransackable_scopes(_auth_object = nil) ⇒ Array<Symbol>
-
.source_id ⇒ ActiveRecord::Relation<ViewOpportunity>
A relation of ViewOpportunities that are source id.
Instance Method Summary collapse
Methods included from Models::SearchableView
#crm_link, #crm_link_subtitle, #has_columns?, #readonly?
Methods inherited from ApplicationViewRecord
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Class Method Details
.contains_product_line_id ⇒ ActiveRecord::Relation<ViewOpportunity>
A relation of ViewOpportunities that are contains product line id. Active Record Scope
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/models/view_opportunity.rb', line 78 scope :contains_product_line_id, ->(*product_line_ids) { ids = product_line_ids.flatten.uniq.filter_map(&:presence).map(&:to_i) return none if ids.empty? # Use ltree descendant check: primary_pl_path_ids <@ ANY(paths from given IDs) pl_sql = %{ EXISTS(SELECT 1 FROM line_items li INNER JOIN items i ON li.item_id = i.id AND i.primary_pl_path_ids <@ ANY(SELECT ltree_path_ids FROM product_lines WHERE id = ANY(ARRAY[?]::integer[])) INNER JOIN orders ord ON li.resource_id = ord.id AND li.resource_type = 'Order' WHERE ord.opportunity_id = view_opportunities.id) OR EXISTS(SELECT 1 FROM line_items li INNER JOIN items i ON li.item_id = i.id AND i.primary_pl_path_ids <@ ANY(SELECT ltree_path_ids FROM product_lines WHERE id = ANY(ARRAY[?]::integer[])) INNER JOIN quotes quo ON li.resource_id = quo.id AND li.resource_type = 'Quote' WHERE quo.opportunity_id = view_opportunities.id) OR EXISTS(SELECT 1 FROM line_items li INNER JOIN items i ON li.item_id = i.id AND i.primary_pl_path_ids <@ ANY(SELECT ltree_path_ids FROM product_lines WHERE id = ANY(ARRAY[?]::integer[])) INNER JOIN room_configurations rc ON li.resource_id = rc.id AND li.resource_type = 'RoomConfiguration' WHERE rc.opportunity_id = view_opportunities.id) } where(pl_sql, ids, ids, ids) } |
.ransackable_scopes(_auth_object = nil) ⇒ Array<Symbol>
112 113 114 |
# File 'app/models/view_opportunity.rb', line 112 def self.ransackable_scopes(_auth_object = nil) super + %i[source_id contains_product_line_id] end |
.source_id ⇒ ActiveRecord::Relation<ViewOpportunity>
A relation of ViewOpportunities that are source id. Active Record Scope
71 72 73 74 75 76 |
# File 'app/models/view_opportunity.rb', line 71 scope :source_id, ->(*sids) { sids = sids.flatten.compact next all if sids.blank? where(source_id: Source.self_and_descendants_ids(sids)) } |
Instance Method Details
#callable_contact_points_array ⇒ Array<ContactPoint>
117 118 119 120 121 122 123 124 125 126 |
# File 'app/models/view_opportunity.rb', line 117 def callable_contact_points_array ar = [] ar += ContactPoint.where(party_id: customer_id).voice_callable.order(:position) # ar += contact_contact_points.voice_callable.order(:position) c = Party.where(customer_id: customer_id).pluck(:id) ContactPoint.where(party_id: c).voice_callable.order(:position).each do |ccp| ar << ccp unless ar.find { |cp| cp.detail == ccp.detail } end ar end |
#contact_contact_points ⇒ ActiveRecord::Relation<ContactPoint>
67 |
# File 'app/models/view_opportunity.rb', line 67 has_many :contact_contact_points, primary_key: :contact_id, foreign_key: :party_id, class_name: 'ContactPoint' |
#customer_contact_points ⇒ ActiveRecord::Relation<ContactPoint>
65 |
# File 'app/models/view_opportunity.rb', line 65 has_many :customer_contact_points, primary_key: :customer_id, foreign_key: :party_id, class_name: 'ContactPoint' |
#distance_friendly ⇒ String?
129 130 131 132 133 134 135 136 137 138 |
# File 'app/models/view_opportunity.rb', line 129 def distance_friendly dist = begin distance.round(2) rescue StandardError nil end return unless dist "#{dist} mi" end |
#location ⇒ Object
Alias for Opportunity#location
69 |
# File 'app/models/view_opportunity.rb', line 69 delegate :location, to: :opportunity |
#opportunity ⇒ Opportunity
62 |
# File 'app/models/view_opportunity.rb', line 62 belongs_to :opportunity, foreign_key: :id, optional: true |