egdb3_14_1
.action
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
age_circ_on_delete()
Parameters
Name
Type
Mode
IN
Definition
DECLARE found char := 'N'; BEGIN -- If there are any renewals for this circulation, don't archive or delete -- it yet. We'll do so later, when we archive and delete the renewals. SELECT 'Y' INTO found FROM action.circulation WHERE parent_circ = OLD.id LIMIT 1; IF found = 'Y' THEN RETURN NULL; -- don't delete END IF; -- Archive a copy of the old row to action.aged_circulation INSERT INTO action.aged_circulation (id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location, copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy, circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, grace_period, due_date, stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine, max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule, max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ, auto_renewal, auto_renewal_remaining) SELECT id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location, copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy, circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, grace_period, due_date, stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine, max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule, max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ, auto_renewal, auto_renewal_remaining FROM action.all_circulation WHERE id = OLD.id; -- Migrate billings and payments to aged tables SELECT 'Y' INTO found FROM config.global_flag WHERE name = 'history.money.age_with_circs' AND enabled; IF found = 'Y' THEN PERFORM money.age_billings_and_payments_for_xact(OLD.id); END IF; -- Break the link with the user in action_trigger.event (warning: event_output may essentially have this information) UPDATE action_trigger.event e SET context_user = NULL FROM action.all_circulation c WHERE c.id = OLD.id AND e.context_user = c.usr AND e.target = c.id AND e.event_def IN ( SELECT id FROM action_trigger.event_definition WHERE hook in (SELECT key FROM action_trigger.hook WHERE core_type = 'circ') ) ; RETURN OLD; END;