-
Notifications
You must be signed in to change notification settings - Fork 8
/
print_invoice.php
97 lines (96 loc) · 2.84 KB
/
print_invoice.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
session_start();
include 'Invoice.php';
$invoice = new Invoice();
$invoice->checkLoggedIn();
if(!empty($_GET['invoice_id']) && $_GET['invoice_id']) {
echo $_GET['invoice_id'];
$invoiceValues = $invoice->getInvoice($_GET['invoice_id']);
$invoiceItems = $invoice->getInvoiceItems($_GET['invoice_id']);
}
$invoiceDate = date("d/M/Y, H:i:s", strtotime($invoiceValues['order_date']));
$output = '';
$output .= '<table width="100%" border="1" cellpadding="5" cellspacing="0">
<tr>
<td colspan="2" align="center" style="font-size:18px"><b>Invoice</b></td>
</tr>
<tr>
<td colspan="2">
<table width="100%" cellpadding="5">
<tr>
<td width="65%">
To,<br />
<b>RECEIVER (BILL TO)</b><br />
Name : '.$invoiceValues['order_receiver_name'].'<br />
Billing Address : '.$invoiceValues['order_receiver_address'].'<br />
</td>
<td width="35%">
Invoice No. : '.$invoiceValues['order_id'].'<br />
Invoice Date : '.$invoiceDate.'<br />
</td>
</tr>
</table>
<br />
<table width="100%" border="1" cellpadding="5" cellspacing="0">
<tr>
<th align="left">Sr No.</th>
<th align="left">Item Code</th>
<th align="left">Item Name</th>
<th align="left">Quantity</th>
<th align="left">Price</th>
<th align="left">Actual Amt.</th>
</tr>';
$count = 0;
foreach($invoiceItems as $invoiceItem){
$count++;
$output .= '
<tr>
<td align="left">'.$count.'</td>
<td align="left">'.$invoiceItem["item_code"].'</td>
<td align="left">'.$invoiceItem["item_name"].'</td>
<td align="left">'.$invoiceItem["order_item_quantity"].'</td>
<td align="left">'.$invoiceItem["order_item_price"].'</td>
<td align="left">'.$invoiceItem["order_item_final_amount"].'</td>
</tr>';
}
$output .= '
<tr>
<td align="right" colspan="5"><b>Sub Total</b></td>
<td align="left"><b>'.$invoiceValues['order_total_before_tax'].'</b></td>
</tr>
<tr>
<td align="right" colspan="5"><b>Tax Rate :</b></td>
<td align="left">'.$invoiceValues['order_tax_per'].'</td>
</tr>
<tr>
<td align="right" colspan="5">Tax Amount: </td>
<td align="left">'.$invoiceValues['order_total_tax'].'</td>
</tr>
<tr>
<td align="right" colspan="5">Total: </td>
<td align="left">'.$invoiceValues['order_total_after_tax'].'</td>
</tr>
<tr>
<td align="right" colspan="5">Amount Paid:</td>
<td align="left">'.$invoiceValues['order_amount_paid'].'</td>
</tr>
<tr>
<td align="right" colspan="5"><b>Amount Due:</b></td>
<td align="left">'.$invoiceValues['order_total_amount_due'].'</td>
</tr>';
$output .= '
</table>
</td>
</tr>
</table>';
// create pdf of invoice
$invoiceFileName = 'Invoice-'.$invoiceValues['order_id'].'.pdf';
require_once 'dompdf/src/Autoloader.php';
Dompdf\Autoloader::register();
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml(html_entity_decode($output));
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream($invoiceFileName, array("Attachment" => false));
?>