/var/www/hkosl.com/innoutstorage/webadmin/backup/order_index210616.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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
<?php
require_once("check_login.php");
require_once(
"Zebra_Pagination/Zebra_Pagination.php");

$_SESSION["index_url_parameter"] = get_index_url_parameter();

if (!isset(
$_GET["filter1"]) && !isset($_GET["filter2"]) && !isset($_GET["filter3"]) && !isset($_GET["all"])) {
    
$order_info = array();
    
$filter_sql " and createdate >= DATE_SUB(CURRENT_DATE(), INTERVAL 2 WEEK) AND createdate <= '".date('Y-m-d 23:59:59')."'";
    
$parameters NULL;
} else {

    
//check date time
    
if ($_GET["filter1"] == || $_GET["filter1"] == 5) {
        
$message "";
        if (empty(
$_GET["filter2"])) {
            
$message .= "請選擇開始日期。\\n\\n";
        } else {
            if (!
validateDate($_GET["filter2"], "Y-m-d")) {
                
$message .= "開始日期格式出錯。\\n\\n";
            }
        }

        if (empty(
$_GET["filter3"])) {
            
$message .= "請選擇完結日期。\\n\\n";
        } else {
            if (!
validateDate($_GET["filter3"], "Y-m-d")) {
                
$message .= "完結日期格式出錯。\\n\\n";
            }
        }

        if (!empty(
$_GET["filter2"]) && !empty($_GET["filter3"]) && validateDate($_GET["filter2"], "Y-m-d") && validateDate($_GET["filter3"], "Y-m-d") && $_GET["filter3"] <= $_GET["filter2"]) {
            
$message .= "開始日期必須早於完結日期。\\n\\n";
        }

        if (!empty(
$message)) {
            echo 
"<script>alert('" $message "'); location.href='order_index.php'</script>";
            exit;
        }

        
$filter_sql "and startdate >= ? and startdate <= ?";
        
$parameters = array($_GET["filter2"], $_GET["filter3"]);
    }


    
$filter_sql "";

    if (isset(
$_GET["all"]) && (int)$_GET["all"] == 1) {
        
$filter_sql "";
        
$parameters NULL;
    } else {
        if (isset(
$_GET["filter1"]) && isset($_GET["filter2"])) {
            if (
$_GET["filter1"] == 0) {
                
$filter_sql "and id = ?";
            }

            if (
$_GET["filter1"] == || $_GET["filter1"] == 2) {
                
$filter_sql "and customer_id = ?";
            }

            if (
$_GET["filter1"] == 4) {
                
$filter_sql "and status = ?";
            }

            
$parameters = array($_GET["filter2"]);

            if (
$_GET["filter1"] == 3) {
                
$filter_sql "and startdate >= ? and startdate <= ?";
                
$parameters = array($_GET["filter2"], $_GET["filter3"]);
            }

            if (
$_GET["filter1"] == 5) {
                
$filter_sql "and createdate >= ? and createdate <= ?";
                
$parameters = array($_GET["filter2"], $_GET["filter3"]);
            }

        }
    }
}

//pagination
// how many records should be displayed on a page?
$records_per_page 20// temp hide
// instantiate the pagination object
$pagination = new Zebra_Pagination();

// records per page
$pagination->records_per_page($records_per_page);

$sql "select count(*) as count from `order` where deleted = 0 " $filter_sql " order by id DESC";
$order_info bind_pdo($sql$parameters"selectone");

// the number of total records is the number of records in the array
$pagination->records($order_info['count']);

$sql "select * from `order` where deleted = 0 " $filter_sql " order by id DESC";
$sql .= ' LIMIT ' . (($pagination->get_page() - 1) * $records_per_page) . ', ' $records_per_page ;
$order_info bind_pdo($sql$parameters"selectall");

foreach (
$order_info as $key => $order) {
    
$order_id $order["id"];
    
$order_info[$key]["order_code"] = $order["code"];
    
/*$customer_info                     = get_customer($order["customer_id"]);
    $order_info[$key]["customer_code"] = $customer_info["code"];
    $order_info[$key]["customer_name"] = $customer_info["customer_name"];*/

    
$customer_name get_customer_name(rsa_crypt($order["customer_firstname"], 2), rsa_crypt($order["customer_lastname"], 2));
    
$order_info[$key]["customer_code"] = $order["customer_code"];
    
$order_info[$key]["customer_name"] = $customer_name;
    
$order_info[$key]["customer_tel"] = rsa_crypt($order_info[$key]["customer_tel"], 2);

}

