1 -- Correct the long-standing "recuring" (recurring) and "recurance" (recurrence) typos
5 INSERT INTO config.upgrade_log (version) VALUES ('0085'); -- dbs
7 ALTER TABLE config.rule_recuring_fine RENAME TO rule_recurring_fine;
8 ALTER TABLE config.rule_recurring_fine RENAME COLUMN recurance_interval TO recurrence_interval;
10 ALTER TABLE action.circulation RENAME COLUMN recuring_fine TO recurring_fine;
11 ALTER TABLE action.circulation RENAME COLUMN recuring_fine_rule TO recurring_fine_rule;
13 ALTER TABLE action.aged_circulation RENAME COLUMN recuring_fine TO recurring_fine;
14 ALTER TABLE action.aged_circulation RENAME COLUMN recuring_fine_rule TO recurring_fine_rule;
16 -- Might as well keep the comment in sync as well
17 COMMENT ON TABLE config.rule_recurring_fine IS $$
19 * Copyright (C) 2005 Georgia Public Library Service
20 * Mike Rylander <mrylander@gmail.com>
22 * Circulation Recurring Fine rules
24 * Each circulation is given a recurring fine amount based on one of
25 * these rules. The recurrence_interval should not be any shorter
26 * than the interval between runs of the fine_processor.pl script
27 * (which is run from CRON), or you could miss fines.
32 * This program is free software; you can redistribute it and/or
33 * modify it under the terms of the GNU General Public License
34 * as published by the Free Software Foundation; either version 2
35 * of the License, or (at your option) any later version.
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
44 ALTER TABLE reporter.report RENAME COLUMN recurance TO recurrence;
46 -- You would think that CREATE OR REPLACE would be enough, but in testing
47 -- PostgreSQL complained about renaming the columns in the view. So we
48 -- drop the view first.
49 DROP VIEW action.all_circulation;
51 -- Now we can recreate the view successfully
52 CREATE OR REPLACE VIEW action.all_circulation AS
53 SELECT id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
54 copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
55 circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, due_date,
56 stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
57 max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
58 max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ
59 FROM action.aged_circulation
61 SELECT DISTINCT circ.id,COALESCE(a.post_code,b.post_code) AS usr_post_code, p.home_ou AS usr_home_ou, p.profile AS usr_profile, EXTRACT(YEAR FROM p.dob)::INT AS usr_birth_year,
62 cp.call_number AS copy_call_number, cp.location AS copy_location, cn.owning_lib AS copy_owning_lib, cp.circ_lib AS copy_circ_lib,
63 cn.record AS copy_bib_record, circ.xact_start, circ.xact_finish, circ.target_copy, circ.circ_lib, circ.circ_staff, circ.checkin_staff,
64 circ.checkin_lib, circ.renewal_remaining, circ.due_date, circ.stop_fines_time, circ.checkin_time, circ.create_time, circ.duration,
65 circ.fine_interval, circ.recurring_fine, circ.max_fine, circ.phone_renewal, circ.desk_renewal, circ.opac_renewal, circ.duration_rule,
66 circ.recurring_fine_rule, circ.max_fine_rule, circ.stop_fines, circ.workstation, circ.checkin_workstation, circ.checkin_scan_time,
68 FROM action.circulation circ
69 JOIN asset.copy cp ON (circ.target_copy = cp.id)
70 JOIN asset.call_number cn ON (cp.call_number = cn.id)
71 JOIN actor.usr p ON (circ.usr = p.id)
72 LEFT JOIN actor.usr_address a ON (p.mailing_address = a.id)
73 LEFT JOIN actor.usr_address b ON (p.billing_address = a.id);
75 CREATE OR REPLACE FUNCTION action.age_circ_on_delete () RETURNS TRIGGER AS $$
80 -- If there are any renewals for this circulation, don't archive or delete
81 -- it yet. We'll do so later, when we archive and delete the renewals.
84 FROM action.circulation
85 WHERE parent_circ = OLD.id
89 RETURN NULL; -- don't delete
92 -- Archive a copy of the old row to action.aged_circulation
94 INSERT INTO action.aged_circulation
95 (id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
96 copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
97 circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, due_date,
98 stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
99 max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
100 max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ)
102 id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
103 copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
104 circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, due_date,
105 stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
106 max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
107 max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ
108 FROM action.all_circulation WHERE id = OLD.id;
112 $$ LANGUAGE 'plpgsql';
114 -- Get the permissions right
115 UPDATE permission.perm_list SET code = 'ADMIN_RECURRING_FINE_RULE' WHERE code = 'ADMIN_RECURING_FINE_RULE';
117 -- Let's not break existing reports
118 UPDATE reporter.template SET data = REGEXP_REPLACE(data, E'^(.*)recuring(.*)$', E'\\1recurring\\2') WHERE data LIKE '%recuring%';
119 UPDATE reporter.template SET data = REGEXP_REPLACE(data, E'^(.*)recurance(.*)$', E'\\1recurrence\\2') WHERE data LIKE '%recurance%';