first commit
This commit is contained in:
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Verifikasi\TriDharma;
|
||||
|
||||
use App\Helpers\BeritaAcaraHelper;
|
||||
use App\Helpers\JabatanPegawaiTambahanHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Verifikator\Team;
|
||||
use App\Models\Verifikator\View\Pegawai;
|
||||
use App\Services\DawaiService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class BawahanController extends Controller
|
||||
{
|
||||
private DawaiService $dawaiService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dawaiService = new DawaiService;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$title = 'Daftar Bawahan';
|
||||
|
||||
$user = Auth::user();
|
||||
$team = Team::find(session('team_id'));
|
||||
$isAdmin = $team && $team->nama === 'Admin';
|
||||
$isDekan = false;
|
||||
|
||||
// Check if user is Dekan
|
||||
$currentPegawai = Pegawai::where('nip', $user->nip)->first();
|
||||
if ($currentPegawai && $team && $team->unit_kerja_id >= 1 && $team->unit_kerja_id <= 9) {
|
||||
$isDekan = JabatanPegawaiTambahanHelper::isDekan($user->nip);
|
||||
}
|
||||
|
||||
// If user is Dekan, show special view with Ketua Jurusan list and their bawahan
|
||||
if ($isDekan && ! $isAdmin) {
|
||||
return $this->indexDekan($request, $currentPegawai, $team);
|
||||
}
|
||||
|
||||
// If admin and nip_atasan is provided, use that NIP, otherwise use current user's NIP
|
||||
$nipAtasan = $request->get('nip_atasan');
|
||||
|
||||
// For Admin, show selection form only if no nip_atasan provided
|
||||
if ($isAdmin && ! $nipAtasan) {
|
||||
// Get all Ketua Jurusan for atasan selection
|
||||
$ketuaJurusans = JabatanPegawaiTambahanHelper::getAllKetuaJurusan();
|
||||
$ketuaJurusanNips = $ketuaJurusans->pluck('nip')->toArray();
|
||||
|
||||
$allPegawais = Pegawai::select('nip', 'nama')
|
||||
->where(function ($query) use ($ketuaJurusanNips) {
|
||||
$query->whereIn('nip', $ketuaJurusanNips)
|
||||
->orWhereIn('nip_siakad', $ketuaJurusanNips);
|
||||
})
|
||||
->orderBy('nama')
|
||||
->get();
|
||||
|
||||
$beritaAcaraCheck = BeritaAcaraHelper::checkBeritaAcaraByTeam(session('team_id'));
|
||||
$beritaAcaraUploaded = $beritaAcaraCheck['uploaded'];
|
||||
$beritaAcaraMessage = $beritaAcaraCheck['message'];
|
||||
|
||||
return view('verifikasi.tri-dharma.bawahan.index', compact('title', 'isAdmin', 'allPegawais', 'nipAtasan', 'beritaAcaraUploaded', 'beritaAcaraMessage'));
|
||||
}
|
||||
|
||||
// Get pegawai data
|
||||
if ($isAdmin && $nipAtasan) {
|
||||
$pegawai = Pegawai::where('nip', $nipAtasan)
|
||||
->orWhere('nip_siakad', $nipAtasan)
|
||||
->first();
|
||||
} else {
|
||||
$pegawai = Pegawai::where('nip', $user->nip)->first();
|
||||
$nipAtasan = $pegawai ? $pegawai->nip : null;
|
||||
}
|
||||
|
||||
if (! $pegawai) {
|
||||
return redirect()->back()->with('error', 'Data pegawai tidak ditemukan');
|
||||
}
|
||||
|
||||
// Get list bawahan from DAWAI service
|
||||
$bawahansData = $this->dawaiService->getListBawahan($pegawai->nip);
|
||||
|
||||
// If no bawahan found and nip != nip_siakad, try with nip_siakad
|
||||
if (empty($bawahansData['data']) && $pegawai->nip !== $pegawai->nip_siakad) {
|
||||
$bawahansData = $this->dawaiService->getListBawahan($pegawai->nip_siakad);
|
||||
}
|
||||
|
||||
// Extract bawahan list
|
||||
$bawahanList = [];
|
||||
if (isset($bawahansData['data']['bawahan']) && is_array($bawahansData['data']['bawahan'])) {
|
||||
$bawahanList = $bawahansData['data']['bawahan'];
|
||||
}
|
||||
|
||||
// Get pegawais - if admin, show all pegawais, otherwise show same unit_kerja
|
||||
if ($isAdmin) {
|
||||
$pegawais = Pegawai::select('nip', 'nama')
|
||||
->orderBy('nama')
|
||||
->get();
|
||||
|
||||
// Get all Ketua Jurusan for atasan selection
|
||||
$ketuaJurusans = JabatanPegawaiTambahanHelper::getAllKetuaJurusan();
|
||||
$ketuaJurusanNips = $ketuaJurusans->pluck('nip')->toArray();
|
||||
|
||||
$allPegawais = Pegawai::select('nip', 'nama')
|
||||
->where(function ($query) use ($ketuaJurusanNips) {
|
||||
$query->whereIn('nip', $ketuaJurusanNips)
|
||||
->orWhereIn('nip_siakad', $ketuaJurusanNips);
|
||||
})
|
||||
->orderBy('nama')
|
||||
->get();
|
||||
} else {
|
||||
$pegawais = Pegawai::select('nip', 'nama')
|
||||
->where('unit_kerja_id', $pegawai->unit_kerja_id)
|
||||
->orderBy('nama')
|
||||
->get();
|
||||
|
||||
$allPegawais = collect([]);
|
||||
}
|
||||
|
||||
// Get bawahan pegawai data from database
|
||||
$bawahanNips = collect($bawahanList)->pluck('nip')->toArray();
|
||||
$bawahans = collect([]);
|
||||
|
||||
if (! empty($bawahanNips)) {
|
||||
$bawahans = Pegawai::select('nip', 'nama')
|
||||
->where(function ($query) use ($bawahanNips) {
|
||||
$query->whereIn('nip', $bawahanNips)
|
||||
->orWhereIn('nip_siakad', $bawahanNips);
|
||||
})
|
||||
->orderBy('nama')
|
||||
->get();
|
||||
}
|
||||
|
||||
$beritaAcaraCheck = BeritaAcaraHelper::checkBeritaAcaraByTeam(session('team_id'));
|
||||
$beritaAcaraUploaded = $beritaAcaraCheck['uploaded'];
|
||||
$beritaAcaraMessage = $beritaAcaraCheck['message'];
|
||||
|
||||
return view('verifikasi.tri-dharma.bawahan.index', compact('title', 'bawahans', 'pegawais', 'isAdmin', 'allPegawais', 'nipAtasan', 'pegawai', 'beritaAcaraUploaded', 'beritaAcaraMessage'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Index view for Dekan - shows Ketua Jurusan list with their bawahan
|
||||
*/
|
||||
private function indexDekan(Request $request, $dekanPegawai, $team)
|
||||
{
|
||||
$title = 'Daftar Bawahan Ketua Jurusan';
|
||||
|
||||
// Get Ketua Jurusan in the same fakultas using JabatanPegawaiTambahanHelper
|
||||
$ketuaJurusans = JabatanPegawaiTambahanHelper::getKetuaJurusanByFakultas($team->unit_kerja_id);
|
||||
|
||||
// Get pegawai data for each Ketua Jurusan
|
||||
$ketuaJurusanNips = $ketuaJurusans->pluck('nip')->toArray();
|
||||
$ketuaJurusanPegawais = Pegawai::whereIn('nip', $ketuaJurusanNips)
|
||||
->orWhereIn('nip_siakad', $ketuaJurusanNips)
|
||||
->get()
|
||||
->keyBy('nip');
|
||||
|
||||
// Build Ketua Jurusan list with their bawahan
|
||||
$ketuaJurusanList = [];
|
||||
foreach ($ketuaJurusans as $kj) {
|
||||
$pegawai = $ketuaJurusanPegawais->get($kj->nip);
|
||||
if (! $pegawai) {
|
||||
// Try to find by nip_siakad
|
||||
$pegawai = $ketuaJurusanPegawais->first(function ($p) use ($kj) {
|
||||
return $p->nip_siakad === $kj->nip;
|
||||
});
|
||||
}
|
||||
|
||||
if ($pegawai) {
|
||||
// Get bawahan for this Ketua Jurusan
|
||||
$bawahansData = $this->dawaiService->getListBawahan($pegawai->nip);
|
||||
|
||||
// If no bawahan found and nip != nip_siakad, try with nip_siakad
|
||||
if (empty($bawahansData['data']) && $pegawai->nip !== $pegawai->nip_siakad) {
|
||||
$bawahansData = $this->dawaiService->getListBawahan($pegawai->nip_siakad);
|
||||
}
|
||||
|
||||
$bawahanList = [];
|
||||
if (isset($bawahansData['data']['bawahan']) && is_array($bawahansData['data']['bawahan'])) {
|
||||
$bawahanNips = collect($bawahansData['data']['bawahan'])->pluck('nip')->toArray();
|
||||
|
||||
if (! empty($bawahanNips)) {
|
||||
$bawahanList = Pegawai::select('nip', 'nama')
|
||||
->where(function ($query) use ($bawahanNips) {
|
||||
$query->whereIn('nip', $bawahanNips)
|
||||
->orWhereIn('nip_siakad', $bawahanNips);
|
||||
})
|
||||
->orderBy('nama')
|
||||
->get()
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
$ketuaJurusanList[] = [
|
||||
'nip' => $pegawai->nip,
|
||||
'nama' => $pegawai->nama,
|
||||
'jabatan' => $kj->jabatan_nama,
|
||||
'keterangan' => $kj->keterangan_jtt,
|
||||
'bawahan' => $bawahanList,
|
||||
'jumlah_bawahan' => count($bawahanList),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$isDekan = true;
|
||||
|
||||
return view('verifikasi.tri-dharma.bawahan.index-dekan', compact(
|
||||
'title',
|
||||
'ketuaJurusanList',
|
||||
'dekanPegawai',
|
||||
'isDekan'
|
||||
));
|
||||
}
|
||||
|
||||
public function data(Request $request)
|
||||
{
|
||||
$nipAtasan = $request->get('nip_atasan');
|
||||
|
||||
if (! $nipAtasan) {
|
||||
return response()->json(['error' => 'NIP Atasan is required'], 400);
|
||||
}
|
||||
|
||||
// Get pegawai data
|
||||
$pegawai = Pegawai::where('nip', $nipAtasan)
|
||||
->orWhere('nip_siakad', $nipAtasan)
|
||||
->first();
|
||||
|
||||
if (! $pegawai) {
|
||||
return response()->json(['error' => 'Data pegawai tidak ditemukan'], 404);
|
||||
}
|
||||
|
||||
// Get list bawahan from DAWAI service
|
||||
$bawahansData = $this->dawaiService->getListBawahan($pegawai->nip);
|
||||
|
||||
// If no bawahan found and nip != nip_siakad, try with nip_siakad
|
||||
if (empty($bawahansData['data']) && $pegawai->nip !== $pegawai->nip_siakad) {
|
||||
$bawahansData = $this->dawaiService->getListBawahan($pegawai->nip_siakad);
|
||||
}
|
||||
|
||||
// Extract bawahan list
|
||||
$bawahanList = [];
|
||||
if (isset($bawahansData['data']['bawahan']) && is_array($bawahansData['data']['bawahan'])) {
|
||||
$bawahanList = $bawahansData['data']['bawahan'];
|
||||
}
|
||||
|
||||
// Get bawahan pegawai data from database
|
||||
$bawahanNips = collect($bawahanList)->pluck('nip')->toArray();
|
||||
$bawahans = collect([]);
|
||||
|
||||
if (! empty($bawahanNips)) {
|
||||
$bawahans = Pegawai::select('nip', 'nama')
|
||||
->where(function ($query) use ($bawahanNips) {
|
||||
$query->whereIn('nip', $bawahanNips)
|
||||
->orWhereIn('nip_siakad', $bawahanNips);
|
||||
})
|
||||
->orderBy('nama')
|
||||
->get();
|
||||
}
|
||||
|
||||
return DataTables::of($bawahans)
|
||||
->skipPaging()
|
||||
->addIndexColumn()
|
||||
->addColumn('aksi', function ($row) {
|
||||
return '<button type="button" class="btn btn-sm btn-danger btn-hapus" data-nip="'.$row->nip.'" data-nama="'.$row->nama.'">
|
||||
<i class="uil-trash-alt"></i> Hapus
|
||||
</button>';
|
||||
})
|
||||
->rawColumns(['aksi'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'bawahan' => 'nullable|array',
|
||||
'bawahan.*' => 'required|string',
|
||||
'nip_atasan' => 'required|string',
|
||||
]);
|
||||
|
||||
$team = Team::find(session('team_id'));
|
||||
$isAdmin = $team && $team->nama === 'Admin';
|
||||
|
||||
// Get NIP atasan - if admin, use nip_atasan from request, otherwise use current user's nip
|
||||
$nipAtasan = $request->nip_atasan;
|
||||
|
||||
// Get pegawai atasan
|
||||
$pegawaiAtasan = Pegawai::where('nip', $nipAtasan)
|
||||
->orWhere('nip_siakad', $nipAtasan)
|
||||
->first();
|
||||
|
||||
if (! $pegawaiAtasan) {
|
||||
return redirect()->back()->with('error', 'Data pegawai atasan tidak ditemukan');
|
||||
}
|
||||
|
||||
// Build bawahan list
|
||||
$bawahans = [];
|
||||
if ($request->has('bawahan') && is_array($request->bawahan)) {
|
||||
foreach ($request->bawahan as $bawahan) {
|
||||
$exists = count($this->dawaiService->listPegawai($bawahan)['data']) > 0;
|
||||
|
||||
if (! $exists) {
|
||||
$pegawai = Pegawai::where('nip', $bawahan)
|
||||
->orWhere('nip_siakad', $bawahan)
|
||||
->first();
|
||||
|
||||
if ($pegawai && $pegawai->nip !== $pegawai->nip_siakad) {
|
||||
$bawahans[] = $this->dawaiService->listPegawai($pegawai->nip_siakad)['data'][0]['nip'];
|
||||
} else {
|
||||
$bawahans[] = $pegawai->nip;
|
||||
}
|
||||
} else {
|
||||
$bawahans[] = $bawahan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update bawahan - use pegawai atasan's NIP
|
||||
$result = $this->dawaiService->updateBawahan($pegawaiAtasan->nip, $bawahans);
|
||||
|
||||
if (! $result['success'] && $pegawaiAtasan->nip !== $pegawaiAtasan->nip_siakad) {
|
||||
$result = $this->dawaiService->updateBawahan($pegawaiAtasan->nip_siakad, $bawahans);
|
||||
}
|
||||
|
||||
if ($result['success']) {
|
||||
$message = $isAdmin
|
||||
? 'Berhasil mengubah daftar bawahan untuk '.$pegawaiAtasan->nama
|
||||
: 'Berhasil mengubah daftar bawahan';
|
||||
|
||||
// Return JSON for AJAX request
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['success' => true, 'message' => $message]);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', $message);
|
||||
}
|
||||
|
||||
$errorMessage = $result['message'] ?? 'Gagal mengubah daftar bawahan';
|
||||
|
||||
// Return JSON for AJAX request
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['success' => false, 'message' => $errorMessage], 400);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', $errorMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,642 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Verifikasi\TriDharma;
|
||||
|
||||
use App\Helpers\BeritaAcaraHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\DokSiremun\SubUnitKerja;
|
||||
use App\Models\DokSiremun\UnitKerja;
|
||||
use App\Models\Verifikator\Periode;
|
||||
use App\Models\Verifikator\Team;
|
||||
use App\Models\Verifikator\UnitKerjaPegawai;
|
||||
use App\Models\Verifikator\View\Pegawai;
|
||||
use App\Services\DokSiremunService;
|
||||
use App\Services\ImamAVService;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class MataKuliahController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected ImamAVService $imamAVService,
|
||||
protected DokSiremunService $dokSiremunService,
|
||||
) {}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$title = 'Mata Kuliah';
|
||||
|
||||
$team = Team::find(session('team_id'));
|
||||
|
||||
// Team dengan unit_kerja_id > 0 difilter otomatis ke unit kerja mereka
|
||||
$teamUnitKerjaId = ($team && $team->unit_kerja_id > 0) ? $team->unit_kerja_id : null;
|
||||
|
||||
// Cek periode verifikasi Tri Dharma
|
||||
$periode = Periode::where('status', true)->first();
|
||||
$canAddMataKuliah = true;
|
||||
$periodeMessage = null;
|
||||
|
||||
if ($periode && ! $periode->canVerifyTriDharma() && Auth::user()->id != 1) {
|
||||
$canAddMataKuliah = false;
|
||||
$periodeMessage = $periode->getTriDharmaVerificationErrorMessage();
|
||||
}
|
||||
|
||||
$beritaAcaraCheck = BeritaAcaraHelper::checkBeritaAcaraByTeam(session('team_id'));
|
||||
$beritaAcaraUploaded = $beritaAcaraCheck['uploaded'];
|
||||
$beritaAcaraMessage = $beritaAcaraCheck['message'];
|
||||
|
||||
return view('verifikasi.tri-dharma.mata-kuliah.index', compact('title', 'team', 'teamUnitKerjaId', 'canAddMataKuliah', 'periodeMessage', 'beritaAcaraUploaded', 'beritaAcaraMessage'));
|
||||
}
|
||||
|
||||
public function getDosenByFakultas(Request $request)
|
||||
{
|
||||
$team = Team::find(session('team_id'));
|
||||
$rawFakultasId = $request->input('fakultas_id');
|
||||
|
||||
$query = Pegawai::query()
|
||||
->where('jenis_pegawai', 'dosen');
|
||||
|
||||
if ($rawFakultasId) {
|
||||
$prodiIds = SubUnitKerja::where('id_unit_kerja', (string) $rawFakultasId)
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
|
||||
if (! empty($prodiIds)) {
|
||||
$query->whereIn('prodi_id', $prodiIds);
|
||||
}
|
||||
}
|
||||
|
||||
// Get all dosen (no pagination, no limit)
|
||||
$dosen = $query->select('nip', 'nama')
|
||||
->distinct()
|
||||
->orderBy('nama')
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'results' => $dosen->map(function ($item) {
|
||||
return [
|
||||
'id' => $item->nip,
|
||||
'text' => $item->nama.' ('.$item->nip.')',
|
||||
'nip' => $item->nip,
|
||||
'nama' => $item->nama,
|
||||
];
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFakultas()
|
||||
{
|
||||
$fakultas = UnitKerja::query()
|
||||
->where('kategori', 'Fakultas')
|
||||
->select('id', 'nama')
|
||||
->orderBy('nama')
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'results' => $fakultas->map(function ($item) {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'text' => $item->nama,
|
||||
];
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getUnitKerjaPegawaiList(): JsonResponse
|
||||
{
|
||||
$unitKerjas = UnitKerjaPegawai::orderBy('nama')->get(['id', 'nama']);
|
||||
|
||||
return response()->json([
|
||||
'results' => $unitKerjas->map(fn ($item) => ['id' => $item->id, 'text' => $item->nama]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getProdiByFakultas(Request $request)
|
||||
{
|
||||
$fakultasId = (string) $request->input('fakultas_id');
|
||||
$prodi = SubUnitKerja::query()
|
||||
->where('id_unit_kerja', $fakultasId)
|
||||
->select('id', 'nama')
|
||||
->orderBy('nama')
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'results' => $prodi->map(function ($item) {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'text' => $item->nama.' ('.$item->id.')',
|
||||
'id_prodi' => $item->id,
|
||||
'nama_prodi' => $item->nama,
|
||||
];
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
public function testToken()
|
||||
{
|
||||
$result = $this->imamAVService->testToken();
|
||||
|
||||
if (isset($result['error'])) {
|
||||
return response()->json($result, 500);
|
||||
}
|
||||
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$dummyData = [
|
||||
'nip' => '198609222014041002',
|
||||
// 'id_kelas' => '1258898',
|
||||
'kode_mata_kuliah' => 'TEST-001',
|
||||
'nama_mata_kuliah' => 'Test Mata Kuliah',
|
||||
'sks' => 3,
|
||||
'program' => 'S1',
|
||||
'jenjang' => 'S1',
|
||||
'jumlah_mahasiswa' => 30,
|
||||
'id_progdi' => '56201',
|
||||
'nama_progdi' => 'Test Program Studi',
|
||||
'nama_dosen' => 'Test Dosen',
|
||||
'jumlah_pertemuan_dosen' => 16,
|
||||
'total_pertemuan' => 16,
|
||||
];
|
||||
|
||||
$result = $this->imamAVService->testCreateRequest($dummyData);
|
||||
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
public function data(Request $request)
|
||||
{
|
||||
try {
|
||||
$result = $this->imamAVService->getListMataKuliah();
|
||||
|
||||
if (! $result['success']) {
|
||||
$errorMsg = $result['error'] ?? 'Failed to authenticate with API';
|
||||
|
||||
if (strpos($errorMsg, 'authenticate') !== false) {
|
||||
$errorMsg .= '. Possible reasons: Invalid credentials or Server IP ('.gethostbyname(gethostname()).') not whitelisted in Sevima API. ';
|
||||
$errorMsg .= 'Please check Laravel log for details.';
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => $errorMsg,
|
||||
'server_ip' => gethostbyname(gethostname()),
|
||||
], 401);
|
||||
}
|
||||
|
||||
$mataKuliah = $result['data'];
|
||||
|
||||
// Ensure we have an array to work with
|
||||
if (! is_array($mataKuliah)) {
|
||||
Log::error('Invalid data structure from API. Expected array, got: '.gettype($mataKuliah));
|
||||
|
||||
return response()->json(['error' => 'Invalid data structure from API'], 500);
|
||||
}
|
||||
|
||||
// Tentukan filter unit kerja: dari request atau auto dari team login
|
||||
$team = Team::find(session('team_id'));
|
||||
$filterUnitKerjaId = $request->input('unit_kerja_id');
|
||||
|
||||
if (! $filterUnitKerjaId && $team && $team->unit_kerja_id > 0) {
|
||||
$filterUnitKerjaId = $team->unit_kerja_id;
|
||||
}
|
||||
|
||||
// Group by dosen dan aggregate data
|
||||
$groupedData = [];
|
||||
foreach ($mataKuliah as $row) {
|
||||
$nip = is_array($row) ? ($row['NIP Dosen'] ?? '') : ($row->{'NIP Dosen'} ?? '');
|
||||
$namaDosen = is_array($row) ? ($row['Nama Dosen'] ?? '') : ($row->{'Nama Dosen'} ?? '');
|
||||
|
||||
if (! isset($groupedData[$nip])) {
|
||||
$groupedData[$nip] = [
|
||||
'nip' => $nip,
|
||||
'nama_dosen' => $namaDosen,
|
||||
'unit_kerja' => null,
|
||||
'unit_kerja_id' => null,
|
||||
'jumlah_matkul' => 0,
|
||||
'total_poin_remunerasi' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
$groupedData[$nip]['jumlah_matkul']++;
|
||||
$poinRemunerasi = is_array($row) ? ($row['Poin Remunerasi'] ?? 0) : ($row->{'Poin Remunerasi'} ?? 0);
|
||||
$groupedData[$nip]['total_poin_remunerasi'] += $poinRemunerasi;
|
||||
}
|
||||
|
||||
// Batch-load unit kerja dari database
|
||||
$pegawaiMap = Pegawai::with('unit')
|
||||
->whereIn('nip', array_keys($groupedData))
|
||||
->get()
|
||||
->keyBy('nip');
|
||||
|
||||
foreach ($groupedData as $nip => &$data) {
|
||||
$pegawai = $pegawaiMap->get($nip);
|
||||
$data['unit_kerja'] = $pegawai?->unit?->nama ?? '-';
|
||||
$data['unit_kerja_id'] = $pegawai?->unit_kerja_id;
|
||||
}
|
||||
unset($data);
|
||||
|
||||
// Filter berdasarkan unit kerja pegawai
|
||||
if ($filterUnitKerjaId) {
|
||||
$groupedData = array_filter($groupedData, fn ($row) => $row['unit_kerja_id'] == $filterUnitKerjaId);
|
||||
}
|
||||
|
||||
return DataTables::of(collect(array_values($groupedData)))
|
||||
->addIndexColumn()
|
||||
->addColumn('nip', function ($row) {
|
||||
return $row['nip'];
|
||||
})
|
||||
->addColumn('nama_dosen', function ($row) {
|
||||
return $row['nama_dosen'];
|
||||
})
|
||||
->addColumn('unit_kerja', function ($row) {
|
||||
return $row['unit_kerja'];
|
||||
})
|
||||
->addColumn('jumlah_matkul', function ($row) {
|
||||
return $row['jumlah_matkul'];
|
||||
})
|
||||
->addColumn('total_poin_remunerasi', function ($row) {
|
||||
return number_format($row['total_poin_remunerasi'], 2);
|
||||
})
|
||||
->addColumn('action', function ($row) {
|
||||
$nip = htmlspecialchars($row['nip']);
|
||||
$nama = htmlspecialchars($row['nama_dosen']);
|
||||
|
||||
return '
|
||||
<div class="dropdown">
|
||||
<span id="dropdownMenuButton" data-bs-toggle="dropdown" style="cursor: pointer;">
|
||||
<i class="uil-ellipsis-v"></i>
|
||||
</span>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a href="'.route('tri-dharma.mata-kuliah.detail', ['nip' => $nip]).'" class="dropdown-item">
|
||||
<i class="uil-eye" style="margin-right: 5px"></i> Detail Mata Kuliah
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
';
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
} catch (Exception $e) {
|
||||
Log::error('Sevima API Error: '.$e->getMessage());
|
||||
Log::error('Stack trace: '.$e->getTraceAsString());
|
||||
|
||||
return response()->json(['error' => 'Error: '.$e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function detail($nip)
|
||||
{
|
||||
$dosen = Pegawai::where('nip', $nip)->first();
|
||||
|
||||
if (! $dosen) {
|
||||
abort(404, 'Dosen tidak ditemukan');
|
||||
}
|
||||
|
||||
// Cek periode verifikasi Tri Dharma
|
||||
$periode = Periode::where('status', true)->first();
|
||||
if ($periode && ! $periode->canVerifyTriDharma() && Auth::user()->id != 1) {
|
||||
$errorMessage = $periode->getTriDharmaVerificationErrorMessage();
|
||||
|
||||
return redirect()->route('tri-dharma.mata-kuliah.index')
|
||||
->with('info', $errorMessage ?: 'Periode Verifikasi Tri Dharma telah Selesai.');
|
||||
}
|
||||
|
||||
$title = 'Detail Mata Kuliah - '.$dosen->nama;
|
||||
|
||||
$beritaAcaraCheck = BeritaAcaraHelper::checkBeritaAcaraByTeam(session('team_id'));
|
||||
$beritaAcaraUploaded = $beritaAcaraCheck['uploaded'];
|
||||
$beritaAcaraMessage = $beritaAcaraCheck['message'];
|
||||
|
||||
return view('verifikasi.tri-dharma.mata-kuliah.detail', compact('title', 'nip', 'dosen', 'beritaAcaraUploaded', 'beritaAcaraMessage'));
|
||||
}
|
||||
|
||||
public function dataDetail(Request $request, string $nip)
|
||||
{
|
||||
try {
|
||||
$result = $this->imamAVService->getListMataKuliah();
|
||||
|
||||
if (! $result['success']) {
|
||||
$errorMsg = $result['error'] ?? 'Failed to authenticate with API';
|
||||
|
||||
if (strpos($errorMsg, 'authenticate') !== false) {
|
||||
$errorMsg .= '. Possible reasons: Invalid credentials or Server IP ('.gethostbyname(gethostname()).') not whitelisted in Sevima API. ';
|
||||
$errorMsg .= 'Please check Laravel log for details.';
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => $errorMsg,
|
||||
'server_ip' => gethostbyname(gethostname()),
|
||||
], 401);
|
||||
}
|
||||
|
||||
$mataKuliah = $result['data'];
|
||||
|
||||
if (! is_array($mataKuliah)) {
|
||||
Log::error('Invalid data structure from API. Expected array, got: '.gettype($mataKuliah));
|
||||
|
||||
return response()->json(['error' => 'Invalid data structure from API'], 500);
|
||||
}
|
||||
|
||||
// Filter by NIP
|
||||
$mataKuliah = array_filter($mataKuliah, fn ($row) => (is_array($row) ? ($row['NIP Dosen'] ?? '') : ($row->{'NIP Dosen'} ?? '')) == $nip);
|
||||
|
||||
// Filter by Matkul Fakultas / Prodi jika ada
|
||||
$filterFakultasId = $request->input('fakultas_id');
|
||||
$filterProdiId = $request->input('prodi_id');
|
||||
|
||||
if ($filterProdiId) {
|
||||
$mataKuliah = array_filter($mataKuliah, fn ($row) => (is_array($row) ? ($row['ID Progdi'] ?? '') : ($row->{'ID Progdi'} ?? '')) == $filterProdiId);
|
||||
} elseif ($filterFakultasId) {
|
||||
$prodiInFakultas = SubUnitKerja::where('id_unit_kerja', $filterFakultasId)->pluck('id')->toArray();
|
||||
$mataKuliah = array_filter($mataKuliah, fn ($row) => in_array(
|
||||
is_array($row) ? ($row['ID Progdi'] ?? '') : ($row->{'ID Progdi'} ?? ''),
|
||||
$prodiInFakultas
|
||||
));
|
||||
}
|
||||
|
||||
// Pre-load fakultas map: id_progdi → nama_fakultas
|
||||
$prodiToFakultas = SubUnitKerja::query()
|
||||
->join('public.unit_kerjas', 'public.sub_unit_kerjas.id_unit_kerja', '=', 'public.unit_kerjas.id')
|
||||
->select('public.sub_unit_kerjas.id as prodi_id', 'public.unit_kerjas.nama as fakultas_nama')
|
||||
->get()
|
||||
->pluck('fakultas_nama', 'prodi_id');
|
||||
|
||||
return DataTables::of(collect($mataKuliah))
|
||||
->addIndexColumn()
|
||||
->addColumn('kode_matkul', function ($row) {
|
||||
return is_array($row) ? ($row['Kode Mata Kuliah'] ?? '-') : ($row->{'Kode Mata Kuliah'} ?? '-');
|
||||
})
|
||||
->addColumn('nama_matkul', function ($row) {
|
||||
return is_array($row) ? ($row['Nama Mata Kuliah'] ?? '-') : ($row->{'Nama Mata Kuliah'} ?? '-');
|
||||
})
|
||||
->addColumn('prodi', function ($row) {
|
||||
return is_array($row) ? ($row['Nama Progdi'] ?? '-') : ($row->{'Nama Progdi'} ?? '-');
|
||||
})
|
||||
->addColumn('fakultas', function ($row) use ($prodiToFakultas) {
|
||||
$idProgdi = is_array($row) ? ($row['ID Progdi'] ?? '') : ($row->{'ID Progdi'} ?? '');
|
||||
|
||||
return $prodiToFakultas->get($idProgdi, '-');
|
||||
})
|
||||
->addColumn('sks', function ($row) {
|
||||
return is_array($row) ? ($row['SKS'] ?? 0) : ($row->SKS ?? 0);
|
||||
})
|
||||
->addColumn('pertemuan', function ($row) {
|
||||
$jumlahPertemuan = is_array($row) ? ($row['Jumlah Pertemuan Dosen'] ?? 0) : ($row->{'Jumlah Pertemuan Dosen'} ?? 0);
|
||||
$totalPertemuan = is_array($row) ? ($row['Total Pertemuan'] ?? 0) : ($row->{'Total Pertemuan'} ?? 0);
|
||||
|
||||
return $jumlahPertemuan.' / '.$totalPertemuan;
|
||||
})
|
||||
->addColumn('poin_remunerasi', function ($row) {
|
||||
return is_array($row) ? number_format($row['Poin Remunerasi'] ?? 0, 2) : number_format($row->{'Poin Remunerasi'} ?? 0, 2);
|
||||
})
|
||||
->addColumn('action', function ($row) use ($prodiToFakultas) {
|
||||
$kode = is_array($row) ? ($row['Kode Mata Kuliah'] ?? '') : ($row->{'Kode Mata Kuliah'} ?? '');
|
||||
$nama = is_array($row) ? ($row['Nama Mata Kuliah'] ?? '') : ($row->{'Nama Mata Kuliah'} ?? '');
|
||||
$idKelas = is_array($row) ? ($row['ID Kelas'] ?? '') : ($row->{'ID Kelas'} ?? '');
|
||||
$nip = is_array($row) ? ($row['NIP Dosen'] ?? '') : ($row->{'NIP Dosen'} ?? '');
|
||||
$idProgdi = is_array($row) ? ($row['ID Progdi'] ?? '') : ($row->{'ID Progdi'} ?? '');
|
||||
|
||||
$rowWithFakultas = is_array($row) ? $row : (array) $row;
|
||||
$rowWithFakultas['Nama Fakultas'] = $prodiToFakultas->get($idProgdi, '-');
|
||||
|
||||
return '
|
||||
<div class="dropdown">
|
||||
<span id="dropdownMenuButton" data-bs-toggle="dropdown" style="cursor: pointer;">
|
||||
<i class="uil-ellipsis-v"></i>
|
||||
</span>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a href="javascript:void(0);" class="dropdown-item detail-btn" data-row="'.htmlspecialchars(json_encode($rowWithFakultas)).'">
|
||||
<i class="uil-eye" style="margin-right: 5px"></i> Detail
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript:void(0);" class="dropdown-item delete-btn"
|
||||
data-id-kelas="'.htmlspecialchars($idKelas).'"
|
||||
data-nip="'.htmlspecialchars($nip).'"
|
||||
data-kode="'.htmlspecialchars($kode).'"
|
||||
data-nama="'.htmlspecialchars($nama).'">
|
||||
<i class="uil-trash-alt" style="margin-right: 5px"></i> Hapus
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
';
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
} catch (Exception $e) {
|
||||
Log::error('Sevima API Error: '.$e->getMessage());
|
||||
Log::error('Stack trace: '.$e->getTraceAsString());
|
||||
|
||||
return response()->json(['error' => 'Error: '.$e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
// Cek periode verifikasi Tri Dharma terlebih dahulu
|
||||
$user = Auth::user();
|
||||
if ($user->id !== 1) {
|
||||
$periode = Periode::where('status', true)->first();
|
||||
if (! $periode) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Periode aktif tidak ditemukan',
|
||||
], 404);
|
||||
}
|
||||
|
||||
if (! $periode->canVerifyTriDharma()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $periode->getTriDharmaVerificationErrorMessage(),
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'nip' => 'required|string',
|
||||
// 'id_kelas' => 'required|string', --- AUTO GENERATE ---
|
||||
'kode_mata_kuliah' => 'required|string',
|
||||
'nama_mata_kuliah' => 'required|string',
|
||||
'sks' => 'required|integer',
|
||||
'program' => 'required|string',
|
||||
'jenjang' => 'required|string',
|
||||
'jumlah_mahasiswa' => 'required|integer',
|
||||
'id_progdi' => 'required|string',
|
||||
'nama_progdi' => 'required|string',
|
||||
'nama_dosen' => 'required|string',
|
||||
'jumlah_pertemuan_dosen' => 'required|integer',
|
||||
'total_pertemuan' => 'required|integer',
|
||||
]);
|
||||
|
||||
try {
|
||||
$data = [
|
||||
'nip' => $request->nip,
|
||||
'id_kelas' => $this->imamAVService->generateIdKelas(),
|
||||
'kode_mata_kuliah' => $request->kode_mata_kuliah,
|
||||
'nama_mata_kuliah' => $request->nama_mata_kuliah,
|
||||
'sks' => (int) $request->sks,
|
||||
'program' => $request->program,
|
||||
'jenjang' => $request->jenjang,
|
||||
'jumlah_mahasiswa' => (int) $request->jumlah_mahasiswa,
|
||||
'id_progdi' => $request->id_progdi,
|
||||
'nama_progdi' => $request->nama_progdi,
|
||||
'nama_dosen' => $request->nama_dosen,
|
||||
'jumlah_pertemuan_dosen' => (int) $request->jumlah_pertemuan_dosen,
|
||||
'total_pertemuan' => (int) $request->total_pertemuan,
|
||||
];
|
||||
|
||||
$result = $this->imamAVService->createMataKuliah($data);
|
||||
|
||||
if ($result['success']) {
|
||||
$periode = Periode::where('status', true)->first();
|
||||
if ($periode) {
|
||||
$this->dokSiremunService->syncMengajar($request->nip, $periode->id_periode);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => $result['message'],
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $result['message'],
|
||||
], 400);
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menambahkan mata kuliah: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request): JsonResponse
|
||||
{
|
||||
$user = Auth::user();
|
||||
if ($user->id !== 1) {
|
||||
$periode = Periode::where('status', true)->first();
|
||||
if (! $periode) {
|
||||
return response()->json(['success' => false, 'message' => 'Periode aktif tidak ditemukan'], 404);
|
||||
}
|
||||
if (! $periode->canVerifyTriDharma()) {
|
||||
return response()->json(['success' => false, 'message' => $periode->getTriDharmaVerificationErrorMessage()], 422);
|
||||
}
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'id_kelas' => 'required|string',
|
||||
'nip' => 'required|string',
|
||||
'kode_mata_kuliah' => 'required|string',
|
||||
'nama_mata_kuliah' => 'required|string',
|
||||
'sks' => 'required|integer',
|
||||
'program' => 'required|string',
|
||||
'jenjang' => 'required|string',
|
||||
'jumlah_mahasiswa' => 'required|integer',
|
||||
'id_progdi' => 'required|string',
|
||||
'nama_progdi' => 'required|string',
|
||||
'nama_dosen' => 'required|string',
|
||||
'jumlah_pertemuan_dosen' => 'required|integer',
|
||||
'total_pertemuan' => 'required|integer',
|
||||
]);
|
||||
|
||||
try {
|
||||
$data = [
|
||||
'id_kelas' => $request->id_kelas,
|
||||
'nip' => $request->nip,
|
||||
'kode_mata_kuliah' => $request->kode_mata_kuliah,
|
||||
'nama_mata_kuliah' => $request->nama_mata_kuliah,
|
||||
'sks' => (int) $request->sks,
|
||||
'program' => $request->program,
|
||||
'jenjang' => $request->jenjang,
|
||||
'jumlah_mahasiswa' => (int) $request->jumlah_mahasiswa,
|
||||
'id_progdi' => $request->id_progdi,
|
||||
'nama_progdi' => $request->nama_progdi,
|
||||
'nama_dosen' => $request->nama_dosen,
|
||||
'jumlah_pertemuan_dosen' => (int) $request->jumlah_pertemuan_dosen,
|
||||
'total_pertemuan' => (int) $request->total_pertemuan,
|
||||
];
|
||||
|
||||
$result = $this->imamAVService->updateMataKuliah($data);
|
||||
|
||||
if ($result['success']) {
|
||||
$periode = Periode::where('status', true)->first();
|
||||
if ($periode) {
|
||||
$this->dokSiremunService->syncMengajar($request->nip, $periode->id_periode);
|
||||
}
|
||||
|
||||
return response()->json(['success' => true, 'message' => $result['message']]);
|
||||
}
|
||||
|
||||
return response()->json(['success' => false, 'message' => $result['message']], 400);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['success' => false, 'message' => 'Gagal memperbarui mata kuliah: '.$e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
// Cek periode verifikasi Tri Dharma terlebih dahulu
|
||||
$user = Auth::user();
|
||||
if ($user->id !== 1) {
|
||||
$periode = Periode::where('status', true)->first();
|
||||
if (! $periode) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Periode aktif tidak ditemukan',
|
||||
], 404);
|
||||
}
|
||||
|
||||
if (! $periode->canVerifyTriDharma()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $periode->getTriDharmaVerificationErrorMessage(),
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'id_kelas' => 'required|string',
|
||||
'nip' => 'required|string',
|
||||
]);
|
||||
|
||||
$idKelas = $request->input('id_kelas');
|
||||
$nip = $request->input('nip');
|
||||
|
||||
try {
|
||||
$result = $this->imamAVService->deleteMataKuliah($idKelas, $nip);
|
||||
|
||||
if ($result['success']) {
|
||||
$periode = Periode::where('status', true)->first();
|
||||
if ($periode) {
|
||||
$this->dokSiremunService->syncMengajar($nip, $periode->id_periode);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => $result['message'],
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $result['message'],
|
||||
], 400);
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menghapus mata kuliah: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user