Perbaikan menu Operator
This commit is contained in:
@@ -11,7 +11,8 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Tugas akhir, yudisium, dan wisuda DB lama (hanya baca): t_skripsi (judul, pembimbing, penguji), t_evaluasi_rekap
|
||||
* Tugas akhir, yudisium, dan wisuda DB lama (hanya baca, kecuali periode yudisium/wisuda yang bisa ditambah, diubah,
|
||||
* dihapus): t_skripsi (judul, pembimbing, penguji), t_evaluasi_rekap
|
||||
* (SKS/mutu/nilai skripsi untuk kelayakan yudisium), lulusan t_mahasiswa (stataktif 2, idperiodewisuda, nomor SK/ijazah)
|
||||
* dilengkapi pdpt_tmst_mahasiswa, t_periodewisuda, dan t_predikatkelulusan.
|
||||
*/
|
||||
@@ -330,12 +331,114 @@ final class Graduation
|
||||
'status' => self::PERIOD_STATUS[trim((string) $w->status)] ?? '–',
|
||||
'tone' => trim((string) $w->status) === '1' ? 'success' : null,
|
||||
'lulusan' => (int) $units->sum('n'),
|
||||
'form' => [
|
||||
'kode' => trim((string) $w->kdperiode), 'nama' => trim((string) $w->namaperiode), 'tahun' => trim((string) $w->tahun),
|
||||
'periode_kuliah' => $w->idperiode_kuliah === null ? '' : (int) $w->idperiode_kuliah,
|
||||
'buka' => $w->tgl_buka === null ? '' : Carbon::parse($w->tgl_buka)->toDateString(),
|
||||
'tutup' => $w->tgl_tutup === null ? '' : Carbon::parse($w->tgl_tutup)->toDateString(),
|
||||
'wisuda' => $w->tgl_wisuda === null ? '' : Carbon::parse($w->tgl_wisuda)->toDateString(),
|
||||
'status' => isset(self::PERIOD_STATUS[trim((string) $w->status)]) ? trim((string) $w->status) : '0',
|
||||
],
|
||||
];
|
||||
})->values();
|
||||
|
||||
return new LengthAwarePaginator($items->forPage($page, $perPage)->values()->all(), $items->count(), $perPage, $page);
|
||||
}
|
||||
|
||||
// ---- Penulisan periode yudisium/wisuda (t_periodewisuda) ---------------------------------------------------------
|
||||
|
||||
/** @return array<string, string> status => label, untuk pilihan formulir */
|
||||
public static function periodStatuses(): array
|
||||
{
|
||||
return self::PERIOD_STATUS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{kode: string, nama: string, tahun?: ?string, periode_kuliah?: ?int, buka?: ?string, tutup?: ?string, wisuda?: ?string, status: string} $input
|
||||
* @return int id baru (idperiode tanpa sequence: maksimum + 1)
|
||||
*/
|
||||
public function createPeriod(array $input): int
|
||||
{
|
||||
$values = $this->periodValues($input, null);
|
||||
|
||||
return $this->db()->transaction(function () use ($values): int {
|
||||
$id = (int) $this->db()->table('t_periodewisuda')->max('idperiode') + 1;
|
||||
$this->db()->table('t_periodewisuda')->insert(['idperiode' => $id] + $values);
|
||||
|
||||
return $id;
|
||||
});
|
||||
}
|
||||
|
||||
/** @param array{kode: string, nama: string, tahun?: ?string, periode_kuliah?: ?int, buka?: ?string, tutup?: ?string, wisuda?: ?string, status: string} $input */
|
||||
public function updatePeriod(int $id, array $input): void
|
||||
{
|
||||
if (! $this->db()->table('t_periodewisuda')->where('idperiode', $id)->exists()) {
|
||||
throw new PortalException('Periode tidak ditemukan.');
|
||||
}
|
||||
|
||||
$this->db()->table('t_periodewisuda')->where('idperiode', $id)->update($this->periodValues($input, $id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus periode yang belum punya lulusan terdaftar; mengembalikan jumlah yang terhapus.
|
||||
*
|
||||
* @param list<int> $ids
|
||||
*/
|
||||
public function deletePeriods(array $ids): int
|
||||
{
|
||||
$ids = array_values(array_unique(array_map('intval', $ids)));
|
||||
$rows = $this->db()->table('t_periodewisuda')->whereIn('idperiode', $ids)->get(['idperiode', 'kdperiode', 'namaperiode']);
|
||||
if ($rows->isEmpty()) {
|
||||
throw new PortalException('Periode tidak ditemukan.');
|
||||
}
|
||||
|
||||
$used = $this->db()->table('t_mahasiswa')->whereIn('idperiodewisuda', $rows->pluck('idperiode')->all())->distinct()->pluck('idperiodewisuda')->map(fn ($id): int => (int) $id);
|
||||
if ($used->isNotEmpty()) {
|
||||
$names = $rows->filter(fn (object $w): bool => $used->contains((int) $w->idperiode))->map(fn (object $w): string => self::periodName($w))->implode(', ');
|
||||
throw new PortalException("Periode {$names} sudah punya lulusan terdaftar, sehingga tidak boleh dihapus.");
|
||||
}
|
||||
|
||||
return $this->db()->table('t_periodewisuda')->whereIn('idperiode', $rows->pluck('idperiode')->all())->delete();
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function periodValues(array $input, ?int $ignore): array
|
||||
{
|
||||
$kode = mb_substr(trim((string) ($input['kode'] ?? '')), 0, 5);
|
||||
$nama = mb_substr(trim((string) ($input['nama'] ?? '')), 0, 50);
|
||||
$tahun = trim((string) ($input['tahun'] ?? ''));
|
||||
$status = trim((string) ($input['status'] ?? '0'));
|
||||
$periode = filled($input['periode_kuliah'] ?? null) ? (int) $input['periode_kuliah'] : null;
|
||||
|
||||
if ($kode === '' || $nama === '') {
|
||||
throw new PortalException('Kode dan nama periode wajib diisi.');
|
||||
}
|
||||
if ($tahun !== '' && ! preg_match('/^\d{4}$/', $tahun)) {
|
||||
throw new PortalException('Tahun harus empat angka.');
|
||||
}
|
||||
if (! isset(self::PERIOD_STATUS[$status])) {
|
||||
throw new PortalException('Status periode harus dipilih.');
|
||||
}
|
||||
if ($periode !== null && ! $this->db()->table('t_periodekuliah')->where('idperiode', $periode)->exists()) {
|
||||
throw new PortalException('Periode akademik tidak dikenal.');
|
||||
}
|
||||
$date = fn (string $key): ?string => filled($input[$key] ?? null) ? Carbon::parse($input[$key])->toDateString() : null;
|
||||
[$buka, $tutup, $wisuda] = [$date('buka'), $date('tutup'), $date('wisuda')];
|
||||
if ($buka !== null && $tutup !== null && $tutup < $buka) {
|
||||
throw new PortalException('Tanggal tutup pendaftaran tidak boleh mendahului tanggal buka.');
|
||||
}
|
||||
$duplicate = $this->db()->table('t_periodewisuda')->whereRaw('upper(trim(coalesce(kdperiode, \'\'))) = ?', [mb_strtoupper($kode)])
|
||||
->when($ignore !== null, fn (Builder $q) => $q->where('idperiode', '<>', $ignore))->exists();
|
||||
if ($duplicate) {
|
||||
throw new PortalException("Kode periode {$kode} sudah ada.");
|
||||
}
|
||||
|
||||
return [
|
||||
'kdperiode' => $kode, 'namaperiode' => $nama, 'tahun' => $tahun === '' ? substr($kode, 0, 4) : $tahun,
|
||||
'idperiode_kuliah' => $periode, 'tgl_buka' => $buka, 'tgl_tutup' => $tutup, 'tgl_wisuda' => $wisuda, 'status' => $status,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Peserta wisuda (lulusan) per periode wisuda.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user