-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestore.sql
1878 lines (1654 loc) · 58.2 KB
/
restore.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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- phpMyAdmin SQL Dump
-- version 5.1.1
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3307
-- Generation Time: Nov 27, 2021 at 11:02 AM
-- Server version: 10.5.11-MariaDB-1:10.5.11+maria~focal
-- PHP Version: 8.0.12
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: `db_JDMC`
--
CREATE DATABASE IF NOT EXISTS `db_JMDC` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
USE `db_JMDC`;
DELIMITER $$
--
-- Procedures
--
DROP PROCEDURE IF EXISTS `usp_AddAccount`$$
CREATE PROCEDURE `usp_AddAccount` (`employee_no` VARCHAR(20), `first_name` VARCHAR(50), `middle_name` VARCHAR(50), `last_name` VARCHAR(50), `suffix` VARCHAR(10), `contact_number` VARCHAR(15), `email_address` VARCHAR(100), `profile_id` INT, `affiliate_level_id` INT, `username` VARCHAR(30), `your_password` VARCHAR(150), `is_active` BIT) BEGIN
DECLARE exist int default 0;
IF employee_no is not NULL OR employee_no !='None'
then
SELECT COUNT(*) INTO exist
FROM tbl_UserInformation
WHERE (fld_Username=username
OR (fld_EmployeeNo=employee_no AND ( fld_EmployeeNo is not NULL OR fld_EmployeeNo !='None'))
OR fld_EmailAddress=email_address
)
AND fld_IsDeleted=false;
else
SELECT COUNT(*) INTO exist
FROM tbl_UserInformation
WHERE (fld_Username=username OR fld_Emailaddress =email_address)
AND fld_IsDeleted=false;
end if;
IF exist = 0
THEN
INSERT INTO tbl_UserInformation
(
fld_EmployeeNo,
fld_FirstName,
fld_MiddleName,
fld_LastName,
fld_Suffix,
fld_ContactNumber,
fld_EmailAddress,
fld_ProfileID,
fld_AffiliateLevelID,
fld_Username,
fld_Password,
fld_DateRegistered,
fld_IsDeleted,
fld_IsActivated,
fld_IstemporaryPassword,
fld_IsActive
)
VALUES
(
employee_no,
first_name,
middle_name,
last_name,
suffix,
contact_number,
email_address,
profile_id,
affiliate_level_id,
username,
your_password,
current_timestamp(),
false,
false,
true,
is_active
);
ELSE
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Account is existing';
END IF;
END$$
DROP PROCEDURE IF EXISTS `usp_AddAppointment`$$
CREATE PROCEDURE `usp_AddAppointment` (`patient_name` VARCHAR(150), `patient_contact_no` VARCHAR(15), `email_address` VARCHAR(60), `branch_code` VARCHAR(5), `branch_name` VARCHAR(60), `appointment_date` DATETIME, `start_timeslot` INT, `end_timeslot` INT, `appointby` VARCHAR(30), `reference_code` VARCHAR(30)) BEGIN
DECLARE exist int default 0;
DECLARE insert_id bigint default 0;
SELECT COUNT(*) INTO exist
FROM tbl_Appointment
WHERE fld_DateOfAppointment = appointment_date
AND (
( start_timeslot <= fld_StartTimeSlot AND end_timeslot >= fld_EndTimeSlot)
OR (start_timeslot >= fld_StartTimeSlot AND end_timeSlot <= fld_EndTimeSlot)
)
AND (fld_IsCancelled = 0 OR fld_IsCancelled IS NULL)
ANd fld_IsDeleted=0
AND fld_BranchCode = branch_code
AND fld_AppointBy = appointby;
if exist = 0
then
INSERT INTO tbl_Appointment
(
fld_PatientName,
fld_PatientContactNumber,
fld_EmailAddress,
fld_BranchCode,
fld_BranchName,
fld_DateOfAppointment,
fld_StartTimeSlot,
fld_EndTimeSlot,
fld_AppointBy,
fld_IsDeleted
)
VALUES
(
patient_name,
patient_contact_no,
email_address,
branch_code,
branch_name,
appointment_date,
start_timeslot,
end_timeslot,
appointby,
0
);
SELECT LAST_INSERT_ID() INTO insert_id;
if insert_id > 0
then
call usp_InsertAppointmentReference(reference_code,insert_id);
end if;
ELSE
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Slot is not available';
END IF;
END$$
DROP PROCEDURE IF EXISTS `usp_AddPromotion`$$
CREATE PROCEDURE `usp_AddPromotion` (`file_type` VARCHAR(10), `file_content_type` VARCHAR(60), `file_name` VARCHAR(100), `file_size` INT, `file_content` LONGBLOB, `created_by` VARCHAR(30), `image_id` VARCHAR(30), `promotion_description` LONGTEXT, `promotion_status` VARCHAR(10), `promotion_name` VARCHAR(60)) BEGIN
DECLARE exist int default 0;
SELECT COUNT(*) INTO exist
FROM tbl_Promotions
WHERE (fld_ImageId = image_id OR fld_PromotionName = promotion_name)
AND fld_IsDeleted =0;
IF exist = 0
THEN
CALL usp_InsertFile(
file_type,
file_content_type,
file_name,
file_size,
file_content,
created_by,
@image_id
);
IF @image_id > 0
THEN
INSERT INTO tbl_Promotions
(
fld_PromotionName,
fld_ImageId,
fld_Description,
fld_Status,
fld_FileId,
fld_DateCreated,
fld_CreatedBy,
fld_IsDeleted
)
VALUES
(
promotion_name,
image_id,
promotion_description,
promotion_status,
@image_id,
current_timestamp(),
created_by,
0
);
ELSE
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Cannot upload the image';
END IF;
ELSE
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Promotion already exist';
END IF;
END$$
DROP PROCEDURE IF EXISTS `usp_AddTutorial`$$
CREATE PROCEDURE `usp_AddTutorial` (`youtube_id` VARCHAR(50), `youtube_title` VARCHAR(150), `youtube_link` VARCHAR(100), `youtube_description` LONGTEXT, `created_by` VARCHAR(30)) BEGIN
DECLARE exist INT default 0;
SELECT COUNT(*) INTO exist
FROM tbl_Tutorials
WHERE ( fld_YoutubeId= youtube_id
OR fld_YoutubeTitle = youtube_title
OR fld_YoutubeLink = youtube_link )
AND fld_IsDeleted =0;
if exist = 0
THEN
INSERT INTO tbl_Tutorials
(
fld_YoutubeId,
fld_YoutubeTitle,
fld_YoutubeLink,
fld_YoutubeDescription,
fld_CreatedBy,
fld_DateCreated,
fld_IsDeleted
)
VALUES
(
youtube_id,
youtube_title,
youtube_link,
youtube_description,
created_by,
current_timestamp(),
0
);
else
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='This tutorial was already exist';
END IF;
END$$
DROP PROCEDURE IF EXISTS `usp_CancelAppointment`$$
CREATE PROCEDURE `usp_CancelAppointment` (`reference_code` VARCHAR(30), `cancelled_by` VARCHAR(30)) BEGIN
DECLARE appointment_id BIGINT default 0;
DECLARE message varchar(150) default null;
SELECT fld_AppointmentId INTO appointment_id
FROM tbl_AppointmentReference
WHERE fld_ReferenceCode=reference_code
AND fld_IsDeleted=0;
if appointment_id > 0
then
UPDATE tbl_Appointment
SET fld_IsCancelled=1,
fld_DateCancelled=current_timestamp(),
fld_CancelledBy= cancelled_by
WHERE fld_AppointmentId = appointment_id;
else
SET message=CONCAT('Reference code: ',reference_code,' is not exist');
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = message;
end if;
END$$
DROP PROCEDURE IF EXISTS `usp_ChangePassword`$$
CREATE PROCEDURE `usp_ChangePassword` (`new_password` VARCHAR(150), `current_password` VARCHAR(150), `username` VARCHAR(30)) BEGIN
DECLARE exist int default 0;
SELECT COUNT(*) INTO exist
FROM tbl_UserInformation
WHERE fld_Username=username
AND fld_Password=current_password
AND fld_IsDeleted=false;
IF exist > 0
THEN
UPDATE tbl_UserInformation
SET fld_Password=new_password,
fld_DateUpdated=current_timestamp(),
fld_IsTemporaryPassword=false
WHERE fld_Username=username
AND fld_IsDeleted=false;
else
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Account does not exist, or the current password is invalid';
END IF;
END$$
DROP PROCEDURE IF EXISTS `usp_DeleteFile`$$
CREATE PROCEDURE `usp_DeleteFile` (`file_id` BIGINT, `deleted_by` VARCHAR(30)) BEGIN
UPDATE tbl_FileStore
SET fld_IsDeleted =1,
fld_DateDeleted= current_timestamp(),
fld_DeletedBy =deleted_by
WHERE fld_FileId= file_id;
END$$
DROP PROCEDURE IF EXISTS `usp_DeletePromotion`$$
CREATE PROCEDURE `usp_DeletePromotion` (IN `promotion_id` BIGINT, `deleted_by` VARCHAR(30)) BEGIN
DECLARE image_id BIGINT default 0;
SELECT fld_FileId INTO image_id
FROM tbl_Promotions
WHERE fld_PromotionId = promotion_id
AND fld_IsDeleted =0;
IF image_id > 0
THEN
CALL usp_DeleteFile(
image_id,
deleted_by
);
END IF;
UPDATE tbl_Promotions
SET fld_IsDeleted=1
, fld_DateDeleted = current_timestamp()
, fld_DeletedBy = deleted_by
WHERE fld_PromotionId = promotion_id;
END$$
DROP PROCEDURE IF EXISTS `usp_DeleteTutorial`$$
CREATE PROCEDURE `usp_DeleteTutorial` (`video_id` BIGINT, `deleted_by` VARCHAR(30)) BEGIN
UPDATE tbl_Tutorials
SET fld_DeletedBy = deleted_by
, fld_DateDeleted =current_timestamp()
, fld_IsDeleted =1
WHERE fld_TutorialId = video_id;
END$$
DROP PROCEDURE IF EXISTS `usp_DeletProduct`$$
CREATE PROCEDURE `usp_DeletProduct` (IN `service_id` BIGINT, `deleted_by` VARCHAR(30)) BEGIN
DECLARE image_id BIGINT default 0;
SELECT fld_ProductImageId INTO image_id
FROM tbl_Service
WHERE fld_ServiceId = service_id
AND fld_IsDeleted =0;
IF image_id > 0
THEN
CALL usp_DeleteFile(
image_id,
deleted_by
);
END IF;
UPDATE tbl_Service
SET fld_IsDeleted=1
, fld_DateDeleted = current_timestamp()
, fld_DeletedBy = deleted_by
WHERE fld_ServiceId = service_id;
END$$
DROP PROCEDURE IF EXISTS `usp_ForgotPasswordChange`$$
CREATE PROCEDURE `usp_ForgotPasswordChange` (IN `email_address` VARCHAR(100), `reset_key` VARCHAR(100), `new_password` VARCHAR(150)) BEGIN
DECLARE uid bigint default 0;
SELECT fld_ID INTO uid
FROM tbl_UserInformation
WHERE fld_EmailAddress= email_address
AND fld_IsDeleted=false LIMIT 1;
if uid > 0
then
UPDATE tbl_UserInformation
SET fld_Password=new_password,
fld_IsTemporaryPassword=false,
fld_DateUpdated=current_timestamp()
WHERE fld_EmailAddress=email_address
AND fld_IsDeleted=false;
UPDATE tbl_PasswordReset
SET fld_IsAlreadyUsed=true
WHERE fld_ResetKey=reset_key
AND fld_Uid=uid;
else
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Account does not exist';
end if;
END$$
DROP PROCEDURE IF EXISTS `usp_GetActiveResetKey`$$
CREATE PROCEDURE `usp_GetActiveResetKey` (`email_address` VARCHAR(100)) BEGIN
DECLARE uid bigint default 0;
DECLARE username varchar(30) default null;
SELECT fld_ID,fld_Username INTO uid,username
FROM tbl_UserInformation
WHERE fld_EmailAddress= email_address
AND fld_IsDeleted=false LIMIT 1;
if uid > 0
then
SELECT ufn_NotExpiredKey(uid) AS 'reset_key',
username as 'username'
;
else
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Account does not exist';
end if;
END$$
DROP PROCEDURE IF EXISTS `usp_GetAllReferenceCode`$$
CREATE PROCEDURE `usp_GetAllReferenceCode` () BEGIN
SELECT fld_ReferenceId 'reference_id',
fld_ReferenceCode 'reference_code',
fld_AppointmentId 'appointment_id',
fld_DateCreated 'date_created',
fld_DateUsed 'date_used',
fld_IsUsed 'is_used'
FROM tbl_AppointmentReference
WHERE fld_IsDeleted=0;
END$$
DROP PROCEDURE IF EXISTS `usp_GetAppointmentByDate`$$
CREATE PROCEDURE `usp_GetAppointmentByDate` (`lookup_date` DATETIME, `appoint_by` VARCHAR(30), `branch_code` VARCHAR(5)) BEGIN
SELECT tbl_Appointment.fld_AppointmentId 'appointment_id',
tbl_AppointmentReference.fld_ReferenceCode 'reference_code',
tbl_Appointment.fld_PatientName 'patient_name',
tbl_Appointment.fld_PatientContactNumber 'patient_contact_no',
tbl_Appointment.fld_EmailAddress 'email_address',
tbl_Appointment.fld_BranchCode 'branch_code',
tbl_Appointment.fld_BranchName 'branch_name',
tbl_Appointment.fld_DateOfAppointment 'appointment_date',
tbl_Appointment.fld_StartTimeSlot 'start_timeslot',
tbl_Appointment.fld_EndTimeSlot 'end_timeslot',
tbl_Appointment.fld_AppointBy 'appoint_by',
tbl_Appointment.fld_DateCancelled 'cancelled_date',
tbl_Appointment.fld_CancelledBy 'cancelled_by',
tbl_Appointment.fld_IsCancelled 'is_cancelled'
FROM tbl_Appointment
LEFT JOIN tbl_AppointmentReference
ON tbl_AppointmentReference.fld_AppointmentId = tbl_Appointment.fld_appointmentId
WHERE tbl_Appointment.fld_DateOfAppointment = lookup_date
AND tbl_Appointment.fld_IsCancelled = false AND tbl_Appointment.fld_IsDeleted=false
AND tbl_Appointment.fld_BranchCode=branch_code
ANd tbl_Appointment.fld_AppointBy=appoint_by;
END$$
DROP PROCEDURE IF EXISTS `usp_GetAppointmentByRange`$$
CREATE PROCEDURE `usp_GetAppointmentByRange` (`from_range` DATETIME, `to_range` DATETIME, `branch_code` VARCHAR(5), `appoint_by` VARCHAR(30)) BEGIN
SELECT A.fld_AppointmentId 'appointment_id',
A.fld_PatientName 'patient_name',
A.fld_PatientContactNumber 'patient_contact_no',
A.fld_EmailAddress 'email_address',
A.fld_BranchCode 'branch_code',
A.fld_BranchName 'branch_name',
A.fld_DateOfAppointment 'appointment_date',
A.fld_StartTimeSlot 'start_timeslot',
A.fld_EndTimeSlot 'end_timeslot',
A.fld_AppointBy 'appoint_by',
A.fld_DateCancelled 'cancelled_date',
A.fld_CancelledBy 'cancelled_by',
A.fld_IsCancelled 'is_cancelled',
B.fld_ReferenceCode 'reference_code'
FROM tbl_Appointment as A
LEFT JOIN tbl_AppointmentReference as B
ON A.fld_AppointmentId=B.fld_AppointmentId
WHERE A.fld_DateOfAppointment >= from_range
AND A.fld_DateOfAppointment <=to_range
#AND A.fld_AppointBy= appoint_by
AND A.fld_BranchCode= branch_code
AND A.fld_IsDeleted=false;
END$$
DROP PROCEDURE IF EXISTS `usp_GetAppointmentInfo`$$
CREATE PROCEDURE `usp_GetAppointmentInfo` (`appointment_id` BIGINT) BEGIN
SELECT fld_AppointmentId 'appointment_id',
fld_PatientName 'patient_name' ,
fld_PatientContactNumber 'patient_contact_no',
fld_EmailAddress 'email_address',
fld_BranchCode 'branch_code',
fld_BranchName 'branch_name',
fld_DateOfAppointment 'appointment_date',
fld_StartTimeSlot 'start_timeslot',
fld_EndTimeSlot 'end_timeslot',
fld_AppointBy 'appoint_by'
FROM tbl_Appointment
WHERE fld_IsDeleted=0
AND fld_AppointmentId= appointment_id
;
END$$
DROP PROCEDURE IF EXISTS `usp_GetAppointmentList`$$
CREATE PROCEDURE `usp_GetAppointmentList` () BEGIN
SELECT fld_AppointmentId 'appointment_id',
fld_PatientName 'patient_name' ,
fld_PatientContactNumber 'patient_contact_no',
fld_EmailAddress 'email_address',
fld_BranchCode 'branch_code',
fld_BranchName 'branch_name',
fld_DateOfAppointment 'appointment_date',
fld_StartTimeSlot 'start_timeslot',
fld_EndTimeSlot 'end_timeslot',
fld_AppointBy 'appoint_by'
FROM tbl_Appointment
WHERE fld_IsDeleted=0;
END$$
DROP PROCEDURE IF EXISTS `usp_GetAppointmentListBy`$$
CREATE PROCEDURE `usp_GetAppointmentListBy` (`username` VARCHAR(30), `branch_code` VARCHAR(30)) BEGIN
SELECT appointment.fld_AppointmentId 'appointment_id',
appointment.fld_PatientName 'patient_name' ,
appointment.fld_PatientContactNumber 'patient_contact_no',
appointment.fld_EmailAddress 'email_address',
appointment.fld_BranchCode 'branch_code',
appointment. fld_BranchName 'branch_name',
appointment. fld_DateOfAppointment 'appointment_date',
appointment. fld_StartTimeSlot 'start_timeslot',
appointment. fld_EndTimeSlot 'end_timeslot',
appointment. fld_AppointBy 'appoint_by',
appointment. fld_IsCancelled 'is_cancelled',
appointment. fld_DateCancelled 'cancelled_date',
appointment. fld_CancelledBy 'cancelled_by',
appointment_reference.fld_ReferenceCode 'reference_code'
FROM tbl_Appointment as appointment
LEFT JOIN tbl_AppointmentReference as appointment_reference
ON appointment_reference.fld_AppointmentId=appointment.fld_AppointmentId
WHERE appointment.fld_IsDeleted=0
AND ( (branch_code is not NULL AND appointment.fld_BranchCode=branch_code)
OR (branch_code is NULL) )
AND appointment.fld_AppointBy=username
;
END$$
DROP PROCEDURE IF EXISTS `usp_GetBranchList`$$
CREATE PROCEDURE `usp_GetBranchList` () BEGIN
SELECT
fld_BranchId 'branch_id',
fld_BranchCode 'branch_code',
fld_BranchName 'branch_name',
fld_BranchAddress 'branch_address',
fld_OpenTime 'open_time',
fld_CloseTime 'close_time',
fld_DateCreated 'date_created'
FROM tbl_Branch
WHERE fld_IsActive=true;
END$$
DROP PROCEDURE IF EXISTS `usp_GetClassification`$$
CREATE PROCEDURE `usp_GetClassification` () BEGIN
SELECT fld_ClassId 'class_id',
fld_ClassCode 'class_code',
fld_ClassName 'class_name'
FROM tbl_ProductClass
WHERE fld_IsActive=true;
END$$
DROP PROCEDURE IF EXISTS `usp_GetFileData`$$
CREATE PROCEDURE `usp_GetFileData` (`file_id` BIGINT) BEGIN
SELECT fld_FileId 'file_id',
fld_FileType 'file_type',
fld_FileContentType 'file_content_type',
fld_FileName 'file_name',
fld_FileSize 'file_size'
FROM tbl_FileStore
WHERE fld_FileId= file_id
AND fld_IsDeleted=0;
END$$
DROP PROCEDURE IF EXISTS `usp_GetInformationByUsername`$$
CREATE PROCEDURE `usp_GetInformationByUsername` (`username` VARCHAR(30)) BEGIN
DECLARE exist int default 0;
SELECT COUNT(*) INTO exist
FROM tbl_UserInformation
WHERE fld_Username=username
AND fld_IsDeleted=false;
if exist > 0
then
SELECT fld_EmployeeNo AS employee_no,
fld_FirstName AS first_name,
fld_MiddleName as middle_name,
fld_LastName as last_name,
fld_Suffix as suffix,
fld_ContactNumber as contact_number,
fld_EmailAddress as email_address,
fld_AffiliateLevelID as affiliate_level_id,
fld_Username as 'username',
fld_DateRegistered as date_registered,
fld_ProfileID as profile_id,
fld_IsActivated as is_activated,
fld_DateRegistered as date_registered,
fld_IsTemporaryPassword as is_temporary_password,
fld_IsActive as is_active
FROM tbl_UserInformation
WHERE fld_Username=username
AND fld_IsDeleted = false;
else
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Username does not exist';
end if;
END$$
DROP PROCEDURE IF EXISTS `usp_GetLoginInformation`$$
CREATE PROCEDURE `usp_GetLoginInformation` (`username` VARCHAR(30), `password` VARCHAR(150)) BEGIN
SELECT fld_EmployeeNo AS employee_no,
fld_FirstName AS first_name,
fld_MiddleName AS middle_name,
fld_LastName AS last_name,
fld_Suffix AS suffix,
fld_ContactNumber AS contact_number,
fld_EmailAddress AS email_address,
fld_ProfileID AS profile_id,
fld_AffiliateLevelID AS affiliate_level_id,
fld_DateRegistered AS date_registered,
fld_IsActivated AS is_activated,
fld_IsTemporaryPassword AS is_temporary_password,
fld_Username AS 'username',
fld_IsActive AS is_active
FROM tbl_UserInformation
WHERE fld_Username=username AND fld_Password = password
AND fld_IsDeleted=false
;
END$$
DROP PROCEDURE IF EXISTS `usp_GetProductById`$$
CREATE PROCEDURE `usp_GetProductById` (`product_id` BIGINT) BEGIN
SELECT service.fld_ServiceId 'service_id',
service.fld_ProductCode 'product_code',
service.fld_ProductName 'product_name',
service.fld_ClassId 'class_id',
classification.fld_ClassCode 'class_code',
classification.fld_ClassName 'class_name',
service.fld_ProductDescription 'product_description',
service.fld_ProductImageId 'image_id',
filestore.fld_FileType 'file_type',
filestore.fld_FileName 'file_name',
filestore.fld_FileSize 'file_size',
filestore.fld_FileContentType 'file_content_type',
filestore.fld_FileContent 'file_content'
FROM tbl_Service as service
LEFT JOIN tbl_ProductClass as classification
ON classification.fld_ClassId=service.fld_ClassId
LEFT JOIN tbl_FileStore as filestore
ON filestore.fld_FileId= service.fld_ProductImageId
WHERE service.fld_IsDeleted=0
AND service.fld_ServiceId= product_id
AND classification.fld_IsActive=1
AND filestore.fld_IsDeleted=0;
END$$
DROP PROCEDURE IF EXISTS `usp_GetProductByProductCode`$$
CREATE PROCEDURE `usp_GetProductByProductCode` (`product_code` VARCHAR(30)) BEGIN
SELECT service.fld_ServiceId 'service_id',
service.fld_ProductCode 'product_code',
service.fld_ProductName 'product_name',
service.fld_ClassId 'class_id',
classification.fld_ClassCode 'class_code',
classification.fld_ClassName 'class_name',
service.fld_ProductDescription 'product_description',
service.fld_ProductImageId 'image_id',
filestore.fld_FileType 'file_type',
filestore.fld_FileName 'file_name',
filestore.fld_FileSize 'file_size',
filestore.fld_FileContentType 'file_content_type',
filestore.fld_FileContent 'file_content'
FROM tbl_Service as service
LEFT JOIN tbl_ProductClass as classification
ON classification.fld_ClassId=service.fld_ClassId
LEFT JOIN tbl_FileStore as filestore
ON filestore.fld_FileId= service.fld_ProductImageId
WHERE service.fld_IsDeleted=0
AND service.fld_ProductCode=product_code
AND classification.fld_IsActive=1
AND filestore.fld_IsDeleted=0;
END$$
DROP PROCEDURE IF EXISTS `usp_GetProductList`$$
CREATE PROCEDURE `usp_GetProductList` () BEGIN
SELECT service.fld_ServiceId 'service_id',
service.fld_ProductCode 'product_code',
service.fld_ProductName 'product_name',
service.fld_ClassId 'class_id',
classification.fld_ClassCode 'class_code',
classification.fld_ClassName 'class_name',
service.fld_ProductDescription 'product_description',
service.fld_ProductImageId 'image_id',
filestore.fld_FileType 'file_type',
filestore.fld_FileName 'file_name',
filestore.fld_FileSize 'file_size',
filestore.fld_FileContentType 'file_content_type',
filestore.fld_FileContent 'file_content'
FROM tbl_Service as service
LEFT JOIN tbl_ProductClass as classification
ON classification.fld_ClassId=service.fld_ClassId
LEFT JOIN tbl_FileStore as filestore
ON filestore.fld_FileId= service.fld_ProductImageId
WHERE service.fld_IsDeleted=0
AND classification.fld_IsActive=1
AND filestore.fld_IsDeleted=0;
END$$
DROP PROCEDURE IF EXISTS `usp_GetPromotionById`$$
CREATE PROCEDURE `usp_GetPromotionById` (`promotion_id` BIGINT) BEGIN
SELECT promo.fld_PromotionId 'promotion_id',
promo.fld_ImageId 'image_id',
promo.fld_Description 'description',
promo.fld_Status 'status',
promo.fld_FileId 'file_id',
promo.fld_PromotionName 'promotion_name',
filestore.fld_FileType 'file_type',
filestore.fld_FileName 'file_name',
filestore.fld_FileSize 'file_size',
filestore.fld_FileContentType 'file_content_type',
filestore.fld_FileContent 'file_content'
FROM tbl_Promotions as promo
LEFT JOIN tbl_FileStore as filestore
ON filestore.fld_FileId= promo.fld_FileId
WHERE promo.fld_IsDeleted=0
AND promo.fld_PromotionId= promotion_id
AND filestore.fld_IsDeleted=0;
END$$
DROP PROCEDURE IF EXISTS `usp_GetPromotionByImageId`$$
CREATE PROCEDURE `usp_GetPromotionByImageId` (`image_id` VARCHAR(60)) BEGIN
SELECT promo.fld_PromotionId 'promotion_id',
promo.fld_ImageId 'image_id',
promo.fld_Description 'description',
promo.fld_Status 'status',
promo.fld_FileId 'file_id',
promo.fld_PromotionName 'promotion_name',
filestore.fld_FileType 'file_type',
filestore.fld_FileName 'file_name',
filestore.fld_FileSize 'file_size',
filestore.fld_FileContentType 'file_content_type',
filestore.fld_FileContent 'file_content'
FROM tbl_Promotions as promo
LEFT JOIN tbl_FileStore as filestore
ON filestore.fld_FileId= promo.fld_FileId
WHERE promo.fld_IsDeleted= 0
AND promo.fld_ImageId = image_id;
END$$
DROP PROCEDURE IF EXISTS `usp_GetPromotionList`$$
CREATE PROCEDURE `usp_GetPromotionList` () BEGIN
SELECT promo.fld_PromotionId 'promotion_id',
promo.fld_ImageId 'image_id',
promo.fld_Description 'description',
promo.fld_PromotionName 'promotion_name',
promo.fld_Status 'status',
promo.fld_FileId 'file_id',
filestore.fld_FileType 'file_type',
filestore.fld_FileName 'file_name',
filestore.fld_FileSize 'file_size',
filestore.fld_FileContentType 'file_content_type',
filestore.fld_FileContent 'file_content'
FROM tbl_Promotions as promo
LEFT JOIN tbl_FileStore as filestore
ON filestore.fld_FileId= promo.fld_FileId
WHERE promo.fld_IsDeleted=0
AND filestore.fld_IsDeleted=0;
END$$
DROP PROCEDURE IF EXISTS `usp_GetReferenceCode`$$
CREATE PROCEDURE `usp_GetReferenceCode` (IN `appointment_id` BIGINT) BEGIN
SELECT fld_ReferenceId 'reference_id',
fld_ReferenceCode 'reference_code',
fld_AppointmentId 'appointment_id',
fld_DateCreated 'date_created',
fld_DateUsed 'date_used',
fld_IsUsed 'is_used'
FROM tbl_AppointmentReference
WHERE fld_IsDeleted=0
AND fld_AppointmentId=appointment_id;
END$$
DROP PROCEDURE IF EXISTS `usp_GetTutorialById`$$
CREATE PROCEDURE `usp_GetTutorialById` (`tutorial_id` BIGINT) BEGIN
SELECT fld_TutorialId 'tutorial_id',
fld_YoutubeId 'youtube_id',
fld_YoutubeTitle 'youtube_title',
fld_YoutubeDescription 'youtube_description'
FROM tbl_Tutorials
WHERE fld_IsDeleted=0
AND fld_TutorialId = tutorial_id;
END$$
DROP PROCEDURE IF EXISTS `usp_GetTutorialByYoutubeId`$$
CREATE PROCEDURE `usp_GetTutorialByYoutubeId` (`youtube_id` VARCHAR(100)) BEGIN
SELECT fld_TutorialId 'video_id',
fld_YoutubeId 'youtube_id',
fld_YoutubeTitle 'video_title',
fld_YoutubeLink 'youtube_link',
fld_YoutubeDescription 'video_description'
FROM tbl_Tutorials
WHERE fld_YoutubeId=youtube_id
ANd fld_IsDeleted =0;
END$$
DROP PROCEDURE IF EXISTS `usp_GetTutorialList`$$
CREATE PROCEDURE `usp_GetTutorialList` () BEGIN
SELECT fld_TutorialId 'video_id',
fld_YoutubeId 'youtube_id',
fld_YoutubeTitle 'video_title',
fld_YoutubeLink 'youtube_link',
fld_YoutubeDescription 'video_description'
FROM tbl_Tutorials
WHERE fld_IsDeleted= 0;
END$$
DROP PROCEDURE IF EXISTS `usp_GetUserInformation`$$
CREATE PROCEDURE `usp_GetUserInformation` (`profile_id` INT, `affiliate_level` INT) BEGIN
IF affiliate_level = 0
THEN
SELECT fld_EmployeeNo AS employee_no,
fld_FirstName AS first_name,
fld_MiddleName as middle_name,
fld_LastName as last_name,
fld_Suffix as suffix,
fld_ContactNumber as contact_number,
fld_EmailAddress as email_address,
fld_AffiliateLevelID as affiliate_level_id,
fld_Username as username,
fld_DateRegistered as date_registered,
fld_ProfileID as 'profile_id',
fld_IsActive as is_active
FROM tbl_UserInformation
WHERE fld_ProfileID = profile_id
AND fld_IsDeleted = false
;
ELSE
SELECT fld_EmployeeNo AS employee_no,
fld_FirstName AS first_name,
fld_MiddleName as middle_name,
fld_LastName as last_name,
fld_Suffix as suffix,
fld_ContactNumber as contact_number,
fld_EmailAddress as email_address,
fld_AffiliateLevelID as affiliate_level_id,
fld_Username as username,
fld_DateRegistered as date_registered,
fld_IsActivated as is_activated
FROM tbl_UserInformation
WHERE fld_ProfileID = profile_id
AND fld_AffiliateLevelID = affiliate_level
AND fld_IsDeleted = false;
END IF;
END$$
DROP PROCEDURE IF EXISTS `usp_InsertAppointmentReference`$$
CREATE PROCEDURE `usp_InsertAppointmentReference` (`reference_code` VARCHAR(30), `appointment_id` BIGINT) BEGIN
INSERT INTO tbl_AppointmentReference
(
fld_ReferenceCode,
fld_AppointmentId,
fld_DateCreated,
fld_IsUsed,
fld_IsDeleted
)
VALUES
(
reference_code,
appointment_id,
current_timestamp(),
0,
0
);
END$$
DROP PROCEDURE IF EXISTS `usp_InsertFile`$$
CREATE PROCEDURE `usp_InsertFile` (`file_type` VARCHAR(10), `file_content_type` VARCHAR(60), `file_name` VARCHAR(100), `file_size` INT, `file_content` LONGBLOB, `created_by` VARCHAR(30), OUT `image_id` BIGINT) BEGIN
INSERT INTO tbl_FileStore
(
fld_FileType,
fld_FileContentType,
fld_FileName,
fld_FileSize,
fld_FileContent,
fld_DateCreated,
fld_CreatedBy,
fld_IsDeleted
)
VALUES
(
file_type,
file_content_type,
file_name,
file_size,
UNHEX(file_content),
current_timestamp(),
created_by,
0
);
SELECT LAST_INSERT_ID() INTO image_id;
END$$
DROP PROCEDURE IF EXISTS `usp_InsertService`$$
CREATE PROCEDURE `usp_InsertService` (`file_type` VARCHAR(10), `file_content_type` VARCHAR(60), `file_name` VARCHAR(100), `file_size` INT, `file_content` LONGBLOB, `created_by` VARCHAR(30), `product_code` VARCHAR(30), `product_name` VARCHAR(150), `class_id` INT, `product_description` VARCHAR(8000)) BEGIN
DECLARE exist int default 0;
SELECT COUNT(*) INTO exist
FROM tbl_Service
WHERE (fld_ProductCode = product_code
OR fld_ProductName = product_name)
AND fld_IsDeleted =0;
IF exist = 0
THEN
CALL usp_InsertFile(
file_type,
file_content_type,
file_name,
file_size,
file_content,
created_by,
@image_id
);
IF @image_id > 0
THEN
INSERT INTO tbl_Service
(
fld_ProductCode,
fld_ProductName,
fld_ClassId,
fld_ProductDescription,
fld_ProductImageId,
fld_DateCreated,
fld_CreatedBy,
fld_IsDeleted
)
VALUES
(
product_code,
product_name,
class_id,
product_description,
@image_id,
current_timestamp(),
created_by,
0
);
ELSE
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Cannot upload the image';
END IF;
ELSE
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Product already exist';
END IF;
END$$
DROP PROCEDURE IF EXISTS `usp_IsValidResetKey`$$
CREATE PROCEDURE `usp_IsValidResetKey` (`email_address` VARCHAR(100), `reset_key` VARCHAR(100)) BEGIN
DECLARE uid bigint default 0;
DECLARE exist int default 0;
SELECT fld_ID INTO uid
FROM tbl_UserInformation
WHERE fld_EmailAddress= email_address
AND fld_IsDeleted=false LIMIT 1;
if uid > 0
then
SELECT COUNT(*) INTO exist
FROM tbl_PasswordReset
WHERE fld_EmailAddress=email_address
AND fld_ResetKey=reset_key
AND ((fld_ShouldExpire=false) OR (fld_ShouldExpire=true AND fld_DateExpiration > current_timestamp()))
AND fld_IsAlreadyUsed=false;
if exist > 0
then
SELECT true as 'is_valid';
else
SELECT false as 'is_valid';
end if;
else
SELECT false as 'is_valid';
end if;
END$$
DROP PROCEDURE IF EXISTS `usp_ReferenceCodeIsUsed`$$
CREATE PROCEDURE `usp_ReferenceCodeIsUsed` (`reference_code` VARCHAR(30)) BEGIN
DECLARE is_exist bit default 0;
SELECT (COUNT(*) > 0) INTO is_exist
FROM tbl_AppointmentReference
WHERE fld_ReferenceCode = reference_code
AND fld_IsDeleted=0;