Moved pdfmake js directly into invoice and quote to avoid the multiple windows and multi queries

This commit is contained in:
johnny@pittpc.com 2021-02-15 22:52:49 -05:00
parent 5b5afa772c
commit 234442e458
11 changed files with 1528 additions and 1817 deletions

View File

@ -72,10 +72,10 @@
$row = mysqli_fetch_array($sql_expenses);
$total_expenses = $row['total_expenses'];
$balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
$account_balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
?>
<option <?php if($config_default_payment_account == $account_id){ echo "selected"; } ?> value="<?php echo $account_id; ?>"><?php echo $account_name; ?> [$<?php echo number_format($balance,2); ?>]</option>
<option <?php if($config_default_payment_account == $account_id){ echo "selected"; } ?> value="<?php echo $account_id; ?>"><?php echo $account_name; ?> [$<?php echo number_format($account_balance,2); ?>]</option>
<?php
}

View File

@ -142,7 +142,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="post.php?email_invoice=<?php echo $invoice_id; ?>">Send</a>
<a class="dropdown-item" target="_blank" href="post.php?download_invoice=<?php echo $invoice_id; ?>">Download</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editInvoiceModal<?php echo $invoice_id; ?>">Edit</a>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addInvoiceCopyModal<?php echo $invoice_id; ?>">Copy</a>

View File

@ -135,7 +135,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
<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="post.php?email_quote=<?php echo $quote_id; ?>">Send</a>
<a class="dropdown-item" target="_blank" href="post.php?download_quote=<?php echo $quote_id; ?>">Download</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="post.php?delete_quote=<?php echo $quote_id; ?>">Delete</a>
</div>

View File

