aonestar
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
sp_cancel_auto_post
Parameters
Name
Type
Mode
register_id
integer
IN
user_name
text
IN (DEFAULT NULL)
Definition
DECLARE trans int[]; v_folio_id int; v_register_id int; shift varchar; void_result json; SYS_DATE date = fn_system_date(); BEGIN user_name := coalesce(user_name, fn_current_user()); shift := coalesce(shift, fn_work_shift(user_name), fn_online_shift()); v_folio_id := (Select r.folio_id from registration r where r.id = $1); trans := ARRAY(Select t.id from transactions t where t.folio_id = v_folio_id and t.post_date = SYS_DATE and t.post_flag in ('R','A') and t.active); raise notice 'Trans: %', trans; if fn_length(trans) > 0 then void_result := sp_void_transactions(trans, 'Cancel auto-post', user_name, shift); if void_result->>'result_code' <> '4' then UPDATE registration_rates rr SET posted = FALSE, inclusive_posted = FALSE, tran_id = null WHERE rr.register_id = $1 AND rr.charge_date = SYS_DATE; UPDATE registration rg SET room_posted = FALSE WHERE rg.id = $1; -- Other charges UPDATE charge_schedule cs SET posted = FALSE WHERE cs.register_id = $1 AND cs.charge_date = SYS_DATE and cs.posted = TRUE; return fn_result_success('00', '%s transactions voided', fn_length(trans)::text); else return void_result; end if; else return fn_result_error('30502', 'No auto-post transaction'); end if; END