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
|
<?php require_once('check_login.php');
//checking data $message = "";
$_SESSION["roughly_size"] = $_POST["roughly_size"]; $_SESSION["total_discounted_price"] = $_POST["total_discounted_price"]; $_SESSION["deposit"] = $_POST["deposit"]; $_SESSION["total_retail_price"] = $_POST["total_retail_price"];
if (empty($_POST["room_id"])) { $message .= "請選擇要租用的倉庫。\\n\\n"; }
if (empty($_POST["roughly_size"])) { $message .= "請輸入大約面積。\\n\\n"; }
if (empty($_POST["total_discounted_price"])) { $message .= "請輸入每月租金。\\n\\n"; } else { if (!is_numeric($_POST["total_discounted_price"]) || $_POST["total_discounted_price"] < 0) { $message .= "每月租金應是正數數字。\\n\\n"; } }
if (!isset($_POST["deposit"])) { $message .= "請輸入按金。\\n\\n"; } else { if (!is_numeric($_POST["deposit"]) || $_POST["deposit"] < 0) { $message .= "按金應是正數數字。\\n\\n"; } }
if (empty($_POST["rent_month"])) { $message .= "請選擇租用期月份。\\n\\n"; } else { if (!is_numeric($_POST["rent_month"])) { $message .= "租用期月份應是數字。\\n\\n"; } }
/*if (!isset($_POST["prepaid_month"])) { $message .= "請選擇預繳月份。\\n\\n"; } else { if (!is_numeric($_POST["prepaid_month"])) { $message .= "預繳月份應是數字。\\n\\n"; } }*/
if ( (!isset($_POST["prepaid_month"]) || $_POST["prepaid_month"] == 0) && isset($_POST["free_first_month"]) && $_POST["free_first_month"] == 1) { $message .= "免首月月費須要客戶選擇預繳。\\n\\n"; }
if(isset($_POST["free_first_month"]) && $_POST["free_first_month"] == 1 && isset($_POST["prepaid_month"]) && $_POST["prepaid_month"] > 0){ if($_POST["biggest_retail_price"] <= 0 || $_POST["biggest_discounted_price"] <= 0){ $message .= "免首月月費計算有問題,請重新整理頁面並再嘗試。\\n\\n"; } } if (!isset($_POST["discount_amount"])) { $message .= "請輸入優惠金額。\\n\\n"; } else if (!is_numeric($_POST["discount_amount"]) || $_POST["discount_amount"] < 0 ) { $message .= "優惠金額應是正數數字。\\n\\n"; }
if (!isset($_POST["last_paid"])) { $message .= "請輸入已付款項。\\n\\n"; } else { if (!is_numeric($_POST["last_paid"]) || $_POST["last_paid"] < 0 ) { $message .= "已付款項應是正數數字。\\n\\n"; }else{ if( ($_POST["last_paid"] - $_POST["deposit"]) > ($_POST["rent_month"]*$_POST["total_discounted_price"])){ $message .= "已付款項不應大於總租金金額和按金的總和,請適當增加租用月份。\\n\\n"; } } }
if (empty($_POST["warehousing_date"])) { $message .= "請輸入入倉日期。\\n\\n"; } else { if (!validateDate($_POST["warehousing_date"], "Y-m-d")) { $message .= "請輸入正確的入倉日期。\\n\\n"; } }
if (empty($_POST["rent_from"])) { $message .= "請輸入生效日期。\\n\\n"; } else { if (!validateDate($_POST["rent_from"], "Y-m-d")) { $message .= "租約期生效日期出錯。\\n\\n"; } }
if (empty($_POST["rent_to"])) { $message .= "請輸入租約期完結日期。\\n\\n"; } else { if (!validateDate($_POST["rent_to"], "Y-m-d")) { $message .= "租約期完結日期出錯。\\n\\n"; } }
//check delivery service content if ($_POST["delivery_service"] == 1) { if (empty($_POST["delivery_date"])) { $message .= "請輸入服務日期。\\n\\n"; } else { if (!validateDate($_POST["delivery_date"], "Y-m-d")) { $message .= "服務日期出錯。\\n\\n"; } }
if (empty($_POST["delivery_from"])) { $message .= "請輸入起點。\\n\\n"; }
if (empty($_POST["delivery_to"])) { $message .= "請輸入終點。\\n\\n"; } }
//按金付款方式 if (empty($_POST["paymethod"])) { $message .= "請選擇按金付款方式。\\n\\n"; }else{ if($_POST["paymethod"] == "CHEQUE"){ /*if(empty($_POST["bank_name"])){ $message .= "請輸入 按金付款方式 銀行名稱 。\\n\\n"; }
if(empty($_POST["cheque_num"])){ $message .= "請輸入 按金付款方式 支票號碼 。\\n\\n"; }*/ }
if($_POST["paymethod"] == "BANKIN"){ /*if(empty($_POST["paymethod_other2"])){ $message .= "請輸入付款方式-銀行入數 。\\n\\n"; }*/ }
if($_POST["paymethod"] == "OTHER"){ if(empty($_POST["paymethod_other"])){ $message .= "請輸入 按金付款方式 付款方式-其他 。\\n\\n"; } } }
//租金付款方式 if (empty($_POST["paymethod2"])) { $message .= "請選擇租金付款方式。\\n\\n"; }else{ if($_POST["paymethod2"] == "CHEQUE"){ /*if(empty($_POST["bank_name"])){ $message .= "請輸入 租金付款方式 銀行名稱 。\\n\\n"; }
if(empty($_POST["cheque_num"])){ $message .= "請輸入 租金付款方式 支票號碼 。\\n\\n"; }*/ }
if($_POST["paymethod2"] == "BANKIN"){ /*if(empty($_POST["paymethod2_other2"])){ $message .= "請輸入付款方式-銀行入數 。\\n\\n"; }*/ }
if($_POST["paymethod2"] == "OTHER"){ if(empty($_POST["paymethod_other2"])){ $message .= "請輸入 租金付款方式 付款方式-其他 。\\n\\n"; } } }
if (!isset($_POST["order_total"])) { $message .= "合約總計出錯。\\n\\n"; }
if (!isset($_POST["final_order_total"])) { $message .= "合約總計(折扣後)出錯。\\n\\n"; }
foreach($_POST["qty"] as $key => $qty){ if(!is_numeric($qty) || $qty < 0){ $message .= "數量應是正數數字。\\n\\n"; break; } }
$discount_info = array();
$total_deduct = 0;
$order_room = array(); $i = 0; $location_id = 0; if(!empty($_POST["room_id"])){ foreach($_POST["room_id"] as $key => $room){ $order_room[$i]["room_id"] = $_POST["room_id"][$key]; $order_room[$i]["room_code"] = $_POST["room_code"][$key]; $order_room[$i]["retail_price"] = $_POST["retail_price"][$key];
//$_SESSION["warehousing"][2]["order_discount"] //not stable with post discounted price, change to using order discount and do calculation if(!empty($_SESSION["warehousing"][2]["order_discount"])){ foreach($_SESSION["warehousing"][2]["order_discount"] as $order_discount){ if($order_discount["room_id"] == $_POST["room_id"][$key]){ $order_room[$i]["discounted_price"] = round($_POST["retail_price"][$key] - $order_discount["monthly_deduct"], 1); } } }else{ $order_room[$i]["discounted_price"] = $_POST["discounted_price"][$key]; }
//$order_room[$i]["discounted_price"] = $_POST["discounted_price"][$key];
$order_room[$i]["location_id"] = $_POST["location_id"][$key]; //check if different location exits if($i == 0){ $location_id = $_POST["location_id"][$key]; } else{ if($location_id != $_POST["location_id"][$key]){ $message .= "你不可以選取不同地點的倉庫。\\n\\n"; break; } }
$i++; } }else{ $message .= "請選取要租用的倉庫。\\n\\n"; }
if(floor($_POST["final_order_total"]) < 0){ $message .= "合約總計(折扣後) 金額不能小於0,請適當增加租用月份或調整其他設定。\\n\\n"; }
if($_POST["total_discounted_price"] > 0 && ceil( ($_POST["last_paid"] - $_POST["deposit"]) / $_POST["total_discounted_price"]) > $_POST["rent_month"]){ $message .= "最少應租用".ceil( ($_POST["last_paid"] - $_POST["deposit"]) / $_POST["total_discounted_price"])."月。\\n\\n"; }
/*if(isset($_POST["prepaid_month"]) && $_POST["prepaid_month"] > 0 && ($_POST["paymethod"] == "UNPAID" || $_POST["paymethod2"] == "UNPAID")){ $message .= "合約選擇預繳,按金和租金付款方式不可以是未付。\\n\\n"; }*/
if(!empty($_POST["free_first_month"])){ $total_deduct += round($_POST["biggest_discounted_price"]-$_POST["biggest_retail_price"]*0.5, 1); }
//direct deduct if(!empty($_POST["free_2_month_deduct"])){ $total_deduct += $_POST["free_2_month_deduct"]; }else{ $free_2_month_deduct = 0; }
if(!empty($_POST["last_paid"])){ $total_deduct += $_POST["last_paid"]; } $total_deduct += $_POST["discount_amount"];
if($_POST["discount_deduct"] != $total_deduct){ $message .= "折扣扣減計算出錯,請與我們聯絡。\\n\\n"; }
if (!empty($message)) { echo "<script>alert('" . $message . "'); history.back();</script>"; //echo "<script>alert('" . $message . "');</script>"; exit; }
//record warehousing order in session $_SESSION["warehousing"][2]["order_room"] = $order_room; $_SESSION["warehousing"][2]["roughly_size"] = $_POST["roughly_size"]; $_SESSION["warehousing"][2]["total_retail_price"] = round($_POST["total_retail_price"],1); $_SESSION["warehousing"][2]["total_discounted_price"] = round($_POST["total_discounted_price"],1); $_SESSION["warehousing"][2]["deposit"] = round($_POST["deposit"],1); $_SESSION["warehousing"][2]["rent_month"] = $_POST["rent_month"]; $_SESSION["warehousing"][2]["biggest_retail_price"] = $_POST["biggest_retail_price"]; $_SESSION["warehousing"][2]["biggest_discounted_price"] = $_POST["biggest_discounted_price"];
if(isset($_POST["prepaid_month"])){ $_SESSION["warehousing"][2]["prepaid_month"] = $_POST["rent_month"]; $_SESSION["warehousing"][2]["prepaid_amount"] = round($_POST["total_discounted_price"],1)*$_POST["rent_month"]+round($_POST["deposit"],1);
if($_POST["last_paid"] > 0){ $_SESSION["warehousing"][2]["prepaid_amount"] -= $_POST["last_paid"]; } }else{ $_SESSION["warehousing"][2]["prepaid_month"] = 0; $_SESSION["warehousing"][2]["prepaid_amount"] = 0; }
//if free_first_month > 0 --> has free first month
if(!empty($_POST["free_first_month"])){ $_SESSION["warehousing"][2]["free_first_month"] = 1; $_SESSION["warehousing"][2]["free_first_month_deduct"] = round($_SESSION["warehousing"][2]["biggest_discounted_price"]-$_SESSION["warehousing"][2]["biggest_retail_price"]*0.5, 1);
if(isset($_POST["prepaid_month"])){ $_SESSION["warehousing"][2]["prepaid_amount"] -= $_SESSION["warehousing"][2]["free_first_month_deduct"]; }
}else{ $_SESSION["warehousing"][2]["free_first_month"] = 0; $_SESSION["warehousing"][2]["free_first_month_deduct"] = 0; }
//free_2_month_deduct $_SESSION["warehousing"][2]["free_2_month_deduct"] = $_POST["free_2_month_deduct"]; if(isset($_POST["prepaid_month"])){ $_SESSION["warehousing"][2]["prepaid_amount"] -= $_SESSION["warehousing"][2]["free_2_month_deduct"]; }
$_SESSION["warehousing"][2]["discount_amount"] = $_POST["discount_amount"]; if(isset($_POST["prepaid_month"])){ $_SESSION["warehousing"][2]["prepaid_amount"] -= $_SESSION["warehousing"][2]["discount_amount"]; } $_SESSION["warehousing"][2]["last_paid"] = $_POST["last_paid"]; $_SESSION["warehousing"][2]["warehousing_date"] = $_POST["warehousing_date"]; $_SESSION["warehousing"][2]["rent_from"] = $_POST["rent_from"]; $_SESSION["warehousing"][2]["rent_to"] = $_POST["rent_to"]; $_SESSION["warehousing"][2]["delivery_service"] = $_POST["delivery_service"]; if($_POST["delivery_service"] == 1){ $_SESSION["warehousing"][2]["delivery_date"] = $_POST["delivery_date"]; $_SESSION["warehousing"][2]["delivery_from"] = $_POST["delivery_from"]; $_SESSION["warehousing"][2]["delivery_to"] = $_POST["delivery_to"]; } $_SESSION["warehousing"][2]["remark"] = $_POST["remark"]; $_SESSION["warehousing"][2]["paymethod"] = $_POST["paymethod"]; if($_POST["paymethod"] == "CHEQUE"){ $_SESSION["warehousing"][2]["bank_name"] = $_POST["bank_name"]; $_SESSION["warehousing"][2]["cheque_num"] = $_POST["cheque_num"]; } if($_POST["paymethod"] == "OTHER"){ $_SESSION["warehousing"][2]["paymethod_other"] = $_POST["paymethod_other"]; }
if($_POST["paymethod"] == "BANKIN"){ $_SESSION["warehousing"][2]["paymethod_other"] = $_POST["paymethod_other2"]; }
$_SESSION["warehousing"][2]["paymethod2"] = $_POST["paymethod2"]; if($_POST["paymethod2"] == "CHEQUE"){ $_SESSION["warehousing"][2]["bank_name2"] = $_POST["bank_name2"]; $_SESSION["warehousing"][2]["cheque_num2"] = $_POST["cheque_num2"]; } if($_POST["paymethod2"] == "OTHER"){ $_SESSION["warehousing"][2]["paymethod_other2"] = $_POST["paymethod_other2"]; }
if($_POST["paymethod2"] == "BANKIN"){ $_SESSION["warehousing"][2]["paymethod_other2"] = $_POST["paymethod_other22"]; }
$_SESSION["warehousing"][2]["discount_deduct"] = round($_POST["discount_deduct"], 1); $_SESSION["warehousing"][2]["order_total"] = round($_POST["order_total"], 1); $_SESSION["warehousing"][2]["final_order_total"] = round($_POST["final_order_total"], 1); $_SESSION["warehousing"][2]["location_id"] = $location_id; $location_info = get_location($location_id); $_SESSION["warehousing"][2]["branch_id"] = $location_info["branch_id"]; $_SESSION["warehousing"][2]["company_id"] = $location_info["company_id"];
//room key //$_SESSION["warehousing"][2]["room_key"] = implode(",", $_POST["room_key"]); $_SESSION["warehousing"][2]["room_key"] = $_POST["room_key"]; //$_SESSION["warehousing"][2]["order_discount"] = $_SESSION["discount_info"];
//order product $order_product = array(); $k = 0; foreach($_POST["qty"] as $key => $qty){ if(!empty($qty) && (int)$qty > 0){ $order_product[$k]["product_id"] = $_POST["product_id"][$key]; $order_product[$k]["product_name"] = $_POST["product_name"][$key]; $order_product[$k]["qty"] = $_POST["qty"][$key]; $order_product[$k]["price"] = $_POST["price"][$key]; $k++; } }
$_SESSION["warehousing"][2]["order_product"] = $order_product;
$_SESSION["warehousing"][2]["pass"] = true;
//go to step 3 header("Location: warehousing_step3.php");
|