$filter_order_code "";
$filter_customer_code "";
$filter_customer_name "";
$filter_status "";
$filter_startfrom "";

$all_order_info get_order2();
foreach (
$all_order_info as $key => $order) {
    
$filter_order_code[$key][0] = $order["id"];
    
$filter_order_code[$key][1] = $order["code"];
}

$all_order_info get_customer2();

foreach (
$all_order_info as $key => $customer) {
    
$filter_customer_code[$key][0] = $customer["id"];
    
$filter_customer_code[$key][1] = $customer["code"];

    
$filter_customer_name[$key][0] = $customer["id"];
    
$filter_customer_name[$key][1] = $customer["customer_name"];
}

$status_info get_master_type_code("ORDER_STATUS");
foreach (
$status_info as $key => $status) {
    
$filter_status[$key][0] = $status["code"];
    
$filter_status[$key][1] = $status["name_tc"];
}

$filter1_info = array("合約編號""客戶編號""客戶姓名""生效日期""狀態""建立日期");
$filter2_info = array(=> $filter_order_code=> $filter_customer_code=> $filter_customer_name=> "user_input"=> $filter_status=> "user_input");

?>
<!DOCTYPE html>
<html>
<head>
    <?php require_once("html_head.php"); ?>
    <link rel="stylesheet" href="Zebra_Pagination/css/zebra_pagination.css" type="text/css">

    <script src="Zebra_Pagination/js/zebra_pagination.js"></script>

    <script type="text/javascript">
        $(function () {
            $("#filter2_35, #filter3_35").datepicker({
                dateFormat: 'yy-mm-dd'
            });
        });
    </script>

    <script type="text/javascript">

        function switch_order(order_id) {

            if (!isNaN(order_id)) {
                var r = confirm("你確定要為這張合約進入轉倉程序?");
                if (r == true) {
                    window.location.href = '_ajax.php?for=switch_order&order_id=' + order_id;
                }
            }
        }

        function terminate_order(order_id) {

            if (!isNaN(order_id)) {
                var r = confirm("你確定要為這張合約進入退倉程序?");
                if (r == true) {
                    window.location.href = 'terminate_order.php?order_id=' + order_id;
                }
            }
        }

        function filter() {
            var filter1 = $("select[name='filter1']").val();
            if (filter1 == 3 || filter1 == 5) {
                var filter2 = $("#filter2_35").val();
                var filter3 = $("#filter3_35").val();
            } else {
                var filter2 = $("#filter2_" + filter1).val();
            }

            if (filter1 != "" && filter2 != "" && filter3 != "") {
                top.location.href = 'order_index.php?filter1=' + filter1 + '&filter2=' + filter2 + '&filter3=' + filter3;
            } else if (filter1 != "" && filter2 != "") {
                top.location.href = 'order_index.php?filter1=' + filter1 + '&filter2=' + filter2;
            } else {
                if (filter1 == "3" || filter1 == "5") {
                    alert("請選擇篩選方式,開始日期及完結日期。");
                } else {
                    alert("請選擇篩選方式。");
                }
            }
        }


        $(function () {
            $("#filter1").chosen({width: "100px", search_contains: true});
            $("#filter2_0").chosen({width: "250px", search_contains: true});
            $("#filter2_1").chosen({width: "250px", search_contains: true});
            $("#filter2_2").chosen({width: "250px", search_contains: true});
            //$("#filter2_3").chosen({width: "250px", search_contains: true});
            $("#filter2_4").chosen({width: "250px", search_contains: true});

            $("#filter2_0_chosen").css("display", "none");
            $("#filter2_1_chosen").css("display", "none");
            $("#filter2_2_chosen").css("display", "none");
            $("#filter2_35").css("display", "none");
            $("#filter3_35").css("display", "none");
            $("#filter2_4_chosen").css("display", "none");

            <?php
            
if (isset($_GET["filter1"])) {
                if (
$_GET["filter1"] == || $_GET["filter1"] == 5) {
                    echo 
'$("#filter2_35").css("display", "inline-block");';
                    echo 
'$("#filter3_35").css("display", "inline-block");';
                } else {
                    echo 
'$("#filter2_"+' $_GET["filter1"] . '+"_chosen").css("display", "inline-block");';
                }
            }
            
?>

            $("#filter1").change(function () {
                var filter_1_key = $(this).val();
                $(".filter2").css("display", "none");
                $("#filter2_0_chosen").css("display", "none");
                $("#filter2_1_chosen").css("display", "none");
                $("#filter2_2_chosen").css("display", "none");
                $("#filter2_35").css("display", "none");
                $("#filter3_35").css("display", "none");
                $("#filter2_4_chosen").css("display", "none");

                if (parseInt(filter_1_key) == 3 || parseInt(filter_1_key) == 5) {
                    $("#filter2_35").css("display", "inline-block");
                    $("#filter3_35").css("display", "inline-block");
                } else {
                    $("#filter2_" + filter_1_key + "_chosen").css("display", "inline-block");
                }
            });

        });

    </script>

    <style>
    #myTable_filter {
        display: none;
    }

    .myFilter {
        display: flex;
        align-items: center;
    }

    .myFilter > div {
        margin-right: 20px;
    }

    .myFilter input[type="text"], .myFilter select {
        width: 100%;
    }

    .myFilter input[type="date"] {
        width: 42%;
    }

    .listtitletxt {
        padding: 0px 0px 0px 5px !important;
        border: 0;
    }

    .dataTables_wrapper .dataTables_paginate {
        float: inherit;
        text-align: center;
    }

    .dataTables_length {
        display: none;
    }
    
    .dataTable td {
        font-size: 13px;
    }
    </style>
