parfum/app/Console/Commands/ClosePayrolls.php
Yoga Pangestu 8d5fdc9801 feat(payroll): membuat fitur penggajian otomatis
-membuat command untuk generate dan close payroll
-membuat enum IsPaid dan SalaryAdjustmentType
-membuat skema db
2025-10-06 19:14:49 +07:00

44 lines
1.2 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 = 'Mark payrolls as paid for the current or specified month. Default: current month.';
public function handle(): void
{
$targetMonth = $this->option('month') ?: Carbon::now()->format('Y-m');
if ($this->option('current')) {
$targetMonth = Carbon::now()->format('Y-m');
}
$payrolls = Payroll::where('period_month', $targetMonth)
->where('is_paid', IsPaid::NOT_PAID)
->get();
if ($payrolls->isEmpty()) {
$this->warn("Tidak ada payroll yang perlu ditutup untuk bulan {$targetMonth}.");
return;
}
$updatedCount = 0;
foreach ($payrolls as $payroll) {
$payroll->is_paid = IsPaid::PAID;
$payroll->save();
$updatedCount++;
}
$this->info("Payroll untuk bulan {$targetMonth} berhasil ditandai selesai. Total: {$updatedCount}");
}
}