]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0167.data.event_definition_po_jedi.sql
LP#1842940: Improve Alert
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0167.data.event_definition_po_jedi.sql
1 BEGIN;
2
3 INSERT INTO config.upgrade_log (version) VALUES ('0167');
4
5 INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, cleanup_success, cleanup_failure, delay, delay_field, group_field, template) VALUES (23, true, 1, 'PO JEDI', 'format.po.jedi', 'NOOP_True', 'ProcessTemplate', NULL, NULL, '00:05:00', NULL, NULL,
6 $$[%- USE date -%]
7 [%# start JEDI document -%]
8 [%- BLOCK big_block -%]
9 ["order", {
10     "po_number":[% target.id %],
11     "date":"[% date.format(date.now, '%Y%m%d') %]",
12     "buyer":[
13         {"id":"[% target.ordering_agency.mailing_address.san %]",
14          "reference":{"API":"[% target.ordering_agency.mailing_address.san %]"}}
15     ],
16     "vendor":[ 
17         "[% target.provider.san %]", // [% target.provider.name %] ([% target.provider.id %])
18         {"id-qualifier":"91", "reference":{"IA":"[% target.provider.id %]"}, "id":"[% target.provider.san %]"}
19     ],
20     "currency":"[% target.provider.currency_type %]",
21     "items":[
22         [% FOR li IN target.lineitems %]
23         {
24             "identifiers":[
25                 {"id-qualifier":"SA","id":"[% li.id %]"},
26                 {"id-qualifier":"IB","id":"[% helpers.get_li_attr('isbn', li.attributes) %]"}
27             ],
28             "price":[% helpers.get_li_attr('estimated_price', '', li.attributes) %],
29             "desc":[
30                 {"BTI":"[% helpers.get_li_attr('title',     '', li.attributes) %]"}, 
31                 {"BPU":"[% helpers.get_li_attr('publisher', '', li.attributes) %]"},
32                 {"BPD":"[% helpers.get_li_attr('pubdate',   '', li.attributes) %]"},
33                 {"BPH":"[% helpers.get_li_attr('pagination','', li.attributes) %]"}
34             ],
35             "quantity":[% li.lineitem_details.size %]
36             [%-# TODO: lineitem details (later) -%]
37         }[% UNLESS loop.last %],[% END -%]
38         [%- END %]
39     ],
40     "line_items":[% target.lineitems.size %]
41 }]
42 [% END %]
43 [% tempo = PROCESS big_block; helpers.escape_json(tempo) %]
44 $$
45 );
46
47 /*
48 // API : additional party identification -- supplier’s code for library acct or dept (EAN code) 
49 // IA  : internal vendor number (vendor profile number)
50 // VA  : VAT registered number.... TODO
51
52 BUYER id-qualifier:
53  9  = EAN - location number -- not the same as EAN-13 barcode
54 31B = US book trade SANs (Standard Address Numbers aka EDItEUR code) - TRANSLATOR DEFAULT!
55 91  = Assigned by supplier or supplier’s agent
56 92  = Assigned by buyer
57
58 ITEM id-qualifier (Item number type, coded):
59 EN = EAN-13 article number - 13 digit barcode
60 IB = ISBN (International Standard Book   Number)
61 IM = ISMN (International Standard Music  Number)
62 IS = ISSN (International Standard Serial Number): use only in a continuation order message coded 22C in BGM DE 1001, to identify the series to which the order applies
63 MF = manufacturer’s article number
64 SA = supplier’s article number
65 */
66
67
68 INSERT INTO action_trigger.environment (event_def, path) VALUES 
69   (23, 'lineitems.attributes'), 
70   (23, 'lineitems.lineitem_details'), 
71   (23, 'lineitems.lineitem_notes'), 
72   (23, 'ordering_agency.mailing_address'), 
73   (23, 'provider');
74
75 -- The environment insert has to happen here because it relies on subquerying the user-editable field "name" to
76 -- provide the FK.  Outside of this transaction, we cannot be sure the user hasn't changed the name to something else.
77
78 COMMIT;
79