[Operator] Perbaikan Laman Portal -> Konsultasi
This commit is contained in:
@@ -8,8 +8,8 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Tulis data pegawai DB lama (t_pegawai) dalam cakupan yang tampil di daftar operator (EmployeeDirectory::scoped).
|
||||
* Hanya ubah data dasar dan hapus (template SATU tidak punya tombol Tambah untuk Pegawai). Akun login
|
||||
* (t_account) tidak disentuh, dan pegawai yang dirujuk jabatan, jadwal, bimbingan, skripsi, atau akun tidak boleh dihapus.
|
||||
* Tambah (sebagai dosen) dan hapus. Mengubah biodata dilakukan di halaman detail (EmployeeBiodata). Akun login (t_account)
|
||||
* tidak disentuh, dan pegawai yang dirujuk jabatan, jadwal, bimbingan, skripsi, atau akun tidak boleh dihapus.
|
||||
*/
|
||||
final class EmployeeRecords
|
||||
{
|
||||
@@ -17,6 +17,9 @@ final class EmployeeRecords
|
||||
|
||||
public const array ACTIVE = [1 => 'Aktif', 0 => 'Tidak aktif'];
|
||||
|
||||
/** t_jenispegawai: 1 Dosen, 2 Staff. */
|
||||
private const int TYPE_LECTURER = 1;
|
||||
|
||||
/** [tabel, kolom rujukan ke idpegawai]; baris di salah satunya menghalangi penghapusan. */
|
||||
private const array DEPENDENTS = [
|
||||
['t_jabatanpegawai', 'idpegawai'], ['t_mastermk', 'idpegawai'], ['t_jadwaldosen', 'iddosen'], ['t_jadwal', 'idpegperkuliahan'],
|
||||
@@ -38,19 +41,26 @@ final class EmployeeRecords
|
||||
}
|
||||
|
||||
/**
|
||||
* Tambah pegawai baru sebagai dosen dengan home base salah satu prodi akun (t_dosen.idprogdi), sehingga langsung masuk
|
||||
* cakupan daftar. Pegawai staf (bukan dosen) hanya tampil di daftar lewat jabatan aktif, yang tidak diatur di sini.
|
||||
*
|
||||
* @param list<int> $prodi
|
||||
* @param list<int> $faculties
|
||||
* @param array<string, mixed> $input
|
||||
* @return int idpegawai baru
|
||||
*/
|
||||
public function update(array $prodi, array $faculties, int $id, array $input, string $actor, ?string $ip): void
|
||||
public function create(array $prodi, int $homeBase, array $input, string $actor, ?string $ip): int
|
||||
{
|
||||
$current = $this->owned($prodi, $faculties)->where('p.idpegawai', $id)->first(['p.idpegawai', 'p.statusaktif']);
|
||||
if ($current === null) {
|
||||
throw new PortalException('Pegawai tidak ditemukan.');
|
||||
if (! in_array($homeBase, $prodi, true)) {
|
||||
throw new PortalException('Home base harus dipilih dari program studi Anda.');
|
||||
}
|
||||
$values = $this->values($input, $current);
|
||||
$values = $this->values($input);
|
||||
|
||||
$this->db()->table('t_pegawai')->where('idpegawai', $id)->update($values + $this->audit($actor, $ip));
|
||||
return $this->db()->transaction(function () use ($values, $homeBase, $actor, $ip): int {
|
||||
$id = (int) $this->db()->table('t_pegawai')->insertGetId($values + ['idjenispegawai' => self::TYPE_LECTURER] + $this->audit($actor, $ip), 'idpegawai');
|
||||
$this->db()->table('t_dosen')->insert(['idpegawai' => $id, 'idprogdi' => $homeBase] + $this->audit($actor, $ip));
|
||||
|
||||
return $id;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +119,7 @@ final class EmployeeRecords
|
||||
* @param array<string, mixed> $input
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function values(array $input, ?object $current): array
|
||||
private function values(array $input): array
|
||||
{
|
||||
$text = fn (mixed $v): ?string => ($v = trim((string) $v)) === '' ? null : $v;
|
||||
$nip = trim((string) ($input['nip'] ?? ''));
|
||||
@@ -117,9 +127,7 @@ final class EmployeeRecords
|
||||
if ($nip === '' || $nama === '') {
|
||||
throw new PortalException('NIP dan nama wajib diisi.');
|
||||
}
|
||||
$duplicate = $this->db()->table('t_pegawai')->whereRaw('upper(trim(nip)) = ?', [mb_strtoupper($nip)])
|
||||
->when($current !== null, fn (Builder $q) => $q->where('idpegawai', '<>', $current->idpegawai))->exists();
|
||||
if ($duplicate) {
|
||||
if ($this->db()->table('t_pegawai')->whereRaw('upper(trim(nip)) = ?', [mb_strtoupper($nip)])->exists()) {
|
||||
throw new PortalException("NIP {$nip} sudah terdaftar.");
|
||||
}
|
||||
$gender = filled($input['kelamin'] ?? null) ? (int) $input['kelamin'] : null;
|
||||
@@ -138,8 +146,6 @@ final class EmployeeRecords
|
||||
if (! isset(self::ACTIVE[$active])) {
|
||||
throw new PortalException('Status aktif tidak dikenal.');
|
||||
}
|
||||
// Kode aktif selain 0 dan 1 (mis. 2, 3, 5, 6) tidak ada artinya di sini: dibiarkan selama tetap dianggap aktif.
|
||||
$keep = $current !== null && (int) $current->statusaktif !== 0 ? (int) $current->statusaktif : 1;
|
||||
|
||||
return [
|
||||
'nip' => $nip,
|
||||
@@ -152,7 +158,7 @@ final class EmployeeRecords
|
||||
'telepon' => $text($input['telepon'] ?? null),
|
||||
'email' => $email,
|
||||
'idstatuspegawai' => $status,
|
||||
'statusaktif' => $active === 0 ? 0 : $keep,
|
||||
'statusaktif' => $active,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user