525 lines
21 KiB
PHP
525 lines
21 KiB
PHP
<?php
|
|
|
|
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\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)) {
|
|
$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;
|
|
$riwayats = $pagu ? $pagu->riwayats()->orderByDesc('id')->get() : collect();
|
|
|
|
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);
|
|
|
|
$title = 'Pagu';
|
|
$currentYear = (int) date('Y');
|
|
$periodes = Pagu::select('tahun')->distinct()->orderBy('tahun', 'desc')->pluck('tahun');
|
|
if (! $periodes->contains($currentYear)) {
|
|
$periodes->prepend($currentYear);
|
|
}
|
|
$hasBacaPagu = auth()->user()->can('Baca Pagu');
|
|
$canTambah = auth()->user()->can('Tambah Pagu');
|
|
$canUbah = auth()->user()->can('Ubah Pagu');
|
|
$canHapus = auth()->user()->can('Hapus Pagu');
|
|
$canKelola = auth()->user()->canAny(['Tambah Pagu', 'Ubah Pagu', 'Hapus Pagu']);
|
|
|
|
$activeTeam = auth()->user()->teams()->wherePivot('active', 1)->first();
|
|
if (! $activeTeam) {
|
|
$activeTeam = auth()->user()->teams()->first();
|
|
}
|
|
|
|
$pivotIds = $activeTeam ? $activeTeam->teamUnitKerjas()->pluck('unit_kerja_id')->toArray() : [];
|
|
|
|
if (empty($pivotIds) || in_array(null, $pivotIds, true)) {
|
|
$unitKerjas = UnitKerja::orderBy('id')->get();
|
|
} else {
|
|
$dbUnits = UnitKerja::whereIn('id', array_filter($pivotIds, fn ($id) => $id > 0))->orderBy('id')->get()->keyBy('id');
|
|
$unitKerjas = collect($pivotIds)->map(function ($id) use ($dbUnits) {
|
|
if ($id === 0) {
|
|
return (object) ['id' => 0, 'nama' => 'Universitas'];
|
|
}
|
|
|
|
return $dbUnits->get($id);
|
|
})->filter()->sortBy('id')->values();
|
|
}
|
|
|
|
$showQuestionMark = false;
|
|
$hideJumlahCards = false;
|
|
if ($hasBacaPagu && ! $canKelola) {
|
|
if (! empty($pivotIds) && ! in_array(null, $pivotIds, true)) {
|
|
$showQuestionMark = true;
|
|
$hideJumlahCards = true;
|
|
}
|
|
}
|
|
|
|
return view('perhitungan.pagu.index', compact(
|
|
'title',
|
|
'periodes',
|
|
'unitKerjas',
|
|
'hasBacaPagu',
|
|
'canTambah',
|
|
'canUbah',
|
|
'canHapus',
|
|
'showQuestionMark',
|
|
'hideJumlahCards'
|
|
));
|
|
}
|
|
|
|
public function getData(Request $request): JsonResponse
|
|
{
|
|
abort_if(! auth()->user()->can('Baca Pagu'), 403);
|
|
|
|
$canUbah = auth()->user()->can('Ubah Pagu');
|
|
$canHapus = auth()->user()->can('Hapus Pagu');
|
|
$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();
|
|
if (! $activeTeam) {
|
|
$activeTeam = auth()->user()->teams()->first();
|
|
}
|
|
|
|
$pivotIds = $activeTeam ? $activeTeam->teamUnitKerjas()->pluck('unit_kerja_id')->toArray() : [];
|
|
if (! empty($pivotIds) && ! in_array(null, $pivotIds, true)) {
|
|
$this->applyPaguUnitKerjaFilter($query, $pivotIds);
|
|
if (! $canKelola) {
|
|
$showQuestionMark = true;
|
|
}
|
|
}
|
|
|
|
if ($request->filled('periode')) {
|
|
$query->where('tahun', $request->periode);
|
|
}
|
|
|
|
$query = $query->orderBy('unit_pembayaran_id', 'asc');
|
|
|
|
return DataTables::of($query)
|
|
->addColumn('unit_kerja_nama', function ($row) {
|
|
return $row->unitKerja ? $row->unitKerja->nama : 'Unit Kerja Tidak Ditemukan';
|
|
})
|
|
->addColumn('jumlah_terpakai', function ($row) use ($showQuestionMark) {
|
|
if ($showQuestionMark) {
|
|
return '?';
|
|
}
|
|
|
|
$rekapitulasi = Rekapitulasi::where('tahun', $row->tahun)
|
|
->where('unit_kerja_nama', $row->unitKerja->nama ?? '')
|
|
->first();
|
|
|
|
if ($rekapitulasi) {
|
|
$totalTerpakai = ($rekapitulasi->total_p1 ?? 0) +
|
|
($rekapitulasi->total_p2 ?? 0) +
|
|
($rekapitulasi->total_thr ?? 0) +
|
|
($rekapitulasi->total_r13 ?? 0) +
|
|
($rekapitulasi->total_publikasi ?? 0);
|
|
|
|
return 'Rp '.number_format($totalTerpakai, 0, ',', '.');
|
|
}
|
|
|
|
return 'Rp 0';
|
|
})
|
|
->addColumn('jumlah_sisa_pagu', function ($row) use ($showQuestionMark) {
|
|
if ($showQuestionMark) {
|
|
return 'Rp '.number_format($row->pagu_smt2 ?? 0, 0, ',', '.');
|
|
}
|
|
|
|
$rekapitulasi = Rekapitulasi::where('tahun', $row->tahun)
|
|
->where('unit_kerja_nama', $row->unitKerja->nama ?? '')
|
|
->first();
|
|
|
|
$totalTerpakai = 0;
|
|
if ($rekapitulasi) {
|
|
$totalTerpakai = ($rekapitulasi->total_p1 ?? 0) +
|
|
($rekapitulasi->total_p2 ?? 0) +
|
|
($rekapitulasi->total_thr ?? 0) +
|
|
($rekapitulasi->total_r13 ?? 0) +
|
|
($rekapitulasi->total_publikasi ?? 0);
|
|
}
|
|
|
|
$sisaPagu = $row->pagu - $totalTerpakai;
|
|
|
|
return 'Rp '.number_format($sisaPagu, 0, ',', '.');
|
|
})
|
|
->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>
|
|
<a href="javascript:void(0);" class="dropdown-item edit-btn" data-id="'.$row->id.'">
|
|
<i class="uil-edit" style="margin-right: 5px"></i> Edit
|
|
</a>
|
|
</li>';
|
|
}
|
|
|
|
if ($canHapus) {
|
|
$items .= '
|
|
<li>
|
|
<a href="javascript:void(0);" class="dropdown-item delete-btn text-danger" data-id="'.$row->id.'">
|
|
<i class="uil-trash-alt" style="margin-right: 5px"></i> Hapus
|
|
</a>
|
|
</li>';
|
|
}
|
|
|
|
if (! $items) {
|
|
return '-';
|
|
}
|
|
|
|
return '
|
|
<div class="dropdown">
|
|
<span id="dropdownMenuButton" data-bs-toggle="dropdown">
|
|
<i class="uil-ellipsis-v"></i>
|
|
</span>
|
|
<ul class="dropdown-menu">
|
|
'.$items.'
|
|
</ul>
|
|
</div>
|
|
';
|
|
})
|
|
->editColumn('pagu', function ($row) use ($showQuestionMark) {
|
|
if ($showQuestionMark) {
|
|
return '?';
|
|
}
|
|
|
|
return 'Rp. '.number_format($row->pagu, 0, ',', '.');
|
|
})
|
|
->editColumn('pagu_smt1', function ($row) use ($showQuestionMark) {
|
|
if ($showQuestionMark) {
|
|
return '?';
|
|
}
|
|
|
|
return 'Rp. '.number_format($row->pagu_smt1 ?? 0, 0, ',', '.');
|
|
})
|
|
->editColumn('pagu_smt2', function ($row) {
|
|
return 'Rp. '.number_format($row->pagu_smt2 ?? 0, 0, ',', '.');
|
|
})
|
|
->rawColumns(['action'])
|
|
->make(true);
|
|
}
|
|
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
abort_if(! auth()->user()->can('Tambah Pagu'), 403);
|
|
|
|
$request->validate([
|
|
'unit_pembayaran_id' => 'required|integer|exists:verifikator.unit_kerjas,id',
|
|
'tahun' => 'required|integer|digits:4|unique:verifikator.pagus,tahun,NULL,id,unit_pembayaran_id,'.$request->unit_pembayaran_id,
|
|
'pagu' => 'required|numeric|min:0',
|
|
'pagu_smt1' => 'required|numeric|min:0',
|
|
'pagu_smt2' => 'required|numeric|min:0',
|
|
], [
|
|
'unit_pembayaran_id.required' => 'Unit Kerja wajib dipilih.',
|
|
'unit_pembayaran_id.exists' => 'Unit Kerja tidak valid.',
|
|
'tahun.required' => 'Tahun wajib diisi.',
|
|
'tahun.digits' => 'Tahun harus terdiri dari 4 digit.',
|
|
'tahun.unique' => 'Data pagu untuk Unit Kerja dan tahun ini sudah ada.',
|
|
'pagu.required' => 'Jumlah pagu wajib diisi.',
|
|
'pagu.numeric' => 'Jumlah pagu harus berupa angka.',
|
|
'pagu_smt1.required' => 'Pagu Semester 1 wajib diisi.',
|
|
'pagu_smt2.required' => 'Pagu Semester 2 wajib diisi.',
|
|
]);
|
|
|
|
Pagu::create($request->only(['unit_pembayaran_id', 'tahun', 'pagu', 'pagu_smt1', 'pagu_smt2']));
|
|
|
|
return response()->json(['success' => true, 'message' => 'Data pagu berhasil ditambahkan.']);
|
|
}
|
|
|
|
public function show(string $id): JsonResponse
|
|
{
|
|
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,
|
|
'unit_pembayaran_id' => $pagu->unit_pembayaran_id,
|
|
'tahun' => $pagu->tahun,
|
|
'pagu' => $pagu->pagu,
|
|
'pagu_smt1' => $pagu->pagu_smt1,
|
|
'pagu_smt2' => $pagu->pagu_smt2,
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request, string $pagu): JsonResponse
|
|
{
|
|
abort_if(! auth()->user()->can('Ubah Pagu'), 403);
|
|
|
|
$record = Pagu::findOrFail($pagu);
|
|
|
|
$request->validate([
|
|
'unit_pembayaran_id' => 'required|integer|exists:verifikator.unit_kerjas,id',
|
|
'tahun' => 'required|integer|digits:4|unique:verifikator.pagus,tahun,'.$pagu.',id,unit_pembayaran_id,'.$request->unit_pembayaran_id,
|
|
'pagu' => 'required|numeric|min:0',
|
|
'pagu_smt1' => 'required|numeric|min:0',
|
|
'pagu_smt2' => 'required|numeric|min:0',
|
|
], [
|
|
'unit_pembayaran_id.required' => 'Unit Kerja wajib dipilih.',
|
|
'unit_pembayaran_id.exists' => 'Unit Kerja tidak valid.',
|
|
'tahun.required' => 'Tahun wajib diisi.',
|
|
'tahun.digits' => 'Tahun harus terdiri dari 4 digit.',
|
|
'tahun.unique' => 'Data pagu untuk Unit Kerja dan tahun ini sudah ada.',
|
|
'pagu.required' => 'Jumlah pagu wajib diisi.',
|
|
'pagu.numeric' => 'Jumlah pagu harus berupa angka.',
|
|
'pagu_smt1.required' => 'Pagu Semester 1 wajib diisi.',
|
|
'pagu_smt2.required' => 'Pagu Semester 2 wajib diisi.',
|
|
]);
|
|
|
|
$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);
|
|
|
|
$pagu = Pagu::findOrFail($id);
|
|
$pagu->delete();
|
|
|
|
return response()->json(['success' => true, 'message' => 'Data pagu berhasil dihapus.']);
|
|
}
|
|
|
|
public function getSummary(Request $request): JsonResponse
|
|
{
|
|
abort_if(! auth()->user()->can('Baca Pagu'), 403);
|
|
|
|
$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();
|
|
if (! $activeTeam) {
|
|
$activeTeam = auth()->user()->teams()->first();
|
|
}
|
|
|
|
$pivotIds = $activeTeam ? $activeTeam->teamUnitKerjas()->pluck('unit_kerja_id')->toArray() : [];
|
|
if (! empty($pivotIds) && ! in_array(null, $pivotIds, true)) {
|
|
$this->applyPaguUnitKerjaFilter($query, $pivotIds);
|
|
if (! $canKelola) {
|
|
$isUnitKerja1to9 = true;
|
|
}
|
|
}
|
|
|
|
if ($request->filled('periode')) {
|
|
$query->where('tahun', $request->periode);
|
|
}
|
|
|
|
$pagus = $query->get();
|
|
|
|
$totalPaguSmt1 = (float) $pagus->sum('pagu_smt1');
|
|
$totalPaguSmt2 = (float) $pagus->sum('pagu_smt2');
|
|
$totalPagu = $totalPaguSmt1 + $totalPaguSmt2;
|
|
$totalTerpakai = 0;
|
|
|
|
foreach ($pagus as $pagu) {
|
|
$rekapitulasi = Rekapitulasi::where('tahun', $pagu->tahun)
|
|
->where('unit_kerja_nama', $pagu->unitKerja->nama ?? '')
|
|
->first();
|
|
|
|
if ($rekapitulasi) {
|
|
$totalTerpakai += ($rekapitulasi->total_p1 ?? 0) +
|
|
($rekapitulasi->total_p2 ?? 0) +
|
|
($rekapitulasi->total_thr ?? 0) +
|
|
($rekapitulasi->total_r13 ?? 0) +
|
|
($rekapitulasi->total_publikasi ?? 0);
|
|
}
|
|
}
|
|
|
|
return response()->json([
|
|
'total_pagu' => $totalPagu,
|
|
'total_pagu_smt1' => $totalPaguSmt1,
|
|
'total_pagu_smt2' => $totalPaguSmt2,
|
|
'total_terpakai' => $totalTerpakai,
|
|
'sisa_pagu' => $totalPagu - $totalTerpakai,
|
|
]);
|
|
}
|
|
|
|
private function applyPaguUnitKerjaFilter($query, array $pivotIds): void
|
|
{
|
|
$hasUniversitas = in_array(0, $pivotIds, true);
|
|
$facultyIds = array_values(array_filter($pivotIds, fn ($id) => $id > 0));
|
|
|
|
$query->where(function ($q) use ($hasUniversitas, $facultyIds) {
|
|
if ($hasUniversitas) {
|
|
$q->orWhereNotIn('unit_pembayaran_id', range(1, 9));
|
|
}
|
|
if (! empty($facultyIds)) {
|
|
$q->orWhereIn('unit_pembayaran_id', $facultyIds);
|
|
}
|
|
});
|
|
}
|
|
|
|
public function export(Request $request): BinaryFileResponse
|
|
{
|
|
abort_if(! auth()->user()->can('Baca Pagu'), 403);
|
|
|
|
$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, JabatanPegawaiTambahanHelper::getPimpinanFakultasInfo(auth()->user()->nip)?->unit_kerja_id), $filename);
|
|
}
|
|
}
|