$expense_total_value = CashFormat($expense_total_value);
$expense_total_diff = CashFormat($expense_total_diff);
$expense_total_vat = CashFormat($expense_total_vat);
//Totals
$y = $pdf->GetY() + 5;
$pdf->SetXY(10, $y);
$y = $pdf->GetY() + 5;
$pdf->SetXY(10, $y);
$pdf->SetFont($format_font, '', 8);
$pdf->SetDrawColor("0");
$expense_invoice_net = CashFormat($expense_invoice_net);
$expense_noinvoice_net = CashFormat($expense_noinvoice_net);
$expense_invoice_vat = CashFormat($expense_invoice_vat);
$expense_noinvoice_vat = CashFormat($expense_noinvoice_vat);
$expense_invoice_gross = CashFormat($expense_invoice_gross);
$expense_noinvoice_gross = CashFormat($expense_noinvoice_gross);
$pdf->Cell(145, 5, "Non-Invoiced Totals", T, 0, L, 0);
$pdf->Cell(15, 5, $expense_noinvoice_net, T, 0, R, 0);
$pdf->Cell(15, 5, $expense_noinvoice_vat, T, 0, R, 0);
$pdf->Cell(15, 5, $expense_noinvoice_gross, T, 1, R, 0);
$y = $pdf->GetY();
$pdf->SetXY(10, $y);
$pdf->Cell(145, 5, "Invoiced Totals", 0, 0, L, 0);
$pdf->Cell(15, 5, $expense_invoice_net, 0, 0, R, 0);
$pdf->Cell(15, 5, $expense_invoice_vat, 0, 0, R, 0);
$pdf->Cell(15, 5, $expense_invoice_gross, 0, 1, R, 0);
$pdf->SetFont($format_font, '', 8);
$pdf->SetDrawColor("0");
$pdf->Cell(145, 5, "TOTAL", T, 0, L, 0);
$pdf->Cell(15, 5, $expense_total_value, T, 0, R, 0);
$pdf->Cell(15, 5, $expense_total_diff, T, 0, R, 0);
        $count_disbursement++;
    }
    if ($count_disbursement == 0) {
        $pdf->MultiCell(0, 4, "- None -", '', 'L');
    }
    $y = $pdf->GetY();
    $y = $y + 2;
    //InsertPage();
    $grand_total = $grand_total + $ts_disbursement_total;
    // Total
    $y = $y + 2;
    $pdf->SetLineWidth(0.1);
    $pdf->SetXY(40, $y);
    $pdf->SetFont($format_font, '', 11);
    $pdf->Cell(150, 6, 'TOTAL NOW DUE', 'B', '', '', false);
    $invoice_total = CashFormat($grand_total);
    $y = $pdf->GetY();
    $y = $y + 6;
    $pdf->SetXY(140, $y);
    $pdf->MultiCell(50, 5, $invoice_total, '', R);
    // And the smallprint
    $y = $y + 12;
    // if ($y > 230) { $y = $y + 20; $pdf->SetY($y); $pdf->SetFont($format_font,'',9); $pdf->MultiCell(180,5,"To next page...",'','R'); $pdf->addPage(); $y = 20; $pdf->SetXY(40,$y); $pdf->MultiCell(0,5,"...from previous page"); $y = $y + 15; }
    $pdf->SetXY(40, $y);
    $pdf->SetFont($format_font, '', 9);
    $pdf->MultiCell(140, 3.75, $invoice_text);
    $counter++;
}
// and send to output
if ($viewall != NULL) {
    $file_name = "Invoice_Complete.pdf";
$expense_noinvoice_net = CashFormat($expense_noinvoice_net);
$expense_invoice_vat = CashFormat($expense_invoice_vat);
$expense_noinvoice_vat = CashFormat($expense_noinvoice_vat);
$expense_invoice_gross = CashFormat($expense_invoice_gross);
$expense_noinvoice_gross = CashFormat($expense_noinvoice_gross);
$pdf->Cell(145, 5, "Non-Invoiced Totals", T, 0, L, 0);
$pdf->Cell(15, 5, $expense_noinvoice_net, T, 0, R, 0);
$pdf->Cell(15, 5, $expense_noinvoice_vat, T, 0, R, 0);
$pdf->Cell(15, 5, $expense_noinvoice_gross, T, 1, R, 0);
$y = $pdf->GetY();
$pdf->SetXY(10, $y);
$pdf->Cell(145, 5, "Invoiced Totals", 0, 0, L, 0);
$pdf->Cell(15, 5, $expense_invoice_net, 0, 0, R, 0);
$pdf->Cell(15, 5, $expense_invoice_vat, 0, 0, R, 0);
$pdf->Cell(15, 5, $expense_invoice_gross, 0, 1, R, 0);
$pdf->SetFont($format_font, '', 8);
$pdf->SetDrawColor("0");
$pdf->Cell(145, 5, "TOTAL", T, 0, L, 0);
$pdf->Cell(15, 5, $expense_total_value, T, 0, R, 0);
$pdf->Cell(15, 5, $expense_total_diff, T, 0, R, 0);
$pdf->Cell(15, 5, $expense_total_vat, T, 1, R, 0);
$y = $pdf->GetY() + 5;
$pdf->SetY($y);
if ($expense_p11d_total > 0) {
    $expense_p11d_total_print = CashFormat($expense_p11d_total);
    $pdf->Cell(175, 5, "P11d TOTAL", T, 0, L, 0);
    $pdf->Cell(15, 5, $expense_p11d_total_print, T, 1, R, 0);
}
// and send to output
$file_name = "Expenses_Schedule_" . Date("Y", time()) . "-" . Date("m", time()) . "-" . Date("d", time()) . ".pdf";
$pdf->Output($file_name, I);
    if ($show_non_personal == NULL) {
        // Non P11d Items
        echo "<tr><th colspan=\"9\">Non-Personal Items</th></tr>";
        echo "<tr><td class=\"total\" colspan=\"7\">Sub Total (non-Personal)</td><td class=\"total\" style=\"text-align: right;\">" . CashFormat($col_alt_3) . "</td><td class=\"total\" style=\"text-align: right;\">" . CashFormat($col_alt_4) . "</td></tr>";
        echo "<tr><td class=\"total\" colspan=\"5\">Total (non-Personal)</td><td class=\"total\" style=\"text-align: right;\">" . CashFormat($col_alt_1) . "</td><td class=\"total\" style=\"text-align: right;\">" . CashFormat($col_alt_2) . "</td><td class=\"total\" style=\"text-align: right;\" colspan=\"3\">" . CashFormat($col_alt_3 + $col_alt_4) . "</td></tr>";
        // Reimbursements only
        echo "<tr><th colspan=\"9\">Reimbursements Only</th></tr>";
        $total_col2 = $col2 + $col_alt_2;
        $total_col3 = $col3 + $col_alt_3;
        echo "<tr><td class=\"total\" colspan=\"6\">Total (Reimbursements)</td><td class=\"total\" style=\"text-align: right;\">" . CashFormat($total_col2) . "</td><td class=\"total\" style=\"text-align: right;\">" . CashFormat($total_col3) . "</td><td></td></tr>";
    }
    echo "</table>";
}
if ($_GET[year] == "all") {
    $show_period = "From the beginning of time, ";
} else {
    $show_period = "In financial year beginning " . date("j M Y", $time_begin) . ", ";
}
echo "<h1>Summary</h1><p style=\"font-size: 13pt\">{$show_period} {$user_name_first} {$user_name_second} has <strong>" . CashFormat($col1 - $total_queried) . "</strong> of personal expenses, <strong>" . CashFormat($col3 + $col4) . "</strong> of which has already been paid by {$pref_practice}, leaving <strong>" . CashFormat($col2) . "</strong> outstanding to be reimbursed.";
if ($total_queried > 0) {
    echo "There is <strong>" . CashFormat($total_queried) . "</strong> of expenses which have been queried, which are excluded from these figures. ";
}
echo "</p>";
if ($show_non_personal == NULL) {
    echo "<p style=\"font-size: 13pt\">In addition, there is <strong>" . CashFormat($col_alt_2) . "</strong> of non-personal expenses outstanding to be reimbursed, resulting in a total to be reimbursed of <strong>" . CashFormat($col2 + $col_alt_2) . "</strong></p>";
    echo "</p>";
}
?>

