isBetween($start, $end)) { return response()->json([ 'code' => 400, 'status' => 'failed', 'message' => 'Pengajuan Sudah Ditutup', ], 400); } try { $pegawai = Pegawai::where('nip', $request->nip)->orWhere('nip_siakad', $request->nip)->firstOrFail(); $kegiatanService = new KegiatanService(); $countUpdated = 0; if (gettype($request->id) === 'array') { foreach ($request->id as $id) { $syarat = Syarat::with('rubrik')->select('id_kegiatan', 'id_kategori', 'id_rubrik', 'status_verifikasi_id')->find($id); if (!$syarat) continue; if ($syarat->rubrik->syarats->where('nama', 'laporan kegiatan')->count() > 0) continue; if ($syarat->status_verifikasi_id == 2 && $syarat->rubrik->syarats->where('nama', 'laporan kegiatan')->count() === 0) { Log::info('Pengajuan Ulang:' . $id); continue; }; if ($syarat->status_verifikasi_id !== 1 && in_array($syarat->id_kategori, [1, 2, 3, 5, 6])) continue; try { $kegiatanService->pengajuan($id, $request->method()); $countUpdated++; } catch (Throwable $th) { continue; } } } else { $syarat = Syarat::select('id_rubrik', 'status_verifikasi_id')->find($request->id); if ($syarat->status_verifikasi_id == 1) { $kegiatanService->pengajuan($request->id, $request->method()); $countUpdated++; } } return response()->json([ 'status' => 'success', 'code' => 200, 'message' => "Berhasil mengajukan $countUpdated kegiatan", ], 200); } catch (Throwable $th) { DB::rollBack(); Log::error("Lainnya: " . $th->getMessage()); Log::error("Lainnya: " . $request->nip); if ($th instanceof ModelNotFoundException) { return response()->json([ 'code' => 404, 'status' => 'failed', 'message' => 'Kegiatan tidak ditemukan', ], 404); } if ($th instanceof AuthorizationException) { throw new AuthorizationException(); } if ($th instanceof DecryptException) { throw new AuthorizationException(); } return response()->json([ 'code' => 500, 'status' => 'failed', 'message' => 'Server Error', ], 500); } } }