mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 10:54:52 +00:00
Moved pdfmake js directly into invoice and quote to avoid the multiple windows and multi queries
This commit is contained in:
353
quote.php
353
quote.php
@@ -60,6 +60,7 @@ if(isset($_GET['quote_id'])){
|
||||
$company_email = $row['company_email'];
|
||||
$company_website = $row['company_website'];
|
||||
$company_logo = $row['company_logo'];
|
||||
$company_logo_base64 = base64_encode(file_get_contents($row['company_logo']));
|
||||
|
||||
$sql_history = mysqli_query($mysqli,"SELECT * FROM history WHERE quote_id = $quote_id ORDER BY history_id DESC");
|
||||
|
||||
@@ -130,7 +131,7 @@ if(isset($_GET['quote_id'])){
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addQuoteCopyModal<?php echo $quote_id; ?>">Copy</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="#" onclick="window.print();">Print</a>
|
||||
<a class="dropdown-item" target="_blank" href="post.php?download_quote=<?php echo $quote_id; ?>">Download</a>
|
||||
<a class="dropdown-item" href="#" onclick="pdfMake.createPdf(docDefinition).download('<?php echo "$quote_date-$company_name-$client_name-Quote-$quote_prefix$quote_number.pdf"; ?>');">Download PDF</a>
|
||||
<a class="dropdown-item" href="post.php?email_quote=<?php echo $quote_id; ?>">Send Email</a>
|
||||
<a class="dropdown-item" target="_blank" href="guest_view_quote.php?quote_id=<?php echo "$quote_id&url_key=$quote_url_key"; ?>">Guest URL</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
@@ -389,4 +390,352 @@ if(isset($_GET['quote_id'])){
|
||||
|
||||
include("footer.php");
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
<script src='plugins/pdfmake/pdfmake.js'></script>
|
||||
<script src='plugins/pdfmake/vfs_fonts.js'></script>
|
||||
|
||||
<script>
|
||||
|
||||
var docDefinition = {
|
||||
info: {
|
||||
title: '<?php echo "$company_name - Quote"; ?>',
|
||||
author: '<?php echo $company_name; ?>'
|
||||
},
|
||||
|
||||
|
||||
footer: {
|
||||
columns: [
|
||||
|
||||
{ text: '<?php echo $config_quote_footer; ?>', style: 'documentFooterCenter' },
|
||||
|
||||
]
|
||||
},
|
||||
|
||||
watermark: {text: '<?php echo $quote_status; ?>', color: 'grey', opacity: 0.3, bold: true, italics: false},
|
||||
|
||||
content: [
|
||||
// Header
|
||||
{
|
||||
columns: [
|
||||
{
|
||||
image: '<?php echo "data:image;base64,$company_logo_base64"; ?>',
|
||||
width: 120
|
||||
},
|
||||
|
||||
[
|
||||
{
|
||||
text: 'QUOTE',
|
||||
style: 'invoiceTitle',
|
||||
width: '*'
|
||||
},
|
||||
{
|
||||
stack: [
|
||||
{
|
||||
columns: [
|
||||
{
|
||||
text:'<?php echo "$quote_prefix$quote_number"; ?>',
|
||||
style:'invoiceSubValue',
|
||||
width: '*'
|
||||
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
columns: [
|
||||
{
|
||||
text:'<?php echo $quote_date ?>',
|
||||
style:'invoiceSubValue',
|
||||
width: '*'
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
],
|
||||
],
|
||||
},
|
||||
// Billing Headers
|
||||
{
|
||||
columns: [
|
||||
{
|
||||
text: '<?php echo $company_name; ?>',
|
||||
style:'invoiceBillingTitle',
|
||||
|
||||
},
|
||||
{
|
||||
text: '<?php echo $client_name; ?>',
|
||||
style:'invoiceBillingTitle',
|
||||
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
columns: [
|
||||
{
|
||||
text: '<?php echo $company_address; ?> \n <?php echo "$company_city $company_state $company_zip"; ?> \n \n <?php echo $company_phone; ?> \n <?php echo $company_website; ?>',
|
||||
style: 'invoiceBillingAddress'
|
||||
},
|
||||
{
|
||||
text: '<?php echo $client_address; ?> \n <?php echo "$client_city $client_state $client_zip"; ?> \n \n <?php echo $client_email; ?> \n <?php echo $client_phone; ?>',
|
||||
style: 'invoiceBillingAddress'
|
||||
},
|
||||
]
|
||||
},
|
||||
// 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'
|
||||
},
|
||||
{
|
||||
text: 'Qty',
|
||||
style: [ 'itemsHeader', 'center']
|
||||
},
|
||||
{
|
||||
text: 'Price',
|
||||
style: [ 'itemsHeader', 'center']
|
||||
},
|
||||
{
|
||||
text: 'Tax',
|
||||
style: [ 'itemsHeader', 'center']
|
||||
},
|
||||
{
|
||||
text: 'Total',
|
||||
style: [ 'itemsHeader', 'center']
|
||||
}
|
||||
],
|
||||
// Items
|
||||
<?php
|
||||
$total_tax = 0;
|
||||
$sub_total = 0;
|
||||
|
||||
$sql_invoice_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE quote_id = $quote_id ORDER BY item_id 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['tax_id'];
|
||||
$total_tax = $item_tax + $total_tax;
|
||||
$total_tax = number_format($total_tax,2);
|
||||
$sub_total = $item_price * $item_quantity + $sub_total;
|
||||
$sub_total = number_format($sub_total, 2);
|
||||
echo "
|
||||
|
||||
// Item 1
|
||||
[
|
||||
[
|
||||
{
|
||||
text: '$item_name',
|
||||
style:'itemTitle'
|
||||
},
|
||||
{
|
||||
text: '$item_description',
|
||||
style:'itemSubTitle'
|
||||
|
||||
}
|
||||
],
|
||||
{
|
||||
text:'$item_quantity',
|
||||
style:'itemNumber'
|
||||
},
|
||||
{
|
||||
text:'$$item_price',
|
||||
style:'itemNumber'
|
||||
},
|
||||
{
|
||||
text:'$$item_tax',
|
||||
style:'itemNumber'
|
||||
},
|
||||
{
|
||||
text: '$$item_total',
|
||||
style:'itemTotal'
|
||||
}
|
||||
],
|
||||
|
||||
";
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
// 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: [ '*', 80 ],
|
||||
|
||||
body: [
|
||||
// Total
|
||||
[
|
||||
{
|
||||
text:'Subtotal',
|
||||
style:'itemsFooterSubTitle'
|
||||
},
|
||||
{
|
||||
text:'$<?php echo $sub_total; ?>',
|
||||
style:'itemsFooterSubValue'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
text:'Tax',
|
||||
style:'itemsFooterSubTitle'
|
||||
},
|
||||
{
|
||||
text: '$<?php echo $total_tax; ?>',
|
||||
style:'itemsFooterSubValue'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
text:'TOTAL',
|
||||
style:'itemsFooterTotalTitle'
|
||||
},
|
||||
{
|
||||
text: '$<?php echo $quote_amount; ?>',
|
||||
style:'itemsFooterTotalValue'
|
||||
}
|
||||
],
|
||||
]
|
||||
}, // table
|
||||
layout: 'lightHorizontalLines'
|
||||
},
|
||||
{
|
||||
text: 'NOTES',
|
||||
style:'notesTitle'
|
||||
},
|
||||
{
|
||||
text: '<?php ?>',
|
||||
style:'notesText'
|
||||
}
|
||||
],
|
||||
styles: {
|
||||
|
||||
// Document Footer
|
||||
documentFooterCenter: {
|
||||
fontSize: 10,
|
||||
margin: [5,5,5,5],
|
||||
alignment:'center'
|
||||
},
|
||||
// Invoice Title
|
||||
invoiceTitle: {
|
||||
fontSize: 22,
|
||||
bold: true,
|
||||
alignment:'right',
|
||||
margin:[0,0,0,15]
|
||||
},
|
||||
// Invoice Details
|
||||
invoiceSubTitle: {
|
||||
fontSize: 12,
|
||||
alignment:'right'
|
||||
},
|
||||
invoiceSubValue: {
|
||||
fontSize: 12,
|
||||
alignment:'right'
|
||||
},
|
||||
// Billing Headers
|
||||
invoiceBillingTitle: {
|
||||
fontSize: 14,
|
||||
bold: true,
|
||||
alignment:'left',
|
||||
margin:[0,20,0,5],
|
||||
},
|
||||
// Billing Details
|
||||
invoiceBillingDetails: {
|
||||
alignment:'left'
|
||||
|
||||
},
|
||||
invoiceBillingAddressTitle: {
|
||||
margin: [0,7,0,3],
|
||||
bold: true
|
||||
},
|
||||
invoiceBillingAddress: {
|
||||
|
||||
},
|
||||
// Items Header
|
||||
itemsHeader: {
|
||||
margin: [0,5,0,5],
|
||||
bold: true
|
||||
},
|
||||
// Item Title
|
||||
itemTitle: {
|
||||
bold: true,
|
||||
},
|
||||
itemSubTitle: {
|
||||
italics: true,
|
||||
fontSize: 11
|
||||
},
|
||||
itemNumber: {
|
||||
margin: [0,5,0,5],
|
||||
alignment: 'center',
|
||||
},
|
||||
itemTotal: {
|
||||
margin: [0,5,0,5],
|
||||
bold: true,
|
||||
alignment: 'center',
|
||||
},
|
||||
|
||||
// Items Footer (Subtotal, Total, Tax, etc)
|
||||
itemsFooterSubTitle: {
|
||||
margin: [0,5,0,5],
|
||||
bold: true,
|
||||
alignment:'right',
|
||||
},
|
||||
itemsFooterSubValue: {
|
||||
margin: [0,5,0,5],
|
||||
bold: true,
|
||||
alignment:'center',
|
||||
},
|
||||
itemsFooterTotalTitle: {
|
||||
margin: [0,5,0,5],
|
||||
bold: true,
|
||||
alignment:'right',
|
||||
},
|
||||
itemsFooterTotalValue: {
|
||||
margin: [0,5,0,5],
|
||||
bold: true,
|
||||
alignment:'center',
|
||||
},
|
||||
notesTitle: {
|
||||
fontSize: 10,
|
||||
bold: true,
|
||||
margin: [0,50,0,3],
|
||||
},
|
||||
notesText: {
|
||||
fontSize: 10
|
||||
},
|
||||
center: {
|
||||
alignment:'center',
|
||||
},
|
||||
},
|
||||
defaultStyle: {
|
||||
columnGap: 20,
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user