parfum/app/Console/Commands/ClosePayrolls.php
2025-12-08 13:51:18 +07:00

37 lines
1.1 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Enums\IsPaid;
use App\Models\Payroll;
use Carbon\Carbon;
use Illuminate\Console\Command;
class ClosePayrolls extends Command
{
protected $signature = 'payroll:close {--current} {--month= : Target month in Y-m format}';
protected $description = 'Tandai payroll sebagai sudah dibayar untuk bulan saat ini atau bulan yang ditentukan. Default: bulan saat ini.';
public function handle(): void
{
$targetMonth = $this->option('month') ?: Carbon::now()->format('Y-m');
if ($this->option('current')) {
$targetMonth = Carbon::now()->format('Y-m');
}
$updatedCount = Payroll::where('period_month', $targetMonth)
->where('is_paid', IsPaid::NOT_PAID)
->update(['is_paid' => IsPaid::PAID]);
if ($updatedCount === 0) {
$this->warn("Tidak ada payroll yang perlu ditutup untuk bulan {$targetMonth}.");
return;
}
$this->info("Payroll untuk bulan {$targetMonth} berhasil ditandai selesai. Total: {$updatedCount}");
}
}