Class: CallLog

Inherits:
ApplicationRecord show all
Defined in:
app/models/call_log.rb

Overview

== Schema Information

Table name: call_logs
Database name: primary

id :integer not null, primary key
campaign :string
from :string
from_number :string
origination :string
start_date_cst :date
start_time :datetime
talk_duration :integer default(0), not null
to :string
to_ext :integer
to_number :string
total_duration :integer default(0), not null
callrail_id :string
cdr_call_id :string
from_account_id :integer
from_party_id :integer
original_id :integer
source_id :integer
to_account_id :integer
to_party_id :integer

Indexes

idx_call_logs_start_origination (start_time,origination)
index_call_logs_on_cdr_call_id (cdr_call_id) UNIQUE
index_call_logs_on_from_account_id (from_account_id)
index_call_logs_on_from_party_id (from_party_id)
index_call_logs_on_origination (origination)
index_call_logs_on_start_date_cst (start_date_cst) USING brin
index_call_logs_on_to_account_id (to_account_id)
index_call_logs_on_to_ext (to_ext)
index_call_logs_on_to_party_id (to_party_id)

Foreign Keys

fk_rails_... (from_party_id => parties.id)
fk_rails_... (to_party_id => parties.id)

Has many collapse

Belongs to collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.last_log_import_datetimeObject



52
53
54
# File 'app/models/call_log.rb', line 52

def self.last_log_import_datetime
  CallLog.maximum(:start_time).localtime.to_fs(:crm_default)
end

.parse_phone_number(number) ⇒ Object



60
61
62
63
64
# File 'app/models/call_log.rb', line 60

def self.parse_phone_number(number)
  return unless number.present?
  n = number.match(/\d+/).to_s.match(/^9?1?(\d{10})$/).try(:[],1) || number
  PhoneNumber.parse_and_format(n)
end

.valid_account_idsObject



56
57
58
# File 'app/models/call_log.rb', line 56

def self.
  EmployeeRecord.where.not(switchvox_account_id: nil).pluck(:switchvox_account_id)
end

Instance Method Details

#call_log_eventsActiveRecord::Relation<CallLogEvent>

Returns:

See Also:



46
# File 'app/models/call_log.rb', line 46

has_many :call_log_events, dependent: :destroy, primary_key: :cdr_call_id, foreign_key: :cdr_call_id

#find_party_using_account_id(account_id) ⇒ Object



88
89
90
91
# File 'app/models/call_log.rb', line 88

def ()
  return unless 
  EmployeePhoneStatus.where(switchvox_account_id:).first.try(:employee)
end

#find_party_using_number(number) ⇒ Object



93
94
95
96
97
98
99
# File 'app/models/call_log.rb', line 93

def find_party_using_number(number)
  return unless number.present?
  Party.joins(:contact_points).
        merge(ContactPoint.voice_callable).
        where(contact_points: { detail: number }).first

end

#from_partyParty

Returns:

See Also:



47
# File 'app/models/call_log.rb', line 47

belongs_to :from_party, class_name: 'Party', inverse_of: :origin_call_logs, optional: true

#match_fromObject



75
76
77
78
79
80
# File 'app/models/call_log.rb', line 75

def match_from
  return if from_party
  #First look at account id
  self.from_party = ()
  self.from_party ||= find_party_using_number(from_number)
end

#match_partiesObject



66
67
68
69
# File 'app/models/call_log.rb', line 66

def match_parties
  match_from
  match_to
end

#match_toObject



82
83
84
85
86
# File 'app/models/call_log.rb', line 82

def match_to
  return if to_party
  self.to_party = ()
  self.to_party ||= find_party_using_number(to_number)
end

#sourceSource

Returns:

See Also:



49
# File 'app/models/call_log.rb', line 49

belongs_to :source, optional: true

#to_partyParty

Returns:

See Also:



48
# File 'app/models/call_log.rb', line 48

belongs_to :to_party, class_name: 'Party', inverse_of: :destination_call_logs, optional: true

#to_sObject



71
72
73
# File 'app/models/call_log.rb', line 71

def to_s
  "Call Log #{id} from #{from_number} to #{to_number} on #{start_time.to_fs(:crm_default)}"
end