-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.sql
3017 lines (1924 loc) · 76.3 KB
/
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
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
--
-- PostgreSQL database dump
--
-- Dumped from database version 10.4
-- Dumped by pg_dump version 10.14
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'SQL_ASCII';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: compliance; Type: SCHEMA; Schema: -; Owner: postgres
--
CREATE SCHEMA compliance;
ALTER SCHEMA compliance OWNER TO postgres;
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
--
-- Name: add_mapping_user_employee(); Type: FUNCTION; Schema: compliance; Owner: postgres
--
CREATE FUNCTION compliance.add_mapping_user_employee() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
user_id integer;
exist integer;
BEGIN
SELECT 1 FROM compliance.wf_employee WHERE employee_id = NEW.id_employee_cc_to_slt INTO exist;
IF (exist is null AND NEW.id_employee_cc_to_slt IS NOT NULL) THEN
INSERT INTO compliance.wf_user(name, email, phone, created, modified)
VALUES(NEW.cc_to_slt, '-', '-', EXTRACT(EPOCH FROM CURRENT_TIMESTAMP), EXTRACT(EPOCH FROM CURRENT_TIMESTAMP))
RETURNING id INTO user_id;
INSERT INTO compliance.wf_employee VALUES (NEW.id_employee_cc_to_slt, user_id);
END IF;
-- IF NEW.last_name <> OLD.last_name THEN
-- INSERT INTO employee_audits(employee_id,last_name,changed_on)
-- VALUES(OLD.id,OLD.last_name,now());
-- END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION compliance.add_mapping_user_employee() OWNER TO postgres;
--
-- Name: add_mapping_user_employee_hod(); Type: FUNCTION; Schema: compliance; Owner: postgres
--
CREATE FUNCTION compliance.add_mapping_user_employee_hod() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
user_id integer;
exist integer;
BEGIN
SELECT 1 FROM compliance.wf_employee WHERE employee_id = NEW.id_employee_hod_gap INTO exist;
IF (exist is null) THEN
INSERT INTO compliance.wf_user(name, email, phone, created, modified)
VALUES(NEW.hod_gap, '-', '-', EXTRACT(EPOCH FROM CURRENT_TIMESTAMP), EXTRACT(EPOCH FROM CURRENT_TIMESTAMP))
RETURNING id INTO user_id;
INSERT INTO compliance.wf_employee VALUES (NEW.id_employee_hod_gap, user_id);
END IF;
-- IF NEW.last_name <> OLD.last_name THEN
-- INSERT INTO employee_audits(employee_id,last_name,changed_on)
-- VALUES(OLD.id,OLD.last_name,now());
-- END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION compliance.add_mapping_user_employee_hod() OWNER TO postgres;
--
-- Name: report_close_gap(); Type: FUNCTION; Schema: compliance; Owner: postgres
--
CREATE FUNCTION compliance.report_close_gap() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
yesterday timestamp without time zone;
today timestamp without time zone;
exist integer;
current_row integer;
BEGIN
SELECT now()::date INTO today;
SELECT
1
FROM
compliance.report_gap_new
WHERE
gap_date = today
INTO current_row;
IF(current_row IS NULL) THEN
INSERT INTO
compliance.report_gap_new
(gap_date, opening, open_gap, close_gap, closing)
SELECT today, closing, 0, 1, closing - 1 FROM compliance.report_gap_new ORDER BY id DESC LIMIT 1;
ELSE
UPDATE
compliance.report_gap_new
SET
close_gap = close_gap + 1,
closing = closing - 1
WHERE
gap_date = today;
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION compliance.report_close_gap() OWNER TO postgres;
--
-- Name: report_close_gap_summary(); Type: FUNCTION; Schema: compliance; Owner: postgres
--
CREATE FUNCTION compliance.report_close_gap_summary() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
current_month integer;
current_year integer;
exist integer;
current_row integer;
BEGIN
SELECT extract('month' from now()) INTO current_month;
SELECT extract('year' from now()) INTO current_year;
SELECT
1
FROM
compliance.report_gap
WHERE
year = current_year
AND
month = current_month
INTO current_row;
IF(current_row IS NULL) THEN
INSERT INTO
compliance.report_gap
(month, year, open_gap)
SELECT current_month, current_year, COALESCE(open_gap, 0) - 1 FROM compliance.report_gap ORDER BY id DESC LIMIT 1;
ELSE
UPDATE
compliance.report_gap
SET
open_gap = open_gap - 1
WHERE
year = current_year
AND
month = current_month;
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION compliance.report_close_gap_summary() OWNER TO postgres;
--
-- Name: report_open_gap(); Type: FUNCTION; Schema: compliance; Owner: postgres
--
CREATE FUNCTION compliance.report_open_gap() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
yesterday timestamp without time zone;
today timestamp without time zone;
exist integer;
current_row integer;
BEGIN
SELECT now()::date INTO today;
SELECT 1 FROM compliance.hod_gap_assessment WHERE approved_date IS NULL AND id_gap_assessment = NEW.id_gap_assessment
INTO exist;
IF(exist IS NULL) THEN
SELECT
1
FROM
compliance.report_gap_new
WHERE
gap_date = today
INTO current_row;
IF(current_row IS NULL) THEN
INSERT INTO
compliance.report_gap_new
(gap_date, opening, open_gap, close_gap, closing)
SELECT today, closing, 1, 0, closing + 1 FROM compliance.report_gap_new ORDER BY id DESC LIMIT 1;
-- VALUES(current_year, current_month, 1);
ELSE
UPDATE
compliance.report_gap_new
SET
open_gap = open_gap + 1,
closing = closing + 1
WHERE
gap_date = today;
END IF;
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION compliance.report_open_gap() OWNER TO postgres;
--
-- Name: report_open_gap_summary(); Type: FUNCTION; Schema: compliance; Owner: postgres
--
CREATE FUNCTION compliance.report_open_gap_summary() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
current_month integer;
current_year integer;
exist integer;
current_row integer;
BEGIN
SELECT extract('month' from now()) INTO current_month;
SELECT extract('year' from now()) INTO current_year;
SELECT 1 FROM compliance.hod_gap_assessment WHERE approved_date IS NULL AND id_gap_assessment = NEW.id_gap_assessment
INTO exist;
IF(exist IS NULL) THEN
SELECT
1
FROM
compliance.report_gap
WHERE
year = current_year
AND
month = current_month
INTO current_row;
IF(current_row IS NULL) THEN
INSERT INTO
compliance.report_gap
(month, year, open_gap)
SELECT current_month, current_year, COALESCE(open_gap, 0) + 1 FROM compliance.report_gap ORDER BY id DESC LIMIT 1;
ELSE
UPDATE
compliance.report_gap
SET
open_gap = open_gap + 1
WHERE
year = current_year
AND
month = current_month;
END IF;
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION compliance.report_open_gap_summary() OWNER TO postgres;
--
-- Name: sp_check_approval_1(bigint); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.sp_check_approval_1(in_workflow_id bigint) RETURNS refcursor
LANGUAGE plpgsql
AS $$
DECLARE
ref refcursor;
BEGIN
OPEN ref FOR SELECT true from wf_run_workflow where id = in_workflow_id;
RETURN ref;
END;
$$;
ALTER FUNCTION public.sp_check_approval_1(in_workflow_id bigint) OWNER TO postgres;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: action_plan; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.action_plan (
id_action_plan character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
id_gap_assessment character varying(255),
action_plan character varying,
initial_target_date timestamp without time zone,
reschedule_target_date timestamp without time zone,
regulation_timeline boolean,
action_owner character varying,
id_department_action_owner character varying,
waiting_implementation_regulation boolean,
revision boolean,
status character varying
);
ALTER TABLE compliance.action_plan OWNER TO postgres;
--
-- Name: approved_attestation; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.approved_attestation (
id_approved_attestation character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
id_attestation character varying(255),
id_employee_approved character varying,
approved_name character varying,
job_title_approved character varying,
approved_date timestamp without time zone,
send_to_type character varying,
id_employee_reassign character varying,
reassign_name character varying,
job_title_reasign character varying
);
ALTER TABLE compliance.approved_attestation OWNER TO postgres;
--
-- Name: article; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.article (
id_article character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
id_regulation character varying(255),
article text,
status_article character varying(255),
article_en text,
gap_identified character varying,
article_number character varying,
progress integer
);
ALTER TABLE compliance.article OWNER TO postgres;
--
-- Name: assign_to; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.assign_to (
id_assign_to character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
id_article character varying(255),
name character varying(255),
department character varying(255),
id_employee character varying,
id_department character varying,
existing_process character varying,
impact_risk_to_business character varying,
submitted boolean
);
ALTER TABLE compliance.assign_to OWNER TO postgres;
--
-- Name: attestation; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.attestation (
id_attestation character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
id_department character varying,
department_name character varying,
status integer,
num bigint
);
ALTER TABLE compliance.attestation OWNER TO postgres;
--
-- Name: comment; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.comment (
id_comment character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
detail_comment character varying(255),
staff_name character varying(255),
id_employee character varying,
id_regulation character varying(255),
id_article character varying(255),
id_department character varying,
department_name character varying
);
ALTER TABLE compliance.comment OWNER TO postgres;
--
-- Name: comment_attestation; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.comment_attestation (
id_comment_attestation character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
id_attestation character varying(255),
detail_comment_attestation character varying,
id_employee character varying,
staff_name character varying,
id_department character varying,
department_name character varying
);
ALTER TABLE compliance.comment_attestation OWNER TO postgres;
--
-- Name: department_related; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.department_related (
id_department_related character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
id_article character varying(255),
id_department character varying,
department_name character varying
);
ALTER TABLE compliance.department_related OWNER TO postgres;
--
-- Name: function_owner; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.function_owner (
id_function_owner character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
id_article character varying(255),
function_owner character varying(255),
id_department character varying
);
ALTER TABLE compliance.function_owner OWNER TO postgres;
--
-- Name: gap_assessment; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.gap_assessment (
id_gap_assessment character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
status character varying,
id_article character varying(255),
remark_closed character varying,
gap character varying,
instance_name character varying,
closed_gap_date timestamp without time zone,
closed_gap_by character varying,
progress integer
);
ALTER TABLE compliance.gap_assessment OWNER TO postgres;
--
-- Name: gap_evidence; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.gap_evidence (
id_gap_evidence character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
file_name character varying(255),
id_gap_assessment character varying(255),
path character varying,
id_department character varying
);
ALTER TABLE compliance.gap_evidence OWNER TO postgres;
--
-- Name: history; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.history (
id character varying NOT NULL,
unique_id character varying,
history_type character varying,
action character varying,
username character varying,
full_name character varying,
department_name character varying,
create_date timestamp without time zone,
data text
);
ALTER TABLE compliance.history OWNER TO postgres;
--
-- Name: COLUMN history.history_type; Type: COMMENT; Schema: compliance; Owner: postgres
--
COMMENT ON COLUMN compliance.history.history_type IS 'REGULATION / ARTICLE / GAP';
--
-- Name: COLUMN history.action; Type: COMMENT; Schema: compliance; Owner: postgres
--
COMMENT ON COLUMN compliance.history.action IS 'CREATE NEW / UPDATE';
--
-- Name: COLUMN history.data; Type: COMMENT; Schema: compliance; Owner: postgres
--
COMMENT ON COLUMN compliance.history.data IS 'json nya';
--
-- Name: hod_gap_assessment; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.hod_gap_assessment (
id_hod_gap_assessment character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
id_gap_assessment character varying(255),
hod_gap character varying,
id_employee_hod_gap character varying,
approved_date timestamp without time zone,
id_employee_reassign character varying,
reassign_name character varying,
reason_reassign character varying,
id_department character varying,
department_name character varying,
approved boolean,
send_to_type character varying,
approved_submitted boolean
);
ALTER TABLE compliance.hod_gap_assessment OWNER TO postgres;
--
-- Name: notification; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.notification (
id integer NOT NULL,
create_by character varying,
create_date timestamp without time zone,
update_by character varying,
update_date timestamp without time zone,
message text,
opened character(1),
user_id character varying,
event_code integer
);
ALTER TABLE compliance.notification OWNER TO postgres;
--
-- Name: notification_id_seq; Type: SEQUENCE; Schema: compliance; Owner: postgres
--
CREATE SEQUENCE compliance.notification_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE compliance.notification_id_seq OWNER TO postgres;
--
-- Name: notification_id_seq; Type: SEQUENCE OWNED BY; Schema: compliance; Owner: postgres
--
ALTER SEQUENCE compliance.notification_id_seq OWNED BY compliance.notification.id;
--
-- Name: regulation; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.regulation (
id_regulation character varying(255) NOT NULL,
regulation_number character varying(255),
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
regulation_title character varying(255),
brief_summary_of_requirement text,
status_regulation character varying(255),
regulation_type character varying,
issued_by character varying,
issuance_date timestamp without time zone,
progress integer,
id_attestation character varying(255),
implication_to_function character varying,
remarks character varying,
upload_regulation boolean
);
ALTER TABLE compliance.regulation OWNER TO postgres;
--
-- Name: report_gap; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.report_gap (
id integer NOT NULL,
year integer NOT NULL,
month integer NOT NULL,
open_gap integer
);
ALTER TABLE compliance.report_gap OWNER TO postgres;
--
-- Name: report_gap_id_seq; Type: SEQUENCE; Schema: compliance; Owner: postgres
--
CREATE SEQUENCE compliance.report_gap_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE compliance.report_gap_id_seq OWNER TO postgres;
--
-- Name: report_gap_id_seq; Type: SEQUENCE OWNED BY; Schema: compliance; Owner: postgres
--
ALTER SEQUENCE compliance.report_gap_id_seq OWNED BY compliance.report_gap.id;
--
-- Name: report_gap_new; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.report_gap_new (
id integer NOT NULL,
gap_date timestamp without time zone,
opening integer,
open_gap integer,
close_gap integer,
closing integer
);
ALTER TABLE compliance.report_gap_new OWNER TO postgres;
--
-- Name: report_gap_new_id_seq; Type: SEQUENCE; Schema: compliance; Owner: postgres
--
CREATE SEQUENCE compliance.report_gap_new_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE compliance.report_gap_new_id_seq OWNER TO postgres;
--
-- Name: report_gap_new_id_seq; Type: SEQUENCE OWNED BY; Schema: compliance; Owner: postgres
--
ALTER SEQUENCE compliance.report_gap_new_id_seq OWNED BY compliance.report_gap_new.id;
--
-- Name: sample_report; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.sample_report (
number integer NOT NULL,
open_date timestamp without time zone,
close_date timestamp without time zone
);
ALTER TABLE compliance.sample_report OWNER TO postgres;
--
-- Name: setting_status; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.setting_status (
id_setting_status character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
internal_timeline_from integer,
internal_timeline_to integer,
timeline_reschedule character varying(255),
timeline_regulator character varying(255),
status_action_gap character varying(255),
auto_reminder integer,
num bigint
);
ALTER TABLE compliance.setting_status OWNER TO postgres;
--
-- Name: status_of_action; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.status_of_action (
id_status_of_action character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
status_of_action character varying,
id_employee character varying,
id_action_plan character varying(255)
);
ALTER TABLE compliance.status_of_action OWNER TO postgres;
--
-- Name: supporting_document; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.supporting_document (
id_supporting_document character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
file_name character varying(255),
id_article character varying(255),
path character varying,
id_department character varying
);
ALTER TABLE compliance.supporting_document OWNER TO postgres;
--
-- Name: upload_regulation; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.upload_regulation (
id_upload_regulation character varying(255) NOT NULL,
create_by character varying(255),
create_date timestamp without time zone,
update_by character varying(255),
update_date timestamp without time zone,
file_name character varying(255),
id_regulation character varying(255),
path character varying
);
ALTER TABLE compliance.upload_regulation OWNER TO postgres;
--
-- Name: vw_open_gap; Type: VIEW; Schema: compliance; Owner: postgres
--
CREATE VIEW compliance.vw_open_gap AS
SELECT to_char(ga.create_date, 'yyyy-MM-dd'::text) AS label,
count(1) AS open_gap
FROM ((compliance.gap_assessment ga
JOIN ( SELECT hod_gap_assessment.id_gap_assessment,
count(1) AS approval
FROM compliance.hod_gap_assessment
GROUP BY hod_gap_assessment.id_gap_assessment) approval ON (((ga.id_gap_assessment)::text = (approval.id_gap_assessment)::text)))
LEFT JOIN ( SELECT hod_gap_assessment.id_gap_assessment,
count(1) AS approved
FROM compliance.hod_gap_assessment
WHERE (hod_gap_assessment.approved_date IS NOT NULL)
GROUP BY hod_gap_assessment.id_gap_assessment) approved ON (((ga.id_gap_assessment)::text = (approved.id_gap_assessment)::text)))
WHERE (COALESCE(approval.approval, (0)::bigint) = COALESCE(approved.approved, (0)::bigint))
GROUP BY (to_char(ga.create_date, 'yyyy-MM-dd'::text))
ORDER BY (to_char(ga.create_date, 'yyyy-MM-dd'::text));
ALTER TABLE compliance.vw_open_gap OWNER TO postgres;
--
-- Name: vw_slt_hod; Type: VIEW; Schema: compliance; Owner: postgres
--
CREATE VIEW compliance.vw_slt_hod AS
SELECT ga.id_article,
ga.id_gap_assessment,
slt.id_employee AS slt,
slt.employee_name AS slt_name,
hod.id_employee AS hod,
hod.employee_name AS hod_name,
slt.id_department AS slt_dept,
hod.id_department AS hod_dept
FROM ((compliance.gap_assessment ga
LEFT JOIN ( SELECT hod_gap_assessment.id_gap_assessment,
hod_gap_assessment.id_employee_hod_gap AS id_employee,
hod_gap_assessment.hod_gap AS employee_name,
hod_gap_assessment.id_department
FROM compliance.hod_gap_assessment
WHERE ((hod_gap_assessment.send_to_type)::text = 'HOD'::text)) hod ON (((hod.id_gap_assessment)::text = (ga.id_gap_assessment)::text)))
LEFT JOIN ( SELECT hod_gap_assessment.id_gap_assessment,
hod_gap_assessment.id_employee_hod_gap AS id_employee,
hod_gap_assessment.hod_gap AS employee_name,
hod_gap_assessment.id_department
FROM compliance.hod_gap_assessment
WHERE ((hod_gap_assessment.send_to_type)::text = 'SLT'::text)) slt ON (((slt.id_gap_assessment)::text = (ga.id_gap_assessment)::text)))
WHERE (ga.progress > 1)
ORDER BY ga.id_article, ga.id_gap_assessment;
ALTER TABLE compliance.vw_slt_hod OWNER TO postgres;
--
-- Name: vw_target_date; Type: VIEW; Schema: compliance; Owner: postgres
--
CREATE VIEW compliance.vw_target_date AS
SELECT ga.id_article,
ga.id_gap_assessment,
ap.target_date,
((now())::date - (ap.target_date)::date) AS diff
FROM (compliance.gap_assessment ga
LEFT JOIN ( SELECT action_plan.id_gap_assessment,
COALESCE(action_plan.reschedule_target_date, action_plan.initial_target_date, NULL::timestamp without time zone) AS target_date,
row_number() OVER (PARTITION BY action_plan.id_gap_assessment ORDER BY COALESCE(action_plan.reschedule_target_date, action_plan.initial_target_date, NULL::timestamp without time zone) DESC) AS row_number
FROM compliance.action_plan) ap ON ((((ga.id_gap_assessment)::text = (ap.id_gap_assessment)::text) AND (ap.row_number = 1))))
WHERE (ap.target_date IS NOT NULL)
ORDER BY ga.id_gap_assessment;
ALTER TABLE compliance.vw_target_date OWNER TO postgres;
--
-- Name: wf_config; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.wf_config (
id bigint NOT NULL,
key character varying(50) NOT NULL,
value character varying NOT NULL,
created bigint NOT NULL,
modified bigint
);
ALTER TABLE compliance.wf_config OWNER TO postgres;
--
-- Name: wf_config_id_seq; Type: SEQUENCE; Schema: compliance; Owner: postgres
--
CREATE SEQUENCE compliance.wf_config_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE compliance.wf_config_id_seq OWNER TO postgres;
--
-- Name: wf_config_id_seq; Type: SEQUENCE OWNED BY; Schema: compliance; Owner: postgres
--
ALTER SEQUENCE compliance.wf_config_id_seq OWNED BY compliance.wf_config.id;
--
-- Name: wf_employee; Type: TABLE; Schema: compliance; Owner: postgres
--
CREATE TABLE compliance.wf_employee (
employee_id character varying NOT NULL,
user_id bigint NOT NULL
);
ALTER TABLE compliance.wf_employee OWNER TO postgres;
--
-- Name: wf_employee_user_id_seq; Type: SEQUENCE; Schema: compliance; Owner: postgres
--
CREATE SEQUENCE compliance.wf_employee_user_id_seq