</body>
</html>
        $pdf->SetXY($x, $y);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetFont($format_font, '', 10);
        $year = date("Y", $invoice_date) . " Total";
        $pdf->Cell(130, 5, $year, 'T');
        $invoice_year_novat_print = CashFormat($invoice_year_novat);
        $invoice_year_vat_print = CashFormat($invoice_year_vat);
        $pdf->Cell(30, 5, $invoice_year_novat_print, 'T', 0, 'R');
        $pdf->Cell(30, 5, $invoice_year_vat_print, 'T', 0, 'R');
        $invoice_year_novat = 0;
        $invoice_year_vat = 0;
        $y = $y + 10;
        $pdf->SetXY($x, $y);
    }
    $pdf->SetTextColor(0, 0, 0);
    $pdf->SetFont($format_font, '', 10);
    $pdf->Cell(130, 5, "TOTAL", 'T');
    $invoice_item_novat_total_all_print = CashFormat($invoice_value_novat_total_all);
    $invoice_item_vat_total_all_print = CashFormat($invoice_value_vat_total_all);
    $pdf->Cell(30, 5, $invoice_item_novat_total_all_print, 'T', 0, 'R');
    $pdf->Cell(30, 5, $invoice_item_vat_total_all_print, 'T', 0, 'R');
    // And the smallprint
    $y = $y + 15;
    $smallprint = "Notes:\nOverdue invoices are highlighted in red.\nAll figures exclude expenses.";
    $pdf->SetXY(10, $y);
    $pdf->SetFont($format_font, '', 9);
    $pdf->MultiCell(140, 3.75, $smallprint);
    // and send to output
    $file_name = "Invoice_Schedule_" . Date("Y", time()) . "-" . Date("m", time()) . "-" . Date("d", time()) . ".pdf";
    $pdf->Output($file_name, I);
}