first commit
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user