| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentSupport\App\Modules\Reporting\Reporting; |
| 6 |
use FluentSupport\App\Modules\StatModule; |
| 7 |
use FluentSupport\App\Services\Helper; |
| 8 |
use FluentSupport\Framework\Request\Request; |
| 9 |
use FluentSupport\App\Models\Ticket; |
| 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 |
public function getActiveTicketsByProduct() |
| 35 |
{ |
| 36 |
return [ |
| 37 |
'stats' => StatModule::getActiveTicketsByProductStats() |
| 38 |
]; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* getTicketsChart method will generate statistics for all tickets within a date range and return ticket number by date |
| 43 |
* @param Request $request |
| 44 |
* @param Reporting $reporting |
| 45 |
* @return array |
| 46 |
*/ |
| 47 |
public function getTicketsChart(Request $request, Reporting $reporting) |
| 48 |
{ |
| 49 |
list($from, $to) = $request->getSafe('date_range', 'sanitize_text_field') ?: ['', '']; |
| 50 |
|
| 51 |
$filter = [ |
| 52 |
'agent_id' => $request->getSafe('agent_id', 'intval') ?: null, |
| 53 |
'product_id' => $request->getSafe('product_id', 'intval') ?: null, |
| 54 |
'mailbox_id' => $request->getSafe('mailbox_id', 'intval') ?: null, |
| 55 |
]; |
| 56 |
|
| 57 |
$stats = $reporting->getTicketsGrowth($from, $to, $filter); |
| 58 |
|
| 59 |
return [ |
| 60 |
'stats' => $stats |
| 61 |
]; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* getResolveChart method will generate statistics for closed tickets within a date range and return ticket number by date |
| 66 |
* @param Request $request |
| 67 |
* @param Reporting $reporting |
| 68 |
* @return array |
| 69 |
*/ |
| 70 |
public static function getResolveChart(Request $request, Reporting $reporting): array |
| 71 |
{ |
| 72 |
$type = $request->getSafe('type', 'sanitize_text_field'); |
| 73 |
list($from, $to) = $request->getSafe('date_range', 'sanitize_text_field') ?: ['', '']; |
| 74 |
|
| 75 |
$filter = [ |
| 76 |
'agent_id' => $request->getSafe('agent_id', 'intval') ?: null, |
| 77 |
'product_id' => $request->getSafe('product_id', 'intval') ?: null, |
| 78 |
'mailbox_id' => $request->getSafe('mailbox_id', 'intval') ?: null, |
| 79 |
]; |
| 80 |
|
| 81 |
$stats = $reporting->getTicketResolveGrowth($from, $to, $filter,$type); |
| 82 |
|
| 83 |
return [ |
| 84 |
'stats' => $stats |
| 85 |
]; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* getResponseChart method will generate response statistics for ticket by date range |
| 90 |
* @param Request $request |
| 91 |
* @param Reporting $reporting |
| 92 |
* @return array |
| 93 |
*/ |
| 94 |
public function getResponseChart(Request $request, Reporting $reporting) |
| 95 |
{ |
| 96 |
list($from, $to) = $request->getSafe('date_range', 'sanitize_text_field') ?: ['', '']; |
| 97 |
$filter = []; |
| 98 |
$stats = $reporting->getResponseGrowth($from, $to); |
| 99 |
|
| 100 |
if($person_id = $request->getSafe('agent_id', 'intval')) { |
| 101 |
$filter['person_id'] = $person_id; |
| 102 |
$stats = $reporting->getResponseGrowth($from, $to, $filter); |
| 103 |
} |
| 104 |
|
| 105 |
return [ |
| 106 |
'stats' => $stats |
| 107 |
]; |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* getAgentsSummary method will generate summary for agent |
| 112 |
* This method will count closed tickets, open tickets, responses/interactions with ticket by agent within a date range |
| 113 |
* @param Request $request |
| 114 |
* @param Reporting $reporting |
| 115 |
* @return array |
| 116 |
*/ |
| 117 |
public function getAgentsSummary(Request $request, Reporting $reporting) |
| 118 |
{ |
| 119 |
return [ |
| 120 |
'summary' => $reporting->agentSummary($request->getSafe('from'), $request->getSafe('to')) |
| 121 |
]; |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* getAgentOverallReports method will return the overall statistics report for logged-in agent |
| 126 |
* @param Request $request |
| 127 |
* @return array |
| 128 |
*/ |
| 129 |
public function getAgentOverallReports(Request $request): array |
| 130 |
{ |
| 131 |
$agent = Helper::getAgentByUserId(get_current_user_id()); |
| 132 |
|
| 133 |
return [ |
| 134 |
'overall_reports' => StatModule::getAgentOverallStats($agent->id), |
| 135 |
'today_reports' => StatModule::getTodayStats($agent->id) |
| 136 |
]; |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* getResponseGrowthChart method will generate response statistics for ticket by date range for product or mailbox |
| 141 |
* @param Request $request |
| 142 |
* @param Reporting $reporting |
| 143 |
* @return array |
| 144 |
*/ |
| 145 |
public static function getResponseGrowthChart(Request $request,Reporting $reporting): array |
| 146 |
{ |
| 147 |
$type = $request->getSafe('type', 'sanitize_text_field'); |
| 148 |
list($from, $to) = $request->getSafe('date_range', 'sanitize_text_field') ?: ['', '']; |
| 149 |
|
| 150 |
$filter = [ |
| 151 |
'product_id' => $request->getSafe('product_id', 'intval') ?: null, |
| 152 |
'mailbox_id' => $request->getSafe('mailbox_id', 'intval') ?: null, |
| 153 |
]; |
| 154 |
|
| 155 |
$stats = $reporting->getResponseGrowthChart($from, $to, $filter,$type); |
| 156 |
|
| 157 |
return [ |
| 158 |
'stats' => $stats |
| 159 |
]; |
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* getProductsSummary method will generate summary for product |
| 164 |
* This method will count closed tickets, open tickets, responses, interactions with ticket by agent within a date range |
| 165 |
* @param Request $request |
| 166 |
* @param Reporting $reporting |
| 167 |
* @return array |
| 168 |
*/ |
| 169 |
public static function getProductsSummary(Request $request,Reporting $reporting): array |
| 170 |
{ |
| 171 |
return [ |
| 172 |
'summary' => $reporting->getSummary('product',$request->getSafe('from', 'sanitize_text_field'), $request->getSafe('to', 'sanitize_text_field')) |
| 173 |
]; |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* getMailBoxesSummary method will generate summary for mailbox |
| 179 |
* This method will count closed tickets, open tickets, responses, interactions with ticket by agent within a date range |
| 180 |
* @param Request $request |
| 181 |
* @param Reporting $reporting |
| 182 |
* @return array |
| 183 |
*/ |
| 184 |
public static function getMailBoxesSummary(Request $request,Reporting $reporting): array |
| 185 |
{ |
| 186 |
return [ |
| 187 |
'summary' => $reporting->getSummary('mailbox',$request->getSafe('from'), $request->getSafe('to')) |
| 188 |
]; |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* getAgentResolveChart method will generate ticket data for resolved ticket |
| 193 |
* @param Request $request |
| 194 |
* @param Reporting $reporting |
| 195 |
* @return array |
| 196 |
*/ |
| 197 |
public function getAgentResolveChart(Request $request, Reporting $reporting) |
| 198 |
{ |
| 199 |
//Get logged in agent information |
| 200 |
$agent = Helper::getAgentByUserId(get_current_user_id()); |
| 201 |
list($from, $to) = $request->getSafe('date_range', 'sanitize_text_field') ?: ['', '']; |
| 202 |
|
| 203 |
return [ |
| 204 |
'stats' => $reporting->getTicketResolveGrowth($from, $to, ['agent_id' => $agent->id]) |
| 205 |
]; |
| 206 |
} |
| 207 |
|
| 208 |
/** |
| 209 |
* getAgentResponseChart method will generate the statistics of response by agent in tickets within date range |
| 210 |
* @param Request $request |
| 211 |
* @param Reporting $reporting |
| 212 |
* @return array |
| 213 |
*/ |
| 214 |
public function getAgentResponseChart(Request $request, Reporting $reporting) |
| 215 |
{ |
| 216 |
$agent = Helper::getAgentByUserId(get_current_user_id()); |
| 217 |
list($from, $to) = $request->getSafe('date_range', 'sanitize_text_field') ?: ['', '']; |
| 218 |
|
| 219 |
return [ |
| 220 |
'stats' => $reporting->getResponseGrowth($from, $to, ['person_id' => $agent->id]) |
| 221 |
]; |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* getPersonalSummary method will generate summary for specific agent |
| 226 |
* This method will count closed tickets, open tickets, responses/interactions with ticket by agent within a date range |
| 227 |
* @param Reporting $reporting |
| 228 |
* @param Request $request |
| 229 |
* @return array |
| 230 |
*/ |
| 231 |
public function getPersonalSummary(Reporting $reporting, Request $request) |
| 232 |
{ |
| 233 |
$agent = Helper::getAgentByUserId(get_current_user_id()); |
| 234 |
|
| 235 |
return [ |
| 236 |
'summary' => $reporting->agentSummary($request->getSafe('from', 'sanitize_text_field'), $request->getSafe('to', 'sanitize_text_field'), $agent->id) |
| 237 |
]; |
| 238 |
} |
| 239 |
|
| 240 |
public function dayTimeStats(Reporting $reporting, Request $request) |
| 241 |
{ |
| 242 |
list($from, $to) = $request->getSafe('date_range', 'sanitize_text_field') ?: ['', '']; |
| 243 |
|
| 244 |
$filter = [ |
| 245 |
'report_type' => $request->getSafe('report_type', 'sanitize_text_field') ?: null, |
| 246 |
'agent_id' => $request->getSafe('agent_id', 'intval') ?: null, |
| 247 |
]; |
| 248 |
|
| 249 |
$results = $reporting->getQueryResults($from, $to, $filter); |
| 250 |
|
| 251 |
return $this->send([ |
| 252 |
'stats' => $results |
| 253 |
]); |
| 254 |
} |
| 255 |
|
| 256 |
public function ticketResponseStats(Reporting $reporting, Request $request) |
| 257 |
{ |
| 258 |
|
| 259 |
list($from, $to) = $request->getSafe('date_range', 'sanitize_text_field') ?: ['', '']; |
| 260 |
|
| 261 |
$filter = [ |
| 262 |
'person_type' => $request->getSafe('person_type', 'sanitize_text_field') ?: null, |
| 263 |
'person_id' => $request->getSafe('person_id', 'intval') ?: null, |
| 264 |
]; |
| 265 |
|
| 266 |
return $reporting->getTicketResponseStats($from, $to, $filter); |
| 267 |
} |
| 268 |
|
| 269 |
} |
| 270 |
|