-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuntitled.html
More file actions
177 lines (149 loc) · 7.47 KB
/
untitled.html
File metadata and controls
177 lines (149 loc) · 7.47 KB
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
<?php
class Canceldrop
{
public function Process($access_token)
{
ini_set('memory_limit', '-1');
set_time_limit(0);
date_default_timezone_set('America/Los_Angeles');
global $wpdb;
$curl = curl_init();
$to_date=date('Y-m-d', strtotime($date. ' - 5 days'));
$current_time = date("H:i:s");
$from_time = "18:00:00";
$to_time = "08:00:00";
if ($this->TimeIsBetweenTwoTimes($current_time, $from_time, $to_time)):
echo 'Have a good night!';exit;
else:
curl_setopt_array($curl, array(
CURLOPT_URL => "https://oci1.a2000cloud.com/ords/cr/api/viewers/view/vr_order_hd",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"\r\n{ \"COLUMNS\": \"CTRL_NO, CUSTOMER, CUST_NAME, ORDER_NO, STORE, ORDER_DATE, START_DATE, CANCEL_DATE, EVENT_DATE, BOOK_DATE, CORP, DIV, BOOK_SEASON, DC_NO, CUST_DEPT, REGION, STATUS, ORDER_TRACK, ORDER_TRACK_DATE, OPEN_QTY, OPEN_EXTENSION, OPEN_VALUE, PICK_QTY, PICK_EXTENSION, PICK_VALUE, BOOK_QTY, BOOK_EXTENSION, BOOK_VALUE, SHIP_QTY, SHIP_EXTENSION, SHIP_VALUE, CANCEL_QTY, CANCEL_EXTENSION, CANCEL_VALUE, CANCEL_CODE, CANCELED_ON_DATE, REP_1, REP_2, REP_3, TERRITORY, TERMS, TERMS_DESCR, PREPAY_AMT, DISC, DISC_RATE, FACTOR, FACTOR_CUSTOMER, CREDIT, APPR_NO, FACTOR_EDI, FACTOR_EDI_QUEUED, FACTOR_EDI_SENT, FACTOR_EDI_REQ_NO, CURRENCY, EXCHANGE_RATE, SHIP_VIA, FOB_POINT, PRIORITY, REORDER, DEF_WH, REF_ART_ID, ST_NAME, ST_ADDR_1, ST_ADDR_2, ST_CITY, ST_STATE, ST_POSTAL, ST_COUNTRY, DROP_SHIP, SHIP_TO_REP, PROMO_CODE, PRICE_LIST_ID, ORDER_REF1, ORDER_REF2, ORDER_REF3, ORDER_REF4, ORDER_REF5, ORDER_CONTROLLER, ORDER_APPR_STATUS, ORDER_TYPE, ORDER_ALIAS, PROJECT_ID, ORDER_HOLD, ORDER_MODE, SHIP_TYPE, FILL_RULE, FIRST_COST_RULE, REGISTER, ENTRY_DATE, ENTERED_BY, MODIFY_DATE, MODIFIED_BY, EDI_ORDER, EDI_MARKFOR, CONTRACT_ORDER_NO, SUMMARY_ORDER_NO, ORDER_EVENT_REF, EDI_MERCHANT, CUST_TYPE, CUST_REF1, CUST_REF2, MASTER_CUST, ST_REF1, ST_REF2, SHIPPING, SURCHARGE, SERVICES, SALES_TAX1, SALES_TAX2, SALES_TAXL, TAX_AUTH, TAX_EXEMPT, FIXED_DISC, DISCOUNT, ORDER_TOTAL, ORDER_TRACK_DUE, ORDER_TRACK_LATE, ORDER_TRACK_CONTROL, ORDER_TRACK_REF, ACK_PRINTED, PO_ACK_PRINTED, EDI_RVPO, EDI_RVPO_QUEUED, EDI_RVPO_SENT\", \"FILTER\": \"CANCEL_CODE = 'DROP' AND CANCEL_ON_DATE >=to_date('".$to_date." 00:00:00' ,'YYYY-MM-DD HH24:MI:SS')\", \"SORT\": \"CANCEL_ON_DATE DESC\" }\r\n\r\n",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Authorization: Bearer ".$access_token
),
));
$response = curl_exec($curl);
curl_close($curl);
$parsed_data=$this->ParseJsonDecode($response);
$trans_list=$parsed_data->VR_ORDER_HD;
foreach($trans_list as $ts):
$metaparam=$this->ChkSms($ts->CTRL_NO);
if($metaparam==""):
$this->SendCanceldropProcessing($ts);
//break;
endif;
endforeach;
endif;
exit;
}
public function TimeIsBetweenTwoTimes($from, $till, $input)
{
$f = DateTime::createFromFormat('H:i
:s
', $from);
$t = DateTime::createFromFormat('H:i
:s
', $till);
$i = DateTime::createFromFormat('H:i
:s
', $input);
if ($f > $t) $t->modify('+1 day');
return ($f <= $i && $i <= $t) || ($f <= $i->modify('+1 day') && $i <= $t);
}
public function ParseJsonDecode($contents)
{
$contents=str_replace("Content-type: application/json
Status: 200 Success","",$contents);
$contents=str_replace("\u","",$contents);
$contents=str_replace("\r","",$contents);
$contents=str_replace("\n","",$contents);
$contents=str_replace("\/","",$contents);
$contents = preg_replace('/( +):/i', '"\1":', $contents);
$parsed_data=json_decode($contents);
return $parsed_data;
}
public function ProcessJsonDecode($contents)
{
$contents=str_replace("Content-type: application/json
Status: 200 Success","",$contents);
$contents=str_replace("\u","",$contents);
$contents=str_replace("\r","",$contents);
$contents=str_replace("\n","",$contents);
$contents=str_replace("\/","",$contents);
$contents = preg_replace('/( +):/i', '"\1":', $contents);
$parsed_data=json_decode($contents);
return $parsed_data;
}
public function SendCanceldropProcessing($info)
{
global $wpdb;
$site_name = get_bloginfo( 'name' );
//$order_id=$this->get_post_id_by_meta_key_and_value('ctrl_no', $info->CTRL_NO);
// // Your order for STYLE DESCR XXX has been cancelled due to this style not being produced.
$msgtocustomer =$site_name." cancelled your order due to this style ".$info->STYLE." not being produced.";
$msgtoadmin="Cancelled order for ".$info->CTRL_NO.". The style ".$info->STYLE." is not being produced. SMS notification sent to customer successfully.";
// $order_phone = $woocommerce->customer->billing['billing_phone'];
$order_phone=$info->MOBILE_CONTACT;
$admin_phone=get_option('admin_phone_number');
//$order_phone="+15015807383";
//$order_phone="+918489313939";
//$admin_phone="+919626345457";
$sid = get_option('msg_api_key');
$token = get_option('msg_token');
send_twilio_text_msg(
$sid,
$token,
get_option('sender_phone_no'),
$order_phone,
$msgtocustomer
);
send_twilio_text_msg(
$sid,
$token,
get_option('sender_phone_no'),
$admin_phone,
$msgtoadmin
);
$ins_query="insert into `wp_a2000_sms`(`ctrl_no`,`meta_value`,`last_updated`)values('".$info->CTRL_NO."','".json_encode($info)."','".date('Y-m-d H:i:s')."')";
$wpdb->query($ins_query);
//print"<pre>";print_r($info);print"</pre>";
}
public function ChkSms($ctrl_no)
{
global $wpdb;
$meta = $wpdb->get_results("SELECT ctrl_no FROM `wp_a2000_sms` WHERE ctrl_no='".$wpdb->escape($ctrl_no)."'");
if (is_array($meta) && !empty($meta) && isset($meta[0])) {
$meta = $meta[0];
}
if (is_object($meta)) {
return $meta->ctrl_no;
}
else {
return false;
}
}
public function get_post_id_by_meta_key_and_value($key, $value)
{
global $wpdb;
$meta = $wpdb->get_results("SELECT post_id FROM `".$wpdb->postmeta."` WHERE meta_key='".$wpdb->escape($key)."' AND meta_value='".$wpdb->escape($value)."'");
if (is_array($meta) && !empty($meta) && isset($meta[0])) {
$meta = $meta[0];
}
if (is_object($meta)) {
return $meta->post_id;
}
else {
return false;
}
}
}
?>