<?php

namespace App\Exports;

use App\Models\Cruise;
use App\Models\Ticket;
use Carbon\Carbon;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;

class CarReportExport implements FromView
{
    public function view(): View
    {
        $cruise = Cruise::findOrFail(request()->query('cruise_id', Cruise::where('status', 1)->firstOrFail()->id));

        $qb = Ticket::with(['segment.cruise', 'boardingPass', 'boardingPass.room'])->whereHas('segment.cruise', function ($query) use ($cruise) {
            $query->where('id', $cruise->id);
        })
            ->whereHas('boardingPass', function ($query) {
                $query->whereNotNull('checked_at');
            })
            ->where('ticket_status', '=', 'U')->orderBy('created_at', 'desc');

        return view('CarReports.exports', [
            'tickets' => $qb->get()
        ]);
    }
}
