aonestar
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
fn_nbis_settings_json
Parameters
Name
Type
Mode
i_prop_id
integer
IN
Definition
DECLARE v_nbis jsonb; v_cm jsonb; BEGIN SELECT coalesce(i.configs, '{}'::jsonb) INTO v_nbis FROM interfaces i WHERE i.code = 'NBIS'; IF v_nbis IS NULL THEN RETURN NULL; -- ผู้เรียกแปลงเป็น 45001 END IF; v_cm := fn_nbis_cm_config(); RETURN jsonb_build_object( 'interface_code', v_cm->>'code', 'enabled', coalesce((v_cm->>'enabled')::boolean, false), 'property_id', v_cm->>'property_id', 'settings', jsonb_build_object( 'RSVTYPE_ID', nullif(v_nbis->>'RSVTYPE_ID', '')::int, 'MAX_SYNC_DAYS', coalesce(nullif(v_nbis->>'MAX_SYNC_DAYS', '')::int, 400), 'DEFAULT_RATEPLAN', nullif(v_nbis->>'DEFAULT_RATEPLAN', '')::int, 'DEFAULT_ROOMTYPE', nullif(v_nbis->>'DEFAULT_ROOMTYPE', '')::int, 'MAP_RATE_DETAILS', coalesce(nullif(v_nbis->>'MAP_RATE_DETAILS', '')::boolean, false), 'DEFAULT_ORIGIN_ID', nullif(v_nbis->>'DEFAULT_ORIGIN_ID', '')::int ), 'sync', fn_nbis_sync_json(i_prop_id), 'lookups', jsonb_build_object( 'reservation_types', ( SELECT coalesce(jsonb_agg(jsonb_build_object('id', t.id, 'name', t.name) ORDER BY t.name), '[]'::jsonb) FROM reservation_type t WHERE coalesce(t.enabled, true) ), 'rate_plans', ( SELECT coalesce(jsonb_agg(jsonb_build_object( 'id', p.id, 'code', p.code::text, 'name', p.name) ORDER BY p.order_seq NULLS LAST, p.code), '[]'::jsonb) FROM rate_plan p WHERE coalesce(p.enabled, true) ), 'room_types', ( SELECT coalesce(jsonb_agg(jsonb_build_object( 'id', r.id, 'code', r.code::text, 'name', r.name) ORDER BY r.order_seq NULLS LAST, r.code), '[]'::jsonb) FROM room_type r WHERE coalesce(r.enabled, true) ), 'origins', ( SELECT coalesce(jsonb_agg(jsonb_build_object( 'id', o.id, 'code', o.code::text, 'name', o.name) ORDER BY o.code), '[]'::jsonb) FROM origin o WHERE coalesce(o.enabled, true) ) ) ); END