|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Agent\helpdesk; |
|
4
|
|
|
|
|
5
|
|
|
// controllers |
|
6
|
|
|
use App\Http\Controllers\Controller; |
|
7
|
|
|
use App\Model\helpdesk\Manage\Help_topic; |
|
8
|
|
|
// request |
|
9
|
|
|
use App\Model\helpdesk\Ticket\Tickets; |
|
10
|
|
|
// Model |
|
11
|
|
|
use Illuminate\Http\Request; |
|
12
|
|
|
// classes |
|
13
|
|
|
use PDF; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* ReportController |
|
17
|
|
|
* This controlleris used to fetch reports in the agent panel. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Ladybird <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class ReportController extends Controller |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Create a new controller instance. |
|
25
|
|
|
* constructor to check |
|
26
|
|
|
* 1. authentication |
|
27
|
|
|
* 2. user roles |
|
28
|
|
|
* 3. roles must be agent. |
|
29
|
|
|
* |
|
30
|
|
|
* @return void |
|
|
|
|
|
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct() |
|
33
|
|
|
{ |
|
34
|
|
|
// checking for authentication |
|
35
|
|
|
$this->middleware('auth'); |
|
36
|
|
|
// checking if the role is agent |
|
37
|
|
|
$this->middleware('role.agent'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Get the Report page. |
|
42
|
|
|
* |
|
43
|
|
|
* @return type view |
|
44
|
|
|
*/ |
|
45
|
|
|
public function index() |
|
46
|
|
|
{ |
|
47
|
|
|
try { |
|
48
|
|
|
return view('themes.default1.agent.helpdesk.report.index'); |
|
49
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* function to get help_topic graph. |
|
55
|
|
|
* |
|
56
|
|
|
* @param type $date111 |
|
57
|
|
|
* @param type $date122 |
|
58
|
|
|
* @param type $helptopic |
|
59
|
|
|
*/ |
|
60
|
|
|
public function chartdataHelptopic(Request $request, $date111 = '', $date122 = '', $helptopic = '') |
|
61
|
|
|
{ |
|
62
|
|
|
$date11 = strtotime($date122); |
|
63
|
|
|
$date12 = strtotime($date111); |
|
64
|
|
|
$help_topic = $helptopic; |
|
65
|
|
|
$duration = $request->input('duration'); |
|
66
|
|
|
if ($date11 && $date12 && $help_topic) { |
|
67
|
|
|
$date2 = $date12; |
|
68
|
|
|
$date1 = $date11; |
|
69
|
|
|
$duration = null; |
|
70
|
|
|
if ($request->input('open') == null || $request->input('closed') == null || $request->input('reopened') == null || $request->input('overdue') == null || $request->input('deleted') == null) { |
|
71
|
|
|
$duration = 'day'; |
|
72
|
|
|
} |
|
73
|
|
|
} else { |
|
74
|
|
|
// generating current date |
|
75
|
|
|
$date2 = strtotime(date('Y-m-d')); |
|
76
|
|
|
$date3 = date('Y-m-d'); |
|
77
|
|
|
$format = 'Y-m-d'; |
|
78
|
|
|
// generating a date range of 1 month |
|
79
|
|
|
if ($request->input('duration') == 'day') { |
|
80
|
|
|
$date1 = strtotime(date($format, strtotime('-15 day'.$date3))); |
|
81
|
|
|
} elseif ($request->input('duration') == 'week') { |
|
82
|
|
|
$date1 = strtotime(date($format, strtotime('-69 days'.$date3))); |
|
83
|
|
|
} elseif ($request->input('duration') == 'month') { |
|
84
|
|
|
$date1 = strtotime(date($format, strtotime('-179 days'.$date3))); |
|
85
|
|
|
} else { |
|
86
|
|
|
$date1 = strtotime(date($format, strtotime('-30 days'.$date3))); |
|
87
|
|
|
} |
|
88
|
|
|
// $help_topic = Help_topic::where('status', '=', '1')->min('id'); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$return = ''; |
|
92
|
|
|
$last = ''; |
|
|
|
|
|
|
93
|
|
|
$j = 0; |
|
94
|
|
|
$created1 = ''; |
|
95
|
|
|
$closed1 = ''; |
|
96
|
|
|
$reopened1 = ''; |
|
97
|
|
|
$in_progress = \DB::table('tickets')->where('help_topic_id', '=', $help_topic)->where('status', '=', 1)->count(); |
|
98
|
|
|
|
|
99
|
|
|
for ($i = $date1; $i <= $date2; $i = $i + 86400) { |
|
100
|
|
|
$j++; |
|
101
|
|
|
$thisDate = date('Y-m-d', $i); |
|
102
|
|
|
$thisDate1 = date('jS F', $i); |
|
103
|
|
|
$open_array = []; |
|
104
|
|
|
$closed_array = []; |
|
105
|
|
|
$reopened_array = []; |
|
106
|
|
|
|
|
107
|
|
|
if ($request->input('open') || $request->input('closed') || $request->input('reopened')) { |
|
108
|
|
View Code Duplication |
if ($request->input('open') && $request->input('open') == 'on') { |
|
|
|
|
|
|
109
|
|
|
$created = \DB::table('tickets')->select('created_at')->where('help_topic_id', '=', $help_topic)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count(); |
|
110
|
|
|
$open_array = ['open' => $created]; |
|
111
|
|
|
} |
|
112
|
|
View Code Duplication |
if ($request->input('closed') && $request->input('closed') == 'on') { |
|
|
|
|
|
|
113
|
|
|
$closed = \DB::table('tickets')->select('closed_at')->where('help_topic_id', '=', $help_topic)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count(); |
|
114
|
|
|
$closed_array = ['closed' => $closed]; |
|
115
|
|
|
} |
|
116
|
|
View Code Duplication |
if ($request->input('reopened') && $request->input('reopened') == 'on') { |
|
|
|
|
|
|
117
|
|
|
$reopened = \DB::table('tickets')->select('reopened_at')->where('help_topic_id', '=', $help_topic)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count(); |
|
118
|
|
|
$reopened_array = ['reopened' => $reopened]; |
|
119
|
|
|
} |
|
120
|
|
|
// if ($request->input('overdue') && $request->input('overdue') == 'on') { |
|
|
|
|
|
|
121
|
|
|
// $overdue = Tickets::where('status', '=', 1)->where('isanswered', '=', 0)->where('dept_id', '=', $dept->id)->orderBy('id', 'DESC')->get(); |
|
122
|
|
|
// } |
|
123
|
|
|
// $open_array = ['open'=>$created1]; |
|
124
|
|
|
// $closed_array = ['closed'=>$closed1]; |
|
125
|
|
|
// $reopened_array = ['reopened'=>$reopened1]; |
|
126
|
|
|
$value = ['date' => $thisDate1]; |
|
127
|
|
|
// if($open_array) { |
|
|
|
|
|
|
128
|
|
|
$value = array_merge($value, $open_array); |
|
129
|
|
|
$value = array_merge($value, $closed_array); |
|
130
|
|
|
$value = array_merge($value, $reopened_array); |
|
131
|
|
|
$value = array_merge($value, ['inprogress' => $in_progress]); |
|
132
|
|
|
// } else { |
|
|
|
|
|
|
133
|
|
|
// $value = ""; |
|
134
|
|
|
// } |
|
135
|
|
|
$array = array_map('htmlentities', $value); |
|
136
|
|
|
$json = html_entity_decode(json_encode($array)); |
|
137
|
|
|
$return .= $json.','; |
|
138
|
|
|
} else { |
|
139
|
|
|
if ($duration == 'week') { |
|
140
|
|
|
$created = \DB::table('tickets')->select('created_at')->where('help_topic_id', '=', $help_topic)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count(); |
|
141
|
|
|
$created1 += $created; |
|
142
|
|
|
$closed = \DB::table('tickets')->select('closed_at')->where('help_topic_id', '=', $help_topic)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count(); |
|
143
|
|
|
$closed1 += $closed; |
|
144
|
|
|
$reopened = \DB::table('tickets')->select('reopened_at')->where('help_topic_id', '=', $help_topic)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count(); |
|
145
|
|
|
$reopened1 += $reopened; |
|
146
|
|
View Code Duplication |
if ($j % 7 == 0) { |
|
|
|
|
|
|
147
|
|
|
$open_array = ['open' => $created1]; |
|
148
|
|
|
$created1 = 0; |
|
149
|
|
|
$closed_array = ['closed' => $closed1]; |
|
150
|
|
|
$closed1 = 0; |
|
151
|
|
|
$reopened_array = ['reopened' => $reopened1]; |
|
152
|
|
|
$reopened1 = 0; |
|
153
|
|
|
$value = ['date' => $thisDate1]; |
|
154
|
|
|
// if($open_array) { |
|
|
|
|
|
|
155
|
|
|
$value = array_merge($value, $open_array); |
|
156
|
|
|
$value = array_merge($value, $closed_array); |
|
157
|
|
|
$value = array_merge($value, $reopened_array); |
|
158
|
|
|
$value = array_merge($value, ['inprogress' => $in_progress]); |
|
159
|
|
|
// } else { |
|
|
|
|
|
|
160
|
|
|
// $value = ""; |
|
161
|
|
|
// } |
|
162
|
|
|
$array = array_map('htmlentities', $value); |
|
163
|
|
|
$json = html_entity_decode(json_encode($array)); |
|
164
|
|
|
$return .= $json.','; |
|
165
|
|
|
} |
|
166
|
|
|
} elseif ($duration == 'month') { |
|
167
|
|
|
$created_month = \DB::table('tickets')->select('created_at')->where('help_topic_id', '=', $help_topic)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count(); |
|
168
|
|
|
$created1 += $created_month; |
|
169
|
|
|
$closed_month = \DB::table('tickets')->select('closed_at')->where('help_topic_id', '=', $help_topic)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count(); |
|
170
|
|
|
$closed1 += $closed_month; |
|
171
|
|
|
$reopened_month = \DB::table('tickets')->select('reopened_at')->where('help_topic_id', '=', $help_topic)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count(); |
|
172
|
|
|
$reopened1 += $reopened_month; |
|
173
|
|
View Code Duplication |
if ($j % 30 == 0) { |
|
|
|
|
|
|
174
|
|
|
$open_array = ['open' => $created1]; |
|
175
|
|
|
$created1 = 0; |
|
176
|
|
|
$closed_array = ['closed' => $closed1]; |
|
177
|
|
|
$closed1 = 0; |
|
178
|
|
|
$reopened_array = ['reopened' => $reopened1]; |
|
179
|
|
|
$reopened1 = 0; |
|
180
|
|
|
$value = ['date' => $thisDate1]; |
|
181
|
|
|
|
|
182
|
|
|
$value = array_merge($value, $open_array); |
|
183
|
|
|
$value = array_merge($value, $closed_array); |
|
184
|
|
|
$value = array_merge($value, $reopened_array); |
|
185
|
|
|
$value = array_merge($value, ['inprogress' => $in_progress]); |
|
186
|
|
|
|
|
187
|
|
|
$array = array_map('htmlentities', $value); |
|
188
|
|
|
$json = html_entity_decode(json_encode($array)); |
|
189
|
|
|
$return .= $json.','; |
|
190
|
|
|
} |
|
191
|
|
|
} else { |
|
192
|
|
|
if ($request->input('default') == null) { |
|
193
|
|
|
$help_topic = Help_topic::where('status', '=', '1')->min('id'); |
|
194
|
|
|
} |
|
195
|
|
|
$created = \DB::table('tickets')->select('created_at')->where('help_topic_id', '=', $help_topic)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count(); |
|
196
|
|
|
$open_array = ['open' => $created]; |
|
|
|
|
|
|
197
|
|
|
$closed = \DB::table('tickets')->select('closed_at')->where('help_topic_id', '=', $help_topic)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count(); |
|
198
|
|
|
$closed_array = ['closed' => $closed]; |
|
|
|
|
|
|
199
|
|
|
$reopened = \DB::table('tickets')->select('reopened_at')->where('help_topic_id', '=', $help_topic)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count(); |
|
200
|
|
|
$reopened_array = ['reopened' => $reopened]; |
|
|
|
|
|
|
201
|
|
|
if ($j % 1 == 0) { |
|
202
|
|
|
$open_array = ['open' => $created]; |
|
203
|
|
|
$created = 0; |
|
|
|
|
|
|
204
|
|
|
$closed_array = ['closed' => $closed]; |
|
205
|
|
|
$closed = 0; |
|
|
|
|
|
|
206
|
|
|
$reopened_array = ['reopened' => $reopened]; |
|
207
|
|
|
$reopened = 0; |
|
|
|
|
|
|
208
|
|
|
$value = ['date' => $thisDate1]; |
|
209
|
|
|
if ($request->input('default') == null) { |
|
210
|
|
|
$value = array_merge($value, $open_array); |
|
211
|
|
|
$value = array_merge($value, $closed_array); |
|
212
|
|
|
$value = array_merge($value, $reopened_array); |
|
213
|
|
|
$value = array_merge($value, ['inprogress' => $in_progress]); |
|
214
|
|
|
} else { |
|
215
|
|
|
if ($duration == null) { |
|
|
|
|
|
|
216
|
|
|
if ($request->input('open') == 'on') { |
|
217
|
|
|
$value = array_merge($value, $open_array); |
|
218
|
|
|
} |
|
219
|
|
|
if ($request->input('closed') == 'on') { |
|
220
|
|
|
$value = array_merge($value, $closed_array); |
|
221
|
|
|
} |
|
222
|
|
|
if ($request->input('reopened') == 'on') { |
|
223
|
|
|
$value = array_merge($value, $reopened_array); |
|
224
|
|
|
} |
|
225
|
|
|
} else { |
|
226
|
|
|
$value = array_merge($value, $open_array); |
|
227
|
|
|
$value = array_merge($value, $closed_array); |
|
228
|
|
|
$value = array_merge($value, $reopened_array); |
|
229
|
|
|
$value = array_merge($value, ['inprogress' => $in_progress]); |
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
// } else { |
|
|
|
|
|
|
234
|
|
|
// $value = ""; |
|
235
|
|
|
// } |
|
236
|
|
|
$array = array_map('htmlentities', $value); |
|
237
|
|
|
$json = html_entity_decode(json_encode($array)); |
|
238
|
|
|
$return .= $json.','; |
|
239
|
|
|
} |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
// $value = ['date' => $thisDate]; |
|
|
|
|
|
|
244
|
|
|
// if($open_array) { |
|
245
|
|
|
// $value = array_merge($value,$open_array); |
|
246
|
|
|
// } |
|
247
|
|
|
// if($closed_array) { |
|
248
|
|
|
// $value = array_merge($value,$closed_array); |
|
249
|
|
|
// } |
|
250
|
|
|
// if($reopened_array) { |
|
251
|
|
|
// $value = array_merge($value,$reopened_array); |
|
252
|
|
|
// } |
|
253
|
|
|
} |
|
254
|
|
|
$last = rtrim($return, ','); |
|
255
|
|
|
|
|
256
|
|
|
return '['.$last.']'; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
public function helptopicPdf(Request $request) |
|
260
|
|
|
{ |
|
261
|
|
|
$table_datas = json_decode($request->input('pdf_form')); |
|
262
|
|
|
$table_help_topic = json_decode($request->input('pdf_form_help_topic')); |
|
263
|
|
|
$html = view('themes.default1.agent.helpdesk.report.pdf', compact('table_datas', 'table_help_topic'))->render(); |
|
|
|
|
|
|
264
|
|
|
$html1 = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'); |
|
265
|
|
|
|
|
266
|
|
|
return PDF::load($html1)->show(); |
|
267
|
|
|
} |
|
268
|
|
|
} |
|
269
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.