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
303
304
305
306
307
308
309
|
<?php require_once('check_login.php'); require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf; use Dompdf\Options;
set_time_limit(0); ini_set('memory_limit', '512M'); ini_set('apc.cache_by_default', 0);
if (!($_GET["invoice_id"] || (int)$_GET["invoice_id"] >= 0 || $_GET["order_id"] || (int)$_GET["order_id"] >= 0)) { echo "<script>alert('請選擇正確的發票。'); history.back();</script>"; exit; }
date_default_timezone_set('Asia/Hong_Kong');
ini_set('apc.cache_by_default', 0);
if (PHP_SAPI == 'cli') { die('This example should only be run from a Web Browser'); }
// get invoice data $invoice_id = NULL; $order_id = NULL; $invoice_info = NULL; $customer_info = NULL; $balance = NULL; $code = NULL;
if ($_GET["invoice_id"]) { $invoice_id = (int)$_GET["invoice_id"]; $invoice_info = get_deposit($invoice_id); $balance = $invoice_info["deposit_balance"]; $code = $invoice_info["deposit_code"]; $order_id = (int)$invoice_info["order_id"]; //$customer_info = get_customer($invoice_info["customer_id"]); $order_info = get_order($order_id);
if ($invoice_info["deposit_status"] === "RETURNED" && !$order_info["withdraw_date"]){ $order_info = get_order_by_first_order_id_latest($order_id); } }
if ($_GET["order_id"]) { $order_id = $_GET["order_id"]; $order_info = get_order($order_id); $invoice_info = get_deposit_by_order_id($order_info['first_order_id']); $balance = $invoice_info["deposit_balance"]; $code = $invoice_info["deposit_code"]; // $customer_info = get_customer($invoice_info["customer_id"]); }
//get order data if(!empty($order_id)){
// $order_info = get_order($order_id); $customer_info = get_customer($order_info["customer_id"]);
$order_room_info = get_order_room($order_id); $order_room_list = ""; foreach($order_room_info as $order_room){ $room_info = get_room($order_room["room_id"]); $order_room_list .= check_combine_room($room_info["code"]).", "; } $order_info["order_room_list"] = substr_replace($order_room_list, "", -2);
$order_room_dtl = ""; foreach ($order_room_info as $order_room) { $room_info = get_room($order_room["room_id"]); $master_room_info = get_master_room($room_info["master_room_id"]); $order_room_list = check_combine_room($room_info["code"]) . " (" . $master_room_info["length"] . "'x" . $master_room_info["width"] . "'x" . $master_room_info["height"] . "')"; //$order_room_list = substr_replace($order_room_list ,"",-2); $order_room_dtl .= "<table><tr><td> 合約編號: " . $order_info["code"] .", 租用單位: " . $order_room_list . "</td></tr></table>"; } $withdraw_remuneration = ""; $actual_returnamount = ""; $deposit_code = ""; $withdraw_remuneration = numberformat($order_info['withdraw_remuneration']); $actual_returnamount = $invoice_info["actual_returnamount"]; $deposit_code = $invoice_info["deposit_code"]; /* if ($_GET["invoice_id"]){ $withdraw_remuneration = numberformat($order_info['withdraw_remuneration']); $actual_returnamount = $invoice_info["actual_returnamount"]; $deposit_code = $invoice_info["deposit_code"]; } else { $withdraw_remuneration = "0.00"; $actual_returnamount = "0.00"; $deposit_code = "不適用"; } */
// check corporate client or personal client if($order_info["customer_typeid"] == "PERSONAL"){ $idno = "Identification Number 身份證明號碼 :" . rsa_crypt($order_info["customer_identity_id"], 2); $name = $order_info["customer_name"]; }else{ $idno = "Business Registration No 商業登記證號碼 :" . rsa_crypt($order_info["customer_identity_id"], 2); $name = $order_info["customer_companyname"]; }
$content = " <!doctype html> <html lang='en'> <head> <meta charset='utf-8'> <title></title> <style> table { width: 100%; }
* { font-family: 'simsun'; }
/** Set the margins of the page to 0, so the footer and the header can be of the full height and width ! **/ @page { margin: 0cm 0cm; }
/** Define now the real margins of every page in the PDF **/ body { margin-top: 3cm; margin-left: 0.5cm; margin-right: 0.5cm; margin-bottom: 0.5cm; }
/** Define the header rules **/ header { position: fixed; top: 0cm; left: 0cm; right: 0cm; height: 3cm; }
/** Define the footer rules **/ footer { position: fixed; bottom: 0cm; left: 0cm; right: 0cm; height: 2cm; }
u { text-decoration: none; border-bottom: 1px solid #333; padding-bottom: 5px; display: inline-block; font-size: 11px; }
td { font-size: 12px; word-wrap: break-word; padding: 0; }
p { margin-top: 0; font-size: 11px; }
.page_break { page-break-before: always; }
.terms p { font-size: 10px; word-wrap: break-word; }
.terms p.title { font-size: 15px; text-align: center; margin: 0; } .title { font-size: 24px; text-align: center; margin: 0; } </style> </head> <body> <header> <img src='http://" . $_SERVER['SERVER_NAME'] . "/webadmin/pdf_template/header.png' width='100%' height='100%'/> </header> <br>
<table> <tr> <td style='font-size: 18px; text-align: center;'> <b> 退倉收據 </b> </td> </tr> </table> <hr> <br>
<table> <tr> <td>客戶編號 : " . $customer_info["code"] . "</td> <td style='text-align: right;'>日期: " . date("Y-m-d") . "</td> </tr> </table> <table> <tr> <td>客戶姓名 : " . $name . "</td> <td style='text-align: right;'>編號 : " . $deposit_code . "</td> </tr> </table> <table> <tr> <td>客戶地址 : " . rsa_crypt($order_info["customer_address"], 2) . "</td> <td style='text-align: right;'>退倉日期: " . substr($order_info["withdraw_date"],0 ,10) . "</td> </tr> </table>
<br> <table> <tr> <td style='font-size: 15px; font-weight: bold'>服務詳情</td> <td style='font-size: 15px; text-align: right; font-weight: bold;'>費用(HK$)</td> </tr> </table>
<table> <tr> <td>按金</td> <td style='text-align: right;'>" . numberformat($invoice_info["deposit_amount"]) . "</td> </tr> </table> ".$order_room_dtl." <br> <table> <tr> <td>合約到期日:". substr($order_info["enddate"],0 ,4) . "年" . substr($order_info["enddate"],5 ,2) . "月" . substr($order_info["enddate"],8 ,2) . "日" ." </td> </tr> </table> <table> <tr> <td>退還日期:". substr($order_info["withdraw_date"],0 ,4) . "年" . substr($order_info["withdraw_date"],5 ,2) . "月" . substr($order_info["withdraw_date"],8 ,2) . "日" ."</td> </tr> </table> <table> <tr> <td>額外租金</td> <td style='text-align: right;'>" . $withdraw_remuneration . "</td> </tr> </table>
<br> <table> <tr> <td style='text-align: right;'>_____________________________</td> </tr> </table>
<br> <table> <tr> <td>實際退回按金</td> <td style='text-align: right;'>" . numberformat($actual_returnamount) . "</td> </tr> </table> <br><br><br>
<b>備註 :</b> <p>**本公司未查核迷你倉的狀況,如發現迷你倉有損壞,本公司保留追討權利。</p> <p>按金會在15個工作天內以支票或銀行轉帳形式退還。</p> </body> </html> ";
$options = new Options(); $options->set('isHtml5ParserEnabled', true); $options->set('isRemoteEnabled', true); $options->set('isFontSubsettingEnabled', true); $dompdf = new Dompdf($options); $dompdf->loadHtml($content); $dompdf->render(); $dompdf->stream("TerminationReceipt_" . $order_info["order_room_list"] . "_" . $invoice_info["deposit_code"] . ".pdf");
/* if ($_GET['invoice_id']){ $dompdf->stream("TerminationReceipt_" . $order_info["order_room_list"] . "_" . $invoice_info["deposit_code"] . ".pdf"); } else { $dompdf->stream("TerminationReceipt_" . $order_info["order_room_list"] . ".pdf"); } */
} else { echo "<script>alert('找不到相關發票。');history.back();</script>"; } exit;
|