Files
2026-12-01 11:03:39 +07:00

1865 lines
86 KiB
PHP

@extends('layouts.main')
@section('breadcrumb')
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="javascript:void(0);">Verifikasi</a></li>
<li class="breadcrumb-item"><a href="javascript:void(0);">Laporan Kegiatan</a></li>
<li class="breadcrumb-item"><a href="javascript:void(0);">Pengajuan</a></li>
<li class="breadcrumb-item active" aria-current="page">{{ $title }}</li>
</ol>
@endsection
@section('content')
<div class="row">
<div class="col-sm-12">
<ul class="nav nav-pills bg-nav-pills nav-justified mb-2">
@foreach ($kegiatans as $index => $nav_kat)
<li class="nav-item">
<a href="#nav-{{ $loop->iteration }}" data-bs-toggle="tab"
aria-expanded="{{ $loop->iteration === 1 ? 'true' : 'false' }}"
class="nav-link rounded-0 {{ $loop->iteration === 1 ? 'active' : '' }}">
<i class="mdi mdi-home-variant d-md-none d-block"></i>
<span class="d-none d-md-block">{{ $nav_kat['nama'] }}</span>
</a>
</li>
@endforeach
</ul>
</div>
</div>
<div class="tab-content">
@foreach ($kegiatans as $key => $kegiatan)
<div class="tab-pane {{ $loop->iteration === 1 ? 'active' : '' }}" id="nav-{{ $loop->iteration }}">
<div class="card border">
<div class="card-body">
<div class="table-responsive">
<table class="table table-sm">
<!-- Nama Kegiatan -->
<tr>
<th>Nama Kegiatan</th>
<td>
<textarea class="form-control" name="nama_kegiatan" id="nama_kegiatan_{{ $key }}" cols="30" rows="3"
readonly>{{ $data->nama_kegiatan ?? ($kegiatan['nama_kegiatan'] ?? '') }}</textarea>
</td>
</tr>
<!-- Tanggal -->
<tr>
<th>Tanggal</th>
<td>{{ isset($data->tanggal_kegiatan) ? \Carbon\Carbon::parse($data->tanggal_kegiatan)->format('d/m/Y') : ($kegiatan['tanggal_kegiatan'] ? \Carbon\Carbon::parse($kegiatan['tanggal_kegiatan'])->format('d/m/Y') : '-') }}
</td>
</tr>
<!-- Kategori -->
<tr>
<th>Kategori</th>
<td>{{ $kegiatan['nama'] }}</td>
</tr>
<!-- Aksi Button -->
<tr>
<th></th>
<td>
@if ($kegiatan['nama'] != 'Kegiatan Kepanitiaan Adhoc')
<button class="btn btn-sm btn-outline-danger jangka-waktu-multiple-btn"
data-kegiatan="{{ $key }}">
<i class="uil-edit"></i>
<span>Ubah Jangka Waktu <span
class="count">{{ isset($kegiatan['anggota']) ? count($kegiatan['anggota']) : 0 }}</span>
Anggota</span>
</button>
@else
<span class="text-danger">Rubrik ini tidak perlu diubah jangka waktunya</span>
@endif
</td>
</tr>
<!-- File Data -->
<tr>
<th>File</th>
<td>
@if (isset($unit) && isset($data->nama_sk) && $data->nama_sk)
<button type="button" class="btn btn-sm btn-outline-secondary"
data-bs-toggle="modal" data-bs-target="#previewSk"
data-links="{{ $data->nama_sk }}">
<i class="uil-eye"></i> SK
</button>
@endif
@if (isset($kegiatan['anggota']) && $kegiatan['anggota']->isNotEmpty())
@php
$laporanKegiatan = $kegiatan['anggota']
->first()
->dokumens->where('kategori_dokumen', 'Laporan Kegiatan')
->first();
@endphp
@if ($laporanKegiatan)
<button type="button" class="btn btn-sm btn-outline-secondary"
data-bs-toggle="modal" data-bs-target="#previewLaporan"
data-links="https://dokumen.siremun.untan.ac.id/storage/dokumen/periode{{ \App\Models\Verifikator\Periode::where('status', true)->first()->id_periode }}/Laporan%20Kegiatan/{{ $laporanKegiatan->nama_file }}">
<i class="uil-eye"></i> Laporan Kegiatan
</button>
@endif
@endif
</td>
</tr>
<!-- Status -->
@if (isset($kegiatan['anggota']) && $kegiatan['anggota']->isNotEmpty())
@php
$firstAnggota = $kegiatan['anggota']->first();
$hasLaporanSyarat =
isset($firstAnggota->rubrik->syarats) &&
$firstAnggota->rubrik->syarats
->whereIn('nama', ['laporan kegiatan'])
->count() > 0;
@endphp
@if ($hasLaporanSyarat)
<tr>
<th>Status</th>
<td>
@php
$avgStatus = $kegiatan['anggota']->avg('status_verifikasi_id');
@endphp
@if (in_array($avgStatus, [6, 7]))
<span class="badge bg-success f-12">
{{ $firstAnggota->statusVerifikasi->name }}
</span>
@elseif(in_array($avgStatus, [3, 4]))
<span class="badge bg-warning f-12">
{{ $firstAnggota->statusVerifikasi->name }}
</span>
@elseif(in_array($avgStatus, [1, 2, 5, 8]))
<span class="badge bg-danger f-12">
{{ $firstAnggota->statusVerifikasi->name }}
</span>
@endif
</td>
</tr>
@endif
@endif
</table>
</div>
</div>
</div>
<div class="card border">
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered table-striped w-100" id="table-{{ $loop->iteration }}">
<thead class="bg-light-dark">
<tr>
<th>
<div class="d-flex justify-content-center">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="checkAll">
</div>
</div>
</th>
<th>No</th>
<th>Pegawai</th>
<th>Posisi</th>
<th>Jabatan Tugas Tambahan</th>
<th>Jangka Waktu</th>
<th>Status</th>
<th>Jumlah</th>
<th>Poin</th>
<th>Aksi</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
@if (in_array($kegiatan['anggota']->average('status_verifikasi_id'), [1, 2, 3, 4, 5, 6]))
@if ($kegiatan['anggota']->first()->rubrik->syarats->where('nama', 'laporan kegiatan')->count() > 0)
<div class="card border">
<div class="card-body">
{{-- Jika status adalah Belum Diajukan (status_verifikasi_id = 1) --}}
@if ($kegiatan['anggota']->average('status_verifikasi_id') == 1)
<div class="d-flex justify-content-center">
<span class="text-danger">Tidak Dapat Melakukan Verifikasi, Silahkan Upload Laporan
Kegiatan Terlebih Dahulu</span>
</div>
@else
<div class="d-flex justify-content-center gap-2">
{{-- Tombol Terima hanya muncul jika status_verifikasi_id adalah 3 --}}
@if ($kegiatan['anggota']->average('status_verifikasi_id') == 3)
<button type="button" class="btn btn-success text-white"
id="konfirmasiTerimaLaporan" data-id="{{ $kegiatan['anggota']->first()->id }}">
<i class="uil-file-bookmark-alt"></i> Terima
</button>
@endif
{{-- Tombol Tolak muncul jika status bukan 6 atau 7 (sudah disetujui/selesai) --}}
@if (!in_array($kegiatan['anggota']->average('status_verifikasi_id'), [2, 5, 6, 7, 8]))
<button type="button" class="btn btn-danger text-white" id="btnTolakLaporan"
data-id="{{ $kegiatan['anggota']->first()->id }}">
<i class="uil-file-bookmark-alt"></i> Tolak
</button>
@endif
{{-- Tombol Batalkan untuk user yang punya permission dan status selain 6 dan 7 --}}
@can('Batalkan Pengajuan Penunjang')
@if (in_array($kegiatan['anggota']->average('status_verifikasi_id'), [2, 5, 6, 8]))
<button type="button" class="btn btn-warning text-dark batal"
id="konfirmasiBatalLaporan" data-id="{{ $kegiatan['anggota']->first()->id }}">
<i class="fa fa-times-circle"></i> Batalkan
</button>
@endif
@endcan
</div>
@endif
</div>
</div>
@endif
@endif
</div>
@endforeach
</div>
@endsection
@section('modal')
<!-- Ubah Jumlah Satuan -->
<div class="modal fade" id="modalEditJumlahSatuan" tabindex="-1" data-bs-backdrop="static" data-bs-keyboard="false"
aria-labelledby="jmlSatuanModalLabel" aria-hidden="true" role="dialog">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-sm" role="document">
<div class="modal-content">
<div class="modal-header bg-primary text-white">
<h5 class="modal-title" id="jmlSatuanModalLabel">Edit Jumlah Satuan</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form id="formEditJmlSatuan">
<input type="hidden" id="syarat_id" name="syarat_id">
<div class="row">
<div class="col-sm-12">
<label id="jumlah_satuan_label" for="jumlah_satuan" class="form-label">Jumlah
Satuan</label>
<input type="number" id="jumlah_satuan" name="jumlah" class="form-control"
min="1" required>
<div class="invalid-feedback" id="jumlah_satuan_error"></div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" id="simpanJumlahSatuan" form="formEditJmlSatuan">
Simpan
</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
</div>
</div>
</div>
</div>
<!-- Preview SK -->
<div class="modal fade" id="previewSk" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-body p-0">
<iframe id="skViewer" src="" style="width: 100%; height: 580px; border: none;"></iframe>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
</div>
</div>
</div>
</div>
<!-- Preview Laporan Kegiatan -->
<div class="modal fade" id="previewLaporan" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-body p-0">
<iframe id="laporanViewer" style="width: 100%; height: 580px; border: none;"></iframe>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
</div>
</div>
</div>
</div>
<!-- Edit Jangka Waktu -->
<div class="modal fade" id="modalEditJangkaWaktu" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
aria-labelledby="modalEditJangkaWaktuLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-primary text-white">
<h5 class="modal-title" id="modalEditJangkaWaktuLabel">Edit Jangka Waktu Anggota</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form id="formEditJangkaWaktu">
<div class="mb-2">
<label for="jumlahBulan" class="form-label">Jumlah Bulan <span
class="text-danger">*</span></label>
<input type="number" class="form-control" id="jumlahBulan" name="jumlah_bulan"
min="1" max="6" placeholder="Masukkan Jangka Waktu" required>
<div class="form-text"><i>Maksimal 6 bulan</i></div>
</div>
<div class="mb-2">
<label for="keterangan" class="form-label">Keterangan <span
class="text-danger">*</span></label>
<textarea class="form-control" id="keterangan" name="keterangan" rows="3" placeholder="Masukkan Keterangan"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="simpanJangkaWaktu">
<span class="btn-text">Simpan</span>
</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
</div>
</div>
</div>
</div>
<!-- Detail Laporan -->
<div class="modal fade" id="detailLaporan" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
aria-labelledby="detailLaporanLabel" aria-hidden="true" role="dialog">
<div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header bg-primary text-white">
<h5 class="modal-title" id="detailLaporanLabel">Detail Laporan</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form id="formDetailLaporan">
<input type="hidden" id="id_syarats" name="id_syarats">
<input type="hidden" id="id_kegiatans" name="id_kegiatans">
<ul class="nav nav-pills bg-nav-pills nav-justified mb-3">
<li class="nav-item">
<a href="#umum" data-bs-toggle="tab" aria-expanded="true"
class="nav-link rounded-0 active">
<i class="mdi mdi-home-variant d-md-none d-block"></i>
<span class="d-none d-md-block">Umum</span>
</a>
</li>
<li class="nav-item">
<a href="#fileSyarat" data-bs-toggle="tab" aria-expanded="false"
class="nav-link rounded-0">
<i class="mdi mdi-account-circle d-md-none d-block"></i>
<span class="d-none d-md-block">File Syarat</span>
</a>
</li>
<li class="nav-item">
<a href="#catatanRiwayat" data-bs-toggle="tab" aria-expanded="false"
class="nav-link rounded-0">
<i class="mdi mdi-settings-outline d-md-none d-block"></i>
<span class="d-none d-md-block">Catatan Riwayat</span>
</a>
</li>
</ul>
<div class="tab-content">
<!-- Umum -->
<div class="tab-pane show active" id="umum">
<div>
<div class="media mb-4">
<div class="media-body d-flex">
<div class="d-flex flex-column">
<img src="{{ asset('assets/images/book.png') }} " width="80px"
alt="">
</div>
<div class="d-flex flex-column ms-2">
<div class="d-flex flex-row align-items-center">
<div id="displayStatusContainer"></div>
<i class="uil-stopwatch text-secondary mx-1"></i> <span
class="pull-right text-secondary" id="displayTanggal">...</span>
</div>
<span class="f-w-600" id="displayNamaKegiatan">...</span>
<span id="displayNamaDosen" class="fw-bold"
style="font-size:16px">...</span>
</div>
</div>
</div>
<div class="table-responsive">
<table class="table table-sm">
<tr>
<th>Uraian</th>
<th style="text-align: right"><span class="text-primary"
id="displayUraian">...</span></th>
</tr>
<tr>
<th>Kategori</th>
<th style="text-align: right"><span class="text-primary"
id="displayKategori">...</span></th>
</tr>
<tr>
<th>Poin</th>
<th style="text-align: right"><span class="text-primary"
id="displayPoin">...</span></th>
</tr>
</table>
</div>
</div>
</div>
<!-- File Syarat -->
<div class="tab-pane" id="fileSyarat">
<div id="dokumenContainer"></div>
</div>
<!-- Catatan Riwayat -->
<div class="tab-pane" id="catatanRiwayat">
<div class="row">
<div class="col-sm-12">
<div class="card border">
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered table-sm table-striped w-100"
id="catatan-verifikasi">
<thead>
<tr>
<th>No.</th>
<th>Verifikator</th>
<th>Catatan</th>
<th>Waktu</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="card border">
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered table-sm table-striped w-100"
id="riwayat-verifikasi">
<thead>
<tr>
<th>No.</th>
<th>Nama</th>
<th>Aktivitas Log</th>
<th>Waktu</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<label class="mb-1" for="sanggahanVerifikasi">Sanggahan dari Pegawai</label>
<textarea class="form-control" name="sanggahanVerifikasi" id="sanggahanVerifikasi" rows="5" disabled></textarea>
</div>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" id="konfirmasiTerimaDetailLaporan">Terima</button>
<button type="button" class="btn btn-danger" id="btnTolakDetailLaporan">Tolak</button>
<button type="button" class="btn btn-warning" id="konfirmasiBatalDetailLaporan">Batalkan</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
</div>
</div>
</div>
</div>
<!-- Modal Tolak Detail Laporan -->
<div class="modal fade" id="modalTolakDetailLaporan" data-bs-backdrop="static" data-bs-keyboard="false"
tabindex="-1" aria-labelledby="modalTolakDetailLaporanLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-danger text-white">
<h5 class="modal-title" id="modalTolakDetailLaporanLabel">Keterangan Penolakan Detail</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form id="formTolakDetailLaporan">
<div class="mb-3">
<label for="keteranganTolakDetail" class="form-label">Alasan Penolakan <span
class="text-danger">*</span></label>
<textarea class="form-control" id="keteranganTolakDetail" name="keterangan_tolak_detail" rows="4"
placeholder="Masukkan alasan penolakan..." required></textarea>
<div class="form-text">Jelaskan alasan mengapa pengajuan ini ditolak</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" id="konfirmasiTolakDetailLaporan">
<i class="uil-times-circle"></i> Tolak Pengajuan
</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
</div>
</div>
</div>
</div>
<!-- Modal Tolak Laporan (Outside Modal) -->
<div class="modal fade" id="modalTolakLaporan" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
aria-labelledby="modalTolakLaporanLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-danger text-white">
<h5 class="modal-title" id="modalTolakLaporanLabel">Keterangan Penolakan Laporan</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form id="formTolakLaporan">
<div class="mb-3">
<label for="keteranganTolakLaporan" class="form-label">Alasan Penolakan <span
class="text-danger">*</span></label>
<textarea class="form-control" id="keteranganTolakLaporan" name="keterangan_tolak_laporan" rows="4"
placeholder="Masukkan alasan penolakan..." required></textarea>
<div class="form-text">Jelaskan alasan mengapa pengajuan ini ditolak</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" id="konfirmasiTolakLaporan">
<i class="uil-times-circle"></i> Tolak Pengajuan
</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
</div>
</div>
</div>
</div>
@endsection
@section('js')
<!-- Sidebar Aktif -->
<script>
$('.si-laporan-kegiatan').addClass('menuitem-active');
$('.ni-laporan-kegiatan').addClass('badge-primary-lighten');
$('.li-laporan-kegiatan').addClass('show');
$('.li-laporan-kegiatan-prestasi').addClass('active badge-primary-lighten');
</script>
<!-- Alert Handler untuk Belum Diajukan -->
<script>
$(document).on('click', '.detail-laporan-disabled', function(e) {
e.preventDefault();
showError('Gagal',
'Tidak Dapat Melakukan Verifikasi, Silahkan Upload Laporan Kegiatan Terlebih Dahulu');
});
</script>
<!-- Tabel Anggota -->
<script>
$(document).ready(function() {
var kegiatanId = {{ $data['id'] }};
var kegiatanConfig = @json($kegiatans);
var tables = {};
const editJumlahRubrikIds = @json(config('editJumlah.rubrik_id'));
kegiatanConfig.forEach(function(kegiatan, index) {
var tableId = 'table-' + (index + 1);
// Cek apakah kegiatan ini memiliki status "Belum Diajukan"
var avgStatus = 0;
if (kegiatan.anggota && kegiatan.anggota.length > 0) {
var totalStatus = 0;
kegiatan.anggota.forEach(function(anggota) {
totalStatus += anggota.status_verifikasi_id || 0;
});
avgStatus = totalStatus / kegiatan.anggota.length;
}
var isBelumDiajukan = avgStatus === 1;
var table = $('#' + tableId).DataTable({
processing: true,
serverSide: true,
ajax: {
url: "{{ route('laporan-kegiatan.prestasi.data-detail', ':id') }}"
.replace(':id', kegiatanId),
data: function(d) {
d.kategori = kegiatan.nama;
}
},
columns: [{
data: 'checkbox',
name: 'checkbox',
className: 'text-center',
orderable: false,
searchable: false,
},
{
data: 'DT_RowIndex',
orderable: false,
searchable: false,
className: 'text-center'
},
{
data: 'info_pegawai',
name: 'pencarian_pegawai',
className: 'align-middle',
width: '26.5%',
orderable: true,
searchable: true,
},
{
data: 'posisi',
name: 'posisi',
orderable: true,
searchable: false,
className: 'text-center'
},
{
data: 'jabatan',
name: 'jabatan',
orderable: false,
searchable: false,
},
{
data: 'jangka_waktu_per_semester',
name: 'jangka_waktu_per_semester',
className: 'text-center',
orderable: false,
searchable: false,
},
{
data: 'status_verifikasi_id',
name: 'status_verifikasi_id',
className: 'text-center',
},
{
data: 'jumlah_satuan',
name: 'jumlah_satuan',
className: 'text-center',
},
{
data: 'poin_total',
name: 'poin_total',
className: 'text-center',
},
{
data: 'aksi',
name: 'aksi',
className: 'text-center',
orderable: false,
searchable: false,
createdCell: function(td, cellData, rowData, row, col) {
// Jika tab ini adalah "Belum Diajukan", ubah semua tombol menjadi merah
if (isBelumDiajukan) {
$(td).html(
'<button class="btn btn-sm btn-danger detail-laporan-disabled"><i class="fa fa-eye"></i> Detail</button>'
);
}
}
}
],
language: {
processing: "<div class='spinner'></div>&nbsp; Sedang Memuat...",
},
drawCallback: function() {
const firstData = kegiatan.anggota[0];
const isInEditJumlah = editJumlahRubrikIds.includes(firstData
.id_rubrik);
const laporanSyaratCount = firstData.rubrik.syarats.filter(s => s
.nama === 'laporan kegiatan').length;
if (!firstData.posisi) {
table.column(3).visible(false);
}
if (!isInEditJumlah) {
table.column(7).visible(false);
}
if (laporanSyaratCount > 0) {
table.column(6).visible(false);
table.column(9).visible(false);
}
}
});
tables[tableId] = table;
});
});
</script>
<!-- Select Checkbox -->
<script>
function getSelectedCheckboxes() {
var selectedIds = [];
$('table[id^="table-"]:visible tbody input[type="checkbox"]:checked').each(function() {
var id = $(this).val() || $(this).data('id');
if (id && id !== 'on') {
selectedIds.push(id);
}
});
return selectedIds;
}
function updateButtonCount() {
var count = getSelectedCheckboxes().length;
$('.jangka-waktu-multiple-btn .count').text(count);
if (count > 0) {
$('.jangka-waktu-multiple-btn').removeClass('btn-outline-danger').addClass('btn-outline-primary');
} else {
$('.jangka-waktu-multiple-btn').removeClass('btn-outline-primary').addClass('btn-outline-danger');
}
}
$(document).on('change', 'table tbody input[type="checkbox"]', function() {
updateButtonCount();
var $table = $(this).closest('table');
var total = $table.find('tbody input[type="checkbox"]').length;
var checked = $table.find('tbody input[type="checkbox"]:checked').length;
var $checkAll = $table.find('thead #checkAll');
if (checked === 0) {
$checkAll.prop('checked', false).prop('indeterminate', false);
} else if (checked === total) {
$checkAll.prop('checked', true).prop('indeterminate', false);
} else {
$checkAll.prop('indeterminate', true);
}
});
$(document).on('change', '#checkAll', function() {
var isChecked = $(this).prop('checked');
var $table = $(this).closest('table');
$table.find('tbody input[type="checkbox"]').prop('checked', isChecked);
updateButtonCount();
});
$(document).on('shown.bs.tab', 'a[data-bs-toggle="tab"]', function() {
setTimeout(updateButtonCount, 100);
});
$(document).ready(function() {
setTimeout(updateButtonCount, 1000);
});
</script>
<!-- Edit Jumlah Satuan -->
<script>
$(document).on('click', '.jml-satuan', function() {
const syaratId = $(this).data('syarat-id');
const jumlahSatuan = $(this).data('jml-satuan');
const satuan = $(this).data('satuan');
if (!syaratId) {
showError('Error', 'ID syarat tidak ditemukan');
return;
}
// Set data ke modal
$('#syarat_id').val(syaratId);
$('#jumlah_satuan').val(jumlahSatuan);
$('#jmlSatuanModalLabel').text('Edit Jumlah ' + (satuan || 'Satuan'));
$('#jumlah_satuan_label').text('Jumlah ' + (satuan || 'Satuan'));
// Reset form validation
$('#jumlah_satuan').removeClass('is-invalid');
$('#jumlah_satuan_error').text('');
// Tampilkan modal
$('#modalEditJumlahSatuan').modal('show');
});
$(document).on('click', '#simpanJumlahSatuan', function(e) {
e.preventDefault();
const button = $(this);
const originalText = button.html();
const modal = $('#modalEditJumlahSatuan');
// Ambil data dari form
const syaratId = $('#syarat_id').val();
const jumlahSatuan = $('#jumlah_satuan').val();
// Validasi input
if (!syaratId) {
showError('Error', 'ID syarat tidak ditemukan');
return;
}
if (!jumlahSatuan || jumlahSatuan < 1) {
$('#jumlah_satuan').addClass('is-invalid');
$('#jumlah_satuan_error').text('Jumlah satuan harus diisi dan minimal 1');
return;
}
// Reset validasi
$('#jumlah_satuan').removeClass('is-invalid');
$('#jumlah_satuan_error').text('');
// Disable button dan tampilkan loading
button.prop('disabled', true).html(
'<span class="spinner-border spinner-border-sm me-2"></span>Memproses...');
// AJAX request
$.ajax({
url: "{{ route('laporan-kegiatan.prestasi.edit-jumlah-satuan', ':id') }}".replace(':id',
syaratId),
type: 'POST',
data: {
_token: $('meta[name="csrf-token"]').attr('content'),
jumlah: jumlahSatuan
},
success: function(response) {
if (response.success) {
modal.modal('hide');
showSuccess('Berhasil', response.message || 'Jumlah satuan berhasil diubah');
// Reload halaman setelah delay
setTimeout(function() {
location.reload();
}, 1500);
} else {
showError('Error', response.message || 'Terjadi kesalahan');
}
},
error: function(xhr, status, error) {
let errorMessage = 'Terjadi kesalahan saat memperbarui jumlah satuan';
// Handle berbagai jenis error
if (xhr.responseJSON) {
if (xhr.responseJSON.message) {
errorMessage = xhr.responseJSON.message;
} else if (xhr.responseJSON.errors) {
const errors = xhr.responseJSON.errors;
errorMessage = Object.values(errors).flat().join('<br>');
}
} else {
switch (xhr.status) {
case 404:
errorMessage = 'Data tidak ditemukan';
break;
case 422:
errorMessage = 'Data yang dikirim tidak valid';
break;
case 500:
errorMessage = 'Terjadi kesalahan pada server';
break;
case 0:
errorMessage = 'Tidak dapat terhubung ke server';
break;
}
}
showError('Error', errorMessage);
},
complete: function() {
// Restore button state
button.prop('disabled', false).html(originalText);
}
});
});
$('#formEditJmlSatuan').on('submit', function(e) {
e.preventDefault();
$('#simpanJumlahSatuan').click();
});
$('#modalEditJumlahSatuan').on('hidden.bs.modal', function() {
$('#formEditJmlSatuan')[0].reset();
$('#jumlah_satuan').removeClass('is-invalid');
$('#jumlah_satuan_error').text('');
});
</script>
<!-- Preview SK -->
<script>
$(document).ready(function() {
$('#previewSk').on('show.bs.modal', function(event) {
var button = $(event.relatedTarget);
var documentUrl = button.data('links');
var googleViewerUrl = documentUrl;
$('#skViewer').attr('src', googleViewerUrl);
});
$('#previewSk').on('hidden.bs.modal', function() {
$('#skViewer').attr('src', '');
});
});
</script>
<!-- Preview Laporan Kegiatan -->
<script>
$(document).ready(function() {
$('#previewLaporan').on('show.bs.modal', function(event) {
var button = $(event.relatedTarget);
var documentUrl = button.data('links');
var googleViewerUrl = documentUrl;
$('#laporanViewer').attr('src', googleViewerUrl);
});
$('#previewLaporan').on('hidden.bs.modal', function() {
$('#laporanViewer').attr('src', '');
});
});
</script>
<!-- Edit Jangka Waktu -->
<script>
$(document).on('click', '.jangka-waktu-multiple-btn', function() {
var selectedIds = getSelectedCheckboxes();
if (selectedIds.length === 0) {
showInfo('Peringatan', 'Pilih minimal satu anggota untuk mengubah jangka waktu');
return;
}
$('#modalEditJangkaWaktu').data('selectedIds', selectedIds);
$('#modalEditJangkaWaktu').data('type', 'multiple');
$('#formEditJangkaWaktu')[0].reset();
$('#modalEditJangkaWaktu').modal('show');
});
$('#simpanJangkaWaktu').on('click', function() {
const button = $(this);
const originalText = button.html();
const modal = $('#modalEditJangkaWaktu');
const selectedIds = modal.data('selectedIds');
const type = modal.data('type') || 'multiple';
const jumlahBulan = $('#jumlahBulan').val();
const keterangan = $('#keterangan').val() || '';
const id = {{ $data->id }};
if (!selectedIds || selectedIds.length === 0) {
showInfo('Info!', 'Tidak ada anggota yang dipilih');
return;
}
if (!jumlahBulan || jumlahBulan < 1 || jumlahBulan > 6) {
showInfo('Info!', 'Jumlah bulan harus diisi antara 1-6');
return;
}
if (!keterangan) {
showInfo('Info!', 'Keterangan wajib diisi!');
return;
}
button.prop('disabled', true).html(
'<span class="spinner-border spinner-border-sm"></span> Memproses...'
);
$.ajax({
url: "{{ route('laporan-kegiatan.prestasi.edit-jangka-waktu', ':id') }}".replace(':id',
id),
type: 'POST',
data: {
_token: '{{ csrf_token() }}',
type: type,
ids: selectedIds,
jangka_waktu: jumlahBulan,
alasan: keterangan
},
success: function(response) {
modal.modal('hide');
if (response.success) {
showSuccess('Success', response.message);
setTimeout(function() {
location.reload();
}, 1500);
} else {
showError('Error', response.message);
}
},
error: function(xhr, status, error) {
let errorMessage = 'Terjadi kesalahan saat memperbarui jangka waktu';
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMessage = xhr.responseJSON.message;
} else if (xhr.responseJSON && xhr.responseJSON.errors) {
const errors = xhr.responseJSON.errors;
errorMessage = Object.values(errors).flat().join('<br>');
} else if (xhr.status === 404) {
errorMessage = 'Data tidak ditemukan';
} else if (xhr.status === 422) {
errorMessage = 'Data yang dikirim tidak valid';
} else if (xhr.status === 500) {
errorMessage = 'Terjadi kesalahan pada server';
}
showError('Error', errorMessage);
},
complete: function() {
button.prop('disabled', false).html(originalText);
}
});
});
$('#modalEditJangkaWaktu').on('hidden.bs.modal', function() {
$(this).removeData('selectedIds');
$(this).removeData('type');
$('#formEditJangkaWaktu')[0].reset();
});
</script>
<!-- Detail Laporan -->
<script>
$(document).on('click', '.detail-laporan', function(e) {
e.preventDefault();
var id_syarats = $(this).data('id-syarat');
var id_kegiatan = $(this).data('id-kegiatan');
var laporanKegiatan = $(this).data('laporan-kegiatan');
var laporanSk = $(this).data('laporan-sk');
var displayStatus = $(this).data('d-status');
var displayTanggal = $(this).data('d-tanggal');
var displayNamaKegiatan = $(this).data('d-nama-kegiatan');
var displayNamaDosen = $(this).data('d-nama-dosen');
var displayUraian = $(this).data('d-uraian');
var displayKategori = $(this).data('d-kategori');
var displayPoin = $(this).data('d-poin');
if (!id_syarats) {
showError('ID syarat tidak ditemukan!');
return;
}
if ($('#formDetailLaporan').length) {
$('#formDetailLaporan')[0].reset();
}
// Navtab Umum
var splitDisplayStatus = displayStatus.split(";");
var statusCode = splitDisplayStatus[0];
var statusMessage = splitDisplayStatus[1];
$('#displayStatusContainer').html(`<span class="badge ${statusCode}">${statusMessage}</span>`);
$('#displayTanggal').html(displayTanggal);
$('#displayNamaKegiatan').text(displayNamaKegiatan);
$('#displayNamaDosen').text(displayNamaDosen);
$('#displayUraian').text(displayUraian);
$('#displayKategori').text(displayKategori);
$('#displayPoin').text(displayPoin);
$('#id_syarats').val(id_syarats);
$('#id_kegiatans').val(id_kegiatan);
// Navtab File Syarat
$('#laporanKegiatanViewer').attr('src', laporanKegiatan);
$('#laporanSkViewer').attr('src', laporanSk);
$('#dokumenContainer').html('<p>Memuat dokumen syarat...</p>');
$.ajax({
url: "{{ route('laporan-kegiatan.prestasi.data-detail-laporan', ['id' => ':id']) }}"
.replace(':id', id_kegiatan),
type: 'GET',
data: {
id: id_syarats
},
success: function(res) {
let pengajuan_syarat = "";
if (res.dokumens && res.dokumens.length > 0) {
// File Syarat
pengajuan_syarat +=
`<div class="accordion custom-accordion" id="custom-accordion-one">`;
$.each(res.dokumens, function(i, v) {
let ext = v.url.split('.').pop().toLowerCase();
let headingId = `heading${i}`;
let collapseId = `collapse${i}`;
let showClass = i === 0 ? 'show' : '';
let collapsedClass = i === 0 ? '' : 'collapsed';
let ariaExpanded = i === 0 ? 'true' : 'false';
// Card start
pengajuan_syarat += `
<div class="card mb-0">
<div class="card-header bg-primary" id="${headingId}">
<h5 class="m-0">
<a class="custom-accordion-title text-white d-block py-1 ${collapsedClass}"
data-bs-toggle="collapse" href="#${collapseId}"
aria-expanded="${ariaExpanded}" aria-controls="${collapseId}">
<i class="uil-file-alt mx-1"></i>
${v.kategori_dokumen}
<i class="mdi mdi-chevron-down accordion-arrow"></i>
</a>
</h5>
</div>
<div id="${collapseId}" class="collapse ${showClass}"
aria-labelledby="${headingId}"
data-bs-parent="#custom-accordion-one">
<div class="card-body">`;
// Isi dokumen
if (ext === "pdf") {
pengajuan_syarat += `
<object data="${v.url}" type="application/pdf" width="100%" height="800px">
<p>Plugin PDF tidak tersedia. Unduh:
<a href="${v.url}" target="_blank">${v.kategori_dokumen}</a>
</p>
</object>`;
} else if (["jpg", "jpeg", "png"].includes(ext)) {
pengajuan_syarat +=
`<img src="${v.url}" alt="${v.kategori_dokumen}" style="width:100%; max-height:800px; object-fit:contain;">`;
} else {
pengajuan_syarat +=
`<a href="${v.url}" class="btn btn-sm btn-success" target="_blank">Unduh ${v.kategori_dokumen}</a>`;
}
// Card close
pengajuan_syarat += `
</div>
</div>
</div>`;
});
pengajuan_syarat += `</div>`;
} else {
pengajuan_syarat =
'<p class="text-muted text-center">Tidak ada dokumen ditemukan.</p>';
}
// Catatan Riwayat - Sanggahan
$('#sanggahanVerifikasi').text('');
res.notes?.reverse()?.some(element => {
if (element.type === 'Sanggahan') {
$('#sanggahanVerifikasi').text(element.message);
return true;
}
});
$('#dokumenContainer').html(pengajuan_syarat);
},
error: function(xhr) {
console.error(xhr);
$('#dokumenContainer').html(
'<p class="text-danger text-center">Gagal memuat dokumen.</p>');
}
});
// Load DataTable
if ($.fn.DataTable.isDataTable('#riwayat-verifikasi')) {
$('#riwayat-verifikasi').DataTable().ajax.url(
"{{ route('laporan-kegiatan.prestasi.data-detail-riwayat', ':id') }}".replace(':id',
id_syarats)).load();
$('#catatan-verifikasi').DataTable().ajax.url(
"{{ route('laporan-kegiatan.prestasi.data-detail-catatan', ':id') }}".replace(':id',
id_syarats)).load();
} else {
initRiwayatTable(id_syarats);
initCatatanTable(id_syarats);
}
$('#detailLaporan').modal('show');
});
function initRiwayatTable(id_syarats) {
if (!id_syarats) return;
var tableRiwayat = $('#riwayat-verifikasi').DataTable({
processing: true,
serverSide: true,
destroy: true,
responsive: true,
ajax: {
url: "{{ route('laporan-kegiatan.prestasi.data-detail-riwayat', ':id') }}".replace(':id',
id_syarats),
type: 'GET',
data: function(d) {
d.id_syarat = id_syarats;
},
error: function(xhr, error, code) {
console.error('Error loading data:', error);
// Tampilkan pesan error yang user-friendly
$('#riwayat-verifikasi tbody').html(
'<tr><td colspan="4" class="text-center text-danger">Gagal memuat data. Silakan coba lagi.</td></tr>'
);
}
},
columns: [{
data: 'DT_RowIndex',
name: 'DT_RowIndex',
orderable: false,
searchable: false,
className: 'text-center',
width: '5%'
},
{
data: 'employee_name',
name: 'employee_name',
orderable: true,
searchable: true,
width: '25%',
render: function(data, type, row) {
return data ? data : '-';
}
},
{
data: 'message',
name: 'message',
orderable: false,
searchable: true,
className: 'text-left',
width: '45%',
render: function(data, type, row) {
return data ? data : '-';
}
},
{
data: 'waktu',
name: 'waktu',
orderable: true,
searchable: false,
className: 'text-center',
width: '25%',
render: function(data, type, row) {
return data ? data : '-';
}
}
],
order: [
[3, 'desc']
],
pageLength: 10,
lengthMenu: [
[10, 25, 50, -1],
[10, 25, 50, "Semua"]
],
language: {
processing: "<div class='spinner-border spinner-border-sm' role='status'></div>&nbsp; Sedang Memuat...",
emptyTable: "Tidak ada data"
},
});
return tableRiwayat;
}
function initCatatanTable(id_syarats) {
if (!id_syarats) return;
var tableRiwayat = $('#catatan-verifikasi').DataTable({
processing: true,
serverSide: true,
destroy: true,
responsive: true,
ajax: {
url: "{{ route('laporan-kegiatan.prestasi.data-detail-catatan', ':id') }}".replace(':id',
id_syarats),
type: 'GET',
data: function(d) {
d.id_syarat = id_syarats;
},
error: function(xhr, error, code) {
console.error('Error loading data:', error);
$('#catatan-verifikasi tbody').html(
'<tr><td colspan="4" class="text-center text-danger">Gagal memuat data. Silakan coba lagi.</td></tr>'
);
}
},
columns: [{
data: 'DT_RowIndex',
name: 'DT_RowIndex',
orderable: false,
searchable: false,
className: 'text-center',
width: '5%'
},
{
data: 'employee_name',
name: 'employee_name',
orderable: true,
searchable: true,
width: '25%',
render: function(data, type, row) {
return data ? data : '-';
}
},
{
data: 'message',
name: 'message',
orderable: false,
searchable: true,
className: 'text-left',
width: '45%',
render: function(data, type, row) {
return data ? data : '-';
}
},
{
data: 'waktu',
name: 'waktu',
orderable: true,
searchable: false,
className: 'text-center',
width: '25%',
render: function(data, type, row) {
return data ? data : '-';
}
}
],
order: [
[3, 'desc']
],
pageLength: 10,
lengthMenu: [
[10, 25, 50, -1],
[10, 25, 50, "Semua"]
],
language: {
processing: "<div class='spinner-border spinner-border-sm' role='status'></div>&nbsp; Sedang Memuat...",
emptyTable: "Tidak ada data"
},
});
return tableRiwayat;
}
$('#detailLaporan').on('hidden.bs.modal', function() {
if ($.fn.DataTable.isDataTable('#riwayat-verifikasi')) {
$('#riwayat-verifikasi').DataTable().destroy();
$('#riwayat-verifikasi tbody').empty();
}
if ($.fn.DataTable.isDataTable('#catatan-verifikasi')) {
$('#catatan-verifikasi').DataTable().destroy();
$('#catatan-verifikasi tbody').empty();
}
});
</script>
<!-- Terima Detail Laporan -->
<script>
$('#konfirmasiTerimaDetailLaporan').on('click', function() {
const button = $(this);
const originalText = button.html();
const modal = $('#detailLaporan');
const id_syarat = $('#id_syarats').val();
const id_kegiatan = $('#id_kegiatans').val();
button.prop('disabled', true).html(
'<span class="spinner-border spinner-border-sm"></span> Memproses...');
$.ajax({
url: "{{ route('laporan-kegiatan.prestasi.detail-terima', ':id') }}".replace(':id',
id_kegiatan),
type: 'POST',
data: {
_token: '{{ csrf_token() }}',
id: id_syarat
},
success: function(response) {
modal.modal('hide');
if (response.success) {
showSuccess('Success', response.message);
setTimeout(function() {
location.reload();
}, 2000);
} else {
showError('Error', response.message);
}
},
error: function(xhr, status, error) {
let errorMessage = 'Terjadi kesalahan saat verifikasi';
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMessage = xhr.responseJSON.message;
} else if (xhr.responseJSON && xhr.responseJSON.errors) {
const errors = xhr.responseJSON.errors;
errorMessage = Object.values(errors).flat().join('<br>');
} else if (xhr.status === 404) {
errorMessage = 'Data pengajuan tidak ditemukan';
} else if (xhr.status === 422) {
errorMessage = 'Data yang dikirim tidak valid';
} else if (xhr.status === 500) {
errorMessage = 'Terjadi kesalahan pada server';
}
showError('Error', errorMessage);
},
complete: function() {
button.prop('disabled', false).html(originalText);
}
});
});
</script>
<!-- Batal Detail Laporan -->
<script>
$('#konfirmasiBatalDetailLaporan').on('click', function() {
const button = $(this);
const originalText = button.html();
const modal = $('#detailLaporan');
const id_syarat = $('#id_syarats').val();
const id_kegiatan = $('#id_kegiatans').val();
console.log(id_syarat, id_kegiatan);
button.prop('disabled', true).html(
'<span class="spinner-border spinner-border-sm"></span> Memproses...');
$.ajax({
url: "{{ route('laporan-kegiatan.prestasi.detail-batal', ':id') }}".replace(':id',
id_kegiatan),
type: 'POST',
data: {
_token: '{{ csrf_token() }}',
id: id_syarat
},
success: function(response) {
modal.modal('hide');
if (response.success) {
showSuccess('Success', response.message);
setTimeout(function() {
location.reload();
}, 2000);
} else {
showError('Error', response.message);
}
},
error: function(xhr, status, error) {
let errorMessage = 'Terjadi kesalahan saat verifikasi';
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMessage = xhr.responseJSON.message;
} else if (xhr.responseJSON && xhr.responseJSON.errors) {
const errors = xhr.responseJSON.errors;
errorMessage = Object.values(errors).flat().join('<br>');
} else if (xhr.status === 404) {
errorMessage = 'Data pengajuan tidak ditemukan';
} else if (xhr.status === 422) {
errorMessage = 'Data yang dikirim tidak valid';
} else if (xhr.status === 500) {
errorMessage = 'Terjadi kesalahan pada server';
}
showError('Error', errorMessage);
},
complete: function() {
button.prop('disabled', false).html(originalText);
}
});
});
</script>
<!-- Tolak Detail Laporan (Inside Modal) -->
<script>
// Variabel untuk menyimpan data modal detail laporan
var detailLaporanData = {};
// Fungsi untuk menyimpan data modal detail laporan
function saveDetailLaporanData() {
detailLaporanData = {
id_syarats: $('#id_syarats').val(),
id_kegiatans: $('#id_kegiatans').val(),
displayStatus: $('#displayStatusContainer').html(),
displayTanggal: $('#displayTanggal').html(),
displayNamaKegiatan: $('#displayNamaKegiatan').text(),
displayNamaDosen: $('#displayNamaDosen').text(),
displayUraian: $('#displayUraian').text(),
displayKategori: $('#displayKategori').text(),
displayPoin: $('#displayPoin').text(),
dokumenContainer: $('#dokumenContainer').html(),
sanggahanVerifikasi: $('#sanggahanVerifikasi').val()
};
}
// Fungsi untuk restore data modal detail laporan
function restoreDetailLaporanData() {
if (Object.keys(detailLaporanData).length > 0) {
$('#id_syarats').val(detailLaporanData.id_syarats);
$('#id_kegiatans').val(detailLaporanData.id_kegiatans);
$('#displayStatusContainer').html(detailLaporanData.displayStatus);
$('#displayTanggal').html(detailLaporanData.displayTanggal);
$('#displayNamaKegiatan').text(detailLaporanData.displayNamaKegiatan);
$('#displayNamaDosen').text(detailLaporanData.displayNamaDosen);
$('#displayUraian').text(detailLaporanData.displayUraian);
$('#displayKategori').text(detailLaporanData.displayKategori);
$('#displayPoin').text(detailLaporanData.displayPoin);
$('#dokumenContainer').html(detailLaporanData.dokumenContainer);
$('#sanggahanVerifikasi').val(detailLaporanData.sanggahanVerifikasi);
// Restore tab yang aktif
if (detailLaporanData.activeTab) {
$('.nav-pills .nav-link').removeClass('active');
$('.tab-pane').removeClass('show active');
$(`a[href="${detailLaporanData.activeTab}"]`).addClass('active');
$(detailLaporanData.activeTab).addClass('show active');
}
// Reinitialize DataTable jika diperlukan
if (detailLaporanData.id_syarats) {
// Destroy existing DataTables first
if ($.fn.DataTable.isDataTable('#riwayat-verifikasi')) {
$('#riwayat-verifikasi').DataTable().destroy();
$('#riwayat-verifikasi tbody').empty();
}
if ($.fn.DataTable.isDataTable('#catatan-verifikasi')) {
$('#catatan-verifikasi').DataTable().destroy();
$('#catatan-verifikasi tbody').empty();
}
// Reinitialize DataTables
setTimeout(function() {
initRiwayatTable(detailLaporanData.id_syarats);
initCatatanTable(detailLaporanData.id_syarats);
}, 100);
}
}
}
// Handle tombol Tolak di modal Detail Laporan
$(document).on('click', '#btnTolakDetailLaporan', function() {
// Simpan data modal detail laporan
saveDetailLaporanData();
// Sembunyikan modal detail laporan
$('#detailLaporan').modal('hide');
// Reset form keterangan tolak detail
$('#formTolakDetailLaporan')[0].reset();
// Tampilkan modal keterangan tolak detail
$('#modalTolakDetailLaporan').modal('show');
});
// Handle ketika modal keterangan tolak detail ditutup
$('#modalTolakDetailLaporan').on('hidden.bs.modal', function() {
// Buka kembali modal detail laporan dengan data yang tersimpan
$('#detailLaporan').modal('show');
// Restore data setelah modal terbuka dengan delay yang lebih lama
setTimeout(function() {
restoreDetailLaporanData();
}, 500);
});
// Handle konfirmasi tolak detail
$('#konfirmasiTolakDetailLaporan').on('click', function() {
const button = $(this);
const originalText = button.html();
const keteranganTolak = $('#keteranganTolakDetail').val().trim();
// Validasi input
if (!keteranganTolak) {
showError('Error', 'Alasan penolakan wajib diisi!');
return;
}
// Ambil data dari variabel yang tersimpan
const id_syarat = detailLaporanData.id_syarats;
const id_kegiatan = detailLaporanData.id_kegiatans;
if (!id_syarat || !id_kegiatan) {
showError('Error', 'Data pengajuan tidak ditemukan!');
return;
}
button.prop('disabled', true).html(
'<span class="spinner-border spinner-border-sm"></span> Memproses...'
);
$.ajax({
url: "{{ route('laporan-kegiatan.prestasi.detail-tolak', ':id') }}".replace(':id',
id_kegiatan),
type: 'POST',
data: {
_token: '{{ csrf_token() }}',
id: id_syarat,
keterangan: keteranganTolak
},
success: function(response) {
$('#modalTolakDetailLaporan').modal('hide');
if (response.success) {
showSuccess('Success', response.message);
// Clear saved data
detailLaporanData = {};
setTimeout(function() {
location.reload();
}, 2000);
} else {
showError('Error', response.message);
// Jika gagal, buka kembali modal detail laporan
setTimeout(function() {
$('#detailLaporan').modal('show');
restoreDetailLaporanData();
}, 500);
}
},
error: function(xhr, status, error) {
let errorMessage = 'Terjadi kesalahan saat menolak pengajuan';
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMessage = xhr.responseJSON.message;
} else if (xhr.responseJSON && xhr.responseJSON.errors) {
const errors = xhr.responseJSON.errors;
errorMessage = Object.values(errors).flat().join('<br>');
} else if (xhr.status === 404) {
errorMessage = 'Data pengajuan tidak ditemukan';
} else if (xhr.status === 422) {
errorMessage = 'Data yang dikirim tidak valid';
} else if (xhr.status === 500) {
errorMessage = 'Terjadi kesalahan pada server';
}
showError('Error', errorMessage);
// Jika error, buka kembali modal detail laporan
setTimeout(function() {
$('#detailLaporan').modal('show');
restoreDetailLaporanData();
}, 500);
},
complete: function() {
button.prop('disabled', false).html(originalText);
}
});
});
// Handle ketika modal detail laporan ditutup secara manual
$('#detailLaporan').on('hidden.bs.modal', function() {
// Jika modal keterangan tolak detail tidak sedang terbuka, maka clear data
if (!$('#modalTolakDetailLaporan').hasClass('show')) {
detailLaporanData = {};
// Destroy DataTable seperti sebelumnya
if ($.fn.DataTable.isDataTable('#riwayat-verifikasi')) {
$('#riwayat-verifikasi').DataTable().destroy();
$('#riwayat-verifikasi tbody').empty();
}
if ($.fn.DataTable.isDataTable('#catatan-verifikasi')) {
$('#catatan-verifikasi').DataTable().destroy();
$('#catatan-verifikasi tbody').empty();
}
}
});
// Tambahan: Handle ketika modal detail laporan dibuka kembali
$('#detailLaporan').on('shown.bs.modal', function() {
// Jika ada data yang tersimpan dan DataTable belum ada, inisialisasi ulang
if (Object.keys(detailLaporanData).length > 0 && detailLaporanData.id_syarats) {
if (!$.fn.DataTable.isDataTable('#riwayat-verifikasi')) {
setTimeout(function() {
initRiwayatTable(detailLaporanData.id_syarats);
}, 200);
}
if (!$.fn.DataTable.isDataTable('#catatan-verifikasi')) {
setTimeout(function() {
initCatatanTable(detailLaporanData.id_syarats);
}, 200);
}
}
});
</script>
<!-- Terima Laporan (Outside Modal) -->
<script>
$('#konfirmasiTerimaLaporan').on('click', function() {
const button = $(this);
const originalText = button.html();
const id_syarat = button.data('id');
const id_kegiatan = {{ $data->id }};
button.prop('disabled', true).html(
'<span class="spinner-border spinner-border-sm"></span> Memproses...');
$.ajax({
url: "{{ route('laporan-kegiatan.prestasi.detail-terima', ':id') }}".replace(':id',
id_kegiatan),
type: 'POST',
data: {
_token: '{{ csrf_token() }}',
id: id_syarat
},
success: function(response) {
if (response.success) {
showSuccess('Success', response.message);
setTimeout(function() {
location.reload();
}, 2000);
} else {
showError('Error', response.message);
}
},
error: function(xhr, status, error) {
let errorMessage = 'Terjadi kesalahan saat verifikasi';
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMessage = xhr.responseJSON.message;
} else if (xhr.responseJSON && xhr.responseJSON.errors) {
const errors = xhr.responseJSON.errors;
errorMessage = Object.values(errors).flat().join('<br>');
} else if (xhr.status === 404) {
errorMessage = 'Data pengajuan tidak ditemukan';
} else if (xhr.status === 422) {
errorMessage = 'Data yang dikirim tidak valid';
} else if (xhr.status === 500) {
errorMessage = 'Terjadi kesalahan pada server';
}
showError('Error', errorMessage);
},
complete: function() {
button.prop('disabled', false).html(originalText);
}
});
});
</script>
<!-- Batal Laporan (Outside Modal) -->
<script>
$('#konfirmasiBatalLaporan').on('click', function() {
const button = $(this);
const originalText = button.html();
const id_syarat = button.data('id');
const id_kegiatan = {{ $data->id }};
button.prop('disabled', true).html(
'<span class="spinner-border spinner-border-sm"></span> Memproses...');
$.ajax({
url: "{{ route('laporan-kegiatan.prestasi.detail-batal', ':id') }}".replace(':id',
id_kegiatan),
type: 'POST',
data: {
_token: '{{ csrf_token() }}',
id: id_syarat
},
success: function(response) {
if (response.success) {
showSuccess('Success', response.message);
setTimeout(function() {
location.reload();
}, 2000);
} else {
showError('Error', response.message);
}
},
error: function(xhr, status, error) {
let errorMessage = 'Terjadi kesalahan saat verifikasi';
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMessage = xhr.responseJSON.message;
} else if (xhr.responseJSON && xhr.responseJSON.errors) {
const errors = xhr.responseJSON.errors;
errorMessage = Object.values(errors).flat().join('<br>');
} else if (xhr.status === 404) {
errorMessage = 'Data pengajuan tidak ditemukan';
} else if (xhr.status === 422) {
errorMessage = 'Data yang dikirim tidak valid';
} else if (xhr.status === 500) {
errorMessage = 'Terjadi kesalahan pada server';
}
showError('Error', errorMessage);
},
complete: function() {
button.prop('disabled', false).html(originalText);
}
});
});
</script>
<!-- Tolak Laporan (Outside Modal) -->
<script>
// Handle tombol Tolak di luar modal
$(document).on('click', '#btnTolakLaporan', function() {
const id_syarat = $(this).data('id');
// Simpan ID untuk digunakan nanti
$('#modalTolakLaporan').data('id-syarat', id_syarat);
// Reset form keterangan tolak laporan
$('#formTolakLaporan')[0].reset();
// Tampilkan modal keterangan tolak laporan
$('#modalTolakLaporan').modal('show');
});
// Handle konfirmasi tolak laporan (outside modal)
$('#konfirmasiTolakLaporan').on('click', function() {
const button = $(this);
const originalText = button.html();
const keteranganTolak = $('#keteranganTolakLaporan').val().trim();
const id_syarat = $('#modalTolakLaporan').data('id-syarat');
const id_kegiatan = {{ $data->id }};
// Validasi input
if (!keteranganTolak) {
showError('Error', 'Alasan penolakan wajib diisi!');
return;
}
if (!id_syarat) {
showError('Error', 'Data pengajuan tidak ditemukan!');
return;
}
button.prop('disabled', true).html(
'<span class="spinner-border spinner-border-sm"></span> Memproses...'
);
$.ajax({
url: "{{ route('laporan-kegiatan.prestasi.detail-tolak', ':id') }}".replace(':id',
id_kegiatan),
type: 'POST',
data: {
_token: '{{ csrf_token() }}',
id: id_syarat,
keterangan: keteranganTolak
},
success: function(response) {
$('#modalTolakLaporan').modal('hide');
if (response.success) {
showSuccess('Success', response.message);
setTimeout(function() {
location.reload();
}, 2000);
} else {
showError('Error', response.message);
}
},
error: function(xhr, status, error) {
let errorMessage = 'Terjadi kesalahan saat menolak pengajuan';
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMessage = xhr.responseJSON.message;
} else if (xhr.responseJSON && xhr.responseJSON.errors) {
const errors = xhr.responseJSON.errors;
errorMessage = Object.values(errors).flat().join('<br>');
} else if (xhr.status === 404) {
errorMessage = 'Data pengajuan tidak ditemukan';
} else if (xhr.status === 422) {
errorMessage = 'Data yang dikirim tidak valid';
} else if (xhr.status === 500) {
errorMessage = 'Terjadi kesalahan pada server';
}
showError('Error', errorMessage);
},
complete: function() {
button.prop('disabled', false).html(originalText);
}
});
});
// Reset data ketika modal tolak laporan ditutup
$('#modalTolakLaporan').on('hidden.bs.modal', function() {
$(this).removeData('id-syarat');
$('#formTolakLaporan')[0].reset();
});
</script>
@endsection