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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
<?php error_reporting(1); //ini_set('display_errors', '1'); require_once('config/lang/eng.php'); require_once('tcpdf.php');
$quotationno = $_GET['quotationno'];
require("../inc/configure.php");
$sql = "SELECT a.quotationno, a.custid, a.custno, a.mileage , 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, licno, modelno, chassisno from OM_QUOTATION_HDR a left outer join OM_QUOTATION_DTL c on a.quotationno = c.quotationno , SYS_USER b , SYS_PAYMENTMETHOD d , SYS_PAYMENTTERM e where a.salesid = b.userid and a.quotationno = $quotationno and a.paymentmethodid = d.paymentmethodid and a.paymenttermid = e.paymenttermid and salesman = 1 group by a.quotationno, 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 = html_entity_decode($row{'prefix'}, ENT_QUOTES).html_entity_decode($row{'custno'}, ENT_QUOTES); $catid = html_entity_decode($row{'catid'}, ENT_QUOTES); $custnameeng = html_entity_decode($row{'custnameeng'}, ENT_QUOTES); $telno = html_entity_decode($row{'telno'}, ENT_QUOTES); $faxno = html_entity_decode($row{'faxno'}, ENT_QUOTES); $email = html_entity_decode($row{'email'}, ENT_QUOTES); $salesman = html_entity_decode($row{'username'}, ENT_QUOTES); $orderdate = html_entity_decode($row{'orderdate'}, ENT_QUOTES); $totalamount = html_entity_decode($row{'totalamount'}, ENT_QUOTES); $billaddress = html_entity_decode($row{'billaddress'}, ENT_QUOTES); $attn = html_entity_decode($row{'attn'}, ENT_QUOTES);
$paymentmethodid = html_entity_decode($row{'paymentmethodid'}, ENT_QUOTES); $paymenttermid = html_entity_decode($row{'paymenttermid'}, ENT_QUOTES);
$headerdiscount = html_entity_decode($row{'discount'}, ENT_QUOTES); $deliverymethod = html_entity_decode($row{'deliverymethod'}, ENT_QUOTES); $status = html_entity_decode($row{'status'}, ENT_QUOTES);
$paymentmethod = html_entity_decode($row{'paymentmethod'}, ENT_QUOTES); $paymentterm = html_entity_decode($row{'paymentterm'}, ENT_QUOTES);
$licno = html_entity_decode($row{'licno'}, ENT_QUOTES); $modelno = html_entity_decode($row{'modelno'}, ENT_QUOTES); $chassisno = html_entity_decode($row{'chassisno'}, ENT_QUOTES); $mileage = html_entity_decode($row['mileage'], ENT_QUOTES); }
$r0 = $r1 = $r2 = $r3 = $x_main = $y_main = 0;
$sc = substr_count($billaddress, "\n");
class quotation extends TCPDF{ //Page header public function Header(){
$image_file = 'quotation.jpg'; $this->Image($image_file, 110, 10, '', 150);
$temp = $GLOBALS['licno']; $result5 = mysql_query("select caryear, mileage from CM_CAR where licno = '$temp'"); $row5 = mysql_fetch_assoc($result5);
$this->SetFont('stsongstdlight', '', 11); // bold $this->SetXY(400,130); $this->Cell(90, 0, 'No.: ', 0, 0, 'R'); $this->Cell(80, 0, $GLOBALS['quotationno'], 0, 1, 'L'); $this->SetX(400); $this->Cell(90, 0, '日期 Date: ', 0, 0, 'R'); $this->Cell(80, 0, $GLOBALS['orderdate'], 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: '.($GLOBALS['custnameeng']).PHP_EOL. '地址Addrs: '.($GLOBALS['billaddress']).PHP_EOL. '電話Tel: '.($GLOBALS['telno']).PHP_EOL. '傳真Fax: '.($GLOBALS['faxno']).PHP_EOL;
$tmp_right = "車牌Lic No.: ".($GLOBALS['licno'])." 年款Year: ".($row5['caryear']).PHP_EOL. '型號Model: '.($GLOBALS['modelno']).PHP_EOL. '車身Chas No.: '.($GLOBALS['chassisno']).PHP_EOL. '里數Mileage(km): '.($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.'Service/Parts replacement item', 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 quotation('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', '', 10); // bold // add a page $pdf->AddPage();
$pdf->SetTopMargin($y_main); $originalCellHeightRatio = $pdf->getCellHeightRatio(); $pdf->setCellHeightRatio(0.9);
$sql = "select * from OM_QUOTATION_DTL where quotationno = $quotationno order by lineno"; $result = mysql_query($sql);
$subamount=0; while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $lineno = html_entity_decode($row{'lineno'}, ENT_QUOTES); $prodid = html_entity_decode($row{'prodid'}, ENT_QUOTES); $prodno = html_entity_decode($row{'prodno'}, ENT_QUOTES); $barcode = html_entity_decode($row{'barcode'}, ENT_QUOTES); $prodname = html_entity_decode($row{'prodname'}, ENT_QUOTES); $qty = html_entity_decode($row{'qty'}, ENT_QUOTES); $uom = html_entity_decode($row{'uom'}, ENT_QUOTES); $price = html_entity_decode($row{'price'}, ENT_QUOTES); $discount = html_entity_decode($row{'discount'}, ENT_QUOTES); $amount = html_entity_decode($row{'amount'}, ENT_QUOTES); $cost = html_entity_decode($row{'cost'}, ENT_QUOTES); $description = html_entity_decode($row{'description'}, ENT_QUOTES);
$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);
if($pdf->GetY()+$maxheight>770){ $pdf->MultiCell(540, 5, '', 'T', 'R', 0); }
$subamount += $amount; } $pdf->setCellHeightRatio($originalCellHeightRatio);
// remarks $sql4 = "select remarks from OM_QUOTATION_HDR where quotationno = $quotationno"; $result4 = mysql_query($sql4); $row4 = mysql_fetch_assoc($result4); $remarks2 = $row4['remarks'];
if (!empty($remarks2)) { switch ($quotationno) { case 100124: $temp_height = 68; break; default: $temp_height = 48; break; }
$pdf->MultiCell(300, $temp_height, 'Remarks:'.PHP_EOL.$remarks2, 'LR', 'L', 0, 0); $pdf->MultiCell(80, $temp_height, ' ', 'LR', 'R', 0, 0); $pdf->MultiCell(80, $temp_height, ' ', 'LR', 'C', 0, 0); $pdf->MultiCell(80, $temp_height, ' ', 'LR', 'R', 0); /* $pdf->Ln(42); switch ($quotationno) { case 100124: $pdf->Ln(20); break; } */ }
$height_2row=30;
$pdf->MultiCell(300, $height_2row, '本報價單有效期為30天'.PHP_EOL.'Quotation validity is 30 days from date of issue', 1, 'L', 0, 0); $pdf->MultiCell(160, $height_2row, '總數 Total:'.PHP_EOL.' ', 1, 'R', 0, 0); $pdf->MultiCell(80, $height_2row, number_format($subamount,2).PHP_EOL.' ', 1, 'R', 0);
if($pdf->GetY()>700){ $pdf->AddPage(); }
$pdf->Ln(62); $pdf->MultiCell(190, 0, '經手人:'.PHP_EOL.'Issued by:', 0, 'L', 0, 0); $pdf->MultiCell(80, 0, ''.PHP_EOL.'', 0, 'L', 0, 0); $pdf->MultiCell(190, 0, '同意接受以上維修報價:'.PHP_EOL.'Agreed & Accepted above:', 0, 'L', 0, 0);
$pdf->Ln(63); $pdf->MultiCell(190, 0, ''.PHP_EOL.'', 'B', 'L', 0, 0); $pdf->MultiCell(80, 0, ''.PHP_EOL.'', 0, 'L', 0, 0); $pdf->MultiCell(190, 0, ''.PHP_EOL.'', 'B', 'L', 0, 0);
//Close and output PDF document $pdf->Output("quotation_$quotationno.pdf", 'I'); ?>
|