-
Notifications
You must be signed in to change notification settings - Fork 4
/
SeriousEater-Eaterio-Database.sql
417 lines (352 loc) · 15.4 KB
/
SeriousEater-Eaterio-Database.sql
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
-- phpMyAdmin SQL Dump
-- version 5.1.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Nov 15, 2021 at 09:17 PM
-- Server version: 10.4.20-MariaDB
-- PHP Version: 8.0.9
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `eaterio`
--
DELIMITER $$
--
-- Procedures
--
CREATE DEFINER=`root`@`localhost` PROCEDURE `customer_order` (IN `order_id` INT(11)) BEGIN
SELECT orh.orh_refcode AS reference_code, CONCAT(c.c_firstname,' ',c.c_lastname) AS customer_name, s.s_name AS shop_name,f.f_name AS food_name,ord.ord_buyprice AS buy_price, ord.ord_amount AS amount ,ord.ord_note AS order_note, orh.orh_ordertime AS order_time , orh.orh_pickuptime AS pickup_time
FROM order_header orh
INNER JOIN order_detail ord ON orh.orh_id = ord.orh_id
INNER JOIN food f ON f.f_id = ord.f_id
INNER JOIN customer c ON orh.c_id = c.c_id
INNER JOIN shop s ON orh.s_id = s.s_id
WHERE orh.orh_id = order_id;
END$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `customer_order_history` (IN `customer_id` INT(11)) BEGIN
SELECT orh.orh_refcode AS reference_code, CONCAT(c.c_firstname,' ',c.c_lastname) AS customer_name,
s.s_name AS shop_name, orh.orh_ordertime AS order_time, orh.orh_pickuptime AS pickup_time,
p.p_amount AS order_cost, orh.orh_orderstatus AS order_status
FROM order_header orh INNER JOIN customer c ON orh.c_id = c.c_id
INNER JOIN payment p ON orh.p_id = p.p_id
INNER JOIN shop s ON orh.s_id = s.s_id
WHERE c.c_id = customer_id;
END$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `shop_alltime_revenue` (IN `shop_id` INT(11)) BEGIN
SELECT SUM(ord.ord_amount*ord.ord_buyprice) AS alltime_revenue
FROM order_header orh INNER JOIN order_detail ord ON orh.orh_id = ord.orh_id
INNER JOIN food f ON f.f_id = ord.f_id INNER JOIN shop s ON s.s_id = orh.s_id
WHERE s.s_id = shop_id AND orh.orh_orderstatus = 'FNSH';
END$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `shop_menu_revenue` (IN `shop_id` INT(11)) BEGIN
SELECT f.f_name AS food_name, SUM(ord.ord_amount*ord.ord_buyprice) AS menu_revenue
FROM order_header orh INNER JOIN order_detail ord ON orh.orh_id = ord.orh_id
INNER JOIN food f ON f.f_id = ord.f_id
WHERE orh.s_id = shop_id AND orh.orh_orderstatus = 'FNSH'
GROUP BY ord.f_id ORDER BY menu_revenue DESC;
END$$
DELIMITER ;
-- --------------------------------------------------------
--
-- Table structure for table `cart`
--
CREATE TABLE `cart` (
`ct_id` int(11) NOT NULL,
`c_id` int(11) NOT NULL,
`s_id` int(11) NOT NULL,
`f_id` int(11) NOT NULL,
`ct_amount` int(11) NOT NULL,
`ct_note` text COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
--
-- Table structure for table `customer`
--
CREATE TABLE `customer` (
`c_id` int(11) NOT NULL,
`c_username` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
`c_pwd` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
`c_firstname` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
`c_lastname` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
`c_email` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`c_gender` varchar(1) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'M for Male, F for Female',
`c_type` varchar(3) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Type of customer in this canteen (STD for student, INS for instructor, STF for staff, GUE for guest, ADM for admin, OTH for other)'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Dumping data for table `customer`
--
INSERT INTO `customer` (`c_id`, `c_username`, `c_pwd`, `c_firstname`, `c_lastname`, `c_email`, `c_gender`, `c_type`) VALUES
(2, '6222780668', '6222780668', 'Sirada', 'Chaisawat', '6222780668@g.siit.tu.ac.th', 'F', 'STD'),
(3, '6222780569', '6222780569', 'Thanakit', 'Lerttomolsakul', '6222780569@g.siit.tu.ac.th', 'M', 'STD'),
(4, 'BKD_Admin01', '12345678', 'Admin', 'Bangkradi', 'admin_dummy@email.com', 'M', 'ADM'),
(11, 'someone', 'someonee', 'someone', 'someone', 'someone@email.com', 'N', 'GUE'),
(16, '6222780379', '6222780379', 'Paphana', 'Yiwsiw', '6222780379@g.siit.tu.ac.th', 'M', 'STD'),
(19, 'iamguest', 'iamguest', 'Guest01', 'Guest01', 'guest@gmail.com', 'M', 'GUE'),
(20, 'johndoe', 'johndoee', 'John', 'Doey', 'john@gmail.com', 'F', 'STF');
-- --------------------------------------------------------
--
-- Table structure for table `food`
--
CREATE TABLE `food` (
`f_id` int(11) NOT NULL,
`s_id` int(11) NOT NULL,
`f_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`f_price` decimal(6,2) NOT NULL,
`f_todayavail` tinyint(4) NOT NULL DEFAULT 1 COMMENT 'Food is available to order or not',
`f_preorderavail` tinyint(4) NOT NULL DEFAULT 1,
`f_pic` text COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Dumping data for table `food`
--
INSERT INTO `food` (`f_id`, `s_id`, `f_name`, `f_price`, `f_todayavail`, `f_preorderavail`, `f_pic`) VALUES
(1, 1, 'ข้าวกะเพราหมูสับ', '40.00', 1, 0, '1_1.jpeg'),
(2, 1, 'ข้าวผัดกุ้ง', '55.00', 1, 1, '2_1.jpeg'),
(3, 1, 'ผัดซีอิ้ว', '40.00', 1, 1, '3_1.jpeg'),
(4, 1, 'ข้าวไข่เจียว', '30.00', 1, 1, '4_1.jpeg'),
(5, 1, 'ข้าวหมูกะเทียม', '35.00', 1, 1, '5_1.jpeg'),
(6, 1, 'มาม่าผัดไข่', '35.00', 1, 1, '6_1.jpeg'),
(7, 1, 'ข้าวผัดไข่', '35.00', 1, 1, '7_1.jpeg'),
(8, 1, 'ผัดพริกแกง', '40.00', 1, 1, NULL),
(9, 1, 'ข้าวกะเพราไก่', '40.00', 1, 1, '9_1.jpeg'),
(10, 1, 'ข้าวไก่ทอด', '40.00', 1, 1, '10_1.jpeg'),
(11, 2, 'ข้าวไข่พะโล้', '30.00', 1, 1, NULL),
(12, 2, 'ข้าวแกงจืดเต้าหู้หมูสับ', '30.00', 1, 1, '12_2.jpeg'),
(13, 2, 'ข้าวพะแนงไก่', '30.00', 1, 1, '13_2.jpeg'),
(14, 2, 'ข้าวมัสมั่นไก่', '30.00', 1, 1, '14_2.jpeg'),
(15, 2, 'ข้าวราดผัดผัก', '30.00', 1, 1, '15_2.jpeg'),
(16, 2, 'ข้าวผัดวุ้นเส้น', '30.00', 1, 1, '16_2.jpeg'),
(17, 2, 'ข้าวบวบผัดไข่', '30.00', 1, 1, NULL),
(18, 2, 'ข้าวผัดเต้าหู้ทรงเครื่อง', '30.00', 1, 1, NULL),
(19, 2, 'ข้าวไข่ตุ๋น', '30.00', 1, 1, '19_2.jpeg'),
(20, 2, 'ข้าวไข่ดาว', '25.00', 1, 1, '20_2.jpeg'),
(21, 3, 'ก๋วยเตี๋ยวน้ำใส', '35.00', 1, 1, '21_3.jpeg'),
(22, 3, 'บะหมี่หมูแดง', '30.00', 1, 1, '22_3.jpeg'),
(23, 3, 'ก๋วยเตี๋ยวต้มยำ', '35.00', 1, 1, '23_3.jpeg'),
(24, 3, 'ก๋วยเตี๋ยวเย็นตาโฟ', '35.00', 1, 1, NULL),
(25, 3, 'ก๋วยเตี๋ยวแห้งต้มยำ', '35.00', 1, 1, NULL),
(26, 3, 'ก๋วยเตี๋ยวน้ำตก', '35.00', 1, 1, '26_3.jpeg'),
(27, 3, 'เกาเหลาหมูตุ๋น', '40.00', 1, 0, NULL),
(28, 3, 'ก๋วยเตี๋ยวหมูตุ๋น', '40.00', 1, 1, '28_3.jpeg'),
(29, 3, 'ข้าวเปล่า', '10.00', 1, 1, '29_3.jpeg'),
(30, 3, 'เล้ง', '40.00', 1, 1, '30_3.jpeg');
-- --------------------------------------------------------
--
-- Table structure for table `order_detail`
--
CREATE TABLE `order_detail` (
`ord_id` int(11) NOT NULL,
`orh_id` int(11) NOT NULL,
`f_id` int(11) NOT NULL,
`ord_amount` int(11) NOT NULL,
`ord_buyprice` decimal(6,2) NOT NULL COMMENT 'To keep the snapshot of selected menu cost at the time of the purchase.',
`ord_note` text COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Dumping data for table `order_detail`
--
INSERT INTO `order_detail` (`ord_id`, `orh_id`, `f_id`, `ord_amount`, `ord_buyprice`, `ord_note`) VALUES
(25, 22, 28, 2, '40.00', ''),
(26, 22, 22, 1, '30.00', ''),
(27, 23, 13, 1, '30.00', ''),
(28, 23, 14, 1, '30.00', ''),
(29, 24, 22, 1, '30.00', 'No veggie'),
(30, 25, 29, 3, '10.00', '');
-- --------------------------------------------------------
--
-- Table structure for table `order_header`
--
CREATE TABLE `order_header` (
`orh_id` int(11) NOT NULL,
`orh_refcode` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`c_id` int(11) NOT NULL,
`s_id` int(11) NOT NULL,
`p_id` int(11) NOT NULL,
`orh_ordertime` timestamp NOT NULL DEFAULT current_timestamp(),
`orh_pickuptime` datetime NOT NULL,
`orh_orderstatus` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
`orh_finishedtime` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Dumping data for table `order_header`
--
INSERT INTO `order_header` (`orh_id`, `orh_refcode`, `c_id`, `s_id`, `p_id`, `orh_ordertime`, `orh_pickuptime`, `orh_orderstatus`, `orh_finishedtime`) VALUES
(22, '202110280000022', 16, 3, 20, '2021-10-28 18:25:53', '2021-10-29 08:30:00', 'FNSH', '2021-11-09 01:55:19'),
(23, '202110290000023', 16, 2, 21, '2021-10-28 19:13:22', '2021-10-29 12:00:00', 'FNSH', '2021-11-14 16:44:32'),
(24, '202110290000024', 16, 3, 22, '2021-10-29 05:22:06', '2021-10-29 13:00:00', 'FNSH', '2021-11-15 12:42:47'),
(25, '202110290000025', 19, 3, 23, '2021-10-29 07:57:07', '2021-10-29 15:00:00', 'FNSH', '2021-11-15 12:17:21');
-- --------------------------------------------------------
--
-- Table structure for table `payment`
--
CREATE TABLE `payment` (
`p_id` int(11) NOT NULL,
`c_id` int(11) NOT NULL,
`p_type` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
`p_amount` decimal(7,2) NOT NULL,
`p_detail` text COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Dumping data for table `payment`
--
INSERT INTO `payment` (`p_id`, `c_id`, `p_type`, `p_amount`, `p_detail`) VALUES
(20, 16, 'CRDC', '110.00', 'Visa [*4242]'),
(21, 16, 'CRDC', '60.00', 'Visa [*4242]'),
(22, 16, 'CRDC', '30.00', 'Visa [*4242]'),
(23, 19, 'CRDC', '30.00', 'Visa [*4242]');
-- --------------------------------------------------------
--
-- Table structure for table `shop`
--
CREATE TABLE `shop` (
`s_id` int(11) NOT NULL,
`s_username` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
`s_pwd` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
`s_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`s_location` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`s_openhour` time NOT NULL,
`s_closehour` time NOT NULL,
`s_status` tinyint(4) NOT NULL DEFAULT 1 COMMENT 'Shop ready for taking an order or not (True for open, False for close)',
`s_preorderStatus` tinyint(4) NOT NULL DEFAULT 1 COMMENT 'Shop is ready for tomorrow pre-order or not',
`s_email` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`s_phoneno` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
`s_pic` text COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Dumping data for table `shop`
--
INSERT INTO `shop` (`s_id`, `s_username`, `s_pwd`, `s_name`, `s_location`, `s_openhour`, `s_closehour`, `s_status`, `s_preorderStatus`, `s_email`, `s_phoneno`, `s_pic`) VALUES
(1, 'shop001', '12345678', 'ร้านอาหารตามสั่ง', 'Unit #2', '07:30:00', '14:30:00', 1, 1, 'shop001@email.com', '0900001234', 'shop1.jpeg'),
(2, 'shop002', '12345678', 'ร้านข้าวราดแกง', 'Unit #1', '08:00:00', '17:30:00', 1, 1, 'shop002@email.com', '0900000002', NULL),
(3, 'shop003', 'qwertyui', 'The Noodle Shop', 'Unit #3', '08:30:00', '16:00:00', 1, 1, 'shop003@email.com', '0901234567', 'shop3.jpg');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `cart`
--
ALTER TABLE `cart`
ADD PRIMARY KEY (`ct_id`),
ADD KEY `fk_ct_c_idx` (`c_id`),
ADD KEY `fk_ct_s_idx` (`s_id`),
ADD KEY `fk_ct_f_idx` (`f_id`);
--
-- Indexes for table `customer`
--
ALTER TABLE `customer`
ADD PRIMARY KEY (`c_id`),
ADD UNIQUE KEY `c_username` (`c_username`),
ADD UNIQUE KEY `c_email` (`c_email`);
--
-- Indexes for table `food`
--
ALTER TABLE `food`
ADD PRIMARY KEY (`f_id`),
ADD KEY `food_shop_s_id_idx` (`s_id`);
--
-- Indexes for table `order_detail`
--
ALTER TABLE `order_detail`
ADD PRIMARY KEY (`ord_id`),
ADD KEY `fk_orh_ord_idx` (`orh_id`),
ADD KEY `fk_f_ord_idx` (`f_id`);
--
-- Indexes for table `order_header`
--
ALTER TABLE `order_header`
ADD PRIMARY KEY (`orh_id`),
ADD KEY `fk_orh_idx` (`c_id`),
ADD KEY `fk_s_orh_idx` (`s_id`),
ADD KEY `fk_p_orh_idx` (`p_id`);
--
-- Indexes for table `payment`
--
ALTER TABLE `payment`
ADD PRIMARY KEY (`p_id`),
ADD KEY `p_c_fk_idx` (`c_id`);
--
-- Indexes for table `shop`
--
ALTER TABLE `shop`
ADD PRIMARY KEY (`s_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `cart`
--
ALTER TABLE `cart`
MODIFY `ct_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=56;
--
-- AUTO_INCREMENT for table `customer`
--
ALTER TABLE `customer`
MODIFY `c_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21;
--
-- AUTO_INCREMENT for table `food`
--
ALTER TABLE `food`
MODIFY `f_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=35;
--
-- AUTO_INCREMENT for table `order_detail`
--
ALTER TABLE `order_detail`
MODIFY `ord_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;
--
-- AUTO_INCREMENT for table `order_header`
--
ALTER TABLE `order_header`
MODIFY `orh_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=26;
--
-- AUTO_INCREMENT for table `payment`
--
ALTER TABLE `payment`
MODIFY `p_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=24;
--
-- AUTO_INCREMENT for table `shop`
--
ALTER TABLE `shop`
MODIFY `s_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
--
-- Constraints for dumped tables
--
--
-- Constraints for table `cart`
--
ALTER TABLE `cart`
ADD CONSTRAINT `fk_ct_c` FOREIGN KEY (`c_id`) REFERENCES `customer` (`c_id`) ON DELETE CASCADE,
ADD CONSTRAINT `fk_ct_f` FOREIGN KEY (`f_id`) REFERENCES `food` (`f_id`) ON DELETE CASCADE,
ADD CONSTRAINT `fk_ct_s` FOREIGN KEY (`s_id`) REFERENCES `shop` (`s_id`) ON DELETE CASCADE;
--
-- Constraints for table `food`
--
ALTER TABLE `food`
ADD CONSTRAINT `fk_food_shop_id` FOREIGN KEY (`s_id`) REFERENCES `shop` (`s_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
--
-- Constraints for table `order_detail`
--
ALTER TABLE `order_detail`
ADD CONSTRAINT `fk_f_ord` FOREIGN KEY (`f_id`) REFERENCES `food` (`f_id`),
ADD CONSTRAINT `fk_orh_ord` FOREIGN KEY (`orh_id`) REFERENCES `order_header` (`orh_id`) ON DELETE CASCADE;
--
-- Constraints for table `order_header`
--
ALTER TABLE `order_header`
ADD CONSTRAINT `fk_c_orh` FOREIGN KEY (`c_id`) REFERENCES `customer` (`c_id`) ON DELETE CASCADE,
ADD CONSTRAINT `fk_p_orh` FOREIGN KEY (`p_id`) REFERENCES `payment` (`p_id`) ON DELETE CASCADE,
ADD CONSTRAINT `fk_s_orh` FOREIGN KEY (`s_id`) REFERENCES `shop` (`s_id`) ON DELETE CASCADE;
--
-- Constraints for table `payment`
--
ALTER TABLE `payment`
ADD CONSTRAINT `fk_p_c` FOREIGN KEY (`c_id`) REFERENCES `customer` (`c_id`) ON DELETE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;