72 lines
2.5 KiB
PHP
72 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Verifikator\JabatanPegawai;
|
|
use App\Models\Verifikator\JabatanPegawaiDetail;
|
|
use App\Models\Verifikator\Periode;
|
|
use App\Models\Verifikator\View\Pegawai;
|
|
use Illuminate\Http\Request;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ProfilController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$title = 'Profil';
|
|
$user = Auth::user();
|
|
|
|
// Ambil data pegawai berdasarkan NIP user
|
|
$pegawai = Pegawai::where('nip', $user->nip)->first();
|
|
|
|
if (!$pegawai) {
|
|
return redirect()->route('dashboard.index')->with('error', 'Data pegawai tidak ditemukan');
|
|
}
|
|
|
|
// Ambil periode yang sedang aktif
|
|
$periodeAktif = Periode::where('status', true)->orderBy('id_periode', 'DESC')->first();
|
|
|
|
// Ambil semua jabatan pegawai untuk periode berjalan
|
|
$jabatans = collect([]);
|
|
if ($periodeAktif) {
|
|
$jabatans = JabatanPegawai::where('nip', $user->nip)
|
|
->where('periode', $periodeAktif->id_periode)
|
|
->where('active', true)
|
|
->orderBy('version', 'DESC')
|
|
->with(['detail' => function($query) {
|
|
$query->with(['fungsional', 'tambahan', 'poin'])
|
|
->orderBy('bulan', 'DESC');
|
|
}])
|
|
->get();
|
|
}
|
|
|
|
// Ambil detail jabatan 6 bulan terakhir
|
|
$detailJabatan6Bulan = collect([]);
|
|
if ($periodeAktif) {
|
|
// Ambil semua jabatan pegawai ID untuk periode aktif
|
|
$jabatanIds = JabatanPegawai::where('nip', $user->nip)
|
|
->where('periode', $periodeAktif->id_periode)
|
|
->where('active', true)
|
|
->pluck('id');
|
|
|
|
if ($jabatanIds->isNotEmpty()) {
|
|
// Ambil detail 6 bulan terakhir
|
|
$detailJabatan6Bulan = JabatanPegawaiDetail::whereIn('jabatan_pegawai_id', $jabatanIds)
|
|
->with(['fungsional', 'tambahan', 'poin', 'jabatan', 'pangkat'])
|
|
->orderBy('bulan', 'DESC')
|
|
->take(6)
|
|
->get();
|
|
}
|
|
}
|
|
|
|
// Ambil status pegawai dari bulan terakhir
|
|
$statusPegawaiBulanTerakhir = null;
|
|
if ($detailJabatan6Bulan->isNotEmpty()) {
|
|
$statusPegawaiBulanTerakhir = $detailJabatan6Bulan->first()->status_pns;
|
|
}
|
|
|
|
return view('profil.index', compact('title', 'pegawai', 'jabatans', 'periodeAktif', 'detailJabatan6Bulan', 'statusPegawaiBulanTerakhir'));
|
|
}
|
|
}
|