|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\ViewComposers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Model\helpdesk\Agent\Department; |
|
6
|
|
|
use App\Model\helpdesk\Settings\Company; |
|
7
|
|
|
use App\Model\helpdesk\Ticket\Tickets; |
|
8
|
|
|
use App\User; |
|
9
|
|
|
use Auth; |
|
10
|
|
|
use Illuminate\View\View; |
|
11
|
|
|
|
|
12
|
|
|
class AgentLayout |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* The user repository implementation. |
|
16
|
|
|
* |
|
17
|
|
|
* @var UserRepository |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $company; |
|
20
|
|
|
protected $users; |
|
21
|
|
|
protected $tickets; |
|
22
|
|
|
protected $department; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Create a new profile composer. |
|
26
|
|
|
* |
|
27
|
|
|
* @param |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(Company $company, User $users, Tickets $tickets, Department $department) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->company = $company; |
|
|
|
|
|
|
34
|
|
|
$this->auth = Auth::user(); |
|
|
|
|
|
|
35
|
|
|
$this->users = $users; |
|
36
|
|
|
$this->tickets = $tickets; |
|
37
|
|
|
$this->department = $department; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Bind data to the view. |
|
42
|
|
|
* |
|
43
|
|
|
* @param View $view |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
public function compose(View $view) |
|
48
|
|
|
{ |
|
49
|
|
|
$notifications = \App\Http\Controllers\Common\NotificationController::getNotifications(); |
|
50
|
|
|
$view->with([ |
|
51
|
|
|
'company' => $this->company, |
|
52
|
|
|
'notifications' => $notifications, |
|
53
|
|
|
'myticket' => $this->myTicket(), |
|
54
|
|
|
'unassigned' => $this->unassigned(), |
|
55
|
|
|
'followup_ticket' => $this->followupTicket(), |
|
56
|
|
|
'deleted' => $this->deleted(), |
|
57
|
|
|
'tickets' => $this->inbox(), |
|
58
|
|
|
'department' => $this->departments(), |
|
59
|
|
|
'overdues' => $this->overdues(), |
|
60
|
|
|
'due_today' => $this->getDueToday(), |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function users() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->users->select('id', 'profile_pic'); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function tickets() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->tickets->select('id', 'ticket_number'); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function departments() |
|
75
|
|
|
{ |
|
76
|
|
|
$array = []; |
|
|
|
|
|
|
77
|
|
|
$tickets = $this->tickets; |
|
78
|
|
|
if (\Auth::user()->role == 'agent') { |
|
79
|
|
|
$tickets = $tickets->where('tickets.dept_id', '=', \Auth::user()->primary_dpt); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
$tickets = $tickets |
|
82
|
|
|
->leftJoin('department as dep', 'tickets.dept_id', '=', 'dep.id') |
|
83
|
|
|
->leftJoin('ticket_status', 'tickets.status', '=', 'ticket_status.id') |
|
84
|
|
|
->select('dep.name as name', 'ticket_status.name as status', \DB::raw('COUNT(ticket_status.name) as count')) |
|
85
|
|
|
->groupBy('dep.name', 'ticket_status.name') |
|
86
|
|
|
->get(); |
|
87
|
|
|
$grouped = $tickets->groupBy('name'); |
|
88
|
|
|
$status = []; |
|
89
|
|
|
foreach ($grouped as $key => $group) { |
|
90
|
|
|
$status[$key] = $group->keyBy('status'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return collect($status); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function myTicket() |
|
97
|
|
|
{ |
|
98
|
|
|
$ticket = $this->tickets(); |
|
99
|
|
|
if ($this->auth->role == 'admin') { |
|
100
|
|
|
return $ticket->where('assigned_to', $this->auth->id) |
|
101
|
|
|
->where('status', '1'); |
|
102
|
|
|
} elseif ($this->auth->role == 'agent') { |
|
103
|
|
|
return $ticket->where('assigned_to', $this->auth->id) |
|
104
|
|
|
->where('status', '1'); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function unassigned() |
|
109
|
|
|
{ |
|
110
|
|
|
$ticket = $this->tickets(); |
|
111
|
|
|
if ($this->auth->role == 'admin') { |
|
112
|
|
|
return $ticket->where('assigned_to', '=', null) |
|
113
|
|
|
->where('status', '=', '1') |
|
114
|
|
|
->select('id'); |
|
115
|
|
|
} elseif ($this->auth->role == 'agent') { |
|
116
|
|
|
return $ticket->where('assigned_to', '=', null) |
|
117
|
|
|
->where('status', '=', '1') |
|
118
|
|
|
->where('dept_id', '=', $this->auth->primary_dpt) |
|
119
|
|
|
->select('id'); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function followupTicket() |
|
124
|
|
|
{ |
|
125
|
|
|
$ticket = $this->tickets(); |
|
126
|
|
|
if ($this->auth->role == 'admin') { |
|
127
|
|
|
return $ticket->where('status', '1')->where('follow_up', '1')->select('id'); |
|
128
|
|
|
} elseif ($this->auth->role == 'agent') { |
|
129
|
|
|
return $ticket->where('status', '1')->where('follow_up', '1')->select('id'); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function deleted() |
|
134
|
|
|
{ |
|
135
|
|
|
$ticket = $this->tickets(); |
|
136
|
|
|
if ($this->auth->role == 'admin') { |
|
137
|
|
|
return $ticket->where('status', '5')->select('id'); |
|
138
|
|
|
} elseif ($this->auth->role == 'agent') { |
|
139
|
|
|
return $ticket->where('status', '5')->where('dept_id', '=', $this->auth->primary_dpt) |
|
140
|
|
|
->select('id'); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function inbox() |
|
145
|
|
|
{ |
|
146
|
|
|
$table = $this->tickets(); |
|
147
|
|
|
if (Auth::user()->role == 'agent') { |
|
148
|
|
|
$id = Auth::user()->primary_dpt; |
|
149
|
|
|
$table = $table->where('tickets.dept_id', '=', $id)->orWhere('assigned_to', '=', Auth::user()->id); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
return $table->Join('ticket_status', function ($join) { |
|
153
|
|
|
$join->on('ticket_status.id', '=', 'tickets.status') |
|
154
|
|
|
->whereIn('ticket_status.id', [1, 7]); |
|
155
|
|
|
}); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function overdues() |
|
159
|
|
|
{ |
|
160
|
|
|
$ticket = $this->tickets(); |
|
161
|
|
|
if ($this->auth->role == 'admin') { |
|
162
|
|
|
return $ticket->where('status', '=', 1) |
|
163
|
|
|
->where('isanswered', '=', 0) |
|
164
|
|
|
->whereNotNull('tickets.duedate') |
|
165
|
|
|
->where('tickets.duedate', '!=', '00-00-00 00:00:00') |
|
166
|
|
|
->where('tickets.duedate', '<', \Carbon\Carbon::now()) |
|
167
|
|
|
->select('tickets.id'); |
|
168
|
|
View Code Duplication |
} elseif ($this->auth->role == 'agent') { |
|
|
|
|
|
|
169
|
|
|
return $ticket->where('status', '=', 1) |
|
170
|
|
|
->where('isanswered', '=', 0) |
|
171
|
|
|
->whereNotNull('tickets.duedate') |
|
172
|
|
|
->where('dept_id', '=', $this->auth->primary_dpt) |
|
173
|
|
|
->where('tickets.duedate', '!=', '00-00-00 00:00:00') |
|
174
|
|
|
->where('tickets.duedate', '<', \Carbon\Carbon::now()) |
|
175
|
|
|
->select('tickets.id'); |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
public function getDueToday() |
|
180
|
|
|
{ |
|
181
|
|
|
$ticket = $this->tickets(); |
|
182
|
|
|
if ($this->auth->role == 'admin') { |
|
183
|
|
|
return $ticket->where('status', '=', 1) |
|
184
|
|
|
->where('status', '=', 1) |
|
185
|
|
|
->where('isanswered', '=', 0) |
|
186
|
|
|
->whereNotNull('duedate') |
|
187
|
|
|
->whereRaw('date(duedate) = ?', [date('Y-m-d')]); |
|
188
|
|
View Code Duplication |
} elseif ($this->auth->role == 'agent') { |
|
|
|
|
|
|
189
|
|
|
return $ticket->where('status', '=', 1) |
|
190
|
|
|
->where('status', '=', 1) |
|
191
|
|
|
->where('isanswered', '=', 0) |
|
192
|
|
|
->whereNotNull('duedate') |
|
193
|
|
|
->where('dept_id', '=', $this->auth->primary_dpt) |
|
194
|
|
|
->whereRaw('date(duedate) = ?', [date('Y-m-d')]); |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
|
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.