          SUBROUTINE (OID,GEN,LDID,LBL.NO,TOL.QTY,UDATA)
** Version# 11.0005[12] - 07/17/2013 - 08:08am - TSMITH - eclipse
*** V11.0005 Change - Custom Coding . - 07/17/2013 - TSMITH - eclipse
*** V11.0004 Change - Custom Coding . - 07/16/2013 - TSMITH - eclipse
** BatchBuild Version# 1.0 - TSMITH
** This software is used to build a submittal for the user by assmebling all
** of the spec sheets attached to each product on the order and merging them
** using PDFTK.
*-------------------------------------------------------------------------*
*** OID      - Order ID                                            [IN]
*** GEN      - Generation                                          [IN]
*** LDID     - Not Used
*** LBL.NO   - Not Used
*** TOL.QTY  - Total quantity shipped of last item (not useful)    (OUT)
*** UDATA    - Not Used
*-------------------------------------------------------------------------*
*** LED, LD, and PRD are self-contained in this routine. They do not need
*** to be current
*-------------------------------------------------------------------------*
          MODE = OID[1,1]
          IF MODE # 'S' THEN RETURN
          MATREAD LED FROM LEDFILE,OID ELSE MAT LED = ''
          OE.GET.QSIGN QSIGN,OID,GEN

          BR    = LED(2)<1,GEN,1>
          BT.CN = LED(1)<1,GEN,1>
          ST.CN = LED(5)<1,GEN,1>
          GET.CUS BR,BT.CN,ST.CN,QSIGN
          CITY.ST = OCONV(LED(78)<1,GEN,4>,'MCT'):', ':LED(78)<1,GEN,5>
          CUST = TRANS('ENTITY',ST.CN,1,'X')<1,1,1>
          ORD.DATE = OCONV(OCONV(LED(4)<1,GEN,1>,'DMA'),'MCT'):' ':FIELD(OCONV(LED(4)<1,GEN,1>,'D4/'),'/',2):', ':OCONV(LED(4)<1,GEN,1>,'DY')


          TB = CHAR(9)
          DESCTB = CHAR(10)
          DATA = ''
          JOB = OCONV(LED(13)<1,GEN,1>,'MCT')
          IF JOB = '' THEN
          JOB = OCONV(TRANS('ENTITY',ST.CN,1,'X')<1,1,1>,'MCT')
          END


          IF BR = '3' THEN
          HEADER = 'red.pdf'
          END ELSE
          HEADER = 'submittal_header.pdf'
          END




          DATA<-1> = '@ECHO off'
          DATA<-1> = 'ECHO Your submittal is being generated. Please wait...'
          DATA<-1> = 'ECHO When finished your submittal will open automatically. The submittal will be'
          DATA<-1> = 'ECHO available in the c:\pdf\':JOB:'\ folder.'
          DATA<-1> = 'net use x: \\172.22.124.12\products >nul 2>&1'
          DATA<-1> = 'mkdir c:\pdf >nul 2>&1'
          DATA<-1> = 'copy x:\libiconv2.dll c:\pdf >nul 2>&1'
          DATA<-1> = 'copy x:\pdftk.exe c:\pdf >nul 2>&1'
          DATA<-1> = 'mkdir c:\pdf\':'"':JOB:'" >nul 2>&1'
          DATA<-1> = 'copy x:\':HEADER:' c:\pdf\':'"':JOB:'" >nul 2>&1'

          IF BR = '3' THEN
          DATA<-1> = 'copy x:\toc.pdf c:\pdf\':'"':JOB:'"\001_toc.pdf >nul 2>&1'
          DATA<-1> = 'copy x:\smart_solar.pdf c:\pdf\':'"':JOB:'"\002_smart_solar.pdf >nul 2>&1'
          *DATA<-1> = 'copy x:\tax_credit_explanation.pdf c:\pdf\':'"':JOB:'" >nul 2>&1'
          END




          DATA<-1> = 'cd c:\pdf\':'"':JOB:'" >nul 2>&1'
          DATA<-1> = 'echo ^<?xml version="1.0" encoding="UTF-8"?^>^<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"^>^<f href="':HEADER:'"/^> > index.xfdf'
          DATA<-1> = 'echo ^<fields^> >> index.xfdf'
          DATA<-1> = 'echo ^<?xml version="1.0" encoding="UTF-8"?^>^<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"^>^<f href="':HEADER:'"/^> > submittal.xfdf'
          DATA<-1> = 'echo ^<fields^> >> submittal.xfdf'
          DATA<-1> = 'echo ^<field name="<general contractor>"^>^<value^>Unknown^</value^>^</field^> >> submittal.xfdf'
          DATA<-1> = 'echo ^<field name="<job name>"^>^<value^>':JOB:'^</value^>^</field^> >> submittal.xfdf'
          DATA<-1> = 'echo ^<field name="<location>"^>^<value^>':CITY.ST:'^</value^>^</field^> >> submittal.xfdf'
          DATA<-1> = 'echo ^<field name="<plumbing contractor>"^>^<value^>':OCONV(CUST,'MCT'):'^</value^>^</field^> >> submittal.xfdf'
          DATA<-1> = 'echo ^<field name="<ord date>"^>^<value^>':ORD.DATE:'^</value^>^</field^> >> submittal.xfdf'
          DATA<-1> = 'echo ^</fields^> >> submittal.xfdf'
          DATA<-1> = 'echo ^<ids original="C8F9D11373F34543A0AE407C553380A6" modified="15A8D3F781E9E24F99EFEA724A3A4659"/^> >> submittal.xfdf'
          DATA<-1> = 'echo ^</xfdf^> >> submittal.xfdf'
          DATA<-1> = 'cd ..\'



          MATBUILD SV.LD FROM LD

          OE.GET.LDID.LIST LDID.LIST,OID,GEN
          LDID.CT = DCOUNT(LDID.LIST,VM)
          FOR LDID.CTR = 1 TO LDID.CT
              LDID = LDID.LIST<1,LDID.CTR>
              LD.GET LDID



          GET.ALL.PRD BR,LD(1),QSIGN,GROUP
          PN      = LD(1)
          DESC    = TRANS('PRODUCT',PN,1,'X')<1,1,1>
          CONVERT "/" TO "-" IN DESC
          CONVERT '"' TO 'IN' IN DESC



          IF NUM(PN) THEN
          IF SUM(LD(5)<1,GEN>)+SUM(LD(6)<1,GEN>) = 0 THEN GOTO SKIP.LD
          END ELSE
          END


          SPEC.LIST=''
          UT.OPEN.FILE 'IMG.XREF',IMGFILE
          ROOT = 'P~':PN
          IMAGE.FLAG = NO
          BSCAN REC.ID,REC.VAL FROM IMGFILE,ROOT USING '&INDEX&.XREFS' ELSE NULL
          IF REC.ID = ROOT OR PN ='S' OR PN = 'C' THEN
          IMAGE.FLAG = YES
          END
          IF IMAGE.FLAG = NO THEN GOTO SKIP.LD
          REC.VAL = REC.VAL<1,1>
          PATH = TRANS('IMG.ARCHIVES',TRANS('IMG.XREF',REC.VAL,7,'X'),2,'X')<1,1,1>;
          TYPE = 'pdf'
          POSITION=LDID.CTR
          IF POSITION < 10 THEN
          POSITION = "0":POSITION
          END
          FULL.PATH = 'X:\':(PATH:'/':REC.VAL:'.':TYPE)
          CHARACTERS = COUNT(FULL.PATH,'')-17
          FULL.PATH = 'X:\':(PATH:'/':REC.VAL:'.':TYPE)[17,CHARACTERS]
          CONVERT "/" TO "\" IN FULL.PATH
          *IF PN = 'S' THEN
          *COMMAND = 'copy X:\submittal_header.pdf c:\pdf\"':JOB:'"\':POSITION:'_submittal_header.pdf >nul 2>&1'
          *SORT = 'ren c:\pdf\':'"':JOB:'"':'\':REC.VAL:'.':TYPE:' "':POSITION:'_':'':DESC:'_XXX.':TYPE:'" >nul 2>&1'
          *END ELSE
          IF PN = 'C' THEN
          COMMENT  = RAISE(LD(3)<1,GEN,2>)
          COMMAND = 'copy X:\':HEADER:' c:\pdf\':'"':JOB:'"\':POSITION:'_':HEADER:' >nul 2>&1'
          SORT = 'ren c:\pdf\':'"':JOB:'"\':POSITION:'_':HEADER:' "':POSITION:'_':FIELD(HEADER,'.',1):'_XXX.pdf" >nul 2>&1'
          END ELSE
          COMMAND = 'copy ':FULL.PATH:' c:\pdf\':'"':JOB:'" >nul 2>&1'
          SORT = 'ren c:\pdf\':'"':JOB:'"\':REC.VAL:'.':TYPE:' "':POSITION:'_':DESC:'_XXX.':TYPE:'" >nul 2>&1'
          END
          *END


          DATA<-1> = COMMAND
          DATA<-1> = SORT
          IF PN = 'C' THEN
          DATA<-1> = 'pdftk ':'"':JOB:'"\':POSITION:'_':FIELD(HEADER,'.',1):'_XXX.pdf fill_form ':'"':JOB:'"\submittal.xfdf output ':'"':JOB:'"\':POSITION:'_header_XXX.pdf'
          DATA<-1> = 'del ':'"':JOB:'"\':POSITION:'_':FIELD(HEADER,'.',1):'_XXX.pdf'
          DATA<-1> = 'echo ^<field name="<header>"^>^<value^>':COMMENT:'^</value^>^</field^> >> index.xfdf'
          END
