$page_count = 1;
 $pdf->SetTextColor($format_bg_r, $format_bg_g, $format_bg_b);
 // Get the relevant infomation from the Invoice Database
 $sql_invoice = "SELECT * FROM intranet_timesheet_invoice WHERE invoice_id = '{$invoice_id}' LIMIT 1";
 $result_invoice = mysql_query($sql_invoice, $conn) or die(mysql_error());
 $array_invoice = mysql_fetch_array($result_invoice);
 $invoice_ref = $array_invoice['invoice_ref'];
 $invoice_date = $array_invoice['invoice_date'];
 $invoice_due = $array_invoice['invoice_due'];
 $invoice_project = $array_invoice['invoice_project'];
 $invoice_paid = $array_invoice['invoice_paid'];
 $invoice_notes = $array_invoice['invoice_notes'];
 $invoice_account = $array_invoice['invoice_account'];
 $invoice_client = $array_invoice['invoice_client'];
 $invoice_purchase_order = $array_invoice['invoice_purchase_order'];
 $invoice_text = InvoiceDueDays($array_invoice['invoice_text'], $invoice_due, $invoice_date);
 $invoice_due_days = $invoice_due - $invoice_date;
 $invoice_due_days = $invoice_due_days / 86400;
 settype($invoice_due_days, "integer");
 $invoice_ref_print = strtoupper($invoice_ref);
 if ($viewall == "yes") {
     $invoice_ref_print = $invoice_ref_print . " (ID: " . $invoice_id . ")";
 }
 $invoice_date_print = TimeFormat($invoice_date);
 // Account name
 if ($invoice_account > 0) {
     $sql_account = "SELECT * FROM intranet_account WHERE account_id = '{$invoice_account}' LIMIT 1";
     $result_account = mysql_query($sql_account, $conn) or die(mysql_error());
     $array_account = mysql_fetch_array($result_account);
     $account_name = $array_account['account_name'];
 }
}
if (mysql_num_rows($result) > 0) {
    $array = mysql_fetch_array($result);
    $invoice_id = $array['invoice_id'];
    $invoice_date = $array['invoice_date'];
    $invoice_due = $array['invoice_due'];
    $invoice_value_novat = $array['invoice_value_novat'];
    $invoice_value_vat = $array['invoice_value_vat'];
    $invoice_project = $array['invoice_project'];
    $invoice_ref = $array['invoice_ref'];
    $invoice_expenses = $array['invoice_expenses'];
    $invoice_expenses_description = TextPresent($array['invoice_expenses_description']);
    $invoice_paid = $array['invoice_paid'];
    $invoice_notes = TextPresent($array['invoice_notes']);
    $invoice_text = TextPresent($array['invoice_text']);
    $invoice_text = InvoiceDueDays($invoice_text, $invoice_due, $invoice_date);
    $invoice_account = $array['invoice_account'];
    $invoice_baddebt = $array['invoice_baddebt'];
    $invoice_purchase_order = $array['invoice_purchase_order'];
    $proj_id = $array['proj_id'];
    $proj_num = $array['proj_num'];
    $proj_name = $array['proj_name'];
    $invoice_due_days = round(($array['invoice_due'] - $array['invoice_date']) / 86400);
    if ($invoice_paid < 1 and $invoice_due < time()) {
        $option1 = " style=\"background-color: #{$settings_alertcolor}\"";
    }
    print "<p class=\"menu_bar\"><a href=\"index2.php?page=timesheet_invoice_edit\" class=\"menu_tab\">Add</a><a href=\"index2.php?page=timesheet_invoice_edit&amp;status=edit&amp;invoice_id={$invoice_id}\" class=\"menu_tab\">Edit</a></p>";
    print "<p class=\"submenu_bar\">";
    if ($user_usertype_current > 1 and $invoice_date > time()) {
        print "<a href=\"index2.php?page=timesheet_invoice_items_edit&amp;proj_id={$proj_id}&amp;invoice_id={$invoice_id}\" class=\"submenu_bar\"><img src=\"images/button_new.png\" alt=\"Add Invoice Item Button\" />&nbsp;&nbsp;Add Invoice Item</a>";
    }