mirror of https://github.com/itflow-org/itflow
Fully Migrated Quote and Invoice to use TCPDF and elimiated PDFMake
This commit is contained in:
parent
012e54161a
commit
2741f78bd8
|
|
@ -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 = '<table width="100%" cellspacing="0" cellpadding="5">
|
||||
<tr>
|
||||
<td width="40%">';
|
||||
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 .= '</td>
|
||||
<td width="60%" align="right">
|
||||
<span style="font-size:18pt; font-weight:bold;">QUOTE</span><br>
|
||||
<span style="font-size:14pt;">' . $quote_prefix . $quote_number . '</span><br>';
|
||||
if (strtolower($quote_status) === 'accepted') {
|
||||
$html .= '<span style="color:green; font-weight:bold;">ACCEPTED</span><br>';
|
||||
}
|
||||
if (strtolower($quote_status) === 'declined') {
|
||||
$html .= '<span style="color:red; font-weight:bold;">DECLINED</span><br>';
|
||||
}
|
||||
$html .= '</td>
|
||||
</tr>
|
||||
</table><br><br>';
|
||||
|
||||
// Billing titles
|
||||
$html .= '<table width="100%" cellspacing="0" cellpadding="2">
|
||||
<tr>
|
||||
<td width="50%" style="font-size:14pt; font-weight:bold;">' . $company_name . '</td>
|
||||
<td width="50%" align="right" style="font-size:14pt; font-weight:bold;">' . $client_name . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-size:10pt; line-height:1.4;">' . nl2br("$company_address\n$company_city $company_state $company_zip\n$company_country\n$company_phone\n$company_website") . '</td>
|
||||
<td style="font-size:10pt; line-height:1.4;" align="right">' . nl2br("$location_address\n$location_city $location_state $location_zip\n$location_country\n$contact_email\n$contact_phone") . '</td>
|
||||
</tr>
|
||||
</table><br>';
|
||||
|
||||
// Date table
|
||||
$html .= '<table border="0" cellpadding="3" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td width="60%"></td>
|
||||
<td width="20%" style="font-size:10pt;"><strong>Date:</strong></td>
|
||||
<td width="20%" style="font-size:10pt;" align="right">' . $quote_date . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td style="font-size:10pt;"><strong>Expires:</strong></td>
|
||||
<td style="font-size:10pt;" align="right">' . $quote_expire . '</td>
|
||||
</tr>
|
||||
</table><br><br>';
|
||||
|
||||
// Items header
|
||||
$html .= '
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%">
|
||||
<tr style="background-color:#f0f0f0;">
|
||||
<th align="left" width="40%"><strong>Item</strong></th>
|
||||
<th align="center" width="10%"><strong>Qty</strong></th>
|
||||
<th align="right" width="15%"><strong>Price</strong></th>
|
||||
<th align="right" width="15%"><strong>Tax</strong></th>
|
||||
<th align="right" width="20%"><strong>Amount</strong></th>
|
||||
</tr>';
|
||||
|
||||
// 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 .= '
|
||||
<tr>
|
||||
<td>
|
||||
<strong>' . $name . '</strong><br>
|
||||
<span style="font-style:italic; font-size:9pt;">' . nl2br($desc) . '</span>
|
||||
</td>
|
||||
<td align="center">' . number_format($qty, 2) . '</td>
|
||||
<td align="right">' . numfmt_format_currency($currency_format, $price, $quote_currency_code) . '</td>
|
||||
<td align="right">' . numfmt_format_currency($currency_format, $tax, $quote_currency_code) . '</td>
|
||||
<td align="right">' . numfmt_format_currency($currency_format, $total, $quote_currency_code) . '</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
$html .= '</table><br><hr><br><br>';
|
||||
|
||||
// Totals
|
||||
$html .= '<table width="100%" cellspacing="0" cellpadding="4">
|
||||
<tr>
|
||||
<td width="70%" rowspan="6" valign="top"><i>' . nl2br($quote_note) . '</i></td>
|
||||
<td width="30%">
|
||||
<table width="100%" cellpadding="3" cellspacing="0">
|
||||
<tr><td>Subtotal:</td><td align="right">' . numfmt_format_currency($currency_format, $sub_total, $quote_currency_code) . '</td></tr>';
|
||||
if ($quote_discount > 0) {
|
||||
$html .= '<tr><td>Discount:</td><td align="right">-' . numfmt_format_currency($currency_format, $quote_discount, $quote_currency_code) . '</td></tr>';
|
||||
}
|
||||
if ($total_tax > 0) {
|
||||
$html .= '<tr><td>Tax:</td><td align="right">' . numfmt_format_currency($currency_format, $total_tax, $quote_currency_code) . '</td></tr>';
|
||||
}
|
||||
$html .= '
|
||||
<tr><td><h3><strong>Total:</strong></h3></td><td align="right"><h3><strong>' . numfmt_format_currency($currency_format, $quote_amount, $quote_currency_code) . '</strong></h3></td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table><br><br>';
|
||||
|
||||
// Footer
|
||||
$html .= '<div style="text-align:center; font-size:9pt; color:gray;">' . nl2br($config_quote_footer) . '</div>';
|
||||
|
||||
$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 = '<table width="100%" cellspacing="0" cellpadding="5">
|
||||
<tr>
|
||||
<td width="40%">';
|
||||
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 .= '</td>
|
||||
<td width="60%" align="right">
|
||||
<span style="font-size:18pt; font-weight:bold;">Invoice</span><br>
|
||||
<span style="font-size:14pt;">' . $invoice_prefix . $invoice_number . '</span><br>';
|
||||
if (strtolower($invoice_status) === 'paid') {
|
||||
$html .= '<span style="color:green; font-weight:bold;">PAID</span><br>';
|
||||
}
|
||||
$html .= '</td>
|
||||
</tr>
|
||||
</table><br><br>';
|
||||
|
||||
// Billing titles
|
||||
$html .= '<table width="100%" cellspacing="0" cellpadding="2">
|
||||
<tr>
|
||||
<td width="50%" style="font-size:14pt; font-weight:bold;">' . $company_name . '</td>
|
||||
<td width="50%" align="right" style="font-size:14pt; font-weight:bold;">' . $client_name . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-size:10pt; line-height:1.4;">' . nl2br("$company_address\n$company_city $company_state $company_zip\n$company_country\n$company_phone\n$company_website\n$company_tax_id_display") . '</td>
|
||||
<td style="font-size:10pt; line-height:1.4;" align="right">' . nl2br("$location_address\n$location_city $location_state $location_zip\n$location_country\n$contact_email\n$contact_phone") . '</td>
|
||||
</tr>
|
||||
</table><br>';
|
||||
|
||||
// Date table
|
||||
$html .= '<table border="0" cellpadding="3" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td width="60%"></td>
|
||||
<td width="20%" style="font-size:10pt;"><strong>Date:</strong></td>
|
||||
<td width="20%" style="font-size:10pt;" align="right">' . $invoice_date . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td style="font-size:10pt;"><strong>Due:</strong></td>
|
||||
<td style="font-size:10pt;" align="right">' . $invoice_due . '</td>
|
||||
</tr>
|
||||
</table><br><br>';
|
||||
|
||||
// Items header
|
||||
$html .= '
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%">
|
||||
<tr style="background-color:#f0f0f0;">
|
||||
<th align="left" width="40%"><strong>Item</strong></th>
|
||||
<th align="center" width="10%"><strong>Qty</strong></th>
|
||||
<th align="right" width="15%"><strong>Price</strong></th>
|
||||
<th align="right" width="15%"><strong>Tax</strong></th>
|
||||
<th align="right" width="20%"><strong>Amount</strong></th>
|
||||
</tr>';
|
||||
|
||||
// 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 .= '
|
||||
<tr>
|
||||
<td>
|
||||
<strong>' . $name . '</strong><br>
|
||||
<span style="font-style:italic; font-size:9pt;">' . nl2br($desc) . '</span>
|
||||
</td>
|
||||
<td align="center">' . number_format($qty, 2) . '</td>
|
||||
<td align="right">' . numfmt_format_currency($currency_format, $price, $invoice_currency_code) . '</td>
|
||||
<td align="right">' . numfmt_format_currency($currency_format, $tax, $invoice_currency_code) . '</td>
|
||||
<td align="right">' . numfmt_format_currency($currency_format, $total, $invoice_currency_code) . '</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
$html .= '</table><br><hr><br><br>';
|
||||
|
||||
// Totals
|
||||
$html .= '<table width="100%" cellspacing="0" cellpadding="4">
|
||||
<tr>
|
||||
<td width="70%" rowspan="6" valign="top"><i>' . nl2br($invoice_note) . '</i></td>
|
||||
<td width="30%">
|
||||
<table width="100%" cellpadding="3" cellspacing="0">
|
||||
<tr><td>Subtotal:</td><td align="right">' . numfmt_format_currency($currency_format, $sub_total, $invoice_currency_code) . '</td></tr>';
|
||||
if ($invoice_discount > 0) {
|
||||
$html .= '<tr><td>Discount:</td><td align="right">-' . numfmt_format_currency($currency_format, $invoice_discount, $invoice_currency_code) . '</td></tr>';
|
||||
}
|
||||
if ($total_tax > 0) {
|
||||
$html .= '<tr><td>Tax:</td><td align="right">' . numfmt_format_currency($currency_format, $total_tax, $invoice_currency_code) . '</td></tr>';
|
||||
}
|
||||
$html .= '
|
||||
<tr><td>Total:</td><td align="right">' . numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code) . '</td></tr>';
|
||||
if ($amount_paid > 0) {
|
||||
$html .= '<tr><td>Paid:</td><td align="right">' . numfmt_format_currency($currency_format, $amount_paid, $invoice_currency_code) . '</td></tr>';
|
||||
}
|
||||
$html .= '
|
||||
<tr><td><h3><strong>Balance:</strong></h3></td><td align="right"><h3><strong>' . numfmt_format_currency($currency_format, $balance, $invoice_currency_code) . '</strong></h3></td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table><br><br>';
|
||||
|
||||
// Footer
|
||||
$html .= '<div style="text-align:center; font-size:9pt; color:gray;">' . nl2br($config_invoice_footer) . '</div>';
|
||||
|
||||
$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']);
|
||||
|
|
|
|||
|
|
@ -168,7 +168,9 @@ if ($balance > 0) {
|
|||
<div class="col-6">
|
||||
<div class="float-right">
|
||||
<a class="btn btn-default" href="#" onclick="window.print();"><i class="fas fa-fw fa-print mr-2"></i>Print</a>
|
||||
<a class="btn btn-default" href="#" onclick="pdfMake.createPdf(docDefinition).download('<?php echo strtoAZaz09(html_entity_decode("$invoice_date-$company_name-Invoice-$invoice_prefix$invoice_number")); ?>');"><i class="fa fa-fw fa-download mr-2"></i>Download</a>
|
||||
<a class="btn btn-default" href="guest_post.php?export_invoice_pdf=<?php echo $invoice_id; ?>&url_key=<?php echo $url_key; ?>">
|
||||
<i class="fa fa-fw fa-download mr-2"></i>Download
|
||||
</a>
|
||||
<?php
|
||||
if ($invoice_status !== "Paid" && $invoice_status !== "Cancelled" && $invoice_status !== "Draft" && $config_stripe_enable == 1) { ?>
|
||||
<a class="btn btn-success" href="guest_pay_invoice_stripe.php?invoice_id=<?php echo $invoice_id; ?>&url_key=<?php echo $url_key; ?>"><i class="fa fa-fw fa-credit-card mr-2"></i>Pay Now </a>
|
||||
|
|
@ -180,10 +182,12 @@ if ($balance > 0) {
|
|||
<div class="card-body">
|
||||
|
||||
<div class="row mb-3">
|
||||
<?php if (file_exists("../uploads/settings/$company_logo")) { ?>
|
||||
<div class="col-sm-2">
|
||||
<img class="img-fluid" src="<?php echo "../uploads/settings/$company_logo"; ?>" alt="Company logo">
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<?php } ?>
|
||||
<div class="col-sm-6 <?php if (!file_exists("../uploads/settings/$company_logo")) { echo "col-sm-8"; } ?>">
|
||||
<ul class="list-unstyled">
|
||||
<li><h4><strong><?php echo $company_name; ?></strong></h4></li>
|
||||
<li><?php echo $company_address; ?></li>
|
||||
|
|
@ -343,473 +347,6 @@ if ($balance > 0) {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script src='../plugins/pdfmake/pdfmake.min.js'></script>
|
||||
<script src='../plugins/pdfmake/vfs_fonts.js'></script>
|
||||
<script>
|
||||
|
||||
var docDefinition = {
|
||||
info: {
|
||||
title: <?php echo json_encode(html_entity_decode($company_name) . "- Invoice") ?>,
|
||||
author: <?php echo json_encode(html_entity_decode($company_name)) ?>
|
||||
},
|
||||
|
||||
//watermark: {text: '<?php echo $invoice_status; ?>', color: 'lightgrey', opacity: 0.3, bold: true, italics: false},
|
||||
|
||||
content: [
|
||||
// Header
|
||||
{
|
||||
columns: [
|
||||
<?php if (!empty($company_logo_base64)) { ?>
|
||||
{
|
||||
image: <?php echo json_encode("data:image;base64,$company_logo_base64") ?>,
|
||||
width: 120
|
||||
},
|
||||
<?php } ?>
|
||||
|
||||
[
|
||||
{
|
||||
text: 'Invoice',
|
||||
style: 'invoiceTitle',
|
||||
width: '*'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode("$invoice_prefix$invoice_number")) ?>,
|
||||
style: 'invoiceNumber',
|
||||
width: '*'
|
||||
},
|
||||
<?php if ($invoice_status == "Paid") { ?>
|
||||
{
|
||||
text: 'PAID',
|
||||
style: 'invoicePaid',
|
||||
width: '*'
|
||||
},
|
||||
<?php } ?>
|
||||
],
|
||||
],
|
||||
},
|
||||
// Billing Headers
|
||||
{
|
||||
columns: [
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode($company_name)) ?>,
|
||||
style: 'invoiceBillingTitle',
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode($client_name)) ?>,
|
||||
style: 'invoiceBillingTitleClient',
|
||||
},
|
||||
]
|
||||
},
|
||||
// Billing Address
|
||||
{
|
||||
columns: [
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode("$company_address \n $company_city $company_state $company_zip \n $company_country \n $company_phone \n $company_website \n $company_tax_id_display")) ?>,
|
||||
style: 'invoiceBillingAddress'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode("$location_address \n $location_city $location_state $location_zip \n $location_country \n $contact_email \n $contact_phone")) ?>,
|
||||
style: 'invoiceBillingAddressClient'
|
||||
},
|
||||
]
|
||||
},
|
||||
//Invoice Dates Table
|
||||
{
|
||||
table: {
|
||||
// headers are automatically repeated if the table spans over multiple pages
|
||||
// you can declare how many rows should be treated as headers
|
||||
headerRows: 0,
|
||||
widths: [ '*',80, 80 ],
|
||||
|
||||
body: [
|
||||
// Total
|
||||
[
|
||||
{
|
||||
text: '',
|
||||
rowSpan: 3
|
||||
},
|
||||
{},
|
||||
{},
|
||||
],
|
||||
[
|
||||
{},
|
||||
{
|
||||
text: 'Date',
|
||||
style: 'invoiceDateTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode($invoice_date)) ?>,
|
||||
style: 'invoiceDateValue'
|
||||
},
|
||||
],
|
||||
[
|
||||
{},
|
||||
{
|
||||
text: 'Due',
|
||||
style: 'invoiceDueDateTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode($invoice_due)) ?>,
|
||||
style: 'invoiceDueDateValue'
|
||||
},
|
||||
],
|
||||
]
|
||||
}, // table
|
||||
layout: 'lightHorizontalLines'
|
||||
},
|
||||
// Line breaks
|
||||
'\n\n',
|
||||
// Items
|
||||
{
|
||||
table: {
|
||||
// headers are automatically repeated if the table spans over multiple pages
|
||||
// you can declare how many rows should be treated as headers
|
||||
headerRows: 1,
|
||||
widths: [ '*', 40, 'auto', 'auto', 80 ],
|
||||
|
||||
body: [
|
||||
// Table Header
|
||||
[
|
||||
{
|
||||
text: 'Product',
|
||||
style: [ 'itemsHeader', 'left']
|
||||
},
|
||||
{
|
||||
text: 'Qty',
|
||||
style: [ 'itemsHeader', 'center']
|
||||
},
|
||||
{
|
||||
text: 'Price',
|
||||
style: [ 'itemsHeader', 'right']
|
||||
},
|
||||
{
|
||||
text: 'Tax',
|
||||
style: [ 'itemsHeader', 'right']
|
||||
},
|
||||
{
|
||||
text: 'Total',
|
||||
style: [ 'itemsHeader', 'right']
|
||||
}
|
||||
],
|
||||
// Items
|
||||
<?php
|
||||
$total_tax = 0;
|
||||
$sub_total = 0;
|
||||
|
||||
$sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_invoice_id = $invoice_id ORDER BY item_order ASC");
|
||||
|
||||
while ($row = mysqli_fetch_array($sql_invoice_items)) {
|
||||
$item_name = $row['item_name'];
|
||||
$item_description = $row['item_description'];
|
||||
$item_quantity = $row['item_quantity'];
|
||||
$item_price = $row['item_price'];
|
||||
$item_subtotal = $row['item_price'];
|
||||
$item_tax = $row['item_tax'];
|
||||
$item_total = $row['item_total'];
|
||||
$tax_id = $row['item_tax_id'];
|
||||
$total_tax = $item_tax + $total_tax;
|
||||
$sub_total = $item_price * $item_quantity + $sub_total;
|
||||
?>
|
||||
|
||||
// Item
|
||||
[
|
||||
[
|
||||
{
|
||||
text: <?php echo json_encode($item_name) ?>,
|
||||
style:'itemTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode($item_description) ?>,
|
||||
style:'itemDescription'
|
||||
}
|
||||
],
|
||||
{
|
||||
text: <?php echo json_encode($item_quantity) ?>,
|
||||
style: 'itemQty'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $item_price, $invoice_currency_code)) ?>,
|
||||
style: 'itemNumber'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $item_tax, $invoice_currency_code)) ?>,
|
||||
style: 'itemNumber'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $item_total, $invoice_currency_code)) ?>,
|
||||
style: 'itemNumber'
|
||||
}
|
||||
],
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
// END Items
|
||||
]
|
||||
}, // table
|
||||
layout: 'lightHorizontalLines'
|
||||
},
|
||||
// TOTAL
|
||||
{
|
||||
table: {
|
||||
// headers are automatically repeated if the table spans over multiple pages
|
||||
// you can declare how many rows should be treated as headers
|
||||
headerRows: 0,
|
||||
widths: [ '*','auto', 80 ],
|
||||
|
||||
body: [
|
||||
// Total
|
||||
[
|
||||
{
|
||||
text: 'Notes',
|
||||
style: 'notesTitle'
|
||||
},
|
||||
{},
|
||||
{}
|
||||
],
|
||||
[
|
||||
{
|
||||
rowSpan: '*',
|
||||
text: <?php echo json_encode(html_entity_decode($invoice_note)) ?>,
|
||||
style: 'notesText'
|
||||
},
|
||||
{
|
||||
text: 'Subtotal',
|
||||
style: 'itemsFooterSubTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $sub_total, $invoice_currency_code)) ?>,
|
||||
style: 'itemsFooterSubValue'
|
||||
}
|
||||
],
|
||||
<?php if ($invoice_discount > 0) { ?>
|
||||
[
|
||||
{},
|
||||
{
|
||||
text: 'Discount',
|
||||
style: 'itemsFooterSubTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, -$invoice_discount, $invoice_currency_code)) ?>,
|
||||
style: 'itemsFooterSubValue'
|
||||
}
|
||||
],
|
||||
<?php } ?>
|
||||
<?php if ($total_tax > 0) { ?>
|
||||
[
|
||||
{},
|
||||
{
|
||||
text: 'Tax',
|
||||
style: 'itemsFooterSubTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $total_tax, $invoice_currency_code)) ?>,
|
||||
style: 'itemsFooterSubValue'
|
||||
}
|
||||
],
|
||||
<?php } ?>
|
||||
[
|
||||
{},
|
||||
{
|
||||
text: 'Total',
|
||||
style: 'itemsFooterSubTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code)) ?>,
|
||||
style: 'itemsFooterSubValue'
|
||||
}
|
||||
],
|
||||
<?php if ($amount_paid > 0) { ?>
|
||||
[
|
||||
{},
|
||||
{
|
||||
text: 'Paid',
|
||||
style: 'itemsFooterSubTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $amount_paid, $invoice_currency_code)) ?>,
|
||||
style: 'itemsFooterSubValue'
|
||||
}
|
||||
],
|
||||
<?php } ?>
|
||||
[
|
||||
{},
|
||||
{
|
||||
text: 'Balance',
|
||||
style: 'itemsFooterTotalTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $balance, $invoice_currency_code)) ?>,
|
||||
|
||||
style: 'itemsFooterTotalTitle'
|
||||
}
|
||||
],
|
||||
]
|
||||
}, // table
|
||||
layout: 'lightHorizontalLines'
|
||||
},
|
||||
// TERMS / FOOTER
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode($config_invoice_footer)) ?>,
|
||||
style: 'documentFooterCenter'
|
||||
}
|
||||
], //End Content,
|
||||
styles: {
|
||||
// Document Footer
|
||||
documentFooterCenter: {
|
||||
fontSize: 9,
|
||||
margin: [10,50,10,10],
|
||||
alignment: 'center'
|
||||
},
|
||||
// Invoice Title
|
||||
invoiceTitle: {
|
||||
fontSize: 18,
|
||||
bold: true,
|
||||
alignment: 'right',
|
||||
margin: [0,0,0,3]
|
||||
},
|
||||
// Invoice Number
|
||||
invoiceNumber: {
|
||||
fontSize: 14,
|
||||
alignment: 'right'
|
||||
},
|
||||
// Invoice Paid
|
||||
invoicePaid: {
|
||||
fontSize: 13,
|
||||
bold: true,
|
||||
margin: [0,5,0,0],
|
||||
alignment: 'right',
|
||||
color: 'green'
|
||||
},
|
||||
// Billing Headers
|
||||
invoiceBillingTitle: {
|
||||
fontSize: 14,
|
||||
bold: true,
|
||||
alignment: 'left',
|
||||
margin: [0,20,0,5]
|
||||
},
|
||||
invoiceBillingTitleClient: {
|
||||
fontSize: 14,
|
||||
bold: true,
|
||||
alignment: 'right',
|
||||
margin: [0,20,0,5]
|
||||
},
|
||||
// Billing Details
|
||||
invoiceBillingAddress: {
|
||||
fontSize: 10,
|
||||
lineHeight: 1.2
|
||||
},
|
||||
invoiceBillingAddressClient: {
|
||||
fontSize: 10,
|
||||
lineHeight: 1.2,
|
||||
alignment: 'right',
|
||||
margin: [0,0,0,30]
|
||||
},
|
||||
// Invoice Date
|
||||
invoiceDateTitle: {
|
||||
fontSize: 10,
|
||||
alignment: 'left',
|
||||
margin: [0,5,0,5]
|
||||
},
|
||||
invoiceDateValue: {
|
||||
fontSize: 10,
|
||||
alignment: 'right',
|
||||
margin: [0,5,0,5]
|
||||
},
|
||||
// Invoice Due Date
|
||||
invoiceDueDateTitle: {
|
||||
fontSize: 10,
|
||||
bold: true,
|
||||
alignment: 'left',
|
||||
margin: [0,5,0,5]
|
||||
},
|
||||
invoiceDueDateValue: {
|
||||
fontSize: 10,
|
||||
bold: true,
|
||||
alignment: 'right',
|
||||
margin: [0,5,0,5]
|
||||
},
|
||||
// Items Header
|
||||
itemsHeader: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
bold: true,
|
||||
alignment: 'right'
|
||||
},
|
||||
// Item Title
|
||||
itemTitle: {
|
||||
fontSize: 10,
|
||||
bold: true,
|
||||
margin: [0,5,0,3]
|
||||
},
|
||||
itemDescription: {
|
||||
italics: true,
|
||||
fontSize: 9,
|
||||
lineHeight: 1.1,
|
||||
margin: [0,3,0,5]
|
||||
},
|
||||
itemQty: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
alignment: 'center'
|
||||
},
|
||||
itemNumber: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
alignment: 'right'
|
||||
},
|
||||
itemTotal: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
bold: true,
|
||||
alignment: 'right'
|
||||
},
|
||||
// Items Footer (Subtotal, Total, Tax, etc)
|
||||
itemsFooterSubTitle: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
alignment: 'right'
|
||||
},
|
||||
itemsFooterSubValue: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
bold: false,
|
||||
alignment: 'right'
|
||||
},
|
||||
itemsFooterTotalTitle: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
bold: true,
|
||||
alignment: 'right'
|
||||
},
|
||||
itemsFooterTotalValue: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
bold: true,
|
||||
alignment: 'right'
|
||||
},
|
||||
notesTitle: {
|
||||
fontSize: 10,
|
||||
bold: true,
|
||||
margin: [0,5,0,5]
|
||||
},
|
||||
notesText: {
|
||||
fontSize: 9,
|
||||
margin: [0,5,50,5]
|
||||
},
|
||||
left: {
|
||||
alignment: 'left'
|
||||
},
|
||||
center: {
|
||||
alignment: 'center'
|
||||
},
|
||||
},
|
||||
defaultStyle: {
|
||||
columnGap: 20
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
// CURRENT INVOICES
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie
|
|||
|
||||
<div class="float-right">
|
||||
<a class="btn btn-primary" href="#" onclick="window.print();"><i class="fas fa-fw fa-print mr-2"></i>Print</a>
|
||||
<a class="btn btn-primary" href="#" onclick="pdfMake.createPdf(docDefinition).download('<?php echo strtoAZaz09(html_entity_decode("$quote_date-$company_name-QUOTE-$quote_prefix$quote_number")); ?>');">
|
||||
<a class="btn btn-primary" href="guest_post.php?export_quote_pdf=<?php echo $quote_id; ?>&url_key=<?php echo $url_key; ?>">
|
||||
<i class="fa fa-fw fa-download mr-2"></i>Download
|
||||
</a>
|
||||
</div>
|
||||
|
|
@ -131,10 +131,12 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie
|
|||
<div class="card-body">
|
||||
|
||||
<div class="row mb-3">
|
||||
<?php if (file_exists("../uploads/settings/$company_logo")) { ?>
|
||||
<div class="col-sm-2">
|
||||
<img class="img-fluid" src="<?php echo "../uploads/settings/$company_logo"; ?>" alt="Company logo">
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<?php } ?>
|
||||
<div class="col-sm-6 <?php if (!file_exists("../uploads/settings/$company_logo")) { echo "col-sm-8"; } ?>">
|
||||
<ul class="list-unstyled">
|
||||
<li><h4><strong><?php echo $company_name; ?></strong></h4></li>
|
||||
<li><?php echo $company_address; ?></li>
|
||||
|
|
@ -297,434 +299,6 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script src='../plugins/pdfmake/pdfmake.min.js'></script>
|
||||
<script src='../plugins/pdfmake/vfs_fonts.js'></script>
|
||||
<script>
|
||||
|
||||
var docDefinition = {
|
||||
info: {
|
||||
title: <?php echo json_encode(html_entity_decode($company_name) . "- Quote") ?>,
|
||||
author: <?php echo json_encode(html_entity_decode($company_name)) ?>
|
||||
},
|
||||
|
||||
//watermark: {text: '<?php echo $quote_status; ?>', color: 'lightgrey', opacity: 0.3, bold: true, italics: false},
|
||||
|
||||
content: [
|
||||
// Header
|
||||
{
|
||||
columns: [
|
||||
<?php if (!empty($company_logo_base64)) { ?>
|
||||
{
|
||||
image: <?php echo json_encode("data:image;base64,$company_logo_base64") ?>,
|
||||
width: 120
|
||||
},
|
||||
<?php } ?>
|
||||
|
||||
[
|
||||
{
|
||||
text: 'Quote',
|
||||
style: 'invoiceTitle',
|
||||
width: '*'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode("$quote_prefix$quote_number")) ?>,
|
||||
style: 'invoiceNumber',
|
||||
width: '*'
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
// Billing Headers
|
||||
{
|
||||
columns: [
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode($company_name)) ?>,
|
||||
style: 'invoiceBillingTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode($client_name)) ?>,
|
||||
style: 'invoiceBillingTitleClient'
|
||||
},
|
||||
]
|
||||
},
|
||||
// Billing Address
|
||||
{
|
||||
columns: [
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode("$company_address \n $company_city $company_state $company_zip \n $company_country \n $company_phone \n $company_website")) ?>,
|
||||
style: 'invoiceBillingAddress'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode("$location_address \n $location_city $location_state $location_zip \n $location_country \n $contact_email \n $contact_phone")) ?>,
|
||||
style: 'invoiceBillingAddressClient'
|
||||
},
|
||||
]
|
||||
},
|
||||
//Invoice Dates Table
|
||||
{
|
||||
table: {
|
||||
// headers are automatically repeated if the table spans over multiple pages
|
||||
// you can declare how many rows should be treated as headers
|
||||
headerRows: 0,
|
||||
widths: [ '*',80, 80 ],
|
||||
|
||||
body: [
|
||||
// Total
|
||||
[
|
||||
{
|
||||
text: '',
|
||||
rowSpan: 3
|
||||
},
|
||||
{},
|
||||
{},
|
||||
],
|
||||
[
|
||||
{},
|
||||
{
|
||||
text: 'Date',
|
||||
style: 'invoiceDateTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode($quote_date)) ?>,
|
||||
style: 'invoiceDateValue'
|
||||
},
|
||||
],
|
||||
[
|
||||
{},
|
||||
{
|
||||
text: 'Expire',
|
||||
style: 'invoiceDueDateTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode($quote_expire)) ?>,
|
||||
style: 'invoiceDueDateValue'
|
||||
},
|
||||
],
|
||||
]
|
||||
}, // table
|
||||
layout: 'lightHorizontalLines'
|
||||
},
|
||||
// Line breaks
|
||||
'\n\n',
|
||||
// Items
|
||||
{
|
||||
table: {
|
||||
// headers are automatically repeated if the table spans over multiple pages
|
||||
// you can declare how many rows should be treated as headers
|
||||
headerRows: 1,
|
||||
widths: [ '*', 40, 'auto', 'auto', 80 ],
|
||||
|
||||
body: [
|
||||
// Table Header
|
||||
[
|
||||
{
|
||||
text: 'Product',
|
||||
style: [ 'itemsHeader', 'left']
|
||||
},
|
||||
{
|
||||
text: 'Qty',
|
||||
style: [ 'itemsHeader', 'center']
|
||||
},
|
||||
{
|
||||
text: 'Price',
|
||||
style: [ 'itemsHeader', 'right']
|
||||
},
|
||||
{
|
||||
text: 'Tax',
|
||||
style: [ 'itemsHeader', 'right']
|
||||
},
|
||||
{
|
||||
text: 'Total',
|
||||
style: [ 'itemsHeader', 'right']
|
||||
}
|
||||
],
|
||||
// Items
|
||||
<?php
|
||||
$total_tax = 0;
|
||||
$sub_total = 0;
|
||||
|
||||
$sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_quote_id = $quote_id ORDER BY item_order ASC");
|
||||
|
||||
while ($row = mysqli_fetch_array($sql_invoice_items)) {
|
||||
$item_name = $row['item_name'];
|
||||
$item_description = $row['item_description'];
|
||||
$item_quantity = $row['item_quantity'];
|
||||
$item_price = $row['item_price'];
|
||||
$item_subtotal = $row['item_price'];
|
||||
$item_tax = $row['item_tax'];
|
||||
$item_total = $row['item_total'];
|
||||
$tax_id = $row['item_tax_id'];
|
||||
$total_tax = $item_tax + $total_tax;
|
||||
$sub_total = $item_price * $item_quantity + $sub_total;
|
||||
?>
|
||||
|
||||
// Item
|
||||
[
|
||||
[
|
||||
{
|
||||
text: <?php echo json_encode($item_name) ?>,
|
||||
style: 'itemTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode($item_description) ?>,
|
||||
style: 'itemDescription'
|
||||
}
|
||||
],
|
||||
{
|
||||
text: <?php echo $item_quantity ?>,
|
||||
style: 'itemQty'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $item_price, $quote_currency_code)) ?>,
|
||||
style: 'itemNumber'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $item_tax, $quote_currency_code)) ?>,
|
||||
style: 'itemNumber'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $item_total, $quote_currency_code)) ?>,
|
||||
style: 'itemNumber'
|
||||
}
|
||||
],
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
// END Items
|
||||
]
|
||||
}, // table
|
||||
layout: 'lightHorizontalLines'
|
||||
},
|
||||
// TOTAL
|
||||
{
|
||||
table: {
|
||||
// headers are automatically repeated if the table spans over multiple pages
|
||||
// you can declare how many rows should be treated as headers
|
||||
headerRows: 0,
|
||||
widths: [ '*','auto', 80 ],
|
||||
|
||||
body: [
|
||||
// Total
|
||||
[
|
||||
{
|
||||
text: 'Notes',
|
||||
style:'notesTitle'
|
||||
},
|
||||
{},
|
||||
{}
|
||||
],
|
||||
[
|
||||
{
|
||||
rowSpan: '*',
|
||||
text: <?php echo json_encode(html_entity_decode($quote_note)) ?>,
|
||||
style: 'notesText'
|
||||
},
|
||||
{
|
||||
text: 'Subtotal',
|
||||
style: 'itemsFooterSubTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $sub_total, $quote_currency_code)) ?>,
|
||||
style: 'itemsFooterSubValue'
|
||||
}
|
||||
],
|
||||
<?php if ($quote_discount > 0) { ?>
|
||||
[
|
||||
{},
|
||||
{
|
||||
text: 'Discount',
|
||||
style: 'itemsFooterSubTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, -$quote_discount, $quote_currency_code)) ?>,
|
||||
style: 'itemsFooterSubValue'
|
||||
}
|
||||
],
|
||||
<?php } ?>
|
||||
<?php if ($total_tax > 0) { ?>
|
||||
[
|
||||
{},
|
||||
{
|
||||
text: 'Tax',
|
||||
style: 'itemsFooterSubTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $total_tax, $quote_currency_code)) ?>,
|
||||
style: 'itemsFooterSubValue'
|
||||
}
|
||||
],
|
||||
<?php } ?>
|
||||
[
|
||||
{},
|
||||
{
|
||||
text: 'Total',
|
||||
style: 'itemsFooterTotalTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $quote_amount, $quote_currency_code)) ?>,
|
||||
style: 'itemsFooterTotalValue'
|
||||
}
|
||||
],
|
||||
]
|
||||
}, // table
|
||||
layout: 'lightHorizontalLines'
|
||||
},
|
||||
// TERMS / FOOTER
|
||||
{
|
||||
text: <?php echo json_encode("$config_quote_footer"); ?>,
|
||||
style: 'documentFooterCenter'
|
||||
}
|
||||
], //End Content,
|
||||
styles: {
|
||||
// Document Footer
|
||||
documentFooterCenter: {
|
||||
fontSize: 9,
|
||||
margin: [10,50,10,10],
|
||||
alignment: 'center'
|
||||
},
|
||||
// Invoice Title
|
||||
invoiceTitle: {
|
||||
fontSize: 18,
|
||||
bold: true,
|
||||
alignment: 'right',
|
||||
margin: [0,0,0,3]
|
||||
},
|
||||
// Invoice Number
|
||||
invoiceNumber: {
|
||||
fontSize: 14,
|
||||
alignment: 'right'
|
||||
},
|
||||
// Billing Headers
|
||||
invoiceBillingTitle: {
|
||||
fontSize: 14,
|
||||
bold: true,
|
||||
alignment: 'left',
|
||||
margin: [0,20,0,5]
|
||||
},
|
||||
invoiceBillingTitleClient: {
|
||||
fontSize: 14,
|
||||
bold: true,
|
||||
alignment: 'right',
|
||||
margin: [0,20,0,5]
|
||||
},
|
||||
// Billing Details
|
||||
invoiceBillingAddress: {
|
||||
fontSize: 10,
|
||||
lineHeight: 1.2
|
||||
},
|
||||
invoiceBillingAddressClient: {
|
||||
fontSize: 10,
|
||||
lineHeight: 1.2,
|
||||
alignment: 'right',
|
||||
margin: [0,0,0,30]
|
||||
},
|
||||
// Invoice Dates
|
||||
invoiceDateTitle: {
|
||||
fontSize: 10,
|
||||
alignment: 'left',
|
||||
margin: [0,5,0,5]
|
||||
},
|
||||
invoiceDateValue: {
|
||||
fontSize: 10,
|
||||
alignment: 'right',
|
||||
margin: [0,5,0,5]
|
||||
},
|
||||
// Invoice Due Dates
|
||||
invoiceDueDateTitle: {
|
||||
fontSize: 10,
|
||||
bold: true,
|
||||
alignment: 'left',
|
||||
margin: [0,5,0,5]
|
||||
},
|
||||
invoiceDueDateValue: {
|
||||
fontSize: 10,
|
||||
bold: true,
|
||||
alignment: 'right',
|
||||
margin: [0,5,0,5]
|
||||
},
|
||||
// Items Header
|
||||
itemsHeader: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
bold: true,
|
||||
alignment: 'right'
|
||||
},
|
||||
// Item Title
|
||||
itemTitle: {
|
||||
fontSize: 10,
|
||||
bold: true,
|
||||
margin: [0,5,0,3]
|
||||
},
|
||||
itemDescription: {
|
||||
italics: true,
|
||||
fontSize: 9,
|
||||
lineHeight: 1.1,
|
||||
margin: [0,3,0,5]
|
||||
},
|
||||
itemQty: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
alignment: 'center'
|
||||
},
|
||||
itemNumber: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
alignment: 'right'
|
||||
},
|
||||
itemTotal: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
bold: true,
|
||||
alignment: 'right'
|
||||
},
|
||||
// Items Footer (Subtotal, Total, Tax, etc)
|
||||
itemsFooterSubTitle: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
alignment: 'right'
|
||||
},
|
||||
itemsFooterSubValue: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
bold: false,
|
||||
alignment: 'right'
|
||||
},
|
||||
itemsFooterTotalTitle: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
bold: true,
|
||||
alignment: 'right'
|
||||
},
|
||||
itemsFooterTotalValue: {
|
||||
fontSize: 10,
|
||||
margin: [0,5,0,5],
|
||||
bold: true,
|
||||
alignment: 'right'
|
||||
},
|
||||
notesTitle: {
|
||||
fontSize: 10,
|
||||
bold: true,
|
||||
margin: [0,5,0,5]
|
||||
},
|
||||
notesText: {
|
||||
fontSize: 9,
|
||||
margin: [0,5,50,5]
|
||||
},
|
||||
left: {
|
||||
alignment: 'left'
|
||||
},
|
||||
center: {
|
||||
alignment: 'center'
|
||||
},
|
||||
},
|
||||
defaultStyle: {
|
||||
columnGap: 20,
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require_once "guest_quote_upload_file_modal.php";
|
||||
require_once "includes/guest_footer.php";
|
||||
|
||||
|
|
|
|||
|
|
@ -309,10 +309,12 @@ if (isset($_GET['invoice_id'])) {
|
|||
<div class="card-body">
|
||||
|
||||
<div class="row mb-3">
|
||||
<?php if (file_exists("uploads/settings/$company_logo")) { ?>
|
||||
<div class="col-sm-2">
|
||||
<img class="img-fluid" src="<?php echo "uploads/settings/$company_logo"; ?>" alt="Company logo">
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<?php } ?>
|
||||
<div class="col-sm-6 <?php if (!file_exists("uploads/settings/$company_logo")) { echo "col-sm-8"; } ?>">
|
||||
<ul class="list-unstyled">
|
||||
<li><h4><strong><?php echo $company_name; ?></strong></h4></li>
|
||||
<li><?php echo $company_address; ?></li>
|
||||
|
|
|
|||
|
|
@ -2002,9 +2002,7 @@ if (isset($_GET['export_invoice_pdf'])) {
|
|||
// Totals
|
||||
$html .= '<table width="100%" cellspacing="0" cellpadding="4">
|
||||
<tr>
|
||||
<td width="70%" rowspan="6" valign="top">
|
||||
<strong>Notes:</strong><br>' . nl2br($invoice_note) . '
|
||||
</td>
|
||||
<td width="70%" rowspan="6" valign="top"><i>' . nl2br($invoice_note) . '</i></td>
|
||||
<td width="30%">
|
||||
<table width="100%" cellpadding="3" cellspacing="0">
|
||||
<tr><td>Subtotal:</td><td align="right">' . numfmt_format_currency($currency_format, $sub_total, $invoice_currency_code) . '</td></tr>';
|
||||
|
|
|
|||
|
|
@ -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 = '<table width="100%" cellspacing="0" cellpadding="5">
|
||||
<tr>
|
||||
<td width="40%">';
|
||||
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 .= '</td>
|
||||
<td width="60%" align="right">
|
||||
<span style="font-size:18pt; font-weight:bold;">QUOTE</span><br>
|
||||
<span style="font-size:14pt;">' . $quote_prefix . $quote_number . '</span><br>';
|
||||
if (strtolower($quote_status) === 'accepted') {
|
||||
$html .= '<span style="color:green; font-weight:bold;">ACCEPTED</span><br>';
|
||||
}
|
||||
if (strtolower($quote_status) === 'declined') {
|
||||
$html .= '<span style="color:red; font-weight:bold;">DECLINED</span><br>';
|
||||
}
|
||||
$html .= '</td>
|
||||
</tr>
|
||||
</table><br><br>';
|
||||
|
||||
// Billing titles
|
||||
$html .= '<table width="100%" cellspacing="0" cellpadding="2">
|
||||
<tr>
|
||||
<td width="50%" style="font-size:14pt; font-weight:bold;">' . $company_name . '</td>
|
||||
<td width="50%" align="right" style="font-size:14pt; font-weight:bold;">' . $client_name . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-size:10pt; line-height:1.4;">' . nl2br("$company_address\n$company_city $company_state $company_zip\n$company_country\n$company_phone\n$company_website") . '</td>
|
||||
<td style="font-size:10pt; line-height:1.4;" align="right">' . nl2br("$location_address\n$location_city $location_state $location_zip\n$location_country\n$contact_email\n$contact_phone") . '</td>
|
||||
</tr>
|
||||
</table><br>';
|
||||
|
||||
// Date table
|
||||
$html .= '<table border="0" cellpadding="3" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td width="60%"></td>
|
||||
<td width="20%" style="font-size:10pt;"><strong>Date:</strong></td>
|
||||
<td width="20%" style="font-size:10pt;" align="right">' . $quote_date . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td style="font-size:10pt;"><strong>Expires:</strong></td>
|
||||
<td style="font-size:10pt;" align="right">' . $quote_expire . '</td>
|
||||
</tr>
|
||||
</table><br><br>';
|
||||
|
||||
// Items header
|
||||
$html .= '
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%">
|
||||
<tr style="background-color:#f0f0f0;">
|
||||
<th align="left" width="40%"><strong>Item</strong></th>
|
||||
<th align="center" width="10%"><strong>Qty</strong></th>
|
||||
<th align="right" width="15%"><strong>Price</strong></th>
|
||||
<th align="right" width="15%"><strong>Tax</strong></th>
|
||||
<th align="right" width="20%"><strong>Amount</strong></th>
|
||||
</tr>';
|
||||
|
||||
// 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 .= '
|
||||
<tr>
|
||||
<td>
|
||||
<strong>' . $name . '</strong><br>
|
||||
<span style="font-style:italic; font-size:9pt;">' . nl2br($desc) . '</span>
|
||||
</td>
|
||||
<td align="center">' . number_format($qty, 2) . '</td>
|
||||
<td align="right">' . numfmt_format_currency($currency_format, $price, $quote_currency_code) . '</td>
|
||||
<td align="right">' . numfmt_format_currency($currency_format, $tax, $quote_currency_code) . '</td>
|
||||
<td align="right">' . numfmt_format_currency($currency_format, $total, $quote_currency_code) . '</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
$html .= '</table><br><hr><br><br>';
|
||||
|
||||
// Totals
|
||||
$html .= '<table width="100%" cellspacing="0" cellpadding="4">
|
||||
<tr>
|
||||
<td width="70%" rowspan="6" valign="top"><i>' . nl2br($quote_note) . '</i></td>
|
||||
<td width="30%">
|
||||
<table width="100%" cellpadding="3" cellspacing="0">
|
||||
<tr><td>Subtotal:</td><td align="right">' . numfmt_format_currency($currency_format, $sub_total, $quote_currency_code) . '</td></tr>';
|
||||
if ($quote_discount > 0) {
|
||||
$html .= '<tr><td>Discount:</td><td align="right">-' . numfmt_format_currency($currency_format, $quote_discount, $quote_currency_code) . '</td></tr>';
|
||||
}
|
||||
if ($total_tax > 0) {
|
||||
$html .= '<tr><td>Tax:</td><td align="right">' . numfmt_format_currency($currency_format, $total_tax, $quote_currency_code) . '</td></tr>';
|
||||
}
|
||||
$html .= '
|
||||
<tr><td><h3><strong>Total:</strong></h3></td><td align="right"><h3><strong>' . numfmt_format_currency($currency_format, $quote_amount, $quote_currency_code) . '</strong></h3></td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table><br><br>';
|
||||
|
||||
// Footer
|
||||
$html .= '<div style="text-align:center; font-size:9pt; color:gray;">' . nl2br($config_quote_footer) . '</div>';
|
||||
|
||||
$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;
|
||||
|
||||
}
|
||||
|
|
|
|||
407
quote.php
407
quote.php
|
|
@ -26,7 +26,12 @@ if (isset($_GET['quote_id'])) {
|
|||
);
|
||||
|
||||
if (mysqli_num_rows($sql) == 0) {
|
||||
echo '<h1 class="text-secondary mt-5" style="text-align: center">Nothing to see here</h1>';
|
||||
if (isset($_GET['client_id'])) {
|
||||
$backlink_append = "?client_id=$client_id";
|
||||
} else {
|
||||
$backlink_append = '';
|
||||
}
|
||||
echo "<h1 class='text-secondary pt-5' style='text-align: center'>There is no Quote here<br><small><a href='quotes.php$backlink_append'><i class='fas fa-arrow-left mr-2'></i>Back to Quotes</a></small></h1>";
|
||||
require_once "includes/footer.php";
|
||||
|
||||
exit();
|
||||
|
|
@ -221,7 +226,7 @@ if (isset($_GET['quote_id'])) {
|
|||
<a class="dropdown-item" href="#" onclick="window.print();">
|
||||
<i class="fa fa-fw fa-print text-secondary mr-2"></i>Print
|
||||
</a>
|
||||
<a class="dropdown-item" href="#" onclick="pdfMake.createPdf(docDefinition).download('<?php echo strtoAZaz09(html_entity_decode("$quote_date-$company_name-$client_name-Quote-$quote_prefix$quote_number")); ?>');">
|
||||
<a class="dropdown-item" href="post.php?export_quote_pdf=<?php echo $quote_id; ?>" target="_blank">
|
||||
<i class="fa fa-fw fa-download text-secondary mr-2"></i>Download PDF
|
||||
</a>
|
||||
<?php if (!empty($config_smtp_host) && !empty($contact_email)) { ?>
|
||||
|
|
@ -248,10 +253,12 @@ if (isset($_GET['quote_id'])) {
|
|||
<div class="card-body">
|
||||
|
||||
<div class="row mb-3">
|
||||
<?php if (file_exists("uploads/settings/$company_logo")) { ?>
|
||||
<div class="col-sm-2">
|
||||
<img class="img-fluid" src="<?php echo "uploads/settings/$company_logo"; ?>" alt="Company logo">
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<?php } ?>
|
||||
<div class="col-sm-6 <?php if (!file_exists("uploads/settings/$company_logo")) { echo "col-sm-8"; } ?>">
|
||||
<ul class="list-unstyled">
|
||||
<li><h4><strong><?php echo $company_name; ?></strong></h4></li>
|
||||
<li><?php echo $company_address; ?></li>
|
||||
|
|
@ -613,400 +620,6 @@ require_once "includes/footer.php";
|
|||
});
|
||||
</script>
|
||||
|
||||
<script src='plugins/pdfmake/pdfmake.min.js'></script>
|
||||
<script src='plugins/pdfmake/vfs_fonts.js'></script>
|
||||
<script>
|
||||
var docDefinition = {
|
||||
info: {
|
||||
title: <?php echo json_encode(html_entity_decode($company_name) . "- Quote") ?>,
|
||||
author: <?php echo json_encode(html_entity_decode($company_name)) ?>
|
||||
},
|
||||
|
||||
//watermark: {text: '<?php echo $quote_status; ?>', color: 'lightgrey', opacity: 0.3, bold: true, italics: false},
|
||||
|
||||
content: [
|
||||
// Header
|
||||
{
|
||||
columns: [
|
||||
<?php if (!empty($company_logo_base64)) { ?> {
|
||||
image: <?php echo json_encode("data:image;base64,$company_logo_base64") ?>,
|
||||
width: 120
|
||||
},
|
||||
<?php } ?>
|
||||
|
||||
[{
|
||||
text: 'Quote',
|
||||
style: 'invoiceTitle',
|
||||
width: '*'
|
||||
}, {
|
||||
text: <?php echo json_encode("$quote_prefix$quote_number") ?>,
|
||||
style: 'invoiceNumber',
|
||||
width: '*'
|
||||
}, ],
|
||||
],
|
||||
},
|
||||
// Billing Headers
|
||||
{
|
||||
columns: [{
|
||||
text: <?php echo json_encode(html_entity_decode($company_name)) ?>,
|
||||
style: 'invoiceBillingTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode($client_name)) ?>,
|
||||
style: 'invoiceBillingTitleClient'
|
||||
},
|
||||
]
|
||||
},
|
||||
// Billing Address
|
||||
{
|
||||
columns: [{
|
||||
text: <?php echo json_encode(html_entity_decode("$company_address \n $company_city $company_state $company_zip \n $company_country \n $company_phone \n $company_website")) ?>,
|
||||
style: 'invoiceBillingAddress'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode("$location_address \n $location_city $location_state $location_zip \n $location_country \n $contact_email \n $contact_phone")) ?>,
|
||||
style: 'invoiceBillingAddressClient'
|
||||
},
|
||||
]
|
||||
},
|
||||
//Invoice Dates Table
|
||||
{
|
||||
table: {
|
||||
// headers are automatically repeated if the table spans over multiple pages
|
||||
// you can declare how many rows should be treated as headers
|
||||
headerRows: 0,
|
||||
widths: ['*', 80, 80],
|
||||
|
||||
body: [
|
||||
// Total
|
||||
[{
|
||||
text: '',
|
||||
rowSpan: 3
|
||||
},
|
||||
{},
|
||||
{},
|
||||
],
|
||||
[{},
|
||||
{
|
||||
text: 'Date',
|
||||
style: 'invoiceDateTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode($quote_date)) ?>,
|
||||
style: 'invoiceDateValue'
|
||||
},
|
||||
],
|
||||
[{},
|
||||
{
|
||||
text: 'Expire',
|
||||
style: 'invoiceDueDateTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(html_entity_decode($quote_expire)) ?>,
|
||||
style: 'invoiceDueDateValue'
|
||||
},
|
||||
],
|
||||
]
|
||||
}, // table
|
||||
layout: 'lightHorizontalLines'
|
||||
},
|
||||
// Line breaks
|
||||
'\n\n',
|
||||
// Items
|
||||
{
|
||||
table: {
|
||||
// headers are automatically repeated if the table spans over multiple pages
|
||||
// you can declare how many rows should be treated as headers
|
||||
headerRows: 1,
|
||||
widths: ['*', 40, 'auto', 'auto', 80],
|
||||
|
||||
body: [
|
||||
// Table Header
|
||||
[{
|
||||
text: 'Product',
|
||||
style: ['itemsHeader', 'left']
|
||||
},
|
||||
{
|
||||
text: 'Qty',
|
||||
style: ['itemsHeader', 'center']
|
||||
},
|
||||
{
|
||||
text: 'Price',
|
||||
style: ['itemsHeader', 'right']
|
||||
},
|
||||
{
|
||||
text: 'Tax',
|
||||
style: ['itemsHeader', 'right']
|
||||
},
|
||||
{
|
||||
text: 'Total',
|
||||
style: ['itemsHeader', 'right']
|
||||
}
|
||||
],
|
||||
// Items
|
||||
<?php
|
||||
$total_tax = 0.00;
|
||||
$sub_total = 0.00;
|
||||
|
||||
$sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_quote_id = $quote_id ORDER BY item_order ASC");
|
||||
|
||||
while ($row = mysqli_fetch_array($sql_invoice_items)) {
|
||||
$item_name = $row['item_name'];
|
||||
$item_description = $row['item_description'];
|
||||
$item_quantity = $row['item_quantity'];
|
||||
$item_price = $row['item_price'];
|
||||
$item_subtotal = $row['item_price'];
|
||||
$item_tax = $row['item_tax'];
|
||||
$item_total = $row['item_total'];
|
||||
$tax_id = $row['item_tax_id'];
|
||||
$total_tax = $item_tax + $total_tax;
|
||||
$sub_total = $item_price * $item_quantity + $sub_total;
|
||||
?>
|
||||
|
||||
// Item
|
||||
[
|
||||
[{
|
||||
text: <?php echo json_encode($item_name) ?>,
|
||||
style: 'itemTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode($item_description) ?>,
|
||||
style: 'itemDescription'
|
||||
}
|
||||
], {
|
||||
text: <?php echo json_encode($item_quantity) ?>,
|
||||
style: 'itemQty'
|
||||
}, {
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $item_price, $quote_currency_code)) ?>,
|
||||
style: 'itemNumber'
|
||||
}, {
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $item_tax, $quote_currency_code)) ?>,
|
||||
style: 'itemNumber'
|
||||
}, {
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $item_total, $quote_currency_code)) ?>,
|
||||
style: 'itemNumber'
|
||||
}
|
||||
],
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
// END Items
|
||||
]
|
||||
}, // table
|
||||
layout: 'lightHorizontalLines'
|
||||
},
|
||||
// TOTAL
|
||||
{
|
||||
table: {
|
||||
// headers are automatically repeated if the table spans over multiple pages
|
||||
// you can declare how many rows should be treated as headers
|
||||
headerRows: 0,
|
||||
widths: ['*', 'auto', 80],
|
||||
|
||||
body: [
|
||||
// Total
|
||||
[{
|
||||
text: 'Notes',
|
||||
style: 'notesTitle'
|
||||
},
|
||||
{},
|
||||
{}
|
||||
],
|
||||
[{
|
||||
rowSpan: '*',
|
||||
text: <?php echo json_encode(html_entity_decode($quote_note)) ?>,
|
||||
style: 'notesText'
|
||||
},
|
||||
{
|
||||
text: 'Subtotal',
|
||||
style: 'itemsFooterSubTitle'
|
||||
},
|
||||
{
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $sub_total, $quote_currency_code)) ?>,
|
||||
style: 'itemsFooterSubValue'
|
||||
}
|
||||
],
|
||||
<?php if ($quote_discount > 0) { ?>[{}, {
|
||||
text: 'Discount',
|
||||
style: 'itemsFooterSubTitle'
|
||||
}, {
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, -$quote_discount, $quote_currency_code)) ?>,
|
||||
style: 'itemsFooterSubValue'
|
||||
}],
|
||||
<?php } ?>
|
||||
<?php if ($total_tax > 0) { ?>[{}, {
|
||||
text: 'Tax',
|
||||
style: 'itemsFooterSubTitle'
|
||||
}, {
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $total_tax, $quote_currency_code)) ?>,
|
||||
style: 'itemsFooterSubValue'
|
||||
}],
|
||||
<?php } ?>[{}, {
|
||||
text: 'Total',
|
||||
style: 'itemsFooterTotalTitle'
|
||||
}, {
|
||||
text: <?php echo json_encode(numfmt_format_currency($currency_format, $quote_amount, $quote_currency_code)) ?>,
|
||||
style: 'itemsFooterTotalValue'
|
||||
}],
|
||||
]
|
||||
}, // table
|
||||
layout: 'lightHorizontalLines'
|
||||
},
|
||||
// TERMS / FOOTER
|
||||
{
|
||||
text: <?php echo json_encode($config_quote_footer) ?>,
|
||||
style: 'documentFooterCenter'
|
||||
}
|
||||
], //End Content,
|
||||
styles: {
|
||||
// Document Footer
|
||||
documentFooterCenter: {
|
||||
fontSize: 9,
|
||||
margin: [10, 50, 10, 10],
|
||||
alignment: 'center'
|
||||
},
|
||||
// Invoice Title
|
||||
invoiceTitle: {
|
||||
fontSize: 18,
|
||||
bold: true,
|
||||
alignment: 'right',
|
||||
margin: [0, 0, 0, 3]
|
||||
},
|
||||
// Invoice Number
|
||||
invoiceNumber: {
|
||||
fontSize: 14,
|
||||
alignment: 'right'
|
||||
},
|
||||
// Billing Headers
|
||||
invoiceBillingTitle: {
|
||||
fontSize: 14,
|
||||
bold: true,
|
||||
alignment: 'left',
|
||||
margin: [0, 20, 0, 5]
|
||||
},
|
||||
invoiceBillingTitleClient: {
|
||||
fontSize: 14,
|
||||
bold: true,
|
||||
alignment: 'right',
|
||||
margin: [0, 20, 0, 5]
|
||||
},
|
||||
// Billing Details
|
||||
invoiceBillingAddress: {
|
||||
fontSize: 10,
|
||||
lineHeight: 1.2
|
||||
},
|
||||
invoiceBillingAddressClient: {
|
||||
fontSize: 10,
|
||||
lineHeight: 1.2,
|
||||
alignment: 'right',
|
||||
margin: [0, 0, 0, 30]
|
||||
},
|
||||
// Invoice Dates
|
||||
invoiceDateTitle: {
|
||||
fontSize: 10,
|
||||
alignment: 'left',
|
||||
margin: [0, 5, 0, 5]
|
||||
},
|
||||
invoiceDateValue: {
|
||||
fontSize: 10,
|
||||
alignment: 'right',
|
||||
margin: [0, 5, 0, 5]
|
||||
},
|
||||
// Invoice Due Dates
|
||||
invoiceDueDateTitle: {
|
||||
fontSize: 10,
|
||||
bold: true,
|
||||
alignment: 'left',
|
||||
margin: [0, 5, 0, 5]
|
||||
},
|
||||
invoiceDueDateValue: {
|
||||
fontSize: 10,
|
||||
bold: true,
|
||||
alignment: 'right',
|
||||
margin: [0, 5, 0, 5]
|
||||
},
|
||||
// Items Header
|
||||
itemsHeader: {
|
||||
fontSize: 10,
|
||||
margin: [0, 5, 0, 5],
|
||||
bold: true,
|
||||
alignment: 'right'
|
||||
},
|
||||
// Item Title
|
||||
itemTitle: {
|
||||
fontSize: 10,
|
||||
bold: true,
|
||||
margin: [0, 5, 0, 3]
|
||||
},
|
||||
itemDescription: {
|
||||
italics: true,
|
||||
fontSize: 9,
|
||||
lineHeight: 1.1,
|
||||
margin: [0, 3, 0, 5]
|
||||
},
|
||||
itemQty: {
|
||||
fontSize: 10,
|
||||
margin: [0, 5, 0, 5],
|
||||
alignment: 'center'
|
||||
},
|
||||
itemNumber: {
|
||||
fontSize: 10,
|
||||
margin: [0, 5, 0, 5],
|
||||
alignment: 'right'
|
||||
},
|
||||
itemTotal: {
|
||||
fontSize: 10,
|
||||
margin: [0, 5, 0, 5],
|
||||
bold: true,
|
||||
alignment: 'right'
|
||||
},
|
||||
// Items Footer (Subtotal, Total, Tax, etc)
|
||||
itemsFooterSubTitle: {
|
||||
fontSize: 10,
|
||||
margin: [0, 5, 0, 5],
|
||||
alignment: 'right'
|
||||
},
|
||||
itemsFooterSubValue: {
|
||||
fontSize: 10,
|
||||
margin: [0, 5, 0, 5],
|
||||
bold: false,
|
||||
alignment: 'right'
|
||||
},
|
||||
itemsFooterTotalTitle: {
|
||||
fontSize: 10,
|
||||
margin: [0, 5, 0, 5],
|
||||
bold: true,
|
||||
alignment: 'right'
|
||||
},
|
||||
itemsFooterTotalValue: {
|
||||
fontSize: 10,
|
||||
margin: [0, 5, 0, 5],
|
||||
bold: true,
|
||||
alignment: 'right'
|
||||
},
|
||||
notesTitle: {
|
||||
fontSize: 10,
|
||||
bold: true,
|
||||
margin: [0, 5, 0, 5]
|
||||
},
|
||||
notesText: {
|
||||
fontSize: 9,
|
||||
margin: [0, 5, 50, 5]
|
||||
},
|
||||
left: {
|
||||
alignment: 'left'
|
||||
},
|
||||
center: {
|
||||
alignment: 'center'
|
||||
},
|
||||
},
|
||||
defaultStyle: {
|
||||
columnGap: 20
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script src="plugins/SortableJS/Sortable.min.js"></script>
|
||||
<script>
|
||||
new Sortable(document.querySelector('table#items tbody'), {
|
||||
|
|
|
|||
Loading…
Reference in New Issue