aonestar
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
fn_precheckin_get_legal_document
Parameters
Name
Type
Mode
p_doc_type
text
IN
p_lang_code
text
IN
Definition
DECLARE v_lang text := UPPER(COALESCE(p_lang_code, 'EN')); v_doc record; BEGIN SELECT title, content_html, version, lang_code, is_translated INTO v_doc FROM public.precheckin_legal_document WHERE doc_type = p_doc_type AND lang_code = v_lang AND is_active ORDER BY version DESC LIMIT 1; IF NOT FOUND THEN SELECT title, content_html, version, lang_code, is_translated INTO v_doc FROM public.precheckin_legal_document WHERE doc_type = p_doc_type AND lang_code = 'EN' AND is_active ORDER BY version DESC LIMIT 1; END IF; IF NOT FOUND THEN RETURN NULL; END IF; RETURN jsonb_build_object( 'doc_type', p_doc_type, 'lang_code', v_doc.lang_code, 'version', v_doc.version, 'title', v_doc.title, 'content_html', v_doc.content_html, 'is_translated', v_doc.is_translated ); END;