-
Notifications
You must be signed in to change notification settings - Fork 1
/
order.php
executable file
·414 lines (355 loc) · 13.2 KB
/
order.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
<?php
include '../lib/config.php';
include '../lib/function.php';
include '../models/order_model.php';
$page = null;
$page = (isset($_GET['page'])) ? $_GET['page'] : "list";
$title = ucfirst("Order");
$_SESSION['menu_active'] = 2;
switch ($page) {
case 'list':
$where_branch = "";
if($_SESSION['user_type_id']==3 || $_SESSION['user_type_id']==4 || $_SESSION['user_type_id']==5){
$where_branch = " where branch_id = '".$_SESSION['branch_id']."' ";
$branch_id = $_SESSION['branch_id'];
}else{
$first_branch_id = get_first_branch_id();
$branch_id = (isset($_GET['branch_id'])) ? $_GET['branch_id'] : $first_branch_id;
}
$first_building_id = get_first_building_id($branch_id);
$building_id = (isset($_GET['building_id'])) ? $_GET['building_id'] : $first_building_id;
$branch_name = get_branch_name($branch_id);
$building_name = get_building_name($building_id);
$building_img = get_building_img($building_id);
//get_header2($title);
//$query = select();
$action_room = "order.php?page=save_room";
$action_table = "order.php?page=save_table&building_id=$building_id";
$action_logout = "logout.php";
$action2 = "order.php?page=switch_table";
//$building_next();
//$building_prev();
include '../views/order/list.php';
//get_footer();
break;
case 'save_table_location':
$id=$_GET['id'];
$data_x=$_GET['data_x'];
$data_y=$_GET['data_y'];
save_table_location($id, $data_x, $data_y);
break;
case 'save_room':
$room_name = $_POST['i_room_name'];
$data = "'','".$room_name."'";
save_room($data);
header('location: order.php');
break;
case 'save_table':
$building_id = $_GET['building_id'];
$table_name = $_POST['i_table_name'];
$data = "'',
'$building_id',
'".$table_name."',
'200',
'200'
";
save_table($data);
header("location: order.php?building_id=$building_id");
break;
case 'save_payment':
$i_payment = $_POST['i_payment'];
$i_change = $_POST['i_change'];
$i_discount = $_POST['i_discount'];
$i_grand_total = $_POST['i_grand_total'];
$i_payment_method = $_POST['i_payment_method'];
$i_totaltax = "";
$i_disc_nominal = $_POST['i_disc_nominal'];
$i_disc_member = $_POST['i_disk2'];
$i_bank_id = "";
$i_bank_account = "";
if($i_payment_method == 2 || $i_payment_method == 3){
$i_bank_id = $_POST['i_bank_id'];
$i_bank_account = $_POST['i_bank_account'];
}
$building_id = $_GET['building_id'];
$table_id = $_GET['table_id'];
$branch_id = get_branch_id($building_id);
$data_total = get_data_total($table_id);
$total_discount = get_total_discount($table_id);
//echo $total_discount;
update_table_status($table_id);
if($i_payment < $i_grand_total){
header("location: payment.php?table_id=$table_id&building_id=$building_id&err=1");
}else{
$query = mysql_query("select *
from transactions_tmp a
where a.table_id = '$table_id'
");
// simpan transaksi
while($row = mysql_fetch_array($query)){
// create settlement
$get_discount_type = get_discount_type($row['member_id']);
if($total_discount > 0 && $get_discount_type == 2){
update_settlement($total_discount, $row['member_id']);
}
$data = "'',
'$table_id',
'$branch_id',
'".$row['member_id']."',
'".$row['transaction_date']."',
'".$data_total."',
'".$i_discount."',
'".$i_disc_member."',
'".$i_grand_total."',
'".$i_payment."',
'".$i_change."',
'".$i_disc_nominal."',
'".$i_payment_method."',
'".$i_bank_id."',
'".$row['user_id']."',
'".$i_bank_account."',
'".$i_totaltax."',
'".$row['transaction_code']."',
0
";
// simpan transaksi
create_config("transactions", $data);
$transaction_id = mysql_insert_id();
$get_table_name = get_table_name($table_id);
// simpan jurnal
create_journal($transaction_id, "", 1, $i_grand_total, "Meja ".$get_table_name, $i_bank_id, $branch_id);
$query_detail = mysql_query("select *
from transaction_tmp_details a
where a.transaction_id = '".$row['transaction_id']."'
");
while($row_detail = mysql_fetch_array($query_detail)){
// simpan transaksi detail
$data_detail = "'',
'$transaction_id',
'".$row_detail['menu_id']."',
'".$row_detail['transaction_detail_original_price']."',
'".$row_detail['transaction_detail_margin_price']."',
'".$row_detail['transaction_detail_price']."',
'".$row_detail['transaction_detail_price_discount']."',
'".$row_detail['transaction_detail_grand_price']."',
'".$row_detail['transaction_detail_qty']."',
'".$row_detail['transaction_detail_total']."'
";
create_config("transaction_details", $data_detail);
$query_item = mysql_query("select *
from menu_recipes a
where a.menu_id = '".$row_detail['menu_id']."'
");
while($row_item = mysql_fetch_array($query_item)){
// update stok bahan
$new_stock = $row_detail['transaction_detail_qty'] * $row_item['item_qty'];
update_stock($branch_id, $row_item['item_id'], $new_stock);
}
}
// hapus tmp
delete_tmp($table_id);
// hapus widget_tmp
delete_widget_tmp_details($table_id);
delete_widget_tmp($table_id);
}
//include '../views/order/print.php';
header("location: print.php?transaction_id=$transaction_id");
}
break;
case 'cancel_order':
$table_id = $_GET['table_id'];
$building_id = $_GET['building_id'];
$query_bill = mysql_query("select * from transaction_bills where table_id = '$table_id'");
$print_bill = mysql_fetch_array($query_bill);
// if($print_bill){
// $branch_id = get_branch_id($building_id);
// $data_total = get_data_total($table_id);
// $total_discount = get_total_discount($table_id);
// $data = "'',
// '$table_id',
// '$branch_id',
// '".$print_bill['member_id']."',
// '".$print_bill['transaction_date']."',
// '".$data_total."',
// '0',
// '".$data_total."',
// '".$data_total."',
// '0',
// '0',
// '0',
// '".$print_bill['user_id']."',
// '0',
// '".$print_bill['transaction_code']."'
// ";
// // simpan transaksi
// create_config("transactions", $data);
// $transaction_id = mysql_insert_id();
// $get_table_name = get_table_name($table_id);
// // simpan jurnal
// create_journal($transaction_id, "", 1, $data_total, "Meja ".$get_table_name, "0", $branch_id);
// $query_detail = mysql_query("select *
// from transaction_tmp_details a
// where a.transaction_id = '".$print_bill['transaction_id']."'
// ");
// while($row_detail = mysql_fetch_array($query_detail)){
// // simpan transaksi detail
// $data_detail = "'',
// '$transaction_id',
// '".$row_detail['menu_id']."',
// '".$row_detail['transaction_detail_original_price']."',
// '".$row_detail['transaction_detail_margin_price']."',
// '".$row_detail['transaction_detail_price']."',
// '".$row_detail['transaction_detail_price_discount']."',
// '".$row_detail['transaction_detail_grand_price']."',
// '".$row_detail['transaction_detail_qty']."',
// '".$row_detail['transaction_detail_total']."'
// ";
// create_config("transaction_details", $data_detail);
//
// $query_item = mysql_query("select *
// from menu_recipes a
// where a.menu_id = '".$row_detail['menu_id']."'
// ");
// while($row_item = mysql_fetch_array($query_item)){
// // update stok bahan
// $new_stock = $row_detail['transaction_detail_qty'] * $row_item['item_qty'];
// update_stock($branch_id, $row_item['item_id'], $new_stock);
// }
// }
// delete_transaction($transaction_id);
// delete_config("transaction_bills", "table_id = '".$table_id."'");
// }
// hapus transaction_tmp_details
$q_detail = mysql_query("select * from transactions_tmp where table_id = '$table_id'");
while($r_detail = mysql_fetch_array($q_detail)){
delete_config("transaction_tmp_details", "transaction_id = '".$r_detail['transaction_id']."'");
}
delete_config("transactions_tmp", "table_id = '$table_id'");
// hapus widget_tmp_details
$q_widget_detail = mysql_query("select * from widget_tmp where table_id = '$table_id'");
while($r_widget_detail = mysql_fetch_array($q_widget_detail)){
delete_config("widget_tmp_details", "wt_id = '".$r_widget_detail['wt_id']."'");
}
delete_config("widget_tmp", "table_id = '$table_id'");
mysql_query("update tables set table_status_id = '1' where table_id = '$table_id'");
//cancel_order($table_id);
header("location: order.php?building_id=$building_id");
break;
case 'order_status':
$id = $_GET['id'];
$building_id = $_GET['building_id'];
update_order_status($id);
header("location: order.php?building_id=$building_id");
break;
case 'cancel_reserved':
$table_id = $_GET['table_id'];
$building_id = $_GET['building_id'];
//echo $table_id;
cancel_reserved($table_id);
header("location: order.php?building_id=$building_id");
break;
case 'merger_table':
$table_id = get_isset($_GET['table_id']);
$building_id = (isset($_GET['building_id'])) ? $_GET['building_id'] : 0;
$building_name = get_building_name($building_id);
$query_table_merger = select_table_merger($building_id, $table_id);
$query_exist = mysql_query("select count(table_id) as jumlah from table_mergers where table_parent_id = '".$table_id."'");
$row_exist = mysql_fetch_array($query_exist);
$jumlah_child = $row_exist['jumlah'];
$action = "order.php?page=save_merger_table&table_id=".$table_id."&building_id=".$building_id;
$delete_merger_action = "order.php?page=delete_all_merger&table_id=".$table_id."&building_id=".$building_id;
$close_button = "order.php?building_id=$building_id";
include '../views/order/merger_table.php';
break;
case 'delete_all_merger':
$table_id = get_isset($_GET['table_id']);
$building_id = (isset($_GET['building_id'])) ? $_GET['building_id'] : 0;
// update status merger si parent
update_merger_status($table_id, 0);
// looping childnya
$query = mysql_query("select * from table_mergers where table_parent_id = '$table_id'");
while($row = mysql_fetch_array($query)){
// update status merger si child
update_merger_status($row['table_id'], 0);
delete_merger_table($table_id, $row['table_id']);
}
header("location: order.php?building_id=$building_id");
break;
case 'save_merger_table':
$table_id = get_isset($_GET['table_id']);
$building_id = (isset($_GET['building_id'])) ? $_GET['building_id'] : 0;
update_merger_status($table_id, 1);
$query_table_merger = select_table_merger($building_id, $table_id);
while($row = mysql_fetch_array($query_table_merger)){
if($row['tms_id']==0){
update_merger_status($row['table_id'], 0);
delete_merger_table($table_id, $row['table_id']);
if($_POST['i_table_id_'.$row['table_id']] == 1){
$data = "'',
'$table_id',
'".$row['table_id']."'
";
save_merger_table($data);
update_merger_status($row['table_id'], 2);
}
}else{
// cek apakah child sendiri ?
$query_exist = mysql_query("select count(table_id) as jumlah from table_mergers where table_parent_id = '".$table_id."' and table_id = '".$row['table_id']."'");
$row_exist = mysql_fetch_array($query_exist);
// jika ya tampilkan
if($row_exist['jumlah'] > 0){
update_merger_status($row['table_id'], 0);
delete_merger_table($table_id, $row['table_id']);
if($_POST['i_table_id_'.$row['table_id']] == 1){
$data = "'',
'$table_id',
'".$row['table_id']."'
";
save_merger_table($data);
update_merger_status($row['table_id'], 2);
}
}
}
}
header("location: order.php?building_id=$building_id");
break;
case 'add_duration':
$reserved_id = $_GET['reserved_id'];
$i_duration = $_POST['i_duration'];
$building_id = (isset($_GET['building_id'])) ? $_GET['building_id'] : 0;
$get_reservation_time = get_reservation_time($reserved_id);
//echo $get_reservation_time;
$minute = $i_duration;
$add = strtotime('+'.$minute.' minutes', strtotime($get_reservation_time));
$add = date("Y-m-d H:i:s", $add);
add_duration($reserved_id, $add);
header("location: order.php?building_id=$building_id");
break;
case 'switch_table':
$i_table_id = '';
$i_table = '';
extract($_POST);
$i_table_id = get_isset($i_table_id);
$i_table = get_isset($i_table);
mysql_query("update transactions_tmp set table_id = '$i_table_id' where table_id = '$i_table'");
mysql_query("update widget_tmp set table_id = '$i_table_id' where table_id = '$i_table'");
mysql_query("update widget_tmp set table_id = '$i_table_id' where table_id = '$i_table'");
mysql_query("update tables set table_status_id = '1' where table_id = '$i_table'");
mysql_query("update tables set table_status_id = '2' where table_id = '$i_table_id'");
header("location: order.php");
//var_dump($_POST);
// var_dump($i_table);
// var_dump($i_table_id);
break;
case 'got_table':
$id = $_POST['x'];
//var_dump($id);
$query = mysql_query("select a.*, b.building_name
from tables a
left join buildings b on b.building_id = a.building_id
where tms_id <> '2'
order by building_id, table_name
");
break;
}
?>