SKIP.LD:  NEXT LDID

          MATPARSE LD FROM SV.LD
          DATA<-1>  = 'cd c:\pdf\':'"':JOB:'"'
          *CUST = TRANS('ENTITY',ST.CN,1,'X')<1,1,1>

          DATA<-1> = 'c:\pdf\pdftk ':HEADER:' fill_form submittal.xfdf output 000_header_XXX.pdf'
          DATA<-1> = 'del ':HEADER
          DATA<-1> = 'c:\pdf\pdftk.exe *.pdf cat output "':OCONV(CUST,'MCT'):'_':JOB:'_incomplete.pdf"'
          DATA<-1> = 'del *_XXX.pdf'
          DATA<-1> = 'del submittal.xfdf'
          DATA<-1> = 'c:\pdf\pdftk "':OCONV(CUST,'MCT'):'_':JOB:'_incomplete.pdf" output "':OCONV(CUST,'MCT'):'_':JOB:'.pdf" flatten'
          DATA<-1> = 'del *_incomplete.pdf'
          DATA<-1> = '"':OCONV(CUST,'MCT'):'_':JOB:'.pdf"'
          DATA<-1> = 'exit'


          DCT = DCOUNT(DATA,AM)
          FOR J = 1 TO DCT

          PRINT DATA<J>
          NEXT J

FINISH:   RETURN
*-------------------------------------------------------------------------*
!TSMITH~07/17/13~08:08
