first commit
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Pengajuan\TriDharma;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\DokSiremun\Syarat;
|
||||
use App\Models\Verifikator\View\Pegawai;
|
||||
use App\Services\KegiatanService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class ModulController extends Controller
|
||||
{
|
||||
function store(Request $request)
|
||||
{
|
||||
$start = Carbon::parse('2024-05-20 00:00:00');
|
||||
$end = Carbon::parse('2024-06-15 23:59:59');
|
||||
if (!now()->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user