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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
<? require("inc/configure.php"); require("inc/global.php"); require("inc/checklogin.php"); if ($logged_in == 0) { //echo 'Not logged in. <a href="login.php">Login</a>'; header('Window-target: _parent'); header('Location: login.php'); exit(); } ?> <?php $invoiceno = $_GET['invoiceno'];
$sql = "SELECT a.invoiceno, a.custid, a.custno , a.custnameeng, a.telno, a.faxno , a.email, b.username, a.orderdate , a.billaddress, a.discount, paymentmethod , paymentterm, sum(c.amount)-a.discount as totalamount , a.status, a.attn from OM_INVOICE_HDR a , SYS_USER b , OM_INVOICE_DTL c , SYS_PAYMENTMETHOD d , SYS_PAYMENTTERM e where a.salesid = b.userid and a.invoiceno = c.invoiceno and a.invoiceno = $invoiceno and a.paymentmethodid = d.paymentmethodid and a.paymenttermid = e.paymenttermid and salesman = 1 group by a.invoiceno, a.custid, a.custno , a.custnameeng, a.telno, a.faxno , a.orderdate, b.username, a.discount , paymentmethod, paymentterm, a.status , a.attn";
$result = mysql_query($sql); if ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $custno = $row{'custno'}; $catid = $row{'catid'}; $custnameeng = $row{'custnameeng'}; $telno = $row{'telno'}; $faxno = $row{'faxno'}; $email = $row{'email'}; $salesman = $row{'username'}; $orderdate = $row{'orderdate'}; $totalamount = $row{'totalamount'}; $billaddress = $row{'billaddress'}; $attn = $row{'attn'};
$paymentmethodid = $row{'paymentmethodid'}; $paymenttermid = $row{'paymenttermid'};
$headerdiscount = $row{'discount'}; $deliverymethod = $row{'deliverymethod'}; $status = $row{'status'};
$paymentmethod = $row{'paymentmethod'}; $paymentterm = $row{'paymentterm'}; }
// don't want any warnings turning up in the pdf code if the server is set to 'anal' mode. //error_reporting(7); error_reporting(E_ALL); set_time_limit(1800);
include 'pdf/class.ezpdf.php';
// define a clas extension to allow the use of a callback to get the table of contents, and to put the dots in the toc class Creport extends Cezpdf {
var $reportContents = array();
function Creport($p,$o){ $this->Cezpdf($p,$o); }
function rf($info){ // this callback records all of the table of contents entries, it also places a destination marker there // so that it can be linked too $tmp = $info['p']; $lvl = $tmp[0]; $lbl = rawurldecode(substr($tmp,1)); $num=$this->ezWhatPageNumber($this->ezGetCurrentPageNumber()); $this->reportContents[] = array($lbl,$num,$lvl ); $this->addDestination('toc'.(count($this->reportContents)-1),'FitH',$info['y']+$info['height']); }
function dots($info){ // draw a dotted line over to the right and put on a page number $tmp = $info['p']; $lvl = $tmp[0]; $lbl = substr($tmp,1); $xpos = 520;
switch($lvl){ case '1': $size=16; $thick=1; break; case '2': $size=12; $thick=0.5; break; }
$this->saveState(); $this->setLineStyle($thick,'round','',array(0,10)); $this->line($xpos,$info['y'],$info['x']+5,$info['y']); $this->restoreState(); $this->addText($xpos+5,$info['y'],$size,$lbl); }
} // I am in NZ, so will design my page for A4 paper.. but don't get me started on that. // (defaults to legal) // this code has been modified to use ezpdf.
//$pdf = new Cezpdf('a4','portrait'); $pdf = new Creport('a4','portrait'); $pdf -> ezSetMargins(30,30,30,30);
//$mainFont = './fonts/Helvetica.afm'; $mainFont = 'pdf/fonts/Times-Roman.afm'; $codeFont = 'pdf/fonts/Courier.afm'; // select a font
$pdf->selectFont($mainFont);
$pdf->openHere('Fit');
//if (file_exists('images/logo01.jpg')){ // $pdf->addJpegFromFile('images/logo01.jpg',20,$pdf->y-20,100,0); //} else { // comment out these two lines if you do not have GD jpeg support // I couldn't quickly see a way to test for this support from the code. // you could also copy the file from the locatioin shown and put it in the directory, then // the code above which doesn't use GD will be activated. $img = ImageCreatefromjpeg('http://www.onesolution.com.hk/oneERP/images/logo01.jpg'); $pdf-> addImage($img,20,$pdf->y-30,180,0); //}
$pdf->ezSetDy(-20);
//** header $data = array( array('col1'=>'Bill To:','col2'=>$custnameeng,'col3'=>'Invoice no.:','col4'=>$invoiceno) ,array('col1'=>'Address','col2'=>$billaddress,'col3'=>'Date:','col4'=>$orderdate) ,array('col1'=>'','col2'=>'','col3'=>'From:','col4'=>$salesman) ,array('col1'=>'','col2'=>'','col3'=>'Tel:','col4'=>'') ,array('col1'=>'','col2'=>'','col3'=>'Fax:','col4'=>'') ,array('col1'=>'Attn:','col2'=>$attn,'col3'=>'Email:','col4'=>'') ,array('col1'=>'Tel:','col2'=>$telno,'col3'=>'Payment Terms:','col4'=>$paymentterm) ,array('col1'=>'Email:','col2'=>$email,'col3'=>'Payment Method:','col4'=>$paymentmethod) ); $pdf->ezTable($data,$cols,'', array('xPos'=>'center','xOrientation'=>'center','showLines'=>0,'shaded'=>0,'showHeadings'=>0,'width'=>700 ,'cols'=>array( 'col1'=>array('justification'=>'right','width'=>120) ,'col2'=>array('width'=>230) ,'col3'=>array('justification'=>'right','width'=>120) ,'col4'=>array('width'=>230)) ));
$pdf->ezText("Delivery Note\n",20,array('justification'=>'centre'));
//** detail $sql = "select * from OM_INVOICE_DTL where invoiceno = $invoiceno order by lineno"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $lineno = $row{'lineno'}; $prodid = $row{'prodid'}; $barcode = $row{'barcode'}; $prodname = $row{'prodname'}; $qty = $row{'qty'}; $uom = $row{'uom'}; $price = $row{'price'}; $discount = $row{'discount'}; $amount = $row{'amount'}; $cost = $row{'cost'}; $description = $row{'description'}; $data1[] = array('subcol1'=>$lineno,'subcol2'=>$prodid,'subcol3'=>$barcode,'subcol4'=>$prodname,'subcol5'=>$qty,'subcol6'=>$uom); $subamount += $amount; }
$subcols = array('subcol1'=>"No.",'subcol2'=>'Product code','subcol3'=>'Barcode','subcol4'=>'Product name','subcol5'=>'Qty','subcol6'=>'UOM'); $pdf->ezTable($data1,$subcols,'', array('xPos'=>'center','xOrientation'=>'center','showLines'=>1,'shaded'=>1,'showHeadings'=>1,'width'=>550 ,'cols'=>array( 'subcol1'=>array('justification'=>'right','width'=>40) ,'subcol2'=>array('width'=>50) ,'subcol3'=>array('width'=>60) ,'subcol4'=>array('width'=>160) ,'subcol5'=>array('justification'=>'right','width'=>50) ,'subcol6'=>array('width'=>40)) ));
//** total /* $datatotal = array( array('subcol1'=>'Amount:','subcol2'=>number_format($subamount,2)) ,array('subcol1'=>'Discount:','subcol2'=>number_format($headerdiscount,2)) ,array('subcol1'=>'Grand Total:','subcol2'=>number_format($subamount-$headerdiscount,2))); $totalcols = array('subcol1'=>"empty",'subcol2'=>'total'); $pdf->ezTable($datatotal,$totalcols,'', array('xPos'=>'center','xOrientation'=>'center','showLines'=>0,'shaded'=>0,'showHeadings'=>0,'width'=>550 ,'cols'=>array( 'subcol1'=>array('justification'=>'right','width'=>500) ,'subcol2'=>array('justification'=>'right','width'=>50)) )); */
if (isset($d) && $d){ $pdfcode = $pdf->ezOutput(1); $pdfcode = str_replace("\n","\n<br>",htmlspecialchars($pdfcode)); echo '<html><body>'; echo trim($pdfcode); echo '</body></html>'; } else { $pdf->ezStream(); } ?>
|