<?php
    require_once '../dompdf/autoload.inc.php';
    include_once("../include/main.inc.php");
    use Dompdf\Dompdf;
    $oid = $_REQUEST['orderid'];
   // $order_res = mysqli_fetch_array($dbconn->query("SELECT * FROM orders_tbl1 WHERE invoice_id='".$oid."'"));
    $invoice = mysqli_fetch_array($dbconn->query("SELECT * FROM order_payment_history WHERE payment_id=".$oid));
    if($invoice){
        $invoiceContent = invoice_html($invoice, $dbconn);
        $dompdf = new Dompdf();
        $dompdf->loadHtml($invoiceContent);
        $dompdf->setPaper('A4', 'portrait');
        $dompdf->render();
        $invoiceContent = $dompdf->output();
        header('Content-Type: application/pdf');
        header('Content-Disposition: attachment; filename="invoice.pdf"');
        header('Content-Length: ' . strlen($invoiceContent));
        echo $invoiceContent;
    }else{
        echo '<center><h3 style="margin-top:15px;">Bad request.</h3></center>';
    }
    
?>