165 lines
7.0 KiB
PHP
165 lines
7.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Perhitungan\Remunerasi;
|
|
|
|
use App\Exports\P2Export;
|
|
use App\Helpers\JabatanPegawaiTambahanHelper;
|
|
use App\Helpers\JenjangPendidikanHelper;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Perhitungan\PlenoPenunjang\RasioP2Controller;
|
|
use App\Models\Verifikator\Periode;
|
|
use App\Models\Verifikator\Team;
|
|
use App\Models\Verifikator\UnitKerja;
|
|
use App\Models\Verifikator\View\Pegawai;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
use Yajra\DataTables\Facades\DataTables;
|
|
|
|
class P2Controller extends Controller
|
|
{
|
|
private function authorizeAccess(): void
|
|
{
|
|
$team = Team::find(session('team_id'));
|
|
$isAdmin = $team && $team->nama === 'Admin';
|
|
|
|
$userNip = auth()->user()->nip;
|
|
$isWakilDekan = JabatanPegawaiTambahanHelper::isWakilDekan($userNip);
|
|
$isDekan = JabatanPegawaiTambahanHelper::isDekan($userNip);
|
|
|
|
abort_unless($isAdmin || $isWakilDekan || $isDekan || $userNip == '198706242010121005', 403);
|
|
}
|
|
|
|
public function index(): View
|
|
{
|
|
$this->authorizeAccess();
|
|
|
|
$title = 'P2';
|
|
$team = Team::find(session('team_id'));
|
|
$periodes = Periode::orderBy('id_periode', 'desc')->get();
|
|
$periodeNow = Periode::where('status', true)->first()?->id_periode;
|
|
$jenjangPendidikanList = JenjangPendidikanHelper::options();
|
|
|
|
return view('perhitungan.remunerasi.p2.index', compact('title', 'team', 'periodes', 'periodeNow', 'jenjangPendidikanList'));
|
|
}
|
|
|
|
public function data(Request $request): JsonResponse
|
|
{
|
|
$this->authorizeAccess();
|
|
|
|
$team = Team::find(session('team_id'));
|
|
|
|
if (! $team) {
|
|
return DataTables::of(collect([]))->make();
|
|
}
|
|
|
|
[$unitKerjaId, $jenisPegawai, $periode, $jenjangPendidikan] = $this->resolveFilters($request, $team);
|
|
|
|
$query = $this->buildQuery($periode, $unitKerjaId, $jenisPegawai, $jenjangPendidikan);
|
|
|
|
return DataTables::of($query)
|
|
->editColumn('nip', fn ($row) => ltrim($row->nip ?? '', "'"))
|
|
->editColumn('jenis_pegawai', fn ($row) => $row->jenis_pegawai === 'dosen' ? 'Dosen' : ($row->jenis_pegawai === 'tendik' ? 'Tendik' : '-'))
|
|
->editColumn('total_p2_bruto', fn ($row) => 'Rp. '.number_format($row->total_p2_bruto ?? 0, 2, ',', '.'))
|
|
->editColumn('total_p2_pajak', fn ($row) => 'Rp. '.number_format($row->total_p2_pajak ?? 0, 2, ',', '.'))
|
|
->editColumn('total_p2_netto', fn ($row) => 'Rp. '.number_format($row->total_p2_netto ?? 0, 2, ',', '.'))
|
|
->filterColumn('nip', fn ($query, $keyword) => $query->where('verifikator.pegawais.nip', 'ILIKE', "%{$keyword}%"))
|
|
->filterColumn('nama', fn ($query, $keyword) => $query->where('verifikator.pegawais.nama', 'ILIKE', "%{$keyword}%"))
|
|
->filterColumn('nama_unit', fn ($query, $keyword) => $query->where('ukp.nama', 'ILIKE', "%{$keyword}%"))
|
|
->make();
|
|
}
|
|
|
|
public function export(Request $request): BinaryFileResponse
|
|
{
|
|
$this->authorizeAccess();
|
|
|
|
$team = Team::find(session('team_id'));
|
|
|
|
[$unitKerjaId, $jenisPegawai, $periode, $jenjangPendidikan] = $this->resolveFilters($request, $team);
|
|
|
|
$periodeNama = Periode::where('id_periode', $periode)->first()?->nama ?? $periode;
|
|
$unitNama = $unitKerjaId !== null && $unitKerjaId !== '' ? (UnitKerja::find($unitKerjaId)?->nama ?? 'Semua Unit') : 'Semua Unit';
|
|
$jenisPegawaiNama = $jenisPegawai ? '_'.ucfirst($jenisPegawai) : '';
|
|
|
|
$filename = 'P2_'.str_replace(['/', ' ', '.'], '_', $periodeNama)
|
|
.'_'.str_replace(['/', ' ', '.'], '_', $unitNama)
|
|
.$jenisPegawaiNama.'.xlsx';
|
|
|
|
return Excel::download(new P2Export($periode, $unitKerjaId, $jenisPegawai, $jenjangPendidikan), $filename);
|
|
}
|
|
|
|
public function detail(Request $request, string $nip): View
|
|
{
|
|
$this->authorizeAccess();
|
|
|
|
$request->merge(['gabung' => '1']);
|
|
|
|
return app(RasioP2Controller::class)->detailNew($request, $nip);
|
|
}
|
|
|
|
public function exportPoin(Request $request, string $nip)
|
|
{
|
|
$this->authorizeAccess();
|
|
|
|
$request->merge(['gabung' => '1']);
|
|
|
|
return app(RasioP2Controller::class)->exportPoin($request, $nip);
|
|
}
|
|
|
|
private function resolveFilters(Request $request, ?Team $team): array
|
|
{
|
|
if (! $team || ! isset($team->unit_kerja_id) || $team->unit_kerja_id === null || $team->unit_kerja_id === 0) {
|
|
$unitKerjaId = $request->unit_kerja_id ?: null;
|
|
} else {
|
|
$unitKerjaId = $team->unit_kerja_id;
|
|
}
|
|
|
|
$periodeNow = Periode::where('status', true)->first()?->id_periode;
|
|
$periode = $request->periode ?? $periodeNow;
|
|
$jenisPegawai = $request->jenis_pegawai ?: null;
|
|
$jenjangPendidikan = $request->jenjang_pendidikan ?: null;
|
|
|
|
return [$unitKerjaId, $jenisPegawai, $periode, $jenjangPendidikan];
|
|
}
|
|
|
|
private function buildQuery(mixed $periode, mixed $unitKerjaId, ?string $jenisPegawai, ?string $jenjangPendidikan = null)
|
|
{
|
|
$fakultasIds = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
|
|
$query = Pegawai::withoutGlobalScopes()
|
|
->join('verifikator.jabatan_pegawais as jp', 'verifikator.pegawais.nip', '=', 'jp.nip')
|
|
->join('verifikator.jabatan_pegawai_details as jpd', 'jp.id', '=', 'jpd.jabatan_pegawai_id')
|
|
->join('verifikator.remunerasi_per_bulans as rpb', 'jpd.id', '=', 'rpb.jabatan_pegawai_detail_id')
|
|
->leftJoin('verifikator.unit_kerja_pegawais as ukp', 'verifikator.pegawais.unit_kerja_id', '=', 'ukp.id')
|
|
->select(['verifikator.pegawais.nip', 'verifikator.pegawais.nama'])
|
|
->selectRaw('MAX(ukp.nama) as nama_unit')
|
|
->selectRaw('MAX(jpd.jenis_pegawai) as jenis_pegawai')
|
|
->selectRaw('MAX(verifikator.pegawais.pendidikan_terakhir) as jenjang_pendidikan')
|
|
->selectRaw('SUM(rpb.p2_bruto) as total_p2_bruto')
|
|
->selectRaw('SUM(rpb.p2_bruto) - SUM(rpb.p2_netto) as total_p2_pajak')
|
|
->selectRaw('SUM(rpb.p2_netto) as total_p2_netto')
|
|
->whereNull('rpb.deleted_at')
|
|
->where('jp.periode', $periode)
|
|
->groupBy('verifikator.pegawais.nip', 'verifikator.pegawais.nama')
|
|
->havingRaw('SUM(rpb.p2_bruto) > 0');
|
|
|
|
if ($unitKerjaId == 99) {
|
|
$query->whereNotIn('verifikator.pegawais.unit_kerja_id', $fakultasIds);
|
|
} elseif ($unitKerjaId !== null && $unitKerjaId !== '') {
|
|
$query->where('verifikator.pegawais.unit_kerja_id', $unitKerjaId);
|
|
}
|
|
|
|
if ($jenisPegawai !== null && $jenisPegawai !== '') {
|
|
$query->where('jpd.jenis_pegawai', $jenisPegawai);
|
|
}
|
|
|
|
if ($jenjangPendidikan !== null && $jenjangPendidikan !== '') {
|
|
JenjangPendidikanHelper::applyQueryFilter($query, 'verifikator.pegawais.pendidikan_terakhir', $jenjangPendidikan);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
}
|