From 2741f78bd8ffd088755a74c5a029065133f929f8 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Tue, 17 Jun 2025 14:22:57 -0400 Subject: [PATCH] Fully Migrated Quote and Invoice to use TCPDF and elimiated PDFMake --- guest/guest_post.php | 432 +++++++++++++++++++++++++++++++ guest/guest_view_invoice.php | 475 +---------------------------------- guest/guest_view_quote.php | 434 +------------------------------- invoice.php | 4 +- post/user/invoice.php | 4 +- post/user/quote.php | 211 ++++++++++++++++ quote.php | 407 +----------------------------- 7 files changed, 667 insertions(+), 1300 deletions(-) diff --git a/guest/guest_post.php b/guest/guest_post.php index bead301c..f18c3fef 100644 --- a/guest/guest_post.php +++ b/guest/guest_post.php @@ -2,6 +2,7 @@ require_once "../config.php"; require_once "../functions.php"; +require_once "../includes/get_settings.php"; session_start(); @@ -201,6 +202,437 @@ if (isset($_GET['add_ticket_feedback'], $_GET['url_key'])) { } } +if (isset($_GET['export_quote_pdf'])) { + + $quote_id = intval($_GET['export_quote_pdf']); + $url_key = sanitizeInput($_GET['url_key']); + + $sql = mysqli_query( + $mysqli, + "SELECT * FROM quotes + LEFT JOIN clients ON quote_client_id = client_id + LEFT JOIN contacts ON clients.client_id = contacts.contact_client_id AND contact_primary = 1 + LEFT JOIN locations ON clients.client_id = locations.location_client_id AND location_primary = 1 + WHERE quote_id = $quote_id AND quote_url_key = '$url_key' + LIMIT 1" + ); + + if (mysqli_num_rows($sql) == 1) { + + $row = mysqli_fetch_array($sql); + $quote_id = intval($row['quote_id']); + $quote_prefix = nullable_htmlentities($row['quote_prefix']); + $quote_number = intval($row['quote_number']); + $quote_scope = nullable_htmlentities($row['quote_scope']); + $quote_status = nullable_htmlentities($row['quote_status']); + $quote_date = nullable_htmlentities($row['quote_date']); + $quote_expire = nullable_htmlentities($row['quote_expire']); + $quote_amount = floatval($row['quote_amount']); + $quote_discount = floatval($row['quote_discount_amount']); + $quote_currency_code = nullable_htmlentities($row['quote_currency_code']); + $quote_note = nullable_htmlentities($row['quote_note']); + $quote_url_key = nullable_htmlentities($row['quote_url_key']); + $quote_created_at = nullable_htmlentities($row['quote_created_at']); + $category_id = intval($row['quote_category_id']); + $client_id = intval($row['client_id']); + $client_name = nullable_htmlentities($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']); + if ($client_net_terms == 0) { + $client_net_terms = $config_default_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_id = intval($row['company_id']); + $company_name = nullable_htmlentities($row['company_name']); + $company_country = nullable_htmlentities($row['company_country']); + $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_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_logo = nullable_htmlentities($row['company_logo']); + $company_locale = nullable_htmlentities($row['company_locale']); + //Set Currency Format + $currency_format = numfmt_create($company_locale, NumberFormatter::CURRENCY); + + require_once("../plugins/TCPDF/tcpdf.php"); + + // Start TCPDF + $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); + $pdf->SetMargins(15, 15, 15); + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + $pdf->AddPage(); + $pdf->SetFont('helvetica', '', 10); + + // Logo + Right Columns + $html = ' + + + + +
'; + if (!empty($company_logo)) { + $logo_path = "../uploads/settings/$company_logo"; + if (file_exists($logo_path)) { + $pdf->Image($logo_path, $pdf->GetX(), $pdf->GetY(), 40); + } + } + $html .= ' + QUOTE
+ ' . $quote_prefix . $quote_number . '
'; + if (strtolower($quote_status) === 'accepted') { + $html .= 'ACCEPTED
'; + } + if (strtolower($quote_status) === 'declined') { + $html .= 'DECLINED
'; + } + $html .= '


'; + + // Billing titles + $html .= ' + + + + + + + + +
' . $company_name . '' . $client_name . '
' . nl2br("$company_address\n$company_city $company_state $company_zip\n$company_country\n$company_phone\n$company_website") . '' . nl2br("$location_address\n$location_city $location_state $location_zip\n$location_country\n$contact_email\n$contact_phone") . '

'; + + // Date table + $html .= ' + + + + + + + + + + +
Date:' . $quote_date . '
Expires:' . $quote_expire . '


'; + + // Items header + $html .= ' + + + + + + + + '; + + // Load items + $sql_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_quote_id = $quote_id ORDER BY item_order ASC"); + while ($item = mysqli_fetch_array($sql_items)) { + $name = $item['item_name']; + $desc = $item['item_description']; + $qty = $item['item_quantity']; + $price = $item['item_price']; + $tax = $item['item_tax']; + $total = $item['item_total']; + + $sub_total += $price * $qty; + $total_tax += $tax; + + $html .= ' + + + + + + + '; + } + + $html .= '
ItemQtyPriceTaxAmount
+ ' . $name . '
+ ' . nl2br($desc) . ' +
' . number_format($qty, 2) . '' . numfmt_format_currency($currency_format, $price, $quote_currency_code) . '' . numfmt_format_currency($currency_format, $tax, $quote_currency_code) . '' . numfmt_format_currency($currency_format, $total, $quote_currency_code) . '




'; + + // Totals + $html .= ' + + + + +
' . nl2br($quote_note) . ' + + '; + if ($quote_discount > 0) { + $html .= ''; + } + if ($total_tax > 0) { + $html .= ''; + } + $html .= ' + +
Subtotal:' . numfmt_format_currency($currency_format, $sub_total, $quote_currency_code) . '
Discount:-' . numfmt_format_currency($currency_format, $quote_discount, $quote_currency_code) . '
Tax:' . numfmt_format_currency($currency_format, $total_tax, $quote_currency_code) . '

Total:

' . numfmt_format_currency($currency_format, $quote_amount, $quote_currency_code) . '

+


'; + + // Footer + $html .= '
' . nl2br($config_quote_footer) . '
'; + + $pdf->writeHTML($html, true, false, true, false, ''); + + $filename = preg_replace('/[^A-Za-z0-9_\-]/', '_', "{$quote_date}_{$company_name}_{$client_name}_Quote_{$quote_prefix}{$quote_number}"); + $pdf->Output("$filename.pdf", 'I'); + } + exit; +} + +if (isset($_GET['export_invoice_pdf'])) { + + $invoice_id = intval($_GET['export_invoice_pdf']); + $url_key = sanitizeInput($_GET['url_key']); + + $sql = mysqli_query( + $mysqli, + "SELECT * FROM invoices + LEFT JOIN clients ON invoice_client_id = client_id + LEFT JOIN contacts ON clients.client_id = contacts.contact_client_id AND contact_primary = 1 + LEFT JOIN locations ON clients.client_id = locations.location_client_id AND location_primary = 1 + WHERE invoice_id = $invoice_id AND invoice_url_key = '$url_key' + LIMIT 1" + ); + + if (mysqli_num_rows($sql) == 1) { + + $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_scope = nullable_htmlentities($row['invoice_scope']); + $invoice_status = nullable_htmlentities($row['invoice_status']); + $invoice_date = nullable_htmlentities($row['invoice_date']); + $invoice_due = nullable_htmlentities($row['invoice_due']); + $invoice_amount = floatval($row['invoice_amount']); + $invoice_discount = floatval($row['invoice_discount_amount']); + $invoice_currency_code = nullable_htmlentities($row['invoice_currency_code']); + $invoice_note = nullable_htmlentities($row['invoice_note']); + $invoice_url_key = nullable_htmlentities($row['invoice_url_key']); + $invoice_created_at = nullable_htmlentities($row['invoice_created_at']); + $category_id = intval($row['invoice_category_id']); + $client_id = intval($row['client_id']); + $client_name = nullable_htmlentities($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']); + if ($client_net_terms == 0) { + $client_net_terms = $config_default_net_terms; + } + + $sql = mysqli_query($mysqli, "SELECT * FROM companies WHERE company_id = 1"); + $row = mysqli_fetch_array($sql); + $company_id = intval($row['company_id']); + $company_name = nullable_htmlentities($row['company_name']); + $company_country = nullable_htmlentities($row['company_country']); + $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_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']); + $company_locale = nullable_htmlentities($row['company_locale']); + //Set Currency Format + $currency_format = numfmt_create($company_locale, NumberFormatter::CURRENCY); + + $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 + 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_overdue = "Overdue"; + } + } + + //Set Badge color based off of invoice status + $invoice_badge_color = getInvoiceBadgeColor($invoice_status); + + require_once("../plugins/TCPDF/tcpdf.php"); + + // Start TCPDF + $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); + $pdf->SetMargins(15, 15, 15); + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + $pdf->AddPage(); + $pdf->SetFont('helvetica', '', 10); + + // Logo + Right Columns + $html = ' + + + + +
'; + if (!empty($company_logo)) { + $logo_path = "../uploads/settings/$company_logo"; + if (file_exists($logo_path)) { + $pdf->Image($logo_path, $pdf->GetX(), $pdf->GetY(), 40); + } + } + $html .= ' + Invoice
+ ' . $invoice_prefix . $invoice_number . '
'; + if (strtolower($invoice_status) === 'paid') { + $html .= 'PAID
'; + } + $html .= '


'; + + // Billing titles + $html .= ' + + + + + + + + +
' . $company_name . '' . $client_name . '
' . nl2br("$company_address\n$company_city $company_state $company_zip\n$company_country\n$company_phone\n$company_website\n$company_tax_id_display") . '' . nl2br("$location_address\n$location_city $location_state $location_zip\n$location_country\n$contact_email\n$contact_phone") . '

'; + + // Date table + $html .= ' + + + + + + + + + + +
Date:' . $invoice_date . '
Due:' . $invoice_due . '


'; + + // Items header + $html .= ' + + + + + + + + '; + + // Load items + $sql_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_invoice_id = $invoice_id ORDER BY item_order ASC"); + while ($item = mysqli_fetch_array($sql_items)) { + $name = $item['item_name']; + $desc = $item['item_description']; + $qty = $item['item_quantity']; + $price = $item['item_price']; + $tax = $item['item_tax']; + $total = $item['item_total']; + + $sub_total += $price * $qty; + $total_tax += $tax; + + $html .= ' + + + + + + + '; + } + + $html .= '
ItemQtyPriceTaxAmount
+ ' . $name . '
+ ' . nl2br($desc) . ' +
' . number_format($qty, 2) . '' . numfmt_format_currency($currency_format, $price, $invoice_currency_code) . '' . numfmt_format_currency($currency_format, $tax, $invoice_currency_code) . '' . numfmt_format_currency($currency_format, $total, $invoice_currency_code) . '




'; + + // Totals + $html .= ' + + + + +
' . nl2br($invoice_note) . ' + + '; + if ($invoice_discount > 0) { + $html .= ''; + } + if ($total_tax > 0) { + $html .= ''; + } + $html .= ' + '; + if ($amount_paid > 0) { + $html .= ''; + } + $html .= ' + +
Subtotal:' . numfmt_format_currency($currency_format, $sub_total, $invoice_currency_code) . '
Discount:-' . numfmt_format_currency($currency_format, $invoice_discount, $invoice_currency_code) . '
Tax:' . numfmt_format_currency($currency_format, $total_tax, $invoice_currency_code) . '
Total:' . numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code) . '
Paid:' . numfmt_format_currency($currency_format, $amount_paid, $invoice_currency_code) . '

Balance:

' . numfmt_format_currency($currency_format, $balance, $invoice_currency_code) . '

+


'; + + // Footer + $html .= '
' . nl2br($config_invoice_footer) . '
'; + + $pdf->writeHTML($html, true, false, true, false, ''); + + $filename = preg_replace('/[^A-Za-z0-9_\-]/', '_', "{$invoice_date}_{$company_name}_{$client_name}_Invoice_{$invoice_prefix}{$invoice_number}"); + $pdf->Output("$filename.pdf", 'I'); + } + + exit; + +} + if (isset($_POST['guest_quote_upload_file'])) { $quote_id = intval($_POST['quote_id']); $url_key = sanitizeInput($_POST['url_key']); diff --git a/guest/guest_view_invoice.php b/guest/guest_view_invoice.php index b6bfedb0..45d6e8f1 100644 --- a/guest/guest_view_invoice.php +++ b/guest/guest_view_invoice.php @@ -168,7 +168,9 @@ if ($balance > 0) {
Print - ');">Download + + Download + Pay Now @@ -180,10 +182,12 @@ if ($balance > 0) {
+
" alt="Company logo">
-
+ +
">
  • @@ -343,473 +347,6 @@ if ($balance > 0) {
- - - - Print - ');"> + Download
@@ -131,10 +131,12 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie
+
" alt="Company logo">
-
+ +
">
  • @@ -297,434 +299,6 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie
- - - -
+
" alt="Company logo">
-
+ +
">
  • diff --git a/post/user/invoice.php b/post/user/invoice.php index 3538d0d8..d41283a2 100644 --- a/post/user/invoice.php +++ b/post/user/invoice.php @@ -2002,9 +2002,7 @@ if (isset($_GET['export_invoice_pdf'])) { // Totals $html .= ' - +
    - Notes:
    ' . nl2br($invoice_note) . ' -
    ' . nl2br($invoice_note) . ' '; diff --git a/post/user/quote.php b/post/user/quote.php index b144aed5..8266b1eb 100644 --- a/post/user/quote.php +++ b/post/user/quote.php @@ -601,3 +601,214 @@ if(isset($_POST['export_quotes_csv'])){ exit; } + +if (isset($_GET['export_quote_pdf'])) { + + $quote_id = intval($_GET['export_quote_pdf']); + + $sql = mysqli_query( + $mysqli, + "SELECT * FROM quotes + LEFT JOIN clients ON quote_client_id = client_id + LEFT JOIN contacts ON clients.client_id = contacts.contact_client_id AND contact_primary = 1 + LEFT JOIN locations ON clients.client_id = locations.location_client_id AND location_primary = 1 + WHERE quote_id = $quote_id + $access_permission_query + LIMIT 1" + ); + + $row = mysqli_fetch_array($sql); + $quote_id = intval($row['quote_id']); + $quote_prefix = nullable_htmlentities($row['quote_prefix']); + $quote_number = intval($row['quote_number']); + $quote_scope = nullable_htmlentities($row['quote_scope']); + $quote_status = nullable_htmlentities($row['quote_status']); + $quote_date = nullable_htmlentities($row['quote_date']); + $quote_expire = nullable_htmlentities($row['quote_expire']); + $quote_amount = floatval($row['quote_amount']); + $quote_discount = floatval($row['quote_discount_amount']); + $quote_currency_code = nullable_htmlentities($row['quote_currency_code']); + $quote_note = nullable_htmlentities($row['quote_note']); + $quote_url_key = nullable_htmlentities($row['quote_url_key']); + $quote_created_at = nullable_htmlentities($row['quote_created_at']); + $category_id = intval($row['quote_category_id']); + $client_id = intval($row['client_id']); + $client_name = nullable_htmlentities($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']); + if ($client_net_terms == 0) { + $client_net_terms = $config_default_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_id = intval($row['company_id']); + $company_name = nullable_htmlentities($row['company_name']); + $company_country = nullable_htmlentities($row['company_country']); + $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_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_logo = nullable_htmlentities($row['company_logo']); + + //Set Badge color based off of quote status + if ($quote_status == "Sent") { + $quote_badge_color = "warning text-white"; + } elseif ($quote_status == "Viewed") { + $quote_badge_color = "primary"; + } elseif ($quote_status == "Accepted") { + $quote_badge_color = "success"; + } elseif ($quote_status == "Declined") { + $quote_badge_color = "danger"; + } elseif ($quote_status == "Invoiced") { + $quote_badge_color = "info"; + } else { + $quote_badge_color = "secondary"; + } + + require_once("plugins/TCPDF/tcpdf.php"); + + // Start TCPDF + $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); + $pdf->SetMargins(15, 15, 15); + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + $pdf->AddPage(); + $pdf->SetFont('helvetica', '', 10); + + // Logo + Right Columns + $html = '
    Subtotal:' . numfmt_format_currency($currency_format, $sub_total, $invoice_currency_code) . '
    + + + + +
    '; + if (!empty($company_logo)) { + $logo_path = "uploads/settings/$company_logo"; + if (file_exists($logo_path)) { + $pdf->Image($logo_path, $pdf->GetX(), $pdf->GetY(), 40); + } + } + $html .= ' + QUOTE
    + ' . $quote_prefix . $quote_number . '
    '; + if (strtolower($quote_status) === 'accepted') { + $html .= 'ACCEPTED
    '; + } + if (strtolower($quote_status) === 'declined') { + $html .= 'DECLINED
    '; + } + $html .= '


    '; + + // Billing titles + $html .= ' + + + + + + + + +
    ' . $company_name . '' . $client_name . '
    ' . nl2br("$company_address\n$company_city $company_state $company_zip\n$company_country\n$company_phone\n$company_website") . '' . nl2br("$location_address\n$location_city $location_state $location_zip\n$location_country\n$contact_email\n$contact_phone") . '

    '; + + // Date table + $html .= ' + + + + + + + + + + +
    Date:' . $quote_date . '
    Expires:' . $quote_expire . '


    '; + + // Items header + $html .= ' + + + + + + + + '; + + // Load items + $sql_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_quote_id = $quote_id ORDER BY item_order ASC"); + while ($item = mysqli_fetch_array($sql_items)) { + $name = $item['item_name']; + $desc = $item['item_description']; + $qty = $item['item_quantity']; + $price = $item['item_price']; + $tax = $item['item_tax']; + $total = $item['item_total']; + + $sub_total += $price * $qty; + $total_tax += $tax; + + $html .= ' + + + + + + + '; + } + + $html .= '
    ItemQtyPriceTaxAmount
    + ' . $name . '
    + ' . nl2br($desc) . ' +
    ' . number_format($qty, 2) . '' . numfmt_format_currency($currency_format, $price, $quote_currency_code) . '' . numfmt_format_currency($currency_format, $tax, $quote_currency_code) . '' . numfmt_format_currency($currency_format, $total, $quote_currency_code) . '




    '; + + // Totals + $html .= ' + + + + +
    ' . nl2br($quote_note) . ' + + '; + if ($quote_discount > 0) { + $html .= ''; + } + if ($total_tax > 0) { + $html .= ''; + } + $html .= ' + +
    Subtotal:' . numfmt_format_currency($currency_format, $sub_total, $quote_currency_code) . '
    Discount:-' . numfmt_format_currency($currency_format, $quote_discount, $quote_currency_code) . '
    Tax:' . numfmt_format_currency($currency_format, $total_tax, $quote_currency_code) . '

    Total:

    ' . numfmt_format_currency($currency_format, $quote_amount, $quote_currency_code) . '

    +


    '; + + // Footer + $html .= '
    ' . nl2br($config_quote_footer) . '
    '; + + $pdf->writeHTML($html, true, false, true, false, ''); + + $filename = preg_replace('/[^A-Za-z0-9_\-]/', '_', "{$quote_date}_{$company_name}_{$client_name}_Quote_{$quote_prefix}{$quote_number}"); + $pdf->Output("$filename.pdf", 'I'); + exit; + +} diff --git a/quote.php b/quote.php index 9680a4ef..aca9028e 100644 --- a/quote.php +++ b/quote.php @@ -26,7 +26,12 @@ if (isset($_GET['quote_id'])) { ); if (mysqli_num_rows($sql) == 0) { - echo '

    Nothing to see here

    '; + if (isset($_GET['client_id'])) { + $backlink_append = "?client_id=$client_id"; + } else { + $backlink_append = ''; + } + echo "

    There is no Quote here
    Back to Quotes

    "; require_once "includes/footer.php"; exit(); @@ -221,7 +226,7 @@ if (isset($_GET['quote_id'])) { Print - ');"> + Download PDF @@ -248,10 +253,12 @@ if (isset($_GET['quote_id'])) {
    +
    " alt="Company logo">
    -
    + +
    ">
    • @@ -613,400 +620,6 @@ require_once "includes/footer.php"; }); - - - -