getPegawais(); if ($pegawais->isEmpty()) { $this->error('No pegawai found with the given criteria.'); return Command::FAILURE; } $this->displayHeader($pegawais->count()); $this->processPegawais($pegawais); $this->displaySummary($pegawais->count()); return Command::SUCCESS; } private function getPegawais() { $query = Pegawai::query()->with('poin'); if ($nip = $this->option('nip')) { $query->where('nip', $nip); } return $query->get(); } private function displayHeader(int $totalPegawai): void { $this->info('══════════════════════════════════════════════════════'); $this->info(' STORE P2 CALCULATION '); $this->info('══════════════════════════════════════════════════════'); $this->info('Total Pegawai: ' . $totalPegawai); $this->info('Total Kolom per Pegawai: ' . count(self::COLUMNS)); $this->info('══════════════════════════════════════════════════════'); $this->newLine(); } private function processPegawais($pegawais): void { $totalPegawai = $pegawais->count(); $totalColumns = count(self::COLUMNS); // Reserve lines for progress bar echo str_repeat("\n", 7); foreach ($pegawais as $index => $pegawai) { $currentPegawai = $index + 1; if (! $pegawai->poin) { $this->updateProgress( $currentPegawai, $totalPegawai, 0, $totalColumns, $pegawai, 'Data poin tidak ditemukan', true ); $this->errorCount++; continue; } $this->processPegawaiColumns($pegawai, $currentPegawai, $totalPegawai, $totalColumns); } // Clear progress lines echo "\033[F\033[F\033[F\033[F\033[F\033[F\033[F"; } private function processPegawaiColumns( Pegawai $pegawai, int $currentPegawai, int $totalPegawai, int $totalColumns ): void { foreach (self::COLUMNS as $index => $column) { $currentColumn = $index + 1; $this->updateProgress( $currentPegawai, $totalPegawai, $currentColumn, $totalColumns, $pegawai, $column ); if (! $this->shouldProcessColumn($pegawai, $column)) { continue; } $this->calculateAndStoreP2($pegawai, $column); usleep(500); // Visual feedback delay } } private function shouldProcessColumn(Pegawai $pegawai, string $column): bool { if (! isset($pegawai->poin->{$column})) { return false; } return $pegawai->poin->{$column} !== 0; } private function calculateAndStoreP2(Pegawai $pegawai, string $column): void { $poin = $pegawai->poin->{$column}; $p2 = $this->remunerasiService->p2Sk($pegawai->nip, $poin); $pegawai->poin->{"p2_{$column}"} = $p2['total']; $pegawai->poin->save(); $this->processedCount++; } private function updateProgress( int $currentPegawai, int $totalPegawai, int $currentColumn, int $totalColumns, Pegawai $pegawai, string $column, bool $isError = false ): void { // Move cursor up to overwrite previous output echo "\033[F\033[F\033[F\033[F\033[F\033[F\033[F"; // Calculate percentages $progressPegawai = number_format(($currentPegawai / $totalPegawai) * 100, 2); $progressColumn = $totalColumns > 0 ? number_format(($currentColumn / $totalColumns) * 100, 2) : 0; // Create progress bars $pegawaiBar = $this->createProgressBar($currentPegawai, $totalPegawai); $columnBar = $this->createProgressBar($currentColumn, $totalColumns); // Display progress information $this->info("Pegawai: {$currentPegawai}/{$totalPegawai} ({$progressPegawai}%)"); $this->info("Progress: |{$pegawaiBar}|"); $this->info('NIP: ' . str_pad($pegawai->nip, 25) . " | Kolom: {$currentColumn}/{$totalColumns} ({$progressColumn}%)"); $this->info('Nama: ' . str_pad(substr($pegawai->nama, 0, 35), 35)); $this->info("Kolom Progress: |{$columnBar}|"); if ($isError) { $this->error('Status: ERROR - ' . $column); } else { $displayName = ucwords(str_replace('_', ' ', $column)); $this->info('Status: Memproses - ' . str_pad(substr($displayName, 0, 30), 30)); } $this->info(''); } private function createProgressBar(int $current, int $total, int $length = 40): string { if ($total === 0) { return str_repeat('░', $length); } $filledLength = round(($length * $current) / $total); return str_repeat('█', $filledLength) . str_repeat('░', $length - $filledLength); } private function displaySummary(int $totalPegawai): void { $this->newLine(); $this->info('══════════════════════════════════════════════════════'); $this->info(' PROSES SELESAI '); $this->info('══════════════════════════════════════════════════════'); $this->info('Total Pegawai Diproses: ' . $totalPegawai); $this->info('Total Data P2 Tersimpan: ' . $this->processedCount); if ($this->errorCount > 0) { $this->warn('Total Error: ' . $this->errorCount); } $this->info('══════════════════════════════════════════════════════'); } }