]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0688.data.circ_history_export_csv.sql
LP#1206936 - Fix wrong billing info in money.transaction_billing_summary
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0688.data.circ_history_export_csv.sql
1 -- Evergreen DB patch 0688.data.circ_history_export_csv.sql
2 --
3 -- FIXME: insert description of change, if needed
4 --
5 BEGIN;
6
7 -- check whether patch can be applied
8 SELECT evergreen.upgrade_deps_block_check('0688', :eg_version);
9
10 INSERT INTO action_trigger.hook (key, core_type, description, passive)
11 VALUES (
12     'circ.format.history.csv',
13     'circ',
14     oils_i18n_gettext(
15         'circ.format.history.csv',
16         'Produce CSV of circulation history',
17         'ath',
18         'description'
19     ),
20     FALSE
21 );
22
23 INSERT INTO action_trigger.event_definition (
24     active, owner, name, hook, reactor, validator, group_field, template) 
25 VALUES (
26     TRUE, 1, 'Circ History CSV', 'circ.format.history.csv', 'ProcessTemplate', 'NOOP_True', 'usr',
27 $$
28 Title,Author,Call Number,Barcode,Format
29 [%-
30 FOR circ IN target;
31     bibxml = helpers.unapi_bre(circ.target_copy.call_number.record, {flesh => '{mra}'});
32     title = "";
33     FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]');
34         title = title _ part.textContent;
35     END;
36     author = bibxml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent;
37     item_type = bibxml.findnodes('//*[local-name()="attributes"]/*[local-name()="field"][@name="item_type"]').getAttribute('coded-value') %]
38
39     [%- helpers.csv_datum(title) -%],
40     [%- helpers.csv_datum(author) -%],
41     [%- helpers.csv_datum(circ.target_copy.call_number.label) -%],
42     [%- helpers.csv_datum(circ.target_copy.barcode) -%],
43     [%- helpers.csv_datum(item_type) %]
44 [%- END -%]
45 $$
46 );
47
48 INSERT INTO action_trigger.environment (event_def, path)
49     VALUES (
50         currval('action_trigger.event_definition_id_seq'),
51         'target_copy.call_number'
52     );
53
54 COMMIT;