]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/tests/datasets/sql/transactions.sql
ed27bbb6d165c8f1b1563b83fe12df2c5aaabd25
[working/Evergreen.git] / Open-ILS / tests / datasets / sql / transactions.sql
1
2 /**
3  * For the first (by ID) 20 users in each Patron group and the first 3 in 
4  * each Staff group:
5  *
6  * 1. create 3 regular circs w/ varying (stock) rules and 3 overdue
7  * circs. 
8  *
9  * 2. create 2 regular title holds and one frozen title hold.  If the user
10  * is in a Staff group, also create one copy-level hold.
11  *
12  */
13
14 /**
15  * NOTE: The fine generator and hold targeter should be run after this is
16  * loaded to creating overdue billings and target copies for holds.
17  */
18
19 DO $$                                                                           
20     DECLARE grp INTEGER;                                                      
21     DECLARE recipient actor.usr%ROWTYPE;
22     DECLARE copy asset.copy%ROWTYPE;
23     DECLARE bre biblio.record_entry%ROWTYPE;
24     DECLARE user_count INTEGER;
25     DECLARE requestor INTEGER;
26 BEGIN                                                                           
27
28     copy := evergreen.next_copy(0);
29     bre := evergreen.next_bib(0);
30
31     FOR grp IN SELECT id FROM permission.grp_tree WHERE id > 1 ORDER BY id LOOP
32
33         IF 2 IN (SELECT id FROM permission.grp_ancestors(grp)) THEN
34             -- patron group
35             user_count := 50;
36         ELSE
37             user_count := 3;
38         END IF;
39
40         FOR recipient IN SELECT * FROM actor.usr 
41             WHERE NOT deleted AND profile = grp 
42                 ORDER BY id LIMIT user_count LOOP
43
44             -- find a suitable circulator/requestor for these transactions
45             SELECT INTO requestor id 
46                 FROM actor.usr 
47                 WHERE home_ou = recipient.home_ou AND
48                       profile = 5 AND -- Circulators
49                       NOT deleted
50                 ORDER BY id LIMIT 1;
51
52             -- regular circs --------------------------------
53
54             copy := evergreen.next_copy(copy.id);
55             EXIT WHEN copy IS NULL;
56             PERFORM evergreen.populate_circ(
57                 recipient.id, requestor, copy.id, copy.circ_lib,
58                 'default', 'default', 'default', FALSE
59             );
60
61             copy := evergreen.next_copy(copy.id);
62             EXIT WHEN copy IS NULL;
63             PERFORM evergreen.populate_circ(
64                 recipient.id, requestor, copy.id, copy.circ_lib,
65                 '1_hour_2_renew', 'default', 'overdue_min', FALSE
66             );
67
68             copy := evergreen.next_copy(copy.id);
69             EXIT WHEN copy IS NULL;
70             PERFORM evergreen.populate_circ(
71                 recipient.id, requestor, copy.id, copy.circ_lib,
72                 '7_days_0_renew', 'default', 'overdue_max', FALSE
73             );
74
75             -- overdue circs ----------------------------------
76
77             copy := evergreen.next_copy(copy.id);
78             EXIT WHEN copy IS NULL;
79             PERFORM evergreen.populate_circ(
80                 recipient.id, requestor, copy.id, copy.circ_lib,
81                 'default', 'default', 'default', TRUE
82             );
83
84             copy := evergreen.next_copy(copy.id);
85             EXIT WHEN copy IS NULL;
86             PERFORM evergreen.populate_circ(
87                 recipient.id, requestor, copy.id, copy.circ_lib,
88                 '1_hour_2_renew', 'default', 'overdue_min', TRUE
89             );
90
91             copy := evergreen.next_copy(copy.id);
92             EXIT WHEN copy IS NULL;
93             PERFORM evergreen.populate_circ(
94                 recipient.id, requestor, copy.id, copy.circ_lib,
95                 '7_days_0_renew', 'default', 'overdue_max', TRUE
96             );
97
98             -- holds ------------------------------------------
99
100             -- title hold
101             bre := evergreen.next_bib(bre.id);
102             EXIT WHEN bre IS NULL;
103             PERFORM evergreen.populate_hold(
104                 'T', bre.id, recipient.id, recipient.id,
105                 recipient.home_ou, FALSE, NULL
106             );
107
108             -- title hold, circulator-placed 
109             bre := evergreen.next_bib(bre.id);
110             EXIT WHEN bre IS NULL;
111             PERFORM evergreen.populate_hold(
112                 'T', bre.id, recipient.id, requestor,
113                 recipient.home_ou, FALSE, NULL
114             );
115
116             -- frozen title hold
117             bre := evergreen.next_bib(bre.id);
118             EXIT WHEN bre IS NULL;
119             PERFORM evergreen.populate_hold(
120                 'T', bre.id, recipient.id, recipient.id,
121                 recipient.home_ou,
122                 TRUE, NOW() + '3 months'::INTERVAL
123             );
124
125             -- Staff accounts get a copy-level hold
126             IF 3 IN (SELECT id FROM permission.grp_ancestors(grp)) THEN
127                 copy := evergreen.next_copy(copy.id);
128                 EXIT WHEN copy IS NULL;
129                 PERFORM evergreen.populate_hold(
130                     'C', copy.id, recipient.id, recipient.id,
131                     recipient.home_ou, FALSE, NULL
132                 );
133             END IF;
134
135         END LOOP;                                                                   
136     END LOOP;                                                                   
137 END $$;
138
139