-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sql
39 lines (35 loc) · 1.93 KB
/
script.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
-- CREATE STORE PROCEDURES FOR DASHBOARD GRAPHICS
DROP PROCEDURE IF EXISTS REPORT_CHART_STATUS_DOCUMENT;
DELIMITER //
CREATE PROCEDURE `REPORT_CHART_STATUS_DOCUMENT` (initDate varchar(10) , endDate varchar(10))
BEGIN
SELECT
DISTINCT( DATE_FORMAT( convert_tz(status.registerDate ,@@session.time_zone,'-05:00') ,"%Y-%m-%d")) AS 'date',
COUNT(CASE WHEN status.status = 'register' THEN 1 END) AS 'register',
COUNT(CASE WHEN status.status = 'processing' THEN 1 END) AS 'processing',
COUNT(CASE WHEN status.status = 'observed' THEN 1 END) AS 'observed',
COUNT(CASE WHEN status.status = 'finalized' THEN 1 END) AS 'finalized'
FROM status
WHERE DATE_FORMAT( convert_tz(status.registerDate ,@@session.time_zone,'-05:00') ,"%Y-%m-%d") BETWEEN initDate AND endDate
GROUP BY DATE_FORMAT( convert_tz(status.registerDate ,@@session.time_zone,'-05:00') ,"%Y-%m-%d");
END//
DELIMITER ;
DROP PROCEDURE IF EXISTS REPORT_CHART_STATUS_DOCUMENT_BY_ID_DOCUMENT;
DELIMITER //
CREATE PROCEDURE `REPORT_CHART_STATUS_DOCUMENT_BY_ID_DOCUMENT` (id varchar(12) ,initDate varchar(10) , endDate varchar(10))
BEGIN
SELECT
DISTINCT( DATE_FORMAT( convert_tz(status.registerDate ,@@session.time_zone,'-05:00') ,"%Y-%m-%d")) AS 'date',
COUNT(CASE WHEN status.status = 'register' THEN 1 END) AS 'register',
COUNT(CASE WHEN status.status = 'processing' THEN 1 END) AS 'processing',
COUNT(CASE WHEN status.status = 'observed' THEN 1 END) AS 'observed',
COUNT(CASE WHEN status.status = 'finalized' THEN 1 END) AS 'finalized'
FROM status
JOIN status_document
ON status.idStatusDocument = status_document.idStatusDocument
JOIN document
ON document.idDocument=status_document.idDocument
WHERE document.idDocument = id AND DATE_FORMAT( convert_tz(status.registerDate ,@@session.time_zone,'-05:00') ,"%Y-%m-%d") BETWEEN initDate AND endDate
GROUP BY DATE_FORMAT( convert_tz(status.registerDate ,@@session.time_zone,'-05:00') ,"%Y-%m-%d");
END//
DELIMITER ;