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
|
<?php error_reporting(1); //ini_set('display_errors', '1'); require_once('pdf/config/lang/eng.php'); require_once('pdf/tcpdf.php'); require("inc/configure.php");
$return = $_GET['returnno'];
$sqlInv = "select invoicedtlid, b.orderdate from OM_RETURN_DTL a, OM_RETURN_HDR b where a.returnno = $return and a.returnno = b.returnno"; $resultInv = mysql_query($sqlInv); $rowInv = mysql_fetch_assoc($resultInv); $invoiceDtlId = $rowInv['invoicedtlid']; $date = $rowInv['orderdate'];
$sqlInv = "select invoiceno from OM_INVOICE_DTL where id = $invoiceDtlId"; $resultInv = mysql_query($sqlInv); $rowInv = mysql_fetch_assoc($resultInv);
$invoice = $rowInv['invoiceno'];
//$return = $GLOBALS['return']; //$invoice = $GLOBALS['invoice']; //$date = $GLOBALS['date'];
$sql = "select custnameeng, billaddress, telno, faxno, licno, caryear, modelno, chassisno, mileage from OM_INVOICE_HDR where invoiceno = $invoice";
$result = mysql_query($sql);
if($row = mysql_fetch_array($result,MYSQL_ASSOC)){
$custnameeng = $row{'custnameeng'}; $telno = $row{'telno'}; $faxno = $row{'faxno'}; $billaddress = $row{'billaddress'}; $licno = $row['licno']; $caryear = $row['caryear']; $mileage = $row['mileage']; $modelno = $row['modelno']; $chassisno = $row['chassisno']; }
$r0 = $r1 = $r2 = $r3 = $x_main = $y_main = 0; /*var_dump($row); echo"hi"; exit;*/ $sc = substr_count($billaddress, "\n");
class creditnote extends TCPDF{ //Page header public function Header(){ $image_file = 'creditnote.jpg'; $this->Image($image_file, 110, 10, '', 150); $this->SetFont('stsongstdlight', '', 12); // bold $this->SetXY(400,130); $this->Cell(90, 0, 'No.: ', 0, 0, 'R'); $this->Cell(80, 0, $GLOBALS['return'], 0, 1, 'L'); $this->SetX(400); $this->Cell(90, 0, 'Date: ', 0, 0, 'R'); $this->Cell(80, 0, $GLOBALS['date'], 0, 1, 'L'); $this->SetCellPadding(5); $this->Cell(270, 0, '客戶資料 Customer Detail', 1, 0); $this->Cell(270, 0, '車輛資料 Vehicle Data', 1, 1); $tmp_left = '姓名Name: '.html_entity_decode($GLOBALS['custnameeng']).PHP_EOL. '地址Addrs: '.html_entity_decode($GLOBALS['billaddress']).PHP_EOL. '電話Tel: '.html_entity_decode($GLOBALS['telno']).PHP_EOL. '傳真Fax: '.html_entity_decode($GLOBALS['faxno']).PHP_EOL; $tmp_right = '車牌Lic No.: '.html_entity_decode($GLOBALS['licno'])." 年款Year: ".html_entity_decode($GLOBALS['caryear']).PHP_EOL. '型號Model: '.html_entity_decode($GLOBALS['modelno']).PHP_EOL. '車身Chas No.: '.html_entity_decode($GLOBALS['chassisno']).PHP_EOL. '里數Mileage: '.html_entity_decode($GLOBALS['mileage']).PHP_EOL; $height_2row = max( $this->getStringHeight(250, $tmp_left), $this->getStringHeight(270, $tmp_right) )+5; $this->MultiCell(270, $height_2row, $tmp_left, 1, 'L', 0, 0); $this->MultiCell(270, $height_2row, $tmp_right, 1, 'L'); $height_2row=35; $GLOBALS['r0']= $this->GetX(); $this->MultiCell(300, $height_2row, '項目'.PHP_EOL.'Particulars', 1, 'C', 0, 0); //$this->Cell(300, 0, 'Particulars', 1, 0, 'C'); $GLOBALS['r1']= $this->GetX(); $this->MultiCell(80, $height_2row, '單價'.PHP_EOL.'Unit price', 1, 'C', 0, 0); //$this->Cell(80, 0, 'Unit Price', 1, 0, 'R'); $this->MultiCell(80, $height_2row, '數量'.PHP_EOL.'Qty', 1, 'C', 0, 0); $GLOBALS['r2']= $this->GetX(); //$this->Cell(80, 0, 'Quantity', 1, 0, 'R'); $this->MultiCell(80, $height_2row, '金額'.PHP_EOL.'Total', 1, 'C', 0); $GLOBALS['r3']= $this->GetX(); //$this->Cell(80, 0, 'Amount', 1, 1, 'R'); $GLOBALS['x_main']= $this->GetX(); $GLOBALS['y_main']= $this->GetY(); }
// Page footer public function Footer(){ $this->SetY(-10); // Set font $this->SetFont('helvetica', 'I', 8); // Page number $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M'); } }
// create new PDF document $pdf = new creditnote('P', 'pt', 'A4', true, 'UTF-8', false); // set document information $pdf->SetCreator('One Solution'); $pdf->SetAuthor('One Solution'); $pdf->SetTitle('One Solution'); $pdf->SetSubject('One Solution'); $pdf->SetKeywords('One Solution'); // set default header data //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 008', PDF_HEADER_STRING); // set header and footer fonts //$pdf->setHeaderFont(Array(stsongstdlight, '', PDF_FONT_SIZE_MAIN)); //$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, 75, PDF_MARGIN_RIGHT); // left, top, right $pdf->SetHeaderMargin(10); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetCellPadding(5); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, 50); //set image scale factor $pdf->setImageScale(1.3333); //set some language-dependent strings $pdf->setLanguageArray($l); // set font $pdf->SetFont('stsongstdlight', '', 12); // bold // add a page $pdf->AddPage();
$pdf->SetTopMargin($y_main);
$sql = "select b.prodno, b.prodname, a.qty, a.amount, b.invoiceno from (select invoicedtlid, qty, amount from OM_RETURN_DTL where returnno = $return) a, OM_INVOICE_DTL b where a.invoicedtlid = b.id"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result);
$pdf->MultiCell(300, $maxheight, "Original Invoice No: ".$row['invoiceno'], 'LR', 'L', 0, 0); $pdf->MultiCell(80, $maxheight, '', 'LR', 'R', 0, 0); $pdf->MultiCell(80, $maxheight, '', 'LR', 'C', 0, 0); $pdf->MultiCell(80, $maxheight, '', 'LR', 'R', 0);
mysql_data_seek($result, 0);
$subamount=0; while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $prodno = $row['prodno']; $prodname = $row['prodname']; $price = $row['price']; $qty = $row['qty']; $amount = $row['amount']; $maxheight= $pdf->getStringHeight(240, $prodname); if($pdf->GetY()+$maxheight>770){ // add a page $pdf->AddPage(); } //$pdf->MultiCell(50, $maxheight, $pdf->GetY(), 1, 'L', 0, 0); $pdf->MultiCell(50, $maxheight, $prodno, 'L', 'L', 0, 0); $pdf->MultiCell(250, $maxheight, $prodname, 'R', 'L', 0, 0); $pdf->MultiCell(80, $maxheight, number_format($price,2), 'LR', 'R', 0, 0); $pdf->MultiCell(80, $maxheight, round($qty,1), 'LR', 'C', 0, 0); $pdf->MultiCell(80, $maxheight, number_format($amount,2), 'LR', 'R', 0);
$subamount += $amount; } $height_2row=20; $pdf->MultiCell(460, $height_2row, '總數 Total:', 1, 'R', 0, 0); $pdf->MultiCell(80, $height_2row, number_format($subamount,2), 1, 'R', 0); $pdf->Ln(10);
/*$pdf->MultiCell(250, 60, ' '.PHP_EOL.'經手人'.PHP_EOL.'Issued by:', 'B', 'L', 0, 0); */
$pdf->MultiCell(250, 90, PHP_EOL.PHP_EOL.PHP_EOL.'簽署'.PHP_EOL.'Signature:', 'B', 'L', 0, 0);
$pdf->SetX(300); $pdf->MultiCell(250, 90, PHP_EOL.PHP_EOL.PHP_EOL.'日期'.PHP_EOL.'Date:', 'B', 'L', 0, 1);
//Close and output PDF document $pdf->Output("invoice_$invoiceno.pdf", 'I'); ?>
|