| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Modules; |
| 4 |
|
| 5 |
use FluentSupport\App\Models\Conversation; |
| 6 |
use FluentSupport\App\Models\Ticket; |
| 7 |
|
| 8 |
class StatModule |
| 9 |
{ |
| 10 |
public static function getAgentStat($agentId, $startDate = false, $endDate = false) |
| 11 |
{ |
| 12 |
if (!$startDate) { |
| 13 |
$currentDate = current_time('mysql'); |
| 14 |
$startDate = $currentDate; |
| 15 |
$endDate = $currentDate; |
| 16 |
} |
| 17 |
|
| 18 |
$startDate = date('Y-m-d 00:00.01', strtotime($startDate)); |
| 19 |
$endDate = date('Y-m-d 23:59.59', strtotime($endDate)); |
| 20 |
|
| 21 |
$newTickets = Ticket::where('agent_id', $agentId) |
| 22 |
->where('status', 'new') |
| 23 |
->count(); |
| 24 |
|
| 25 |
$activeTickets = Ticket::where('agent_id', $agentId) |
| 26 |
->where('status', 'active') |
| 27 |
->count(); |
| 28 |
|
| 29 |
$closedTickets = Ticket::where('agent_id', $agentId) |
| 30 |
->where('status', 'closed') |
| 31 |
->whereBetween('resolved_at', [$startDate, $endDate]) |
| 32 |
->count(); |
| 33 |
|
| 34 |
$responses = Conversation::where('conversation_type', 'response') |
| 35 |
->where('person_id', $agentId) |
| 36 |
->whereBetween('created_at', [$startDate, $endDate]) |
| 37 |
->count(); |
| 38 |
|
| 39 |
$interactions = Conversation::where('person_id', $agentId) |
| 40 |
->where('conversation_type', 'response') |
| 41 |
->whereBetween('created_at', [$startDate, $endDate]) |
| 42 |
->groupBy('ticket_id') |
| 43 |
->get() |
| 44 |
->count(); |
| 45 |
|
| 46 |
return [ |
| 47 |
'new_tickets' => [ |
| 48 |
'title' => 'New Tickets', |
| 49 |
'count' => $newTickets |
| 50 |
], |
| 51 |
'active_tickets' => [ |
| 52 |
'title' => 'Active Tickets', |
| 53 |
'count' => $activeTickets |
| 54 |
], |
| 55 |
'closed_tickets' => [ |
| 56 |
'title' => 'Closed Tickets', |
| 57 |
'count' => $closedTickets |
| 58 |
], |
| 59 |
'responses' => [ |
| 60 |
'title' => 'Responses', |
| 61 |
'count' => $responses |
| 62 |
], |
| 63 |
'interactions' =>[ |
| 64 |
'title' =>'Interactions', |
| 65 |
'count' => $interactions |
| 66 |
] |
| 67 |
]; |
| 68 |
} |
| 69 |
|
| 70 |
public static function getOverAllStats() |
| 71 |
{ |
| 72 |
$newTickets = Ticket::where('status', 'new') |
| 73 |
->count(); |
| 74 |
|
| 75 |
$activeTickets = Ticket::where('status', 'active') |
| 76 |
->count(); |
| 77 |
|
| 78 |
$closedTickets = Ticket::where('status', 'closed') |
| 79 |
->count(); |
| 80 |
|
| 81 |
$responses = Conversation::where('conversation_type', 'response') |
| 82 |
->count(); |
| 83 |
|
| 84 |
return [ |
| 85 |
'new_tickets' => [ |
| 86 |
'title' => 'New Tickets', |
| 87 |
'count' => $newTickets |
| 88 |
], |
| 89 |
'active_tickets' => [ |
| 90 |
'title' => 'Active Tickets', |
| 91 |
'count' => $activeTickets |
| 92 |
], |
| 93 |
'closed_tickets' => [ |
| 94 |
'title' => 'Closed Tickets', |
| 95 |
'count' => $closedTickets |
| 96 |
], |
| 97 |
'responses' => [ |
| 98 |
'title' => 'Responses', |
| 99 |
'count' => $responses |
| 100 |
] |
| 101 |
]; |
| 102 |
} |
| 103 |
|
| 104 |
public static function getAgentOverallStats($agentId) |
| 105 |
{ |
| 106 |
$replies_count = Conversation::where('person_id', $agentId)->count(); |
| 107 |
|
| 108 |
$interactions_count = Conversation::where('person_id', $agentId) |
| 109 |
->where('conversation_type', 'response') |
| 110 |
->groupBy('ticket_id') |
| 111 |
->get() |
| 112 |
->count(); |
| 113 |
|
| 114 |
$total_closed = Ticket::where('agent_id', $agentId)->where('status', 'closed')->count(); |
| 115 |
|
| 116 |
return [ |
| 117 |
'replies_count' => [ |
| 118 |
'title' => 'Total Replies', |
| 119 |
'count' => $replies_count |
| 120 |
], |
| 121 |
'interactions_count' => [ |
| 122 |
'title' => 'Total Interactions', |
| 123 |
'count' => $interactions_count |
| 124 |
], |
| 125 |
'total_closed' => [ |
| 126 |
'title' => 'Total Closed', |
| 127 |
'count' => $total_closed |
| 128 |
] |
| 129 |
]; |
| 130 |
} |
| 131 |
|
| 132 |
} |
| 133 |
|