@ -3,905 +3,6 @@
include("config.php");
include("functions.php");
if(isset($_GET['download_invoice'], $_GET['url_key'])){
$invoice_id = intval($_GET['download_invoice']);
$url_key = mysqli_real_escape_string($mysqli,$_GET['url_key']);
$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients, companies, settings
WHERE invoices.client_id = clients.client_id
AND invoices.company_id = companies.company_id
AND settings.company_id = companies.company_id
AND invoices.invoice_id = $invoice_id
AND invoices.invoice_url_key = '$url_key'"
);
if(mysqli_num_rows($sql) == 1){
$row = mysqli_fetch_array($sql);
$invoice_id = $row['invoice_id'];
$invoice_prefix = $row['invoice_prefix'];
$invoice_number = $row['invoice_number'];
$invoice_status = $row['invoice_status'];
$invoice_date = $row['invoice_date'];
$invoice_due = $row['invoice_due'];
$invoice_amount = $row['invoice_amount'];
$invoice_note = $row['invoice_note'];
$invoice_category_id = $row['category_id'];
$client_id = $row['client_id'];
$client_name = $row['client_name'];
$client_address = $row['client_address'];
$client_city = $row['client_city'];
$client_state = $row['client_state'];
$client_zip = $row['client_zip'];
$client_email = $row['client_email'];
$client_phone = $row['client_phone'];
if(strlen($client_phone)>2){
$client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4);
}
$client_website = $row['client_website'];
$company_id = $row['company_id'];
$company_name = $row['company_name'];
$company_address = $row['company_address'];
$company_city = $row['company_city'];
$company_state = $row['company_state'];
$company_zip = $row['company_zip'];
$company_phone = $row['company_phone'];
if(strlen($company_phone)>2){
$company_phone = substr($row['company_phone'],0,3)."-".substr($row['company_phone'],3,3)."-".substr($row['company_phone'],6,4);
}
$company_email = $row['company_email'];
$company_website = $row['company_website'];
$company_logo = base64_encode(file_get_contents($row['company_logo']));
$config_invoice_footer = $row['config_invoice_footer'];
//Mark downloaded in history
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = '$invoice_status', history_description = 'Invoice downloaded', history_created_at = NOW(), invoice_id = $invoice_id, company_id = $company_id");
$sql_payments = mysqli_query($mysqli,"SELECT * FROM payments, accounts WHERE payments.account_id = accounts.account_id AND payments.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 invoice_id = $invoice_id");
$row = mysqli_fetch_array($sql_amount_paid);
$amount_paid = $row['amount_paid'];
$amount_paid = number_format($amount_paid, 2);
$balance = $invoice_amount - $amount_paid;
$balance = number_format($balance, 2);
?>
<script src='plugins/pdfmake/pdfmake.js'></script>
<script src='plugins/pdfmake/vfs_fonts.js'></script>
<script>
// Invoice markup
// Author: Max Kostinevich
// BETA (no styles)
// http://pdfmake.org/playground.html
// playground requires you to assign document definition to a variable called dd
// CodeSandbox Example: https://codesandbox.io/s/pdfmake-invoice-oj81y
var docDefinition = {
info: {
title: '<?php echo "$company_name - Invoice"; ?>',
author: '<?php echo $company_name; ?>'
},
footer: {
columns: [
{ text: '<?php echo $config_invoice_footer; ?>', style: 'documentFooterCenter' },
]
},
watermark: {text: '<?php echo $invoice_status; ?>', color: 'grey', opacity: 0.3, bold: true, italics: false},
content: [
// Header
{
columns: [
{
image: '<?php echo "data:image;base64,$company_logo"; ?>',
width: 120
},
[
{
text: 'INVOICE',
style: 'invoiceTitle',
width: '*'
},
{
stack: [
{
columns: [
{
text:'Invoice #',
style:'invoiceSubTitle',
width: '*'
},
{
text:'<?php echo "$invoice_prefix$invoice_number"; ?>',
style:'invoiceSubValue',
width: 100
}
]
},
{
columns: [
{
text:'Date Issued',
style:'invoiceSubTitle',
width: '*'
},
{
text:'<?php echo $invoice_date ?>',
style:'invoiceSubValue',
width: 100
}
]
},
{
columns: [
{
text:'Due Date',
style:'invoiceSubTitle',
width: '*'
},
{
text:'<?php echo $invoice_due ?>',
style:'invoiceSubValue',
width: 100
}
]
},
]
}
],
],
},
// 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 invoice_id = $invoice_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 $invoice_amount; ?>',
style:'itemsFooterTotalValue'
}
],
[
{
text:'Paid',
style:'itemsFooterSubTitle'
},
{
text: '$<?php echo $amount_paid; ?>',
style:'itemsFooterSubValue'
}
],
[
{
text:'Balance',
style:'itemsFooterSubTitle'
},
{
text: '$<?php echo $balance; ?>',
style:'itemsFooterSubValue'
}
],
]
}, // 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,
}
};
pdfMake.createPdf(docDefinition).download('<?php echo "$invoice_date-$company_name-Invoice-$invoice_prefix$invoice_number.pdf"; ?>');
</script>
<?php
}else{
echo "GTFO!!!";
}
}
if(isset($_GET['download_quote'], $_GET['url_key'])){
$quote_id = intval($_GET['download_quote']);
$url_key = mysqli_real_escape_string($mysqli,$_GET['url_key']);
$sql = mysqli_query($mysqli,"SELECT * FROM quotes, clients, companies, settings
WHERE quotes.client_id = clients.client_id
AND quotes.company_id = companies.company_id
AND settings.company_id = companies.company_id
AND quotes.quote_id = $quote_id
AND quotes.quote_url_key = '$url_key'"
);
if(mysqli_num_rows($sql) == 1){
$row = mysqli_fetch_array($sql);
$quote_id = $row['quote_id'];
$quote_prefix = $row['quote_prefix'];
$quote_number = $row['quote_number'];
$quote_status = $row['quote_status'];
$quote_date = $row['quote_date'];
$quote_amount = $row['quote_amount'];
$quote_note = $row['quote_note'];
$quote_url_key = $row['quote_url_key'];
$client_id = $row['client_id'];
$client_name = $row['client_name'];
$client_address = $row['client_address'];
$client_city = $row['client_city'];
$client_state = $row['client_state'];
$client_zip = $row['client_zip'];
$client_email = $row['client_email'];
$client_phone = $row['client_phone'];
if(strlen($client_phone)>2){
$client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4);
}
$client_website = $row['client_website'];
$company_id = $row['company_id'];
$company_name = $row['company_name'];
$company_address = $row['company_address'];
$company_city = $row['company_city'];
$company_state = $row['company_state'];
$company_zip = $row['company_zip'];
$company_phone = $row['company_phone'];
if(strlen($company_phone)>2){
$company_phone = substr($row['company_phone'],0,3)."-".substr($row['company_phone'],3,3)."-".substr($row['company_phone'],6,4);
}
$company_email = $row['company_email'];
$company_website = $row['company_website'];
$company_logo = base64_encode(file_get_contents($row['company_logo']));
$config_quote_footer = $row['config_quote_footer'];
?>
<script src='plugins/pdfmake/pdfmake.js'></script>
<script src='plugins/pdfmake/vfs_fonts.js'></script>
<script>
// Invoice markup
// Author: Max Kostinevich
// BETA (no styles)
// http://pdfmake.org/playground.html
// playground requires you to assign document definition to a variable called dd
// CodeSandbox Example: https://codesandbox.io/s/pdfmake-invoice-oj81y
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"; ?>',
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,
}
};
pdfMake.createPdf(docDefinition).download('<?php echo "$quote_date-$company_name-QUOTE-$quote_prefix$quote_number.pdf"; ?>');
</script>
<?php
}else{
echo "GTFO!!!";
}
}
if(isset($_GET['accept_quote'], $_GET['url_key'])){
$quote_id = intval($_GET['accept_quote']);

View File

@ -61,6 +61,7 @@ if(isset($_GET['invoice_id'], $_GET['url_key'])){
}
$company_email = $row['company_email'];
$company_logo = $row['company_logo'];
$company_logo_base64 = base64_encode(file_get_contents($row['company_logo']));
$config_invoice_footer = $row['config_invoice_footer'];
$config_stripe_enable = $row['config_stripe_enable'];
$config_stripe_publishable = $row['config_stripe_publishable'];
@ -120,7 +121,7 @@ if(isset($_GET['invoice_id'], $_GET['url_key'])){
<div class="float-right">
<a class="btn btn-secondary" data-toggle="collapse" href="#collapsePreviousInvoices"><i class="fa fa-fw fa-history"></i> Invoice History</a>
<a class="btn btn-primary" href="#" onclick="window.print();"><i class="fa fa-fw fa-print"></i> Print</a>
<a class="btn btn-primary" target="_blank" href="guest_post.php?download_invoice=<?php echo $invoice_id; ?>&url_key=<?php echo $url_key; ?>"><i class="fa fa-fw fa-download"></i> Download</a>
<a class="btn btn-primary" href="#" onclick="pdfMake.createPdf(docDefinition).download('<?php echo "$invoice_date-$company_name-Invoice-$invoice_prefix$invoice_number.pdf"; ?>');"><i class="fa fa-fw fa-download"></i> Download</a>
<?php
if($invoice_status != "Paid" and $invoice_status != "Cancelled" and $invoice_status != "Draft" and $config_stripe_enable == 1){
?>
@ -492,6 +493,409 @@ if(isset($_GET['invoice_id'], $_GET['url_key'])){
</table>
</div>
</div>
<script src='plugins/pdfmake/pdfmake.js'></script>
<script src='plugins/pdfmake/vfs_fonts.js'></script>
<script>
// Invoice markup
// Author: Max Kostinevich
// BETA (no styles)
// http://pdfmake.org/playground.html
// playground requires you to assign document definition to a variable called dd
// CodeSandbox Example: https://codesandbox.io/s/pdfmake-invoice-oj81y
var docDefinition = {
info: {
title: '<?php echo "$company_name - Invoice"; ?>',
author: '<?php echo $company_name; ?>'
},
footer: {
columns: [
{ text: '<?php echo $config_invoice_footer; ?>', style: 'documentFooterCenter' },
]
},
watermark: {text: '<?php echo $invoice_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: 'INVOICE',
style: 'invoiceTitle',
width: '*'
},
{
stack: [
{
columns: [
{
text:'Invoice #',
style:'invoiceSubTitle',
width: '*'
},
{
text:'<?php echo "$invoice_prefix$invoice_number"; ?>',
style:'invoiceSubValue',
width: 100
}
]
},
{
columns: [
{
text:'Date Issued',
style:'invoiceSubTitle',
width: '*'
},
{
text:'<?php echo $invoice_date ?>',
style:'invoiceSubValue',
width: 100
}
]
},
{
columns: [
{
text:'Due Date',
style:'invoiceSubTitle',
width: '*'
},
{
text:'<?php echo $invoice_due ?>',
style:'invoiceSubValue',
width: 100
}
]
},
]
}
],
],
},
// 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 invoice_id = $invoice_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 $invoice_amount; ?>',
style:'itemsFooterTotalValue'
}
],
[
{
text:'Paid',
style:'itemsFooterSubTitle'
},
{
text: '$<?php echo $amount_paid; ?>',
style:'itemsFooterSubValue'
}
],
[
{
text:'Balance',
style:'itemsFooterSubTitle'
},
{
text: '$<?php echo $balance; ?>',
style:'itemsFooterSubValue'
}
],
]
}, // 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>
<?php
}
?>

