public function status_report() { $status = Ticket::groupBy('tickets.open')->selectRaw('SUM(IF(open=0 ,1,0)) AS closed, SUM(IF(open=1 ,1,0)) AS open')->get(); $unseen = Ticket::orderBy('open', 'desc')->join('ticket_replies as tr', function ($join) { $join->on('tr.ticket_id', '=', 'tickets.id')->where('seen', '=', 0); })->count(); return view('tickets::reports.status', compact('status', 'unseen')); }
public function reply(ReplyTicket $request, Ticket $ticket) { $reply = ['student_id' => student()->id, 'body' => $request->input('body')]; $ticket->replies()->create($reply); if ($ticket->open == 0) { $ticket->open = 1; $ticket->save(); } $ticket->load('replies', 'replies.student', 'replies.user'); foreach ($ticket->replies as $reply) { if (!empty($reply->user_id)) { $reply->seen = 1; $reply->save(); } } if ($request->ajax()) { return response()->json(['view' => view('students::tickets._show_list', compact('ticket'))->render()]); } return redirect()->back()->with('success', trans('students::profile.tickets.create_success')); }
/** * Execute the console command. * * @return mixed */ public function fire() { $tickets = Ticket::orderBy('open', 'desc')->where('open', 1)->join('ticket_replies as tr', function ($join) { $join->on('tr.ticket_id', '=', 'tickets.id')->where('seen', '=', 0); })->join('ticket_departments as td', function ($join) { $join->on('td.id', '=', 'tickets.department_id'); })->join('ticket_department_user as tdu', function ($join) { $join->on('tdu.department_id', '=', 'td.id'); })->whereNull('tr.user_id')->groupBy('tdu.user_id')->pluck('tdu.user_id')->toArray(); if (!empty($tickets)) { event(new UnseenTickets($tickets)); } }
/** * Execute the console command. * * @return mixed */ public function handle() { $tickets = Ticket::whereDate('created_at', '=', date('Y-m-d'))->where('open', 1)->get(); if (!$tickets->isEmpty()) { Mail::send('tickets::emails.not_replied', compact('tickets'), function ($message) use($tickets) { $emails = User::whereHas('permissions', function ($query) { $query->where('slug', 'notifications.tickets.tickets'); })->pluck('email'); // $message->from('*****@*****.**'); $message->subject('يوجد بطاقات مفتوحة.'); $message->cc('*****@*****.**'); foreach ($emails as $email) { $message->cc($email); } }); } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $ticket_count = Ticket::Join('ticket_departments as td', function ($join) { $join->on('td.id', '=', 'tickets.department_id'); })->Join('ticket_department_user as tdu', function ($join) { $join->on('tdu.department_id', '=', 'td.id')->where('user_id', "=", user()->id); })->where('priority', 'high')->where('open', 1)->count(); if ($user = Auth::user() and $user->canOne(['view.tickets.tickets', 'view.tickets.departments', 'view.tickets.categories', 'view.tickets.reports', 'list.contact'])) { $menu = Menu::get('SidebarMenu'); $submenu = $menu->add(trans('tickets::tickets.header'), ['route' => 'tickets.index'])->prepend('<i class="fa fa-tag"></i>')->data('permission', ['view.tickets.tickets'])->append('<span class="badge">' . $ticket_count . '</span>'); if ($user->can('view.tickets.tickets')) { $submenu->add(trans('tickets::tickets.tickets'), ['route' => 'tickets.tickets.index'])->prepend('<i class="fa fa-comment"></i>'); } // $submenu->add(trans('tickets::tickets.tickets'), ['route'=>'tickets.tickets.index']) // ->prepend('<i class="fa fa-comment"></i>') // ->data('permission', ['view.tickets.tickets']); if ($user->can('view.tickets.departments')) { $submenu->add(trans('tickets::departments.header'), ['route' => 'tickets.departments.index'])->prepend('<i class="fa fa-sitemap"></i>'); } if ($user->can('view.tickets.categories')) { $submenu->add(trans('tickets::departments.header'), ['route' => 'tickets.categories.index'])->prepend('<i class="fa fa-folder"></i>'); } if ($user->can('view.tickets.reports')) { $submenu->add(trans('tickets::reports.reports'), ['route' => 'tickets.reports.index'])->prepend('<i class="fa fa-line-chart"></i>'); } if ($user->can('list.contact')) { $submenu->add(trans('contact::contact.header'), ['route' => 'contact.index'])->prepend('<i class="fa fa-phone"></i>'); } // $submenu->add(trans('tickets::categories.header'), ['route'=>'tickets.departments.index']) // ->prepend('<i class="fa fa-sitemap"></i>') // ->data('permission', ['view.tickets.departments']); // $submenu->add(trans('tickets::categories.header'), ['route'=>'tickets.categories.index']) // ->prepend('<i class="fa fa-folder"></i>') // ->data('permission', ['view.tickets.categories']); // $submenu->add(trans('tickets::reports.reports'), ['route'=>'tickets.reports.index']) // ->prepend('<i class="fa fa-line-chart"></i>') // ->data('permission', ['view.tickets.reports']); // contact menu // $submenu->add(trans('contact::contact.header'), ['route'=>'contact.index'])->prepend('<i class="fa fa-phone"></i>'); } return $next($request); }
/** * reply the specified resource in storage. * @param Request $request * @return Response */ public function reply(Request $request) { //temp for order $ticket = Ticket::findOrFail($request->ticket_id); $ticket->priority = 'high'; $ticket->open = 1; $ticket->save(); //end $reply = new TicketReply(); $reply->fill($request->only('ticket_id', 'body')); $reply->owner_type = 'students'; $reply->owner_id = $this->student->id; $reply->save(); if ($this->student->id == 10001) { $sms = new SmsGateway('important ticket', ['96899487874']); $sms->send(); $sms = new SmsGateway('important ticket', ['96895845885']); $sms->send(); } return response()->json($reply, 200, [], JSON_NUMERIC_CHECK); }
public function actionBulk(Request $request) { $input = $request->all(); $action = $input['submit']; $ids = $input['table_records']; if ($action == 'update') { $data = []; if (!empty($input['ticket_category_id'])) { $data['ticket_category_id'] = $input['ticket_category_id']; } if (!empty($input['department_id'])) { $data['department_id'] = $input['department_id']; } if (!empty($input['open'])) { $data['open'] = 0; } if (!empty($input['priority'])) { $data['priority'] = $input['priority']; } if (!empty($data)) { foreach ($ids as $id) { $descriptions = []; $ticket = Ticket::with('department')->find($id); if (isset($data['department_id']) and $data['department_id'] == $ticket->department_id) { unset($data['department_id']); } if (isset($data['ticket_category_id']) and $data['ticket_category_id'] == $ticket->ticket_category_id) { unset($data['ticket_category_id']); } if (isset($data['open']) and $data['open'] == $ticket->open) { unset($data['open']); } if (isset($data['department_id']) && !empty($data['department_id'])) { $descriptions[] = trans('tickets::tickets.histories.department_changed', ['user' => user()->name, 'old' => $ticket->department->name, 'new' => TicketDepartment::find($data['department_id'])->name]); } if (isset($data['open'])) { $descriptions[] = trans('tickets::tickets.histories.ticket_closed', ['user' => user()->name]); } if (isset($data['priority']) && !empty($data['priority'])) { $descriptions[] = trans('tickets::tickets.histories.priority_changed', ['user' => user()->name, 'old' => trans('tickets.tickets.priorities.' . $ticket->priority), 'new' => trans('tickets.tickets.priorities.' . $data['priority'])]); } if (!empty($data)) { event(new TicketUpdated($ticket, $descriptions)); if (!$ticket->fill($data)->save()) { return $ticket->errors(); } } } return redirect()->back()->with('success', trans('tickets::tickets.bulk_update_success')); } else { return redirect()->back()->with('warning', trans('tickets::tickets.bulk_update_no_data')); } } }