From 96e8b0a3d5a85828296a9847c8cb8f4610bb8166 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Mon, 8 Dec 2025 13:51:18 +0700 Subject: [PATCH] refactor(command): menyesuaikan custom command nya --- app/Console/Commands/ClosePayrolls.php | 15 ++++----------- app/Console/Commands/GeneratePayrolls.php | 7 +++++-- app/Console/Commands/GenerateStockOpname.php | 7 +++++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/Console/Commands/ClosePayrolls.php b/app/Console/Commands/ClosePayrolls.php index 7bcc659..9d48168 100644 --- a/app/Console/Commands/ClosePayrolls.php +++ b/app/Console/Commands/ClosePayrolls.php @@ -11,7 +11,7 @@ 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.'; + protected $description = 'Tandai payroll sebagai sudah dibayar untuk bulan saat ini atau bulan yang ditentukan. Default: bulan saat ini.'; public function handle(): void { @@ -21,23 +21,16 @@ public function handle(): void $targetMonth = Carbon::now()->format('Y-m'); } - $payrolls = Payroll::where('period_month', $targetMonth) + $updatedCount = Payroll::where('period_month', $targetMonth) ->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}."); 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}"); } } diff --git a/app/Console/Commands/GeneratePayrolls.php b/app/Console/Commands/GeneratePayrolls.php index 4272b5b..d28cdd9 100644 --- a/app/Console/Commands/GeneratePayrolls.php +++ b/app/Console/Commands/GeneratePayrolls.php @@ -12,7 +12,7 @@ class GeneratePayrolls extends Command { 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 { @@ -22,7 +22,10 @@ public function handle(): void $periodMonth = $targetDate->format('Y-m'); $periodLabel = $targetDate->translatedFormat('F Y'); - $users = User::whereHas('employee')->active()->get(); + $users = User::whereHas('employee') + ->active() + ->with('employee') + ->get(); if ($users->isEmpty()) { $this->warn('Tidak ada pegawai.'); diff --git a/app/Console/Commands/GenerateStockOpname.php b/app/Console/Commands/GenerateStockOpname.php index a42a87c..e13e978 100644 --- a/app/Console/Commands/GenerateStockOpname.php +++ b/app/Console/Commands/GenerateStockOpname.php @@ -13,13 +13,16 @@ class GenerateStockOpname extends Command { protected $signature = 'stock-opname:generate'; - protected $description = 'Automatically generate a stock opname document'; + protected $description = 'Otomatis generate dokumen stock opname'; public function handle() { $periodMonth = now()->format('Y-m'); - $outlets = Outlet::query()->operational()->get(); + $outlets = Outlet::query() + ->operational() + ->with(['perfumes', 'bottles', 'products']) + ->get(); $user = User::role('Developer')->first();