View File

@ -60,6 +60,7 @@ if(isset($_GET['quote_id'], $_GET['url_key'])){
}
$company_email = $row['company_email'];
$company_logo = $row['company_logo'];
$company_logo_base64 = base64_encode(file_get_contents($row['company_logo']));
$quote_footer = $row['quote_footer'];
$ip = get_ip();
@ -93,7 +94,7 @@ if(isset($_GET['quote_id'], $_GET['url_key'])){
<div class="float-right">
<a class="btn btn-primary" href="#" onclick="window.print();"><i class="fa fa-fw fa-print"></i> Print</a>
<a class="btn btn-primary" target="_blank" href="guest_post.php?download_quote=<?php echo $quote_id; ?>&url_key=<?php echo $url_key; ?>"><i class="fa fa-fw fa-download"></i> Download</a>
<a class="btn btn-primary" href="#" onclick="pdfMake.createPdf(docDefinition).download('<?php echo "$quote_date-$company_name-QUOTE-$quote_prefix$quote_number.pdf"; ?>');"><i class="fa fa-fw fa-download"></i> Download</a>
</div>
</div>
<div class="card-body">
@ -243,6 +244,363 @@ if(isset($_GET['quote_id'], $_GET['url_key'])){
</div>
</div>
<script src='plugins/pdfmake/pdfmake.js'></script>
<script src='plugins/pdfmake/vfs_fonts.js'></script>
<script>
// Invoice markup
// Author: Max Kostinevich
// BETA (no styles)
// http://pdfmake.org/playground.html
// playground requires you to assign document definition to a variable called dd
// CodeSandbox Example: https://codesandbox.io/s/pdfmake-invoice-oj81y
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>
<?php
}else{
echo "GTFO";

View File

@ -65,6 +65,7 @@ if(isset($_GET['invoice_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 invoice_id = $invoice_id ORDER BY history_id DESC");
@ -76,6 +77,7 @@ if(isset($_GET['invoice_id'])){
$amount_paid = $row['amount_paid'];
$balance = $invoice_amount - $amount_paid;
$balance = number_format($balance,2);
//check to see if overdue
if($invoice_status !== "Paid" AND $invoice_status !== "Draft" AND $invoice_status !== "Cancelled"){
@ -150,7 +152,7 @@ if(isset($_GET['invoice_id'])){
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addInvoiceRecurringModal<?php echo $invoice_id; ?>">Recurring</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_invoice=<?php echo $invoice_id; ?>">Download</a>
<a class="dropdown-item" href="#" onclick="pdfMake.createPdf(docDefinition).download('<?php echo "$invoice_date-$company_name-$client_name-Invoice-$invoice_prefix$invoice_number.pdf"; ?>');">Download PDF</a>
<a class="dropdown-item" href="post.php?email_invoice=<?php echo $invoice_id; ?>">Send Email</a>
<a class="dropdown-item" target="_blank" href="guest_view_invoice.php?invoice_id=<?php echo "$invoice_id&url_key=$invoice_url_key"; ?>">Guest URL</a>
@ -269,9 +271,9 @@ if(isset($_GET['invoice_id'])){
<td><?php echo $item_name; ?></td>
<td><?php echo $item_description; ?></td>
<td class="text-center"><?php echo $item_quantity; ?></td>
<td class="text-right text-monospace">$<?php echo number_format($item_price,2); ?></td>
<td class="text-right text-monospace">$<?php echo number_format($item_tax,2); ?></td>
<td class="text-right text-monospace">$<?php echo number_format($item_total,2); ?></td>
<td class="text-right">$<?php echo number_format($item_price,2); ?></td>
<td class="text-right">$<?php echo number_format($item_tax,2); ?></td>
<td class="text-right">$<?php echo number_format($item_total,2); ?></td>
</tr>
<?php
@ -342,23 +344,23 @@ if(isset($_GET['invoice_id'])){
<tbody>
<tr class="border-bottom">
<td>Subtotal</td>
<td class="text-right text-monospace">$<?php echo number_format($sub_total,2); ?></td>
<td class="text-right">$<?php echo number_format($sub_total,2); ?></td>
</tr>
<?php if($total_tax > 0){ ?>
<tr class="border-bottom">
<td>Tax</td>
<td class="text-right text-monospace">$<?php echo number_format($total_tax,2); ?></td>
<td class="text-right">$<?php echo number_format($total_tax,2); ?></td>
</tr>
<?php } ?>
<?php if($amount_paid > 0){ ?>
<tr class="border-bottom">
<td><div class="text-success">Paid to Date</div></td>
<td class="text-right text-monospace text-success">$<?php echo number_format($amount_paid,2); ?></td>
<td class="text-right text-success">$<?php echo number_format($amount_paid,2); ?></td>
</tr>
<?php } ?>
<tr class="border-bottom">
<td><strong>Balance Due</strong></td>
<td class="text-right text-monospace"><strong>$<?php echo number_format($balance,2); ?></strong></td>
<td class="text-right"><strong>$<?php echo number_format($balance,2); ?></strong></td>
</tr>
</tbody>
</table>
@ -484,6 +486,407 @@ include("footer.php");
?>
<script src='plugins/pdfmake/pdfmake.js'></script>
<script src='plugins/pdfmake/vfs_fonts.js'></script>
<script>
// Invoice markup
// Author: Max Kostinevich
// BETA (no styles)
// http://pdfmake.org/playground.html
// playground requires you to assign document definition to a variable called dd
// CodeSandbox Example: https://codesandbox.io/s/pdfmake-invoice-oj81y
var docDefinition = {
info: {
title: '<?php echo "$company_name - Invoice"; ?>',
author: '<?php echo $company_name; ?>'
},
footer: {
columns: [
{ text: '<?php echo $config_invoice_footer; ?>', style: 'documentFooterCenter' },
]
},
watermark: {text: '<?php echo $invoice_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: 'INVOICE',
style: 'invoiceTitle',
width: '*'
},
{
stack: [
{
columns: [
{
text:'Invoice #',
style:'invoiceSubTitle',
width: '*'
},
{
text:'<?php echo "$invoice_prefix$invoice_number"; ?>',
style:'invoiceSubValue',
width: 100
}
]
},
{
columns: [
{
text:'Date Issued',
style:'invoiceSubTitle',
width: '*'
},
{
text:'<?php echo $invoice_date ?>',
style:'invoiceSubValue',
width: 100
}
]
},
{
columns: [
{
text:'Due Date',
style:'invoiceSubTitle',
width: '*'
},
{
text:'<?php echo $invoice_due ?>',
style:'invoiceSubValue',
width: 100
}
]
},
]
}
],
],
},
// 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 invoice_id = $invoice_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 $invoice_amount; ?>',
style:'itemsFooterTotalValue'
}
],
[
{
text:'Paid',
style:'itemsFooterSubTitle'
},
{
text: '$<?php echo $amount_paid; ?>',
style:'itemsFooterSubValue'
}
],
[
{
text:'Balance',
style:'itemsFooterSubTitle'
},
{
text: '$<?php echo $balance; ?>',
style:'itemsFooterSubValue'
}
],
]
}, // 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>
<script>
var products = [

View File

@ -295,7 +295,6 @@
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addInvoiceCopyModal<?php echo $invoice_id; ?>">Copy</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="post.php?email_invoice=<?php echo $invoice_id; ?>">Send</a>
<a class="dropdown-item" target="_blank" href="post.php?pdf_invoice=<?php echo $invoice_id; ?>">Download</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="post.php?delete_invoice=<?php echo $invoice_id; ?>">Delete</a>
</div>

900
post.php
View File

@ -2041,425 +2041,6 @@ if(isset($_GET['decline_quote'])){
}
if(isset($_GET['download_quote'])){
$quote_id = intval($_GET['download_quote']);
$sql = mysqli_query($mysqli,"SELECT * FROM quotes, clients, companies
WHERE quotes.client_id = clients.client_id
AND quotes.company_id = companies.company_id
AND quotes.quote_id = $quote_id
AND quotes.company_id = $session_company_id"
);
$row = mysqli_fetch_array($sql);
$quote_id = $row['quote_id'];
$quote_prefix = $row['quote_prefix'];
$quote_number = $row['quote_number'];
$quote_status = $row['quote_status'];
$quote_date = $row['quote_date'];
$quote_amount = $row['quote_amount'];
$quote_note = $row['quote_note'];
$quote_url_key = $row['quote_url_key'];
$client_id = $row['client_id'];
$client_name = $row['client_name'];
$client_address = $row['client_address'];
$client_city = $row['client_city'];
$client_state = $row['client_state'];
$client_zip = $row['client_zip'];
$client_email = $row['client_email'];
$client_phone = $row['client_phone'];
if(strlen($client_phone)>2){
$client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4);
}
$client_extension = $row['client_extension'];
$client_mobile = $row['client_mobile'];
if(strlen($client_mobile)>2){
$client_mobile = substr($row['client_mobile'],0,3)."-".substr($row['client_mobile'],3,3)."-".substr($row['client_mobile'],6,4);
}
$client_website = $row['client_website'];
$company_name = $row['company_name'];
$company_country = $row['company_country'];
$company_address = $row['company_address'];
$company_city = $row['company_city'];
$company_state = $row['company_state'];
$company_zip = $row['company_zip'];
$company_phone = $row['company_phone'];
if(strlen($company_phone)>2){
$company_phone = substr($row['company_phone'],0,3)."-".substr($row['company_phone'],3,3)."-".substr($row['company_phone'],6,4);
}
$company_email = $row['company_email'];
$company_website = $row['company_website'];
$company_logo = base64_encode(file_get_contents($row['company_logo']));
?>
<script src='plugins/pdfmake/pdfmake.js'></script>
<script src='plugins/pdfmake/vfs_fonts.js'></script>
<script>
// Invoice markup
// Author: Max Kostinevich
// BETA (no styles)
// http://pdfmake.org/playground.html
// playground requires you to assign document definition to a variable called dd
// CodeSandbox Example: https://codesandbox.io/s/pdfmake-invoice-oj81y
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"; ?>',
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,
}
};
pdfMake.createPdf(docDefinition).download('<?php echo "$quote_date-$company_name-$client_name-Quote-$quote_prefix$quote_number.pdf"; ?>');
</script>
<?php
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Quote', log_action = 'Downloaded', log_description = '$quote_id', log_created_at = NOW(), company_id = $session_company_id, user_id = $session_user_id");
}
if(isset($_GET['email_quote'])){
$quote_id = intval($_GET['email_quote']);
@ -3327,487 +2908,6 @@ if(isset($_GET['delete_revenue'])){
}
if(isset($_GET['download_invoice'])){
$invoice_id = intval($_GET['download_invoice']);
$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients, companies
WHERE invoices.client_id = clients.client_id
AND invoices.company_id = companies.company_id
AND invoices.invoice_id = $invoice_id"
);
$row = mysqli_fetch_array($sql);
$invoice_id = $row['invoice_id'];
$invoice_prefix = $row['invoice_prefix'];
$invoice_number = $row['invoice_number'];
$invoice_scope = $row['invoice_scope'];
$invoice_status = $row['invoice_status'];
$invoice_date = $row['invoice_date'];
$invoice_due = $row['invoice_due'];
$invoice_amount = $row['invoice_amount'];
$invoice_note = $row['invoice_note'];
$invoice_url_key = $row['invoice_url_key'];
$invoice_created_at = $row['invoice_created_at'];
$category_id = $row['category_id'];
$client_id = $row['client_id'];
$client_name = $row['client_name'];
$client_address = $row['client_address'];
$client_city = $row['client_city'];
$client_state = $row['client_state'];
$client_zip = $row['client_zip'];
$client_email = $row['client_email'];
$client_phone = $row['client_phone'];
if(strlen($client_phone)>2){
$client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4);
}
$client_extension = $row['client_extension'];
$client_mobile = $row['client_mobile'];
if(strlen($client_mobile)>2){
$client_mobile = substr($row['client_mobile'],0,3)."-".substr($row['client_mobile'],3,3)."-".substr($row['client_mobile'],6,4);
}
$client_website = $row['client_website'];
$client_net_terms = $row['client_net_terms'];
if($client_net_terms == 0){
$client_net_terms = $config_default_net_terms;
}
$company_name = $row['company_name'];
$company_country = $row['company_country'];
$company_address = $row['company_address'];
$company_city = $row['company_city'];
$company_state = $row['company_state'];
$company_zip = $row['company_zip'];
$company_phone = $row['company_phone'];
if(strlen($company_phone)>2){
$company_phone = substr($row['company_phone'],0,3)."-".substr($row['company_phone'],3,3)."-".substr($row['company_phone'],6,4);
}
$company_email = $row['company_email'];
$company_website = $row['company_website'];
$company_logo = base64_encode(file_get_contents($row['company_logo']));
//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 invoice_id = $invoice_id");
$row = mysqli_fetch_array($sql_amount_paid);
$amount_paid = $row['amount_paid'];
$amount_paid = number_format($amount_paid, 2);
$balance = $invoice_amount - $amount_paid;
$balance = number_format($balance, 2);
?>
<script src='plugins/pdfmake/pdfmake.js'></script>
<script src='plugins/pdfmake/vfs_fonts.js'></script>
<script>
// Invoice markup
// Author: Max Kostinevich
// BETA (no styles)
// http://pdfmake.org/playground.html
// playground requires you to assign document definition to a variable called dd
// CodeSandbox Example: https://codesandbox.io/s/pdfmake-invoice-oj81y
var docDefinition = {
info: {
title: '<?php echo "$company_name - Invoice"; ?>',
author: '<?php echo $company_name; ?>'
},
footer: {
columns: [
{ text: '<?php echo $config_invoice_footer; ?>', style: 'documentFooterCenter' },
]
},
watermark: {text: '<?php echo $invoice_status; ?>', color: 'grey', opacity: 0.3, bold: true, italics: false},
content: [
// Header
{
columns: [
{
image: '<?php echo "data:image;base64,$company_logo"; ?>',
width: 120
},
[
{
text: 'INVOICE',
style: 'invoiceTitle',
width: '*'
},
{
stack: [
{
columns: [
{
text:'Invoice #',
style:'invoiceSubTitle',
width: '*'
},
{
text:'<?php echo "$invoice_prefix$invoice_number"; ?>',
style:'invoiceSubValue',
width: 100
}
]
},
{
columns: [
{
text:'Date Issued',
style:'invoiceSubTitle',
width: '*'
},
{
text:'<?php echo $invoice_date ?>',
style:'invoiceSubValue',
width: 100
}
]
},
{
columns: [
{
text:'Due Date',
style:'invoiceSubTitle',
width: '*'
},
{
text:'<?php echo $invoice_due ?>',
style:'invoiceSubValue',
width: 100
}
]
},
]
}
],
],
},
// 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 invoice_id = $invoice_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 $invoice_amount; ?>',
style:'itemsFooterTotalValue'
}
],
[
{
text:'Paid',
style:'itemsFooterSubTitle'
},
{
text: '$<?php echo $amount_paid; ?>',
style:'itemsFooterSubValue'
}
],
[
{
text:'Balance',
style:'itemsFooterSubTitle'
},
{
text: '$<?php echo $balance; ?>',
style:'itemsFooterSubValue'
}
],
]
}, // 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,
}
};
pdfMake.createPdf(docDefinition).download('<?php echo "$invoice_date-$company_name-$client_name-Invoice-$invoice_prefix$invoice_number.pdf"; ?>');
</script>
<?php
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Invoice', log_action = 'Downloaded', log_description = '$invoice_number', log_created_at = NOW(), company_id = $session_company_id, user_id = $session_user_id");
}
if(isset($_POST['add_contact'])){
$client_id = intval($_POST['client_id']);

353
quote.php
View File

@ -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>

View File

@ -176,7 +176,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
<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="post.php?email_quote=<?php echo $quote_id; ?>">Send</a>
<a class="dropdown-item" target="_blank" href="post.php?download_quote=<?php echo $quote_id; ?>">Download</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="post.php?delete_quote=<?php echo $quote_id; ?>">Delete</a>
</div>