2022-03-29 05:01:52 +00:00
|
|
|
module ReportHelper
|
|
|
|
private
|
|
|
|
|
|
|
|
def scope
|
|
|
|
case params[:type]
|
|
|
|
when :account
|
|
|
|
account
|
|
|
|
when :inbox
|
|
|
|
inbox
|
|
|
|
when :agent
|
|
|
|
user
|
|
|
|
when :label
|
|
|
|
label
|
|
|
|
when :team
|
|
|
|
team
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def conversations_count
|
2022-05-11 09:01:57 +00:00
|
|
|
(get_grouped_values scope.conversations.where(account_id: account.id)).count
|
2022-03-29 05:01:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def incoming_messages_count
|
2022-05-11 09:01:57 +00:00
|
|
|
(get_grouped_values scope.messages.where(account_id: account.id).incoming.unscope(:order)).count
|
2022-03-29 05:01:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def outgoing_messages_count
|
2022-05-11 09:01:57 +00:00
|
|
|
(get_grouped_values scope.messages.where(account_id: account.id).outgoing.unscope(:order)).count
|
2022-03-29 05:01:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def resolutions_count
|
2022-05-11 09:01:57 +00:00
|
|
|
(get_grouped_values scope.conversations.where(account_id: account.id).resolved).count
|
2022-03-29 05:01:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def avg_first_response_time
|
2022-05-11 09:01:57 +00:00
|
|
|
grouped_reporting_events = (get_grouped_values scope.reporting_events.where(name: 'first_response', account_id: account.id))
|
2022-04-08 07:18:18 +00:00
|
|
|
return grouped_reporting_events.average(:value_in_business_hours) if params[:business_hours]
|
|
|
|
|
|
|
|
grouped_reporting_events.average(:value)
|
2022-03-29 05:01:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def avg_resolution_time
|
2022-05-11 09:01:57 +00:00
|
|
|
grouped_reporting_events = (get_grouped_values scope.reporting_events.where(name: 'conversation_resolved', account_id: account.id))
|
2022-04-08 07:18:18 +00:00
|
|
|
return grouped_reporting_events.average(:value_in_business_hours) if params[:business_hours]
|
|
|
|
|
|
|
|
grouped_reporting_events.average(:value)
|
2022-03-29 05:01:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def avg_resolution_time_summary
|
2022-04-08 07:18:18 +00:00
|
|
|
reporting_events = scope.reporting_events
|
2022-05-11 09:01:57 +00:00
|
|
|
.where(name: 'conversation_resolved', account_id: account.id, created_at: range)
|
2022-04-08 07:18:18 +00:00
|
|
|
avg_rt = params[:business_hours] ? reporting_events.average(:value_in_business_hours) : reporting_events.average(:value)
|
2022-03-29 05:01:52 +00:00
|
|
|
|
|
|
|
return 0 if avg_rt.blank?
|
|
|
|
|
|
|
|
avg_rt
|
|
|
|
end
|
|
|
|
|
|
|
|
def avg_first_response_time_summary
|
2022-04-08 07:18:18 +00:00
|
|
|
reporting_events = scope.reporting_events
|
2022-05-11 09:01:57 +00:00
|
|
|
.where(name: 'first_response', account_id: account.id, created_at: range)
|
2022-04-08 07:18:18 +00:00
|
|
|
avg_frt = params[:business_hours] ? reporting_events.average(:value_in_business_hours) : reporting_events.average(:value)
|
2022-03-29 05:01:52 +00:00
|
|
|
|
|
|
|
return 0 if avg_frt.blank?
|
|
|
|
|
|
|
|
avg_frt
|
|
|
|
end
|
|
|
|
end
|