|
32 | 32 |
|
33 | 33 | CREATE FUNCTION public.contact_hierarchy( |
34 | 34 | parent_establishment_id INTEGER, |
35 | | - parent_legal_unit_id INTEGER |
| 35 | + parent_legal_unit_id INTEGER, |
| 36 | + valid_on DATE |
36 | 37 | ) RETURNS JSONB LANGUAGE sql STABLE AS $$ |
37 | 38 | SELECT COALESCE( |
38 | 39 | (SELECT jsonb_build_object('contact',to_jsonb(c.*)) |
39 | 40 | FROM public.contact AS c |
40 | 41 | WHERE ( parent_establishment_id IS NOT NULL AND c.establishment_id = parent_establishment_id |
41 | 42 | OR parent_legal_unit_id IS NOT NULL AND c.legal_unit_id = parent_legal_unit_id |
42 | | - )), |
| 43 | + ) AND c.valid_from <= valid_on AND valid_on < c.valid_until), |
43 | 44 | '{}'::JSONB |
44 | 45 | ); |
45 | 46 | $$; |
@@ -71,7 +72,7 @@ CREATE FUNCTION public.establishment_hierarchy( |
71 | 72 | || CASE WHEN scope IN ('all','details') THEN (SELECT public.sector_hierarchy(es.sector_id)) ELSE '{}'::JSONB END |
72 | 73 | || CASE WHEN scope IN ('all','details') THEN (SELECT public.unit_size_hierarchy(es.unit_size_id)) ELSE '{}'::JSONB END |
73 | 74 | || CASE WHEN scope IN ('all','details') THEN (SELECT public.status_hierarchy(es.status_id)) ELSE '{}'::JSONB END |
74 | | - || CASE WHEN scope IN ('all','details') THEN (SELECT public.contact_hierarchy(es.id,NULL)) ELSE '{}'::JSONB END |
| 75 | + || CASE WHEN scope IN ('all','details') THEN (SELECT public.contact_hierarchy(es.id,NULL,valid_on)) ELSE '{}'::JSONB END |
75 | 76 | || CASE WHEN scope IN ('all','details') THEN (SELECT public.data_source_hierarchy(es.data_source_id)) ELSE '{}'::JSONB END |
76 | 77 | || CASE WHEN scope IN ('all','details') THEN (SELECT public.notes_for_unit(es.id,NULL,NULL,NULL)) ELSE '{}'::JSONB END |
77 | 78 | || CASE WHEN scope IN ('all','details') THEN (SELECT public.tag_for_unit_hierarchy(es.id,NULL,NULL,NULL)) ELSE '{}'::JSONB END |
@@ -111,7 +112,7 @@ CREATE FUNCTION public.legal_unit_hierarchy( |
111 | 112 | || CASE WHEN scope IN ('all','details') THEN (SELECT public.unit_size_hierarchy(lu.unit_size_id)) ELSE '{}'::JSONB END |
112 | 113 | || CASE WHEN scope IN ('all','details') THEN (SELECT public.status_hierarchy(lu.status_id)) ELSE '{}'::JSONB END |
113 | 114 | || CASE WHEN scope IN ('all','details') THEN (SELECT public.legal_form_hierarchy(lu.legal_form_id)) ELSE '{}'::JSONB END |
114 | | - || CASE WHEN scope IN ('all','details') THEN (SELECT public.contact_hierarchy(NULL,lu.id)) ELSE '{}'::JSONB END |
| 115 | + || CASE WHEN scope IN ('all','details') THEN (SELECT public.contact_hierarchy(NULL,lu.id,valid_on)) ELSE '{}'::JSONB END |
115 | 116 | || CASE WHEN scope IN ('all','details') THEN (SELECT public.data_source_hierarchy(lu.data_source_id)) ELSE '{}'::JSONB END |
116 | 117 | || CASE WHEN scope IN ('all','details') THEN (SELECT public.notes_for_unit(NULL,lu.id,NULL,NULL)) ELSE '{}'::JSONB END |
117 | 118 | || CASE WHEN scope IN ('all','details') THEN (SELECT public.tag_for_unit_hierarchy(NULL,lu.id,NULL,NULL)) ELSE '{}'::JSONB END |
|
0 commit comments