| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentSupport\App\Models\Agent; |
| 6 |
use FluentSupport\App\Modules\Reporting\Reporting; |
| 7 |
use FluentSupport\App\Modules\StatModule; |
| 8 |
use FluentSupport\App\Services\Helper; |
| 9 |
use FluentSupport\Framework\Request\Request; |
| 10 |
|
| 11 |
/** |
| 12 |
* ReportingController class for REST API |
| 13 |
* This class is responsible for getting data for all request related to report |
| 14 |
* @package FluentSupport\App\Http\Controllers |
| 15 |
* |
| 16 |
* @version 1.0.0 |
| 17 |
*/ |
| 18 |
class ReportingController extends Controller |
| 19 |
{ |
| 20 |
/** |
| 21 |
* getOverallReports method will return the overall statistics of all ticket by ticket statuses |
| 22 |
* The response will have an array with ticket number by ticket status |
| 23 |
* @param Request $request |
| 24 |
* @return array |
| 25 |
*/ |
| 26 |
public function getOverallReports(Request $request) |
| 27 |
{ |
| 28 |
return [ |
| 29 |
'overall_reports' => StatModule::getOverAllStats(), |
| 30 |
'today_reports' => StatModule::getTodayStats() |
| 31 |
]; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* getTicketsChart method will generate statistics for all tickets within a date range and return ticket number by date |
| 36 |
* @param Request $request |
| 37 |
* @param Reporting $reporting |
| 38 |
* @return array |
| 39 |
*/ |
| 40 |
public function getTicketsChart(Request $request, Reporting $reporting) |
| 41 |
{ |
| 42 |
list($from, $to) = $request->get('date_range') ?: ['', '']; |
| 43 |
$filter = []; |
| 44 |
$stats = $reporting->getTicketsGrowth($from, $to); |
| 45 |
|
| 46 |
if($agent_id = $request->get('agent_id')) { |
| 47 |
$filter['agent_id'] = $agent_id; |
| 48 |
$stats = $reporting->getTicketsGrowth($from, $to, $filter); |
| 49 |
} |
| 50 |
return [ |
| 51 |
'stats' => $stats |
| 52 |
]; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* getResolveChart method will generate statistics for closed tickets within a date range and return ticket number by date |
| 57 |
* @param Request $request |
| 58 |
* @param Reporting $reporting |
| 59 |
* @return array |
| 60 |
*/ |
| 61 |
public function getResolveChart(Request $request, Reporting $reporting) |
| 62 |
{ |
| 63 |
list($from, $to) = $request->get('date_range') ?: ['', '']; |
| 64 |
$filter = []; |
| 65 |
$stats = $reporting->getTicketResolveGrowth($from, $to); |
| 66 |
|
| 67 |
if($agent_id = $request->get('agent_id')) { |
| 68 |
$filter['agent_id'] = $agent_id; |
| 69 |
$stats = $reporting->getTicketResolveGrowth($from, $to, $filter); |
| 70 |
} |
| 71 |
|
| 72 |
return [ |
| 73 |
'stats' => $stats |
| 74 |
]; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* getResponseChart method will generate response statistics for ticket by date range |
| 79 |
* @param Request $request |
| 80 |
* @param Reporting $reporting |
| 81 |
* @return array |
| 82 |
*/ |
| 83 |
public function getResponseChart(Request $request, Reporting $reporting) |
| 84 |
{ |
| 85 |
list($from, $to) = $request->get('date_range') ?: ['', '']; |
| 86 |
$filter = []; |
| 87 |
$stats = $reporting->getResponseGrowth($from, $to); |
| 88 |
|
| 89 |
if($person_id = $request->get('agent_id')) { |
| 90 |
$filter['person_id'] = $person_id; |
| 91 |
$stats = $reporting->getResponseGrowth($from, $to, $filter); |
| 92 |
} |
| 93 |
|
| 94 |
return [ |
| 95 |
'stats' => $stats |
| 96 |
]; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* getAgentsSummary method will generate summary for agent |
| 101 |
* This method will count closed tickets, open tickets, responses/interactions with ticket by agent within a date range |
| 102 |
* @param Request $request |
| 103 |
* @param Reporting $reporting |
| 104 |
* @return array |
| 105 |
*/ |
| 106 |
public function getAgentsSummary(Request $request, Reporting $reporting) |
| 107 |
{ |
| 108 |
return [ |
| 109 |
'summary' => $reporting->agentSummary($request->get('from'), $request->get('to')) |
| 110 |
]; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* getAgentOverallReports method will return the overall statistics report for logged-in agent |
| 115 |
* @param Request $request |
| 116 |
* @return array |
| 117 |
*/ |
| 118 |
public function getAgentOverallReports(Request $request) |
| 119 |
{ |
| 120 |
$agent = Helper::getAgentByUserId(get_current_user_id()); |
| 121 |
|
| 122 |
return [ |
| 123 |
'overall_reports' => StatModule::getAgentOverallStats($agent->id), |
| 124 |
'today_reports' => StatModule::getTodayStats($agent->id) |
| 125 |
]; |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* getAgentResolveChart method will generate ticket data for resolved ticket |
| 130 |
* @param Request $request |
| 131 |
* @param Reporting $reporting |
| 132 |
* @return array |
| 133 |
*/ |
| 134 |
public function getAgentResolveChart(Request $request, Reporting $reporting) |
| 135 |
{ |
| 136 |
//Get logged in agent information |
| 137 |
$agent = Helper::getAgentByUserId(get_current_user_id()); |
| 138 |
list($from, $to) = $request->get('date_range') ?: ['', '']; |
| 139 |
|
| 140 |
return [ |
| 141 |
'stats' => $reporting->getTicketResolveGrowth($from, $to, ['agent_id' => $agent->id]) |
| 142 |
]; |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* getAgentResponseChart method will generate the statistics of response by agent in tickets within date range |
| 147 |
* @param Request $request |
| 148 |
* @param Reporting $reporting |
| 149 |
* @return array |
| 150 |
*/ |
| 151 |
public function getAgentResponseChart(Request $request, Reporting $reporting) |
| 152 |
{ |
| 153 |
$agent = Helper::getAgentByUserId(get_current_user_id()); |
| 154 |
list($from, $to) = $request->get('date_range') ?: ['', '']; |
| 155 |
|
| 156 |
return [ |
| 157 |
'stats' => $reporting->getResponseGrowth($from, $to, ['person_id' => $agent->id]) |
| 158 |
]; |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* getPersonalSummary method will generate summary for specific agent |
| 163 |
* This method will count closed tickets, open tickets, responses/interactions with ticket by agent within a date range |
| 164 |
* @param Reporting $reporting |
| 165 |
* @param Request $request |
| 166 |
* @return array |
| 167 |
*/ |
| 168 |
public function getPersonalSummary(Reporting $reporting, Request $request) |
| 169 |
{ |
| 170 |
$agent = Helper::getAgentByUserId(get_current_user_id()); |
| 171 |
|
| 172 |
return [ |
| 173 |
'summary' => $reporting->agentSummary($request->get('from'), $request->get('to'), $agent->id) |
| 174 |
]; |
| 175 |
} |
| 176 |
} |
| 177 |
|