Oops, something went wrong! Please raise a ticket if you believe this is an error.

"; require_once("guest_footer.php"); exit(); } $url_key = sanitizeInput($_GET['url_key']); $invoice_id = intval($_GET['invoice_id']); $sql = mysqli_query( $mysqli, "SELECT * FROM invoices LEFT JOIN clients ON invoice_client_id = client_id LEFT JOIN locations ON primary_location = location_id LEFT JOIN contacts ON primary_contact = contact_id LEFT JOIN companies ON invoices.company_id = companies.company_id LEFT JOIN settings ON settings.company_id = companies.company_id WHERE invoice_id = $invoice_id AND invoice_url_key = '$url_key'" ); if (mysqli_num_rows($sql) !== 1) { // Invalid invoice/key echo "

Oops, something went wrong! Please raise a ticket if you believe this is an error.

"; require_once("guest_footer.php"); exit(); } $row = mysqli_fetch_array($sql); $invoice_id = intval($row['invoice_id']); $invoice_prefix = htmlentities($row['invoice_prefix']); $invoice_number = intval($row['invoice_number']); $invoice_status = htmlentities($row['invoice_status']); $invoice_date = htmlentities($row['invoice_date']); $invoice_due = htmlentities($row['invoice_due']); $invoice_amount = floatval($row['invoice_amount']); $invoice_currency_code = htmlentities($row['invoice_currency_code']); $invoice_note = htmlentities($row['invoice_note']); $invoice_category_id = intval($row['invoice_category_id']); $client_id = intval($row['client_id']); $client_name = htmlentities($row['client_name']); $location_address = htmlentities($row['location_address']); $location_city = htmlentities($row['location_city']); $location_state = htmlentities($row['location_state']); $location_zip = htmlentities($row['location_zip']); $contact_email = htmlentities($row['contact_email']); $contact_phone = formatPhoneNumber($row['contact_phone']); $contact_extension = htmlentities($row['contact_extension']); $contact_mobile = formatPhoneNumber($row['contact_mobile']); $client_website = htmlentities($row['client_website']); $client_currency_code = htmlentities($row['client_currency_code']); $client_net_terms = intval($row['client_net_terms']); if ($client_net_terms == 0) { $client_net_terms = intval($row['config_default_net_terms']); } $company_id = intval($row['company_id']); $company_name = htmlentities($row['company_name']); $company_address = htmlentities($row['company_address']); $company_city = htmlentities($row['company_city']); $company_state = htmlentities($row['company_state']); $company_zip = htmlentities($row['company_zip']); $company_phone = formatPhoneNumber($row['company_phone']); $company_email = htmlentities($row['company_email']); $company_website = htmlentities($row['company_website']); $company_logo = htmlentities($row['company_logo']); if (!empty($company_logo)) { $company_logo_base64 = base64_encode(file_get_contents("uploads/settings/$company_id/$company_logo")); } $company_locale = htmlentities($row['company_locale']); $config_invoice_footer = htmlentities($row['config_invoice_footer']); $config_stripe_enable = intval($row['config_stripe_enable']); $config_stripe_publishable = $row['config_stripe_publishable']; $config_stripe_secret = $row['config_stripe_secret']; //Set Currency Format $currency_format = numfmt_create($company_locale, NumberFormatter::CURRENCY); $invoice_tally_total = 0; // Default //Set Badge color based off of invoice status $invoice_badge_color = getInvoiceBadgeColor($invoice_status); //Update status to Viewed only if invoice_status = "Sent" if ($invoice_status == 'Sent') { mysqli_query($mysqli, "UPDATE invoices SET invoice_status = 'Viewed' WHERE invoice_id = $invoice_id"); } //Mark viewed in history mysqli_query($mysqli, "INSERT INTO history SET history_status = '$invoice_status', history_description = 'Invoice viewed - $ip - $os - $browser', history_invoice_id = $invoice_id, company_id = $company_id"); if ($invoice_status !== 'Paid') { $client_name_escaped = sanitizeInput($row['client_name']); mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Invoice Viewed', notification = 'Invoice $invoice_prefix$invoice_number has been viewed by $client_name_escaped - $ip - $os - $browser', notification_client_id = $client_id, company_id = $company_id"); } $sql_payments = mysqli_query($mysqli, "SELECT * FROM payments, accounts WHERE payment_account_id = account_id AND payment_invoice_id = $invoice_id ORDER BY payments.payment_id DESC"); //Add up all the payments for the invoice and get the total amount paid to the invoice $sql_amount_paid = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS amount_paid FROM payments WHERE payment_invoice_id = $invoice_id"); $row = mysqli_fetch_array($sql_amount_paid); $amount_paid = floatval($row['amount_paid']); $balance = $invoice_amount - $amount_paid; //check to see if overdue $invoice_color = $invoice_badge_color; // Default if ($invoice_status !== "Paid" && $invoice_status !== "Draft" && $invoice_status !== "Cancelled") { $unixtime_invoice_due = strtotime($invoice_due) + 86400; if ($unixtime_invoice_due < time()) { $invoice_color = "text-danger"; } } // Invoice individual items $sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_invoice_id = $invoice_id ORDER BY item_id ASC"); ?>
">

Invoice

Date
Due
Product Description Qty Price Tax Total
0) { ?> 0) { ?>
Subtotal
Tax
Paid
Balance

1) { ?>
Previous Unpaid Invoices
>
Invoice # Date Due Date Amount
( Days Late)
CURDATE() AND(invoice_status = 'Sent' OR invoice_status = 'Viewed' OR invoice_status = 'Partial') ORDER BY invoice_number DESC"); if (mysqli_num_rows($sql) > 1) { ?>
Current Invoices
>
Invoice # Date Due Amount
(Due in Days)
1) { ?>
Previous Invoices Paid
> strtotime($invoice_due)) { $payment_note = "Late"; $difference = strtotime($payment_date) - strtotime($invoice_due); $days = floor($difference / (60*60*24)) . " Days"; } else { $payment_note = ""; $days = ""; } $invoice_tally_total = $invoice_amount + $invoice_tally_total; ?>
Invoice # Date Due Date Amount
Payments
- - - -