ob_start(); require "./includes/php/invoice_template.php"; $template = ob_get_contents(); ob_end_clean(); $mpdf = new \mPDF(); $mpdf->WriteHTML($template); $outputTag = $_GET['page'] === "preview-invoice" ? 'I' : 'D'; $mpdf->Output($fileName, $outputTag); } elseif ($_GET['page'] === "issue-invoice") { $result = $model->getInvoice($_POST['id']); $row = $result[0]; $requestedINV = $model->calculateInvoice($row); $requestedINV['discount'] = $row['discount']; $requestedINV['received'] = $row['received']; $requestedINV['comment'] = $row['comment']; $model->updateInvoiceDetail($requestedINV, $row['invoice_detail_id']); $year = date('Y', strtotime($row['event_start_date'])); $month = date('n', strtotime($row['event_start_date'])); $month >= 1 && $month <= 4 ? $year-- : ''; $startyear = $year; $endyear = $year + 1; $fileName = "SCS{$startyear}/{$endyear}-{$row['employer_id']}{$row['event_id']}.pdf"; ob_start(); require "./includes/php/invoice_template.php"; $template = ob_get_contents(); ob_end_clean(); $model->issueInvoice($row['id'], $fileName, $template); $loggers['audit']->info("Invoice {$row['id']} issued"); header('Content-Type: text/plain; charset=utf-8'); echo $row['id']; exit;