· 8 years ago · Apr 16, 2018, 04:14 PM
1/***********************************************************************************
2 Used to stamp a 2D barcode suitable for Neopost AIMS enclosing machines.
3
4 Call:
5 spdbscript -script DBSCRIPTS\doNeopostOutput.dbscp [opts=v|V|summary] mode="<mode>" docs="<docs>" delivery="<del>" [banner="<banner>"]
6 where:
7 opts = Optional argument that displays the script version (upper or lower case V)
8 if opts=summary then a summary file is created showing how many items
9 were output on each stream type.
10 mode = The stream to be processed e.g. "MONO|DUPLEX|STD" or "COLOUR|SIMPLEX|OS" etc.
11 docs = A comma-separated list of document types to be processed on that stream
12 del = Delivery type. Acceptable values are "post" or "test"
13 banner = An optional stream banner. Specified by filename and full path.
14
15
16 Two types of barcode are available - for AIMS-100 and, the default, AIMS-500 machines
17 and this decision is held in the 'AIMS_Type' entry in the publisure_config database table.
18 AIMS-100 format 1 (AIMS_Type value 100D):
19 0103000000001234567890
20 where 0103 = physical page sequence of each document e.g. page 01 of 03
21 0000 = position of document in the batch. 1st = 0001,...
22 00001234567890 = A 14-char reference for each document For example:
23 repeat of doc position (0000) + 10 char pubkeyfield01 (the CHI/NHS number)
24
25 AIMS-100 format 2 (AIMS_Type value 100P):
26 0103000ABCDEFGHIJKLMNOPQRSTUVWXY
27 where 0103 = physical page sequence of each document e.g. page 01 of 03
28 000 = position of page in the batch. 1st page = 000, 2nd = 001,...
29 A-Y = A 25-char reference for each document e.g. pubkeyfield01 (the CHI number)
30
31 AIMS-500 format:
32 9FB51E42C70000000001AD
33 where 9FB51E42C7 = The document batch Id i.e. UUID without '-'
34 0000000001 = position of document within the batch
35 A = the enclosing instruction, A = enclose, B = last page of document
36 D = the document sequence order. Cycles around A-Z, continuing over
37 multiple documents within the batch
38************************************************************************************
39 vsn Name Change
40 1.00 NB Copied from commercial version. Modified to properly include attachments
41 (PDF output not tested)
42 1.01 NB Ensure AIMS-100 barcode page sequence starts at 000.
43 Change sequencing to increment for every page rather than each document in batch.
44 General layout change to DoStamp routine to allow for both AIMS-100 formats.
45 Lines 128, 136/140, 146, 176-191, 979-1012 (DoStamp routine)
46 1.02 NB Changed Create_Final_File to convert combined PS output to PDF (lines 864-869)
47 Modified test for banners (lines 47-66, 957-974)
48 1.03 NB Added processing for First Class streams (lines 108-121, 277-289, 341-354, 426-439
49 1.04 NB Changed Create_Final_File to output both PS and PDF version (lines 958-966)
50 Clear down attachment array (1429-31). Workaround for Cloud issue (1373)
51 1.05 NB Corrections to clear down loop (line 1429). Reinstated CleanUp_Temps after testing.
52 Various SQL statements updated to include PostageTypeId selection for 1st/2nd class.
53 1.06 NB Mod to prepend CHI number in barcode with incremental count (lines 175, 1122/3, 1137)
54 Included option to display script version (lines 54-61).
55 Included usage comments at top of file.
56 1.06.1 NB Correction to badly formed SQL on OS streams, 4 and 12. (lines 369 and 394)
57 Added checks to SQL to ensure doc + attachments count toward OS (lines 295-331, 360-394)
58 Changed AIMS-100 barcode to use unique page count to workaround Neopost problems (lines 1133-41, 1153-58)
59 Batch limit set to 500.
60 1.06.2 NB Yet another change to try and get AIMS-100 working. This time set the custom field
61 to the itemCount but padded to 10 (as well as it being set to 3 previously!) (line 1145)
62 1.06.3 NB And another change to try and get AIMS-100 working. Back to setting the custom field
63 to the itemCount (padded to 4) followed by the NHS number (10 chars) (line 1147)
64 1.06.4 NB And another...(hopefully, the last). Increase the document count field to 4 digits and
65 set the custom field to the document count (padded to 4) followed by the NHS number (10 chars).
66 If there is no NHS number the this will be set to 10 zeroes (lines 573/4, 1151, 1157, 1166)
67 1.06.5 DP Updated Output files for Print Room to Validate Number of Letters per stream.
68 Added the date and hour to the summary filename to prevent overwriting on later runs.
69 1.7.6 RJ Modified to output items from PAS testing
70 1.7.7 JK Modified to try remove the duplicated lines from showing on the copied totals to Radiology -01/12 tried different way to delete old file.
71************************************************************************************************/
72
73 // Don't forget to update this if you modify this script!!
74 let SCRIPT_VERSION = "1.7.6";
75
76 let provideSummary = FALSE;
77
78 // Check input arguments
79 if opts = "V" or opts = "v" then
80 print "Version " & SCRIPT_VERSION;
81 END;
82 endif;
83 if opts = "summary" then
84 let provideSummary = TRUE;
85 let inDateTime = time();
86 gosub ConvertDateTime;
87 // datetime in 'yyyy-mm-dd_hh-mm-ss' format
88 let summaryTimeOrig = isoFileDateTime;
89 // let summaryTime = mid( summaryTime, 1, strindex( summaryTime, "_" ) - 1 );
90 let summaryTime = mid( summaryTimeOrig, 1, strindex( summaryTimeOrig, "_" ) - 1 );
91 let tmpHr = mid( summaryTimeOrig, ( strindex( summaryTimeOrig, "_" ) + 1) , 2 );
92 if tmpHr > 12 then
93 let tmpHr = format( (tmpHr - 12), 1, 0, "" );
94 let summaryTime = summaryTime & "_" & tmpHr & "pm";
95 else
96 let summaryTime = summaryTime & "_" & tmpHr & "am";
97 endif;
98 let _totalsFileName = "PAS_ExpectedTotals_" & summaryTime & ".txt";
99 let _file = SPHOME & "\\Output\\" & _totalsFileName;
100 let _type = "a";
101 gosub Open_File;
102 let hndSummary = fp;
103 endif;
104
105 if mode = "" then
106 print "No mode supplied, exiting....";
107 END;
108 endif;
109
110 if docs = "" then
111 print "No docs supplied, exiting....";
112 END;
113 endif;
114
115 if banner = "" then
116// print "No banner supplied exiting....";
117// END
118 let banner = "NA";
119 else
120 let _file = banner;
121 let _type = "r";
122 gosub Check_File_Exists;
123 if exists = FALSE then
124 print "Banner " & _file & " does not exist";
125 END;
126 else
127 let inLastSlash = search ( banner, "\\", len ( banner ), -1 );
128 if inLastSlash > 0 then
129 let bannerFilename = mid ( banner, (inLastSlash + 1), len (banner) );
130 else
131 let bannerFilename = banner;
132 endif;
133 endif;
134 endif;
135
136 if delivery = "" then
137 print "No delivery supplied, exiting....";
138 END;
139 else
140 if delivery <> "test" and delivery <> "post" and delivery <> "print" then
141 print "Delivery type not recognised, exiting....";
142 END;
143 endif;
144 endif;
145
146 if run_now = 1 then
147 print "Running live with no date modifications.";
148 let date = " between subdate(now(), interval 20 day) AND now() ";
149 else
150 if date1 = "" then
151 PRINT "Must specify a Start SQL date for test script. If you're reading this and not sure what it means, you've got the wrong script.";
152 END;
153 endif
154
155 if date2 = "" then
156 PRINT "Must specify an End SQL date for test script. If you're reading this and not sure what it means, you've got the wrong script.";
157 END;
158 endif
159
160 let date = " between '" & date1 & "' AND '" & date2 & "'";
161 endif
162
163
164
165 print "Running stream for mode [" & mode & "], docs [" & docs & "], banner [" & banner & "] and delivery [" & delivery & "]\n";
166
167 let set = FALSE;
168 let stream = "0";
169
170 if mode = "MONO|DUPLEX|STD" then
171 let stream = "1";
172 let streamdesc = "2nd Class Standard";
173 endif
174 if mode = "MONO|DUPLEX|STD|DM" then
175 let stream = "2";
176 let streamdesc = "2nd Class Dirty Mail";
177 endif
178 if mode = "MONO|DUPLEX|STD|OLA" then
179 let stream = "3";
180 let streamdesc = "2nd Class Overseas";
181 endif
182 if mode = "MONO|DUPLEX|STD|OS" then
183 let stream = "4";
184 let streamdesc = "2nd Class Oversized";
185 endif
186 if mode = "MONO|DUPLEX|DL" then
187 let stream = "5";
188 let streamdesc = "2nd Class DL";
189 endif
190 if mode = "MONO|DUPLEX|DL|DM" then
191 let stream = "6";
192 let streamdesc = "2nd Class DL Dirty Mail";
193 endif
194 if mode = "MONO|DUPLEX|DL|OLA" then
195 let stream = "7";
196 let streamdesc = "2nd Class DL Overseas";
197 endif
198 if mode = "MONO|DUPLEX|DL|OS" then
199 let stream = "8";
200 let streamdesc = "2nd Class DL Oversized";
201 endif
202 //********** FIRST CLASS STREAMS v1.03 ***********
203 if mode = "MONO|DUPLEX|FRST" then
204 let stream = "9";
205 let streamdesc = "1st Class Standard";
206 endif
207 if mode = "MONO|DUPLEX|FRST|DM" then
208 let stream = "10";
209 let streamdesc = "1st Class Dirty Mail";
210 endif
211 if mode = "MONO|DUPLEX|FRST|OLA" then
212 let stream = "11";
213 let streamdesc = "1st Class Overseas";
214 endif
215 if mode = "MONO|DUPLEX|FRST|OS" then
216 let stream = "12";
217 let streamdesc = "1st Class Oversized";
218 endif
219 //*************************************
220
221 print "*********** Starting stream [" & mode & "] ***********";
222
223 if stream = "0" then
224 print "Mode not found exiting....";
225 END;
226 endif;
227
228 let DEBUG = TRUE;
229 let DBServerName = "localhost"
230 let DBServerPort = 55010
231 let bDBCon = "FALSE"
232 let _bAddJobOK = FALSE;
233
234 let PBHOME = SPHOME;
235 let DIRSEP = "\\";
236 let _bCnt = "1";
237 let _uCnt = "0";
238
239 let outputRunIdent = "";
240
241 let _pdfmode = 0;
242 let _keepUncompressed = 0;
243 let _compressedMode = 0;
244 let _isHomeSet = 0;
245 let _seq = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
246 let _seqPos = format(1, 1, 0, "");
247 let _pgCntInBatch = format( 0, 1, 0, "" );
248 let _CHIcnt = format( 1, 1, 0, "" );
249
250 let QUEUENAME = "";
251 let DOCADDJOBQUEUE = "FromPrintRoom";
252 let DOCADDJOBQUEUECNTRL = "PrintRoomCntrl";
253 let NETSENDHOST = "localhost";
254 let NETSENDPORT = "50002";
255
256 let AIMS100P_CTRLFILE = "Output\\ControlFiles\\NEO2D_100P.cfg";
257 let AIMS100D_CTRLFILE = "Output\\ControlFiles\\NEO2D_100D.cfg";
258 let AIMS500_CTRLFILE = "Output\\ControlFiles\\NEO2D.cfg";
259 let aimsType = "";
260 let aims100Seq = "DOC"; // Set a default sequence type
261
262 let _status = "";
263
264 // Get system configuration values
265 gosub OpenDataBase;
266 let SQL = "SELECT config_name, config_value FROM publisure_config WHERE config_name IN ('KeepUncompressed','ImageStreamsDefault', 'PDFMode', 'CompressedMode', 'AIMS_Type');";
267 gosub DO_SQL_SELECT_1;
268 if (RET = FALSE) then
269 gosub CleanUp;
270 print "Failed Select. Exiting...";
271 END
272 endif
273 if RET = TRUE and GetRecordCount(#1) > 0 then
274 LOOP
275 let config_name = GetFieldByName(#1, "config_name");
276 let config_value = GetFieldByName(#1, "config_value");
277
278 if config_value = "1" then
279 if config_name = "KeepUncompressed" then
280 let _keepUncompressed = 1;
281 endif;
282 if config_name = "PDFMode" then
283 let _pdfmode = 1;
284 endif;
285 if config_name = "CompressedMode" then
286 let _compressedMode = 1;
287 endif;
288 endif;
289
290 if config_value = "0" then
291 if config_name = "ImageStreamsDefault" then
292 let _isHomeSet = 1;
293 endif;
294 endif;
295
296 if config_name = "AIMS_Type" then
297 if config_value = "100P" or config_value = "100p" then
298 let NEO2D_CTRLFILE = AIMS100P_CTRLFILE;
299 let aimsType = "100";
300 let aims100Seq = "PAGE";
301 endif;
302 if config_value = "100D" or config_value = "100d" then
303 let NEO2D_CTRLFILE = AIMS100D_CTRLFILE;
304 let aimsType = "100";
305 let aims100Seq = "DOC";
306 endif;
307 if left( config_value, 3 ) <> "100" then
308 let NEO2D_CTRLFILE = AIMS500_CTRLFILE;
309 let aimsType = config_value;
310 endif;
311 endif;
312
313 let _status = _status & "| Config: " & config_name & ", Value: " & config_value;
314 print "\tConfig: " & config_name & " = " & config_value;
315
316 if ( GetNextRecord( #1 ) = FALSE ) then
317 exitloop;
318 endif;
319 endloop;
320 endif;
321 CloseRecordset #1;
322
323 if _pdfmode = 1 then
324 // Currently we cannot stamp barcodes on PDFs
325 print "PDF mode not supported for IPR implementations. Barcodes cannot be stamped onto PDF at this time. Exiting.....";
326 END;
327 endif;
328
329 // Mark all available items for this stream (mode) as 'in progress'
330 gosub OpenDataBase;
331 let _sqlGetId = FALSE;
332
333 /* let SQL="UPDATE mailsort SET execution_set = '-14' WHERE execution_set = '0' AND recall_item = 0 AND deliveryMethod = 'post' AND failed = 0;"; */
334
335 /*****************************/
336 /* 1 = MONO|DUPLEX|STD */
337 /* 2 = MONO|DUPLEX|STD|DM */
338 /* 3 = MONO|DUPLEX|STD|OLA */
339 /* 4 = MONO|DUPLEX|STD|OS */
340 /* */
341 /* 5 = MONO|DUPLEX|DL */
342 /* 6 = MONO|DUPLEX|DL|DM */
343 /* 7 = MONO|DUPLEX|DL|OLA /
344 /* 8 = MONO|DUPLEX|DL|OS */
345 /* */
346 /* 9 = MONO|DUPLEX|FRST */
347 /* 10 = MONO|DUPLEX|FRST|DM */
348 /* 11 = MONO|DUPLEX|FRST|OLA */
349 /* 12 = MONO|DUPLEX|FRST|OS */
350 /*****************************/
351
352 if stream = "1" then
353 let SQL = "UPDATE mailsort SET execution_set = '-14' WHERE duplex='duplex' AND colour='mono' and ssc120 <> '999' AND postageTypeId in (0,2) AND envtype = 1 AND physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, attachments)), 0) <= 8 AND execution_set = '0' AND recall_item = 0 AND deliveryMethod = '" & delivery & "' AND failed = 0 AND doc_type in (" & docs & ") AND time_submitted " & date & ";";
354 endif;
355 if stream = "2" then
356 let SQL = "UPDATE mailsort SET execution_set = '-14' WHERE duplex='duplex' AND colour='mono' and ssc120 = '999' AND intchecked <> 2 AND postageTypeId in (0,2) AND envtype = 1 AND physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, attachments)), 0) <= 8 AND execution_set = '0' AND recall_item = 0 AND deliveryMethod = '" & delivery & "' AND failed = 0 AND doc_type in (" & docs & ") AND time_submitted " & date & ";";
357 endif;
358 if stream = "3" then
359 let SQL = "UPDATE mailsort SET execution_set = '-14' WHERE duplex='duplex' AND colour='mono' and ssc120 = '999' AND intchecked = 2 AND postageTypeId in (0,2) AND envtype = 1 AND physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, attachments)), 0) <= 8 AND execution_set = '0' AND recall_item = 0 AND deliveryMethod = '" & delivery & "' AND failed = 0 AND doc_type in (" & docs & ") AND time_submitted " & date & ";";
360 endif;
361 if stream = "4" then
362 let SQL = "UPDATE mailsort SET execution_set = '-14' WHERE duplex='duplex' AND colour='mono' AND envtype = 1 AND physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, attachments)), 0) > 8 AND postageTypeId in (0,2) AND execution_set = '0' AND recall_item = 0 AND deliveryMethod = '" & delivery & "' AND failed = 0 AND doc_type in (" & docs & ") AND time_submitted " & date & ";";
363 endif;
364 if stream = "5" then
365 let SQL = "UPDATE mailsort SET execution_set = '-14' WHERE duplex='duplex' AND colour='mono' and ssc120 <> '999' AND postageTypeId in (0,2) AND envtype = 5 AND physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, attachments)), 0) <= 8 AND execution_set = '0' AND recall_item = 0 AND deliveryMethod = '" & delivery & "' AND failed = 0 AND doc_type in (" & docs & ") AND time_submitted " & date & ";";
366 endif;
367 if stream = "6" then
368 let SQL = "UPDATE mailsort SET execution_set = '-14' WHERE duplex='duplex' AND colour='mono' and ssc120 = '999' AND intchecked <> 2 AND postageTypeId in (0,2) AND envtype = 5 AND physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, attachments)), 0) <= 8 AND execution_set = '0' AND recall_item = 0 AND deliveryMethod = '" & delivery & "' AND failed = 0 AND doc_type in (" & docs & ") AND time_submitted " & date & ";";
369 endif;
370 if stream = "7" then
371 let SQL = "UPDATE mailsort SET execution_set = '-14' WHERE duplex='duplex' AND colour='mono' and ssc120 = '999' AND intchecked = 2 AND postageTypeId in (0,2) AND envtype = 5 AND physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, attachments)), 0) <= 8 AND execution_set = '0' AND recall_item = 0 AND deliveryMethod = '" & delivery & "' AND failed = 0 AND doc_type in (" & docs & ") AND time_submitted " & date & ";";
372 endif;
373 if stream = "8" then
374 let SQL = "UPDATE mailsort SET execution_set = '-14' WHERE duplex='duplex' AND colour='mono' AND postageTypeId in (0,2) AND envtype = 5 AND physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, attachments)), 0) > 8 AND execution_set = '0' AND recall_item = 0 AND deliveryMethod = '" & delivery & "' AND failed = 0 AND doc_type in (" & docs & ") AND time_submitted " & date & ";";
375 endif;
376 //******** NEW FIRST CLASS ********
377 if stream = "9" then
378 let SQL = "UPDATE mailsort SET execution_set = '-14' WHERE duplex='duplex' AND colour='mono' and ssc120 <> '999' AND postageTypeId=1 AND envtype = 1 AND physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, attachments)), 0) <= 8 AND execution_set = '0' AND recall_item = 0 AND deliveryMethod = '" & delivery & "' AND failed = 0 AND doc_type in (" & docs & ") AND time_submitted " & date & ";";
379 endif;
380 if stream = "10" then
381 let SQL = "UPDATE mailsort SET execution_set = '-14' WHERE duplex='duplex' AND colour='mono' and ssc120 = '999' AND postageTypeId=1 AND intchecked <> 2 AND envtype = 1 AND physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, attachments)), 0) <= 8 AND execution_set = '0' AND recall_item = 0 AND deliveryMethod = '" & delivery & "' AND failed = 0 AND doc_type in (" & docs & ") AND time_submitted " & date & ";";
382 endif;
383 if stream = "11" then
384 let SQL = "UPDATE mailsort SET execution_set = '-14' WHERE duplex='duplex' AND colour='mono' and ssc120 = '999' AND postageTypeId=1 AND intchecked = 2 AND envtype = 1 AND physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, attachments)), 0) <= 8 AND execution_set = '0' AND recall_item = 0 AND deliveryMethod = '" & delivery & "' AND failed = 0 AND doc_type in (" & docs & ") AND time_submitted " & date & ";";
385 endif;
386 if stream = "12" then
387 let SQL = "UPDATE mailsort SET execution_set = '-14' WHERE duplex='duplex' AND colour='mono' AND envtype = 1 AND postageTypeId=1 AND physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, attachments)), 0) > 8 AND execution_set = '0' AND recall_item = 0 AND deliveryMethod = '" & delivery & "' AND failed = 0 AND doc_type in (" & docs & ") AND time_submitted " & date & ";";
388 endif;
389 //*********************************
390 gosub DO_SQL_EXECUTE;
391 if RET = FALSE THEN
392 print "Failed to mark items for output processing. Error( " & GetLastError() & ")";
393 END;
394 endif;
395
396 /* let SQL = "SELECT ma.DS_FilePath AS FilePath, UPPER(replace (LEFT(UUID(), 11), '-', '')) AS BatchRef, NOW() as Creation, ma.record_id AS RecordIndex,ma.pages AS DocuPages,ma.physicalpages AS DocuPhysicalPages, ma.envtype AS PostageType, ma.company AS departID, ma.doc_type AS DocID ,ma.uuid AS DocRef, ma.company AS departmentname, ma.title AS documentname,ma.duplex as DocDuplex,ma.colour AS DocColour,'' AS BranchCode,'' AS RecipEmail,ma.address1 AS address1,ma.address2 AS address2,ma.address3 AS address3,ma.address4 AS address4,ma.address5 AS address5,ma.address6 AS address6,ma.address7 AS address7,ma.buuid AS BatchID,ma.uuid AS UniqueID, '' AS DocType FROM mailsort AS ma WHERE ma.execution_set = '-14' and ma.recall_item = 0 AND ma.deliveryMethod='post' AND ma.failed = 0 ORDER BY ma.record_id asc;"; */
397
398 /*****************************/
399 /* 1 = MONO|DUPLEX|STD */
400 /* 2 = MONO|DUPLEX|STD|DM */
401 /* 3 = MONO|DUPLEX|STD|OLA */
402 /* 4 = MONO|DUPLEX|STD|OS */
403 /* */
404 /* 5 = MONO|DUPLEX|DL */
405 /* 6 = MONO|DUPLEX|DL|DM */
406 /* 7 = MONO|DUPLEX|DL|OLA */
407 /* 8 = MONO|DUPLEX|DL|OS */
408 /* */
409 /* 9 = MONO|DUPLEX|FRST */
410 /* 10 = MONO|DUPLEX|FRST|DM */
411 /* 11 = MONO|DUPLEX|FRST|OLA */
412 /* 12 = MONO|DUPLEX|FRST|OS */
413 /*****************************/
414
415 // Now get the data for all available records for this stream
416 if stream = "1" then
417 let SQL = "SELECT ma.DS_FilePath AS FilePath, UPPER(replace (LEFT(UUID(), 11), '-', '')) AS BatchRef, NOW() as Creation, ma.record_id AS RecordIndex, ma.pages + IFNULL((SELECT SUM(s.pages) FROM resources r JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET (r.resuniid, ma.attachments)),0) as DocuPages, ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) as DocuPhysicalPages, ma.attachments as attachments, ma.pubkeyfield01 as CHInum, ma.envtype AS PostageType, ma.company AS departID, ma.doc_type AS DocID ,ma.uuid AS DocRef, ma.company AS departmentname, ma.title AS documentname,ma.duplex as DocDuplex,ma.colour AS DocColour,'' AS BranchCode,'' AS RecipEmail,ma.address1 AS address1,ma.address2 AS address2,ma.address3 AS address3,ma.address4 AS address4,ma.address5 AS address5,ma.address6 AS address6,ma.address7 AS address7,ma.buuid AS BatchID,ma.uuid AS UniqueID, '' AS DocType FROM mailsort AS ma WHERE ma.duplex='duplex' AND ma.colour='mono' and ma.ssc120 <> '999' AND ma.envtype = 1 AND ma.postageTypeId in (0,2) AND ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) <= 8 AND ma.execution_set = '-14' and ma.recall_item = 0 AND ma.deliveryMethod='" & delivery & "' AND ma.failed = 0 AND ma.doc_type in (" & docs & ") AND ma.time_submitted " & date & " ORDER BY ma.record_id asc;";
418 endif;
419 if stream = "2" then
420 let SQL = "SELECT ma.DS_FilePath AS FilePath, UPPER(replace (LEFT(UUID(), 11), '-', '')) AS BatchRef, NOW() as Creation, ma.record_id AS RecordIndex, ma.pages + IFNULL((SELECT SUM(s.pages) FROM resources r JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET (r.resuniid, ma.attachments)),0) as DocuPages, ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) as DocuPhysicalPages, ma.attachments as attachments, ma.pubkeyfield01 as CHInum, ma.envtype AS PostageType, ma.company AS departID, ma.doc_type AS DocID ,ma.uuid AS DocRef, ma.company AS departmentname, ma.title AS documentname,ma.duplex as DocDuplex,ma.colour AS DocColour,'' AS BranchCode,'' AS RecipEmail,ma.address1 AS address1,ma.address2 AS address2,ma.address3 AS address3,ma.address4 AS address4,ma.address5 AS address5,ma.address6 AS address6,ma.address7 AS address7,ma.buuid AS BatchID,ma.uuid AS UniqueID, '' AS DocType FROM mailsort AS ma WHERE ma.duplex='duplex' AND ma.colour='mono' and ma.ssc120 = '999' AND ma.intchecked <> 2 AND ma.envtype = 1 AND ma.postageTypeId in (0,2) AND ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) <= 8 AND ma.execution_set = '-14' and ma.recall_item = 0 AND ma.deliveryMethod='" & delivery & "' AND ma.failed = 0 AND ma.doc_type in (" & docs & ") AND ma.time_submitted " & date & " ORDER BY ma.record_id asc;";
421 endif;
422 if stream = "3" then
423 let SQL = "SELECT ma.DS_FilePath AS FilePath, UPPER(replace (LEFT(UUID(), 11), '-', '')) AS BatchRef, NOW() as Creation, ma.record_id AS RecordIndex, ma.pages + IFNULL((SELECT SUM(s.pages) FROM resources r JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET (r.resuniid, ma.attachments)),0) as DocuPages, ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) as DocuPhysicalPages, ma.attachments as attachments, ma.pubkeyfield01 as CHInum, ma.envtype AS PostageType, ma.company AS departID, ma.doc_type AS DocID ,ma.uuid AS DocRef, ma.company AS departmentname, ma.title AS documentname,ma.duplex as DocDuplex,ma.colour AS DocColour,'' AS BranchCode,'' AS RecipEmail,ma.address1 AS address1,ma.address2 AS address2,ma.address3 AS address3,ma.address4 AS address4,ma.address5 AS address5,ma.address6 AS address6,ma.address7 AS address7,ma.buuid AS BatchID,ma.uuid AS UniqueID, '' AS DocType FROM mailsort AS ma WHERE ma.duplex='duplex' AND ma.colour='mono' and ma.ssc120 = '999' AND ma.intchecked = 2 AND ma.envtype = 1 AND ma.postageTypeId in (0,2) AND ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) <= 8 AND ma.execution_set = '-14' and ma.recall_item = 0 AND ma.deliveryMethod='" & delivery & "' AND ma.failed = 0 AND ma.doc_type in (" & docs & ") AND ma.time_submitted " & date & " ORDER BY ma.record_id asc;";
424 endif;
425 if stream = "4" then
426 let SQL = "SELECT ma.DS_FilePath AS FilePath, UPPER(replace (LEFT(UUID(), 11), '-', '')) AS BatchRef, NOW() as Creation, ma.record_id AS RecordIndex, ma.pages + IFNULL((SELECT SUM(s.pages) FROM resources r JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET (r.resuniid, ma.attachments)),0) as DocuPages, ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) as DocuPhysicalPages, ma.attachments as attachments, ma.pubkeyfield01 as CHInum, ma.envtype AS PostageType, ma.company AS departID, ma.doc_type AS DocID ,ma.uuid AS DocRef, ma.company AS departmentname, ma.title AS documentname,ma.duplex as DocDuplex,ma.colour AS DocColour,'' AS BranchCode,'' AS RecipEmail,ma.address1 AS address1,ma.address2 AS address2,ma.address3 AS address3,ma.address4 AS address4,ma.address5 AS address5,ma.address6 AS address6,ma.address7 AS address7,ma.buuid AS BatchID,ma.uuid AS UniqueID, '' AS DocType FROM mailsort AS ma WHERE ma.duplex='duplex' AND ma.colour='mono' AND ma.envtype = 1 AND ma.postageTypeId in (0,2) AND ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) > 8 AND ma.execution_set = '-14' and ma.recall_item = 0 AND ma.deliveryMethod='" & delivery & "' AND ma.failed = 0 AND ma.doc_type in (" & docs & ") AND ma.time_submitted " & date & " ORDER BY ma.record_id asc;";
427 endif;
428 if stream = "5" then
429 let SQL = "SELECT ma.DS_FilePath AS FilePath, UPPER(replace (LEFT(UUID(), 11), '-', '')) AS BatchRef, NOW() as Creation, ma.record_id AS RecordIndex, ma.pages + IFNULL((SELECT SUM(s.pages) FROM resources r JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET (r.resuniid, ma.attachments)),0) as DocuPages, ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) as DocuPhysicalPages, ma.attachments as attachments, ma.pubkeyfield01 as CHInum, ma.envtype AS PostageType, ma.company AS departID, ma.doc_type AS DocID ,ma.uuid AS DocRef, ma.company AS departmentname, ma.title AS documentname,ma.duplex as DocDuplex,ma.colour AS DocColour,'' AS BranchCode,'' AS RecipEmail,ma.address1 AS address1,ma.address2 AS address2,ma.address3 AS address3,ma.address4 AS address4,ma.address5 AS address5,ma.address6 AS address6,ma.address7 AS address7,ma.buuid AS BatchID,ma.uuid AS UniqueID, '' AS DocType FROM mailsort AS ma WHERE ma.duplex='duplex' AND ma.colour='mono' and ma.ssc120 <> '999' AND ma.envtype = 5 AND ma.postageTypeId in (0,2) AND ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) <= 8 AND ma.execution_set = '-14' and ma.recall_item = 0 AND ma.deliveryMethod='" & delivery & "' AND ma.failed = 0 AND ma.doc_type in (" & docs & ") AND ma.time_submitted " & date & " ORDER BY ma.record_id asc;";
430 endif;
431 if stream = "6" then
432 let SQL = "SELECT ma.DS_FilePath AS FilePath, UPPER(replace (LEFT(UUID(), 11), '-', '')) AS BatchRef, NOW() as Creation, ma.record_id AS RecordIndex, ma.pages + IFNULL((SELECT SUM(s.pages) FROM resources r JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET (r.resuniid, ma.attachments)),0) as DocuPages, ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) as DocuPhysicalPages, ma.attachments as attachments, ma.pubkeyfield01 as CHInum, ma.envtype AS PostageType, ma.company AS departID, ma.doc_type AS DocID ,ma.uuid AS DocRef, ma.company AS departmentname, ma.title AS documentname,ma.duplex as DocDuplex,ma.colour AS DocColour,'' AS BranchCode,'' AS RecipEmail,ma.address1 AS address1,ma.address2 AS address2,ma.address3 AS address3,ma.address4 AS address4,ma.address5 AS address5,ma.address6 AS address6,ma.address7 AS address7,ma.buuid AS BatchID,ma.uuid AS UniqueID, '' AS DocType FROM mailsort AS ma WHERE ma.duplex='duplex' AND ma.colour='mono' and ma.ssc120 = '999' AND ma.intchecked <> 2 AND ma.envtype = 5 AND ma.postageTypeId in (0,2) AND ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) <= 8 AND ma.execution_set = '-14' and ma.recall_item = 0 AND ma.deliveryMethod='" & delivery & "' AND ma.failed = 0 AND ma.doc_type in (" & docs & ") AND ma.time_submitted " & date & " ORDER BY ma.record_id asc;";
433 endif
434 if stream = "7" then
435 let SQL = "SELECT ma.DS_FilePath AS FilePath, UPPER(replace (LEFT(UUID(), 11), '-', '')) AS BatchRef, NOW() as Creation, ma.record_id AS RecordIndex, ma.pages + IFNULL((SELECT SUM(s.pages) FROM resources r JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET (r.resuniid, ma.attachments)),0) as DocuPages, ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) as DocuPhysicalPages, ma.attachments as attachments, ma.pubkeyfield01 as CHInum, ma.envtype AS PostageType, ma.company AS departID, ma.doc_type AS DocID ,ma.uuid AS DocRef, ma.company AS departmentname, ma.title AS documentname,ma.duplex as DocDuplex,ma.colour AS DocColour,'' AS BranchCode,'' AS RecipEmail,ma.address1 AS address1,ma.address2 AS address2,ma.address3 AS address3,ma.address4 AS address4,ma.address5 AS address5,ma.address6 AS address6,ma.address7 AS address7,ma.buuid AS BatchID,ma.uuid AS UniqueID, '' AS DocType FROM mailsort AS ma WHERE ma.duplex='duplex' AND ma.colour='mono' and ma.ssc120 = '999' AND ma.intchecked = 2 AND ma.envtype = 5 AND ma.postageTypeId in (0,2) AND ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) <= 8 AND ma.execution_set = '-14' and ma.recall_item = 0 AND ma.deliveryMethod='" & delivery & "' AND ma.failed = 0 AND ma.doc_type in (" & docs & ") AND ma.time_submitted " & date & " ORDER BY ma.record_id asc;";
436 endif;
437 if stream = "8" then
438 let SQL = "SELECT ma.DS_FilePath AS FilePath, UPPER(replace (LEFT(UUID(), 11), '-', '')) AS BatchRef, NOW() as Creation, ma.record_id AS RecordIndex, ma.pages + IFNULL((SELECT SUM(s.pages) FROM resources r JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET (r.resuniid, ma.attachments)),0) as DocuPages, ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) as DocuPhysicalPages, ma.attachments as attachments, ma.pubkeyfield01 as CHInum, ma.envtype AS PostageType, ma.company AS departID, ma.doc_type AS DocID ,ma.uuid AS DocRef, ma.company AS departmentname, ma.title AS documentname,ma.duplex as DocDuplex,ma.colour AS DocColour,'' AS BranchCode,'' AS RecipEmail,ma.address1 AS address1,ma.address2 AS address2,ma.address3 AS address3,ma.address4 AS address4,ma.address5 AS address5,ma.address6 AS address6,ma.address7 AS address7,ma.buuid AS BatchID,ma.uuid AS UniqueID, '' AS DocType FROM mailsort AS ma WHERE ma.duplex='duplex' AND ma.colour='mono' AND ma.envtype = 5 AND ma.postageTypeId in (0,2) AND ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) > 8 AND ma.execution_set = '-14' and ma.recall_item = 0 AND ma.deliveryMethod='" & delivery & "' AND ma.failed = 0 AND ma.doc_type in (" & docs & ") AND ma.time_submitted " & date & " ORDER BY ma.record_id asc;";
439 endif;
440 //**** NEW FIRST CLASS ******
441 if stream = "9" then
442 let SQL = "SELECT ma.DS_FilePath AS FilePath, UPPER(REPLACE(LEFT(UUID(), 11), '-', '')) AS BatchRef, NOW() as Creation, ma.record_id AS RecordIndex, ma.pages + IFNULL((SELECT SUM(s.pages) FROM resources r JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET (r.resuniid, ma.attachments)),0) as DocuPages, ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) as DocuPhysicalPages, ma.attachments as attachments, ma.pubkeyfield01 as CHInum, ma.envtype AS PostageType, ma.company AS departID, ma.doc_type AS DocID ,ma.uuid AS DocRef, ma.company AS departmentname, ma.title AS documentname,ma.duplex as DocDuplex,ma.colour AS DocColour,'' AS BranchCode,'' AS RecipEmail,ma.address1 AS address1,ma.address2 AS address2,ma.address3 AS address3,ma.address4 AS address4,ma.address5 AS address5,ma.address6 AS address6,ma.address7 AS address7,ma.buuid AS BatchID,ma.uuid AS UniqueID, '' AS DocType FROM mailsort AS ma WHERE ma.duplex='duplex' AND ma.colour='mono' and ma.ssc120 <> '999' AND ma.envtype = 1 AND ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) <= 8 AND ma.execution_set = '-14' AND ma.postageTypeId=1 and ma.recall_item = 0 AND ma.deliveryMethod='" & delivery & "' AND ma.failed = 0 AND ma.doc_type in (" & docs & ") AND ma.time_submitted " & date & " ORDER BY ma.record_id asc;";
443 endif;
444 if stream = "10" then
445 let SQL = "SELECT ma.DS_FilePath AS FilePath, UPPER(REPLACE(LEFT(UUID(), 11), '-', '')) AS BatchRef, NOW() as Creation, ma.record_id AS RecordIndex, ma.pages + IFNULL((SELECT SUM(s.pages) FROM resources r JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET (r.resuniid, ma.attachments)),0) as DocuPages, ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) as DocuPhysicalPages, ma.attachments as attachments, ma.pubkeyfield01 as CHInum, ma.envtype AS PostageType, ma.company AS departID, ma.doc_type AS DocID ,ma.uuid AS DocRef, ma.company AS departmentname, ma.title AS documentname,ma.duplex as DocDuplex,ma.colour AS DocColour,'' AS BranchCode,'' AS RecipEmail,ma.address1 AS address1,ma.address2 AS address2,ma.address3 AS address3,ma.address4 AS address4,ma.address5 AS address5,ma.address6 AS address6,ma.address7 AS address7,ma.buuid AS BatchID,ma.uuid AS UniqueID, '' AS DocType FROM mailsort AS ma WHERE ma.duplex='duplex' AND ma.colour='mono' and ma.ssc120 = '999' AND ma.intchecked <> 2 AND ma.envtype = 1 AND ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) <= 8 AND ma.postageTypeId=1 AND ma.execution_set = '-14' and ma.recall_item = 0 AND ma.deliveryMethod='" & delivery & "' AND ma.failed = 0 AND ma.doc_type in (" & docs & ") AND ma.time_submitted " & date & " ORDER BY ma.record_id asc;";
446 endif;
447 if stream = "11" then
448 let SQL = "SELECT ma.DS_FilePath AS FilePath, UPPER(REPLACE(LEFT(UUID(), 11), '-', '')) AS BatchRef, NOW() as Creation, ma.record_id AS RecordIndex, ma.pages + IFNULL((SELECT SUM(s.pages) FROM resources r JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET (r.resuniid, ma.attachments)),0) as DocuPages, ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) as DocuPhysicalPages, ma.attachments as attachments, ma.pubkeyfield01 as CHInum, ma.envtype AS PostageType, ma.company AS departID, ma.doc_type AS DocID ,ma.uuid AS DocRef, ma.company AS departmentname, ma.title AS documentname,ma.duplex as DocDuplex,ma.colour AS DocColour,'' AS BranchCode,'' AS RecipEmail,ma.address1 AS address1,ma.address2 AS address2,ma.address3 AS address3,ma.address4 AS address4,ma.address5 AS address5,ma.address6 AS address6,ma.address7 AS address7,ma.buuid AS BatchID,ma.uuid AS UniqueID, '' AS DocType FROM mailsort AS ma WHERE ma.duplex='duplex' AND ma.colour='mono' and ma.ssc120 = '999' AND ma.intchecked = 2 AND ma.envtype = 1 AND ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) <= 8 AND ma.postageTypeId=1 AND ma.execution_set = '-14' and ma.recall_item = 0 AND ma.deliveryMethod='" & delivery & "' AND ma.failed = 0 AND ma.doc_type in (" & docs & ") AND ma.time_submitted " & date & " ORDER BY ma.record_id asc;";
449 endif;
450 if stream = "12" then
451 let SQL = "SELECT ma.DS_FilePath AS FilePath, UPPER(REPLACE(LEFT(UUID(), 11), '-', '')) AS BatchRef, NOW() as Creation, ma.record_id AS RecordIndex, ma.pages + IFNULL((SELECT SUM(s.pages) FROM resources r JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET (r.resuniid, ma.attachments)),0) as DocuPages, ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) as DocuPhysicalPages, ma.attachments as attachments, ma.pubkeyfield01 as CHInum, ma.envtype AS PostageType, ma.company AS departID, ma.doc_type AS DocID ,ma.uuid AS DocRef, ma.company AS departmentname, ma.title AS documentname,ma.duplex as DocDuplex,ma.colour AS DocColour,'' AS BranchCode,'' AS RecipEmail,ma.address1 AS address1,ma.address2 AS address2,ma.address3 AS address3,ma.address4 AS address4,ma.address5 AS address5,ma.address6 AS address6,ma.address7 AS address7,ma.buuid AS BatchID,ma.uuid AS UniqueID, '' AS DocType FROM mailsort AS ma WHERE ma.duplex='duplex' AND ma.colour='mono' AND ma.envtype = 1 AND ma.physicalpages + IFNULL((SELECT (sum(s.pages)) DIV 2 FROM resources r left JOIN single s ON r.resourceid = s.resourceid WHERE FIND_IN_SET(r.resuniid, ma.attachments)), 0) > 8 AND ma.execution_set = '-14' and ma.recall_item = 0 AND ma.postageTypeId=1 AND ma.deliveryMethod='" & delivery & "' AND ma.failed = 0 AND ma.doc_type in (" & docs & ") AND ma.time_submitted " & date & " ORDER BY ma.record_id asc;";
452 endif;
453 //***************************
454 gosub DO_SQL_SELECT_1;
455 if RET = FALSE then
456 print "Failed to read items for output processing. Error [" & GetLastError() & "]";
457 END;
458 endif;
459
460 let NumItems = GetRecordCount( #1 );
461
462 print "\nStarting to process " & NumItems & " items on stream " & stream & " (" & mode & ")\n";
463
464
465 let Count = format( 1, 1, 0, "");
466 let _itemCount = format( 1, 1, 0, "");
467 let _limit = format( 500, 1, 0, "");
468 let _batchCount = format( 1, 1, 0, "");
469 let _totalItems = format( GetRecordCount(), 1, 0, "" );
470 if provideSummary = TRUE then
471 print!hndSummary "Stream " & rpad( streamdesc, 24 ) & " : Total number of expected items = " & _totalItems;
472 endif;
473 let DocBatchID = GetFieldByName( #1, "BatchRef" );
474 let _firstInBatch = TRUE;
475
476 //let FTIME = format(time(), 1, 0, "" );
477 let inDateTime = time();
478 gosub ConvertDateTime;
479 let FTIME = isoFileDateTime;
480
481 if _totalItems < _limit then
482 let _limit = _totalItems;
483 endif;
484
485 let preTFile1 = FTIME & "_" & DocBatchID & "_" & _batchCount & "_" & _itemCount & "-" & format( _limit, 1, 0, "");
486
487 print "\nDebug file [" & preTFile1 & "] totalItems [" & _totalItems & "] limit [" & _limit & "] \n";
488
489 /*****************************/
490 /* 1 = MONO|DUPLEX|STD */
491 /* 2 = MONO|DUPLEX|STD|DM */
492 /* 3 = MONO|DUPLEX|STD|OLA */
493 /* 4 = MONO|DUPLEX|STD|OS */
494 /* */
495 /* 5 = MONO|DUPLEX|DL */
496 /* 6 = MONO|DUPLEX|DL|DM */
497 /* 7 = MONO|DUPLEX|DL|OLA */
498 /* 8 = MONO|DUPLEX|DL|OS */
499 /* */
500 /* 9 = MONO|DUPLEX|FRST */
501 /* 10 = MONO|DUPLEX|FRST|DM */
502 /* 11 = MONO|DUPLEX|FRST|OLA */
503 /* 12 = MONO|DUPLEX|FRST|OS */
504 /*****************************/
505
506 // Modify output filename according to stream/mode
507 if stream = "1" then
508 let preTFile1 = "PAS_MONO_DUPLEX_STD_" & delivery & "_" & preTFile1;
509 endif;
510 if stream = "2" then
511 let preTFile1 = "PAS_MONO_DUPLEX_STD_DM_" & delivery & "_" & preTFile1;
512 endif;
513 if stream = "3" then
514 let preTFile1 = "PAS_MONO_DUPLEX_STD_OLA_" & delivery & "_" & preTFile1;
515 endif;
516 if stream = "4" then
517 let preTFile1 = "PAS_MONO_DUPLEX_STD_OS_" & delivery & "_" & preTFile1;
518 endif;
519 if stream = "5" then
520 let preTFile1 = "PAS_MONO_DUPLEX_DL_" & delivery & "_" & preTFile1;
521 endif;
522 if stream = "6" then
523 let preTFile1 = "PAS_MONO_DUPLEX_DL_DM_" & delivery & "_" & preTFile1;
524 endif;
525 if stream = "7" then
526 let preTFile1 = "PAS_MONO_DUPLEX_DL_OLA_" & delivery & "_" & preTFile1;
527 endif;
528 if stream = "8" then
529 let preTFile1 = "PAS_MONO_DUPLEX_DL_OS_" & delivery & "_" & preTFile1;
530 endif;
531 /********** NEW FIRST CLASS *********/
532 if stream = "9" then
533 let preTFile1 = "PAS_MONO_DUPLEX_FRST_" & delivery & "_" & preTFile1;
534 endif;
535 if stream = "10" then
536 let preTFile1 = "PAS_MONO_DUPLEX_FRST_DM_" & delivery & "_" & preTFile1;
537 endif;
538 if stream = "11" then
539 let preTFile1 = "PAS_MONO_DUPLEX_FRST_OLA_" & delivery & "_" & preTFile1;
540 endif;
541 if stream = "12" then
542 let preTFile1 = "PAS_MONO_DUPLEX_FRST_OS_" & delivery & "_" & preTFile1;
543 endif;
544 /************************************/
545
546 let preJAF = DocBatchID;
547
548 if _pdfmode = 1 then
549 let PDFFile = preTFile1 & "_OutputFile.pdf";
550 else
551 let PDFFile = preTFile1 & "_OutputFile.ps";
552 endif;
553
554 let FIRSTTIME = TRUE;
555 let _batchItemCount = format(1, 1, 0, "");
556
557 // Process each available record for this stream
558 LOOP
559 print "Processing item " & Count;
560 /* initialise */
561 let ItemRecordID = "";
562 let CHInum = "";
563 let Branch = "";
564 let ItemRef = "";
565 let LeadPassName = "";
566 let DocType = "";
567 let DocColour = "";
568 let _vFileName = ""
569 let DocUUID = "";
570 let chkDuplex = "";
571 let chkInsert = "";
572 let chkLetterHead = "";
573 let chkPostType = "";
574 let UserID = "";
575 let DocID = "";
576 let DepartID = "";
577 let DepartName = "";
578 let DocuName = "";
579 let DocuPages = "";
580 let PSMARKTEXT = "";
581 let PDFFileTmp = "";
582 let TrigFile = "";
583 let _bAddJobOK = FALSE;
584
585 let ItemRecordID = GetFieldByName( #1, "RecordIndex" );
586 let DocUUID = ItemRecordID;
587 if ( IsNotEmpty( ItemRecordID ) ) then
588 let _tFile1 = preTFile1 & "_" & ItemRecordID;
589 else
590 print "\tNo Record index, aborting";
591 exitloop;
592 endif;
593
594 let _vFileName = GetFieldByName( #1, "FilePath" );
595 let ItemRef = GetFieldByName( #1, "DocRef" );
596 let Branch = GetFieldByName( #1, "BranchCode" );
597 let DocID = GetFieldByName( #1, "DocID" );
598 let DepartID = GetFieldByName( #1, "departID" );
599 let DepartName = GetFieldByName( #1, "company" );
600 let DocuName = GetFieldByName( #1, "documentname" );
601 let _uCnt = format( (_uCnt + 1), 1, 0, "" );
602 let UserID = GetFieldByName( #1, "CustRef" );
603 let Creation = GetFieldByName( #1, "Creation" );
604 let chkDuplex = GetFieldByName( #1, "DocDuplex" );
605 let DocType = GetFieldByName( #1, "DocType" );
606 let DocuPages = GetFieldByName( #1, "DocuPages" );
607 let Duplex = GetFieldByName( #1, "DocDuplex" );
608 let DocColour = GetFieldByName( #1, "DocColour" );
609 let _atts = GetFieldByName( #1, "attachments");
610 let CHInum = GetFieldByName( #1, "CHInum");
611 let UUID = GetFieldByName( #1, "UniqueID");
612 let chkInsert = GetFieldByName( #1, "PhysAttach" );
613 let address1 = trim( GetFieldByName( #1, "address1" ) );
614 let address2 = trim( GetFieldByName( #1, "address2" ) );
615 let address3 = trim( GetFieldByName( #1, "address3" ) );
616 let address4 = trim( GetFieldByName( #1, "address4" ) );
617 let address5 = trim( GetFieldByName( #1, "address5" ) );
618 let address6 = trim( GetFieldByName( #1, "address6" ) );
619 let address7 = trim( GetFieldByName( #1, "address7" ) );
620 let DocuPhysicalPages = GetFieldByName( #1, "DocuPhysicalPages" );
621 let chkLetterHead = trim( GetFieldByName( #1, "PhysLetterHead" ));
622
623 // Ensure correct format for AIMS barcode - should give 10 zeroes if blank CHI/NHS num
624 let CHInum = lpadex ( CHInum, 0, 10 );
625
626 if trim( chkLetterHead ) = "" then
627 let chkLetterHead = "None";
628 endif;
629
630 if trim( chkInsert ) <> "" then
631 // gosub Full_Insert;
632 if trim( _vInsert ) <> "" then
633 let chkInsert = _vInsert;
634 let _vInsert = "";
635 endif;
636 else
637 let chkInsert = "None|None|None|None";
638 endif;
639
640 if ( IsNotEmpty( _vFileName ) ) then
641 let tmp = _vFileName & ".tmp";
642 let Count = lpadex( Count, 0, 10 );
643 let file_output = _batchCount & "_" & Count;
644
645 /* assume the inputfile will be compressed */
646 if _compressedMode = 1 then
647 gosub Decompress_File;
648 if( _uRet = FALSE ) then
649 print "Failed to decompress item";
650 exitloop;
651 endif;
652 else
653 gosub Copy_Decompressed_File
654 if( _uRet = FALSE ) then
655 print "Failed to copy item";
656 exitloop;
657 endif;
658 endif;
659
660 if trim( _atts ) <> "" then
661 gosub Set_Up_Attachments;
662 endif;
663 print "\tAttachments finished";
664
665 // Append document to current batch and, if necessary, add data to JAF.
666 gosub Create_Output;
667 if ( _uRet = FALSE ) then
668 print "Failed to create Output job";
669 gosub Update_Failed_Item;
670 exitloop;
671 else
672 gosub Update_DB_Ref;
673 if( _uRet = FALSE ) then
674 print "Failed to update execution";
675 gosub Update_Failed_Item;
676 exitloop;
677 endif;
678 endif;
679 else
680 print "\tFailed to get FileReference for (" & ItemRecordID & ")"
681 gosub Update_Failed_Item;
682 exitloop;
683 endif;
684
685 if FIRSTTIME = TRUE then
686 // prevent any banner from being added again and JAF file being created again
687 let FIRSTTIME = FALSE;
688 endif;
689
690 if Count = _limit then
691 // reached the max number of docs in this file
692 gosub Create_Final_File;
693
694 if (GetNextRecord( #1 ) = FALSE) then
695 print "\tNo More Records";
696 exitloop;
697 endif;
698
699 // Reset the counts for the next file in this batch
700 let Count = format( 1, 1, 0, "");
701 let _batchCount = format( ( _batchCount+1 ), 1, 0, "");
702 let _itemCount = format( ( _itemCount+1 ), 1, 0, "");
703
704 // print "item count = " & _itemCount & " limit = " & _limit & " total items = " & _totalItems;
705
706 if (_itemCount + _limit) >= _totalItems then
707 let _limitTag = _totalItems;
708 let _limit = format((_totalItems - _limit), 1, 0, "");
709 else
710 let _limitTag = format((_itemCount + _limit - 1), 1, 0, "");
711 endif
712
713 let preTFile1 = FTIME & "_" & DocBatchID & "_" & _batchCount & "_" & _itemCount & "-" & _limitTag;
714
715 print "\nDebug 2 file [" & preTFile1 & "] totalItems [" & _totalItems & "] limit [" & _limit & "] limitTag [" & _limitTag & "] \n";
716
717 /*****************************/
718 /* 1 = MONO|DUPLEX|STD */
719 /* 2 = MONO|DUPLEX|STD|DM */
720 /* 3 = MONO|DUPLEX|STD|OLA */
721 /* 4 = MONO|DUPLEX|STD|OS */
722 /* */
723 /* 5 = MONO|DUPLEX|DL */
724 /* 6 = MONO|DUPLEX|DL|DM */
725 /* 7 = MONO|DUPLEX|DL|OLA */
726 /* 8 = MONO|DUPLEX|DL|OS */
727 /* */
728 /* 9 = MONO|DUPLEX|FRST */
729 /* 10 = MONO|DUPLEX|FRST|DM */
730 /* 11 = MONO|DUPLEX|FRST|OLA */
731 /* 12 = MONO|DUPLEX|FRST|OS */
732 /*****************************/
733
734 if stream = "1" then
735 let preTFile1 = "PAS_MONO_DUPLEX_STD_" & delivery & "_" & preTFile1;
736 endif;
737 if stream = "2" then
738 let preTFile1 = "PAS_MONO_DUPLEX_STD_DM_" & delivery & "_" & preTFile1;
739 endif;
740 if stream = "3" then
741 let preTFile1 = "PAS_MONO_DUPLEX_STD_OLA_" & delivery & "_" & preTFile1;
742 endif;
743 if stream = "4" then
744 let preTFile1 = "PAS_MONO_DUPLEX_STD_OS_" & delivery & "_" & preTFile1;
745 endif;
746 if stream = "5" then
747 let preTFile1 = "PAS_MONO_DUPLEX_DL_" & delivery & "_" & preTFile1;
748 endif;
749 if stream = "6" then
750 let preTFile1 = "PAS_MONO_DUPLEX_DL_DM_" & delivery & "_" & preTFile1;
751 endif;
752 if stream = "7" then
753 let preTFile1 = "PAS_MONO_DUPLEX_DL_OLA_" & delivery & "_" & preTFile1;
754 endif;
755 if stream = "8" then
756 let preTFile1 = "PAS_MONO_DUPLEX_DL_OS_" & delivery & "_" & preTFile1;
757 endif;
758 /**** NEW FIRST CLASS *******/
759 if stream = "9" then
760 let preTFile1 = "PAS_MONO_DUPLEX_FRST_" & delivery & "_" & preTFile1;
761 endif;
762 if stream = "10" then
763 let preTFile1 = "PAS_MONO_DUPLEX_FRST_DM_" & delivery & "_" & preTFile1;
764 endif;
765 if stream = "11" then
766 let preTFile1 = "PAS_MONO_DUPLEX_FRST_OLA_" & delivery & "_" & preTFile1;
767 endif;
768 if stream = "12" then
769 let preTFile1 = "PAS_MONO_DUPLEX_FRST_OS_" & delivery & "_" & preTFile1;
770 endif;
771 /******************************/
772
773 let preJAF = DocBatchID;
774
775 if _pdfmode = 1 then
776 let PDFFile = preTFile1 & "_OutputFile.pdf";
777 else
778 let PDFFile = preTFile1 & "_OutputFile.ps";
779 endif;
780
781 let FIRSTTIME = TRUE;
782 else
783 let _itemCount = format((_itemCount+1), 1, 0, "");
784 let Count = format((Count+1), 1, 0, "");
785 endif ;
786
787 let _batchItemCount = format( (_batchItemCount + 1), 1, 0, "");
788
789 if ( GetNextRecord ( #1 ) = FALSE ) then
790 gosub Create_Final_File;
791 print "\tNo More Records";
792 exitloop;
793 endif;
794 endloop;
795
796 gosub Cleanup_Temps;
797
798 close hndSummary;
799
800 let _vTotals = _totalsFileName;
801
802
803 if aimsType <> "100" then
804 // Not an AIMS-100 machine so we need a JAF file
805 let QUEUENAME = DOCADDJOBQUEUECNTRL;
806 let TITLE = preJAF & ".jaf";
807 let FILE = PBHOME & "Output\\Final\\" & preJAF & ".jaf";
808 gosub Do_Add_Job;
809 endif;
810
811 gosub Record_Run;
812
813 print "\nNeopost Output script completed...";
814 GOSUB Clear_Totals_File;
815 //need to clear the old file first as frmcopy was simply appending the outputs.
816 GOSUB Copy_Totals_File;
817END
818
819//********************************************** END SCRIPT **************************************************
820
821:OpenDataBase
822
823 let RET = FALSE
824
825 if ( IsOpenDB() = FALSE ) then
826 for x = 1 to 10
827 if ( OpenDB( DBServerName, DBServerPort ) = FALSE ) then
828 print "Failed to connect to server: " & DBServerName & " On Port: " & DBServerPort & " Tries: " & x;
829 else
830 //print "Connected to Server: " & DBServerName & " On Port: " & DBServerPort;
831 let RET = TRUE;
832 exitfor;
833 endif;
834 next x;
835 endif;
836
837RETURN
838
839//***************************************************************************************
840:DO_SQL_SELECT_1
841
842 let RET = FALSE;
843 if SQL <> "" then
844 gosub OpenDataBase;
845 if ( DoSQLToRecordSet( #1,SQL ) = FALSE ) then
846 CloseDB;
847 print "Failed to get #1 record set. Error (" & GetLastError() & ") SQL [" & SQL & "]";
848 RETURN;
849 endif;;
850
851 if ( GetRecordCount( #1 ) = 0 ) then
852 CloseDB;
853 print "No #1 records to use. Error (" & GetLastError() & ") SQL [" & SQL & "]";
854 RETURN;
855 endif;
856
857 if ( OpenRecordSet( #1 ) = FALSE ) then
858 CloseDB;
859 print "Failed to open #1 record set. Error (" & GetLastError() & ") SQL [" & SQL & "]";
860 RETURN;
861 endif;
862
863 print "Number of #1 records ready to use: " & GetRecordCount( #1 ) & " SQL (" & SQL & ")";
864
865 let RET = TRUE;
866 endif;
867
868 CloseDB;
869
870RETURN
871
872//***************************************************************************************
873:DO_SQL_SELECT_2
874
875 let RET = FALSE;
876 if SQL <> "" then
877 gosub OpenDataBase;
878 if ( DoSQLToRecordSet( #2,SQL ) = FALSE ) then
879 CloseDB;
880 print "Failed to get #2 record set. Error (" & GetLastError() & ") SQL [" & SQL & "]";
881 RETURN;
882 endif;
883
884 if ( GetRecordCount( #2 ) = 0 ) then
885 CloseDB;
886 print "No #2 records to use. Error (" & GetLastError() & ") SQL [" & SQL & "]";
887 RETURN;
888 endif;
889
890 if ( OpenRecordSet( #2 ) = FALSE ) then
891 CloseDB;
892 print "Failed to open #2 record set. Error (" & GetLastError() & ") SQL [" & SQL & "]";
893 RETURN;
894 endif;
895
896 print "Number of #2 records ready to use: " & GetRecordCount( #2 ) & " SQL (" & SQL & ")";
897
898 let RET = TRUE;
899 endif;
900
901 CloseDB;
902
903RETURN
904
905//***************************************************************************************
906:DO_SQL_SELECT_3
907
908 let RET = FALSE;
909 if SQL <> "" then
910 gosub OpenDataBase;
911 if ( DoSQLToRecordSet( #3,SQL ) = FALSE) then
912 CloseDB;
913 print "Failed to get #3 record set. Error (" & GetLastError() & ") SQL [" & SQL & "]";
914 RETURN;
915 endif;
916 if ( GetRecordCount( #3 ) = 0 ) then
917 CloseDB;
918 print "No #3 records to use. Error (" & GetLastError() & ") SQL [" & SQL & "]";
919 RETURN;
920 endif;
921 if ( OpenRecordSet( #3 ) = FALSE ) then
922 CloseDB;
923 print "Failed to open #3 record set. Error (" & GetLastError() & ") SQL [" & SQL & "]";
924 RETURN;
925 endif;
926 print "Number of #3 records ready to use: " & GetRecordCount( #3 ) & " SQL (" & SQL & ")";
927
928 let RET = TRUE;
929 endif;
930
931 CloseDB;
932
933RETURN
934
935//***************************************************************************************
936:DO_SQL_EXECUTE
937
938 let RET = FALSE;
939 if SQL <> "" then
940 gosub OpenDataBase;
941 print "Opened DB, Query: (" & SQL & ")";
942 if ( DoSQLQuery( SQL ) = FALSE ) then
943 print "Execute to database failed. Error (" & GetLastError() & ") SQL [" & SQL & "]";
944 RETURN;
945 else
946 if _sqlGetId = TRUE then
947 let SQL = "SELECT last_insert_id() as 'lastId'";
948
949 gosub DO_SQL_SELECT_EXEC;
950
951 if RET = TRUE and GetRecordCount( #8 ) > 0 then
952 let _lastId = GetFieldByName( #8, "lastId");
953 print "last Id = " & _lastId;
954 else
955 print "Failed to get last ID. Error (" & GetLastError() & ") SQL [" & SQL & "]";
956 gosub CLEANUP;
957 RETURN;
958 endif;
959 endif;
960 endif;
961 endif;
962
963 let RET = TRUE;
964 let _sqlGetId = FALSE;
965
966 CloseDB;
967
968RETURN
969
970//***************************************************************************************
971:DO_SQL_SELECT_EXEC
972
973 let RET = FALSE;
974 if SQL <> "" then
975 gosub OpenDataBase;
976 if ( DoSQLToRecordSet( #8,SQL ) = FALSE ) then
977 CloseDB;
978 print "\tFailed to get exec record set. Error (" & GetLastError() & ") SQL [" & SQL & "]";
979 RETURN;
980 endif;
981 if ( GetRecordCount( #8 ) = 0 ) then
982 CloseDB;
983 print "\tNo exec records to use. Error (" & GetLastError() & ") SQL [" & SQL & "]";
984 RETURN;
985 endif;
986 if ( OpenRecordSet( #8 ) = FALSE ) then
987 CloseDB;
988 print "\tFailed to open exec record set. Error (" & GetLastError() & ") SQL [" & SQL & "]";
989 RETURN;
990 endif;
991
992 print "\tNumber of exec records ready to use: " & GetRecordCount( #8 ) & " SQL (" & SQL & ")";
993
994 let RET = TRUE;
995 endif;
996 CloseDB;
997
998RETURN
999
1000//***************************************************************************************
1001:Execute_Cmd
1002
1003 let _uRet = FALSE
1004
1005 if trim( CMD_LINE) <> "" then
1006 let CmdOutput = "";
1007 let _RETURN = PIPEEXEC( CMD_LINE, ADR(CmdOutput) );
1008 if (_RETURN = 0) then
1009 let _uRet = TRUE;
1010 print "\tSuccess (" & CMD_LINE & ")";
1011 else
1012 print "\tFailed (" & CMD_LINE & ")";
1013 endif;
1014 endif;
1015
1016RETURN
1017
1018//***************************************************************************************
1019
1020:Record_Run
1021
1022 let SQL = "INSERT INTO outputRuns (outUnique,outTitle,outStart,outEnd,outTotalItems,outTotalBatches) values ( '" & DocBatchID & "', '" & mode & "', '" & Creation & "', NOW(), '" & _totalItems & "', '" & _batchCount & "')";
1023 gosub DO_SQL_EXECUTE;
1024
1025RETURN
1026
1027//***************************************************************************************
1028:Decompress_File
1029 let _uRet = FALSE;
1030
1031 if( IsNotEmpty( _tFile1 ) AND IsNotEmpty( _vFileName ) ) then
1032
1033 let CMD_LINE = "spzip -d -i " & _vFileName & " -o Output\\Temp\\" & file_output & ".decomp";
1034 gosub Execute_Cmd;
1035
1036 if _pdfmode = 1 then
1037 let CMD_LINE = "frmps2pdf -i Output\\Temp\\" & file_output & ".decomp -o Output\\Temp\\" & file_output & ".2pdf";
1038 gosub Execute_Cmd;
1039 endif;
1040 endif;
1041return
1042
1043
1044
1045//***************************************************************************************
1046:Clear_Totals_File
1047
1048 let _uRet = FALSE;
1049
1050 let _delf = "\\\\YDH-NEOPOST\\c$\\IPR\\Output\\" & _vTotals;
1051 DELETEFILE _delf;
1052
1053return
1054
1055
1056//***************************************************************************************
1057:Copy_Totals_File
1058
1059 let _uRet = FALSE;
1060
1061 if ( IsNotEmpty( _vTotals ) ) then
1062
1063 let CMD_LINE = "frmcopy Output\\" & _vTotals & " \\\\YDH-NEOPOST\\c$\\IPR\\Output\\" & _vTotals;
1064 gosub Execute_Cmd;
1065
1066 endif;
1067return
1068
1069//***************************************************************************************
1070
1071//***************************************************************************************
1072:Copy_Decompressed_File
1073
1074 let _uRet = FALSE;
1075
1076 if( IsNotEmpty( _tFile1 ) AND IsNotEmpty( _vFileName ) ) then
1077
1078 let CMD_LINE = "frmcopy " & _vFileName & " Output\\Temp\\" & file_output & ".decomp";
1079 gosub Execute_Cmd;
1080
1081 if _pdfmode = 1 then
1082 let CMD_LINE = "frmps2pdf -i Output\\Temp\\" & file_output & ".decomp -o Output\\Temp\\" & file_output & ".2pdf";
1083 gosub Execute_Cmd;
1084 endif;
1085 endif;
1086return
1087
1088//***************************************************************************************
1089:Create_Final_File
1090
1091 if _pdfmode = 1 then
1092 let CMD_LINE = PBHOME & "\\sppdftk Output\\Temp\\*.dat cat output \"" & PBHOME & "\\Output\\Final\\" & PDFFile & "\"";
1093// let CMD_LINE = PBHOME & "\\frmcopy \"Output\\Temp\\" & PDFFile & "\" \"Output\\Temp\\" & PDFFile & "\"";
1094 else
1095 let CMD_LINE = PBHOME & "\\frmcopy \"Output\\Temp\\" & PDFFile & "\" \"Output\\Final\\" & PDFFile & "\"";
1096 gosub Execute_Cmd;
1097 if _uRet = FALSE then
1098 gosub Cleanup_Temps;
1099 close hndSummary;
1100 END;
1101 endif;
1102 // Now convert combined PS file to PDF
1103 let PDFOut = replace( PDFFile, ".ps", ".pdf" );
1104 let CMD_LINE = "frmps2pdf -i \"" & SPHOME & "\\Output\\Temp\\" & PDFFile & "\" -o \"" & SPHOME & "\\Output\\Final\\" & PDFOut & "\"";
1105 endif;
1106 gosub Execute_Cmd;
1107 if _uRet = FALSE then
1108 gosub Cleanup_Temps;
1109 close hndSummary;
1110 END;
1111 endif;
1112 let QUEUENAME = DOCADDJOBQUEUE;
1113 let TITLE = PDFFile;
1114 let FILE = PBHOME & "\\Output\\Final\\" & PDFFile;
1115 gosub Do_Add_Job;
1116 gosub Cleanup_Temps;
1117 if FIRSTTIME = FALSE then
1118 let FIRSTTIME = TRUE;
1119 endif;
1120RETURN
1121
1122
1123//***************************************************************************************
1124:Create_Output
1125
1126 let _uRet = FALSE;
1127 if( IsNotEmpty( preTFile1 ) ) then
1128
1129 print "\tFirst time? : " & FIRSTTIME;
1130
1131 if aimsType <> "100" then
1132 // Not an AIMS-100 machine so we need a JAF file
1133 // Syntax:
1134 // First row (header) H<JOBID><19spaces><CreationDateTime><Mode - padded to 32 spaces>
1135 // Subsequent rows B<JOBID><itemCount><32 spaces><31 zeroes><addr1...7><spaces>0
1136 if _firstInBatch = TRUE then
1137 let PSMARKTEXT = "H" & DocBatchID & rpad( "", 19) & Creation & rpad( mode, 32);
1138 let _file = PBHOME & "\\Output\\Final\\" & preJAF & ".jaf"
1139 let _type = "a";
1140 let _str = PSMARKTEXT;
1141 gosub Open_File;
1142 gosub Write_To_File;
1143 gosub Close_File;
1144 let _firstInBatch = FALSE;
1145 endif;
1146
1147 // let PSMARKTEXT = " " & chkDuplex & "|" & DocColour & "|" & DocuPages & "|" & DepartID & "|" & DocuName & "|" & DocBatchID & "|" & DocUUID & "|" & _batchItemCount & "|" & chkInsert & "|" & "DL" & "|" & chkPostType & "|" & chkLetterHead & "|" & " " & "|" & _address
1148 let PSMARKTEXT = "B" & DocBatchID & lpadex( _itemCount, 0, 10 ) & " 0000000000000000000000000000000" & rpad( address1, 50) & rpad( address2, 50) & rpad( address3, 50) & rpad( address4, 50) & rpad( address5, 50) & rpad( address6, 50) & rpad( address7, 50) & lpadex("", " ", 150) & "0";
1149 let PSMARKTEXT = replace( PSMARKTEXT, "'", " " );
1150 let PSMARKTEXT = replace( PSMARKTEXT, "\"", " " );
1151 let PSMARKTEXT = replace( PSMARKTEXT, "/", " " );
1152 let PSMARKTEXT = replace( PSMARKTEXT, "\\", " " );
1153 let _file = PBHOME & "\\Output\\Final\\" & preJAF & ".jaf";
1154 let _type = "a";
1155 let _str = PSMARKTEXT;
1156 gosub Open_File;
1157 gosub Write_To_File;
1158 gosub Close_File;
1159 endif;
1160
1161 /* USED for STAMPING WHITE TEXT HEADER - not required anymore for Neo AIMS */
1162 /*
1163 let PSMARKTEXT = " " & chkDuplex & "|" & DocColour & "|" & DocuPages & "|" & DepartID & "|" & DocuName & "|" & DocBatchID & "|" & DocUUID & "|" & _batchItemCount & "|" & chkInsert & "|" & "DL" & "|" & chkPostType & "|" & chkLetterHead & "|" & " "
1164 let PSMARKTEXT = replace (PSMARKTEXT, "'", " ");
1165 let PSMARKTEXT = replace (PSMARKTEXT, "\"", " ");
1166 let PSMARKTEXT = replace (PSMARKTEXT, "/", " ");
1167 let PSMARKTEXT = replace (PSMARKTEXT, "\\", " ");
1168
1169 let _file = PBHOME & "\\Output\\ControlFiles\\NEOTEXT.cfg";
1170 let _type = "r"
1171 let _str = PSMARKTEXT
1172
1173 gosub Open_File
1174 gosub Replace_In_File
1175 gosub Close_File
1176
1177 let _file = PBHOME & "\\Output\\ControlFiles\\NEOTEXT_STAMP.cfg";
1178 let _type = "w"
1179 let _str = _buffer;
1180
1181 gosub Open_File
1182 gosub Write_To_File
1183 gosub Close_File
1184 let PSMARKCMD_LINE = PBHOME & "\\sppdfpproc -i \"Output\\Temp\\" & file_output & ".2pdf\" -o \"Output\\Temp\\" & file_output & ".dat\" -c Output\\ControlFiles\\NEOTEXT_STAMP.cfg ";
1185 */
1186
1187 if FIRSTTIME = TRUE then
1188 // Get any required banner
1189 if _pdfmode = 1 then
1190 /* BANNERS NOT SETUP for PDF Mode on this script */
1191 else
1192 if banner <> "NA" then
1193 let _file = banner;
1194 gosub CheckFileContents;
1195 if _fType = "pdf" then
1196 let _in = _file;
1197 let _out = "Output\\Temp\\" & bannerFilename & "_temp.ps";
1198 gosub PDF2PS;
1199 let bannerPS = _out;
1200 else
1201 let bannerPS = banner;
1202 endif;
1203 let CMD_LINE = SPHOME & "\\frmcopy \"" & bannerPS & "\" \"Output\\Temp\\" & PDFFile & "\"";
1204 gosub Execute_Cmd;
1205 if _uRet = FALSE then
1206 gosub Cleanup_Temps;
1207 END;
1208 endif;
1209 endif;
1210 endif;
1211 endif;
1212
1213 if _pdfmode = 1 then
1214 let CMD_LINE = PBHOME & "\\frmcopy \"Output\\Temp\\" & file_output & ".2pdf\" \"Output\\Temp\\" & file_output & ".dat\"";
1215 else
1216 gosub Do_Stamp;
1217 let CMD_LINE = PBHOME & "\\frmcopy \"Output\\Temp\\" & file_output & ".stamp\" \"Output\\Temp\\" & PDFFile & "\"";
1218 endif;
1219 gosub Execute_Cmd;
1220 if _uRet = FALSE then
1221 gosub Cleanup_Temps;
1222 END;
1223 endif;
1224 endif;
1225
1226RETURN
1227
1228//***************************************************************************************
1229
1230:Do_Stamp
1231
1232 // NOTE: Changing the fldList format may require you to change the barcode configuration
1233 // specified in the appropriate NEO2D_xxx.cfg file.
1234
1235 let SEQ = mid(_seq, _seqPos, 1);
1236
1237 if aimsType = "100" then
1238// let paddedCustomFld = lpad( ItemRef, 25);
1239// let myCustFld = _CHIcnt & "_" & CHInum;
1240// let myCustFld = lpadex( _CHIcnt, "0", 5 ) & "_" & CHInum;
1241// let myCustFld = UUID;
1242// let myCustFld = _CHIcnt;
1243 let myCustFld = lpadex( _itemCount, "0", 4 ) & CHInum;
1244 let paddedCustomFld = lpad( myCustFld, 25);
1245 if aims100Seq = "DOC" then
1246// let fldList = "\"PIECEID=" & lpadex(_itemCount, 0, 3) & ";SEQ=" & paddedCustomFld & "\"";
1247// let fldList = "\"PIECEID=" & lpadex(_itemCount, 0, 3) & ";SPos=" & _CHIcnt & "\"";
1248//1.06.03 let fldList = "\"PIECEID=" & lpadex( _itemCount, 0, 3) & ";SEQ=" & lpadex( _itemCount, 0, 10) & "\"";
1249 let fldList = "\"PIECEID=" & lpadex(_itemCount, 0, 4) & ";SEQ=" & myCustFld & "\"";
1250 else
1251 if aims100Seq = "PAGE" then
1252 let fldList = "\"SPos=" & _pgCntInBatch & ";SEQ=" & paddedCustomFld & "\"";
1253 endif;
1254 endif;
1255 for asLoop = 1 to DocuPhysicalPages
1256 let _pgCntInBatch = format( ( _pgCntInBatch + 1 ), 1, 0, "" );
1257// if _pgCntInBatch > 999 then
1258 if _pgCntInBatch > 9999 then
1259 let _pgCntInBatch = format( 0, 1, 0, "" );
1260 endif;
1261 next asLoop;
1262 for asLoop = 1 to DocuPhysicalPages
1263 let _CHIcnt = format( ( _CHIcnt + 1 ), 1, 0, "" );
1264 if _CHIcnt > 9999 then
1265 let _CHIcnt = format( 1, 1, 0, "" );
1266 endif;
1267 next asLoop;
1268 else
1269 let fldList = "\"JOBID=" & DocBatchID & ";PIECEID=" & lpadex(_itemCount, 0, 10) & ";SEQ=" & SEQ & "\"";
1270 // update sequence start position for AIMS-500 machines
1271 for asLoop = 1 to DocuPhysicalPages
1272 let _seqPos = format( ( _seqPos + 1 ), 1, 0, "" );
1273 if _seqPos > 26 then
1274 let _seqPos = format( 1, 1, 0, "" );
1275 endif;
1276 next asLoop;
1277 endif;
1278 let CMD_LINE = PBHOME & "\\psomr -c \"" & NEO2D_CTRLFILE & "\" -i \"Output\\Temp\\" & file_output & ".decomp\" -p " & DocuPhysicalPages & " -o \"Output\\Temp\\" & file_output & ".stamp\" -FieldList " & fldList;
1279 gosub Execute_Cmd;
1280 if _uRet = FALSE then
1281 gosub Cleanup_Temps;
1282 END;
1283 endif;
1284
1285RETURN
1286
1287//***************************************************************************************
1288
1289:Do_Net_Send
1290
1291 if( IsNotEmpty( PDFFile ) ) then
1292 let CMD_LINE = PBHOME & DIRSEP & "spnetsend -i \"" & FILE & "\" -submitkeys \"TITLE=<" & TITLE & ">\" -host \"" & NETSENDHOST & "\" -port \"" & NETSENDPORT & "\"";
1293 gosub Execute_Cmd;
1294 if _uRet = FALSE then
1295 gosub Cleanup_Temps;
1296 END;
1297 endif;
1298 endif;
1299 let FILE="";
1300 let TITLE="";
1301
1302RETURN
1303
1304//***************************************************************************************
1305
1306:Do_Add_Job
1307
1308 if( IsNotEmpty( PDFFile ) ) then
1309 let CMD_LINE = PBHOME & DIRSEP & "spaddjob filename=\"" & FILE & "\" title=\"" & TITLE & "\" queue=\"" & QUEUENAME & "\"";
1310 gosub Execute_Cmd;
1311 if _uRet = FALSE then
1312 gosub Cleanup_Temps;
1313 END;
1314 endif;
1315 endif ;
1316 let QUEUENAME="";
1317 let FILE="";
1318 let TITLE="";
1319
1320RETURN
1321
1322//***************************************************************************************
1323
1324:Update_DB_Ref
1325
1326 let SQL="UPDATE mailsort SET execution_set = '2', run_date = now(), skipMethod = '|decide||post|', shepjobid = '" & DocBatchID & "', sheppieceid = '" & lpadex(_itemCount, 0, 10) & "' WHERE record_id = '" & ItemRecordID & "';";
1327 gosub DO_SQL_EXECUTE;
1328
1329RETURN
1330
1331//***************************************************************************************
1332
1333:Update_Failed_Item
1334
1335 let SQL="UPDATE mailsort SET failed = '1', run_date = now() WHERE record_id = " & ItemRecordID & ";";
1336 gosub DO_SQL_EXECUTE;
1337
1338RETURN
1339
1340//***************************************************************************************
1341
1342:Full_Insert
1343
1344 let _vfPart = "";
1345 let _vsPart = "";
1346 let _vtPart = "";
1347
1348 let _vTempInsert = chkInsert;
1349 if strindex( _vTempInsert, "|" ) = 0 then
1350 let _vInsert = trim( _vTempInsert & "|None|None|None";
1351 RETURN;
1352 else
1353 /* determine the parts */
1354 let _vfPart = trim( mid( _vTempInsert, 1, ( strindex ( _vTempInsert, "|" ) - 1 ) ) );
1355 let _vTempInsert = trim( mid( _vTempInsert, ( strindex ( _vTempInsert, "|" ) + 1 ), len( _vTempInsert ) ) );
1356
1357 if strindex( _vTempInsert, "|" ) > 0 then
1358 let _vsPart = trim( mid( _vTempInsert, 1, ( strindex( _vTempInsert, "|" ) - 1 ) ) );
1359 let _vTempInsert = trim( mid( _vTempInsert, ( strindex( _vTempInsert, "|" ) + 1), len( _vTempInsert ) ) );
1360 else
1361 let _vInsert = _vfPart & "|" & _vTempInsert & "|None";
1362 RETURN;
1363 endif;
1364
1365 if strindex( _vTempInsert, "|" ) > 0 then
1366 let _vtPart = trim ( mid( _vTempInsert, 1, ( strindex( _vTempInsert, "|" ) - 1 ) ) );
1367 let _vTempInsert = trim( mid( _vTempInsert, ( strindex( _vTempInsert, "|" ) + 1), len( _vTempInsert ) ) );
1368 let _vInsert = _vfPart & "|" & _vsPart & "|" & _vtPart & "|" & _vTempInsert;
1369 endif;
1370 endif ;
1371
1372RETURN
1373
1374//***************************************************************************************
1375:Cleanup_Temps
1376
1377 print "Starting Clean up..."
1378
1379 let CLCMD = "IF EXIST " & PBHOME & "\\Output\\Temp\\*.dat ( DEL /F /Q " & PBHOME & "\\Output\\Temp\\*.dat )";
1380 Execute CLCMD;
1381 let CLCMD = "IF EXIST " & PBHOME & "\\Output\\Temp\\*.decomp ( DEL /F /Q " & PBHOME & "\\Output\\Temp\\*.decomp )";
1382 Execute CLCMD;
1383 let CLCMD = "IF EXIST " & PBHOME & "\\Output\\Temp\\*.2pdf ( DEL /F /Q " & PBHOME & "\\Output\\Temp\\*.2pdf )";
1384 Execute CLCMD;
1385 let CLCMD = "IF EXIST " & PBHOME & "\\Output\\Temp\\*.ps ( DEL /F /Q " & PBHOME & "\\Output\\Temp\\*.ps )";
1386 Execute CLCMD;
1387 let CLCMD = "IF EXIST " & PBHOME & "\\Output\\Temp\\*.stamp ( DEL /F /Q " & PBHOME & "\\Output\\Temp\\*.stamp )";
1388 Execute CLCMD;
1389
1390// close hndSummary;
1391
1392RETURN
1393
1394//***************************************************************************************
1395
1396:Check_File_Exists
1397
1398 let FILE = _file;
1399 let TYPE = _type;
1400 let exists = FALSE;
1401 Print "\tChecking for file: " & FILE;
1402 if ( IsNotEmpty( FILE ) ) then
1403 let fp = open (FILE, TYPE);
1404 if (fp <> -1) then
1405 let exists = TRUE;
1406 gosub Close_File;
1407 endif;
1408 endif;
1409return
1410
1411//***************************************************************************************
1412
1413:Open_File
1414
1415 let FILE = _file;
1416 let TYPE = _type;
1417 let openRet = FALSE;
1418 Print "\tOpening file: " & FILE;
1419 if ( IsNotEmpty( FILE )) then
1420 let fp = open ( FILE, TYPE );
1421 if (fp <> -1) then
1422 let openRet = TRUE;
1423 endif;
1424 endif;
1425return
1426
1427//***************************************************************************************
1428
1429:Close_File
1430
1431 let FILE = _file;
1432 let closeRef = FALSE;
1433 if ( IsNotEmpty( FILE ) ) then
1434 if (fp <> -1) then
1435 close (fp);
1436 let closeRef = TRUE;
1437 endif;
1438 endif;
1439 let FILE = "";
1440 let fp = NULL;
1441return
1442
1443//***************************************************************************************
1444
1445:Write_To_File
1446
1447 let STR = _str;
1448 let _wfRet = FALSE;
1449
1450 if ( IsNotEmpty( STR ) ) then
1451 if ( openRet = TRUE) then
1452 print!fp STR;
1453 let _wfRet = TRUE;
1454 endif;
1455 endif;
1456 let _str = "";
1457return
1458
1459//***************************************************************************************
1460:Replace_In_File
1461
1462 let STR = _str;
1463 let _wfRet = FALSE;
1464 let _buffer = "";
1465
1466 if ( fp <> -1 ) then
1467 let loopcnt = "1";
1468 while ( EOF( fp ) = 0 )
1469 INPUT!fp, DummyLine
1470 if strindex( DummyLine, "##STR" ) > 0 then
1471 let DummyLine = replace ( DummyLine, "##STR", STR );
1472 endif;
1473 if trim( DummyLine) <> "" then
1474 let _buffer = _buffer & DummyLine & "\n";
1475 endif;
1476 wend ;
1477 endif;
1478return
1479
1480//***************************************************************************************
1481:Set_Up_Attachments
1482
1483 let tempPS = "";
1484 let stocks = "";
1485
1486 if _pdfmode = 1 then
1487 let attachToMe = "Output\\Temp\\" & file_output & ".2pdf";
1488 else
1489 let attachToMe = "Output\\Temp\\" & file_output & ".decomp";
1490 endif;
1491
1492 print "\n\tStart attachments, create tmp file for addition of resources."
1493 let x = 1;
1494 while strindex( _atts, "," ) > 0
1495 let p = strindex( _atts, "," );
1496 let var = trim( mid( _atts, 1, ( p - 1 ) ) );
1497 let arr#x = var;
1498 let _atts = trim( mid( _atts,( p + 1 ), len( _atts )));
1499 let x = format( ( x + 1 ), 1, "", 0 );
1500 wend;
1501 // Ensure that if only one attachment is specified (or it's the last in a list) that it is captured
1502 let arr#x = _atts;
1503 let arrUpbound = upper("arr") - 1;
1504 for z=1 to arrUpbound
1505 if trim( arr#z) <> "" then
1506 let SQL = "select location,state,(select name from single_styleType where id=styleType) as type, stockcode from single where resourceid=(select resourceid from resources where resourceType=1 and resuniid='" & arr#z & "');";
1507 gosub OpenDataBase;
1508 if ( DoSQLToRecordset( #2, SQL ) = FALSE ) then
1509 print "\tFailed to do resources query to record set: " & GetLastError();
1510 CloseDB;
1511 RETURN;
1512 endif;
1513 if ( OpenRecordSet( #2 ) = FALSE ) then
1514 print "\tCannot open resources query,";
1515 CloseDB;
1516 endif;
1517 CloseDB;
1518
1519 let _aLoc = "";
1520 let _aState = "";
1521 let _aType = "";
1522 let _aStockCode = "";
1523 LOOP
1524 let _aLoc = GetFieldByName( #2, "location" );
1525 let _aState = GetFieldByName( #2, "state" );
1526 let _aType = GetFieldByName( #2, "type" );
1527 let _aStockCode = GetFieldByName( #2, "stockcode" );
1528
1529 print "\tGet resources details: ";
1530 print "\t\tlocation = " & _aLoc;
1531 print "\t\tstate = " & _aState;
1532 print "\t\ttype = " & _aType;
1533 print "\t\tstockcode = " & _aStockCode;
1534
1535 if trim( _aType) = "Attachment" OR trim( _aType) = "attachment" then
1536 if trim( _aState) = "Digital" OR trim( _aState) = "digital" or trim( _aState) = "Cloud" OR trim( _aState) = "cloud" then
1537 if _pdfmode = 1 then
1538 print "PDF Mode resources section";
1539 let _in = _aLoc;
1540 let _out = _aLoc & "_attach.2pdf";
1541 gosub FRMCOPY;
1542 let _in = _out;
1543 let _out = attachToMe;
1544 print "\tAppending attachment:";
1545 print "\t\tIN : " & _in;
1546 print "\t\tOUT: " & _out;
1547 gosub Concatenate_PDFs;
1548 let _del = _aLoc & "_attach.2pdf";
1549 print "\tDeleting temp resource : " & _del;
1550 DELETEFILE _del;
1551 else
1552 print "\tPostscript Mode resources section";
1553 let _in = _aLoc;
1554 let _out = _aLoc & "_temp.ps";
1555 print "\tStarting PDF2PS:";
1556 print "\t\tIN : " & _in;
1557 print "\t\tOUT: " & _out;
1558 gosub PDF2PS;
1559 let _in = _out;
1560 let _out = attachToMe;
1561 print "\tAppending attachment:";
1562 print "\t\tIN : " & _in;
1563 print "\t\tOUT: " & _out;
1564 gosub FRMCOPY;
1565 let _del = _aLoc & "_temp.ps";
1566 print "\tDeleting temp resource : " & _del;
1567 DELETEFILE _del;
1568 endif;
1569 endif;
1570 if trim( _aState) = "Physical" OR trim( _aState) = "physical" then
1571 if trim( _aStockCode) <> "" then
1572 if trim( stocks) = "" then
1573 let stocks = _aStockCode;
1574 else
1575 let stocks = stocks & "," & _aStockCode;
1576 endif;
1577 endif;
1578 endif;
1579 if trim( _aState) = "Cloud" OR trim( _aState) = "cloud" then
1580 /* No need to do anything, cloud resources can only be used in the cloud */
1581 endif;
1582 endif;
1583
1584 if ( GetNextRecord( #2 ) = FALSE ) then
1585 exitloop;
1586 endif;
1587 endloop;
1588 CloseRecordset #2;
1589 endif;
1590 next z;
1591
1592 for z=1 to arrUpbound
1593 let arr#z = "";
1594 next z;
1595
1596 print "\tNo more resources to add. No need to finalise file. Just attach the tmp file to output. The collection server file will still be using the ids as detailing in mailsor;";
1597
1598RETURN
1599
1600
1601//***************************************************************************************
1602:PDF2PS
1603
1604 if _in <> "" and _out <> "" then
1605 let CMD = "sppdf2ps -i \"" & _in & "\" -o \"" & _out & "\" -duplex";
1606 let RET = FALSE;
1607 let PSUCMD_LINE = CMD;
1608 let _RETURN = PIPEEXEC( PSUCMD_LINE, ADR(CmdOutput) );
1609 if (_RETURN = 0) then
1610 let RET = TRUE;
1611 print "\tSuccessfully converted PDF to PS, exec cmd (" & PSUCMD_LINE & ")";
1612 else
1613 print "\tFailed to convert PDF to PS, exec cmd (" & PSUCMD_LINE & ")";
1614 endif;
1615 endif;
1616
1617RETURN
1618
1619
1620//***************************************************************************************
1621:Concatenate_PDFs
1622 if _out <> "" and _in <> "" then
1623 let CMD_LINE = SPHOME & "\\sppdftk " & _in & "*.2pdf cat output \"" & _out & "\"";
1624 let CmdOutput = "";
1625 let _RETURN = PIPEEXEC( CMD_LINE, ADR(CmdOutput) );
1626 if (_RETURN = 0) then
1627 let _pRet = TRUE;
1628 print "\tSuccessfully concatenated PDFs. (" & CMD_LINE & ")"
1629 else
1630 print "\tFailed to concatenate PDFs. (" & CMD_LINE & ")"
1631 endif;
1632 else
1633 print "\tIn ( " & _in & " ) or out ( " & _out & " ) are blank";
1634 endif;
1635RETURN
1636
1637
1638//***************************************************************************************
1639
1640:FRMCOPY
1641
1642 if _in <> "" and _out <> "" then
1643 let CMD = "frmcopy \"" & _in & "\" \"" & _out & "\"";
1644 let RET = FALSE;
1645 let PSUCMD_LINE = CMD;
1646 let _RETURN = PIPEEXEC( PSUCMD_LINE, ADR(CmdOutput) );
1647 if (_RETURN = 0) then
1648 let RET = TRUE;
1649 print "\tSuccessfully copied file, (" & PSUCMD_LINE & ")";
1650 else
1651 print "\tFailed to copy file (" & PSUCMD_LINE & ")";
1652 endif;
1653 endif;
1654RETURN
1655
1656/******************************************************************************
1657 ConvertDateTime
1658 Takes a date and time in either 'dd/mm/yyyy hh:mm:ss' or 'secs from epoch'
1659 format and reformats it to one of those specified below.
1660
1661 Required Input:
1662 inDateTime - the date and time to be reformatted
1663 Outputs:
1664 isoDateTime - the converted value as 'yyyy-mm-dd hh:mm:ss'
1665 isoTZDateTime - the converted value as 'yyyy-mm-ddThh:mm:ssZ'
1666 prettyDateTime1 - the converted value as 'hh:mm:ss on dd-mm-yyyy'
1667 prettyDateTime2 - the converted value as 'hh:mm:ss on dd-mmm-yyyy'
1668 dateOnly - the converted value as 'ddmmmyyyy'
1669 timeOnly - the converted value as 'hh:mm:ss'
1670 isoFileDateTime - the converted value as 'yyyy-mm-dd_hh-mm-ss'
1671*******************************************************************************/
1672
1673:ConvertDateTime
1674
1675 let MONTHS = "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec";
1676
1677 if strindex( inDateTime, "/" ) < 1 then
1678 // date in 'dd/mm/yyyy hh:mm:ss' format not found so assume 'secs from epoch'
1679 let inDateTime = showtime( inDateTime );
1680 endif;
1681
1682 let day = trim ( mid ( inDateTime, 1, strindex( inDateTime, "/" ) - 1 ) );
1683 if len ( day ) = 1 then
1684 let day = "0" & day
1685 endif;
1686 let slashpos = strindex( inDateTime, "/" );
1687 let slashPlus1 = slashpos + 1;
1688 let inDateTime = mid ( inDateTime, slashPlus1, len ( inDateTime ) );
1689 let month = trim ( mid ( inDateTime, 1, strindex( inDateTime, "/" ) - 1 ) );
1690 let fullMonth = csvindex( MONTHS, month );
1691 let slashpos = strindex( inDateTime, "/" );
1692 let slashPlus1 = slashpos + 1;
1693 let inDateTime = mid ( inDateTime, slashPlus1, len ( inDateTime ) );
1694 let year = trim ( mid ( inDateTime, 1, strindex( inDateTime, " " ) - 1 ) );
1695 let inDateTime = trim ( mid ( inDateTime, strindex( inDateTime, " " ) + 1, len ( inDateTime ) ) );
1696 let timeOnly = inDateTime;
1697
1698 let isoDateTime = year & "-" & month & "-" & day & " " & inDateTime;
1699 let isoFileDateTime = year & "-" & month & "-" & day & "_" & replace (inDateTime, ":", "-");
1700 let isoTZDateTime = year & "-" & month & "-" & day & "T" & inDateTime & "Z";
1701
1702 let prettyDateTime1 = inDateTime & " on " & day & "-" & month & "-" & year;
1703 let prettyDateTime2 = inDateTime & " on " & day & "-" & fullMonth & "-" & year;
1704
1705 let dateOnly = day & fullMonth & year;
1706
1707return
1708
1709/********************************************************************************
1710 CheckFileContents
1711 This routine is used to determine the file type of a given file e.g. What type
1712 of data does a .DAT file contain... postscript, PDF, text, is it compressed?
1713 Inputs:
1714 _file - the name (and path) of the file to be tested
1715 Outputs:
1716 _fType - string indicating the type of file e.g. ps, pdf, spzip, frmzip
1717 _check - TRUE/FALSE depending on whether file could be checked
1718*******************************************************************************/
1719
1720:CheckFileContents
1721
1722 let _check = FALSE;
1723 if _file <> "" then
1724 let _fType = "";
1725 let _accessmode = "r";
1726 gosub Open_File;
1727 if openRet = TRUE then
1728 let _fhnd = fp;
1729 print "OPENED";
1730 if fp <> -1 then
1731 while ( EOF(fp) = 0 )
1732 INPUT!fp, DummyLine;
1733 if DummyLine = "" then
1734 // let _fType = "blank";
1735 // exitwhile;
1736 let _fType = "spzip";
1737 exitwhile;
1738 endif;
1739 if strindex( DummyLine, "SLMZ" ) > 0 then
1740 let _fType = "frmzip";
1741 endif;
1742 if strindex( DummyLine, "%!PS-" ) > 0 then
1743 let _fType = "ps";
1744 endif;
1745 if strindex( DummyLine, "%PDF-" ) > 0 then
1746 let _fType = "pdf";
1747 endif;
1748 if _fType = "" then
1749 let _fType = "spzip";
1750 endif;
1751 let _check = TRUE;
1752 exitwhile;
1753 wend;
1754 endif;
1755 gosub Close_File;
1756 else
1757 print "File [" & _file & "] does not exist";
1758 endif;
1759 endif;
1760 print "File type is : " & _fType;
1761
1762return;