/var/www/hkosl.com/innoutstorage2019/webadmin/duedate_alert.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
<?php
    
require_once('check_login.php');

    
$duedate_alert_info = array();
    
$i 0;

    
//$duedate_alert = 0;
    //$duedate_alert = -21;

    /*$date = new DateTime();
    $date->modify('-'.$duedate_alert.' day');*/

    
$sql "select * from deposit where balance != ? and status != ? and ? > duedate and deleted = ?";
    
$parameters = array(0"PAID"date("Y-m-d"), 0);
    
$deposit_info bind_pdo($sql$parameters"selectall");

    foreach(
$deposit_info as $deposit){
        
$order_info get_order($deposit["order_id"]);
        
$duedate_alert_info[$i]["order_id"] = $order_info["id"];
        
$customer_info get_customer($order_info["customer_id"]);
        
$duedate_alert_info[$i]["customer_id"] = $customer_info["id"];
        
$duedate_alert_info[$i]["customer_code"] = $customer_info["code"];
        
$duedate_alert_info[$i]["customer_name"] = $customer_info["customer_name"];

        
$type_info get_master_type_code("PAYMENT_TYPE""DEPOSIT");
        
$duedate_alert_info[$i]["type"] = $type_info["name_tc"];
        
$duedate_alert_info[$i]["type_code"] = "DEPOSIT";
        
$duedate_alert_info[$i]["code"] = $deposit["code"];
        
$duedate_alert_info[$i]["id"] = $deposit["id"];
        
$duedate_alert_info[$i]["amount"] = $deposit["amount"];
        
$duedate_alert_info[$i]["balance"] = $deposit["balance"];
        
$duedate_alert_info[$i]["duedate"] = $deposit["duedate"];

        
$start_date = new DateTime($deposit["duedate"]);
        
$since_start $start_date->diff(new DateTime(date("Y-m-d")));
        
$duedate_alert_info[$i]["overdue"] = $since_start->days;

        
$i++;
    }

    
$sql "select * from invoice where balance != ? and status != ? and ? > duedate and deleted = ?";
    
$parameters = array(0"SETTLED"date("Y-m-d"), 0);
    
$invoice_info bind_pdo($sql$parameters"selectall");

    foreach(
$invoice_info as $invoice){
        if(!empty(
$invoice["order_id"])){
            
$order_info get_order($invoice["order_id"]);
            
$duedate_alert_info[$i]["order_id"] = $order_info["id"];
            
$customer_info get_customer($order_info["customer_id"]);
            
$duedate_alert_info[$i]["customer_id"] = $customer_info["id"];
            
$duedate_alert_info[$i]["customer_code"] = $customer_info["code"];
            
$duedate_alert_info[$i]["customer_name"] = $customer_info["customer_name"];
        }else{

            
$duedate_alert_info[$i]["order_id"] = 0;
            
$customer_info get_customer($invoice["customer_id"]);
            
$duedate_alert_info[$i]["customer_id"] = $customer_info["id"];
            
$duedate_alert_info[$i]["customer_code"] = $customer_info["code"];
            
$duedate_alert_info[$i]["customer_name"] = $customer_info["customer_name"];

        }


        
$type_info get_master_type_code("PAYMENT_TYPE""INVOICE");
        
$duedate_alert_info[$i]["type"] = $type_info["name_tc"];
        
$duedate_alert_info[$i]["type_code"] = "INVOICE";
        
$duedate_alert_info[$i]["code"] = $invoice["code"];
        
$duedate_alert_info[$i]["id"] = $invoice["id"];
        
$duedate_alert_info[$i]["amount"] = $invoice["amount"];
        
$duedate_alert_info[$i]["balance"] = $invoice["balance"];
        
$duedate_alert_info[$i]["duedate"] = $invoice["duedate"];

        
$start_date = new DateTime($invoice["duedate"]);
        
$since_start $start_date->diff(new DateTime(date("Y-m-d")));
        
$duedate_alert_info[$i]["overdue"] = $since_start->days;
        
$i++;
    }
?>
<!DOCTYPE html>
<html>
<head>
    <?php require_once("html_head.php"); ?>

    <script type="text/javascript">
        function duedate_email(order_id, type_code, invoice_id){
            alert("電郵發送中,請稍候。");

            var xmlhttp;

            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }
            else {// code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    var result = $.trim(xmlhttp.responseText);

                    //console.log(result);
                    if(parseInt(result) == 1){
                        alert("電郵已成功送出。");
                    }else{
                        alert("電郵未能成功送出。");
                    }
                }
            }
            xmlhttp.open("POST", "_ajax.php?for=overdue_email", true);
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlhttp.send("order_id=" + (order_id) + "&type_code=" + type_code + "&invoice_id=" + invoice_id);
        }
    </script>
</head>

<body>
<table width="1000" 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="800" align="left" valign="top">
            <table width="800" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td>
                        <table width="800" 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">

                        <table width="1000" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td width="10" class="listtitletxt"></td>
                                <td width="130" class="listtitletxt">客戶姓名</td>
                                <td width="100" class="listtitletxt">客戶編號</td>
                                <td width="100" class="listtitletxt">發票類型</td>
                                <td width="130" class="listtitletxt">發票編號</td>
                                <td width="100" class="listtitletxt">金額</td>
                                <td width="100" class="listtitletxt">未付金額</td>
                                <td width="80" class="listtitletxt">繳費日期</td>
                                <td width="50" class="listtitletxt">已逾期</td>
                                <td width="80" class="listtitletxt"></td>
                            </tr>

                            <?php
                                
foreach($duedate_alert_info as $detail){
                                    print 
"<tr>";
                                    print 
"<td class='listtxt' style='padding-left:5'>&nbsp;</td>";
                                    print 
"<td class='listtxt' style='padding-left:5'>" $detail{'customer_name'} . "</td>";
                                    print 
"<td class='listtxt' style='padding-left:5'>" $detail{'customer_code'} . "</td>";
                                    print 
"<td class='listtxt' style='padding-left:5'>" $detail["type"] . "</td>";
                                    print 
"<td class='listtxt' style='padding-left:5'>" $detail["code"] . "</td>";
                                    print 
"<td class='listtxt' style='padding-left:5'>" numberformat($detail["amount"]) . "</td>";
                                    print 
"<td class='listtxt' style='padding-left:5'>" numberformat($detail["balance"]) . "</td>";
                                    print 
"<td class='listtxt' style='padding-left:5'>" $detail["duedate"] . "</td>";
                                    print 
"<td class='listtxt' style='padding-left:5'>" $detail["overdue"] . "日</td>";
                                    print 
"<td class='listtxt' style='padding-left:5'><button type='button' onclick='duedate_email(".$detail["order_id"].",\"".$detail["type_code"]. "\",".$detail["id"].")'>發送電郵</button> </td>";

                                    print 
"</tr>";

                                    print 
"</tr>";

                                }

                            
?>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
</body>
</html>