]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0384.data.hold_pull_list_template.sql
Stamping upgrade for truncate-to-max-fine
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0384.data.hold_pull_list_template.sql
1 BEGIN;
2
3 INSERT INTO config.upgrade_log (version) VALUES ('0384');
4
5 INSERT INTO action_trigger.hook (key,core_type,description,passive) 
6     VALUES (   
7         'ahr.format.pull_list',
8         'ahr', 
9         oils_i18n_gettext(
10             'ahr.format.pull_list',
11             'Format holds pull list for printing',
12             'ath',
13             'description'
14         ), 
15         FALSE
16     );
17
18 INSERT INTO action_trigger.event_definition (
19         id,
20         active,
21         owner,
22         name,
23         hook,
24         validator,
25         reactor,
26         group_field,
27         granularity,
28         template
29     ) VALUES (
30         35,
31         TRUE,
32         1,
33         'Holds Pull List',
34         'ahr.format.pull_list',
35         'NOOP_True',
36         'ProcessTemplate',
37         'pickup_lib',
38         'print-on-demand',
39 $$
40 [%- USE date -%]
41 <style>
42     table { border-collapse: collapse; } 
43     td { padding: 5px; border-bottom: 1px solid #888; } 
44     th { font-weight: bold; }
45 </style>
46 [% 
47     # Sort the holds into copy-location buckets
48     # In the main print loop, sort each bucket by callnumber before printing
49     SET holds_list = [];
50     SET loc_data = [];
51     SET current_location = target.0.current_copy.location.id;
52     FOR hold IN target;
53         IF current_location != hold.current_copy.location.id;
54             SET current_location = hold.current_copy.location.id;
55             holds_list.push(loc_data);
56             SET loc_data = [];
57         END;
58         SET hold_data = {
59             'hold' => hold,
60             'callnumber' => hold.current_copy.call_number.label
61         };
62         loc_data.push(hold_data);
63     END;
64     holds_list.push(loc_data)
65 %]
66 <table>
67     <thead>
68         <tr>
69             <th>Title</th>
70             <th>Author</th>
71             <th>Shelving Location</th>
72             <th>Call Number</th>
73             <th>Barcode</th>
74             <th>Patron</th>
75         </tr>
76     </thead>
77     <tbody>
78     [% FOR loc_data IN holds_list  %]
79         [% FOR hold_data IN loc_data.sort('callnumber') %]
80             [% 
81                 SET hold = hold_data.hold;
82                 SET copy_data = helpers.get_copy_bib_basics(hold.current_copy.id);
83             %]
84             <tr>
85                 <td>[% copy_data.title | truncate %]</td>
86                 <td>[% copy_data.author | truncate %]</td>
87                 <td>[% hold.current_copy.location.name %]</td>
88                 <td>[% hold.current_copy.call_number.label %]</td>
89                 <td>[% hold.current_copy.barcode %]</td>
90                 <td>[% hold.usr.card.barcode %]</td>
91             </tr>
92         [% END %]
93     [% END %]
94     <tbody>
95 </table>
96 $$
97 );
98
99 INSERT INTO action_trigger.environment (
100         event_def,
101         path
102     ) VALUES
103         (35, 'current_copy.location'),
104         (35, 'current_copy.call_number'),
105         (35, 'usr.card'),
106         (35, 'pickup_lib')
107 ;
108
109 -- DELETE FROM config.upgrade_log WHERE version = 'tmp'; DELETE FROM action_trigger.event WHERE event_def IN (35); DELETE FROM action_trigger.environment WHERE event_def IN (35); DELETE FROM action_trigger.event_definition WHERE id IN (35); DELETE FROM action_trigger.hook WHERE key IN ( 'ahr.format.pull_list' );
110
111 COMMIT;
112