          SUBROUTINE (OID,GEN,LDID,LBL.NO,TOL.QTY,UDATA)
** Version# 11.0013 - 06/11/2015 - 03:46pm - TSMITH - eclipse
*** V11.0013 Change - Custom Coding . - 06/11/2015 - TSMITH - eclipse
*** V11.0012 Change - Custom Coding . - 02/19/2015 - TSMITH - eclipse
*** V11.0011 Change - Custom Coding . - 01/16/2015 - TSMITH - eclipse
*** V11.001 Change - Custom Coding . - 12/23/2014 - TSMITH - eclipse
*** V11.0009 Change - Custom Coding . - 02/18/2014 - TSMITH - eclipse
*** V11.0008 Change - Custom Coding . - 10/29/2013 - TSMITH - eclipse
** Copied from CBP LABEL.BAT.PDF.PARTS Version# 11.0007[24] - 09/11/2013 - 10:43pm - TSMITH - eclipse
*** V11.0007 Change - Custom Coding . - 09/11/2013 - TSMITH - eclipse
*** V11.0006 Change - Custom Coding CUSTOM - 07/05/2013 - TSMITH - eclipse
*** V11.0005 Change - Custom Coding . - 07/05/2013 - TSMITH - eclipse
*** V11.0004 Change - Custom Coding . - 07/01/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

          PROG.CHECK=TRANS('LEDGER.GPS',OID,8,'X')
          BR    = LED(2)<1,GEN,1>
          BT.CN = LED(1)<1,GEN,1>
          ST.CN = LED(5)<1,GEN,1>
          NO.PAGES = TRANS('LEDGER.GPS',OID,3,'X')
          GET.CUS BR,BT.CN,ST.CN,QSIGN
          CITY.ST = OCONV(LED(78)<1,GEN,4>,'MCU'):', ':LED(78)<1,GEN,5>
          CUST = TRANS('ENTITY',BT.CN,1,'X')<1,1,1>
          AMPER = COUNT(CUST,'&')
          IF AMPER>0 THEN
          CUST = FIELD(TRANS('ENTITY',BT.CN,1,'X')<1,1,1>,'&',1):'^&':FIELD(TRANS('ENTITY',BT.CN,1,'X')<1,1,1>,'&',2)
          END
          CONVERT "*" TO " " IN CUST
          ORD.DATE = OCONV(OCONV(LED(4)<1,GEN,1>,'DMA'),'MCU'):' ':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>,'MCU')
          IF JOB = '' THEN
          JOB = OCONV(TRANS('ENTITY',ST.CN,1,'X')<1,1,1>,'MCU')
          END

          CONVERT "/" TO "-" IN JOB

          JOB = TRIM(JOB,' ','E')


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

          IF PROG.CHECK # '1' THEN
          DATA<-1> = '@ECHO off'
          END




            DATA<-1> = 'color 4F'
          DATA<-1> = 'title BatchBuild V11.0009'
          DATA<-1> = 'mode con: cols=80 lines=4'
          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> = 'mkdir c:\pdf >nul 2>&1'
          DATA<-1> = 'mkdir c:\pdf\':'"':JOB:'" >nul 2>&1'
          DATA<-1> = 'cd c:\pdf\':'"':JOB:'" >nul 2>&1'
          DATA<-1> = 'del *.pdf >nul 2>&1'
          DATA<-1> = 'net use x: \\172.22.124.12\products >nul 2>&1'
          DATA<-1> = 'copy x:\bb.jpg c:\pdf\':'"':JOB:'" >nul 2>&1'
          *IF USER.ID#'TSMITH' AND USER.ID#'DAVIDW' THEN
*-------------------------------------------------------------------------*
          *** Generate HTML Page for viewing while BatchBuild works
          *DATA<-1> = 'echo ^<html^>^<head^>^<title^>Batch Build V11.0006^</title^>^</head^> > index.htm'
          *DATA<-1> = 'echo ^<body^>^<center^>^<img src="bb.jpg" border="0"^>^<br>^<br^> >> index.htm'
          *DATA<-1> = 'echo ^<font face="Tahoma" color="#000000" size="2"^>Your submittal is being put together by BatchBuild. >> index.htm'
          *DATA<-1> = 'echo When finished it will open automatically.^<br^>The PDF it generates will be >> index.htm'
          *DATA<-1> = 'echo available in the "c:\pdf\':JOB:'\" folder or by clicking the link below.^<br^>^<br^> >> index.htm'
          *DATA<-1> = 'echo ^<a href="file:///c:\pdf\':JOB:'"^>':JOB:'^</a^>^<br^>^<br^>^<br^>^</font^> >> index.htm'
          *DATA<-1> = 'echo ^<audio controls autoplay^>^<source src="http://172.22.124.11/man_and_a_woman.mp3" type="audio/mpeg"^>^<source src="http://172.22.124.11/man_and_a_woman.ogg" type="audio/ogg"^> >> index.htm'
          *DATA<-1> = 'echo ^<embed height="50" width="100" src="http://172.22.124.11/man_and_a_woman.mp3"^>^</audio^> >> index.htm'
          *DATA<-1> = 'echo ^</body^>^</html^> >> index.htm'
          *DATA<-1> = 'start index.htm'
