argument('month') ?? now()->format('Y-m'); $prevMonth = now()->parse($month.'-01')->subMonth()->format('Y-m'); $payrollsToPay = Payroll::where('period_month', $prevMonth) ->paid() ->get(); foreach ($payrollsToPay as $payroll) { $payroll->update([ 'is_paid' => IsPaid::PAID, ]); } $users = User::role(RoleEnum::ADMINISTRATOR->value)->get(); $count = 0; foreach ($users as $user) { $exists = Payroll::where('user_id', $user->id) ->where('period_month', $month) ->exists(); if (! $exists) { $baseSalary = $user->base_salary; Payroll::create([ 'user_id' => $user->id, 'period_month' => $month, 'base_salary' => $baseSalary, 'bonus' => 0, 'deduction' => 0, 'total_salary' => $baseSalary, 'is_paid' => IsPaid::NOT_PAID, ]); $count++; } } if ($payrollsToPay->count() > 0) { $this->info("Berhasil memproses pembayaran untuk {$payrollsToPay->count()} data payroll bulan {$prevMonth}."); } $this->info("Berhasil membuat {$count} data payroll baru untuk bulan {$month}."); } }