</head>

<body>
<table width="1200" height="600" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td width="200" align="left" valign="top">
            <table width="200" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td height="70" align="left" valign="middle">&nbsp;</td>
                </tr>
                <tr>
                    <td width="200" align="left" valign="top"><!-- Main Menu -->
                        <?php require("menu.php"); ?><!-- End Main Menu --></td>
                </tr>
            </table>
        </td>
        <td width="1000" align="left" valign="top">
            <table width="1000" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td>
                        <table width="1000" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td height="70" class="pagetitletxt">&nbsp;&nbsp;</td>
                                <td width="50" align="center" class="icontxt">

                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td class="pagetitletxt">
                        &nbsp;&nbsp;<b><img src="images/iconList.jpg" width="48" height="48" align="absmiddle"/>

                            合約

                        </b></td>
                </tr>
                <tr>
                    <td height="25" align="left" valign="middle" class="msg"><?php if (isset($_GET["msg"])) echo $_GET['msg']; ?></td>
                </tr>

                <tr>
                    <td align="left" valign="middle">

                        <!--
                        <div>篩選: <select name="filter1" id="filter1">
                                <option value="">---請選擇---</option>
                                <?php
                                
foreach ($filter1_info as $key => $filter1) {
                                    if (isset(
$_GET["filter1"]))
                                        
$selected matched_option($key$_GET["filter1"], "select");

                                    echo 
'<option value="' $key '" ' $selected '>' $filter1 '</option>';
                                }
                                
?>
                            </select>

                            <select name="filter2" id="filter2_0" class="filter2 ">
                                <option value="">---請選擇---</option>
                                <?php

                                
foreach ($filter2_info[0] as $data) {
                                    if (isset(
$_GET["filter2"]))
                                        
$selected matched_option($data[0], $_GET["filter2"], "select");

                                    echo 
'<option value="' $data[0] . '" ' $selected ' class="' $key '">' $data[1] . '</option>';
                                }

                                
?>
                            </select>

                            <select name="filter2" id="filter2_1" class="filter2 ">
                                <option value="">---請選擇---</option>
                                <?php
                                
foreach ($filter2_info[1] as $data) {
                                    if (isset(
$_GET["filter2"]))
                                        
$selected matched_option($data[0], $_GET["filter2"], "select");

                                    echo 
'<option value="' $data[0] . '" ' $selected ' class="' $key '">' $data[1] . '</option>';
                                }


                                
?>
                            </select>

                            <select name="filter2" id="filter2_2" class="filter2 ">
                                <option value="">---請選擇---</option>
                                <?php

                                
foreach ($filter2_info[2] as $data) {
                                    if (isset(
$_GET["filter2"]))
                                        
$selected matched_option($data[0], $_GET["filter2"], "select");

                                    echo 
'<option value="' $data[0] . '" ' $selected ' class="' $key '">' $data[1] . '</option>';
                                }

                                
