367 lines
15 KiB
PHP
367 lines
15 KiB
PHP
<?php
|
|
|
|
namespace Modules\Konselor\Http\Controllers;
|
|
|
|
use Illuminate\Contracts\Support\Renderable;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
use DataTables;
|
|
use Modules\Seller\Entities\TicketModel;
|
|
use Modules\Seller\Entities\TicketResponseModel;
|
|
use Modules\Seller\Events\TicketCreated;
|
|
use App\Enums\GlobalEnum;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use App\Models\Siswa;
|
|
use App\Models\User;
|
|
use App\Models\Konselor;
|
|
use App\Models\LogActivites;
|
|
|
|
class TicketController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
if ($request->ajax()) {
|
|
$data = TicketModel::where('konselor_id', user()->id)->orderBy('created_at', 'desc');
|
|
// Convert the Eloquent Collection to a regular PHP array
|
|
$data->each(function ($item, $key) {
|
|
$item->rowIndex = $key + 1;
|
|
});
|
|
|
|
return Datatables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('title-post', function($row){
|
|
$text = '
|
|
<p class="mb-0">' . $row->subject . '</p>
|
|
<p class="mb-0 small">Terakhir diperbarui pada ' . date_formatting($row->updated_at, 'timeago') . '</p>
|
|
';
|
|
return $text;
|
|
})
|
|
->addColumn('siswa', function($row){
|
|
return User::where('id', $row->user_id)->first()->name;
|
|
})
|
|
->addColumn('action', function($row){
|
|
$view = route('ticket.view', ['id' => $row->id]);
|
|
$delete = route('ticket.delete', ['id' => $row->id]);
|
|
$btn = '
|
|
<a href="' . $view . '" class="btn btn-light btn-sm px-4"><i class="ki-outline ki-eye"></i></a>
|
|
<a data-url="' . $delete . '" href="#" class="btn btn-light btn-sm deleteContent px-4"><i class="ki-outline ki-trash"></i></a>
|
|
';
|
|
return $btn;
|
|
})
|
|
->addColumn('status', function($row){
|
|
if ($row->is_status == 1) {
|
|
return '<span class="mb-1 badge font-medium bg-light-dark text-dark">Pending</span>';
|
|
} elseif($row->is_status == 2) {
|
|
return '<span class="mb-1 badge font-medium bg-light-primary text-primary">User Membalas</span>';
|
|
} elseif($row->is_status == 3) {
|
|
return '<span class="mb-1 badge font-medium bg-light-info text-info">Konselor Membalas</span>';
|
|
} elseif($row->is_status == 4) {
|
|
return '<span class="mb-1 badge font-medium bg-light-danger text-danger">Ditutup</span>';
|
|
}
|
|
})
|
|
->addColumn('jenis', function($row){
|
|
if ($row->type == 1) {
|
|
return '<span class="mb-1 badge font-medium bg-light-primary text-primary">Aplikasi</span>';
|
|
} elseif($row->type == 2) {
|
|
return '<span class="mb-1 badge font-medium bg-light-success text-success">Face to Face<br>pada<br>'.$row->meet_at.'</span>';
|
|
}
|
|
})
|
|
->addColumn('approval', function($row){
|
|
if ($row->is_approval_konselor == 3) {
|
|
return '<span class="mb-1 badge font-medium bg-light-dark text-dark">Wali Menunggu Persetujuan</span>';
|
|
} elseif($row->is_approval_konselor == 1) {
|
|
return '<span class="mb-1 badge font-medium bg-light-success text-success">Wali Disetujui</span>';
|
|
} elseif($row->is_approval_konselor == 4) {
|
|
return '<span class="mb-1 badge font-medium bg-light-danger text-danger">Persetujuan Ditolak</span>';
|
|
} else {
|
|
return '<span class="mb-1 badge font-medium bg-light-info text-info">-</span>';
|
|
}
|
|
})
|
|
->addColumn('priority', function($row){
|
|
if ($row->is_priority == GlobalEnum::isTicketPriorityNormal) {
|
|
return '<span class="mb-1 badge font-medium bg-light-info text-info">Normal</span>';
|
|
} elseif($row->is_priority == GlobalEnum::isTicketPriorityMedium) {
|
|
return '<span class="mb-1 badge font-medium bg-light-primary text-primary">Sedang</span>';
|
|
} elseif($row->is_priority == GlobalEnum::isTicketPriorityHigh) {
|
|
return '<span class="mb-1 badge font-medium bg-light-danger text-danger">Parah</span>';
|
|
}
|
|
})
|
|
->rawColumns(['title-post','action','status','priority','siswa','approval', 'jenis'])
|
|
->filter(function ($query) use ($request) {
|
|
if ($request->has('search')) {
|
|
$search = $request->get('search')['value'];
|
|
|
|
$decodedSearch = json_decode($search, true);
|
|
|
|
if (json_last_error() === JSON_ERROR_NONE) {
|
|
$filters = $decodedSearch;
|
|
|
|
if (isset($filters['startDate']) && !empty($filters['startDate'])) {
|
|
$query->whereDate('created_at', '>=', $filters['startDate']);
|
|
}
|
|
|
|
if (isset($filters['endDate']) && !empty($filters['endDate'])) {
|
|
$query->whereDate('created_at', '<=', $filters['endDate']);
|
|
}
|
|
|
|
if (isset($filters['subjek']) && !empty($filters['subjek'])) {
|
|
if ($filters['subjek'] === 'Yang Lain') {
|
|
$query->whereNotIn('subjek', ['Non Akademis', 'Akademis', 'Masuk Universitas', 'Masalah Keluarga']);
|
|
} else {
|
|
$query->where('subjek', 'LIKE', $filters['subjek'] . "%");
|
|
}
|
|
}
|
|
|
|
if (isset($filters['jenis']) && !empty($filters['jenis'])) {
|
|
$query->where('type', '=', $filters['jenis']);
|
|
}
|
|
|
|
if (isset($filters['status']) && !empty($filters['status'])) {
|
|
$query->where('is_status', '=', $filters['status']);
|
|
}
|
|
|
|
if (isset($filters['kasus']) && !empty($filters['kasus'])) {
|
|
$query->where('is_priority', '=', $filters['kasus']);
|
|
}
|
|
} else {
|
|
// $search is a regular string
|
|
$filterCategory = explode('|', $search);
|
|
if ($filterCategory[0] === 'status') {
|
|
if (!empty($filterCategory[1])) {
|
|
$query->where('is_status', 'LIKE', "%$filterCategory[1]%");
|
|
} else {
|
|
$query->get();
|
|
}
|
|
} elseif ($filterCategory[0] === 'user') {
|
|
if (!empty($filterCategory[1])) {
|
|
$query->where('user_id', '=', User::where('name', 'like', "%$filterCategory[1]%")->first()->id);
|
|
} else {
|
|
$query->get();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
->make(true);
|
|
}
|
|
|
|
$data = [
|
|
'subtitle' => 'Riwayat Bimbingan & Konseling',
|
|
'button' => true,
|
|
'module' => [
|
|
'url' => site_url('konselor', 'ticket/create'),
|
|
'name' => 'Jadwal B.K'
|
|
]
|
|
];
|
|
|
|
return view('konselor::ticket.index', compact('data'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$data = [
|
|
'subtitle' => 'Jadwal Bimbingan & Konseling',
|
|
];
|
|
|
|
$getListSiswa = User::where('level', GlobalEnum::isSiswa)->get();
|
|
return view('konselor::ticket.add', compact('data', 'getListSiswa'));
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'siswa_id' => 'required',
|
|
'subject' => 'required',
|
|
'message' => 'required',
|
|
'is_priority' => 'required',
|
|
'type' => 'required'
|
|
]);
|
|
|
|
if($validator->fails()) {
|
|
return redirect()->back()->with('swal', swal_alert('error', $validator->errors()->first()))->withInput();
|
|
}
|
|
|
|
$input = $request->all();
|
|
$ticket = new TicketModel([
|
|
'id' => Str::uuid(),
|
|
'user_id' => $input['siswa_id'],
|
|
'konselor_id' => user()->id,
|
|
'subject' => $input['subject'],
|
|
'is_priority' => $input['is_priority'],
|
|
'senderAs' => 1,
|
|
'type' => $input['type'],
|
|
'is_status' => 1,
|
|
]);
|
|
|
|
if($input['type'] == 1) {
|
|
$check = TicketModel::where('subject', $ticket->subject)->count();
|
|
$messages = "Siswa ingin melakukan bimbingan secara virtual aplikasi";
|
|
$ticketResponse = new TicketResponseModel();
|
|
$ticketResponse->id = Str::uuid();
|
|
$ticketResponse->id_ticket = $ticket->id; // Isi dengan nilai yang sesuai
|
|
$ticketResponse->user_id = $ticket->user_id; // Isi dengan nilai yang sesuai
|
|
$ticketResponse->message = clean($messages);
|
|
$ticketResponse->save();
|
|
}
|
|
|
|
$postTicket = $ticket->save();
|
|
if($check == 0) {
|
|
if($postTicket) {
|
|
return redirect()->to(site_url('konselor', 'ticket'))->with('swal', swal_alert('success', 'Anda berhasil membuka tiket baru.'));
|
|
} else {
|
|
return redirect()->back()->with('swal', swal_alert('error', 'Terjadi kesalahan saat membuka tiket.'));
|
|
}
|
|
} else {
|
|
return redirect()->back()->with('swal', swal_alert('error', 'Ditemukan data yang telah ada'));
|
|
}
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'message' => 'required',
|
|
]);
|
|
|
|
if($validator->fails()) {
|
|
return redirect()->back()->with('swal', swal_alert('error', $validator->errors()->first()))->withInput();
|
|
}
|
|
|
|
$input = $request->all();
|
|
$ticket = TicketModel::find($id);
|
|
if($ticket) {
|
|
$post = new TicketResponseModel([
|
|
'id' => Str::uuid(),
|
|
'id_ticket' => $id,
|
|
'user_id' => auth()->user()->id,
|
|
'message' => $input['message']
|
|
]);
|
|
|
|
$ticket->is_status = 3;
|
|
if($post->save() && $ticket->save()) {
|
|
return redirect()->route('konselor.ticket.detail', ['id' => $id])->with('swal', swal_alert('success', 'Anda berhasil membalas tiket.'));
|
|
} else {
|
|
return redirect()->route('konselor.ticket.detail', ['id' => $id])->with('swal', swal_alert('error', 'Terjadi kesalahan saat membalas tiket.'));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function view($id)
|
|
{
|
|
$data = [
|
|
'subtitle' => TicketModel::where('id', $id)->first()->subject
|
|
];
|
|
|
|
$detail = TicketModel::where('id', $id)->first();
|
|
$siswa = User::where('id', $detail->user_id)->first()->name;
|
|
$nis = Siswa::where('user_id', $detail->user_id)->first()->nis;
|
|
$ticketResponse = TicketResponseModel::where('id_ticket', $id)->orderBy('created_at', 'asc')->get();
|
|
return view('konselor::ticket.detail', compact('data', 'nis', 'ticketResponse', 'detail', 'siswa'));
|
|
}
|
|
|
|
public function delete($id)
|
|
{
|
|
$ticket = TicketModel::find($id);
|
|
if($ticket) {
|
|
$detailReply = TicketResponseModel::where('id_ticket', $ticket->id)->get();
|
|
|
|
if($ticket->delete() && $detailReply->delete()) {
|
|
return redirect()->route('konselor.ticket')->with('swal', swal_alert('success', 'Anda berhasil menghapus tiket.'));
|
|
} else {
|
|
return redirect()->route('konselor.ticket')->with('swal', swal_alert('error', 'Terjadi kesalahan saat menghapus tiket.'));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function closed($id)
|
|
{
|
|
$ticket = TicketModel::find($id);
|
|
if($ticket) {
|
|
$ticket->is_status = 4;
|
|
if($ticket->save()) {
|
|
return redirect()->route('konselor.ticket')->with('swal', swal_alert('success', 'Anda berhasil menghapus tiket.'));
|
|
} else {
|
|
return redirect()->route('konselor.ticket')->with('swal', swal_alert('error', 'Terjadi kesalahan saat menghapus tiket.'));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function accept()
|
|
{
|
|
$chat = TicketModel::find(segment(4));
|
|
if($chat)
|
|
{
|
|
$chat->is_approval_konselor = 1;
|
|
$chat->save();
|
|
|
|
return redirect()->back()->with('swal', swal_alert('success', 'Request berhasil disetujui.'));
|
|
} else {
|
|
return redirect()->back()->with('swal', swal_alert('error', 'Tidak ditemukan data yang dituju.'));
|
|
}
|
|
}
|
|
|
|
public function decline()
|
|
{
|
|
$chat = TicketModel::find(segment(4));
|
|
if($chat)
|
|
{
|
|
$chat->is_approval_konselor = 4;
|
|
$chat->save();
|
|
|
|
return redirect()->back()->with('swal', swal_alert('success', 'Request berhasil ditolak.'));
|
|
} else {
|
|
return redirect()->back()->with('swal', swal_alert('error', 'Tidak ditemukan data yang dituju.'));
|
|
}
|
|
}
|
|
|
|
public function cetak(Request $request)
|
|
{
|
|
$startDate = $request->input('start_date', '');
|
|
$endDate = $request->input('end_date', '');
|
|
$subjek = $request->input('subjek', '');
|
|
$jenis = $request->input('jenis', '');
|
|
$status = $request->input('status', '');
|
|
$kasus = $request->input('kasus', '');
|
|
|
|
|
|
$query = TicketModel::query();
|
|
|
|
if (!empty($startDate)) {
|
|
$query->whereDate('created_at', '>=', $startDate);
|
|
}
|
|
|
|
if (!empty($endDate)) {
|
|
$query->whereDate('created_at', '<=', $endDate);
|
|
}
|
|
|
|
if ($subjek === 'Yang Lain') {
|
|
$query->whereNotIn('subjek', ['Non Akademis', 'Akademis', 'Masuk Universitas', 'Masalah Keluarga']);
|
|
} elseif (!empty($subjek)) {
|
|
$query->where('subjek', 'LIKE', $subjek . "%");
|
|
}
|
|
|
|
if (!empty($jenis)) {
|
|
$query->where('type', '=', $jenis);
|
|
}
|
|
|
|
if (!empty($status)) {
|
|
$query->where('is_status', '=', $status);
|
|
}
|
|
|
|
if (!empty($kasus)) {
|
|
$query->where('is_priority', '=', $kasus);
|
|
}
|
|
|
|
$report = $query->get();
|
|
|
|
$periode = $startDate . ' s/d ' . $endDate;
|
|
|
|
return view('konselor::ticket.cetak', compact('report', 'periode'));
|
|
}
|
|
}
|