DECLARE duration config.rule_circ_duration%ROWTYPE;
DECLARE recurring config.rule_recurring_fine%ROWTYPE;
DECLARE max_fine config.rule_max_fine%ROWTYPE;
+ DECLARE patron actor.usr%ROWTYPE;
+ DECLARE xact_base_date TIMESTAMP;
DECLARE due_date TIMESTAMP;
DECLARE xact_start TIMESTAMP;
BEGIN
SELECT INTO duration * FROM config.rule_circ_duration WHERE name = duration_rule;
SELECT INTO recurring * FROM config.rule_recurring_fine WHERE name = recurring_fine_rule;
SELECT INTO max_fine * FROM config.rule_max_fine WHERE name = max_fine_rule;
+ SELECT INTO patron * FROM actor.usr WHERE id = patron_id;
+
+ IF patron.expire_date < NOW() THEN
+ xact_base_date = patron.expire_date;
+ ELSE
+ xact_base_date = NOW();
+ END IF;
IF overdue THEN
-- if duration is '7 days', the overdue item was due 7 days ago
- due_date := NOW() - duration.normal;
+ due_date := xact_base_date - duration.normal;
-- make overdue circs appear as if they were created two durations ago
- xact_start := NOW() - duration.normal - duration.normal;
+ xact_start := xact_base_date - duration.normal - duration.normal;
ELSE
- due_date := NOW() + duration.normal;
- xact_start := NOW();
+ due_date := xact_base_date + duration.normal;
+ xact_start := xact_base_date;
END IF;
IF duration.normal >= '1 day'::INTERVAL THEN
WHERE id=CURRVAL('actor.usr_id_seq');
+-- Soon to expire patron
INSERT INTO actor.usr
(profile, ident_type, usrname, home_ou, family_name, passwd, first_given_name, second_given_name, expire_date, dob, suffix)
VALUES (2, 3, '99999355250', 5, 'Jones', 'gregoryj1234',
- 'Gregory', '', NOW() + '3 years'::INTERVAL, NULL, NULL);
+ 'Gregory', '', NOW() + '1 day'::INTERVAL, NULL, NULL);
INSERT INTO actor.usr_address
(country, within_city_limits, post_code, street1, valid, state, city, street2, county, usr)
WHERE id=CURRVAL('actor.usr_id_seq');
+-- Soon to expire patron
INSERT INTO actor.usr
(profile, ident_type, usrname, home_ou, family_name, passwd, first_given_name, second_given_name, expire_date, dob, suffix)
VALUES (2, 1, '99999387993', 9, 'Moran', 'vincentm1234',
- 'Vincent', 'Kenneth', NOW() + '3 years'::INTERVAL, NULL, NULL);
+ 'Vincent', 'Kenneth', NOW() + '1 week'::INTERVAL, NULL, NULL);
INSERT INTO actor.usr_address
(country, within_city_limits, post_code, street1, valid, state, city, street2, county, usr)
WHERE id=CURRVAL('actor.usr_id_seq');
+-- Soon to expire patron
INSERT INTO actor.usr
(profile, ident_type, usrname, home_ou, family_name, passwd, first_given_name, second_given_name, expire_date, dob, suffix)
VALUES (2, 1, '99999335859', 8, 'Jones', 'gregoryj1234',
- 'Gregory', 'Adam', NOW() + '3 years'::INTERVAL, NULL, NULL);
+ 'Gregory', 'Adam', NOW() + '3 weeks'::INTERVAL, NULL, NULL);
INSERT INTO actor.usr_address
(country, within_city_limits, post_code, street1, valid, state, city, street2, county, usr)
WHERE id=CURRVAL('actor.usr_id_seq');
+-- Recently expired patron
INSERT INTO actor.usr
(profile, ident_type, usrname, home_ou, family_name, passwd, first_given_name, second_given_name, expire_date, dob, suffix)
VALUES (2, 1, '99999373186', 7, 'Walker', 'brittanyw1234',
- 'Brittany', 'Geraldine', NOW() + '3 years'::INTERVAL, NULL, NULL);
+ 'Brittany', 'Geraldine', NOW() - '1 week'::INTERVAL, NULL, NULL);
INSERT INTO actor.usr_address
(country, within_city_limits, post_code, street1, valid, state, city, street2, county, usr)
WHERE id=CURRVAL('actor.usr_id_seq');
+-- Recently expired patron
INSERT INTO actor.usr
(profile, ident_type, usrname, home_ou, family_name, passwd, first_given_name, second_given_name, expire_date, dob, suffix)
VALUES (2, 1, '99999384262', 9, 'Miller', 'ernestom1234',
- 'Ernesto', 'Robert', NOW() + '3 years'::INTERVAL, '1997-02-02', 'II');
+ 'Ernesto', 'Robert', NOW() - '3 weeks'::INTERVAL, '1997-02-02', 'II');
INSERT INTO actor.usr_address
(country, within_city_limits, post_code, street1, valid, state, city, street2, county, usr)