?>
                            </select>

                            <input type="text" name="filter2"
                                   value="<?php if (isset($_GET["filter2"]) && isset($_GET["filter1"]) && ($_GET["filter1"] == || $_GET["filter1"] == 5)) echo $_GET["filter2"]; else echo ""?>"
                                   id="filter2_35" class="filter2" style="width: 100px;" placeholder="開始日期"/>

                            <input type="text" name="filter3"
                                   value="<?php if (isset($_GET["filter3"]) && isset($_GET["filter1"]) && ($_GET["filter1"] == || $_GET["filter1"] == 5)) echo $_GET["filter3"]; else echo ""?>"
                                   id="filter3_35" class="filter3" style="width: 100px;" placeholder="完結日期"/>

                            <select name="filter2" id="filter2_4" class="filter2 ">
                                <option value="">---請選擇---</option>
                                <?php
                                
foreach ($filter2_info[4] as $data) {
                                    if (isset(
$_GET["filter2"]))
                                        
$selected matched_option($data[0], $_GET["filter2"], "select");

                                    echo 
'<option value="' $data[0] . '" ' $selected ' class="' $key '">' $data[1] . '</option>';
                                }
                                
?>
                            </select>

                            <button type="button" onclick="filter();">送出</button>

                            <button type="button" onclick="window.location.href='order_index.php?all=1';" style="margin-left: 15px;">
                                全部合約
                            </button>
                        </div>
                        -->

                        <?php
                        $name_list 
= array();
                        
$status_list = array();

                        foreach (
$order_info as $order) {
                            
$name_list[] = $order['customer_name'];
                            
$order_status get_master_type_code("ORDER_STATUS"$order["status"]);
                            
$status_list[] = $order_status["name_tc"];
                        }

                        
$name_list array_unique($name_list);
                        
$status_list array_unique($status_list);
                        
