first commit
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits\TriDharma;
|
||||
|
||||
use App\Models\DokSiremun\Syarat;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
trait ModulPembelajaranTrait
|
||||
{
|
||||
function modul(string $nip, int $periode, int $status = 1, int $upperLimit = 9)
|
||||
{
|
||||
$moduls = Syarat::with('kegiatan', 'dokumens')
|
||||
->select('syarats.id', 'id_kegiatan', 'syarats.uraian_kegiatan as uraian', 'poin_total', 'status_verifikasi_id', 'id_kegiatan')
|
||||
->selectRaw("'ModulPembelajaran' as type, 'ModulPembelajaran' as category")
|
||||
->with('kegiatan', 'dokumens', 'statusVerifikasi')
|
||||
->whereHas('kegiatan', function ($query) use ($periode) {
|
||||
$query->where('id_periode', $periode);
|
||||
})
|
||||
->where('id_rubrik', 657)
|
||||
->where('id_pelaksana', $nip)
|
||||
->where('status_verifikasi_id', '>', $status)
|
||||
->where('status_verifikasi_id', '<', $upperLimit)
|
||||
->get();
|
||||
|
||||
foreach ($moduls as &$modul) {
|
||||
$modul->nama_kegiatan = $modul->kegiatan->nama_kegiatan;
|
||||
}
|
||||
|
||||
return $moduls;
|
||||
}
|
||||
|
||||
function verifikasiModulPembelajaran(int $id_kegiatan, int $status_verifikasi_id, string $method, string $message, string $catatan)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$pengajuans = Syarat::where('id_kegiatan', $id_kegiatan)->where('id_rubrik', 657)->get();
|
||||
|
||||
foreach ($pengajuans as $pengajuan) {
|
||||
$pengajuan->update([
|
||||
'status_verifikasi_id' => $status_verifikasi_id,
|
||||
]);
|
||||
|
||||
$pengajuan->logs()->create([
|
||||
'user_id' => Auth::user()->id,
|
||||
'method' => $method,
|
||||
'employee_id' => Auth::user()->nip,
|
||||
'employee_name' => Auth::user()->name,
|
||||
'employee_role' => 'Verifikator',
|
||||
'message' => $message,
|
||||
]);
|
||||
|
||||
if ($catatan != null) {
|
||||
$pengajuan->notes()->create([
|
||||
'type' => 'catatan',
|
||||
'user_id' => Auth::user()->id,
|
||||
'employee_id' => Auth::user()->nip,
|
||||
'employee_name' => Auth::user()->name,
|
||||
'employee_role' => 'Verifikator',
|
||||
'message' => $catatan,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return [
|
||||
'code' => 201,
|
||||
'status' => 'success',
|
||||
'message' => 'Berhasil melakukan verifikasi pengajuan',
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
Log::error($th->getMessage());
|
||||
Log::info($id_kegiatan);
|
||||
Log::info('modul pembelajaran');
|
||||
DB::rollBack();
|
||||
return [
|
||||
'code' => 500,
|
||||
'status' => 'error',
|
||||
'message' => 'Gagal melakukan verifikasi pengajuan',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user