mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
make refunded booking expired status
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Carbon\Carbon;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\Booking;
|
||||
|
||||
class DeleteOrderCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'make-refunded-booking-expired {bookings_reference}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Change refunded booking status to expired';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$bookings_reference = $this->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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user