*-------------------------------------------------------------------------*
          *END




              DATA<-1> = 'IF NOT EXIST c:\pdf\libiconv2.dll copy x:\libiconv2.dll c:\pdf >nul 2>&1'
          DATA<-1> = 'IF NOT EXIST c:\pdf\pdftk.exe copy x:\pdftk.exe c:\pdf >nul 2>&1'
          DATA<-1> = 'copy x:\':HEADER:' c:\pdf\':'"':JOB:'" >nul 2>&1'
          DATA<-1> = 'IF NOT EXIST c:\pdf\batesmaster.exe copy x:\batesmaster.exe c:\pdf >nul 2>&1'

          DATA<-1> = 'mkdir c:\pdf\':'"':JOB:'" >nul 2>&1'
          DATA<-1> = 'copy x:\submittal_cover_page.docx c:\pdf\':'"':JOB:'" >nul 2>&1'
          DATA<-1> = 'copy x:\submittal_header.pdf c:\pdf\':'"':JOB:'" >nul 2>&1'

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

          END

          DATA<-1> = 'cd c:\pdf\':'"':JOB:'" >nul 2>&1'
          IF BR = '3' THEN
          DATA<-1> = 'echo ^<?xml version="1.0" encoding="UTF-8"?^>^<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"^>^<f href="toc.pdf"/^>^<fields^>^<field name="item"^> > index.xfdf'
          END ELSE
          DATA<-1> = 'echo ^<?xml version="1.0" encoding="UTF-8"?^>^<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"^>^<f href="toc.pdf"/^>^<fields^> > index.xfdf'

          END


*-------------------------------------------------------------------------*
          *** Submittal.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="<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,'MCU'):'^</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

*-------------------------------------------------------------------------*
          *** Comment Code
          OE.GET.LDID.COMM OID,GEN,,PRD.LIST
          SEC.HEADER = PRD.LIST

*-------------------------------------------------------------------------*
          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)
          SECTION =  RAISE(RAISE(LD(3)<1,1,2>))
          DESC    = TRANS('PRODUCT',PN,1,'X')<1,1,1>
          CONVERT "/" TO "-" IN SECTION
          CONVERT ":" TO "-" IN SECTION

          IF TRANS('PRODUCT',PN,66,'X') THEN
          DESC    = TRANS('PRODUCT',PN,66,'X')
          END ELSE
          DESC    = TRANS('PRODUCT',PN,1,'X')<1,1,1>
          END
          CONVERT "/" TO "-" IN DESC
          CONVERT '"' TO 'IN' IN DESC
          CONVERT '.' to "_" IN DESC
          CONVERT "&" TO "_" IN DESC

