diff --git a/app/Console/Commands/DeleteOrderCommand.php b/app/Console/Commands/DeleteOrderCommand.php new file mode 100644 index 00000000..a4702ff0 --- /dev/null +++ b/app/Console/Commands/DeleteOrderCommand.php @@ -0,0 +1,79 @@ +argument('bookings_reference'); + $bookings_reference = explode(',', $bookings_reference); + + $start = new Carbon(); + $this->logOutput('Process started'); + + foreach ($bookings_reference as $reference) { + $booking = Booking::where('marking', $reference)->first(); + + if (!$booking) { + $this->logOutput('Booking not found: ' . $reference); + } else { + $booking->status = ApprovalStatus::EXPIRED; + $booking->save(); + $this->logOutput('Booking deleted: ' . $reference); + } + } + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + + $this->logOutput('Process ended. ElapsedTime: ' . $elapsedTime); + } + + public function logOutput($text) + { + if (is_array($text)) { + $text = implode(', ', $text); + } + + $this->info(Carbon::now() . ' : ' . $text); + + $filePath = storage_path('logs/delete-orders.log'); + $textToAppend = Carbon::now()->format('[Y-m-d H:i:s]') . ' ' . $text . PHP_EOL; + file_put_contents($filePath, $textToAppend, FILE_APPEND); + } +}