startOfDay(); $endDate = Carbon::create(2025, 7, 31)->endOfDay(); $bookings = Booking::where('status', ApprovalStatus::COMPLETED) ->whereBetween('created_at', [$startDate, $endDate]) ->get(); $count = 0; foreach ($bookings as $booking) { $firstInvoice = $booking->transactions() ->whereIn('type', [TransactionType::INVOICE]) ->withTrashed() ->whereBetween('created_at', [$startDate, $endDate]) ->orderBy('created_at', 'asc') ->first(); $normalInvoice = $booking->documents()->where('document_type', DocumentType::INVOICE)->first(); $eInvoice = $booking->documents()->where('document_type', DocumentType::EINVOICE)->first(); // if($firstInvoice && !$normalInvoice && !$eInvoice){ if(!$firstInvoice && !$normalInvoice && !$eInvoice){ OneTimeBatchProcessEInvoicesV2CommandJob::dispatch($booking); $count++; Log::info('Processed: ' . $count); Log::info('Booking ID: ' . $booking->marking . ' | created_at: ' . $booking->created_at); } } } }