*          CONVERT @VM TO "-" IN LDID.LIST
*          DATA<-1> = 'echo ':LDID.LIST:' > test.txt'




          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

          PARTS.CHK1 = TRANS('IMG.XREF',REC.VAL<1,1>,1,'X')
          PARTS.CHK2 = TRANS('IMG.XREF',REC.VAL<2,1>,1,'X')
          PARTS.CHK3 = TRANS('IMG.XREF',REC.VAL<3,1>,1,'X')
          NO.BLANKS1 = COUNT(PARTS.CHK1,' ')+1
          NO.BLANKS2 = COUNT(PARTS.CHK2,' ')+1
          NO.BLANKS3 = COUNT(PARTS.CHK3,' ')+1
          PARTS1 = FIELD(FIELD(PARTS.CHK1,' ',NO.BLANKS1),'.',1)
          PARTS2 = FIELD(FIELD(PARTS.CHK2,' ',NO.BLANKS2),'.',1)
          PARTS3 = FIELD(FIELD(PARTS.CHK3,' ',NO.BLANKS3),'.',1)
          NO.PARTS = ''
          IF PN#'C' THEN
          IF OCONV(PARTS1,'MCL') # 'parts' AND OCONV(PARTS2,'MCL') # 'parts' AND OCONV(PARTS3,'MCL') # 'parts' THEN
          NO.PARTS = 1
          END
          END
          IF NO.PARTS = 1 THEN GOTO SKIP.LD

          PARTS = ''

          RECORDS = DCOUNT(REC.VAL,AM)
          IF RECORDS # '1' THEN
          IF PN#'C' THEN
          IF OCONV(PARTS1,'MCL') # 'parts' THEN
          ATTR   =  2
          REC.VAL = REC.VAL<ATTR,1>
          END ELSE
          ATTR   =  1
          REC.VAL = REC.VAL<ATTR,1>

          END
          END
          END

          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 = "00":POSITION
          END ELSE
          IF POSITION > 9 AND POSITION < 100 THEN
          POSITION = "0":POSITION
          END ELSE
          POSITION = POSITION
          END
          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 = 'C' THEN
          COMMENT  = RAISE(LD(3)<1,GEN,2>)
          DATA<-1> = 'copy X:\':DIVIDER:' c:\pdf\':'"':JOB:'"\':POSITION:'_':DIVIDER:' >nul 2>&1'
          DATA<-1> = 'ren c:\pdf\':'"':JOB:'"\':POSITION:'_':DIVIDER:' "':POSITION:'_':FIELD(DIVIDER,'.',1):'_XXX.pdf" >nul 2>&1'
          END ELSE
          DATA<-1> = 'copy ':FULL.PATH:' c:\pdf\':'"':JOB:'" >nul 2>&1'
          DATA<-1> = 'ren c:\pdf\':'"':JOB:'"\':REC.VAL:'.':TYPE:' "':POSITION:'_':DESC:'_XXX.':TYPE:'" >nul 2>&1'

          END
          IF PROG.CHECK="1" THEN
          DATA<-1> = 'pause'
          END
          DATA<-1>  = 'cd c:\pdf\':JOB
                 IF PN = 'C' THEN
          DATA<-1> = 'echo ^<?xml version="1.0" encoding="UTF-8"?^>^<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"^>^<f href="':POSITION:'_':'divider.pdf"/^>^<fields^> > "':SECTION:'".xfdf'
          DATA<-1> = 'echo ^<field name="<job name>"^>^<value^>':JOB:'^</value^>^</field^> >> "':SECTION:'".xfdf'
          DATA<-1> = 'echo ^<field name="<location>"^>^<value^>':CITY.ST:'^</value^>^</field^> >> "':SECTION:'".xfdf'
          DATA<-1> = 'echo ^<field name="<plumbing contractor>"^>^<value^>':OCONV(CUST,'MCU'):'^</value^>^</field^> >> "':SECTION:'".xfdf'
          DATA<-1> = 'echo ^<field name="<ord date>"^>^<value^>':ORD.DATE:'^</value^>^</field^> >> "':SECTION:'".xfdf'
          DATA<-1> = 'echo ^<field name="<section>"^>^<value^>':SECTION:'^</value^>^</field^> >> "':SECTION:'".xfdf'
          DATA<-1> = 'echo ^</fields^> >> "':SECTION:'".xfdf'
          DATA<-1> = 'echo ^<ids original="C8F9D11373F34543A0AE407C553380A6" modified="2042F98C87FAAC41AC7AB53F7EB704A5"/^> >> "':SECTION:'".xfdf'
          DATA<-1> = 'echo ^</xfdf^> >> "':SECTION:'".xfdf'
          DATA<-1> = 'c:\pdf\pdftk ':POSITION:'_':FIELD(DIVIDER,'.',1):'_XXX.pdf fill_form ':'"':SECTION:'"':'.xfdf output ':POSITION:'_divider.pdf'
          DATA<-1> = 'del ':POSITION:'_':FIELD(DIVIDER,'.',1):'_XXX.pdf'

          END

          IF PROG.CHECK="1" THEN
          DATA<-1> = 'pause'
          END

                                                                          *
        * DATA<-1> = COMMAND
        * DATA<-1> = SORT
        * DATA<-1> = 'cd ':PARTS
SKIP.LD:  NEXT LDID

          MATPARSE LD FROM SV.LD
          DATA<-1>  = 'cd c:\pdf\':JOB


          DATA<-1> = 'echo ^<?xml version="1.0" encoding="UTF-8"?^>^<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"^>^<f href="submittal_header.pdf"/^> > 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,'MCU'):'^</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> = 'c:\pdf\pdftk submittal_header.pdf fill_form submittal.xfdf output 000_header_XXX.pdf'
          DATA<-1> = 'del submittal_header.pdf toc.pdf divider.pdf'
          DATA<-1> = 'c:\pdf\pdftk.exe *.pdf cat output "':OCONV(CUST,'MCU'):'_':JOB:'_incomplete.pdf"'
          DATA<-1> = 'del *_XXX.pdf'
          DATA<-1> = 'del submittal.xfdf'
          DATA<-1> = 'c:\pdf\pdftk "':OCONV(CUST,'MCU'):'_':JOB:'_incomplete.pdf" output "':OCONV(CUST,'MCU'):'_':JOB:'.pdf" flatten'
          DATA<-1> = 'del *_incomplete.pdf bb.jpg  index.xfdf submittal_cover_page.docx'
          DATA<-1> = '"':OCONV(CUST,'MCU'):'_':JOB:'.pdf"'
 *         DATA<-1> = PARTS
 *          DATA<-1> = 'pause'


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

          PRINT DATA<J>
          NEXT J

FINISH:   RETURN
*-------------------------------------------------------------------------*
!TSMITH~06/11/15~15:46
