unit_kerja_id) || $team->unit_kerja_id === null || $team->unit_kerja_id === 0) { $units = UnitKerja::get(); return view('perhitungan.remunerasi.p1.index', compact('units', 'team', 'title')); } return view('perhitungan.remunerasi.p1.index', compact('team', 'title')); } public function data(Request $request): JsonResponse { $datenow = Carbon::now(); $bulanNow = $datenow->format('m'); $tahunNow = $datenow->format('Y'); $team = Team::find(session('team_id')); if (! $team) { return DataTables::of(collect([]))->make(); } if (! isset($team->unit_kerja_id) || $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; $bulan = $request->bulan ?? $bulanNow; $cacheKey = "p1_data_{$jenisPegawai}_{$tahun}_{$bulan}_{$unit}"; $data = Cache::remember($cacheKey, now()->addDay(), function () use ($jenisPegawai, $tahun, $bulan, $unit) { $dawaiService = new DawaiService; return $dawaiService->getDataP1($jenisPegawai, $tahun, $bulan, $unit); }); $filteredData = collect($data) ->filter(fn ($item) => isset($item['harga_p1']) && $item['harga_p1'] > 0); return DataTables::of($filteredData) ->addIndexColumn() ->editColumn('nip', function ($row) { return ltrim($row['nip'] ?? '', "'"); }) ->editColumn('nama_jtt', function ($row) { return $row['nama_jtt'] ?: '-'; }) ->editColumn('jenis_pegawai', function ($row) { return $row['jenis_pegawai'] == 'dosen' ? 'Dosen' : ($row['jenis_pegawai'] == 'tendik' ? 'Tendik' : '-'); }) ->editColumn('harga_p1', function ($row) { return 'Rp. '.number_format($row['harga_p1'] ?: 0, 2, ',', '.'); }) ->editColumn('pajak_p1', function ($row) { return 'Rp. '.number_format($row['pajak_p1'] ?: 0, 2, ',', '.'); }) ->editColumn('harga_p1_setelah_pajak', function ($row) { return 'Rp. '.number_format($row['harga_p1_setelah_pajak'] ?: 0, 2, ',', '.'); }) ->make(); } public function dataSelisih(Request $request): JsonResponse { $datenow = Carbon::now(); $bulanNow = $datenow->format('m'); $tahunNow = $datenow->format('Y'); $team = Team::find(session('team_id')); if (! $team) { return DataTables::of(collect([]))->make(); } if (! isset($team->unit_kerja_id) || $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; $bulan = $request->bulan ?? $bulanNow; $cacheKey = "p1_selisih_data_{$jenisPegawai}_{$tahun}_{$bulan}_{$unit}"; $data = Cache::remember($cacheKey, now()->addDay(), function () use ($jenisPegawai, $tahun, $bulan, $unit) { $dawaiService = new DawaiService; return $dawaiService->getDataP1Selisih($jenisPegawai, $tahun, $bulan, $unit); }); $filteredData = collect($data)->filter(function ($item) { return isset($item['harga_p1']) && $item['harga_p1'] > 0; }); 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('p1_lama_jafung', function ($row) { return $row['riwayat_pembayaran'][0]['nama_jafung'] ?? '-'; }) ->addColumn('p1_lama_jtt', function ($row) { return $row['riwayat_pembayaran'][0]['nama_jtt'] ?? '-'; }) ->addColumn('p1_lama_bruto', function ($row) { $value = $row['riwayat_pembayaran'][0]['harga_p1'] ?? 0; return 'Rp. '.number_format($value, 2, ',', '.'); }) ->addColumn('p1_lama_netto', function ($row) { $value = $row['riwayat_pembayaran'][0]['harga_p1_setelah_pajak'] ?? 0; return 'Rp. '.number_format($value, 2, ',', '.'); }) ->addColumn('p1_baru_jafung', function ($row) { return $row['nama_jafung'] ?? '-'; }) ->addColumn('p1_baru_jtt', function ($row) { return $row['nama_jtt'] ?? '-'; }) ->addColumn('p1_baru_bruto', function ($row) { $value = $row['harga_p1'] ?? 0; return 'Rp. '.number_format($value, 2, ',', '.'); }) ->addColumn('p1_baru_netto', function ($row) { $value = $row['harga_p1_setelah_pajak'] ?? 0; return 'Rp. '.number_format($value, 2, ',', '.'); }) ->addColumn('selisih_bruto', function ($row) { $value = $row['selisih_harga_p1'] ?? 0; return 'Rp. '.number_format($value, 2, ',', '.'); }) ->addColumn('selisih_netto', function ($row) { $value = $row['selisih_harga_p1_setelah_pajak'] ?? 0; return 'Rp. '.number_format($value, 2, ',', '.'); }) ->addColumn('detail', function ($row) { return json_encode([ 'p1_lama_jafung' => $row['riwayat_pembayaran'][0]['nama_jafung'] ?? '-', 'p1_lama_jtt' => $row['riwayat_pembayaran'][0]['nama_jtt'] ?? '-', 'p1_lama_bruto' => 'Rp. '.number_format($row['riwayat_pembayaran'][0]['harga_p1'] ?? 0, 2, ',', '.'), 'p1_lama_netto' => 'Rp. '.number_format($row['riwayat_pembayaran'][0]['harga_p1_setelah_pajak'] ?? 0, 2, ',', '.'), 'p1_baru_jafung' => $row['nama_jafung'] ?? '-', 'p1_baru_jtt' => $row['nama_jtt'] ?? '-', 'p1_baru_bruto' => 'Rp. '.number_format($row['harga_p1'] ?? 0, 2, ',', '.'), 'p1_baru_netto' => 'Rp. '.number_format($row['harga_p1_setelah_pajak'] ?? 0, 2, ',', '.'), 'selisih_bruto' => 'Rp. '.number_format($row['selisih_harga_p1'] ?? 0, 2, ',', '.'), 'selisih_netto' => 'Rp. '.number_format($row['selisih_harga_p1_setelah_pajak'] ?? 0, 2, ',', '.'), ]); }) ->rawColumns(['detail']) ->make(); } public function export(Request $request): BinaryFileResponse { $datenow = Carbon::now(); $bulanNow = $datenow->format('m'); $tahunNow = $datenow->format('Y'); $team = Team::find(session('team_id')); 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; $bulan = $request->bulan ?? null; $unitIdForModel = ($unit == 99) ? 0 : $unit; if (! $bulan) { $unitName = ''; if ($unit) { $unitKerja = UnitKerja::find($unitIdForModel); if ($unitKerja) { $unitName = '_'.str_replace(['/', ' ', '.'], '_', $unitKerja->nama); } } else { $unitName = '_Semua_Unit_Kerja'; } $bulanNames = [ 1 => 'Januari', 2 => 'Februari', 3 => 'Maret', 4 => 'April', 5 => 'Mei', 6 => 'Juni', 7 => 'Juli', 8 => 'Agustus', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Desember', ]; $namaBulanSekarang = $bulanNames[(int) $bulanNow]; $filename = "P1_Januari_sampai_{$namaBulanSekarang}_{$tahun}{$unitName}.xlsx"; return Excel::download(new P1Export($jenisPegawai, $tahun, null, $unit), $filename); } $bulanNames = [ 1 => 'Januari', 2 => 'Februari', 3 => 'Maret', 4 => 'April', 5 => 'Mei', 6 => 'Juni', 7 => 'Juli', 8 => 'Agustus', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Desember', ]; $bulanName = $bulanNames[(int) $bulan]; $unitName = ''; if ($unit) { $unitKerja = UnitKerja::find($unitIdForModel); if ($unitKerja) { $unitName = '_'.str_replace(['/', ' ', '.'], '_', $unitKerja->nama); } } else { $unitName = '_Semua_Unit_Kerja'; } $filename = "P1_{$bulanName}_{$tahun}{$unitName}.xlsx"; return Excel::download(new P1Export($jenisPegawai, $tahun, $bulan, $unit), $filename); } public function exportSelisih(Request $request): BinaryFileResponse { $datenow = Carbon::now(); $bulanNow = $datenow->format('m'); $tahunNow = $datenow->format('Y'); $team = Team::find(session('team_id')); 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; $bulan = $request->bulan ?? null; $unitIdForModel = ($unit == 99) ? 0 : $unit; if (! $bulan) { $unitName = ''; if ($unit) { $unitKerja = UnitKerja::find($unitIdForModel); if ($unitKerja) { $unitName = '_'.str_replace(['/', ' ', '.'], '_', $unitKerja->nama); } } else { $unitName = '_Semua_Unit_Kerja'; } $bulanNames = [ 1 => 'Januari', 2 => 'Februari', 3 => 'Maret', 4 => 'April', 5 => 'Mei', 6 => 'Juni', 7 => 'Juli', 8 => 'Agustus', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Desember', ]; $namaBulanSekarang = $bulanNames[(int) $bulanNow]; $filename = "P1_Selisih_Januari_sampai_{$namaBulanSekarang}_{$tahun}{$unitName}.xlsx"; return Excel::download(new P1Export($jenisPegawai, $tahun, null, $unit, 'selisih'), $filename); } $bulanNames = [ 1 => 'Januari', 2 => 'Februari', 3 => 'Maret', 4 => 'April', 5 => 'Mei', 6 => 'Juni', 7 => 'Juli', 8 => 'Agustus', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Desember', ]; $bulanName = $bulanNames[(int) $bulan]; $unitName = ''; if ($unit) { $unitKerja = UnitKerja::find($unitIdForModel); if ($unitKerja) { $unitName = '_'.str_replace(['/', ' ', '.'], '_', $unitKerja->nama); } } else { $unitName = '_Semua_Unit_Kerja'; } $filename = "P1_Selisih_{$bulanName}_{$tahun}{$unitName}.xlsx"; return Excel::download(new P1Export($jenisPegawai, $tahun, $bulan, $unit, 'selisih'), $filename); } public function logs(Request $request): JsonResponse { Log::info('Export P1 Log:', $request->all()); return response()->json(['status' => 'success', 'message' => 'Log berhasil disimpan']); } }