argument('nip'); if (! $nips || count($nips) === 0) { $pegawais = Pegawai::query(); $nips = $pegawais->pluck('nip')->toArray(); } $periode = Periode::where('status', true)->first()->id_periode; $perhitunganKegiatanService = new PerhitunganKegiatanService; if ($periode % 2 === 1) { $bulan = [1, 2, 3, 4, 5, 6]; } else { $bulan = [7, 8, 9, 10, 11, 12]; } $num = 1; try { DB::beginTransaction(); foreach ($nips as $nip) { try { $nama = Pegawai::where('nip', $nip)->value('nama') ?? '-'; $nama = Str::limit($nama, 37); $kegiatans = collect($perhitunganKegiatanService->listKegiatan($nip, $periode, $bulan, null, true)); $p2 = $kegiatans->sum(fn ($bulan) => $bulan['p2']['total']['bruto'] ?? 0); $p2Formatted = number_format($p2, 2, ',', '.'); $this->info(sprintf( '%3d. %-20s %-40s %20s %s', $num, $nip, $nama, $p2Formatted, now() )); $num++; } catch (Exception $e) { continue; } } DB::commit(); return 0; } catch (Exception $e) { DB::rollBack(); return 1; } } }