mailer = $mailer; $this->channelManagerBookingService = $channelManagerBookingService; } public function handle() { $this->info(date('Y-m-d H:i:s') . ' : Start'); $today = Carbon::now()->startOfDay()->toDateString(); if(!Carbon::parse($today)->isLastOfMonth()) { $this->alert(date('Y-m-d H:i:s') . ' : Not Today!'); return false; } $fistDayOfMonth = Carbon::parse($today)->startOfMonth()->toDateString(); $lastDayOfMonth = Carbon::parse($today)->addMonth()->startOfMonth()->toDateString(); $cancellationBooking = Booking::where('channel_id', 1) ->where('status', 0) ->where('checkout_date', '>', $fistDayOfMonth) ->where('checkout_date', '<', $lastDayOfMonth) //->where('id', 68690) ->with('channelManagerBooking') ->with('bookingRoom') ->get(); //11 - Trivago $cancellationBooking = $cancellationBooking ? $cancellationBooking->toArray() : []; foreach ($cancellationBooking as $booking) { try { if (empty($booking['channel_manager_booking'])) { $this->line(date('Y-m-d H:i:s') . ' : Booking ID: ' . $booking['id']); continue; } $channelBookingCheck = collect($booking['channel_manager_booking']) ->where('channel_manager_id', 11) ->where('type', 'Booking') ->where('is_pushed', 1) ->isEmpty(); if ($channelBookingCheck) { $this->line(date('Y-m-d H:i:s') . ' : Booking ID: ' . $booking['id']); continue; } $channelCancelCheck = collect($booking['channel_manager_booking']) ->where('channel_manager_id', 11) ->where('type', 'Cancel') ->where('is_pushed', 1) ->isEmpty(); if (!$channelCancelCheck) { $this->line(date('Y-m-d H:i:s') . ' : Booking ID: ' . $booking['id']); continue; } $channelManagerBookingCreateParam = [ 'property_id' => $booking['property_id'], 'booking_id' => $booking['id'], 'channel_manager_id' => 11, 'type' => 'Cancel', ]; $this->channelManagerBookingService->create($channelManagerBookingCreateParam); $this->info(date('Y-m-d H:i:s') . ' : Booking ID: ' . $booking['id']); } catch (ApiErrorException $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $this->error(date('Y-m-d H:i:s') . ' : Error: ' . $e->getMessage()); } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $this->error(date('Y-m-d H:i:s') . ' : Error: ' . $message); } } $this->info(date('Y-m-d H:i:s') . ' : Finished'); } }