Class: ViewActivity

Inherits:
ApplicationViewRecord show all
Includes:
Models::SearchableView, PgSearch::Model
Defined in:
app/models/view_activity.rb

Overview

== Schema Information

Table name: view_activities
Database name: primary

id(FK → activities.id.) :integer primary key
activity_age(Days since the original target datetime (integer). Measures how overdue/old the activity is.) :integer
activity_result_type_result_code(Result code (e.g. completed, cancelled). NULL if activity is still open.) :string(255)
activity_type_priority(Priority level from the activity type definition.) :integer
activity_type_task_type(Task type classification (Call, Email, Task, Note, etc.). Defaults to 'Note'.) :string
assigned_resource_full_name(Full name of the currently assigned employee.) :string(255)
buying_group_name(Name of the customer's buying group.) :string(255)
campaign_name(Name of the linked campaign.) :string(255)
closer_full_name(Full name of the employee who completed the activity.) :string(255)
completion_datetime(Date/time when the activity was completed (NULL if still open).) :datetime
contact_full_name(Full name of the contact person (NULL if party is the customer directly).) :string(255)
creator_full_name(Full name of the activity creator.) :string(255)
customer_full_name(Full name of the customer account.) :string(255)
customer_open_sales_activity(Whether the customer has any open sales activity.) :boolean
customer_spi(Customer's Sales Priority Index (SPI) — numeric score for sales prioritization.) :integer
customer_watch(Whether the customer is on the sales watch list.) :integer
description(Activity description/subject text.) :string(255)
has_notes(Boolean — true if the notes field is non-empty.) :boolean
lock_target_datetime(Whether the target datetime is locked (cannot be rescheduled).) :boolean
notes(Activity notes/comments text.) :text
opportunity_name(Name/title of the linked opportunity.) :string(80)
opportunity_state(State of the linked opportunity (e.g. quoting, won, lost).) :string(255)
original_assigned_resource_full_name(Full name of the originally assigned employee (before reassignment).) :string(255)
original_target_datetime(Original scheduled date before any rescheduling (falls back to target_datetime).) :datetime
party_full_name(Full name of the party (customer or contact) the activity relates to.) :string(255)
primary_address_city(City from the customer's primary address.) :string(255)
primary_address_state_code(State/province code from the customer's primary address.) :string(20)
primary_email(Primary email address of the contact or customer.) :string(255)
primary_sales_rep_full_name(Full name of the customer's primary sales rep.) :string(255)
report_grouping(Sales channel grouping: customer → buying group → profile → 'Homeowners'.) :string
resource_type(Polymorphic type of the linked resource (e.g. 'Opportunity', 'Order').) :string(255)
tag1(Primary activity category tag: CLOSE_THE_DEAL, LEAD_THE_WAY, MISC, NURTURE_ME, or OTHERS.) :text
tag2(Secondary tag: CALLBLOCK if tagged as sales_call or callblock, NULL otherwise.) :text
target_datetime(Scheduled date/time for the activity.) :datetime
time_at_location(Current local time at the contact/customer location (formatted as 'HH:MI AM').) :text
timezone_name(IANA timezone name for the contact or customer (e.g. 'America/Chicago').) :string
created_at(Activity creation timestamp.) :datetime
activity_result_type_id(FK → activity_result_types.id. NULL if activity is still open.) :integer
activity_type_id(FK → activity_types.id.) :integer
assigned_resource_id(FK → parties.id for the employee assigned to this activity.) :integer
buying_group_id(FK → buying_groups.id for the customer's buying group.) :integer
campaign_id(FK → campaigns.id if the activity is linked to a campaign.) :integer
closed_by_id(FK → parties.id for the employee who closed/completed the activity.) :integer
contact_id(FK → parties.id for the contact person (NULL if party is the customer).) :integer
creator_id(FK → parties.id for the employee who created the activity.) :integer
customer_id(FK → parties.id for the customer account.) :integer
opportunity_id(FK → opportunities.id (NULL if not linked to an opportunity).) :integer
original_assigned_resource_id(FK → parties.id for the originally assigned employee.) :integer
party_id(FK → parties.id — the party (customer or contact) this activity is about.) :integer
primary_address_id(FK → addresses.id for the customer's primary address.) :integer
primary_sales_rep_id(FK → parties.id for the customer's primary sales rep.) :integer
resource_id(Polymorphic FK — ID of the linked resource (opportunity, order, etc.).) :integer

Belongs to collapse

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::SearchableView

#crm_link, #crm_link_subtitle, #has_columns?, #main_resource, #readonly?

Methods inherited from ApplicationViewRecord

create, create!, #readonly?

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.customer_watchActiveRecord::Relation<ViewActivity>

A relation of ViewActivities that are customer watch. Active Record Scope

Returns:

See Also:



68
# File 'app/models/view_activity.rb', line 68

scope :customer_watch, ->(value) { ['Y','1','T'].include?(value.to_s.first.upcase) ? where("customer_watch >= 2") : where("customer_watch IS NULL or customer_watch = 1") }

.open_on_dateActiveRecord::Relation<ViewActivity>

A relation of ViewActivities that are open on date. Active Record Scope

Returns:

See Also:



69
# File 'app/models/view_activity.rb', line 69

scope :open_on_date, ->(date) { where("(view_activities.activity_result_type_id IS NULL AND view_activities.target_datetime <= :datetime) OR EXISTS(select 1 from historical_open_activities hoa where hoa.activity_id = view_activities.id and hoa.open_date = :date and hoa.assigned_resource_id = view_activities.assigned_resource_id)", datetime: Time.zone.parse(date.to_s).end_of_day, date: Time.zone.parse(date.to_s).to_date) }

.ransackable_scopes(_auth_object = nil) ⇒ Object



80
81
82
# File 'app/models/view_activity.rb', line 80

def self.ransackable_scopes(_auth_object = nil)
  super + %i[customer_watch open_on_date search_notes search_description]
end

Instance Method Details

#callable_contact_points_arrayObject



84
85
86
87
88
89
90
91
92
93
# File 'app/models/view_activity.rb', line 84

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).map{ |r| r.id }
  ContactPoint.where(party_id: c).voice_callable.order(:position).each do |ccp|
    ar << ccp unless ar.detect{|cp| cp.detail == ccp.detail}
  end
  ar
end

#contact_contact_pointsActiveRecord::Relation<ContactPoint>

Returns:

See Also:



66
# File 'app/models/view_activity.rb', line 66

has_many :contact_contact_points, primary_key: :contact_id, foreign_key: :party_id, class_name: 'ContactPoint'

#customer_contact_pointsActiveRecord::Relation<ContactPoint>

Returns:

See Also:



65
# File 'app/models/view_activity.rb', line 65

has_many :customer_contact_points, primary_key: :customer_id, foreign_key: :party_id, class_name: 'ContactPoint'

#partyParty

Returns:

See Also:



64
# File 'app/models/view_activity.rb', line 64

belongs_to :party, foreign_key: :party_id, optional: true

#resourceResource

Returns:

  • (Resource)

See Also:



63
# File 'app/models/view_activity.rb', line 63

belongs_to :resource, polymorphic: true, optional: true