diff --git a/app/Console/Commands/UpdateCooperationStatusCommand.php b/app/Console/Commands/UpdateCooperationStatusCommand.php new file mode 100644 index 0000000..e6622e7 --- /dev/null +++ b/app/Console/Commands/UpdateCooperationStatusCommand.php @@ -0,0 +1,69 @@ +info('Updating cooperation statuses...'); + + $today = Carbon::today(); + + Log::info('Running UpdateCooperationStatusJob at ' . now()); + + // 1. PENDING -> ASSIGNMENT (final_submission_date) + $updatedPending = Cooperation::where('status', CooperationStatus::PENDING) + ->whereDate('final_submission_date', '<=', $today) + ->update(['status' => CooperationStatus::ASSIGNMENT]); + + if ($updatedPending > 0) { + Log::info("Updated {$updatedPending} cooperations from PENDING to ASSIGNMENT."); + } + + // 2. ASSIGNMENT -> VERIFICATION (assignment_deadline) + $updatedAssignment = Cooperation::where('status', CooperationStatus::ASSIGNMENT) + ->whereDate('assignment_deadline', '<=', $today) + ->update(['status' => CooperationStatus::VERIFICATION]); + + if ($updatedAssignment > 0) { + Log::info("Updated {$updatedAssignment} cooperations from ASSIGNMENT to VERIFICATION."); + } + + // 3. VERIFICATION -> PAYMENT (verification_deadline) + $updatedVerification = Cooperation::where('status', CooperationStatus::VERIFICATION) + ->whereDate('verification_deadline', '<=', $today) + ->update(['status' => CooperationStatus::PAYMENT]); + + if ($updatedVerification > 0) { + Log::info("Updated {$updatedVerification} cooperations from VERIFICATION to PAYMENT."); + } + + $this->info('Cooperation statuses updated successfully.'); + + return Command::SUCCESS; + } +} diff --git a/routes/console.php b/routes/console.php index 3c9adf1..55fd9db 100644 --- a/routes/console.php +++ b/routes/console.php @@ -1,8 +1,5 @@ comment(Inspiring::quote()); -})->purpose('Display an inspiring quote'); +Schedule::command('cooperation:update-status')->daily();