3 INSERT INTO config.upgrade_log (version) VALUES ('0101');
5 -- represents a circ chain summary
6 CREATE TYPE action.circ_chain_summary AS (
8 start_time TIMESTAMP WITH TIME ZONE,
9 checkout_workstation TEXT,
10 last_renewal_time TIMESTAMP WITH TIME ZONE, -- NULL if no renewals
12 last_stop_fines_time TIMESTAMP WITH TIME ZONE,
13 last_renewal_workstation TEXT, -- NULL if no renewals
14 last_checkin_workstation TEXT,
15 last_checkin_time TIMESTAMP WITH TIME ZONE,
16 last_checkin_scan_time TIMESTAMP WITH TIME ZONE
20 CREATE OR REPLACE FUNCTION action.circ_chain ( ctx_circ_id INTEGER ) RETURNS SETOF action.circulation AS $$
22 tmp_circ action.circulation%ROWTYPE;
23 circ_0 action.circulation%ROWTYPE;
26 SELECT INTO tmp_circ * FROM action.circulation WHERE id = ctx_circ_id;
28 IF tmp_circ IS NULL THEN
33 -- find the front of the chain
35 SELECT INTO tmp_circ * FROM action.circulation WHERE id = tmp_circ.parent_circ;
36 IF tmp_circ IS NULL THEN
42 -- now send the circs to the caller, oldest to newest
45 IF tmp_circ IS NULL THEN
49 SELECT INTO tmp_circ * FROM action.circulation WHERE parent_circ = tmp_circ.id;
53 $$ LANGUAGE 'plpgsql';
55 CREATE OR REPLACE FUNCTION action.summarize_circ_chain ( ctx_circ_id INTEGER ) RETURNS action.circ_chain_summary AS $$
59 -- first circ in the chain
60 circ_0 action.circulation%ROWTYPE;
62 -- last circ in the chain
63 circ_n action.circulation%ROWTYPE;
65 -- circ chain under construction
66 chain action.circ_chain_summary;
67 tmp_circ action.circulation%ROWTYPE;
72 FOR tmp_circ IN SELECT * FROM action.circ_chain(ctx_circ_id) LOOP
74 IF chain.num_circs = 0 THEN
78 chain.num_circs := chain.num_circs + 1;
82 chain.start_time := circ_0.xact_start;
83 chain.last_stop_fines := circ_n.stop_fines;
84 chain.last_stop_fines_time := circ_n.stop_fines_time;
85 chain.last_checkin_time := circ_n.checkin_time;
86 chain.last_checkin_scan_time := circ_n.checkin_scan_time;
87 SELECT INTO chain.checkout_workstation name FROM actor.workstation WHERE id = circ_0.workstation;
88 SELECT INTO chain.last_checkin_workstation name FROM actor.workstation WHERE id = circ_n.checkin_workstation;
90 IF chain.num_circs > 1 THEN
91 chain.last_renewal_time := circ_n.xact_start;
92 SELECT INTO chain.last_renewal_workstation name FROM actor.workstation WHERE id = circ_n.workstation;
98 $$ LANGUAGE 'plpgsql';