/var/www/hkosl.com/innoutstorage/webadmin/output_order2_test.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
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
<?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(empty(
$_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 order data
$order_id = (int)$_GET["order_id"];
if(!empty(
$order_id)){
    
$order_info get_order($order_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_room_list substr_replace($order_room_list"", -2);

    
//$customer_info = get_customer($order_info["customer_id"]);

    
$location_info get_location($order_info["location_id"]);
    
$Licensor_en $location_info['contract_en'];
    
$Licensor_tc $location_info['contract_tc'];

    
$sql       "SELECT * FROM otherspage WHERE ospageid = 3";
    
$row       bind_pdo($sqlnull"selectone");
    
$wine_terms "";
    
$wine_terms_en "";
    if(
$order_info["location_id"] == 8){
        
$wine_terms '<div class="page_break"></div>' nl2br($row["wine_ospagedesc_tc"]);
        
$wine_terms_en '<div class="page_break"></div>' nl2br($row["wine_ospagedesc_en"]);
    }
    
$terms_txt '<div class="page_break"></div>' nl2br($row["ospagedesc_tc"]);
    
$terms_txt_en '<div class="page_break"></div>' nl2br($row["ospagedesc_en"]);

    if(
$order_info["customer_typeid"] == "PERSONAL"){
        
$idno "Identification Number 身份證明號碼 :" rsa_crypt($order_info["customer_identity_id"], 2);
        
$name "Name 姓名 :" $order_info["customer_name"];
    }else{
        
$idno "Business Registration No 商業登記證號碼 :" rsa_crypt($order_info["customer_identity_id"], 2);
        
$name "Company Name 公司名稱 :" $order_info["customer_companyname"];
    }

    
$paymethod get_master_type_code("PAYMENT_METHOD"$order_info["paymethod"]);
    if(empty(
$order_info["paymethod2"]))
        
$order_info["paymethod2"] = $order_info["paymethod"];

    
$paymethod2 get_master_type_code("PAYMENT_METHOD"$order_info["paymethod2"]);

    if(
$order_info["prepaid_month"] > 0){
        
$total_prepaid $order_info["prepaid_amount"]+$order_info["total_order_product"];

        
$total_paid $order_info["last_paid"]+$order_info["prepaid_amount"]+$order_info["total_order_product"];

        
//$total_remain = $order_info["total_discounted_price"]*$order_info["rent_month"]+$order_info["deposit"]+$order_info["total_order_product"]-$order_info["last_paid"]-$order_info["prepaid_amount"]-$order_info["free_first_month_deduct"]-$order_info["free_2_month_deduct"];
        //kelvin, 20200803
        
$total_remain $order_info["total_discounted_price"]*$order_info["rent_month"]+$order_info["deposit"]+$order_info["total_order_product"]-$order_info["last_paid"]-$total_prepaid-$order_info["free_first_month_deduct"]-$order_info["free_2_month_deduct"]-$order_info["discount_amount"];
    }else{
        
//prevent error
        
if($order_info["prepaid_month"] == 0){
            
$total_prepaid 0;

            
$total_paid $order_info["last_paid"];
            
$total_remain $order_info["total_discounted_price"]*$order_info["rent_month"]+$order_info["deposit"]+$order_info["total_order_product"]-$order_info["last_paid"]-$order_info["prepaid_amount"]-$order_info["free_first_month_deduct"]-$order_info["free_2_month_deduct"]-$order_info["discount_amount"];
        }
    }

    
//unit change
    
if($order_info["createdate"] > "2017-04-27 18:00:00"){
        
$unit "平方呎";
    }else{
        
$unit "立方呎";
    }

    if(
$order_info['renew'] == 1){
        
$rent_txt "租金以".$paymethod2["name_tc"]."支付";
        
$rent_txt2 "";
    }else{
        
$rent_txt $paymethod["name_tc"] == "未付" "按金未付" "按金以".$paymethod["name_tc"]."支付".($order_info["paymethod"] == "CREDIT_CARD"?" (並會扣除3%手續費)":"");
        
$rent_txt2 $paymethod2["name_tc"] == "未付" "租金未付" "租金以".$paymethod2["name_tc"]."支付";
    }

    
$contact "";
    if(
$order_info["customer_typeid"] == "BUSINESS"){
        
$contact "Contact Person 聯絡人 :" $order_info["customer_name"] . "<br>";
    }

    
$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: 11px;
        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;
    }
  </style>
</head>
<body>
    <header>
        <img src='http://" 
$_SERVER['SERVER_NAME'] . "/webadmin/pdf_template/header.png' width='100%' height='100%'/>
    </header>
    <p style='font-size: 15px; text-align: center; margin: 0;'>Unit Storage License Agreement<br>單位儲存許可協議書</p>
    <table>
        <tr>
            <td>License Agreement Number 許可協議書編號: " 
$order_info["code"] . "</td>
            <td style='text-align: right;'>Date 日期: " 
date("Y-m-d") . "</td>
        </tr>
    </table>
    <table style='table-layout:fixed;'>
        <tr>
            <td style='width: 20%;'>Licensor:<br>許可人:</td>
            <td style='width: 80%;'>
$Licensor_en<br>$Licensor_tc</td>
        </tr>
    </table>
    <br>
    <b><u>Licensee Information 被許可人資料</u></b>
    <p>
$idno<br>
    
$name<br>
    Address 地址: " 
rsa_crypt($order_info["customer_address"], 2) . "<br>
    
$contact
    Contact Phone 聯絡電話: " 
rsa_crypt($order_info["customer_tel"], 2) . "<br>
    E-Mail Address 電郵地址: " 
rsa_crypt($order_info["customer_email"], 2) . "<br>
    </p>
    <b><u>Agreed Terms By Licensor and Licensee</u></b>
    <p>Unit Number 單位號碼: 
$order_room_list<br>
    Customer I.D. 顧客編號: " 
$order_info['customer_code'] . "<br>
    Approximate Size 大約面積: " 
$order_info["roughly_size"].$unit "<br>
    Effective Date 生效日期: " 
$order_info["startdate"]." 至 ".$order_info["enddate"] . "<br>
    Smart Card No. 智能卡號碼: " 
$order_info["room_key"] . "<br>
    </p>
    <table>
    <tr>
        <td><b><u>Fees and Charges 費用及收費</u></b></td>
        <td style='text-align: right;'>港幣 : HKD$" 
numberformat($order_info["total_discounted_price"])." x ".$order_info["rent_month"] . "月</td>
    </tr>
    <tr>
        <td>Monthly License Fee 每月許可費:</td>
        <td style='text-align: right;'>(原價 : HKD$" 
numberformat($order_info["total_retail_price"]) . ")</td>
    </tr>
    <tr>
        <td>Effective Duration Fee 有效期價:</td>
        <td style='text-align: right;'>港幣 : HKD$" 
numberformat($order_info["total_discounted_price"]*$order_info["rent_month"]) . "</td>
    </tr>
    <tr>
        <td>Deposit 按金:</td>
        <td style='text-align: right;'>港幣 : HKD$" 
numberformat($order_info["deposit"]) . "</td>
    </tr>
    <tr>
        <td>Others 其他:</td>
        <td style='text-align: right;'>港幣 : HKD$" 
numberformat($order_info["total_order_product"]) . "</td>
    </tr>
    <tr>
        <td>Discount 租金優惠:</td>
        <td style='text-align: right;'>港幣 : -HKD$" 
numberformat($order_info["free_first_month_deduct"]+$order_info["free_2_month_deduct"]) . "</td>
    </tr>
    <tr>
        <td>Other Discount 其餘優惠:</td>
        <td style='text-align: right;'>港幣 : -HKD$" 
numberformat($order_info["discount_amount"]) . "</td>
    </tr>
    <tr>
        <td>Total 合計:</td>
        <td style='text-align: right;'>港幣 : HKD$" 
numberformat(($order_info["total_discounted_price"]*$order_info["rent_month"])+$order_info["deposit"]+$order_info["total_order_product"]-$order_info["free_first_month_deduct"]-$order_info["free_2_month_deduct"]-$order_info["discount_amount"]) . "</td>
    </tr>
    <tr>
        <td>Paid 已付費用: (預繳: HKD$" 
numberformat($total_prepaid) . ")</td>
        <td style='text-align: right;'>港幣 : -HKD$" 
numberformat($total_paid) . "</td>
    </tr>
    <tr>
        <td>Remaining Balance 餘款:</td>
        <td style='text-align: right;'>港幣 : HKD$" 
numberformat($total_remain) . "</td>
    </tr>
    </table>
    <br>
    <b><u>Remark 備註</b></u>
    <p>" 
$order_info["remark"] . "</p>
    <p>
$rent_txt<br>$rent_txt2</p>
    <p style='font-size: 10px;'>
    I have read and agreed all the terms and conditions in this License Agreement and that of the company annexed hereto which this agreement is subject to my signature below indicates acceptance thereof.<br>
    In case of any disputes, In N Out International Corporate Limited reserves the right of final decision.<br>
    本人已經閱讀並同意本許可協議及借用條款及細則。<br>
    本人在下欄的簽署表示本人接受該等條文及聲明。<br>
    如有任何爭議 , 出入易國際有限公司保留最終之決定權。
    </p>
    <table>
        <tr>
            <td>
                Licensee Signature 被許可人簽署<br>
                <div style='height: 60px; display: block;'></div>
                _________________________________<br>Date 日期 " 
date("Y-m-d") . "
            </td>                                                                                             
            <td>
                Licensor Signature 許可人簽署<br>
                <div style='height: 60px; display: block; position: relative;'>
                    <img src='http://" 
$_SERVER['SERVER_NAME'] . "/webadmin/pdf_template/chop.jpg' style='width: 60px; left: 16%; position: absolute; top: 5px;'>
                </div>
                _________________________________<br>Date 日期 " 
date("Y-m-d") . "
            </td>
        </tr>
    </table>
</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(str_replace(",""_"$order_room_list) . "_" date("d-m-Y"strtotime($order_info["startdate"])) . "_" date("d-m-Y"strtotime($order_info["enddate"])) . ".pdf");
}else{
    echo 
"<script>alert('找不到相關合約。');history.back();</script>";
}
exit;