Penambahan Fitur Export Total Simulasi Jabatan dan Perubahan Login
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
/**
|
||||
* Rekap Excel "Total" untuk menu Simulasi Jabatan: satu baris per pegawai
|
||||
* (atau per unit pembayaran bila mode pecah aktif) berisi Total P2 (2022),
|
||||
* P2 (2023), dan P2 (Excel), ditutup satu baris TOTAL keseluruhan.
|
||||
*
|
||||
* Nilai sudah dihitung di controller (dari dataset yang sama dengan tabel &
|
||||
* kartu ringkasan) dan diterima di sini sebagai angka mentah.
|
||||
*
|
||||
* @param Collection<int, array{nama_pegawai:string, nip:string, jenis_pegawai:string, unit_kerja:string, unit_pembayaran?:string, p2_2022:float, p2_2023:float, p2_excel:float, keterangan:string}> $items
|
||||
*/
|
||||
class SimulasiJabatanTotalExport implements FromCollection, WithHeadings, WithStyles, ShouldAutoSize, WithColumnFormatting, WithTitle
|
||||
{
|
||||
private const RUPIAH_FORMAT = '_([$Rp-421]* #,##0.00_);_([$Rp-421]* (#,##0.00);_([$Rp-421]* "-"??_);_(@_)';
|
||||
|
||||
public function __construct(private readonly Collection $items, private readonly bool $splitUnit = false) {}
|
||||
|
||||
public function collection(): Collection
|
||||
{
|
||||
$rows = $this->items->map(fn ($r) => array_values($r));
|
||||
|
||||
$total = collect(['p2_2022', 'p2_2023', 'p2_excel'])
|
||||
->mapWithKeys(fn ($key) => [$key => $this->items->sum(fn ($r) => (float) ($r[$key] ?? 0))]);
|
||||
|
||||
// Kolom teks sebelum angka: Nama, NIP, Jenis Pegawai, Unit Kerja (+ Unit Pembayaran).
|
||||
$lead = array_fill(0, $this->splitUnit ? 5 : 4, '');
|
||||
$lead[0] = 'TOTAL';
|
||||
|
||||
return $rows->push(array_merge($lead, [$total['p2_2022'], $total['p2_2023'], $total['p2_excel'], '']));
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
$head = ['Nama Pegawai', 'NIP', 'Jenis Pegawai', 'Unit Kerja'];
|
||||
if ($this->splitUnit) {
|
||||
$head[] = 'Unit Pembayaran';
|
||||
}
|
||||
|
||||
return array_merge($head, ['Total P2 (2022)', 'Total P2 (2023)', 'Total P2 (Excel)', 'Keterangan']);
|
||||
}
|
||||
|
||||
public function columnFormats(): array
|
||||
{
|
||||
$cols = $this->splitUnit ? ['F', 'G', 'H'] : ['E', 'F', 'G'];
|
||||
|
||||
return array_fill_keys($cols, self::RUPIAH_FORMAT);
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return 'Total P2';
|
||||
}
|
||||
|
||||
public function styles(Worksheet $sheet): array
|
||||
{
|
||||
return [
|
||||
1 => ['font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF']], 'fill' => ['fillType' => Fill::FILL_SOLID, 'startColor' => ['rgb' => '20C997']]],
|
||||
$sheet->getHighestRow() => ['font' => ['bold' => true]],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,13 @@ class LoginController extends Controller
|
||||
return redirect('dashboard');
|
||||
}
|
||||
|
||||
if (config('app.login_mode') === 2) {
|
||||
return view('auth.login-sso');
|
||||
return view('auth.login-sso');
|
||||
}
|
||||
|
||||
function ariyutta()
|
||||
{
|
||||
if (Auth::check()) {
|
||||
return redirect('dashboard');
|
||||
}
|
||||
|
||||
return view('auth.login');
|
||||
|
||||
@@ -14,6 +14,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Exports\SimulasiJabatanExport;
|
||||
use App\Exports\SimulasiJabatanTotalExport;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class SimulasiJabatanController extends Controller
|
||||
@@ -316,6 +317,57 @@ class SimulasiJabatanController extends Controller
|
||||
return Excel::download(new SimulasiJabatanExport($periode, null, $jenis, $unitKerjaId, $grade12), 'simulasi-jabatan-'.$periode.$suffix.'.xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Rekap Excel "Total": ringkas — satu baris per pegawai (atau per unit
|
||||
* pembayaran bila mode pecah aktif) berisi Total P2 (2022), P2 (2023),
|
||||
* P2 (Excel), plus satu baris TOTAL keseluruhan. Sumber angka sama dengan
|
||||
* tabel & kartu ringkasan (dataset ter-cache), menghormati filter periode,
|
||||
* unit kerja, jenis pegawai, simulasi +12 poin grade, dan unit pembayaran.
|
||||
*/
|
||||
public function exportTotal(Request $request)
|
||||
{
|
||||
@set_time_limit(300);
|
||||
@ini_set('max_execution_time', '300');
|
||||
|
||||
$periode = (int) ($request->input('periode') ?: optional(Periode::where('status', true)->first())->id_periode);
|
||||
$splitUnit = $request->boolean('split_unit');
|
||||
$grade12 = $request->boolean('grade12');
|
||||
$unitKerjaId = $request->input('unit_kerja_id') ?: null;
|
||||
|
||||
$key = $grade12 ? '_g12' : '';
|
||||
$parse = fn ($value) => (float) str_replace(',', '.', str_replace('.', '', (string) $value));
|
||||
|
||||
$rows = $this->applyUnitJenisFilter($this->dataset($periode, $splitUnit), $request)
|
||||
->values()
|
||||
->map(function ($row) use ($parse, $key, $splitUnit) {
|
||||
$out = [
|
||||
'nama_pegawai' => $row['nama_pegawai'],
|
||||
'nip' => "'".$row['nip'],
|
||||
'jenis_pegawai' => strtoupper((string) $row['jenis_pegawai']),
|
||||
'unit_kerja' => $row['unit_kerja'] ?: 'Tanpa Unit Kerja',
|
||||
];
|
||||
if ($splitUnit) {
|
||||
$out['unit_pembayaran'] = $row['unit_pembayaran'] ?: '-';
|
||||
}
|
||||
$out['p2_2022'] = $parse($row['p2_total_374'.$key]);
|
||||
$out['p2_2023'] = $parse($row['p2_total_377'.$key]);
|
||||
$out['p2_excel'] = $parse($row['p2_total_excel'.$key]);
|
||||
// Poin P2 baru terbentuk bila Total Poin melewati ambang 12
|
||||
// (rumus P2 memakai ...-12). Bila di bawah itu, atau ketiga versi
|
||||
// P2 nol, tandai supaya mudah difilter di Excel.
|
||||
$out['keterangan'] = ($parse($row['total_poin']) < 12
|
||||
|| ($out['p2_2022'] == 0.0 && $out['p2_2023'] == 0.0 && $out['p2_excel'] == 0.0))
|
||||
? 'Poin P2 tidak mencukupi 12 Poin'
|
||||
: '';
|
||||
|
||||
return $out;
|
||||
});
|
||||
|
||||
$suffix = ($unitKerjaId ? '-unit'.$unitKerjaId : '').($grade12 ? '-grade12' : '').($splitUnit ? '-unit-pembayaran' : '');
|
||||
|
||||
return Excel::download(new SimulasiJabatanTotalExport($rows, $splitUnit), 'simulasi-jabatan-total-'.$periode.$suffix.'.xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Rincian modal mengikuti aturan menu Remunerasi > P2: seluruh Poin P2 dikali
|
||||
* SATU harga jabatan — tendik: JTT bila ada & harga 377-nya > 0 (selain itu
|
||||
|
||||
Reference in New Issue
Block a user