5, // Set your desired top margin in millimeters 'margin_bottom' => 1, 'margin_left' => 1, 'margin_right' => 1, ]); $mpdf->Addpage('L'); $stylesheet = file_get_contents('Styles/pdf.css'); $mpdf->WriteHTML($stylesheet, \Mpdf\HTMLParserMode::HEADER_CSS); $client_id = $_GET['record_id']; $client_res = $db->exec_query("clients", ['*'], '', '', '', '', "record_id = '$client_id'"); $client = $client_res->fetch_assoc(); $client_name = $client['clients_name']; $invoices_res = $db->exec_query("invoices", ['*'], '', '', '', '', "clients_id = '$client_id'"); $table_data = ' '; $invoice_global_total = 0; $payments_golbal_total = 0; $net_total = 0; while ($invoices = $invoices_res->fetch_assoc()) { $content_array = explode(';', $invoices['invoice_content']); $content_table = ''; $invoice_total = 0; foreach ($content_array as $content) { if (strlen($content) > 2) { $info = explode(',', $content); $invoice_total += $info[4]; } } $payments_res = $db->exec_query("income", ['*'], '', '', '', '', "invoices_id = '$invoices[record_id]'"); $payments_total = 0; while ($payments = $payments_res->fetch_assoc()) { $payments_total += $payments['amount']; } $net = $invoice_total - $payments_total; $table_data .= " "; $invoice_global_total += $invoice_total; $payments_golbal_total += $payments_total; $net_total += $net; } $table_data .= "
"; $table_data .= '

INVOICE NO

INVOICE TOTAL

PAYMENTS TOTAL

NET

DATE

$invoices[invoice_no] R " . number_format($invoice_total, 2) . " R " . number_format($payments_total, 2) . " R " . number_format($net, 2) . " $invoices[date_created]
TOTALS R " . number_format($invoice_global_total, 2) . " R " . number_format($payments_golbal_total, 2) . " R " . number_format($net_total, 2) . "
'; $htmlContent = "

$client_name STATEMENT

$table_data "; $mpdf->WriteHTML($htmlContent); $mpdf->Output(); }