145 lines
6.1 KiB
PHP
145 lines
6.1 KiB
PHP
<?php
|
|
namespace App\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 App\Models\Siswa;
|
|
use App\Models\User;
|
|
use App\Models\Konselor;
|
|
use App\Models\LogActivites;
|
|
|
|
class ReportController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
if ($request->ajax()) {
|
|
$data = TicketModel::select('*');
|
|
// 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">Admin Membalas</span>';
|
|
} elseif($row->is_status == 3) {
|
|
return '<span class="mb-1 badge font-medium bg-light-info text-info">User Membalas</span>';
|
|
} elseif($row->is_status == 4) {
|
|
return '<span class="mb-1 badge font-medium bg-light-danger text-danger">Ditutup</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'])
|
|
->filter(function ($query) use ($request) {
|
|
if ($request->has('search')) {
|
|
$search = $request->get('search')['value'];
|
|
|
|
$filterCategory = explode('|', $search);
|
|
if($filterCategory[0] === 'status') {
|
|
if(!empty($filterCategory[1])) {
|
|
$query->where('is_status', '=', $filterCategory[1]);
|
|
} else {
|
|
$query->get();
|
|
}
|
|
} elseif($filterCategory[0] === 'user') {
|
|
if(!empty($filterCategory[1])) {
|
|
$query->where('name', 'LIKE', "%$filterCategory[1]%");
|
|
} else {
|
|
$query->get();
|
|
}
|
|
}
|
|
}
|
|
})
|
|
->make(true);
|
|
}
|
|
|
|
$data = [
|
|
'subtitle' => 'Riwayat Bimbingan & Konseling',
|
|
];
|
|
|
|
return view('admin.app.ticket.index', compact('data'));
|
|
}
|
|
|
|
public function view($id)
|
|
{
|
|
$data = [
|
|
'subtitle' => 'Bimbingan & Konseling #' . explode('-', $id)[0],
|
|
];
|
|
|
|
$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 = TicketModel::find($id)->responses;
|
|
return view('admin.app.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()->back()->with('swal', swal_alert('success', 'Anda berhasil menghapus tiket.'));
|
|
} else {
|
|
return redirect()->back()->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()->back()->with('swal', swal_alert('success', 'Anda berhasil menghapus tiket.'));
|
|
} else {
|
|
return redirect()->back()->with('swal', swal_alert('error', 'Terjadi kesalahan saat menghapus tiket.'));
|
|
}
|
|
}
|
|
}
|
|
}
|