first commit
This commit is contained in:
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Perhitungan\Remunerasi;
|
||||
|
||||
use App\Exports\ThrExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Verifikator\Team;
|
||||
use App\Models\Verifikator\UnitKerja;
|
||||
use App\Services\DawaiService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class THRController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$title = 'THR';
|
||||
$team = Team::find(session('team_id'));
|
||||
|
||||
if ($team->unit_kerja_id === null || $team->unit_kerja_id === 0) {
|
||||
$units = UnitKerja::get();
|
||||
|
||||
return view('perhitungan.remunerasi.thr.index', compact('units', 'team', 'title'));
|
||||
}
|
||||
|
||||
return view('perhitungan.remunerasi.thr.index', compact('team', 'title'));
|
||||
}
|
||||
|
||||
public function data(Request $request)
|
||||
{
|
||||
$tahunNow = Carbon::now()->format('Y');
|
||||
$team = Team::find(session('team_id'));
|
||||
|
||||
if ($team->unit_kerja_id === null || $team->unit_kerja_id === 0) {
|
||||
$unit = $request->unit;
|
||||
} else {
|
||||
$unit = $team->unit_kerja_id;
|
||||
}
|
||||
|
||||
$jenisPegawai = $request->jenis_pegawai ?? '';
|
||||
$tahun = $request->tahun ?? $tahunNow;
|
||||
|
||||
// Create cache key based on parameters
|
||||
$cacheKey = "thr_data_{$jenisPegawai}_{$tahun}_{$unit}";
|
||||
|
||||
// Get data from cache or fetch from API
|
||||
$data = Cache::remember($cacheKey, now()->addDay(), function () use ($jenisPegawai, $tahun, $unit) {
|
||||
$dawaiService = new DawaiService;
|
||||
|
||||
return $dawaiService->getDataThr($jenisPegawai, $tahun, $unit, false);
|
||||
});
|
||||
|
||||
// Filter data yang total_thr nya tidak nol
|
||||
$filteredData = collect($data)->filter(function ($item) {
|
||||
return ($item['total_thr'] ?? 0) > 0;
|
||||
})->sortBy('nama')->values();
|
||||
|
||||
return DataTables::of($filteredData)
|
||||
->addIndexColumn()
|
||||
->editColumn('nip', function ($row) {
|
||||
return ltrim($row['nip'] ?? '', "'");
|
||||
})
|
||||
->editColumn('jenis_pegawai', function ($row) {
|
||||
return $row['jenis_pegawai'] == 'dosen' ? 'Dosen' : ($row['jenis_pegawai'] == 'tendik' ? 'Tendik' : '-');
|
||||
})
|
||||
->addColumn('total_thr_formatted', function ($row) {
|
||||
return 'Rp. '.number_format($row['total_thr'] ?? 0, 2, ',', '.');
|
||||
})
|
||||
->addColumn('total_pajak_thr_formatted', function ($row) {
|
||||
return 'Rp. '.number_format($row['total_pajak_thr'] ?? 0, 2, ',', '.');
|
||||
})
|
||||
->addColumn('total_thr_setelah_pajak_formatted', function ($row) {
|
||||
return 'Rp. '.number_format($row['total_thr_setelah_pajak'] ?? 0, 2, ',', '.');
|
||||
})
|
||||
->addColumn('detail', function ($row) {
|
||||
return json_encode([
|
||||
'golongan' => $row['golongan'] ?? '-',
|
||||
'status_pegawai' => $row['status_pegawai'] ?? '-',
|
||||
'poin_p2' => $row['poin_p2'] ?? '-',
|
||||
'faktor' => $row['faktor'] ?? '-',
|
||||
'jabatan_fungsional' => $row['jabatan_fungsional'] ?? '-',
|
||||
'jabatan_tugas_tambahan' => $row['jabatan_tugas_tambahan'] ?? '-',
|
||||
'thr_p1' => $row['thr_p1'] ?? [],
|
||||
'thr_p2' => $row['thr_p2'] ?? [],
|
||||
'steps' => $row['steps'] ?? [],
|
||||
]);
|
||||
})
|
||||
->rawColumns(['detail'])
|
||||
->make();
|
||||
}
|
||||
|
||||
public function dataSelisih(Request $request)
|
||||
{
|
||||
$tahunNow = Carbon::now()->format('Y');
|
||||
$team = Team::find(session('team_id'));
|
||||
|
||||
if ($team->unit_kerja_id === null) {
|
||||
$unit = $request->unit;
|
||||
} else {
|
||||
$unit = $team->unit_kerja_id;
|
||||
}
|
||||
|
||||
$jenisPegawai = $request->jenis_pegawai ?? '';
|
||||
$tahun = $request->tahun ?? $tahunNow;
|
||||
|
||||
// Create cache key for selisih data
|
||||
$cacheKey = "thr_selisih_data_{$jenisPegawai}_{$tahun}_{$unit}";
|
||||
|
||||
// Get data from cache or fetch from API
|
||||
$data = Cache::remember($cacheKey, now()->addDay(), function () use ($jenisPegawai, $tahun, $unit) {
|
||||
$dawaiService = new DawaiService;
|
||||
|
||||
return $dawaiService->getDataThr($jenisPegawai, $tahun, $unit, true);
|
||||
});
|
||||
|
||||
// Filter data yang total_thr nya tidak nol
|
||||
$filteredData = collect($data)->filter(function ($item) {
|
||||
return ($item['total_thr'] ?? 0) > 0;
|
||||
})->sortBy('nama')->values();
|
||||
|
||||
return DataTables::of($filteredData)
|
||||
->addIndexColumn()
|
||||
->addColumn('nip', function ($row) {
|
||||
return ltrim($row['nip'] ?? '', "'");
|
||||
})
|
||||
->addColumn('nama', function ($row) {
|
||||
return $row['nama'] ?? '';
|
||||
})
|
||||
->addColumn('nama_unit', function ($row) {
|
||||
return $row['nama_unit'] ?? '';
|
||||
})
|
||||
->editColumn('jenis_pegawai', function ($row) {
|
||||
return $row['jenis_pegawai'] == 'dosen' ? 'Dosen' : ($row['jenis_pegawai'] == 'tendik' ? 'Tendik' : '-');
|
||||
})
|
||||
->addColumn('selisih_thr_formatted', function ($row) {
|
||||
$value = $row['selisih_total_thr'] ?? 0;
|
||||
|
||||
return 'Rp. '.number_format($value, 2, ',', '.');
|
||||
})
|
||||
->addColumn('selisih_pajak_formatted', function ($row) {
|
||||
$totalThr = $row['selisih_total_thr'] ?? 0;
|
||||
$totalThrSetelahPajak = $row['selisih_total_thr_setelah_pajak'] ?? 0;
|
||||
$value = $totalThr - $totalThrSetelahPajak;
|
||||
|
||||
return 'Rp. '.number_format($value, 2, ',', '.');
|
||||
})
|
||||
->addColumn('selisih_total_formatted', function ($row) {
|
||||
$value = $row['selisih_total_thr_setelah_pajak'] ?? 0;
|
||||
|
||||
return 'Rp. '.number_format($value, 2, ',', '.');
|
||||
})
|
||||
->addColumn('detail', function ($row) {
|
||||
return json_encode([
|
||||
'golongan' => $row['golongan'] ?? '-',
|
||||
'status_pegawai' => $row['status_pegawai'] ?? '-',
|
||||
'poin_p2' => $row['poin_p2'] ?? '-',
|
||||
'faktor' => $row['faktor'] ?? '-',
|
||||
'jabatan_fungsional' => $row['jabatan_fungsional'] ?? '-',
|
||||
'jabatan_tugas_tambahan' => $row['jabatan_tugas_tambahan'] ?? '-',
|
||||
'thr_p1' => $row['thr_p1'] ?? [],
|
||||
'thr_p2' => $row['thr_p2'] ?? [],
|
||||
'steps' => $row['steps'] ?? [],
|
||||
]);
|
||||
})
|
||||
->rawColumns(['detail'])
|
||||
->make();
|
||||
}
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
$tahunNow = Carbon::now()->format('Y');
|
||||
$team = Team::find(session('team_id'));
|
||||
|
||||
// Prioritaskan pilihan user dari request, baru fallback ke team unit
|
||||
if ($request->has('unit_kerja') && $request->unit_kerja !== null) {
|
||||
$unit = $request->unit_kerja;
|
||||
} elseif ($team && $team->unit_kerja_id !== null && $team->unit_kerja_id !== 0) {
|
||||
$unit = $team->unit_kerja_id;
|
||||
} else {
|
||||
$unit = $request->unit_kerja;
|
||||
}
|
||||
|
||||
$jenisPegawai = $request->jenis_pegawai ?? '';
|
||||
$tahun = $request->tahun ?? $tahunNow;
|
||||
|
||||
// Debug log
|
||||
Log::info('THR Export Request', [
|
||||
'jenis_pegawai' => $jenisPegawai,
|
||||
'tahun' => $tahun,
|
||||
'unit' => $unit,
|
||||
'request_all' => $request->all(),
|
||||
]);
|
||||
|
||||
if (! $tahun) {
|
||||
return response()->json(['error' => 'Tahun harus dipilih'], 400);
|
||||
}
|
||||
|
||||
// Get unit name for filename
|
||||
// Model UnitKerja uses 0 for Universitas, but blade and DAWAI API use 99
|
||||
$unitIdForModel = ($unit == 99) ? 0 : $unit;
|
||||
$unitName = '';
|
||||
if ($unit) {
|
||||
$unitKerja = UnitKerja::find($unitIdForModel);
|
||||
if ($unitKerja) {
|
||||
$unitName = '_'.str_replace(['/', ' ', '.'], '_', $unitKerja->nama);
|
||||
}
|
||||
} else {
|
||||
// If no unit selected, show "Semua Unit Kerja"
|
||||
$unitName = '_Semua_Unit_Kerja';
|
||||
}
|
||||
|
||||
$filename = "THR_{$tahun}{$unitName}.xlsx";
|
||||
|
||||
return Excel::download(new ThrExport($jenisPegawai, $tahun, $unit), $filename);
|
||||
}
|
||||
|
||||
public function exportSelisih(Request $request)
|
||||
{
|
||||
$tahunNow = Carbon::now()->format('Y');
|
||||
$team = Team::find(session('team_id'));
|
||||
|
||||
// Prioritaskan pilihan user dari request, baru fallback ke team unit
|
||||
if ($request->has('unit_kerja') && $request->unit_kerja !== null) {
|
||||
$unit = $request->unit_kerja;
|
||||
} elseif ($team && $team->unit_kerja_id !== null && $team->unit_kerja_id !== 0) {
|
||||
$unit = $team->unit_kerja_id;
|
||||
} else {
|
||||
$unit = $request->unit_kerja;
|
||||
}
|
||||
|
||||
$jenisPegawai = $request->jenis_pegawai ?? '';
|
||||
$tahun = $request->tahun ?? $tahunNow;
|
||||
|
||||
if (! $tahun) {
|
||||
return response()->json(['error' => 'Tahun harus dipilih'], 400);
|
||||
}
|
||||
|
||||
// Get unit name for filename
|
||||
// Model UnitKerja uses 0 for Universitas, but blade and DAWAI API use 99
|
||||
$unitIdForModel = ($unit == 99) ? 0 : $unit;
|
||||
$unitName = '';
|
||||
if ($unit) {
|
||||
$unitKerja = UnitKerja::find($unitIdForModel);
|
||||
if ($unitKerja) {
|
||||
$unitName = '_'.str_replace(['/', ' ', '.'], '_', $unitKerja->nama);
|
||||
}
|
||||
} else {
|
||||
// If no unit selected, show "Semua Unit Kerja"
|
||||
$unitName = '_Semua_Unit_Kerja';
|
||||
}
|
||||
|
||||
$filename = "THR_Selisih_{$tahun}{$unitName}.xlsx";
|
||||
|
||||
// Send original unit value to DAWAI API (99 for Universitas)
|
||||
return Excel::download(new ThrExport($jenisPegawai, $tahun, $unit, 'selisih'), $filename);
|
||||
}
|
||||
|
||||
public function logs(Request $request)
|
||||
{
|
||||
// Ambil data dari request
|
||||
$data = $request->all();
|
||||
|
||||
// Log informasi ke file log Laravel
|
||||
Log::info('Export THR Log:', $data);
|
||||
|
||||
// Berikan respons ke klien
|
||||
return response()->json(['status' => 'success', 'message' => 'Log berhasil disimpan']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user