-
Notifications
You must be signed in to change notification settings - Fork 0
/
pan_db.sql
456 lines (441 loc) · 12.4 KB
/
pan_db.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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
CREATE DATABASE IF NOT EXISTS pan_db;
USE pan_db;
CREATE TABLE
IF NOT EXISTS `employee` (
employee_id INT NOT NULL AUTO_INCREMENT,
first_name VARCHAR(300) NOT NULL,
last_name VARCHAR(300) NOT NULL,
password VARCHAR(280) NOT NULL,
contact_no VARCHAR(11) NOT NULL,
email VARCHAR(300) NOT NULL,
date_employed DATE NOT NULL,
role ENUM ('manager', 'employee') NOT NULL DEFAULT 'employee',
is_active ENUM ('0', '1') NOT NULL DEFAULT '1',
CONSTRAINT PK_Employee PRIMARY KEY (employee_id),
CONSTRAINT UC_Employee_Email UNIQUE (email)
);
CREATE TABLE
IF NOT EXISTS `order` (
order_id INT NOT NULL AUTO_INCREMENT,
employee_id INT NOT NULL,
date_placed DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT PK_Order PRIMARY KEY (order_id),
CONSTRAINT FK_Order_Employee FOREIGN KEY (employee_id) REFERENCES employee (employee_id)
);
CREATE TABLE
IF NOT EXISTS `category` (
category_id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
CONSTRAINT PK_Category PRIMARY KEY (category_id)
);
CREATE TABLE
IF NOT EXISTS `product` (
product_id INT NOT NULL AUTO_INCREMENT,
category_id INT DEFAULT NULL,
creator_id INT NOT NULL,
date_created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
name VARCHAR(100) NOT NULL,
description TEXT,
unit_price DECIMAL(7, 2) NOT NULL,
is_available ENUM ('0', '1') NOT NULL DEFAULT '1',
CONSTRAINT PK_Product PRIMARY KEY (product_id),
CONSTRAINT FK_Product_Category FOREIGN KEY (category_id) REFERENCES category (category_id) ON DELETE SET NULL,
CONSTRAINT FK_Product_Employee FOREIGN KEY (creator_id) REFERENCES employee (employee_id)
);
CREATE TABLE
IF NOT EXISTS `order_line` (
order_id INT NOT NULL,
product_id INT NOT NULL,
quantity INT NOT NULL,
selling_price DECIMAL(7, 2) NOT NULL,
CONSTRAINT PK_OrderLine PRIMARY KEY (order_id, product_id),
CONSTRAINT FK_OrderLine_Order FOREIGN KEY (order_id) REFERENCES `order` (order_id) ON DELETE CASCADE,
CONSTRAINT FK_OrderLine_Product FOREIGN KEY (product_id) REFERENCES product (product_id)
);
CREATE TABLE
IF NOT EXISTS `supplier` (
supplier_id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(300) NOT NULL,
building VARCHAR(150),
street_no VARCHAR(10),
street_name VARCHAR(150),
city VARCHAR(150) NOT NULL,
zip_code VARCHAR(10) NOT NULL,
contact_no VARCHAR(11) NOT NULL,
email VARCHAR(300) NOT NULL,
is_active ENUM ('0', '1') NOT NULL DEFAULT '1',
CONSTRAINT PK_Supplier PRIMARY KEY (supplier_id)
);
CREATE TABLE
IF NOT EXISTS `stock` (
stock_id INT NOT NULL AUTO_INCREMENT,
product_id INT NOT NULL,
supplier_id INT NOT NULL,
date_supplied DATE NOT NULL,
quantity INT NOT NULL DEFAULT 0,
unit VARCHAR(5) NOT NULL,
unit_price DECIMAL(7, 2) NOT NULL,
notes TEXT,
CONSTRAINT PK_Stock PRIMARY KEY (stock_id),
CONSTRAINT FK_Stock_Product FOREIGN KEY (product_id) REFERENCES product (product_id),
CONSTRAINT FK_Stock_Supplier FOREIGN KEY (supplier_id) REFERENCES supplier (supplier_id)
);
-- SAMPLE DATA FOR CATEGORY TABLE --
INSERT INTO
`category` (
`category_id`,
`name`
)
VALUES
(
'1',
'Bread'
), (
'2',
'Cakes'
), (
'3',
'Pies'
), (
'4',
'Muffins'
), (
'5',
'Cookies'
), (
'6',
'Doughnuts'
);
-- SAMPLE DATA FOR EMPLOYEE TABLE --
INSERT INTO
`employee` (
`employee_id`,
`first_name`,
`last_name`,
`password`,
`contact_no`,
`email`,
`date_employed`,
`role`,
`is_active`
)
VALUES
(
1,
'Jonh',
'Buot',
'$2b$10$qcPZ9U16R5ynxV4kyQ1RAekhPqAtrM6qKhSH0OMFTsMCXbP54WVcS',
'09345678910',
CURRENT_DATE(),
'employee',
'1'
), (
2,
'Nathan',
'Arriesgado',
'$2b$10$aFfQ6N.gAMrH/fOUPnrSyeVzeIiTyOCrcJu3Pz0ttoJm0j/ZYKEWe',
'09987654321',
CURRENT_DATE(),
'employee',
'1'
), (
3,
'Erwin',
'Antepuesto',
'$2b$10$aFfQ6N.gAMrH/fOUPnrSyeVzeIiTyOCrcJu3Pz0ttoJm0j/ZYKEWe',
'09223344556',
CURRENT_DATE(),
'employee',
'1'
), (
4,
'Sherly',
'Jao',
'$2b$10$aFfQ6N.gAMrH/fOUPnrSyeVzeIiTyOCrcJu3Pz0ttoJm0j/ZYKEWe',
'09263748596',
CURRENT_DATE(),
'employee',
'1'
), (
5,
'Manager',
'User',
'$2b$10$qcPZ9U16R5ynxV4kyQ1RAekhPqAtrM6qKhSH0OMFTsMCXbP54WVcS',
'09823782938',
CURRENT_DATE(),
'manager',
'1'
), (
6,
'Employee',
'User',
'$2b$10$aFfQ6N.gAMrH/fOUPnrSyeVzeIiTyOCrcJu3Pz0ttoJm0j/ZYKEWe',
'09278197382',
CURRENT_DATE(),
'employee',
'1'
);
-- SAMPLE DATA FOR ORDER TABLE --
INSERT INTO
`order` (`employee_id`, `date_placed`)
VALUES
('4', '2022-8-2'),
('3', '2022-8-4'),
('3', '2022-8-5'),
('2', '2022-8-5'),
('1', '2022-8-6'),
('4', '2022-8-8'),
('3', '2022-8-12'),
('1', '2022-8-14'),
('2', '2022-9-22'),
('2', '2022-9-11'),
('4', '2022-9-11'),
('4', '2022-9-19'),
('4', '2022-9-26'),
('4', '2022-10-1'),
('2', '2022-10-2'),
('1', '2022-10-2'),
('1', '2022-10-10'),
('3', '2022-10-11'),
('3', '2022-10-20'),
('3', '2022-11-4'),
('3', '2022-11-12'),
('2', '2022-11-16'),
('1', '2022-11-17'),
('1', '2022-11-17'),
('1', '2022-11-29'),
('4', '2022-11-30');
-- SAMPLE DATA FOR PRODUCT TABLE --
INSERT INTO
`product` (
`product_id`,
`category_id`,
`creator_id`,
`date_created`,
`name`,
`description`,
`unit_price`,
`is_available`
)
VALUES
(
1,
'1',
'2',
current_timestamp(),
'Pain au Chocolat',
'Almost like a crispy, buttery, airy, and simply irresistibly delicious French Croissant, but filled with chocolate!',
'9.99',
'0'
), (
2,
'1',
'2',
current_timestamp(),
'French Toast',
'A dish of sliced bread soaked in beaten eggs and often milk or cream, then pan fried.',
'7.99',
'1'
), (
3,
'3',
'3',
current_timestamp(),
'Raspberry Pie',
'A type of pie with a raspberry filling',
'19.99',
'0'
), (
4,
'5',
'4',
current_timestamp(),
'Macademia Nut Cookie',
'White chocolate cookies with brown sugar, almonds, and macademia nuts.',
'2.99',
'1'
), (
5,
'2',
'3',
current_timestamp(),
'Cheese Cake',
'Soft spongy yellow goodness in a box.',
'49.99',
'1'
), (
6,
'2',
'1',
current_timestamp(),
'Chocolate Cake',
'A classic delight with an incredibly filling belgian chocolate center!',
'49.99',
'1'
), (
7,
'4',
'4',
current_timestamp(),
'Chocolate Chip Muffin',
'Light and Fluffy, the right texture, and all the right taste. Packed into a simple and elegant design!',
'14.99',
'1'
), (
8,
'6',
'5',
current_timestamp(),
'Glazed Doughnuts',
'Classic golden baked doughnuts covered in sweet glaze for your satisfaction.',
'8.99',
'0'
), (
9,
NULL,
'2',
current_timestamp(),
'Snowy Surprise',
'A mysterious treat prepared by our employees. Available only in Christmas season.',
'19.99',
'1'
);
-- SAMPLE DATA FOR ORDERLINE TABLE --
INSERT INTO
`order_line` (`order_id`, `product_id`, `quantity`, `selling_price`)
VALUES
('1', '1', '4', '39.96'),
('1', '7', '1', '14.99'),
('2', '5', '2', '99.98'),
('3', '7', '1', '14.99'),
('3', '2', '2', '15.98'),
('3', '1', '2', '19.98'),
('4', '3', '1', '19.99'),
('5', '4', '6', '17.94'),
('6', '5', '1', '49.99'),
('7', '5', '2', '99.98'),
('7', '6', '1', '49.99'),
('8', '1', '1', '9.99'),
('9', '1', '4', '39.96'),
('10', '2', '2', '15.98'),
('11', '2', '1', '7.99'),
('11', '3', '2', '39.98'),
('12', '4', '4', '11.96'),
('13', '7', '2', '29.98'),
('14', '1', '2', '19.98'),
('15', '1', '8', '79.92'),
('16', '6', '1', '49.99'),
('17', '8', '2', '53.94'),
('18', '8', '12', '107.88'),
('19', '8', '2', '17.98'),
('20', '4', '1', '2.99'),
('21', '6', '2', '99.98'),
('22', '2', '1', '31.96'),
('23', '9', '2', '39.98'),
('24', '5', '1', '49.99'),
('24', '6', '2', '99.98'),
('25', '1', '2', '19.98'),
('25', '9', '1', '19.99');
-- SAMPLE DATA FOR SUPPLIER TABLE --
INSERT INTO
`supplier` (
`supplier_id`,
`name`,
`building`,
`street_no`,
`street_name`,
`city`,
`zip_code`,
`contact_no`,
`email`,
`is_active`
)
VALUES
(
1,
'Wheat and Goods Co.',
'Quarry House',
'42',
'Main Road',
'Manila City',
'1000',
'83726192874',
'1'
), (
2,
'Bread Express',
'Daytona Apartment',
'21',
'Half Street',
'Lapu-Lapu City',
'6015',
'18572940192',
'1'
), (
3,
'House of Sweets',
'Bunzel',
'69',
'Park Road',
'Quezon City',
'1008',
'02938746172',
'1'
);
-- SAMPLE DATA FOR STOCK TABLE --
INSERT INTO
`stock` (
`product_id`,
`supplier_id`,
`date_supplied`,
`quantity`,
`unit`,
`unit_price`,
`notes`
)
VALUES
('1', '2', '2022-8-1', '30', 'pcs', '4.99', 'N/A'),
('2', '2', '2022-8-1', '40', 'pcs', '3.99', 'N/A'),
('3', '1', '2022-8-1', '30', 'pcs', '3.49', 'N/A'),
('4', '1', '2022-8-1', '60', 'pcs', '1.49', 'N/A'),
('5', '3', '2022-8-1', '10', 'pcs', '24.99', 'N/A'),
('6', '3', '2022-8-1', '15', 'pcs', '19.99', 'N/A'),
('7', '3', '2022-8-1', '30', 'pcs', '7.99', 'N/A'),
('8', '3', '2022-8-1', '50', 'pcs', '6.99', 'N/A'),
('9', '1', '2022-8-1', '20', 'pcs', '4.99', 'N/A'),
('1', '2', '2022-9-1', '30', 'pcs', '4.99', 'N/A'),
('2', '2', '2022-9-1', '40', 'pcs', '3.99', 'N/A'),
('3', '1', '2022-9-1', '30', 'pcs', '3.49', 'N/A'),
('4', '1', '2022-9-1', '60', 'pcs', '1.49', 'N/A'),
('5', '3', '2022-9-1', '10', 'pcs', '24.99', 'N/A'),
('6', '3', '2022-9-1', '15', 'pcs', '19.99', 'N/A'),
('7', '3', '2022-9-1', '30', 'pcs', '7.99', 'N/A'),
('8', '3', '2022-9-1', '50', 'pcs', '6.99', 'N/A'),
('9', '1', '2022-9-1', '20', 'pcs', '4.99', 'N/A'),
('1', '2', '2022-10-1', '30', 'pcs', '4.99', 'N/A'),
('2', '2', '2022-10-2', '40', 'pcs', '3.99', 'N/A'),
('3', '1', '2022-10-3', '30', 'pcs', '3.49', 'N/A'),
('4', '1', '2022-10-2', '60', 'pcs', '1.49', 'N/A'),
('5', '3', '2022-10-4', '10', 'pcs', '24.99', 'N/A'),
('6', '3', '2022-10-2', '15', 'pcs', '19.99', 'N/A'),
('7', '3', '2022-10-4', '30', 'pcs', '7.99', 'N/A'),
('8', '3', '2022-10-2', '50', 'pcs', '6.99', 'N/A'),
('9', '1', '2022-10-3', '20', 'pcs', '4.99', 'N/A'),
('1', '2', '2022-11-1', '30', 'pcs', '4.99', 'N/A'),
('2', '2', '2022-11-2', '40', 'pcs', '3.99', 'N/A'),
('3', '1', '2022-11-3', '30', 'pcs', '3.49', 'N/A'),
('4', '1', '2022-11-2', '60', 'pcs', '1.49', 'N/A'),
('5', '3', '2022-11-3', '10', 'pcs', '24.99', 'N/A'),
('6', '3', '2022-11-2', '15', 'pcs', '19.99', 'N/A'),
('7', '3', '2022-11-1', '30', 'pcs', '7.99', 'N/A'),
('8', '3', '2022-11-2', '50', 'pcs', '6.99', 'N/A'),
('9', '1', '2022-11-3', '20', 'pcs', '4.99', 'N/A');