?>

                        <div class="myFilter">
                            <div style="width: 10%;">合約編號<br><input type="text" data-col="1"></div>
                            <div style="width: 10%;">門卡號碼<br><input type="text" data-col="2"></div>
                            <div style="width: 10%;">
                                客戶姓名<br>
                                <select data-col="3">
                                    <option value=""></option>
                                    <?php foreach ($name_list as $nl) { ?>
                                        <option value="<?= $nl?>"><?= $nl?></option>
                                    <?php ?>
                                </select>
                            </div>
                            <div style="width: 10%;">聯絡電話<br><input type="text" data-col="4"></div>
                            <div style="width: 10%;">租用單位<br><input type="text" data-col="5"></div>
                            <div style="width: 30%;">有效日期<br><input type="date" id="filter_from"> 至 <input type="date" id="filter_to"></div>
                            <div style="width: 10%;">
                                狀態<br>
                                <select data-col="9">
                                    <option value=""></option>
                                    <?php foreach ($status_list as $sl) { ?>
                                        <option value="<?= $sl?>"><?= $sl?></option>
                                    <?php ?>
                                </select>
                            </div>
                            <div style="width: 10%;">
                                <button class="reset">重設</button>
                            </div>
                        </div>

                        <br>

                        <table width="1150" border="0" cellpadding="0" cellspacing="0" id="myTable">
                            <thead>
                            <tr>
                                <td width="10" class="listtitletxt"></td>
                                <td width="100" class="listtitletxt">合約編號</td>
                                <td width="100" class="listtitletxt">門卡號碼</td>
                                <!--<td width="150" class="listtitletxt">客戶類別</td>-->
                                <td width="150" class="listtitletxt">客戶姓名</td>
                                <td width="80" class="listtitletxt">聯絡電話</td>
                                <td width="200" class="listtitletxt">租用單位</td>
                                <td width="70" class="listtitletxt" style="white-space: nowrap">租用期(月)</td>
                                <td width="80" class="listtitletxt">生效日期</td>
                                <td width="80" class="listtitletxt">結束日期</td>
                                <td width="50" class="listtitletxt">狀態</td>
                                <td width="50" class="listtitletxt">轉倉</td>
                                <td width="50" class="listtitletxt">退倉</td>
                                <td width="50" class="listtitletxt">詳情</td>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            
foreach ($order_info as $order) {
                                echo 
"<tr>";
                                echo 
"<td class='listtxt' style='padding-left:5'>&nbsp;</td>";
                                echo 
"<td class='listtxt' style='padding-left:5; white-space: nowrap'>" $order['order_code'] . "</td>";

                                echo 
"<td class='listtxt' style='padding-left:5'>" $order['room_key'] . "</td>";

                                
/*$customer_type = get_master_type_code("CUSTOMER_TYPE", $order["customer_typeid"]);
                                if($order["customer_typeid"] == "BUSINESS"){
                                    echo "<td class='listtxt' style='padding-left:5'>" . $customer_type["name_tc"] . "<br>".$order["customer_companyname"]."</td>";
                                }else if($order["customer_typeid"] == "PERSONAL"){
                                    echo "<td class='listtxt' style='padding-left:5'>" . $customer_type["name_tc"] . "</td>";
                                }*/

                                
echo "<td class='listtxt' style='padding-left:5'>" $order['customer_name'] . "<br>(" $order['customer_code'] . ")</td>";
                                echo 
"<td class='listtxt' style='padding-left:5'>" $order['customer_tel'] . "</td>";

                                
$order_room_info get_order_room($order["id"]);
                                
$order_room_list "";
                                foreach (
$order_room_info as $detail) {
                                    
$room_info get_room($detail["room_id"]);
                                    
$order_room_list .= check_combine_room($room_info["code"]) . ", ";
                                }

                                
$order_room_list substr_replace($order_room_list"", -2);

                                echo 
"<td class='listtxt' style='padding-left:5'>" $order_room_list "</td>";

                                echo 
"<td class='listtxt' style='padding-left:5'>" $order['rent_month'] . "</td>";
                                echo 
"<td class='listtxt' style='padding-left:5'>" $order['startdate'] . "</td>";
                                echo 
"<td class='listtxt' style='padding-left:5'>" $order['enddate'] . "</td>";

                                
$order_status get_master_type_code("ORDER_STATUS"$order["status"]);

                                echo 
"<td class='listtxt' style='padding-left:5'>" $order_status["name_tc"] . "</td>";

                                if (
$order["status"] == "NEW") {
                                    echo 
"<td class='listtxt' style='padding-left:5'><button type='button' onclick='switch_order(" $order["id"] . ");'>轉倉</button></td>";
                                } else {
                                    echo 
"<td class='listtxt' style='padding-left:5'>不適用</td>";
                                }

                                if (
$order["status"] == "NEW") {
                                    echo 
"<td class='listtxt' style='padding-left:5'><button type='button' onclick='terminate_order(" $order["id"] . ");'>退倉</button></td>";
                                } else {
                                    echo 
"<td class='listtxt' style='padding-left:5'>不適用</td>";
                                }


                                
// Modify
                                
echo "<td class='listtxt' align='center'><a href='#' onClick=\"window.location='order_modifyform.php?order_id=" $order['id'] . "'\"><img src='images/btnModify.png' title='Modify' alt='Modify' hspace='2' border='0'></a></td>";

                                echo 
"</tr>";

                            }
                            
?>
                            </tbody>
                        </table>

                        <br>

                        <?php
                        
// render the pagination links
                        
$pagination->render();
                        
?>
                        
                        <br>
                        
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<script>
$(window).ready( function () {
    /*
    var table = $('#myTable').DataTable({
        // paging: false,
        // searching: false,
        orderClasses: false,
        pageLength: 20,
        ordering: false,
        info: false,
        language: {
            url: "//cdn.datatables.net/plug-ins/1.10.24/i18n/Chinese-traditional.json"
        }
    });

    $.fn.dataTable.ext.search.push(
        function (settings, data, dataIndex) {
            var min = $('#filter_from').val() == "" ? null : new Date($('#filter_from').val());
            var max = $('#filter_to').val() ==  "" ? null : new Date($('#filter_to').val());
            var startDate = new Date(data[7].trim());
            var endDate = new Date(data[8].trim());
            if (min == null && max == null) { return true; }
            if (min == null && max >= endDate) { return true; }
            if (max == null && startDate >= min) { return true; }
            if (startDate >= min && max >= endDate) { return true; }
            return false;
        }
    );

    $('#filter_from, #filter_to').on('change', function() {
        table.draw();
    });

    $('.myFilter input[type="text"], .myFilter select').on('change', function() {
        table.columns($(this).data('col'))
        .search($(this).val())
        .draw();
    });
    */

    $('.reset').on('click', function() {
        var parent = $(this).parent().parent();
        parent.find('input').val('');
        parent.find('select').val('').trigger("chosen:updated")
        table.columns().search('').draw();
    });

    $(".myFilter select").chosen({search_contains: true});
});
</script>
</body>
</html>