Class: CallLog
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)
Constant Summary
Constants included
from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Class Method Summary
collapse
Instance Method Summary
collapse
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
config
#after_commit
#publish_event
Class Method Details
.last_log_import_datetime ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'app/models/call_log.rb', line 52
def self.last_log_import_datetime
CallLog.maximum(:start_time)&.to_fs(:crm_default)
end
|
.parse_phone_number(number) ⇒ Object
65
66
67
68
69
70
|
# File 'app/models/call_log.rb', line 65
def self.parse_phone_number(number)
return if number.blank?
n = number.match(/\d+/).to_s.match(/^9?1?(\d{10})$/).try(:[], 1) || number
PhoneNumber.parse_and_format(n)
end
|
.valid_account_ids ⇒ Object
61
62
63
|
# File 'app/models/call_log.rb', line 61
def self.valid_account_ids
EmployeeRecord.where.not(switchvox_account_id: nil).pluck(:switchvox_account_id)
end
|
Instance Method Details
#call_log_events ⇒ ActiveRecord::Relation<CallLogEvent>
47
|
# File 'app/models/call_log.rb', line 47
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
96
97
98
99
100
|
# File 'app/models/call_log.rb', line 96
def find_party_using_account_id(account_id)
return unless account_id
EmployeePhoneStatus.where(switchvox_account_id: account_id).first.try(:employee)
end
|
#find_party_using_number(number) ⇒ Object
102
103
104
105
106
107
108
|
# File 'app/models/call_log.rb', line 102
def find_party_using_number(number)
return if number.blank?
Party.joins(:contact_points)
.merge(ContactPoint.voice_callable)
.where(contact_points: { detail: number }).first
end
|
#from_party ⇒ Party
48
|
# File 'app/models/call_log.rb', line 48
belongs_to :from_party, class_name: 'Party', inverse_of: :origin_call_logs, optional: true
|
#match_from ⇒ Object
81
82
83
84
85
86
87
|
# File 'app/models/call_log.rb', line 81
def match_from
return if from_party
self.from_party = find_party_using_account_id(from_account_id)
self.from_party ||= find_party_using_number(from_number)
end
|
#match_parties ⇒ Object
72
73
74
75
|
# File 'app/models/call_log.rb', line 72
def match_parties
match_from
match_to
end
|
#match_to ⇒ Object
89
90
91
92
93
94
|
# File 'app/models/call_log.rb', line 89
def match_to
return if to_party
self.to_party = find_party_using_account_id(to_account_id)
self.to_party ||= find_party_using_number(to_number)
end
|
50
|
# File 'app/models/call_log.rb', line 50
belongs_to :source, optional: true
|
#to_party ⇒ Party
49
|
# File 'app/models/call_log.rb', line 49
belongs_to :to_party, class_name: 'Party', inverse_of: :destination_call_logs, optional: true
|
#to_s ⇒ Object
77
78
79
|
# File 'app/models/call_log.rb', line 77
def to_s
"Call Log #{id} from #{from_number} to #{to_number} on #{start_time.to_fs(:crm_default)}"
end
|