Penambahan Menu Pagu Fakultas

This commit is contained in:
Ariyutta
2026-10-21 08:41:10 +07:00
parent 62c55f3f0f
commit 452dc4269d
6 changed files with 113 additions and 6 deletions
+4 -1
View File
@@ -17,7 +17,7 @@ class PaguExport implements FromCollection, WithHeadings, WithMapping, WithColum
{
protected $periode;
public function __construct($periode = null)
public function __construct($periode = null, protected ?int $facultyId = null)
{
$this->periode = $periode;
}
@@ -30,6 +30,9 @@ class PaguExport implements FromCollection, WithHeadings, WithMapping, WithColum
public function collection()
{
$query = Pagu::with('unitKerja');
if ($this->facultyId !== null) {
$query->where('unit_pembayaran_id', $this->facultyId);
}
if ($this->periode) {
$query->where('tahun', $this->periode);
@@ -2,6 +2,7 @@
namespace App\Helpers;
use App\Models\Sidia\Pegawai as SidiaPegawai;
use App\Models\Verifikator\Dosen;
use App\Models\Verifikator\View\Pegawai;
use Illuminate\Support\Collection;
@@ -37,6 +38,26 @@ class JabatanPegawaiTambahanHelper
*/
const WAKIL_DEKAN_2_IDS = [7];
public static function getPimpinanFakultasInfo(?string $nip): ?object
{
if (! $nip) {
return null;
}
$pegawai = SidiaPegawai::where(function ($query) use ($nip) {
$query->where('nip', $nip)->orWhere('nip_siakad', $nip)->orWhere('nip_honorer', $nip);
})
->whereIn('jabatan_tugas_tambahan_id', array_merge(self::DEKAN_IDS, self::WAKIL_DEKAN_IDS))
->whereBetween('unit_kerja_id', [1, 9])->first();
return $pegawai ? (object) [
'nip' => $pegawai->nip,
'unit_kerja_id' => $pegawai->unit_kerja_id,
'unit_kerja_nama' => $pegawai->nama_unit_kerja,
'jabatan_dtt_nama' => $pegawai->nama_jabatan_tugas_tambahan,
] : null;
}
public static function isDekan(string $nip): bool
{
if (Dosen::where('nip', $nip)->whereIn('jabatan_dtt_id', self::DEKAN_IDS)->exists()) {
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Perhitungan;
use App\Exports\PaguExport;
use App\Helpers\JabatanPegawaiTambahanHelper;
use App\Http\Controllers\Controller;
use App\Models\Verifikator\Pagu;
use App\Models\Verifikator\Rekapitulasi;
@@ -16,8 +17,26 @@ use Yajra\DataTables\Facades\DataTables;
class PaguController extends Controller
{
public function index(): View
public function index(Request $request): View
{
if ($faculty = JabatanPegawaiTambahanHelper::getPimpinanFakultasInfo(auth()->user()->nip)) {
$request->validate(['periode' => 'nullable|integer|digits:4']);
$title = 'Pagu Fakultas';
$year = (int) $request->input('periode', date('Y'));
$periodes = Pagu::where('unit_pembayaran_id', $faculty->unit_kerja_id)
->distinct()->orderByDesc('tahun')->pluck('tahun');
if (! $periodes->contains((int) date('Y'))) {
$periodes->prepend((int) date('Y'));
}
$facultyName = UnitKerja::find($faculty->unit_kerja_id)?->nama ?? $faculty->unit_kerja_nama;
$pagu = Pagu::where('unit_pembayaran_id', $faculty->unit_kerja_id)->where('tahun', $year)->first();
$paguSemester1 = (float) ($pagu->pagu_smt1 ?? 0);
$paguSemester2 = (float) ($pagu->pagu_smt2 ?? 0);
$totalPagu = $paguSemester1 + $paguSemester2;
return view('perhitungan.pagu.fakultas', compact('title', 'faculty', 'facultyName', 'year', 'periodes', 'pagu', 'paguSemester1', 'paguSemester2', 'totalPagu'));
}
abort_if(! auth()->user()->canAny(['Baca Pagu', 'Tambah Pagu', 'Ubah Pagu', 'Hapus Pagu']), 403);
$title = 'Pagu';
@@ -83,6 +102,9 @@ class PaguController extends Controller
$canKelola = auth()->user()->canAny(['Tambah Pagu', 'Ubah Pagu', 'Hapus Pagu']);
$query = Pagu::with('unitKerja');
if ($faculty = JabatanPegawaiTambahanHelper::getPimpinanFakultasInfo(auth()->user()->nip)) {
$query->where('unit_pembayaran_id', $faculty->unit_kerja_id);
}
$showQuestionMark = false;
$activeTeam = auth()->user()->teams()->wherePivot('active', 1)->first();
@@ -240,6 +262,9 @@ class PaguController extends Controller
abort_if(! auth()->user()->can('Baca Pagu'), 403);
$pagu = Pagu::findOrFail($id);
if ($faculty = JabatanPegawaiTambahanHelper::getPimpinanFakultasInfo(auth()->user()->nip)) {
abort_unless((int) $pagu->unit_pembayaran_id === (int) $faculty->unit_kerja_id, 403);
}
return response()->json([
'id' => $pagu->id,
@@ -296,6 +321,9 @@ class PaguController extends Controller
$canKelola = auth()->user()->canAny(['Tambah Pagu', 'Ubah Pagu', 'Hapus Pagu']);
$query = Pagu::with('unitKerja');
if ($faculty = JabatanPegawaiTambahanHelper::getPimpinanFakultasInfo(auth()->user()->nip)) {
$query->where('unit_pembayaran_id', $faculty->unit_kerja_id);
}
$isUnitKerja1to9 = false;
$activeTeam = auth()->user()->teams()->wherePivot('active', 1)->first();
@@ -367,6 +395,6 @@ class PaguController extends Controller
$periode = $request->get('periode');
$filename = 'Data_Pagu_'.($periode ? $periode : 'Semua_Periode').'_'.date('Y-m-d_H-i-s').'.xlsx';
return Excel::download(new PaguExport($periode), $filename);
return Excel::download(new PaguExport($periode, JabatanPegawaiTambahanHelper::getPimpinanFakultasInfo(auth()->user()->nip)?->unit_kerja_id), $filename);
}
}