Penghapusan menu Pengajuan Aktivitas yg sudah tidak terpakai
This commit is contained in:
@@ -6,17 +6,25 @@ use App\Exports\PaguExport;
|
||||
use App\Helpers\JabatanPegawaiTambahanHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Verifikator\Pagu;
|
||||
use App\Models\Verifikator\PaguRiwayat;
|
||||
use App\Models\Verifikator\Rekapitulasi;
|
||||
use App\Models\Verifikator\UnitKerja;
|
||||
use App\Services\PaguMutasiService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\View\View;
|
||||
use InvalidArgumentException;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class PaguController extends Controller
|
||||
{
|
||||
public function __construct(private PaguMutasiService $mutasiService)
|
||||
{
|
||||
}
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
if ($faculty = JabatanPegawaiTambahanHelper::getPimpinanFakultasInfo(auth()->user()->nip)) {
|
||||
@@ -33,8 +41,9 @@ class PaguController extends Controller
|
||||
$paguSemester1 = (float) ($pagu->pagu_smt1 ?? 0);
|
||||
$paguSemester2 = (float) ($pagu->pagu_smt2 ?? 0);
|
||||
$totalPagu = $paguSemester1 + $paguSemester2;
|
||||
$riwayats = $pagu ? $pagu->riwayats()->orderByDesc('id')->get() : collect();
|
||||
|
||||
return view('perhitungan.pagu.fakultas', compact('title', 'faculty', 'facultyName', 'year', 'periodes', 'pagu', 'paguSemester1', 'paguSemester2', 'totalPagu'));
|
||||
return view('perhitungan.pagu.fakultas', compact('title', 'faculty', 'facultyName', 'year', 'periodes', 'pagu', 'paguSemester1', 'paguSemester2', 'totalPagu', 'riwayats'));
|
||||
}
|
||||
|
||||
abort_if(! auth()->user()->canAny(['Baca Pagu', 'Tambah Pagu', 'Ubah Pagu', 'Hapus Pagu']), 403);
|
||||
@@ -173,9 +182,27 @@ class PaguController extends Controller
|
||||
|
||||
return 'Rp '.number_format($sisaPagu, 0, ',', '.');
|
||||
})
|
||||
->addColumn('action', function ($row) use ($canUbah, $canHapus) {
|
||||
->addColumn('action', function ($row) use ($canUbah, $canHapus, $showQuestionMark) {
|
||||
$items = '';
|
||||
|
||||
if (! $showQuestionMark) {
|
||||
$items .= '
|
||||
<li>
|
||||
<a href="javascript:void(0);" class="dropdown-item riwayat-btn" data-id="'.$row->id.'">
|
||||
<i class="uil-history" style="margin-right: 5px"></i> Riwayat Saldo
|
||||
</a>
|
||||
</li>';
|
||||
}
|
||||
|
||||
if ($canUbah) {
|
||||
$items .= '
|
||||
<li>
|
||||
<a href="javascript:void(0);" class="dropdown-item mutasi-btn" data-id="'.$row->id.'">
|
||||
<i class="uil-exchange" style="margin-right: 5px"></i> Tambah / Kurangi Saldo
|
||||
</a>
|
||||
</li>';
|
||||
}
|
||||
|
||||
if ($canUbah) {
|
||||
$items .= '
|
||||
<li>
|
||||
@@ -300,11 +327,108 @@ class PaguController extends Controller
|
||||
'pagu_smt2.required' => 'Pagu Semester 2 wajib diisi.',
|
||||
]);
|
||||
|
||||
$record->update($request->only(['unit_pembayaran_id', 'tahun', 'pagu', 'pagu_smt1', 'pagu_smt2']));
|
||||
$sebelum = [1 => (float) $record->pagu_smt1, 2 => (float) $record->pagu_smt2];
|
||||
|
||||
DB::transaction(function () use ($request, $record, $sebelum) {
|
||||
$record->update($request->only(['unit_pembayaran_id', 'tahun', 'pagu', 'pagu_smt1', 'pagu_smt2']));
|
||||
|
||||
foreach ([1, 2] as $semester) {
|
||||
$this->mutasiService->catatSelisih($record, $semester, $sebelum[$semester], (float) $record->{'pagu_smt'.$semester}, 'Perubahan melalui Edit Pagu');
|
||||
}
|
||||
});
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Data pagu berhasil diperbarui.']);
|
||||
}
|
||||
|
||||
public function mutasi(Request $request, string $pagu): JsonResponse
|
||||
{
|
||||
abort_if(! auth()->user()->can('Ubah Pagu'), 403);
|
||||
|
||||
$record = Pagu::findOrFail($pagu);
|
||||
|
||||
$request->validate([
|
||||
'semester' => 'required|integer|in:1,2',
|
||||
'jenis' => 'required|in:'.PaguRiwayat::JENIS_PENAMBAHAN.','.PaguRiwayat::JENIS_PENGURANGAN,
|
||||
'jumlah' => 'required|numeric|gt:0',
|
||||
'keterangan' => 'nullable|string|max:255',
|
||||
], [
|
||||
'semester.required' => 'Semester wajib dipilih.',
|
||||
'semester.in' => 'Semester tidak valid.',
|
||||
'jenis.required' => 'Jenis mutasi wajib dipilih.',
|
||||
'jenis.in' => 'Jenis mutasi tidak valid.',
|
||||
'jumlah.required' => 'Jumlah wajib diisi.',
|
||||
'jumlah.numeric' => 'Jumlah harus berupa angka.',
|
||||
'jumlah.gt' => 'Jumlah harus lebih dari 0.',
|
||||
]);
|
||||
|
||||
try {
|
||||
$riwayat = $this->mutasiService->catat(
|
||||
$record,
|
||||
(int) $request->semester,
|
||||
$request->jenis,
|
||||
(float) $request->jumlah,
|
||||
$request->keterangan
|
||||
);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
return response()->json(['success' => false, 'message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
$label = $riwayat->jenis === PaguRiwayat::JENIS_PENAMBAHAN ? 'ditambahkan' : 'dikurangi';
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Saldo pagu semester '.$riwayat->semester.' berhasil '.$label.'.']);
|
||||
}
|
||||
|
||||
public function riwayat(Request $request, string $pagu): JsonResponse
|
||||
{
|
||||
abort_if(! auth()->user()->can('Baca Pagu'), 403);
|
||||
|
||||
$record = Pagu::findOrFail($pagu);
|
||||
if ($faculty = JabatanPegawaiTambahanHelper::getPimpinanFakultasInfo(auth()->user()->nip)) {
|
||||
abort_unless((int) $record->unit_pembayaran_id === (int) $faculty->unit_kerja_id, 403);
|
||||
}
|
||||
abort_if($this->isPaguMasked(), 403);
|
||||
|
||||
$request->validate(['semester' => 'nullable|integer|in:1,2']);
|
||||
|
||||
$rows = $record->riwayats()
|
||||
->when($request->filled('semester'), fn ($q) => $q->where('semester', $request->semester))
|
||||
->orderByDesc('id')
|
||||
->get()
|
||||
->map(fn (PaguRiwayat $r) => [
|
||||
'tanggal' => $r->created_at?->format('d/m/Y H:i'),
|
||||
'semester' => $r->semester,
|
||||
'jenis' => $r->jenis,
|
||||
'jumlah' => $r->jumlah,
|
||||
'saldo_sebelum' => $r->saldo_sebelum,
|
||||
'saldo_sesudah' => $r->saldo_sesudah,
|
||||
'keterangan' => $r->keterangan,
|
||||
'oleh' => $r->created_by_nama,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'unit_kerja' => $record->unitKerja?->nama,
|
||||
'tahun' => $record->tahun,
|
||||
'pagu_smt1' => (float) $record->pagu_smt1,
|
||||
'pagu_smt2' => (float) $record->pagu_smt2,
|
||||
'data' => $rows,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pengguna hanya-baca dengan akses unit fakultas tertentu tidak boleh melihat nominal pagu.
|
||||
*/
|
||||
private function isPaguMasked(): bool
|
||||
{
|
||||
if (auth()->user()->canAny(['Tambah Pagu', 'Ubah Pagu', 'Hapus Pagu'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$activeTeam = auth()->user()->teams()->wherePivot('active', 1)->first() ?? auth()->user()->teams()->first();
|
||||
$pivotIds = $activeTeam ? $activeTeam->teamUnitKerjas()->pluck('unit_kerja_id')->toArray() : [];
|
||||
|
||||
return ! empty($pivotIds) && ! in_array(null, $pivotIds, true);
|
||||
}
|
||||
|
||||
public function destroy(string $id): JsonResponse
|
||||
{
|
||||
abort_if(! auth()->user()->can('Hapus Pagu'), 403);
|
||||
|
||||
Reference in New Issue
Block a user