PDF Invoice generation as guest

It seems when I generate a PDF invoice when logged in as a guest, it won’t work unless an admin has already generated the PDF.
This is caused by these checks, which seem unnecessary ?

        if (!empty($invoice_array) AND $isGuest) {
        rsort($invoice_array);
        header('Content-type: application/pdf');
        return readfile($invoice_array[0]);
    } else
        if ($isGuest){
        //todo flashdata is deleted between requests
        //$CI->session->flashdata('alert_error', 'sorry no Invoice found!');
        redirect('guest/view/invoice/' . end($CI->uri->segment_array()));
    }