LP#1373690 template continued
authorBill Erickson <berickxx@gmail.com>
Fri, 26 Sep 2014 15:12:06 +0000 (11:12 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 13 May 2015 22:41:52 +0000 (18:41 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/sql/Pg/upgrade/XXXX.data.acq-order-edi.sql

index aad83ec..5765ce3 100644 (file)
@@ -108,11 +108,44 @@ FOR li IN target.lineitems;
     li_hash.idqual = idqual;
     li_hash.title = helpers.get_li_attr_edi('title',     '', li.attributes);
     li_hash.author = helpers.get_li_attr_edi('author',    '', li.attributes);
+    li_hash.edition = helpers.get_li_attr_edi('edition',   '', li.attributes);
     li_hash.pubdate = helpers.get_li_attr_edi('pubdate',   '', li.attributes);
+    li_hash.publisher = helpers.get_li_attr_edi('publisher',   '', li.attributes);
     li_hash.pagination = helpers.get_li_attr_edi('pagination','', li.attributes);
     li_hash.quantity = li.lineitem_details.size;
     li_hash.copies = [];
 
+    ftx_vals = []; 
+    FOR note IN li.lineitem_notes;
+        NEXT UNLESS note.vendor_public == 't'; 
+        ftx_vals.push(note.value); 
+    END; 
+    IF VENDOR_BRODART; # look for copy-level spec code
+        FOR lid IN li.lineitem_details;
+            IF lid.note;
+                spec_note = lid.note.match('spec code ([a-zA-Z0-9_])');
+                IF spec_note.0; ftx_vals.push(spec_note.0); END;
+            END;
+        END;
+    END; 
+    IF xtra_ftx; ftx_vals.unshift(xtra_ftx); END; 
+
+    # BT & ULS want FTX+LIN for every LI, even if empty
+    IF ((VENDOR_BT OR VENDOR_ULS) AND ftx_vals.size == 0);
+        ftx_vals.unshift('');
+    END;  
+
+    # EDI FTX fields have a max length of 512
+    notes = [];
+    FOR note IN ftx_vals;
+        sub_notes = note.chunk(512);
+        FOR sub_note IN sub_notes;
+            notes.push(helpers.escape_edi(sub_note));
+        END;
+    END;
+
+    li_hash.notes = notes;
+
     IF INC_COPIES;
         SEGMENT_COUNT = SEGMENT_COUNT + 1;
         FOR lid IN li.lineitem_details;
@@ -177,15 +210,20 @@ BGM+220+98+9'
 DTM+137:[% date.format(date.now, '%Y%m%d') %]:102'
 NAD+BY+[% BUYER_CODE %]::91'
 NAD+SU+[% VENDOR_SAN %]::31B'
-NAD+SU+12::92'
+NAD+SU+[% target.provider.id %]::92'
 CUX+2:[% target.provider.currency_type %]:9'
 [%- FOR li_hash IN LINEITEMS -%]
 LIN+[% li_hash.id %]++[% li_hash.idval %]:[% li_hash.idqual %]'
 PIA+5+[% li_hash.idval %]:[% li_hash.idqual %]'
 IMD+F+BTI+:::[% li_hash.title %]'
-IMD+F+BPU+:::[% li_hash.author %]'
 IMD+F+BPD+:::[% li_hash.pubdate %]'
+IMD+F+BPU+:::[% li_hash.publisher %]'
+[%- IF VENDOR_ULS -%]
+IMD+F+BPU+:::[% li_hash.author %]'
+IMD+F+BEN+:::[% li_hash.edition %]'
+[%- ELSE -%]
 IMD+F+BPH+:::[% li_hash.pagination %]'
+[%- END -%]
 QTY+21:[% li_hash.quantity %]'
 [%- GIR_INDEX = 0; -%]
 [% FOR copy IN li_hash.copies;
@@ -227,10 +265,17 @@ GIR+[% GIR_INDEX.format('%03d') -%][% END -%]
 [%- IF INC_COPY_ID AND (VENDOR_BT OR copy.copy_id); 
     FIELD_COUNT = FIELD_COUNT + 1 -%]
 +[% copy.copy_id %]:LCO[%- END -%]
+'[%# finalize the GIR segment with a "'" -%]
 [% END %] [%# FOR copies %]
-FTX+LIN+1'
+[%- FOR note IN li_hash.notes -%]
+FTX+LIN+1+[% note %]'
+[% END -%]
 PRI+AAB:[% li.estimated_unit_price || "0.00" %]'
+[%- IF INC_PO_NAME -%]
+RFF+LI:[% helpers.escape_edi(target.name) %]/[% li.id %]'
+[%- ELSE -%]
 RFF+LI:[% target.id %]/[% li.id %]'
+[%- END -%]
 [%- END -%][%# for lineitems %]
 UNS+S'
 CNT+2:[% target.lineitems.size %]'
@@ -238,10 +283,9 @@ UNT+40+1'
 UNZ+1+1'
 [% END %][%# block %]
 [% 
-    tempo = PROCESS big_block; 
-    # EDI should not have newlines, but they are useful for testing.
-    #tempo.remove('\n');
-    tempo;
+    edi_text = PROCESS big_block; 
+    #edi_text; # To test with newlines, which are easier on the eyes.
+    edi_text.remove('\n');
 %]
 $$
 );