refactor(command): menyesuaikan custom command nya

This commit is contained in:
Yoga Pangestu 2025-12-08 13:51:18 +07:00
parent 67fe31439c
commit 96e8b0a3d5
3 changed files with 14 additions and 15 deletions

View File

@ -11,7 +11,7 @@ class ClosePayrolls extends Command
{ {
protected $signature = 'payroll:close {--current} {--month= : Target month in Y-m format}'; 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.'; protected $description = 'Tandai payroll sebagai sudah dibayar untuk bulan saat ini atau bulan yang ditentukan. Default: bulan saat ini.';
public function handle(): void public function handle(): void
{ {
@ -21,23 +21,16 @@ public function handle(): void
$targetMonth = Carbon::now()->format('Y-m'); $targetMonth = Carbon::now()->format('Y-m');
} }
$payrolls = Payroll::where('period_month', $targetMonth) $updatedCount = Payroll::where('period_month', $targetMonth)
->where('is_paid', IsPaid::NOT_PAID) ->where('is_paid', IsPaid::NOT_PAID)
->get(); ->update(['is_paid' => IsPaid::PAID]);
if ($payrolls->isEmpty()) { if ($updatedCount === 0) {
$this->warn("Tidak ada payroll yang perlu ditutup untuk bulan {$targetMonth}."); $this->warn("Tidak ada payroll yang perlu ditutup untuk bulan {$targetMonth}.");
return; 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}"); $this->info("Payroll untuk bulan {$targetMonth} berhasil ditandai selesai. Total: {$updatedCount}");
} }
} }

View File

@ -12,7 +12,7 @@ class GeneratePayrolls extends Command
{ {
protected $signature = 'payroll:generate {--current} {--next}'; protected $signature = 'payroll:generate {--current} {--next}';
protected $description = 'Generate payroll data for the current or next month. Default: next month.'; protected $description = 'Generate data payroll untuk bulan saat ini atau bulan berikutnya. Default: bulan berikutnya.';
public function handle(): void public function handle(): void
{ {
@ -22,7 +22,10 @@ public function handle(): void
$periodMonth = $targetDate->format('Y-m'); $periodMonth = $targetDate->format('Y-m');
$periodLabel = $targetDate->translatedFormat('F Y'); $periodLabel = $targetDate->translatedFormat('F Y');
$users = User::whereHas('employee')->active()->get(); $users = User::whereHas('employee')
->active()
->with('employee')
->get();
if ($users->isEmpty()) { if ($users->isEmpty()) {
$this->warn('Tidak ada pegawai.'); $this->warn('Tidak ada pegawai.');

View File

@ -13,13 +13,16 @@ class GenerateStockOpname extends Command
{ {
protected $signature = 'stock-opname:generate'; protected $signature = 'stock-opname:generate';
protected $description = 'Automatically generate a stock opname document'; protected $description = 'Otomatis generate dokumen stock opname';
public function handle() public function handle()
{ {
$periodMonth = now()->format('Y-m'); $periodMonth = now()->format('Y-m');
$outlets = Outlet::query()->operational()->get(); $outlets = Outlet::query()
->operational()
->with(['perfumes', 'bottles', 'products'])
->get();
$user = User::role('Developer')->first(); $user = User::role('Developer')->first();