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

"; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/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 clients.client_id = locations.location_client_id AND location_primary = 1 LEFT JOIN contacts ON clients.client_id = contacts.contact_client_id AND contact_primary = 1 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 $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php'; exit(); } $row = mysqli_fetch_array($sql); $invoice_id = intval($row['invoice_id']); $invoice_prefix = nullable_htmlentities($row['invoice_prefix']); $invoice_number = intval($row['invoice_number']); $invoice_status = nullable_htmlentities($row['invoice_status']); $invoice_date = nullable_htmlentities($row['invoice_date']); $invoice_due = nullable_htmlentities($row['invoice_due']); $invoice_discount = floatval($row['invoice_discount_amount']); $invoice_amount = floatval($row['invoice_amount']); $invoice_currency_code = nullable_htmlentities($row['invoice_currency_code']); $invoice_note = nullable_htmlentities($row['invoice_note']); $invoice_category_id = intval($row['invoice_category_id']); $client_id = intval($row['client_id']); $client_name = nullable_htmlentities($row['client_name']); $client_name_escaped = sanitizeInput($row['client_name']); $location_address = nullable_htmlentities($row['location_address']); $location_city = nullable_htmlentities($row['location_city']); $location_state = nullable_htmlentities($row['location_state']); $location_zip = nullable_htmlentities($row['location_zip']); $location_country = nullable_htmlentities($row['location_country']); $contact_email = nullable_htmlentities($row['contact_email']); $contact_phone_country_code = nullable_htmlentities($row['contact_phone_country_code']); $contact_phone = nullable_htmlentities(formatPhoneNumber($row['contact_phone'], $contact_phone_country_code)); $contact_extension = nullable_htmlentities($row['contact_extension']); $contact_mobile_country_code = nullable_htmlentities($row['contact_mobile_country_code']); $contact_mobile = nullable_htmlentities(formatPhoneNumber($row['contact_mobile'], $contact_mobile_country_code)); $client_website = nullable_htmlentities($row['client_website']); $client_currency_code = nullable_htmlentities($row['client_currency_code']); $client_net_terms = intval($row['client_net_terms']); $sql = mysqli_query($mysqli, "SELECT * FROM companies, settings WHERE companies.company_id = settings.company_id AND companies.company_id = 1"); $row = mysqli_fetch_array($sql); $company_name = nullable_htmlentities($row['company_name']); $company_address = nullable_htmlentities($row['company_address']); $company_city = nullable_htmlentities($row['company_city']); $company_state = nullable_htmlentities($row['company_state']); $company_zip = nullable_htmlentities($row['company_zip']); $company_country = nullable_htmlentities($row['company_country']); $company_phone_country_code = nullable_htmlentities($row['company_phone_country_code']); $company_phone = nullable_htmlentities(formatPhoneNumber($row['company_phone'], $company_phone_country_code)); $company_email = nullable_htmlentities($row['company_email']); $company_website = nullable_htmlentities($row['company_website']); $company_tax_id = nullable_htmlentities($row['company_tax_id']); if ($config_invoice_show_tax_id && !empty($company_tax_id)) { $company_tax_id_display = "Tax ID: $company_tax_id"; } else { $company_tax_id_display = ""; } $company_logo = nullable_htmlentities($row['company_logo']); if (!empty($company_logo)) { $company_logo_base64 = base64_encode(file_get_contents("../uploads/settings/$company_logo")); } $company_locale = nullable_htmlentities($row['company_locale']); $config_invoice_footer = nullable_htmlentities($row['config_invoice_footer']); // Get Payment Provide Details $sql = mysqli_query($mysqli, "SELECT * FROM payment_providers WHERE payment_provider_active = 1 LIMIT 1"); $row = mysqli_fetch_array($sql); $payment_provider_id = intval($row['payment_provider_id']); $payment_provider_name = nullable_htmlentities($row['payment_provider_name']); $payment_provider_threshold = floatval($row['payment_provider_threshold']); //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"); if ($invoice_status !== 'Paid') { appNotify("Invoice Viewed", "Invoice $invoice_prefix$invoice_number has been viewed by $client_name_escaped - $ip - $os - $browser", "/agent/invoice.php?invoice_id=$invoice_id", $client_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']); // Calculate the balance owed $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" && $invoice_status !== "Non-Billable") { $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_order ASC"); // Get Total Account Balance //Add up all the payments for the invoice and get the total amount paid to the invoice $sql_invoice_amounts = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS invoice_amounts FROM invoices WHERE invoice_client_id = $client_id AND invoice_status != 'Draft' AND invoice_status != 'Cancelled' AND invoice_status != 'Non-Billable'"); $row = mysqli_fetch_array($sql_invoice_amounts); $account_balance = floatval($row['invoice_amounts']); $sql_amount_paid = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS amount_paid FROM payments, invoices WHERE payment_invoice_id = invoice_id AND invoice_client_id = $client_id"); $row = mysqli_fetch_array($sql_amount_paid); $account_amount_paid = floatval($row['amount_paid']); $account_balance = $account_balance - $account_amount_paid; //set Text color on balance if ($balance > 0) { $balance_text_color = "text-danger font-weight-bold"; } else { $balance_text_color = ""; } ?>

Account Balance:

Print Download $invoice_amount ) ){ ?> Pay Now
" alt="Company logo">
">

INVOICE

Invoice #:
Date:
Due:
Bill To:
Item Description Qty Unit Price Tax Amount
0) { ?> 0) { ?> 0) { ?>
Subtotal:
Discount: -
Tax:
Total:
Paid:
Balance:

CURDATE() AND(invoice_status = 'Sent' OR invoice_status = 'Viewed' OR invoice_status = 'Partial') ORDER BY invoice_number DESC"); $current_invoices_count = mysqli_num_rows($sql_current_invoices); if ($current_invoices_count > 0) { ?>
Current Invoices
>
Invoice Date Due Amount
(Due in Days)
0) { ?>
Outstanding Invoices
>
Invoice Date Due Amount
(Over Due by Days)