-
Notifications
You must be signed in to change notification settings - Fork 2
/
storedProcedure_SuperAdmin.sql
87 lines (79 loc) · 2.29 KB
/
storedProcedure_SuperAdmin.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
--REPORTES DEL SUPER USUARIO
--REPORTE POR RECURSO
DELIMITER //
CREATE PROCEDURE ResourceTotal_super()
BEGIN
DECLARE curMonth INT;
DECLARE curYear INT;
SET curMonth = (select MONTH(NOW()));
SET curYear = (select YEAR(NOW()));
select resources.name,count(resources.id) as total
from resources,bookings
where bookings.resource_id = resources.id
AND MONTH(bookings.start_date) = curMonth
AND YEAR(bookings.start_date) = curYear
group by resources.name;
END //
DELIMITER ;
--REPORTE POR CATEGORIA
DELIMITER //
CREATE PROCEDURE CategoryTotal_super()
BEGIN
DECLARE curMonth INT;
DECLARE curYear INT;
SET curMonth = (select MONTH(NOW()));
SET curYear = (select YEAR(NOW()));
select categories.name,count(resources.id) as total
from resources,bookings, categories
where bookings.resource_id = resources.id
AND resources.category_id = categories.id
AND MONTH(bookings.start_date) = curMonth
AND YEAR(bookings.start_date) = curYear
group by categories.name;
END //
DELIMITER ;
--REPORTE POR USUARIO
DELIMITER //
CREATE PROCEDURE UserTotal_super()
BEGIN
DECLARE curMonth INT;
DECLARE curYear INT;
SET curMonth = (select MONTH(NOW()));
SET curYear = (select YEAR(NOW()));
select users.school_id, count(users.id) as total
from bookings, users
where bookings.user_id = users.school_id
AND MONTH(bookings.start_date) = curMonth
AND YEAR(bookings.start_date) = curYear
group by users.school_id;
END //
DELIMITER ;
-- Mes
DELIMITER //
CREATE PROCEDURE monthTotal_super()
BEGIN
DECLARE curYear INT;
SET curYear = (select YEAR(NOW()));
select MONTH(bookings.start_date) as month ,count(bookings.id) as total
from resources,bookings
where bookings.resource_id = resources.id
AND YEAR(bookings.start_date) = curYear
group by MONTH(bookings.start_date);
END //
DELIMITER ;
-- Dia
DELIMITER //
CREATE PROCEDURE DayTotal_super()
BEGIN
DECLARE curMonth INT;
DECLARE curYear INT;
SET curMonth = (select MONTH(NOW()));
SET curYear = (select YEAR(NOW()));
select DAYOFWEEK(bookings.start_date) as day ,count(bookings.id) as total
from resources,bookings
where bookings.resource_id = resources.id
AND MONTH(bookings.start_date) = curMonth
AND YEAR(bookings.start_date) = curYear
group by DAYOFWEEK(bookings.start_date);
END //
DELIMITER ;